Sculpt: Reuse existing mesh triangles cache in sculpt mode #123638
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#123638
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "HooglyBoogly/blender:sculpt-triangles-freeze"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Addresses #121240.
Instead of allocating a new array and recalculating mesh triangulation
every time the user enters sculpt mode, reuse the mesh's existing cache.
Currently in order to avoid recalculating triangulation on every brush update
(which would typically be necessary because the triangulation direction
depends on vertex positions), add a mechanism to "freeze" the cache to
skip recalculations until the user exits sculpt mode. That even avoids
recalculation if vertex positions aren't affected. This is necessary because
we can't use the cache in a dirty state; tagging the cache dirty frees the
triangulation array.
Removing the duplicate triangles array reduces memory usage by 384 MB
in a 16 million vertex sculpt, and makes entering sculpt mode 125ms faster
(tested on a Ryzen 7840u).
In the long term, I hope we find a different solution that's a bit more
transparent and hopefully more integrated with the caching system
in general. In the meantime, this is a relatively safe low impact change
that helps document the needs for such a system anyway.
@blender-bot build
I am confused by the explanation in the current code, and in this PR.
I don't understand how we can re-calculate triangulation of a mesh without changing anything else in the BVH. So the related part of the current comment
/* Owned by the #PBVH, because after deformations they have to be recomputed. */
seems odd. I also don't see any calls to thecorner_tris_calc_impl
when sculpting on a base mesh (without modifiers). So do we really re-calculate anything?The part in the new code around
has a couple of issues (at least from the wording and presentation perspectives):
So for the base mesh sculpting what this change effectively is doing is use pre-calculated triangles from the input mesh, and that where the speedup is coming from. To achieve this speedup we can just use the input mesh triangulation in the PBVH.
The bigger unknown impact is the fact that the PBVH is referencing the array now. Ignoring the deformed mesh case it seems we can remove this field from PBVH, and pass it along just like
corner_tris
orcorner_tri_faces
.For the sculpting on the deformed mesh the triangulation is strange already, as it triangulation from the non-deformed mesh. So, perhaps the strategy from above will also work for the deformed mesh sculpting as well.
But all that leads me to thinking: why do we even need this "freeze" idea for triangulation? What cases it covers which are not covered with a simpler approach from above?
@ -656,4 +656,3 @@
const int totvert = mesh->verts_num;
const int corner_tris_num = poly_to_tri_count(mesh->faces_num, mesh->corners_num);
MutableSpan<float3> vert_positions = mesh->vert_positions_for_write();
const OffsetIndices<int> faces = mesh->faces();
const OffsetIndices<int> faces = mesh->faces();
is now unused.Thanks for the in-depth comment. I think you're misunderstanding though, thinking that we are currently recalculating triangles during sculpting. We aren't, the triangulation is unchanged after brush strokes. This PR is about maintaining that fact without the need to duplicate the triangles into a separate array just for the PBVH/sculpt mode. It's implementing 3.iii. from #121240.
Right, I wouldn't take changing that lightly, but that's already how it is.
Not so weird IMO. The PBVH draws data from the original mesh with positions retrieved from the evaluated mesh. And sculpting modifies the original mesh rather than the evaluated mesh.
Yes, removing the reference from the PBVH is the next step, but I'd commit that separately, it makes the change in this PR less clear.
Not sure what simpler approach you're describing. I think it comes from the same misunderstanding/miscommunication?
This is not what I am thinking.
What I am thinking is that:
To me those statements do not add up in a coherent state of the code and the change.
Simpler solution: remove
PBVH::corner_tris;
WITHOUT adding the freezing mechanism.From talking in a video call, the missing bit of information was that it isn't possible to safely continue using the triangulation cache after tagging it dirty.
SharedCache::tag_dirty()
is implementing by deleting the data, which un-shares it. I rephrased the PR description to hopefully make that clearer. We hack around this with theupdate()
function for normals, which need to be updated during sculpting. But in this case it's better to keep using the currenttag_positions_changed
and not introduce more complexity to the more public mesh API.Thanks for the clarification, it helps a lot!