From 146618fb221ebe1f008a0dd1ed05a0fc5ba935da Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 1 Feb 2022 08:38:34 +0100 Subject: [PATCH 1/3] Fix T95376: Fix crash when switching to UV workspace. Can also happen in other places when the overlay engine is active. Some parts of the overlay engine uses builtin shaders, but disable the color space conversion to the target texture. Currently there the overlay engine has its own set of libraries it could include and defined a macro to pass-throught the color space conversion. The library include mechanism currently fails when it couldn't find the builtin library in the libraries of the overlay engine. This only happened in debug mode. This change will not fail, but warns the developer if a library could not be included. In the future this should be replaced by a different mechanism that can disable the builtin library. See {T95382}. --- source/blender/draw/CMakeLists.txt | 1 + source/blender/draw/intern/draw_manager_shader.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 3c25252efe8..47d99963ef9 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -45,6 +45,7 @@ set(INC ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/opensubdiv + ../../../intern/clog # dna_type_offsets.h ${CMAKE_CURRENT_BINARY_DIR}/../makesdna/intern diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c index f8e64041a92..4715bd62779 100644 --- a/source/blender/draw/intern/draw_manager_shader.c +++ b/source/blender/draw/intern/draw_manager_shader.c @@ -46,6 +46,10 @@ #include "draw_manager.h" +#include "CLG_log.h" + +static CLG_LogRef LOG = {"draw.manager.shader"}; + extern char datatoc_gpu_shader_2D_vert_glsl[]; extern char datatoc_gpu_shader_3D_vert_glsl[]; extern char datatoc_gpu_shader_depth_only_frag_glsl[]; @@ -616,11 +620,10 @@ static uint32_t drw_shader_dependencies_get(const DRWShaderLibrary *lib, const c } dbg_name[i + 1] = '\0'; - printf( - "Error: Dependency not found: %s\n" - "This might be due to bad lib ordering.\n", - dbg_name); - BLI_assert(0); + CLOG_WARN(&LOG, + "Error: Dependency not found: %s\n" + "This might be due to bad lib ordering or overriding a builtin shader.\n", + dbg_name); } else { deps |= 1u << (uint32_t)dep; From 396413dedf079478418771da159bb2c97bb0e4e9 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 1 Feb 2022 10:49:28 +0100 Subject: [PATCH 2/3] Partial Fix: Showing Compositor Backdrop in node editor. Since splitting the depth and the color shader in the image engine the backdrop wasn't visible anymore. The reson is that the min max uv coordinates were never working for the node editor backdrop that uses its own coordinate space. This partial fix will ignore the depth test when drawing the color part of the backdrop. This will still have artifacts that are visible when showing other options as RGBA. Proper fix would be to calculate the the uv vbo in uv space and not in image space. --- source/blender/draw/engines/image/image_private.hh | 2 ++ source/blender/draw/engines/image/image_space_node.hh | 1 + .../engines/image/shaders/image_engine_color_frag.glsl | 9 ++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/blender/draw/engines/image/image_private.hh b/source/blender/draw/engines/image/image_private.hh index d8f8adb7e84..d586515c6be 100644 --- a/source/blender/draw/engines/image/image_private.hh +++ b/source/blender/draw/engines/image/image_private.hh @@ -54,6 +54,8 @@ struct IMAGE_Data { #define IMAGE_DRAW_FLAG_APPLY_ALPHA (1 << 1) #define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2) #define IMAGE_DRAW_FLAG_DEPTH (1 << 3) +/** Flag to disable depth testing (used for node editor back drop drawing).*/ +#define IMAGE_DRAW_FLAG_DEPTH_ALWAYS (1 << 4) /** * Abstract class for a drawing mode of the image engine. diff --git a/source/blender/draw/engines/image/image_space_node.hh b/source/blender/draw/engines/image/image_space_node.hh index 15eef8f6499..b0da3d1055b 100644 --- a/source/blender/draw/engines/image/image_space_node.hh +++ b/source/blender/draw/engines/image/image_space_node.hh @@ -56,6 +56,7 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor { void get_shader_parameters(ShaderParameters &r_shader_parameters, ImBuf *ibuf) override { + r_shader_parameters.flags |= IMAGE_DRAW_FLAG_DEPTH_ALWAYS; if ((snode->flag & SNODE_USE_ALPHA) != 0) { /* Show RGBA */ r_shader_parameters.flags |= IMAGE_DRAW_FLAG_SHOW_ALPHA | IMAGE_DRAW_FLAG_APPLY_ALPHA; diff --git a/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl index 0edc18836f0..65fd4833b23 100644 --- a/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl +++ b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl @@ -5,6 +5,7 @@ #define IMAGE_DRAW_FLAG_APPLY_ALPHA (1 << 1) #define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2) #define IMAGE_DRAW_FLAG_DEPTH (1 << 3) +#define IMAGE_DRAW_FLAG_DEPTH_ALWAYS (1 << 4) #define FAR_DISTANCE farNearDistances.x #define NEAR_DISTANCE farNearDistances.y @@ -12,9 +13,11 @@ void main() { ivec2 uvs_clamped = ivec2(uv_screen); - float depth = texelFetch(depth_texture, uvs_clamped, 0).r; - if (depth == 1.0) { - discard; + if ((drawFlags & IMAGE_DRAW_FLAG_DEPTH_ALWAYS) == 0) { + float depth = texelFetch(depth_texture, uvs_clamped, 0).r; + if (depth == 1.0) { + discard; + } } vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0); From 6f9828289f397228c6cab6f352fb4a84a65da22a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 31 Jan 2022 17:37:07 +0100 Subject: [PATCH 3/3] Fix T95356: Crash in armature edit mode and certain condition Blender would have crashed when renaming bone in Edit Mode, Saving, and than selecting/deselecting. Caused by a mistake in the 0f89bcdbebf5: can not "short-circuit" the CoW update if it was explicitly requested. Safest for now solution seems to be to store whether the CoW component has been explicitly tagged, so that the following configuration can be supported: DEG_id_tag_update(id, ID_RECALC_GEOMETRY); DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE); Differential Revision: https://developer.blender.org/D13966 --- source/blender/depsgraph/intern/depsgraph_tag.cc | 5 +++++ .../blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 2 +- source/blender/depsgraph/intern/node/deg_node_id.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index 4bc9e0d2d14..6614509f860 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -284,6 +284,7 @@ void depsgraph_tag_component(Depsgraph *graph, * here. */ if (component_node == nullptr) { if (component_type == NodeType::ANIMATION) { + id_node->is_cow_explicitly_tagged = true; depsgraph_id_tag_copy_on_write(graph, id_node, update_source); } return; @@ -301,6 +302,9 @@ void depsgraph_tag_component(Depsgraph *graph, if (component_node->need_tag_cow_before_update()) { depsgraph_id_tag_copy_on_write(graph, id_node, update_source); } + if (component_type == NodeType::COPY_ON_WRITE) { + id_node->is_cow_explicitly_tagged = true; + } } /* This is a tag compatibility with legacy code. @@ -888,6 +892,7 @@ void DEG_ids_clear_recalc(Depsgraph *depsgraph, const bool backup) * correctly when there are multiple depsgraph with others still using * the recalc flag. */ id_node->is_user_modified = false; + id_node->is_cow_explicitly_tagged = false; deg_graph_clear_id_recalc_flags(id_node->id_cow); if (deg_graph->is_active) { deg_graph_clear_id_recalc_flags(id_node->id_orig); diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index 851d0bcf000..8a3c5c5b776 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -904,7 +904,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, const IDNode * modifiers. * * TODO: Investigate modes besides edit-mode. */ - if (check_datablock_expanded(id_cow)) { + if (check_datablock_expanded(id_cow) && !id_node->is_cow_explicitly_tagged) { const ID_Type id_type = GS(id_orig->name); if (OB_DATA_SUPPORT_EDITMODE(id_type) && BKE_object_data_is_in_editmode(id_orig)) { /* Make sure pointers in the edit mode data are updated in the copy. diff --git a/source/blender/depsgraph/intern/node/deg_node_id.h b/source/blender/depsgraph/intern/node/deg_node_id.h index 257e42b8e67..f18c44b6332 100644 --- a/source/blender/depsgraph/intern/node/deg_node_id.h +++ b/source/blender/depsgraph/intern/node/deg_node_id.h @@ -121,6 +121,9 @@ struct IDNode : public Node { /* Accumulated flag from operation. Is initialized and used during updates flush. */ bool is_user_modified; + /* Copy-on-Write component has been explicitly tagged for update. */ + bool is_cow_explicitly_tagged; + /* Accumulate recalc flags from multiple update passes. */ int id_cow_recalc_backup;