shaderc icon indicating copy to clipboard operation
shaderc copied to clipboard

Allow keeping reflection data in optimized shaders

Open kayru opened this issue 5 years ago • 6 comments

When glslc is used to compile shaders with -O flag, the reflection data is always stripped. This may not always be desired.

For example:

#version 450
layout (location = 0) out vec4 fragColor;
layout (set=0, binding = 0) uniform Uniforms { vec4 uniformColor; };
void main() { fragColor = uniformColor; }

> glslangValidator shader.frag && spirv-cross a.spv --reflect produces the desired result (referenced resources and their names are present). > glslc shader.frag -O && spirv-cross a.spv --reflect produces auto-generated symbol names, since real reflection data is not present.

Would it be possible / make sense to add an option to glslc that would keep reflection data even in the optimized spv? Or perhaps it would be worth changing default behavior to be similar to fxc.exe, where reflection data must be explicitly stripped via /Qstrip_reflect or that of glslangValidator?

I understand and expect that reflection with and without optimizations will be different. This is the case for fxc as well, and would not be surprising.

Is this a simple oversight or is there a serious issue that prevents this that I overlooked?

Just in case: this is using glslc in LunarG Vulkan SDK 1.1.106.0.

kayru avatar Apr 29 '19 19:04 kayru

Any response to this?

Edit: looks like -g can be used to preserve the reflection data, even though the description says that it has no effect.

Edit2: alternatively, spirv-opt can be used to do the optimization afterwards.

jaelpark avatar Sep 10 '19 15:09 jaelpark

But -g is for preserving full debug data, which may not always be needed.

I indeed currently first compile a shader without optimizations, extract reflection data and then run spirv-opt explicitly. It would be nice to just streamline this workflow.

kayru avatar Sep 12 '19 08:09 kayru

spirv-opt actually preserves the reflection data during optimization the way glslc also should, so it's possible to swap the last two phases in your workflow. But I agree, there should be no need to invoke spirv-opt separately after the first build step.

jaelpark avatar Sep 12 '19 10:09 jaelpark

This would be great feature to have, +1.

speedym avatar Jul 02 '20 14:07 speedym

+1 as I've arrived here myself, ~3 years on

pdm-pcb avatar Sep 28 '22 03:09 pdm-pcb