Fix: Incorrect BMesh to Mesh attribute copying #104421

Merged
Hans Goudey merged 11 commits from HooglyBoogly/blender:bmesh-mesh-conversion-faster-hot-loops into main 2023-02-13 20:52:14 +01:00
Member

The existing logic to copy BMesh custom data layers to Mesh attribute
arrays was quite complicated, and incorrect in some cases when the
source and destinations didn't have the same layers. The functions
leave a lot to be desired in general, since they have a lot of redundant
complexity that ends up doing the same thing for every element.

The problem in #104154 was that the "rest_position" attribute overwrote
the mesh positions since it has the same type and the positions weren't
copied. This same problem has shown up in boolean attribute conversion
in the past. Other changes fixed some specific cases but I think a larger
change is the only proper solution.

This patch adds preprocessing before looping over all elements to
find the basic information for copying the relevant layers, taking
layer names into account. The preprocessing makes the hot loops
simpler.

In a simple file with a 1 million vertex grid, I observed a 6% improvement
animation playback framerate in edit mode with a simple geometry nodes
modifier, from 5 to 5.3 FPS.

Fixes #104154, #104348

The existing logic to copy `BMesh` custom data layers to `Mesh` attribute arrays was quite complicated, and incorrect in some cases when the source and destinations didn't have the same layers. The functions leave a lot to be desired in general, since they have a lot of redundant complexity that ends up doing the same thing for every element. The problem in #104154 was that the "rest_position" attribute overwrote the mesh positions since it has the same type and the positions weren't copied. This same problem has shown up in boolean attribute conversion in the past. Other changes fixed some specific cases but I think a larger change is the only proper solution. This patch adds preprocessing before looping over all elements to find the basic information for copying the relevant layers, taking layer names into account. The preprocessing makes the hot loops simpler. In a simple file with a 1 million vertex grid, I observed a 6% improvement animation playback framerate in edit mode with a simple geometry nodes modifier, from 5 to 5.3 FPS. Fixes #104154, #104348
Hans Goudey added 4 commits 2023-02-07 19:24:55 +01:00
Hans Goudey requested review from Campbell Barton 2023-02-09 15:43:24 +01:00
Hans Goudey changed title from Mesh: Simplify BMesh Mesh conversion attribute copying to Fix: Incorrect BMesh to Mesh attribute copying 2023-02-09 15:44:26 +01:00
Hans Goudey added 1 commit 2023-02-10 02:33:57 +01:00
Campbell Barton requested changes 2023-02-10 07:42:56 +01:00
Campbell Barton left a comment
Owner

Generally this looks fine, noticed an issue (noted inline).

I'd also really prefer not use get/copy as prefixes - see patch: 3d82ba7ad4 ... it includes some additional code-comments too.

Generally this looks fine, noticed an issue (noted inline). I'd also really prefer not use get/copy as prefixes - see patch: https://projects.blender.org/ideasman42/blender/commit/3d82ba7ad44c87f17f38b075fe4c62b635dbb353 ... it includes some additional code-comments too.
@ -153,0 +177,4 @@
CustomData_get_layer_index_n(&bm_data, type, per_type_index[type]) :
CustomData_get_named_layer_index(&bm_data, type, bm_layer.name);
if (mesh_layer_index == -1) {
infos.append({});

Appending a zeroed MeshToBMeshLayerInfo doesn't seem correct, the BMesh data should still be initialized so even if there is no source layer (where MeshToBMeshLayerInfo::mesh_data is NULL), the CustomData_data_set_default_value needs the bmesh_offset to be set. From what I can tell the other members should be set (type, elem_size) just not the mesh_data.

If I'm misunderstanding the logic, an explanation of why a zeroed MeshToBMeshLayerInfo is needed should be included.


It would also be good to have doc-strings for the functions that generate *LayerInfo vectors noting that Vector<BMeshToMeshLayerInfo> isn't mesh_data.totlayer aligned, were Vector<MeshToBMeshLayerInfo> is bm_data.totlayer aligned, it's not obvious why conversion in one direction needs to account for all layers while conversion in the other direction doesn't.

Appending a zeroed MeshToBMeshLayerInfo doesn't seem correct, the BMesh data should still be initialized so even if there is no source layer (where `MeshToBMeshLayerInfo::mesh_data` is NULL), the `CustomData_data_set_default_value` needs the `bmesh_offset` to be set. From what I can tell the other members should be set (type, elem_size) just not the mesh_data. If I'm misunderstanding the logic, an explanation of why a zeroed `MeshToBMeshLayerInfo` is needed should be included. ---- It would also be good to have doc-strings for the functions that generate `*LayerInfo` vectors noting that `Vector<BMeshToMeshLayerInfo>` isn't `mesh_data.totlayer` aligned, were `Vector<MeshToBMeshLayerInfo>` is `bm_data.totlayer` aligned, it's not obvious why conversion in one direction needs to account for all layers while conversion in the other direction doesn't.
Author
Member

Good point, the logic was bad there, thanks.


I added more comments about why some layers are skipped. I kept BMToMesh instead of BMeshToMesh since it's shorter and keeps statements on a single line which looks so much better.

I also added comments to the copy info struct elements.

Good point, the logic was bad there, thanks. --- I added more comments about why some layers are skipped. I kept `BMToMesh` instead of `BMeshToMesh` since it's shorter and keeps statements on a single line which looks so much better. I also added comments to the copy info struct elements.
Author
Member

I kept BMToMesh instead of BMeshToMesh since it's shorter and keeps statements on a single line which looks so much better.

Oops, this wasn't necessary. I made that change too.

> I kept BMToMesh instead of BMeshToMesh since it's shorter and keeps statements on a single line which looks so much better. Oops, this wasn't necessary. I made that change too.
ideasman42 marked this conversation as resolved
Hans Goudey added 16 commits 2023-02-10 19:05:15 +01:00
a8d951abdd Docs: remove malformed patterns for RNA mapping
The generator now skips these with a warning, they will need to be
corrected in the user manual.

This caused tests/python/bl_rna_manual_reference.py to fail looking
up URL's.
buildbot/vdev-code-daily-coordinator Build done. Details
c2c62c3618
RNA: return a dummy language value when WITH_INTERNATIONAL=OFF
Without this, every access to "language" would warn that the enum
value didn't match a value in the enum items.

This made the bl_rna_manual_reference.py test output practically
unusable.
buildbot/vdev-code-daily-coordinator Build done. Details
b77c82e2bb
Tests: minor updates to make bl_rna_manual_reference more useful
- Avoid flooding the output with every match that succeeds.
- Report patterns listed in the manual that don't match anything in
  Blender.
- Disable external URL lookups, this is too slow.
  Instead use a LOCAL_PREFIX (a local build of the manual)
  or skip the test.
buildbot/vdev-code-daily-coordinator Build done. Details
01480229b1
Cycles: Fix MetalRT checkbox not hooked up to device on AMD
(Follow on from D17043)
On AMD Navi2 devices the MetalRT checkbox was not hooked up properly and had no effect. This patch fixes it.

Co-authored-by: Michael Jones <michael_p_jones@apple.com>
Pull Request #104520
buildbot/vdev-code-daily-coordinator Build done. Details
51ceeb506f
Fix #104026: Click-Drag to select graph editor channels no longer working
Box-Selecting channels in the dope sheet with click-drag was no longer possible as of Blender 3.2

Due to the removal of tweak events the box select operator was always shadowed by the click operator.

Original Phabricator discussion here: https://archive.blender.org/developer/D17065

Use `WM_operator_flag_only_pass_through_on_press` on click operator to fix it

Co-authored-by: Christoph Lendenfeld <chris.lenden@gmail.com>
Pull Request #104505
buildbot/vdev-code-daily-coordinator Build done. Details
5d30c3994e
Sequencer: Don't create undo step when click-select does nothing
When the sequencer is empty (i.e., there are no sequences),
we would have the deselect_all variable set to true called
ED_sequencer_deselect_all to select any existing sequences.

Ref !104453
buildbot/vdev-code-daily-coordinator Build done. Details
dc9f7fe64f
Fix #104514: GPencil merge down layer misses some frames
When merging two gpencil layers, if the destination layer had a keyframe
where the source layer did not, strokes of the previous keyframe
in source layer were lost in that frame.

This happened because the merge operator was looping through
frames of the source layer and appending strokes in the
corresponding destination layer, but never completing
other frames than the ones existing in the source layer.

This patch fixes it by first adding in source layer
all frames that are in destination layer.

Co-authored-by: Amelie Fondevilla <amelie.fondevilla@les-fees-speciales.coop>
Pull Request #104558
buildbot/vdev-code-daily-coordinator Build done. Details
88f9c55f7f
Sculpt: Fix Dyntopo Warnings
Because of T95965, some attributes are stored as generic attributes
in Mesh but have special handling for the conversion to BMesh.

Expose a function to tell whether certain attribute names are handled
specially in the conversion, and refactor the error checking process
to use it. Also check for generic attributes on the face domain which
wasn't done before.

Author: Hans Goudey
Reviewed By: Joseph Eagar

Co-authored-by: Joseph Eagar <joeedh@gmail.com>
Pull Request #104567
buildbot/vdev-code-daily-coordinator Build done. Details
bad2c3b9ef
Geometry Nodes: Experimental option for Volumes
Adds an experimental option under "New Features" in preferences,
which enables visibility of the new Volume Nodes.
Right now this option does nothing but will be used during development.
See #103248

Pull Request #104552
buildbot/vdev-code-daily-coordinator Build done. Details
284cdbb6cf
Cleanup: Use lambdas in mesh mapping callback, remove unused arguments
Using callback functions didn't scale well as more arguments are added.
It got very confusing when to pass tehmarguments weren't always used.
Instead use a `FunctionRef` with indices for arguments. Also remove
unused edge arguments to topology mapping functions.
buildbot/vdev-code-daily-coordinator Build done. Details
0ea15a6fbb
Fix: Inaccessible default for node group image sockets
The type was just skipped when drawing defaults for the image sockets.
923152d180 Geometry Nodes: improve parallelization in Delete/Separate Geometry node
This just adds `threading::parallel_for` and `threading::parallel_invoke` in a few
places where it can be added trivially. The run time of the `separate_geometry`
function changes from 830 ms to 413 ms in my test file.

Pull Request #104563
buildbot/vdev-code-daily-coordinator Build done. Details
fae661a1ab
Revert "Un-ignore modules in .gitmodules configuration"
This reverts commit aab707ab70.

A different solution to the submodule problem is being considered in #104573.
Revert to the previous behavior that developers are familiar with for now.
Hans Goudey requested review from Campbell Barton 2023-02-10 19:06:12 +01:00
Hans Goudey added 2 commits 2023-02-10 19:29:50 +01:00
31e1a927d1 Fix incorrect custom data copy callback
This one was only implemented for a few types, noticeably, not vertex groups.
Campbell Barton approved these changes 2023-02-11 02:59:42 +01:00
Brecht Van Lommel added this to the Modeling project 2023-02-13 09:20:25 +01:00
Hans Goudey added 1 commit 2023-02-13 20:50:34 +01:00
Hans Goudey merged commit dfacaf4f40 into main 2023-02-13 20:52:14 +01:00
Hans Goudey deleted branch bmesh-mesh-conversion-faster-hot-loops 2023-02-13 20:52:16 +01: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#104421
No description provided.