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.
This commit is contained in:
2017-05-30 15:40:14 +02:00
parent b62a7767a0
commit 03469d90b2
3 changed files with 33 additions and 0 deletions

View File

@@ -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);
}
}
}
}