microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Emit `OpacityMicromapIdKHR` execution mode for OMM-enabled `RayQuery`
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
SPIR-V's equivalent for DXIL's RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS on inline ray traces seems to be an execution mode with OpacityMicromapIdKHR [^1] referencing an OpSpecConstantTrue (default-true spec constant). Is this something DXC can emit for us? It seems to be cumbersome to use https://github.com/microsoft/DirectXShaderCompiler/wiki/Inline-SPIR%E2%80%90V to emit a vk::ext_execution_mode_id(OpacityMicromapIdKHR, true) via a custom wrapper while still keeping the original constant working for DXIL.
[^1]: Using https://github.com/KhronosGroup/Vulkan-Docs/issues/2810 to clarify that this exclusively applies to inline ray tracing, while ray tracing pipelines use the VK_PIPELINE_CREATE_RAY_TRACING_OPACITY_MICROMAP_BIT_KHR host flag. Ray tracing pipeline shaders which perform inline ray queries with OMMs do need the execution mode though.
And there's a further limitation linked there:
If using a
lib_6_xtarget profile with multiple entry points, it will only be applied to one of them.
We have multiple entrypoints for RTPSO shaders that all use ray queries, so a possible workaround would need to apply to all of them.
And note that any shader containing OpExtension SPV_KHR_opacity_micromap in current DXC does not get properly deadstripped until the SPIRV-Tools submodule is updated to include https://github.com/KhronosGroup/SPIRV-Tools/pull/6833.
Attributes on constants
As an aside I'd been quite happy to learn that extension and capability attributes can be applied on constants like so:
[[vk::ext_extension("SPV_KHR_opacity_micromap")]]
[[vk::ext_capability(RayTracingOpacityMicromapExecutionModeKHR)]]
static const uint OpacityMicromapIdKHR = 6031;
But these are emitted in the final SPIR-V even if the constant itself is clearly never referenced: https://godbolt.org/z/xc3aPrvad
Is that intended?
Actual Behavior
No OpExecutionModeId OpacityMicromapIdKHR %true is emitted for RayQuery shaders with RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS.
Likely complications live in the fact that this execution mode can be a spec constant, likely mimicking the host-settable behaviour for RTPSOs via VK_PIPELINE_CREATE_RAY_TRACING_OPACITY_MICROMAP_BIT_KHR. Unlike DXIL, SPIR-V users might want the ability to actually configure the spec constant instead of hardcoding it based on the presence of RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS?
Environment
- DXC version: https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.10.2605.37
- Host Operating System: any
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name implementation files or tests. Start by tracing DXC's SPIR-V lowering for RayQuery and RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS, then inspect generated SPIR-V for OpExecutionModeId OpacityMicromapIdKHR and handling of multiple entry points and unused extension attributes. Done means the intended behavior is implemented and covered for the described cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100