Page MenuHome

Eevee preview nodes performance drop
Closed, ResolvedPublicBUG


System Information
Operating system:Windows 10
Graphics card: GeForce GTX 1060

Blender Version
Broken: Blender 2.81 Beta aff6446e064f
Worked: 2.8

Short description of error
Complex shader with large amount of math nodes slow down performance
in 2.8 60 fps
in 2.81 30 fps

Exact steps for others to reproduce the error
Create material with 30 node groups contains 30 math nodes. Set viewport to material preview and watch performance droping

Event Timeline

Danila (Afir) updated the task description. (Show Details)
Germano Cavalcante (mano-wii) lowered the priority of this task from 90 to Low.

I can confirm, but I don't know if the solution is simple.
The problem arose because now all the shader tree is flattened before evaluation.

But the main reason for slowness is because of animated materials (see rB9d59d209).
Blender doesn't differentiate whether a material is animated or not, so the BKE_material_eval simply clears all gpumaterials references with each frame change.
Then DRW_manager needs to recreate the gpumaterial, but first check for similar passes.
And to do this check, it has to go through the entire node tree to create a hash.
And so finds the pass of the original gpumaterial.

Removing this line, the problem is solved:

diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 73c278a0ab6..2e87f04a4bc 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1613,5 +1613,4 @@ void paste_matcopybuf(Main *bmain, Material *ma)
 void BKE_material_eval(struct Depsgraph *depsgraph, Material *material)
   DEG_debug_print_eval(depsgraph, __func__, material->, material);
-  GPU_material_free(&material->gpumaterial);

But then it would bring a problem for the animated materials.
It would be nice to find another solution for animated materials (updating only uniforms for example).

Assigning to @Clément Foucault (fclem), but @Dalai Felinto (dfelinto) and @Sergey Sharybin (sergey) may also have some remarks about it.

Part of the issue here is that material is not supposed to be re-evaluating on playback here.
The reason it was is because of some rather uncommon (in my experience) situation when ID has action but no f-curve. This can be fixed with something like P1149.

But there should be a way to speed up things even for the case when there is a real animation involved.

Not sure about current implementation, but we can calculate hash of every node group from dependency graph (which will happen in nice and threaded environment). We can even do things like constant folding and removal of unconnected nodes from there.

Now, even if that is still by-passed (imagine, that all the groups are connected and such) we can re-use hashes calculated for every group and use those to save on calculating hashes.

I was a bit hasty, the hash is not the problem (obtained from GPU_generate_pass),
but it is GPU_material_from_nodetree in general (it should not even be called again),
especially ntreeGPUMaterialNodes (68,66% of the frame time).

If the material changes then i don't see how you can avoid GPU_material_from_nodetree.

dews any hope this bug will be fixed?

Clément Foucault (fclem) closed this task as Resolved.Feb 5 2020, 2:27 PM
Clément Foucault (fclem) claimed this task.
Clément Foucault (fclem) raised the priority of this task from Low to Normal.
Clément Foucault (fclem) changed the subtype of this task from "Report" to "Bug".

This has been fixed by rB32f0bb052308