Hi! Trying to wrap my head around some basic Fuse concepts. I asked a similar question some time ago in the chat, but it still bothers me :)
This patch outlines my question:
On the left is how I know things from beta. I got the ConstantColorShader, which I assume is loaded in the first ForEach iteration, and then the uniforms (color, world transform) are updated each iteration.
On the right is how I would naivly approach building the same shader with Fuse’s DrawShaderGraph. Here, performance is much worse – which makes sense, because I guess there’s a shader program change each iteration, with 10000 “different” shader programs. Is this assumption correct? If yes, is there a way to somehow define the shader graph somewhere else, and just invoke it in the loop?
fuse_performance_comparison.vl (37.0 KB)
Yes, that’s correct. vvvv shader nodes load a single shader and use it multiple times. Each iteration of the shader graph version creates a new shader, which requires a “context switch” for the GPU, negatively impacting performance. The GPU can call the same shader multiple times quite efficiently, so loading a new shader should be avoided when drawing the same thing multiple times per frame.
Stride uses hash codes for shaders, so it is clear when two shaders are the same. I think fuse also does this, but not for entire shaders.
But in your case, instancing would be the correct solution. but I guess this patch is only for demonstration purposes.
Thanks for the clarification, tonfilm. The patch is indeed only for demonstration.
It just feels like it could be possible to take the ShaderSource from DrawShaderGraph and put it into some kind of “DefineShader” node or something similar (also because there exists such a node in beta)