Commit ec8136c
[DX] Add ray tracing state object, SBT, and DispatchRays bring-up
Second per-backend bring-up in the PSO raytracing series (llvm#1268).
Mirrors PR llvm#1273 for D3D12: builds an ID3D12StateObject from the YAML
schema, hands out shader identifiers via ID3D12StateObjectProperties,
lays out the SBT in an upload heap, and routes DispatchRays through
ID3D12GraphicsCommandList4 (same query path the AS build already uses).
DXRayTracingPipelineState derives from DXPipelineState with an
IsRayTracing flag on the base for classof — matching the
VulkanPipelineState pattern. It carries the ID3D12StateObject + a
cached ID3D12StateObjectProperties + a StringMap<const void *> that
resolves each shader EntryPoint or hit-group Name to its 32-byte shader
identifier blob. The identifiers are driver-owned and stay alive for
the Properties COM lifetime, so the PSO keeps Properties alive.
DXShaderBindingTable holds a single upload-heap buffer plus four
pre-built D3D12_DISPATCH_RAYS_DESC ranges (raygen, miss, hit-group,
callable) — `RANGE` for raygen since it's always one record, and
`RANGE_AND_STRIDE` for the others.
createPipelineRT builds a CD3DX12_STATE_OBJECT_DESC with subobjects
for the DXIL library (one export per Shader entry), per-hit-group
subobjects with closest-hit / any-hit / intersection imports, the
pipeline shader config (max payload + max attribute bytes), pipeline
config (max recursion depth), and a global root signature subobject.
The root signature comes from the library's embedded RTS0 part when
present, falling back to the BindingsDesc path (matching the existing
compute / raster pipeline behaviour). Wide strings for the subobject
exports live in a SmallVector that outlives the SODesc, since the
helper classes store pointers into the strings rather than copying.
createShaderBindingTable lays out each entry as
[identifier][LocalRootData][padding-to-stride] with per-region
stride = align(D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES + max-LocalRoot-
Data-in-region, D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT) and
per-region size = align(count * stride,
D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT). The buffer lives in an
upload heap with D3D12_RESOURCE_STATE_GENERIC_READ — PR3 simplification;
a staging copy into a default heap is a follow-up.
dispatchRays queries the underlying CommandListX for
ID3D12GraphicsCommandList4 (matching the AS-build path), binds the
global root signature via SetComputeRootSignature, calls
SetPipelineState1 with the state object, and issues DispatchRays with
a D3D12_DISPATCH_RAYS_DESC populated from the SBT's four ranges plus
the dispatch dimensions. The descriptor heap + descriptor-table bindings
are set up by the existing createComputeCommands helper before the
encoder is created.
createComputeCommands grows an isRayTracing branch at the dispatch
point so it calls dispatchRays instead of dispatch, reusing all of the
descriptor-heap and root-signature wiring. InvocationState carries a
ShaderBindingTable unique_ptr that's only populated for RT pipelines.
executeProgram's isRayTracing branch builds a RayTracingPipelineCreate-
Desc from Pipeline.Shaders / HitGroups / RTConfig, calls
createPipelineRT then createShaderBindingTable, then re-enters
createComputeCommands which dispatches via the new RT path.
raygen-roundtrip.test's XFAIL becomes Clang, Metal — DirectX should
PASS via this implementation on Windows CI (and via Wine + vkd3d-proton
locally on Linux). The Clang token still catches the compile failure
on clang-dxc since [shader("raygeneration")] doesn't yet lower to
either DXIL libraries or SPIR-V on that path.
Locally verified by cross-compiling lib/API/DX/Device.cpp via
`clang++ --target=x86_64-pc-windows-msvc` against the xwin Windows SDK
headers and the project's bundled DirectX-Headers. Runtime verification
is left to Windows CI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 36c89b6 commit ec8136c
2 files changed
Lines changed: 378 additions & 22 deletions
0 commit comments