Repository navigation
startup: bind compute root SRV buffers (srv <i> buf root <param>) at Dispatch - #2953
Conversation
…t Dispatch Record guest compute root SRV addresses and bound bits on the command list in slot 43 (`SetComputeRootShaderResourceView`), clearing them when a different compute root signature is bound in slot 33 or when the list is closed or reset. Extend `ComputeTranslation::Slot` and `load_compute_translation` in `src/startup_stubs/d3d12_compute_dispatch.inl` to parse `srv <i> buf root <param>` emitted by `tools/startup/gfx2hlsl.py` for compute `global_load_dword` loads through a 64-bit root SRV pointer, rejecting descriptor-word entry values that reference a root SRV slot and refusing indirect dispatches that require root SRV bindings. At translated compute `Dispatch` (slot 14), validate that `<param>` in the bound compute root signature has `D3D12_ROOT_PARAMETER_TYPE_SRV`, was set since the compute root signature was bound or reset, has a non-null 4-byte-aligned guest address at a 16-byte-aligned resource offset inside a recording upload allocation or live aliased placed buffer in `COMMON` state, and does not alias an output UAV buffer, then bind a bounded raw `R32_TYPELESS` `ByteAddressBuffer` view from that offset to the end of its backing range. Add `tests/startup_compute_root_srv_dispatch_check.py` (registered in `tests/cmake/startup_compute_root_srv.cmake`) and `docs/experiments/startup-compute-root-srv.md` verifying single- and two-root-SRV dispatches, non-zero byte offsets, bounded out-of-bounds zero reads, refusal controls, and negative controls on WARP and AMD Radeon RX 9070 XT. Refs R0Y00#2618, R0Y00#2274 AI-assisted.
KelboLive
left a comment
There was a problem hiding this comment.
PR #2953 by @consolelogkyo — startup: bind compute root SRV buffers at Dispatch
What works
- Clean separation: command-list tracking in d3d12_xs_device.cpp and manifest consumer in d3d12_compute_dispatch.inl
- Manifest parsing properly enforces sequential order (i == tr.srvs.size()), whole-line match, and param >= 0
- Good invariant: rejects descriptor-word entry values (stride, descword3) that reference root SRV slots
- Dispatch binding verifies root param type, slot-43 set bit, alignment, no-UAV-alias, and guest address validity
- Bound ByteAddressBuffer uses DXGI_FORMAT_R32_TYPELESS capped at backing range (up to 16 MiB)
- Upload tail lookup via list_upload_tail() correctly returns remaining bytes from a split offset
- Test suite covers 1-3 root SRVs, placed/offset upload variations, out-of-bounds zero clamp, canary preservation
- New docs/experiments/startup-compute-root-srv.md ties everything together
Issues
- compute_root_srvs is std::array<u64, 64> — safe but consider a static_assert or runtime guard if D3D12 root parameters can exceed 64 on any platform; the current PR uses up to param indices seen in manifests, which is fine for now.
- list_upload_tail acquires a shared lock and iterates allocations in reverse; the reverse-first-match is correct for contiguous non-overlapping upload allocations but should include a debug assertion that no later allocation has a lower cpu (overlap detection).
- The 16 MiB cap on the bound view is sensible for a safety ceiling, but consider whether any manifests might legitimately reference larger SRV buffers — if so, split the bind or report an error instead of silently truncating.
- At Dispatch, the check for 4-byte-aligned guest address uses address % 4 == 0 — consider using D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT (16) instead, since all raw SRV/UAV views require this alignment anyway.
- Indirect dispatch refusal at load time only checks is_indirect in the manifest; if the runtime later sees an indirect dispatch that was not flagged, no check fires for it. Adding a runtime assert in slot 14 would close that gap.
Recommendations
- Add DEBUG-only cross-check in compute_root_srv_buffer: assert (address % 4 == 0) to make misalignments visible immediately rather than via subtle buffer alias bugs.
- Consider adding a slot-43 guard: before recording, verify the parameter index is within the bound compute root signature parameter count rather than trusting the manifest value.
- In the test, add a case with a root SRV param that is table type (not SRV) to verify the refusal path explicitly.
Overall
Solid, well-scoped follow-on to #2715. The split between command-list tracking and manifest consumer is clean, the invariant checks are thorough, and the test suite gives good coverage including canary boundary preservation. With the alignment guard and indirect-dispatch runtime assert, this would be ready to merge.
R0Y00
left a comment
There was a problem hiding this comment.
Reviewed f76adb7e050a794ed354f485ea16e6da4350e687 in a clean integration build against main e62e3a5e. Both root-SRV readbacks and neighboring compute regressions passed. The fixture exercised a wrong-kind root CBV, +16-byte placed/upload starts, bounded OOB reads, and three negative controls. The binder checks the effective resource offset for 16-byte alignment and rejects root SRVs in indirect dispatch. Windows 11 26200.9974, Release /O2, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Relevant release tests: startup_compute_root_srv_dispatch_(warp|hardware), startup_compute_dispatch_warp, startup_gfx2hlsl_heap_word. Required Windows CI passed.
Summary
Consume
srv <i> buf root <param>in the startup compute manifest loader and bind the recorded guest root SRV buffer at translated computeDispatch(the runtime follow-up to theglobal_load_dwordlowering in #2715, ticketC500-01/031):src/startup_stubs/d3d12_xs_device.cpp): record the guest address and a bound bit per compute root parameter in slot 43 (SetComputeRootShaderResourceView) while a compute root signature is bound; clear them onClose(slot 9),Reset(slot 139), or when slot 33 (SetComputeRootSignature) binds a different compute root signature, while preserving them when re-binding the same root signature.src/startup_stubs/d3d12_compute_dispatch.inl):srv <i> buf root <param>inload_compute_translation(exact whole-line match,param >= 0, sequentiali), reject descriptor-word entry values (stride,descword3) referencing a root SRV slot, and refuse indirect dispatches that require root SRV bindings.Dispatch(slot 14), verify incompute_root_srv_bufferthat<param>in the bound compute root signature hasD3D12_ROOT_PARAMETER_TYPE_SRV, was set by slot 43 since the compute root signature was bound or reset, has a non-null 4-byte-aligned guest address at a 16-byte-aligned offset inside a recording upload allocation (slot 148) or live aliased placed buffer inCOMMONstate (slot 133), and does not alias an output UAV buffer, then bind a bounded rawDXGI_FORMAT_R32_TYPELESSByteAddressBufferview from that offset to the end of its backing range (up to 16 MiB).tests/startup_compute_root_srv_dispatch_check.py(tests/cmake/startup_compute_root_srv.cmake),tests/startup_stream_consumer.cppdispatch-root-srv*modes, anddocs/experiments/startup-compute-root-srv.md.Refs #2618, #2274
Verification
Windows 11 (
10.0.26100), Release preset (MSVC 19.44, Windows SDK10.0.26100.0DXC),X2W_D3D12_DEBUG=1(0D3D12 debug-layer errors) on both Microsoft Basic Render Driver (WARP) (1414:008c, driver10.0.26100.9818) and AMD Radeon RX 9070 XT (1002:7550, driver32.0.32029.2010):startup_compute_root_srv_dispatch_warp: PASS (1- and 2-root-SRV dispatches,+16/+32placed and upload offsets, out-of-bounds zero clamp with neighbor canaries untouched, 16 refusal controls, 3 negative controls)startup_compute_root_srv_dispatch_hardware(RX 9070 XT): PASSAI-assisted.