Mesh: Replace MLoop struct with generic attributes #104424
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#104424
Loading…
Reference in New Issue
No description provided.
Delete Branch "refactor-mesh-corners-generic"
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?
Implements #102359.
Split the
MLoop
struct into two separate integer arrays calledcorner_verts
andcorner_edges
, referring to the vertex each corneris attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with
Mesh
isslightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
Before (Average: 3.7 ms, Min: 3.4 ms)
After (Average: 2.9 ms, Min: 2.6 ms)
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
@blender-bot build
@blender-bot build
Besides the things mentioned, this looks good to me.
Make sure to run geometry nodes tests in a debug build after merging master.
@ -1751,3 +1770,2 @@
if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) {
BLI_assert(POINTER_AS_INT(loop_link) == i);
const int nidx = use_vertices ? int(loops[i].v) : i;
BLI_assert(POINTER_AS_INT(loops) == i);
This does not build in a debug build.
@ -246,2 +242,2 @@
/** Write access to loop data. */
blender::MutableSpan<MLoop> loops_for_write();
blender::Span<int> corner_verts() const;
Some comment here and below would be good.
Generally seems fine - minor issues noted inline.
Testing I ran into two issues though:
Mesh::mloop
pointer is left set after writing a file, shouldn't this be cleared after writing, so the dangling pointer isn't left?Saving and loading the default startup file is crashing too, attached ASAN log.
@ -1665,3 +1683,3 @@
LinkNode *loop_link = lnors_spacearr.lspacearr[i]->loops;
const MLoop *prev_ml = nullptr;
int corner_prev = -1;
*picky*: reverse prefix/suffix, inconsistent with existing naming.
@ -65,3 +65,3 @@
{
const Span<float3> input_positions = input_mesh->vert_positions();
const Span<MLoop> input_loops = input_mesh->loops();
const Span<int> src_corner_verts = input_mesh->corner_verts();
*picky* renames
input_
tosrc_
, a prefix which remains used elsewhere. Useinput_
here too?@ -641,1 +641,3 @@
v2 = mloops[sp->loopstart + (j + 1) % poly.totloop].v;
for (j = 0; j < poly.totloop; j++) {
const int corner = sp->loopstart + j;
const int vert = corner_verts[corner];
*picky*: odd not to call this
vert_i
? (used elsewhere).@ -3740,4 +3741,3 @@
pbvh_face_iter_verts_reserve(fd, poly.totloop);
const MLoop *ml = fd->mloop_ + poly.loopstart;
const int grid_area = fd->subdiv_key_.grid_area;
*minor*: assignment to
int *poly_verts = &fd->corner_verts_[poly.loopstart];
can be kept here.Then
fd->verts[i].i = poly_verts[i];
later on.@ -641,1 +641,3 @@
v2 = mloops[sp->loopstart + (j + 1) % poly.totloop].v;
for (j = 0; j < poly.totloop; j++) {
const int corner = sp->loopstart + j;
const int vert = corner_verts[corner];
I'm trying to use the
vert
name consistently actually (I just didn't want to change some existing variable names). The idea is that the index is all the vertex is really-- a marker in an array used to access various attributes. So it makes sense to use the simplest name for that. It's also shorter, easier to say and read, etc.The
blend_write
calls are run on local copies of the ID data-block, so any changes to themesh
pointer there have no effect elsewhere. That's why we can do things likemesh->runtime = nullptr;
in that function.Hmm, I'm not able to reproduce this here. Is loading and saving the default startup file and loading it again enough to trigger the problem for you?
@blender-bot build
Of course, no issue with this then.
It is:
blender --factory-startup
save, load, save (crash).Edit it's not crashing with ASAN every time, but often enough, at least 1 in 5 times.
Looking into this - it's caused by
BKE_mesh_legacy_convert_uvs_to_struct
callingCustomData_get_layer_named(...)
with anmesh->ldata.totlayer
that has already been set to a fake value byCustomData_blend_write_prepare
(which may not matchmesh->ldata.layers
allocation, causing out of bounds access).It looks like this bug is exposed by this patch (as the UV conversion is running with a potentially invalid totlayer in the
main
branch too).Attached a proof of concept fix, although it would be simpler if all custom-data handling can be done before
CustomData_blend_write_prepare(..)
as doing so seems quite error prone.Issue with layer-writing noted in reply.
Thanks, that makes sense! Should be fixed in the release branch and
main
withde49d18af5
.@blender-bot build
@blender-bot build