diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-03-20 17:56:09 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-03-20 17:56:09 +0300 |
commit | 62b31a6e997ca6ca10cad695252909c657d67401 (patch) | |
tree | e153c9e5d228873933858fbf8a9f4d2c34e1d96f | |
parent | 339e43e1e821276cf69c0f9829c83999bf79d769 (diff) |
Avoid per-draw allocation when drawing currently rendering tiles
-rw-r--r-- | source/blender/editors/space_image/image_draw.c | 7 | ||||
-rw-r--r-- | source/blender/render/extern/include/RE_engine.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/external_engine.c | 19 |
3 files changed, 18 insertions, 10 deletions
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index d03f3c157a9..517cf64214c 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -106,9 +106,10 @@ static void draw_render_info(const bContext *C, if (re) { int total_tiles; + bool need_free_tiles; rcti *tiles; - RE_engine_get_current_tiles(re, &total_tiles, &tiles); + tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles); if (total_tiles) { int i, x, y; @@ -133,7 +134,9 @@ static void draw_render_info(const bContext *C, glaDrawBorderCorners(tile, zoomx, zoomy); } - MEM_freeN(tiles); + if (need_free_tiles) { + MEM_freeN(tiles); + } glPopMatrix(); } diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index 5edf970c129..bc4c4c54f17 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -159,7 +159,7 @@ void RE_engines_exit(void); RenderEngineType *RE_engines_find(const char *idname); -void RE_engine_get_current_tiles(struct Render *re, int *total_tiles_r, rcti **tiles_r); +rcti* RE_engine_get_current_tiles(struct Render *re, int *total_tiles_r, bool *needs_free_r); struct RenderData *RE_engine_get_render_data(struct Render *re); void RE_bake_engine_set_engine_parameters(struct Render *re, struct Main *bmain, struct Scene *scene); diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 557fcb01778..d5f1cab3a66 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -368,26 +368,31 @@ void RE_engine_set_error_message(RenderEngine *engine, const char *msg) } } -void RE_engine_get_current_tiles(Render *re, int *total_tiles_r, rcti **tiles_r) +rcti* RE_engine_get_current_tiles(Render *re, int *total_tiles_r, bool *needs_free_r) { + static rcti tiles_static[BLENDER_MAX_THREADS]; + const int allocation_step = BLENDER_MAX_THREADS; RenderPart *pa; int total_tiles = 0; - rcti *tiles = NULL; - int allocation_size = 0, allocation_step = BLENDER_MAX_THREADS; + rcti *tiles = tiles_static; + int allocation_size = BLENDER_MAX_THREADS; BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_READ); if (re->engine && (re->engine->flag & RE_ENGINE_HIGHLIGHT_TILES) == 0) { *total_tiles_r = 0; - *tiles_r = NULL; BLI_rw_mutex_unlock(&re->partsmutex); - return; + needs_free_r = false; + return NULL; } for (pa = re->parts.first; pa; pa = pa->next) { if (pa->status == PART_STATUS_IN_PROGRESS) { if (total_tiles >= allocation_size) { - if (tiles == NULL) + /* Just in case we're using crazy network rendering with more + * slaves as BLENDER_MAX_THREADS. + */ + if (tiles == tiles_static) tiles = MEM_mallocN(allocation_step * sizeof(rcti), "current engine tiles"); else tiles = MEM_reallocN(tiles, (total_tiles + allocation_step) * sizeof(rcti)); @@ -409,7 +414,7 @@ void RE_engine_get_current_tiles(Render *re, int *total_tiles_r, rcti **tiles_r) } BLI_rw_mutex_unlock(&re->partsmutex); *total_tiles_r = total_tiles; - *tiles_r = tiles; + return tiles; } RenderData *RE_engine_get_render_data(Render *re) |