DiligentGraphics / DiligentSamples

Sample projects demonstrating the usage of Diligent Engine
http://diligentgraphics.com/diligent-engine/samples/
Apache License 2.0
320 stars 80 forks source link

Add hint in tutorials that unused cbuffers in shaders are not reflected (i.e. GetStaticVariableByName,.. does not work) #129

Open simsevi opened 5 months ago

simsevi commented 5 months ago

One possible reason for this issue is that the HLSL compiler may optimize away unused cbuffer declarations, causing the shader reflection to overlook these buffers. As a result, when calling GetStaticVariableBy..., it returns a nullptr, and invoking ->Set subsequently triggers an exception. This is probably common knowledge for some but it might be helpful :) I am not sure if the same is true for other variable types.

TheMostDiligent commented 5 months ago

Same is true for any shader resource - if you declare it but not use, the compiler will optimize it out as if it was not declared.