diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-11 05:34:16 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-01-11 05:34:16 +0300 |
commit | f134341e03b5fe3edd5112557bcf42f6667ba69d (patch) | |
tree | 34376b0f99a862d4956596a91dab987d7f2c62aa /source/blender/blenkernel/intern | |
parent | 922ae55a16a96784427080505f0a751c05a74fb6 (diff) |
Fix T94671: performance regression with subsurf modifier
rBeed45d2a239a introduced a GPU backend for OpenSubDiv which lets us do
the subdivision at render time. However, some tools might still need to
have the subdivision data available on the CPU side. For this a
subdivision mesh wrapper was also introduced, and is computed whenever a
CPU side mesh is needed. The subdivision settings for this wrapper are
stored during modifier evaluation if GPU subdivision can be done.
The performance regression is due to the fact that although the
subdivision mesh was already computed on the CPU, and no subdivision
wrapper is generated, some checks for creating subdivision data in
`BKE_mesh_wrapper_ensure_subdivision` where still run, one of which is
very expensive.
To fix this we first check the runtime settings of the mesh to see if
subdivision is needed at all.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_wrapper.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/mesh_wrapper.c b/source/blender/blenkernel/intern/mesh_wrapper.c index 4cc43354a44..d1f15cf9007 100644 --- a/source/blender/blenkernel/intern/mesh_wrapper.c +++ b/source/blender/blenkernel/intern/mesh_wrapper.c @@ -331,6 +331,18 @@ Mesh *BKE_mesh_wrapper_ensure_subdivision(const Object *ob, Mesh *me) return me; } + /* Initialize the settings before ensuring the descriptor as this is checked to decide whether + * subdivision is needed at all, and checking the descriptor status might involve checking if the + * data is out-of-date, which is a very expensive operation. */ + SubdivToMeshSettings mesh_settings; + mesh_settings.resolution = me->runtime.subsurf_resolution; + mesh_settings.use_optimal_display = me->runtime.subsurf_use_optimal_display; + + if (mesh_settings.resolution < 3) { + BLI_mutex_unlock(mesh_eval_mutex); + return me; + } + const bool apply_render = me->runtime.subsurf_apply_render; SubdivSettings subdiv_settings; @@ -349,15 +361,6 @@ Mesh *BKE_mesh_wrapper_ensure_subdivision(const Object *ob, Mesh *me) return me; } - SubdivToMeshSettings mesh_settings; - mesh_settings.resolution = me->runtime.subsurf_resolution; - mesh_settings.use_optimal_display = me->runtime.subsurf_use_optimal_display; - - if (mesh_settings.resolution < 3) { - BLI_mutex_unlock(mesh_eval_mutex); - return me; - } - Mesh *subdiv_mesh = BKE_subdiv_to_mesh(subdiv, &mesh_settings, me); if (subdiv != runtime_data->subdiv) { |