Geometry Nodes drop in performance when adding an output attribute #119938

Closed
opened 2024-03-26 23:29:13 +01:00 by Monaime · 4 comments

System Information
Operating system: Windows 10 Pro
Graphics card: NVIDIA GeForce GTX 1080

Blender Version
Broken: Blender 4.1.0 stable
Worked: Blender 4.1.0 Beta ced066e0c8

Short description of error
In Geometry Nodes there is a drop in performance when adding an output attribute to instances, the instances are comming from a collection (storing a named attribute seems to work fine).

Exact steps for others to reproduce the error

  • Open the attached blend file in blender 4.1.0 stable.
  • Play the animation.
  • Remove the output attribute "Attr" and notice the change in the fps.
  • Open the same file in Blender 4.0 where adding or removing an output attribute does not affect the fps greatly.
**System Information** Operating system: Windows 10 Pro Graphics card: NVIDIA GeForce GTX 1080 **Blender Version** Broken: Blender 4.1.0 stable Worked: Blender 4.1.0 Beta ced066e0c8db **Short description of error** In Geometry Nodes there is a drop in performance when adding an output attribute to instances, the instances are comming from a collection (storing a named attribute seems to work fine). **Exact steps for others to reproduce the error** - Open the attached blend file in blender 4.1.0 stable. - Play the animation. - Remove the output attribute "Attr" and notice the change in the fps. - Open the same file in Blender 4.0 where adding or removing an output attribute does not affect the fps greatly.
Monaime added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-03-26 23:29:14 +01:00
Member

Hi, thanks for the report. Can confirm the regression.

Hi, thanks for the report. Can confirm the regression.
Member

Can confirm, it does also affect 4.2.

While it is this way, 4.1.0 rc will also run faster than 4.2 even when removed that attribute socket. So there must be other changes

Can confirm, it does also affect 4.2. While it is this way, 4.1.0 rc will also run faster than 4.2 even when removed that attribute socket. So there must be other changes
Member

Bisecting points to b020173984
@JacquesLucke ^

Bisecting points to b020173984e4292561a528c5a9eb2a8bffe0122e @JacquesLucke ^
Member

Was looking into this a bit now.

The short term fix is to add a special case to store_output_attributes to handle the case when all output attributes are on the instance domain.

I think it may also be possible to fix this at a deeper level which involves changes to the modifier evaluation system on meshes (possibly simplifications overall though). The regression basically happened because now the evaluated instanced meshes are new meshes on every frame, instead of the same mesh all the time (note that each cube in the file is a separate mesh data block, they are not instances of the same mesh). Therefor, the drawing cache has to be recreated for every mesh on every frame. Previously, the drawing cache was only created once per mesh.

This happens for a combination of reasons, but at the core, the mesh copies are created in modifier_modify_mesh_and_geometry_set by calling ensure_owns_direct_data. A copy is made, because the cube meshes are currently not owned but GeometryOwnershipType::Editable/ReadOnly. This is because the evaluated mesh ownership is not using GeometrySet yet (see comments in mesh_build_data).

I believe the situation can be improved by changing mesh object evaluation like so:

  • Make the object.runtime.geometry_set_eval the owner of the evaluated mesh (this likely has some other implicitions that need to be worked out).
  • For the case of having multiple objects that share the some mesh (linked duplicates), we can change it so that evaluated MeshComponent is shared between the evaluated objects, instead of sharing the Mesh itself in case there are no modifiers. This may be a prerequisite for the change mentioned above.

This hack also fixes the regression (but breaks other stuff):

diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 55fda2dcba8..73a6400dc17 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -1302,7 +1302,7 @@ static void mesh_build_data(Depsgraph *depsgraph,
                       need_mapping,
                       dataMask,
                       true,
-                      true,
+                      false,
                       &mesh_deform_eval,
                       &mesh_eval,
                       &geometry_set_eval);
@@ -1315,11 +1315,11 @@ static void mesh_build_data(Depsgraph *depsgraph,
    * the final result might be freed prior to object). */
   Mesh *mesh = (Mesh *)ob->data;
   const bool is_mesh_eval_owned = (mesh_eval != mesh->runtime->mesh_eval);
-  BKE_object_eval_assign_data(ob, &mesh_eval->id, is_mesh_eval_owned);
+  BKE_object_eval_assign_data(ob, &mesh_eval->id, false);
 
   /* Add the final mesh as a non-owning component to the geometry set. */
   MeshComponent &mesh_component = geometry_set_eval->get_component_for_write<MeshComponent>();
-  mesh_component.replace(mesh_eval, GeometryOwnershipType::Editable);
+  mesh_component.replace(mesh_eval, GeometryOwnershipType::Owned);
   ob->runtime->geometry_set_eval = geometry_set_eval;
 
   ob->runtime->mesh_deform_eval = mesh_deform_eval;

Was looking into this a bit now. The short term fix is to add a special case to `store_output_attributes` to handle the case when all output attributes are on the instance domain. I think it may also be possible to fix this at a deeper level which involves changes to the modifier evaluation system on meshes (possibly simplifications overall though). The regression basically happened because now the evaluated instanced meshes are new meshes on every frame, instead of the same mesh all the time (note that each cube in the file is a separate mesh data block, they are not instances of the same mesh). Therefor, the drawing cache has to be recreated for every mesh on every frame. Previously, the drawing cache was only created once per mesh. This happens for a combination of reasons, but at the core, the mesh copies are created in `modifier_modify_mesh_and_geometry_set` by calling `ensure_owns_direct_data`. A copy is made, because the cube meshes are currently not owned but `GeometryOwnershipType::Editable/ReadOnly`. This is because the evaluated mesh ownership is not using `GeometrySet` yet (see comments in `mesh_build_data`). I believe the situation can be improved by changing mesh object evaluation like so: * Make the `object.runtime.geometry_set_eval` the owner of the evaluated mesh (this likely has some other implicitions that need to be worked out). * For the case of having multiple objects that share the some mesh (linked duplicates), we can change it so that evaluated `MeshComponent` is shared between the evaluated objects, instead of sharing the `Mesh` itself in case there are no modifiers. This may be a prerequisite for the change mentioned above. ----- This hack also fixes the regression (but breaks other stuff): ```diff diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 55fda2dcba8..73a6400dc17 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -1302,7 +1302,7 @@ static void mesh_build_data(Depsgraph *depsgraph, need_mapping, dataMask, true, - true, + false, &mesh_deform_eval, &mesh_eval, &geometry_set_eval); @@ -1315,11 +1315,11 @@ static void mesh_build_data(Depsgraph *depsgraph, * the final result might be freed prior to object). */ Mesh *mesh = (Mesh *)ob->data; const bool is_mesh_eval_owned = (mesh_eval != mesh->runtime->mesh_eval); - BKE_object_eval_assign_data(ob, &mesh_eval->id, is_mesh_eval_owned); + BKE_object_eval_assign_data(ob, &mesh_eval->id, false); /* Add the final mesh as a non-owning component to the geometry set. */ MeshComponent &mesh_component = geometry_set_eval->get_component_for_write<MeshComponent>(); - mesh_component.replace(mesh_eval, GeometryOwnershipType::Editable); + mesh_component.replace(mesh_eval, GeometryOwnershipType::Owned); ob->runtime->geometry_set_eval = geometry_set_eval; ob->runtime->mesh_deform_eval = mesh_deform_eval; ```
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-04-02 17:51:39 +02:00
Sign in to join this conversation.
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
4 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#119938
No description provided.