From 03469d90b2a03a61a1c7933a0f49fed3bd334c3b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 30 May 2017 15:40:14 +0200 Subject: Displace modifier: Pre-fetch all possible images to image pool prior execution This way we reduce amount of time wasted in spin-lock later on when all threads are starting to sample texture. --- source/blender/blenkernel/BKE_texture.h | 2 ++ source/blender/blenkernel/intern/texture.c | 30 ++++++++++++++++++++++++++ source/blender/modifiers/intern/MOD_displace.c | 1 + 3 files changed, 33 insertions(+) diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 9a60eb29957..e353d032ee4 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -144,6 +144,8 @@ void BKE_texture_get_value( const struct Scene *scene, struct Tex *texture, float *tex_co, struct TexResult *texres, bool use_color_management); +void BKE_texture_fetch_images_for_pool(struct Tex *texture, struct ImagePool *pool); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index ba04dd9b8f4..b62a72c7d9c 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -1519,3 +1519,33 @@ void BKE_texture_get_value( { BKE_texture_get_value_ex(scene, texture, tex_co, texres, NULL, use_color_management); } + +static void texture_nodes_fetch_images_for_pool(bNodeTree *ntree, struct ImagePool *pool) +{ + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->type == SH_NODE_TEX_IMAGE && node->id != NULL) { + Image *image = (Image *)node->id; + BKE_image_pool_acquire_ibuf(image, NULL, pool); + } + else if (node->type == NODE_GROUP && node->id != NULL) { + /* TODO(sergey): Do we need to control recursion here? */ + bNodeTree *nested_tree = (bNodeTree *)node->id; + texture_nodes_fetch_images_for_pool(nested_tree, pool); + } + } +} + +/* Make sure all images used by texture are loaded into pool. */ +void BKE_texture_fetch_images_for_pool(Tex *texture, struct ImagePool *pool) +{ + if (texture->nodetree != NULL) { + texture_nodes_fetch_images_for_pool(texture->nodetree, pool); + } + else { + if (texture->type == TEX_IMAGE) { + if (texture->ima != NULL) { + BKE_image_pool_acquire_ibuf(texture->ima, NULL, pool); + } + } + } +} diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 18f60bab490..3325f05025f 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -384,6 +384,7 @@ static void displaceModifier_do( data.vert_clnors = vert_clnors; if (dmd->texture != NULL) { data.pool = BKE_image_pool_new(); + BKE_texture_fetch_images_for_pool(dmd->texture, data.pool); } BLI_task_parallel_range(0, numVerts, &data, displaceModifier_do_task, numVerts > 512); -- cgit v1.2.3