From a32dbb892fe557573f432f22008c40af57dd7183 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Thu, 27 Apr 2023 17:09:27 +0200 Subject: [PATCH] Realtime Compositor: Optimize image textures This patch optimizes the evaluation of image textures by using and prefetching a unified texture pool for the evaluation. --- .../cached_resources/intern/cached_texture.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc index f078aed8500..d1728779458 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc @@ -11,6 +11,7 @@ #include "GPU_texture.h" +#include "BKE_image.h" #include "BKE_texture.h" #include "DNA_ID.h" @@ -50,6 +51,9 @@ bool operator==(const CachedTextureKey &a, const CachedTextureKey &b) CachedTexture::CachedTexture( Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale) { + ImagePool *image_pool = BKE_image_pool_new(); + BKE_texture_fetch_images_for_pool(texture, image_pool); + Array color_pixels(size.x * size.y); Array value_pixels(size.x * size.y); threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) { @@ -61,7 +65,7 @@ CachedTexture::CachedTexture( /* Note that it is expected that the offset is scaled by the scale. */ coordinates = (coordinates + offset) * scale; TexResult texture_result; - BKE_texture_get_value(scene, texture, coordinates, &texture_result, true); + BKE_texture_get_value_ex(scene, texture, coordinates, &texture_result, image_pool, true); color_pixels[y * size.x + x] = float4(texture_result.trgba); value_pixels[y * size.x + x] = texture_result.talpha ? texture_result.trgba[3] : texture_result.tin; @@ -69,6 +73,8 @@ CachedTexture::CachedTexture( } }); + BKE_image_pool_free(image_pool); + color_texture_ = GPU_texture_create_2d("Cached Color Texture", size.x, size.y,