You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] Specialization constants don't work if the shader uses the implicit Globals UBO #4542
[SPIR-V] Specialization constants don't work if the shader uses the implicit Globals UBO
Functional impact
Specialization constants get placed into the $Globals UBO as regular constants when the $Globals UBO is present. This is incorrect and makes them practically unusable.
Minimal repro steps
Compile the following shader with dxc.exe -T ps_6_0 -E main -spirv repro_shader.txt:
The SPIR-V should contain a specialization constant named mySpecializationConstant and the $Globals UBO should contain only one member named myGlobal
Actual result
The SPIR-V doesn't contain any specialization constants and it places mySpecializationConstant into the $Globals UBO (see full output in spec_constant_simple_repro.spv.txt):
Also, the compiler produces a warning pointing to the wrong name myGlobal:
spec_constant_simple_repro.txt:1:65: warning: variable 'myGlobal' will be placed in $Globals so initializer ignored
[[ vk::constant_id ( 1 )]] const int mySpecializationConstant = 0;
^
Further technical details
Used DXC from the latest official built release v1.6.2112
Placing the constant myGlobal into a named cbuffer (as is commented out in the repro shader) instead of into the implicit $Globals cbuffer fixes the issue
Activity
chenyangchenyang commentedon Aug 25, 2023
Has Any Update?
s-perron commentedon Jul 26, 2024
Yes, we should fix this. I'll look into it next week.
s-perron commentedon Jul 29, 2024
push constants have the same problem.
We should update this function:
DirectXShaderCompiler/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
Line 301 in 9ef0481
We need to add checks for external variables that would have an early return before this call:
DirectXShaderCompiler/tools/clang/lib/SPIRV/SpirvEmitter.cpp
Line 1949 in 9ef0481
[spirv] Avoid adding spec and push constants to global ubo
[spirv] Avoid adding spec and push constants to global ubo (#6832)
[spirv] Avoid adding spec and push constants to global ubo (microsoft…