Sculpt: Improve mesh normals update performance #116209
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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#116209
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:pbvh-mesh-normals-full-node"
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?
Instead of storing a boolean "update tag" for every vertex, just
recalculate the normals of all the faces and vertices in affected PBVH
nodes. This avoids the overhead of tracking position updates at the
vertex level, and simplifies the normal calculation, since we can
just calculate values for all the normals in a node.
The main way we gain performance is avoiding building a
VectorSet
for all vertices and faces that need updates in the entire mesh. That
process had to be single threaded, and was a large bottleneck when many
vertices were affected at a time.
That
VectorSet
was necessary for thread safety deduplication of workthough, because neighboring nodes can't calculate the normals of the
same faces or vertices at the same time. (Normals need to be calculated
for all faces connected to moved vertices and all vertices connected to
those faces). In this PR, we only build a set of the boundary faces
and vertices. We calculate those in a separate step, which duplicates
work from the non-boundary calculations, but at least it's threadsafe.
I measured normal recalculation timing when sculpting on a 16 million
vertex mesh. The removal of the
vert_bitmap
array also saves 16 MBof memory.
@blender-bot build
That is quite a speedup shown in the table!
I have few questions:
Thinking a bit into the future, when we'll hopefully have smaller nodes: would it be benefitial to limit updates to modified nodes only? Surely doing per-vertex tracking is overkill which leads to slowdown, but maybe tagging modified nodes and limiting normals update to them is something we'd want to have in the long term? If an artist is zoomed into into some detail of a mesh it seems a bit wasteful to re-calculate all normals while they are only modifying vertices in a handful of nodes. What are your thoughts about it?
Right, my bad, the description is confusing. It's the number of vertices affected by the brush stroke (depending on the brush size) in that 16 million vertex mesh.
It's only the normals update time.
Maybe I was misleading-- only normals of affected nodes are recalculated. That's handled by the existing
BKE_pbvh_node_mark_update
calls.More generally though, this is still the main trouble with this code. Changing vertex normals also changes surrounding face normals, which changes the normals of all vertices connected to those faces. So the set of vertices that need recalculated normals can propagate into unchanged/untagged PBVH nodes. It's the best solution I have now, but I don't really like the
vert_to_face_map
andVectorSet
combination. I think it will continue to give us performance problems in the future, and it won't scale as well with smaller nodes, since the proportion of boundary vertices will increase.PBVH: Improve mesh normals update performanceto Sculpt: Improve mesh normals update performanceAh, the comment makes it more clear and aligns better with what I see in the code. Maybe tweak the description "in entire PBVH nodes" -> "in entire affected PBVH nodes" ?
Didn't have time to apply the patch and verify it, would trust your testing on this. Unless you explicitly want extra eyes for testing..
Good point, I went with "all the faces and vertices in affected PBVH nodes".
I'll double check again before committing. But yeah, I've tested this a few times by now.