From 86991fbcb0e8a1c65acff5aed85ce55f8b108baa Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 21 Jan 2013 08:49:42 +0000 Subject: Fixed render time regression in Blender Internal It was caused by image threading safe commit and it was noticeable only on really multi-core CPU (like dual-socket Xeon stations), was not visible on core i7 machine. The reason of slowdown was spinlock around image buffer referencing, which lead to lots of cores waiting for single core and using image buffer after it was referenced was not so much longer than doing reference itself. The most clear solution here seemed to be introducing Image Pool which will contain list of loaded and referenced image buffers, so all threads could skip lock if the pool is used for reading only. Lock only needed in cases when buffer for requested image user is missing in the pool. This lock will happen only once per image so overall amount of locks is much less that it was before. To operate with pool: - BKE_image_pool_new() creates new pool - BKE_image_pool_free() destroys pool and dereferences all image buffers which were loaded to it - BKE_image_pool_acquire_ibuf() returns image buffer for given image and user. Pool could be NULL and in this case fallback to BKE_image_acquire_ibuf will happen. This helps to avoid lots to if(poll) checks in image sampling code. - BKE_image_pool_release_ibuf releases image buffer. In fact, it will only do something if pool is NULL, in all other case it'll equal to DoNothing operation. --- source/blender/render/extern/include/RE_shader_ext.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/blender/render/extern') diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 10045a8f7e1..4b3e7c2bc42 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -189,14 +189,15 @@ typedef struct ShadeInput { struct Tex; struct MTex; struct ImBuf; +struct ImagePool; /* this one uses nodes */ -int multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres); +int multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, struct ImagePool *pool); /* nodes disabled */ -int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres); +int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool); /* only for internal node usage */ int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, - const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex); + const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex, struct ImagePool *pool); /* shaded view and bake */ struct Render; -- cgit v1.2.3 From 04affbe80eeddd0cd9a47b888cce3f9b26dbbe04 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 21 Jan 2013 09:05:05 +0000 Subject: Support normalized displacement maps in cases maximal distance is not set This will calculate maximal distance automatically and normalize displacement to it. Before this change normalization will not happen at all in cases max distance is not set manually. This affects on "regular" baker only, there are still some fixes to come for multiresolution baker, but that could be solved separately. --- source/blender/render/extern/include/RE_shader_ext.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/blender/render/extern') diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 4b3e7c2bc42..8818aa67c32 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -184,6 +184,11 @@ typedef struct ShadeInput { } ShadeInput; +typedef struct BakeImBufuserData { + float *displacement_buffer; + float displacement_min, displacement_max; + char *mask_buffer; +} BakeImBufuserData; /* node shaders... */ struct Tex; @@ -207,6 +212,7 @@ struct Object; int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob, short *do_update, float *progress); struct Image *RE_bake_shade_get_image(void); void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter); +void RE_bake_ibuf_normalize_displacement(struct ImBuf *ibuf, float *displacement, char *mask, float global_displacement_min, float global_displacement_max); #define BAKE_RESULT_OK 0 #define BAKE_RESULT_NO_OBJECTS 1 -- cgit v1.2.3 From 709a86a8d96825069820dca4b68da5739bcd791c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 21 Jan 2013 18:34:27 +0000 Subject: Multires baker: fix wrong normalization if baking happens to multiple images Previously normalization will happen per image buffer individually, which was wrong in cases different faces of the sane mesh uses different images. Also solved possible threading issues when calculating min.max displacement. --- source/blender/render/extern/include/RE_shader_ext.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/blender/render/extern') diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 8818aa67c32..d686de21517 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -186,7 +186,6 @@ typedef struct ShadeInput { typedef struct BakeImBufuserData { float *displacement_buffer; - float displacement_min, displacement_max; char *mask_buffer; } BakeImBufuserData; @@ -212,7 +211,7 @@ struct Object; int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob, short *do_update, float *progress); struct Image *RE_bake_shade_get_image(void); void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter); -void RE_bake_ibuf_normalize_displacement(struct ImBuf *ibuf, float *displacement, char *mask, float global_displacement_min, float global_displacement_max); +void RE_bake_ibuf_normalize_displacement(struct ImBuf *ibuf, float *displacement, char *mask, float displacement_min, float displacement_max); #define BAKE_RESULT_OK 0 #define BAKE_RESULT_NO_OBJECTS 1 -- cgit v1.2.3 From 95a13a2c02caec332d4d5b521441f1c49ddb07a3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 22 Jan 2013 08:05:00 +0000 Subject: Fix projection texture painting crash It was caused by own mistake by not noticing externtex is used not only by render engine. Now this function uses pool passed as argument rather than using R.pool. --- source/blender/render/extern/include/RE_render_ext.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender/render/extern') diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 2a9a1becc42..2dfbdd0d6f5 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -49,10 +49,11 @@ struct RNode; struct Render; struct MTex; struct ImBuf; +struct ImagePool; struct DerivedMesh; /* particle.c, effect.c, editmesh_modes.c and brush.c, returns 1 if rgb, 0 otherwise */ -int externtex(struct MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta, const int thread); +int externtex(struct MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta, const int thread, struct ImagePool *pool); /* particle.c */ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype); -- cgit v1.2.3 From 59a187b33876ad274cfd5cfcf13a3d25dbfe1b0a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 24 Jan 2013 08:14:20 +0000 Subject: Fix threading issues of viewport rendering when using movies/generated images Issue was caused by the fact that guarded allocator is not thread-safe and generated images/movies could allocate memory when loading pixels to Cycles. Currently solved by switching memory allocator to using mutex lock (the same as sued for jobs) when viewport rendering is used. Nicer solution would be to make guarded allocator thread-safe by using atomic operations and lock-free lists, but that's more serious change. --- source/blender/render/extern/include/RE_engine.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/render/extern') diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index 64135a16f5d..b687acae1f7 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -62,6 +62,7 @@ struct Scene; #define RE_ENGINE_DO_UPDATE 8 #define RE_ENGINE_RENDERING 16 #define RE_ENGINE_HIGHLIGHT_TILES 32 +#define RE_ENGINE_USED_FOR_VIEWPORT 64 extern ListBase R_engines; @@ -105,6 +106,7 @@ typedef struct RenderEngine { } RenderEngine; RenderEngine *RE_engine_create(RenderEngineType *type); +RenderEngine *RE_engine_create_ex(RenderEngineType *type, int use_for_viewport); void RE_engine_free(RenderEngine *engine); void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y); -- cgit v1.2.3