From 6efdfeb8866a5583ad64e1c74f4089f0b16d55b4 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 18 Feb 2022 07:55:36 +0100 Subject: Image Engine: Store image usage to identity changes. Previous implementation had a copy of the image user, which doesn't contain all the data to identify changes. This patch introduces a new struct to store the data and can be extended with other data as well (color spaces, alpha settings). --- .../draw/engines/image/image_drawing_mode.hh | 2 +- .../draw/engines/image/image_instance_data.hh | 25 +++------- source/blender/draw/engines/image/image_usage.hh | 53 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 source/blender/draw/engines/image/image_usage.hh (limited to 'source') diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh index 795f0c0c45e..124f8057cfe 100644 --- a/source/blender/draw/engines/image/image_drawing_mode.hh +++ b/source/blender/draw/engines/image/image_drawing_mode.hh @@ -475,7 +475,7 @@ template class ScreenSpaceDrawingMode : public AbstractD method.update_screen_uv_bounds(); /* Check for changes in the image user compared to the last time. */ - instance_data->update_image_user(iuser); + instance_data->update_image_usage(iuser); /* Step: Update the GPU textures based on the changes in the image. */ instance_data->update_gpu_texture_allocations(); diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh index 68c61a82e96..e5e19593e23 100644 --- a/source/blender/draw/engines/image/image_instance_data.hh +++ b/source/blender/draw/engines/image/image_instance_data.hh @@ -27,6 +27,7 @@ #include "image_private.hh" #include "image_shader_params.hh" #include "image_texture_info.hh" +#include "image_usage.hh" #include "image_wrappers.hh" #include "DRW_render.h" @@ -40,8 +41,8 @@ constexpr int SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN = 1; struct IMAGE_InstanceData { struct Image *image; - /** Copy of the last image user to detect iuser differences that require a full update. */ - struct ImageUser last_image_user; + /** Usage data of the previous time, to identify changes that require a full update. */ + ImageUsage last_usage; PartialImageUpdater partial_update; @@ -110,23 +111,11 @@ struct IMAGE_InstanceData { } } - void update_image_user(const ImageUser *image_user) + void update_image_usage(const ImageUser *image_user) { - short requested_pass = image_user ? image_user->pass : 0; - short requested_layer = image_user ? image_user->layer : 0; - short requested_view = image_user ? image_user->multi_index : 0; - /* There is room for 2 multiview textures. When a higher number is requested we should always - * target the first view slot. This is fine as multi view images aren't used together. */ - if (requested_view > 1) { - requested_view = 0; - } - - if (last_image_user.pass != requested_pass || last_image_user.layer != requested_layer || - last_image_user.multi_index != requested_view) { - - last_image_user.pass = requested_pass; - last_image_user.layer = requested_layer; - last_image_user.multi_index = requested_view; + ImageUsage usage(image_user); + if (last_usage != usage) { + last_usage = usage; reset_dirty_flag(true); } } diff --git a/source/blender/draw/engines/image/image_usage.hh b/source/blender/draw/engines/image/image_usage.hh new file mode 100644 index 00000000000..fb85d88cd11 --- /dev/null +++ b/source/blender/draw/engines/image/image_usage.hh @@ -0,0 +1,53 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2022, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ + +#pragma once + +/** + * ImageUsage contains data of the image and image user to identify changes that require a rebuild + * of the texture slots. + */ +struct ImageUsage { + /** Render pass of the image that is used. */ + short pass = 0; + /** Layer of the image that is used.*/ + short layer = 0; + /** View of the image that is used. */ + short view = 0; + + ImageUsage() = default; + ImageUsage(const struct ImageUser *image_user) + { + pass = image_user ? image_user->pass : 0; + layer = image_user ? image_user->layer : 0; + view = image_user ? image_user->multi_index : 0; + } + + bool operator==(const ImageUsage &other) const + { + return memcmp(this, &other, sizeof(ImageUsage)) == 0; + } + bool operator!=(const ImageUsage &other) const + { + return !(*this == other); + } +}; -- cgit v1.2.3 From 400e57b64acc5fee1859a815d96db91e4e89aaa0 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 18 Feb 2022 08:11:51 +0100 Subject: Fix T95809: Compositor Node not directly updated in image editor. Image wasn't tagged to be dirty. --- source/blender/compositor/operations/COM_CompositorOperation.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc b/source/blender/compositor/operations/COM_CompositorOperation.cc index 696dbb1807c..cffbf152f27 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cc +++ b/source/blender/compositor/operations/COM_CompositorOperation.cc @@ -105,11 +105,10 @@ void CompositorOperation::deinit_execution() re = nullptr; } + Image *image = BKE_image_ensure_viewer(G.main, IMA_TYPE_R_RESULT, "Render Result"); + BKE_image_partial_update_mark_full_update(image); BLI_thread_lock(LOCK_DRAW_IMAGE); - BKE_image_signal(G.main, - BKE_image_ensure_viewer(G.main, IMA_TYPE_R_RESULT, "Render Result"), - nullptr, - IMA_SIGNAL_FREE); + BKE_image_signal(G.main, image, nullptr, IMA_SIGNAL_FREE); BLI_thread_unlock(LOCK_DRAW_IMAGE); } else { -- cgit v1.2.3 From fe26d188891f95d199e2559929204fddacea2ba8 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 18 Feb 2022 08:22:18 +0100 Subject: Fix T95809: Check color space changes to refresh image engine. Previous commit fixed the compositor node, this commit is related to the shader tree. Also checks if the color space or alpha mode have changed. --- source/blender/draw/engines/image/image_instance_data.hh | 2 +- source/blender/draw/engines/image/image_usage.hh | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh index e5e19593e23..420f9396f3f 100644 --- a/source/blender/draw/engines/image/image_instance_data.hh +++ b/source/blender/draw/engines/image/image_instance_data.hh @@ -113,7 +113,7 @@ struct IMAGE_InstanceData { void update_image_usage(const ImageUser *image_user) { - ImageUsage usage(image_user); + ImageUsage usage(image, image_user); if (last_usage != usage) { last_usage = usage; reset_dirty_flag(true); diff --git a/source/blender/draw/engines/image/image_usage.hh b/source/blender/draw/engines/image/image_usage.hh index fb85d88cd11..1eadee4481d 100644 --- a/source/blender/draw/engines/image/image_usage.hh +++ b/source/blender/draw/engines/image/image_usage.hh @@ -34,12 +34,18 @@ struct ImageUsage { /** View of the image that is used. */ short view = 0; + ColorManagedColorspaceSettings colorspace_settings; + /** IMA_ALPHA_* */ + char alpha_mode; + ImageUsage() = default; - ImageUsage(const struct ImageUser *image_user) + ImageUsage(const struct Image *image, const struct ImageUser *image_user) { pass = image_user ? image_user->pass : 0; layer = image_user ? image_user->layer : 0; view = image_user ? image_user->multi_index : 0; + colorspace_settings = image->colorspace_settings; + alpha_mode = image->alpha_mode; } bool operator==(const ImageUsage &other) const -- cgit v1.2.3