Raytracing extension/capability not removed when RaytracingAccelerationStructure
is deadstripped
#5358
Labels
RaytracingAccelerationStructure
is deadstripped
#5358
Hi! We rely on a bindless model where we have one HLSL "header" that defines all our bindings, access wrappers for these, and various DXIL/SPIR-V-specific bits to implement it. Unfortunately, as we expose ray-tracing bindings through this header, it currently means that all our shaders get the ray tracing extension and capability even if they don't use any ray tracing operations, and the
RaytracingAccelerationStructure
binding ultimately gets culled.As far as I understand/remember it is up to
spirv-opt
's DCE to get rid of the unreferenced TLAS binding. DXC originally emits the extension and capability when it sees the TLAS type (with a note for needing anotherspirv-opt
pass when the target is aray_pipeline
and not aray_query
shader... not to mentionray_pipeline
shaders containing extra inlineray_query
s):https://github.com/microsoft/DirectXShaderCompiler/blob/a5b0488bc5b20659662bdfdad134c13cb376189b/tools/clang/lib/SPIRV/CapabilityVisitor.cpp#L217-L228
There is also a test in DXC to assert that the capability is not culled even if the binding is not used:
https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/test/CodeGenSPIRV/raytracing.acceleration-structure.hlsl
We observe the same with a simple example shader:
Compile the above with
dxc -E main -T vs_6_6 rt-dce.hlsl -spirv
:Observe
OpCapability RayQueryKHR
andOpExtension "SPV_KHR_ray_query"
even though there are no ray-tracing operations nor bindings in this shader anymore.To confirm that it has been
spirv-opt
that removed the binding, according to https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#optimization all optimization including DCE is offloaded tospirv-opt
, which we can turn off using-fcgl
and observe that the TLAS binding is there, emitted by DXC despite being unused:I am not sure where this is supposed to be fixed, as it sounds like a chicken-and-egg problem that has many different solutions. Maybe a post-pass checking if a certain extension/capability is still in use by any of the other
Op
s? This is needed anyway if the DCE pass were to try and understand that it just removed anOp
which requires an ext/cap... and can only remove the ext/cap when there are no otherOp
s still requiring it which must become wildly complex and error-prone.The text was updated successfully, but these errors were encountered: