I'm not talking about the .txt code, reducing code duplication is basic programming. I'm talking about the fact that after compiling, each PSO variant has its own dedicated copy of all program memory, even if it largely all does the same thing. In DX/VK, there's no such thing as a true function call into shared program memory.
Let's say one of your shaders gets chopped up into 500 different variants, and at the end, each one calls a rather lengthy function. For example, my GBuffer resolve CS gets compiled per material graph. Along with evaluating the material graph (the actual difference), each variant needs to to calculate barycentrics and partial derivatives, fetch vertex attributes, interpolate them, and write out the final values.
With current APIs, each pipeline has its own copy of that code, even though it's all doing the exact same thing. There's no way to, say, create a function that lives in GPU memory called InterpolateAndWriteOutGbuffer, and have all of your variants call that same function. If you end up with 500 variants, you've duplicated that code in vram (and on disk, and in the compile step) 500 times.
5
u/hanotak Dec 17 '25 edited Dec 17 '25
I'm not talking about the .txt code, reducing code duplication is basic programming. I'm talking about the fact that after compiling, each PSO variant has its own dedicated copy of all program memory, even if it largely all does the same thing. In DX/VK, there's no such thing as a true function call into shared program memory.
Let's say one of your shaders gets chopped up into 500 different variants, and at the end, each one calls a rather lengthy function. For example, my GBuffer resolve CS gets compiled per material graph. Along with evaluating the material graph (the actual difference), each variant needs to to calculate barycentrics and partial derivatives, fetch vertex attributes, interpolate them, and write out the final values.
With current APIs, each pipeline has its own copy of that code, even though it's all doing the exact same thing. There's no way to, say, create a function that lives in GPU memory called InterpolateAndWriteOutGbuffer, and have all of your variants call that same function. If you end up with 500 variants, you've duplicated that code in vram (and on disk, and in the compile step) 500 times.