Sculpt: Use C++ Set to store PBVH Node BMesh elements #113907
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#113907
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:cleanup-pbvh-bmesh-set"
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?
Mainly to simplify code and also add some add type safety, replace
GSet
withblender::Set
for the storage of BMesh triangles andvertices on each PBVH node. Some initial tests point to better
performance too, but the numbers are hard to verify so far.
Because of the larger
PBVHNode
, memory usage slightly increases(observed a 2% increase with a 1M face grid) for regular Mesh sculpting,
but it seems
Set
is more memory efficient thanGSet
, because I alsoobserved a 10% decrease in memory usage for dynamic topology.
In the future nodes can be split in a more data-oriented fashion to
reduce memory usage overall.
This also makes it simpler to switch to another type in the future.
Cleanup: Use C++ Set to store BMesh facesto Cleanup: Use C++ Set to store PBVH Node BMesh faces@blender-bot build
Cleanup: Use C++ Set to store PBVH Node BMesh facesto Cleanup: Use C++ Set to store PBVH Node BMesh elements@blender-bot build
Cleanup: Use C++ Set to store PBVH Node BMesh elementsto Sculpt: Use C++ Set to store PBVH Node BMesh elements@ -114,3 +117,1 @@
GSet *bm_faces = nullptr;
GSet *bm_unique_verts = nullptr;
GSet *bm_other_verts = nullptr;
blender::Set<BMFace *> bm_faces;
Storing the blender::Set directly like this increases the size of
PBVHNode
from 272 to 608 bytes (each set is 120). Is that alright?Would be nice to double-check on some production high-poky mesh.
AFAIK, the nodes are quite "big" in the terms of amount of geometry they hold, so intuitively I would not consider it a worrysome increase for the files.
In the future we'd need to look into making nodes much smaller, in both memory foorptintm, but also in terms of amount of geometry per leaf node.
That being said, maybe it would be better to do
std::unique_ptr<blender::Set>
so that the increase of memory footprint only happen for BMesh case (where a lot more of memory will be allocated on heap for GSet anyway) ?Using a zero inline buffer size brought the size per set down to 64 bytes. With the total
PBVHNode
size now at 416. That's still not a great increase, but at leas the size isn't double anymore.My hope for PBVH leaf nodes it to separate them into separate structs for each different PBVH type. That way the size of these sets wouldn't influence the size of nodes for multires or Mesh sculpting. I'd also separate things like
PBVHColorBufferNode
andPBVHPixelsNode
so we don't always have to store them. Non-leaf nodes wouldn't store any of this data at all.If it helps I can make a design/todo task about that.
For dynamic topology, I think storing the sets directly is nice and will help reduce indirection.
That's cool improvement!
Still think it would be nice to get some numbers for memory consumption before/after.
To give you some background. This is 50% increase of node size. Increasing BVH2 node size in used in Cycles will lead to around 30% (give of take) overall memory usage for scenes with complex geometry and procedural materials. On a typical production file it will be 10-15% hit. Is not something we should be accepting that easily.
As I've said before, I don't really expect it to be that big of a problem for the PBVH, but it would be very nice to see some number to confirm our expectations. Should be an easy test to do: subdivide cube to 1M faces, enabled dyntopo, compare total memory usage before/after patch.
I did some basic testing with a 1 million face grid.
Conclusion: 2% memory usage increase for mesh sculpting, 10% less memory usage in dynamic topology. The idea of splitting the
PBVHNode
struct in the future is enough to make this seem worthwhile currently IMO.Think 2% is a fine trade-off.
@ -230,3 +227,3 @@
}
static void partialvis_update_bmesh_faces(GSet *faces)
static void partialvis_update_bmesh_faces(const blender::Set<BMFace *> faces)
Pass by reference here?
@ -522,0 +520,4 @@
std::optional<blender::Set<BMVert *>::Iterator> bm_unique_verts;
std::optional<blender::Set<BMVert *>::Iterator> bm_unique_verts_end;
std::optional<blender::Set<BMVert *>::Iterator> bm_other_verts;
std::optional<blender::Set<BMVert *>::Iterator> bm_other_verts_end;
Think we need to add
#include <optional>
at the top of the file. We shouldn't rely on indirectly included headers.@blender-bot build