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] Global struct variables containing only resources fail validation with '-O0' optimization level #3100
Hi, it seems that the fix to #2695 doesn't work when optimization is disabled.
Functional impact
The shader doesn't compile. Cannot use the unoptimized version of the shader for debugging purposes when shader uses the legacy combined texture sampler emulation workaround mentioned in #2695
Compiling with opt. level 0: dxc.exe -T ps_6_0 -E PSMain repro_shader.txt -spirv -O0 results in error:
fatal error: generated SPIR-V is invalid: UniformConstant OpVariable <id> '8[%g_CombinedTextureSampler]' has illegal type.
From Vulkan spec, section 14.5.2:
Variables identified with the UniformConstant storage class are used only as handles to refer to opaque resources. Such variables must be typed as OpTypeImage, OpTypeSampler, OpTypeSampledImage, OpTypeAccelerationStructureNV, OpTypeAccelerationStructureKHR, OpTypeRayQueryProvisionalKHR, or an array of one of these types.
%g_CombinedTextureSampler = OpVariable %_ptr_UniformConstant_sampler2D UniformConstant
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
This is expected I'm afraid. DXC relies on SPIRV-Tools (spirv-opt in particular) to properly handle these structures. What essentially happens is that spirv-opt "flattens" these structures and resolves all references to their members as standalone resources with their own dset/binding. So, sadly as it stands today, disabling spirv-opt will prevent this from working.
I just realized that we can modify the interaction between DXC and spirv-opt such that we run the necessary spirv-opt pass for such cases as part of "legalization" rather than "optimization" (which sounds like a better fit anyway, as without this the result is not valid/legal).
I've been thinking about whether moving this pass earlier in the flow could have any unforeseen consequences, but I can't think of any. Our testing is with pretty lightweight shaders, and they all pass. So I'm going to post a PR for it.
Activity
Disable DXC for shaders which have issues with optimisations off
ehsannas commentedon Nov 12, 2020
This is expected I'm afraid. DXC relies on SPIRV-Tools (
spirv-optin particular) to properly handle these structures. What essentially happens is that spirv-opt "flattens" these structures and resolves all references to their members as standalone resources with their own dset/binding. So, sadly as it stands today, disabling spirv-opt will prevent this from working.ehsannas commentedon Nov 13, 2020
I just realized that we can modify the interaction between DXC and
spirv-optsuch that we run the necessary spirv-opt pass for such cases as part of "legalization" rather than "optimization" (which sounds like a better fit anyway, as without this the result is not valid/legal).I've been thinking about whether moving this pass earlier in the flow could have any unforeseen consequences, but I can't think of any. Our testing is with pretty lightweight shaders, and they all pass. So I'm going to post a PR for it.
ehsannas commentedon Nov 13, 2020
Posted the PR. Lukas Taparauskas (@Dredhog) Please let me know if you face any issues with this. Thanks!
Dredhog commentedon Nov 16, 2020
Great news Ehsan (@ehsannas), I'll try it out!
Dredhog commentedon Nov 17, 2020
Seems to be fixed, didn't find any regressions!
ehsannas commentedon Nov 17, 2020
Awesome! Thanks for checking 👍