Mesh: Cache loose vertices #105567

Merged
Hans Goudey merged 29 commits from HooglyBoogly/blender:mesh-loose-vert-cache into main 2023-04-22 13:46:23 +02:00
Member

Similar to the cache of loose edges added in 1ea169d90e,
cache the number of loose vertices and which are loose in a bit map.
This can save significant time when drawing large meshes in the
viewport, because recalculations can be avoided when the data doesn't
change, and because many geometry nodes set the loose geometry caches
eagerly when the meshes contain no loose elements.

There are two types of loose vertices:

  1. Vertices not used by any edges or faces
    Mesh.loose_verts()
  2. Vertices not used by any faces (may be used by loose edges)
    Mesh.verts_no_face()

Because both are used by Blender in various places, because the cost
is only a bit per vertex (or constant at best) and because of design
consistency, we cache both types of loose elements. The bit maps will
only be allocated when they're actually used, but they are already
accessed in a few important places:

  • Attribute domain interpolation
  • Subdivision surface modifier
  • Viewport drawing

Just the skipping viewport drawing calculation after certain geometry
nodes setups can have a large impact. Here is the time taken by
viewport loose geometry extraction before and after the change:

  • 4 million vertex grid node: 28 ms to 0 ms
  • Large molecular nodes setup (curve to mesh node): 104 ms to 0 ms
  • Realize instances with 1 million cubes: 131 ms to 0 ms
Similar to the cache of loose edges added in 1ea169d90e39647eac72, cache the number of loose vertices and which are loose in a bit map. This can save significant time when drawing large meshes in the viewport, because recalculations can be avoided when the data doesn't change, and because many geometry nodes set the loose geometry caches eagerly when the meshes contain no loose elements. There are two types of loose vertices: 1. Vertices not used by any edges or faces `Mesh.loose_verts()` 2. Vertices not used by any faces (may be used by loose edges) `Mesh.verts_no_face()` Because both are used by Blender in various places, because the cost is only a bit per vertex (or constant at best) and because of design consistency, we cache both types of loose elements. The bit maps will only be allocated when they're actually used, but they are already accessed in a few important places: - Attribute domain interpolation - Subdivision surface modifier - Viewport drawing Just the skipping viewport drawing calculation after certain geometry nodes setups can have a large impact. Here is the time taken by viewport loose geometry extraction before and after the change: - 4 million vertex grid node: 28 ms to 0 ms - Large molecular nodes setup (curve to mesh node): 104 ms to 0 ms - Realize instances with 1 million cubes: 131 ms to 0 ms
Hans Goudey added 1 commit 2023-03-08 15:31:38 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
dd72389a4f
Mesh: Cache loose vertices
Similar to the cache of loose edges added in 1ea169d90e, cache
the number of loose vertices and which are loose in a bit map. This
can save significant time when drawing large meshes in the viewport.
Hans Goudey added this to the Modeling project 2023-03-08 15:32:54 +01:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 4 commits 2023-03-08 19:09:23 +01:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey changed title from Mesh: Cache loose vertices to WIP: Mesh: Cache loose vertices 2023-03-08 21:36:48 +01:00
Hans Goudey added 2 commits 2023-03-22 16:42:01 +01:00
Hans Goudey added 1 commit 2023-03-22 17:43:31 +01:00
Hans Goudey added 2 commits 2023-03-27 13:23:05 +02:00
Hans Goudey added 3 commits 2023-03-28 00:29:50 +02:00
Hans Goudey added 1 commit 2023-03-28 00:58:05 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
c8db4fa453
Cleanup
Hans Goudey changed title from WIP: Mesh: Cache loose vertices to Mesh: Cache loose vertices 2023-03-28 00:58:27 +02:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Jacques Lucke 2023-03-28 01:14:54 +02:00
Hans Goudey added this to the 3.6 LTS milestone 2023-03-30 16:31:07 +02:00
Hans Goudey added 1 commit 2023-03-31 17:57:30 +02:00
Hans Goudey added 1 commit 2023-04-04 22:27:14 +02:00
Hans Goudey added 4 commits 2023-04-14 18:53:04 +02:00
Hans Goudey added 1 commit 2023-04-16 22:10:02 +02:00
Hans Goudey added 2 commits 2023-04-17 14:10:59 +02:00
Jacques Lucke requested changes 2023-04-21 13:02:03 +02:00
@ -1145,3 +1145,1 @@
static BitVector<> loose_verts_map_get(const Span<blender::int2> edges,
int verts_num,
int *r_loose_vert_num)
static BitVector<> loose_verts_map_get(const Mesh &mesh, int *r_loose_vert_num)
Member

Does this intentionally return by value instead of const-references? Same below.

Does this intentionally return by value instead of const-references? Same below.
HooglyBoogly marked this conversation as resolved
@ -307,6 +317,9 @@ typedef struct Mesh {
* cache dirty. If the mesh was changed first, the relevant dirty tags should be called first.
*/
void loose_edges_tag_none() const;
void loose_verts_edge_tag_none() const;
Member

Why are these const? Aren't these function you should call after changing the topology when having non-const access to the mesh? BKE_mesh_tag_positions_changed is non-const as well.

Why are these `const`? Aren't these function you should call after changing the topology when having non-const access to the mesh? `BKE_mesh_tag_positions_changed` is non-const as well.
Author
Member

They're const because setting them doesn't change the logical state of the mesh. Let's say you're doing a mostly unrelated calculation and discover that there are no loose vertices, these could be called to pass that information elsewhere without changing the mesh.

BKE_mesh_tag_positions_changed is different, it means "I've changed the positions, the mesh is now different than it was".

They're const because setting them doesn't change the logical state of the mesh. Let's say you're doing a mostly unrelated calculation and discover that there are no loose vertices, these could be called to pass that information elsewhere without changing the mesh. `BKE_mesh_tag_positions_changed` is different, it means "I've changed the positions, the mesh is now different than it was".
@ -308,2 +318,4 @@
*/
void loose_edges_tag_none() const;
void loose_verts_edge_tag_none() const;
void loose_verts_face_tag_none() const;
Member

It feels a bit like these tag functions are redundant. Shouldn't tag_no_loose_edges and tag_no_loose_verts methods be enough?

It feels a bit like these `tag` functions are redundant. Shouldn't `tag_no_loose_edges` and `tag_no_loose_verts` methods be enough?
Author
Member

Generally they're used in similar situations, but not always. For example, the realize instances node:

  if (all_meshes_info.no_loose_verts_edge_hint) {
    dst_mesh->loose_verts_edge_tag_none();
  }
  if (all_meshes_info.no_loose_verts_face_hint) {
    dst_mesh->loose_verts_face_tag_none();
  }
Generally they're used in similar situations, but not always. For example, the realize instances node: ``` if (all_meshes_info.no_loose_verts_edge_hint) { dst_mesh->loose_verts_edge_tag_none(); } if (all_meshes_info.no_loose_verts_face_hint) { dst_mesh->loose_verts_face_tag_none(); } ```
Hans Goudey requested review from Jacques Lucke 2023-04-21 14:50:50 +02:00
Hans Goudey added 3 commits 2023-04-21 16:07:23 +02:00
Hans Goudey added 1 commit 2023-04-21 16:13:59 +02:00
Hans Goudey added 1 commit 2023-04-21 17:23:00 +02:00
41de436fcb WIP: Progress with naming and removing redundancy
tag_verts_no_face_none is actually not redundant with
loose_edges_tag_none though, since it also contains loose verts.
Hans Goudey added 1 commit 2023-04-21 20:23:23 +02:00
Jacques Lucke approved these changes 2023-04-22 11:45:41 +02:00
Hans Goudey merged commit 8e967cfeaf into main 2023-04-22 13:46:23 +02:00
Hans Goudey deleted branch mesh-loose-vert-cache 2023-04-22 13:46:24 +02:00
Sign in to join this conversation.
No reviewers
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
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105567
No description provided.