google / shaderc

A collection of tools, libraries, and tests for Vulkan shader compilation.
Other
1.79k stars 344 forks source link

Allow keeping reflection data in optimized shaders #600

Open kayru opened 5 years ago

kayru commented 5 years ago

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.

jaelpark commented 4 years ago

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.

kayru commented 4 years ago

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.

jaelpark commented 4 years ago

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.

speedym commented 4 years ago

This would be great feature to have, +1.

pdm-pcb commented 1 year ago

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

jjiangweilan commented 1 month ago

any update?