From cde5e12c0bcc55b7c19b625ebf7a6f29dbd833d7 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 1 Mar 2022 11:35:11 +0100 Subject: [PATCH 1/2] Fix T96097: Image editor tile drawing not working. The image engine is depth aware when using tile drawing the depth is only updated for the central image what lead to showing the background on top of other areas. Also makes sure that switching the tile drawing would lead to an update of the texture slots. --- source/blender/draw/engines/image/image_drawing_mode.hh | 8 ++++++-- source/blender/draw/engines/image/image_instance_data.hh | 2 +- source/blender/draw/engines/image/image_usage.hh | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh index 267b0477a29..12d8607a8bd 100644 --- a/source/blender/draw/engines/image/image_drawing_mode.hh +++ b/source/blender/draw/engines/image/image_drawing_mode.hh @@ -507,7 +507,9 @@ template class ScreenSpaceDrawingMode : public AbstractD /* Step: Add the GPU textures to the shgroup. */ instance_data->update_batches(); - add_depth_shgroups(*instance_data, image, iuser); + if (!instance_data->flags.do_tile_drawing) { + add_depth_shgroups(*instance_data, image, iuser); + } add_shgroups(instance_data); } @@ -523,8 +525,10 @@ template class ScreenSpaceDrawingMode : public AbstractD DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); GPU_framebuffer_bind(dfbl->default_fb); + static float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - GPU_framebuffer_clear_color_depth(dfbl->default_fb, clear_col, 1.0); + float clear_depth = instance_data->flags.do_tile_drawing ? 0.75 : 1.0f; + GPU_framebuffer_clear_color_depth(dfbl->default_fb, clear_col, clear_depth); DRW_view_set_active(instance_data->view); DRW_draw_pass(instance_data->passes.depth_pass); diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh index f8f20fbe178..7aeb423071e 100644 --- a/source/blender/draw/engines/image/image_instance_data.hh +++ b/source/blender/draw/engines/image/image_instance_data.hh @@ -121,7 +121,7 @@ struct IMAGE_InstanceData { void update_image_usage(const ImageUser *image_user) { - ImageUsage usage(image, image_user); + ImageUsage usage(image, image_user, flags.do_tile_drawing); 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 bbd56e3db7a..a581731036e 100644 --- a/source/blender/draw/engines/image/image_usage.hh +++ b/source/blender/draw/engines/image/image_usage.hh @@ -24,7 +24,7 @@ /** * ImageUsage contains data of the image and image user to identify changes that require a rebuild - * of the texture slots. + * the texture slots. */ struct ImageUsage { /** Render pass of the image that is used. */ @@ -37,11 +37,12 @@ struct ImageUsage { ColorManagedColorspaceSettings colorspace_settings; /** IMA_ALPHA_* */ char alpha_mode; + bool last_tile_drawing; const void *last_image = nullptr; ImageUsage() = default; - ImageUsage(const struct Image *image, const struct ImageUser *image_user) + ImageUsage(const struct Image *image, const struct ImageUser *image_user, bool do_tile_drawing) { pass = image_user ? image_user->pass : 0; layer = image_user ? image_user->layer : 0; @@ -49,6 +50,7 @@ struct ImageUsage { colorspace_settings = image->colorspace_settings; alpha_mode = image->alpha_mode; last_image = static_cast(image); + last_tile_drawing = do_tile_drawing; } bool operator==(const ImageUsage &other) const From 629f22f161abfbe492d71e08cc89651da683aded Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 24 Feb 2022 14:15:38 +0100 Subject: [PATCH 2/2] Fix T95997: Crash when entering edit mode The issue was uncovered by the 0f89bcdbebf5, but the root cause goes into a much earlier design violation happened in the code: the modifier evaluation function is modifying input mesh, which is not something what is ever expected. Bring code closer to the older state where such modification is only done for the object in edit mode. --- From own tests works seems to work fine, but extra eyes and testing is needed. Differential Revision: https://developer.blender.org/D14191 --- source/blender/blenkernel/intern/DerivedMesh.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 1fcf1bf1839..00a6fa6d178 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -1667,7 +1667,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph, } else { Mesh *me_orig = mesh_input; - if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) { + /* Modifying the input mesh is weak, however as there can only be one object in edit mode + * even if multiple are sharing the same mesh this should be thread safe. */ + if ((me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) && (ob->mode & OB_MODE_EDIT)) { if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) { BKE_mesh_runtime_reset_edit_data(me_orig); }