From 68ca12a7fc0eea117103d894609eb46c169ec88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Wed, 27 Apr 2022 10:22:07 +0200 Subject: [PATCH] Fix T96283: last disabled subsurf is used for GPU subdivision When more than one, consecutive, subdivision modifier is used on a Mesh, the last subsurf modifier is used for GPU subdivision even though it might be disabled. This is because retrieving the last subsurf modifier in the draw code did not check whether the modifier was disabled or not. To fix this, the session UUID of the modifier which delegated evaluation to the GPU code is cached and used in the draw to select the right subsurf modifier. Differential Revision: https://developer.blender.org/D14488 --- source/blender/draw/intern/draw_cache_impl_subdivision.cc | 3 ++- source/blender/makesdna/DNA_mesh_types.h | 4 +++- source/blender/modifiers/intern/MOD_subsurf.c | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index c859a72b371..1b84ac9b5a6 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -1898,7 +1898,8 @@ static bool draw_subdiv_create_requested_buffers(const Scene *scene, const bool /*use_hide*/, OpenSubdiv_EvaluatorCache *evaluator_cache) { - SubsurfModifierData *smd = BKE_object_get_last_subsurf_modifier(ob); + SubsurfModifierData *smd = reinterpret_cast( + BKE_modifiers_findby_session_uuid(ob, &mesh->runtime.subsurf_session_uuid)); BLI_assert(smd); const bool is_final_render = DRW_state_is_scene_render(); diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index cd4676ee08e..1f8ff182510 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -10,6 +10,7 @@ #include "DNA_ID.h" #include "DNA_customdata_types.h" #include "DNA_defs.h" +#include "DNA_session_uuid_types.h" #ifdef __cplusplus extern "C" { @@ -120,11 +121,12 @@ typedef struct Mesh_Runtime { */ char wrapper_type_finalize; - int subsurf_resolution; /** * Settings for lazily evaluating the subdivision on the CPU if needed. These are * set in the modifier when GPU subdivision can be performed. */ + SessionUUID subsurf_session_uuid; + int subsurf_resolution; char subsurf_apply_render; char subsurf_use_optimal_display; diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 249d09e5d2e..571e564f583 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -205,6 +205,7 @@ static void subdiv_cache_cpu_evaluation_settings(const ModifierEvalContext *ctx, me->runtime.subsurf_apply_render = (ctx->flag & MOD_APPLY_RENDER) != 0; me->runtime.subsurf_resolution = mesh_settings.resolution; me->runtime.subsurf_use_optimal_display = mesh_settings.use_optimal_display; + me->runtime.subsurf_session_uuid = smd->modifier.session_uuid; } /* Modifier itself. */