Massive slowdown when animating material in a highpoly mesh #55326

Closed
opened 2018-06-04 18:56:07 +02:00 by Dalai Felinto · 19 comments

Blender Version
Broken: bda0175984 (blender2.8 HEAD)

Short description of error
If you keyframe any material nodetree node input the playback performance suffers severely

Exact steps for others to reproduce the error

  • Open wasp_bot.blend from EEVEE sample files.
  • Replace the material of the HEAD object with a simple emission node.

Test playback performance in your system. - It should be fast.

  • Keyframe the emission node color

Re-evaluate playback performance - It should be slow.

Note, performance goes back to normal in the following cases:

  • If you animation data from the node (in dopeshet delete all the channels, instead of the individual keyframes).
  • In mesh edit mode, add a cube and remove the rest of the head.
**Blender Version** Broken: bda017598402 (blender2.8 HEAD) **Short description of error** If you keyframe any material nodetree node input the playback performance suffers severely **Exact steps for others to reproduce the error** * Open `wasp_bot.blend` from EEVEE sample files. * Replace the material of the `HEAD` object with a simple emission node. **Test playback performance in your system.** - It should be fast. * Keyframe the emission node color **Re-evaluate playback performance** - It should be slow. Note, performance goes back to normal in the following cases: * If you animation data from the node (in dopeshet delete all the channels, instead of the individual keyframes). * In mesh edit mode, add a cube and remove the rest of the head.
Author
Owner

Added subscriber: @dfelinto

Added subscriber: @dfelinto

#62176 was marked as duplicate of this issue

#62176 was marked as duplicate of this issue
Sergey Sharybin was assigned by Dalai Felinto 2018-06-04 18:56:59 +02:00
Author
Owner

Added subscribers: @brecht, @fclem

Added subscribers: @brecht, @fclem
Author
Owner

Adding @brecht as a subscriber too in case he wants to have fun profiling it.

Adding @brecht as a subscriber too in case he wants to have fun profiling it.
Author
Owner

I found the problem:

  1. BKE_object_eval_update_shading
  2. BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING)
  3. cache->is_dirty = true
  4. mesh_batch_cache_valid(...) returns false
  5. mesh_batch_cache_get(...) clears and re-init the cache.
I found the problem: 1. BKE_object_eval_update_shading 2. BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING) 3. cache->is_dirty = true 4. mesh_batch_cache_valid(...) returns false 5. mesh_batch_cache_get(...) clears and re-init the cache.
Author
Owner

Also note that the comment on DRW_mesh_batch_cache_dirty about:

/* TODO: This should only update UV and tangent data, and not free the entire cache. */

This is not correct. If we update the UV and tangent data every time the shader changes this will be also super slow since tangent is the batch slowest to calculate.

Also note that the comment on DRW_mesh_batch_cache_dirty about: > /* TODO: This should only update UV and tangent data, and not free the entire cache. */ This is not correct. If we update the UV and tangent data every time the shader changes this will be also super slow since tangent is the batch slowest to calculate.
Author
Owner

This was introduced on 0a57597aff by the way.

This was introduced on 0a57597aff by the way.
Sergey Sharybin removed their assignment 2018-06-05 10:53:50 +02:00
Clément Foucault was assigned by Sergey Sharybin 2018-06-05 10:53:50 +02:00

Added subscriber: @Sergey

Added subscriber: @Sergey

The problem here is that we are missing a more fine grained tagging of the shader nodetree.

As of now, there is no way to know if the user changed a UV channel name in a UV node or just a value of a socket.
The former needs a batch recreation because the needed CD Layers are not the same anymore.

The problem here is that we are missing a more fine grained tagging of the shader nodetree. As of now, there is no way to know if the user changed a UV channel name in a UV node or just a value of a socket. The former needs a batch recreation because the needed CD Layers are not the same anymore.
Clément Foucault removed their assignment 2018-09-19 20:07:13 +02:00
Sergey Sharybin was assigned by Clément Foucault 2018-09-19 20:07:13 +02:00

Adding a simple file to reproduce the issue
shading_update_perf.blend

Just open the file and change emission shader color. It should be has fast as when subdiv level is 0.
It should not call BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING) in this instance. Only modifying Tangent/UV maps nodes (and maybe a few others) should do that.
Please note that 7ad8272952 made it at least twice faster already but does not fix the core of the problem.

Adding a simple file to reproduce the issue [shading_update_perf.blend](https://archive.blender.org/developer/F4755899/shading_update_perf.blend) Just open the file and change emission shader color. It should be has fast as when subdiv level is 0. It should not call BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING) in this instance. Only modifying Tangent/UV maps nodes (and maybe a few others) should do that. Please note that 7ad8272952c6 made it at least twice faster already but does not fix the core of the problem.

I noticed the same kind of slowness when editing material nodes on high poly meshes.

Fine grained dependency graph tagging seems difficult here, I think it would require compiling the GPU shader to know exactly which mesh attributes are affected by the change.

Would it be possible to not discard the GPU buffers on BKE_MESH_BATCH_DIRTY_SHADING, but rather on draw compare if the requested attributes still match the previous ones?

I noticed the same kind of slowness when editing material nodes on high poly meshes. Fine grained dependency graph tagging seems difficult here, I think it would require compiling the GPU shader to know exactly which mesh attributes are affected by the change. Would it be possible to not discard the GPU buffers on BKE_MESH_BATCH_DIRTY_SHADING, but rather on draw compare if the requested attributes still match the previous ones?

Added subscribers: @Rawalanche, @ZedDB

Added subscribers: @Rawalanche, @ZedDB
Sergey Sharybin removed their assignment 2019-04-19 15:49:24 +02:00
Clément Foucault was assigned by Sergey Sharybin 2019-04-19 15:49:24 +02:00

@fclem, we've discussed things here at the studio, and the solution was not related to the dependency graph changes.
Let me know if there is something else i can help you here with.

@fclem, we've discussed things here at the studio, and the solution was not related to the dependency graph changes. Let me know if there is something else i can help you here with.
Clément Foucault removed their assignment 2019-04-19 16:24:42 +02:00
Sergey Sharybin was assigned by Clément Foucault 2019-04-19 16:24:42 +02:00

@Sergey Everything on my end has been fixed.

Only removing the batch cache tagging from the depsgraph is needed to fix this issue. I tried to do it but depsgraph was complaining about some missing link thingamajig.

@Sergey Everything on my end has been fixed. Only removing the batch cache tagging from the depsgraph is needed to fix this issue. I tried to do it but depsgraph was complaining about some missing link thingamajig.

@fclem, just to verify, mind testing P958: (An Untitled Masterwork)

diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 66a3b418f3a..183bc968897 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -369,14 +369,6 @@ void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *o
   BKE_object_eval_transform_final(depsgraph, object);
 }
 
-void BKE_object_eval_update_shading(Depsgraph *depsgraph, Object *object)
-{
-  DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
-  if (object->type == OB_MESH) {
-    BKE_mesh_batch_cache_dirty_tag(object->data, BKE_MESH_BATCH_DIRTY_SHADING);
-  }
-}
-
 void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
 {
   DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index c4a2fc71d1b..a4c269886a3 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -1177,12 +1177,6 @@ void DepsgraphNodeBuilder::build_object_data_geometry(Object *object, bool is_ob
   op_node->set_as_exit();
   /* Materials. */
   if (object->totcol != 0) {
-    if (object->type == OB_MESH) {
-      add_operation_node(&object->id,
-                         NodeType::SHADING,
-                         OperationCode::SHADING,
-                         function_bind(BKE_object_eval_update_shading, _1, object_cow));
-    }
     for (int a = 1; a <= object->totcol; a++) {
       Material *ma = give_current_material(object, a);
       if (ma != NULL) {
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 87a8875f819..8955e6c08eb 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -1904,12 +1904,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
       Material *ma = give_current_material(object, a);
       if (ma != NULL) {
         build_material(ma);
-
-        if (object->type == OB_MESH) {
-          OperationKey material_key(&ma->id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE);
-          OperationKey shading_key(&object->id, NodeType::SHADING, OperationCode::SHADING);
-          add_relation(material_key, shading_key, "Material Update");
-        }
       }
     }
   }
@@ -1923,12 +1917,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
     OperationKey obdata_ubereval_key(
         &object->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL);
     add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval");
-    if (object->totcol != 0 && object->type == OB_MESH) {
-      ComponentKey object_shading_key(&object->id, NodeType::SHADING);
-      Relation *rel = add_relation(
-          obdata_ubereval_key, object_shading_key, "Object Geometry batch Update");
-      rel->flag |= RELATION_FLAG_NO_FLUSH;
-    }
   }
   if (object->type == OB_MBALL) {
     Object *mom = BKE_mball_basis_find(scene_, object);

?

@fclem, just to verify, mind testing [P958: (An Untitled Masterwork)](https://archive.blender.org/developer/P958.txt) ``` diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 66a3b418f3a..183bc968897 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -369,14 +369,6 @@ void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *o BKE_object_eval_transform_final(depsgraph, object); } -void BKE_object_eval_update_shading(Depsgraph *depsgraph, Object *object) -{ - DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); - if (object->type == OB_MESH) { - BKE_mesh_batch_cache_dirty_tag(object->data, BKE_MESH_BATCH_DIRTY_SHADING); - } -} - void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data) { DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index c4a2fc71d1b..a4c269886a3 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -1177,12 +1177,6 @@ void DepsgraphNodeBuilder::build_object_data_geometry(Object *object, bool is_ob op_node->set_as_exit(); /* Materials. */ if (object->totcol != 0) { - if (object->type == OB_MESH) { - add_operation_node(&object->id, - NodeType::SHADING, - OperationCode::SHADING, - function_bind(BKE_object_eval_update_shading, _1, object_cow)); - } for (int a = 1; a <= object->totcol; a++) { Material *ma = give_current_material(object, a); if (ma != NULL) { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 87a8875f819..8955e6c08eb 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -1904,12 +1904,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) Material *ma = give_current_material(object, a); if (ma != NULL) { build_material(ma); - - if (object->type == OB_MESH) { - OperationKey material_key(&ma->id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); - OperationKey shading_key(&object->id, NodeType::SHADING, OperationCode::SHADING); - add_relation(material_key, shading_key, "Material Update"); - } } } } @@ -1923,12 +1917,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) OperationKey obdata_ubereval_key( &object->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL); add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval"); - if (object->totcol != 0 && object->type == OB_MESH) { - ComponentKey object_shading_key(&object->id, NodeType::SHADING); - Relation *rel = add_relation( - obdata_ubereval_key, object_shading_key, "Object Geometry batch Update"); - rel->flag |= RELATION_FLAG_NO_FLUSH; - } } if (object->type == OB_MBALL) { Object *mom = BKE_mball_basis_find(scene_, object); ``` ?

@Sergey I confirm it fixes the slowdown.

@Sergey I confirm it fixes the slowdown.

This issue was referenced by 8955ec6776

This issue was referenced by 8955ec6776db74b3e09f4ad8fb5cd3fd94f1caab

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Contributor

I've just tested latest build and I can confirm it also fixes the #62176

I've just tested latest build and I can confirm it also fixes the #62176
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
6 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#55326
No description provided.