Struct of Arrays Refactor for Mesh Face Corners #102359
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#102359
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
The Change
MLoop
currently contains the index of the vertex at each face corner, and the index of the edge that connects to the next vertex in the face.The vertex indices are always necessary, they're the ground truth of the face topology. On the other hand, the edge indices aren't necessary for much of the geometry processing in Blender.
This task describes splitting
MLoop
into two separate arrays, usually accessed like:Benefits
Memory Bandwidth
Except when building meshes from scratch, the edge and vertex indices are very rarely used at the same time. However, because they are stored together, they both have to be read from memory. Currently
MLoop
uses 32 MB of memory for a mesh with 1 million quads. If an algorithm need to know the vertex at each face corner, which is very common, it has to read all of that. With this change, we could skip reading 16 MB.Code Simplicity
In the end, many algorithms boil down to simple operations with indices. We have many existing utilities for processing basic arrays with indices. Using a special type that combines two indices makes it impossible to use those utilities directly. If the indices of vertices in a face are all stored contiguously then code doesn't have to know about
MLoop
or meshes at all to process that data.This simplicity makes more performance improvements possible, since efforts improving performance will affect more areas and common patterns will be more visible.
Example: Iterating over edges in faces
Example: Collecting vertex face indices
Example: Accessing both edges and vertices
This is the worst case for the new design, but it's still pretty much the same in the end.
Example: Geometry Nodes Input
The implementation of the "Vertex of Corner" input node can output a span directly, giving decreased overhead for most access. This shows how the new method works better for areas that are designed around a SoA paradigm.
Optional Edges
For many meshes it isn't necessary to store edges if they aren't used. If we take this change further, we could skip storing the second edge index array and skip storing
MEdge
completely. That would save 30 MB of memory on a 1 million face grid, and save extra processing to find loose edges, etc.That change isn't part of this task, but it's just here to show what possibilities this change allows.
Discussion
Naming
The arrays can be called
corner_vert
andcorner_edge
, moving away from the "loop" naming completely."Loops" have always been a confusing name for people learning Blender code. I think moving away from that word would make the code much friendlier and more obvious. The "corner vert" name just refers to the index of the vertex at each corner. "Corner edges" are the index of the next edge around the face at each corner. Reusing the "corner" prefix is similar to the naming from other mesh domains (like "vert normals") and using the other domain as the next part of the domain makes the mapping clear.
One possible downside is that it's not clear enough that "corner edge" refers to the next edge at a face corner. But that's still much easier than learning what
loop.e
means.Store as Attributes
These arrays should be stored as attributes directly, rather than a special custom data type. This follows the simple design of separating storage data type from usage semantics, and allows simpler internal data-processing. With the
.
name prefix, we can avoid exposing users to the low-level attributes directly but keep them available as part of the attribute API or other opt-in UI in the future.Implementation
#104424
MLoop.e
andMLoop.v
are used in hundreds of places, so this is a large change-- maybe one of the bigger changes in the whole mesh refactor.However, none of the individual changes are complex, they just cover a lot of areas.
Python API
The current Python API can remain, just like the rest of the changes in the SoA refactor (parent task). It may become slightly less efficient, so we may want to add a new API that aligns better with the internal data.
Eventually the old API could be deprecated, but there is no real reason to do that any time soon.
BMesh
BMesh also has the
BMLoop
type. I do not propose changing that here, since the reason for the change is performance in SoA code, which doesn't work well with BMesh anyway. Naming could be changed to align better with the newMesh
naming, but that would mostly be a separate cleanup change.