Geometry Nodes: Avoid copying attributes before reordering #117910

Open
Iliya Katushenock wants to merge 13 commits from mod_moder/blender:tmp_sort_elements_del_att into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Instead of creating copy of shared attribute to write sorted data, create new empty domains and copy only needed attributes.

Instead of creating copy of shared attribute to write sorted data, create new empty domains and copy only needed attributes.
Iliya Katushenock added the
Interest
Geometry Nodes
label 2024-02-06 18:04:52 +01:00
Iliya Katushenock added 1 commit 2024-02-06 18:05:03 +01:00
Iliya Katushenock added this to the Nodes & Physics project 2024-02-06 18:05:14 +01:00
Iliya Katushenock requested review from Hans Goudey 2024-02-06 18:05:19 +01:00
Hans Goudey requested changes 2024-02-06 18:47:18 +01:00
Hans Goudey left a comment
Member

Good find. It seems like it would be better not to copy the attributes in the first place. Basically using BKE_mesh_new_nomain and BKE_mesh_copy_parameters instead of BKE_mesh_copy_for_eval.

Good find. It seems like it would be better not to copy the attributes in the first place. Basically using `BKE_mesh_new_nomain` and `BKE_mesh_copy_parameters` instead of `BKE_mesh_copy_for_eval`.
Author
Member

We still need to copy all attributes in other domains.

We still need to copy all attributes in other domains.
Member

Hmm, right. That would make things more complicated. In that case, how about calling CustomData_free(&dst_mesh.vert_data, dst_mesh.verts_num); in the switch cases in reorder_mesh_exec? That would be clearest since this is just a performance optimization.

Hmm, right. That would make things more complicated. In that case, how about calling `CustomData_free(&dst_mesh.vert_data, dst_mesh.verts_num);` in the switch cases in `reorder_mesh_exec`? That would be clearest since this is just a performance optimization.
Author
Member

This need to be done for all supported components.

This need to be done for all supported components.
Author
Member

Im okay with creating empty components, resizing them and coping all attributes in non-target domain... just a lot of hard code with extending components..

Im okay with creating empty components, resizing them and coping all attributes in non-target domain... just a lot of hard code with extending components..
Iliya Katushenock added 3 commits 2024-02-06 21:24:02 +01:00
Iliya Katushenock added 1 commit 2024-02-06 21:25:52 +01:00
Iliya Katushenock added 1 commit 2024-02-06 22:49:09 +01:00
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
2172d75c78
progress
Iliya Katushenock requested review from Hans Goudey 2024-02-06 22:49:58 +01:00
Hans Goudey approved these changes 2024-02-07 16:11:21 +01:00
Hans Goudey left a comment
Member

Okay, this is nice since we can remove clean_unused_attributes.

Okay, this is nice since we can remove `clean_unused_attributes`.
Member

@blender-bot build

@blender-bot build
Hans Goudey changed title from Geometry Nodes: Sort Elements node: Delete old attributes to Geometry Nodes: Avoid copying attributes before reordering 2024-02-07 17:05:48 +01:00
Hans Goudey reviewed 2024-02-07 17:07:16 +01:00
@ -248,3 +301,1 @@
Mesh *dst_mesh = BKE_mesh_copy_for_eval(&src_mesh);
clean_unused_attributes(propagation_info, dst_mesh->attributes_for_write());
reorder_mesh_exec(src_mesh, old_by_new_map, domain, *dst_mesh);
Mesh *dst_mesh = BKE_mesh_new_nomain(
Member

Actually, this will be a regression in some cases, because the builtin attributes and face offsets won't be shared anymore.

Actually, this will be a regression in some cases, because the builtin attributes and face offsets won't be shared anymore.
Author
Member

Face offsets can be shared?
Isn't bke::copy_attributes copy built-in attributes?

Face offsets can be shared? Isn't `bke::copy_attributes` copy built-in attributes?
Member

BKE_mesh_new_nomain creates the attributes. Once they already exist, they won't be shared by copy_attributes. And yes, face offsets can be shared.

`BKE_mesh_new_nomain` creates the attributes. Once they already exist, they won't be shared by `copy_attributes`. And yes, face offsets can be shared.
Author
Member

Sorry for merging with main and changes in the same commit.

Sorry for merging with main and changes in the same commit.
mod_moder marked this conversation as resolved
Iliya Katushenock added 1 commit 2024-02-09 18:48:53 +01:00
Iliya Katushenock requested review from Hans Goudey 2024-02-09 18:51:08 +01:00
Hans Goudey reviewed 2024-02-14 17:17:01 +01:00
@ -244,3 +298,1 @@
Mesh *dst_mesh = BKE_mesh_copy_for_eval(&src_mesh);
clean_unused_attributes(propagation_info, dst_mesh->attributes_for_write());
reorder_mesh_exec(src_mesh, old_by_new_map, domain, *dst_mesh);
Mesh *dst_mesh = BKE_mesh_new_nomain(
Member

This will allocate the builtin attributes only to free them a moment later. I do think it's better to use some function like create_mesh_no_attributes.

This will allocate the builtin attributes only to free them a moment later. I do think it's better to use some function like `create_mesh_no_attributes`.
mod_moder marked this conversation as resolved
Iliya Katushenock added 2 commits 2024-02-16 20:50:05 +01:00
Hans Goudey requested changes 2024-02-16 20:53:54 +01:00
@ -114,0 +144,4 @@
const bke::AttributeAccessor src_attributes = src_mesh.attributes();
bke::MutableAttributeAccessor dst_attributes = dst_mesh.attributes_for_write();
remove_attributes({"position", ".edge_verts", ".corner_vert", ".corner_edge"}, dst_attributes);
Member

Pretty sure this is unnecessary now

Pretty sure this is unnecessary now
mod_moder marked this conversation as resolved
@ -265,3 +318,1 @@
bke::CurvesGeometry dst_curves = bke::CurvesGeometry(src_curves);
clean_unused_attributes(propagation_info, dst_curves.attributes_for_write());
reorder_curves_exec(src_curves, old_by_new_map, dst_curves);
bke::CurvesGeometry dst_curves = bke::CurvesGeometry(src_curves.points_num(),
Member

The same optimization would apply to curves and point clouds

The same optimization would apply to curves and point clouds
Author
Member

Not sure this is actually optimization rather than just new abstraction for future optimizations of how data block with custom data were allocated. But i can add new functions to construct point cloud/curves/ and so now.

Not sure this is actually optimization rather than just new abstraction for future optimizations of how data block with custom data were allocated. But i can add new functions to construct point cloud/curves/ and so now.
Member

It's worth testing then, I think that's reasonable since the goal of this whole PR is optimization.

It's worth testing then, I think that's reasonable since the goal of this whole PR is optimization.
Author
Member

I mean, right now we still allocate custom data for mesh, but delete it just in time. This can be done both in reorder.cc and in mesh.cc, but here is no much change, while this allocation is even did.

I mean, right now we still allocate custom data for mesh, but delete it just in time. This can be done both in `reorder.cc` and in `mesh.cc`, but here is no much change, while this allocation is even did.
mod_moder marked this conversation as resolved
Iliya Katushenock added 2 commits 2024-02-16 22:24:37 +01:00
Iliya Katushenock added 1 commit 2024-02-16 22:33:51 +01:00
Iliya Katushenock requested review from Hans Goudey 2024-02-16 22:33:59 +01:00
Iliya Katushenock added 1 commit 2024-04-07 14:22:02 +02:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u tmp_sort_elements_del_att:mod_moder-tmp_sort_elements_del_att
git checkout mod_moder-tmp_sort_elements_del_att
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 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.

Reference: blender/blender#117910
No description provided.