Page MenuHome

Massive slowdown when animating material in a highpoly mesh
Closed, ResolvedPublic


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.

Event Timeline

Dalai Felinto (dfelinto) lowered the priority of this task from Needs Triage by Developer to Confirmed, Medium.
Dalai Felinto (dfelinto) created this task.

Adding @Brecht Van Lommel (brecht) as a subscriber too in case he wants to have fun profiling it.

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.

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.

This was introduced on rB0a57597aff8c by the way.

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.

Adding a simple file to reproduce the issue

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?

Brecht Van Lommel (brecht) raised the priority of this task from Confirmed, Medium to Confirmed, High.Apr 1 2019, 1:50 PM

@Clément Foucault (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.

@Sergey Sharybin (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.

@Clément Foucault (fclem), just to verify, mind testing

1diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
2index 66a3b418f3a..183bc968897 100644
3--- a/source/blender/blenkernel/intern/object_update.c
4+++ b/source/blender/blenkernel/intern/object_update.c
5@@ -369,14 +369,6 @@ void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *o
6 BKE_object_eval_transform_final(depsgraph, object);
7 }
9-void BKE_object_eval_update_shading(Depsgraph *depsgraph, Object *object)
11- DEG_debug_print_eval(depsgraph, __func__, object->, object);
12- if (object->type == OB_MESH) {
13- BKE_mesh_batch_cache_dirty_tag(object->data, BKE_MESH_BATCH_DIRTY_SHADING);
14- }
17 void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
18 {
19 DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
20diff --git a/source/blender/depsgraph/intern/builder/ b/source/blender/depsgraph/intern/builder/
21index c4a2fc71d1b..a4c269886a3 100644
22--- a/source/blender/depsgraph/intern/builder/
23+++ b/source/blender/depsgraph/intern/builder/
24@@ -1177,12 +1177,6 @@ void DepsgraphNodeBuilder::build_object_data_geometry(Object *object, bool is_ob
25 op_node->set_as_exit();
26 /* Materials. */
27 if (object->totcol != 0) {
28- if (object->type == OB_MESH) {
29- add_operation_node(&object->id,
30- NodeType::SHADING,
31- OperationCode::SHADING,
32- function_bind(BKE_object_eval_update_shading, _1, object_cow));
33- }
34 for (int a = 1; a <= object->totcol; a++) {
35 Material *ma = give_current_material(object, a);
36 if (ma != NULL) {
37diff --git a/source/blender/depsgraph/intern/builder/ b/source/blender/depsgraph/intern/builder/
38index 87a8875f819..8955e6c08eb 100644
39--- a/source/blender/depsgraph/intern/builder/
40+++ b/source/blender/depsgraph/intern/builder/
41@@ -1904,12 +1904,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
42 Material *ma = give_current_material(object, a);
43 if (ma != NULL) {
44 build_material(ma);
46- if (object->type == OB_MESH) {
47- OperationKey material_key(&ma->id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE);
48- OperationKey shading_key(&object->id, NodeType::SHADING, OperationCode::SHADING);
49- add_relation(material_key, shading_key, "Material Update");
50- }
51 }
52 }
53 }
54@@ -1923,12 +1917,6 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
55 OperationKey obdata_ubereval_key(
56 &object->id, NodeType::GEOMETRY, OperationCode::GEOMETRY_EVAL);
57 add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval");
58- if (object->totcol != 0 && object->type == OB_MESH) {
59- ComponentKey object_shading_key(&object->id, NodeType::SHADING);
60- Relation *rel = add_relation(
61- obdata_ubereval_key, object_shading_key, "Object Geometry batch Update");
62- rel->flag |= RELATION_FLAG_NO_FLUSH;
63- }
64 }
65 if (object->type == OB_MBALL) {
66 Object *mom = BKE_mball_basis_find(scene_, object);

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