Fix #130636: Sculpt performance regression under certain circumstances
As part of the overall sculpt brush refactor project, the `corner_tris` attribute was removed from the PBVH and accessed directly from the mesh runtime data. A new set of methods was introduced to the `TrianglesCache` `struct` to prevent tagging the cache as dirty and requiring a subsequent evaluation because the performance hit while in sculpt mode was significant. This was enabled upon entering sculpt mode and disabled upon exiting it. Unfortunately, there are some operations inside Sculpt mode which can cause either the Mesh object itself or the MeshRuntime object to be recreated, effectively unfreezing the cache. A few examples that cause this are: * Undoing the first brush operation on file load * Performing a remesh operation To fix this issue, this commit checks and re-freezes the cache if it is detected to be in a bad state prior to tagging the cache as dirty. Further changes to fix this on a more fundamental level are well outside of the scope of a fix needed for 4.3.1. Pull Request: https://projects.blender.org/blender/blender/pulls/130709
This commit is contained in:
@@ -5039,6 +5039,20 @@ void flush_update_step(bContext *C, UpdateType update_type)
|
||||
|
||||
if (update_type == UpdateType::Position && !ss.shapekey_active) {
|
||||
if (pbvh.type() == bke::pbvh::Type::Mesh) {
|
||||
/* Various operations inside sculpt mode can cause either the MeshRuntimeData or the entire
|
||||
* Mesh to be changed (e.g. Undoing the very first operation after opening a file, performing
|
||||
* remesh, etc).
|
||||
*
|
||||
* This is an unideal fix for the core issue here, but to mitigate the drastic performance
|
||||
* falloff, we refreeze the cache before we do any operation that would tag this runtime
|
||||
* cache as dirty.
|
||||
*
|
||||
* See #130636.
|
||||
*/
|
||||
if (!mesh->runtime->corner_tris_cache.frozen) {
|
||||
mesh->runtime->corner_tris_cache.freeze();
|
||||
}
|
||||
|
||||
/* Updating mesh positions without marking caches dirty is generally not good, but since
|
||||
* sculpt mode has special requirements and is expected to have sole ownership of the mesh it
|
||||
* modifies, it's generally okay. */
|
||||
|
||||
Reference in New Issue
Block a user