Skip to content

startup: bind compute root SRV buffers (srv <i> buf root <param>) at Dispatch - #2953

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
consolelogkyo:feat/startup-compute-root-srv
Nov 27, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
consolelogkyo:feat/startup-compute-root-srv

Conversation

@consolelogkyo

Copy link
Copy Markdown
Contributor

Summary

Consume srv <i> buf root <param> in the startup compute manifest loader and bind the recorded guest root SRV buffer at translated compute Dispatch (the runtime follow-up to the global_load_dword lowering in #2715, ticket C500-01/031):

  • Command-list tracking (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 on Close (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.
  • Manifest consumer & Dispatch binding (src/startup_stubs/d3d12_compute_dispatch.inl):
    • Parse srv <i> buf root <param> in load_compute_translation (exact whole-line match, param >= 0, sequential i), reject descriptor-word entry values (stride, descword3) referencing a root SRV slot, and refuse indirect dispatches that require root SRV bindings.
    • At translated Dispatch (slot 14), verify in compute_root_srv_buffer that <param> in the bound compute root signature has D3D12_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 in COMMON state (slot 133), and does not alias an output UAV buffer, then bind a bounded raw DXGI_FORMAT_R32_TYPELESS ByteAddressBuffer view from that offset to the end of its backing range (up to 16 MiB).
  • Source-built tests & docs: add tests/startup_compute_root_srv_dispatch_check.py (tests/cmake/startup_compute_root_srv.cmake), tests/startup_stream_consumer.cpp dispatch-root-srv* modes, and docs/experiments/startup-compute-root-srv.md.

Refs #2618, #2274

Verification

Windows 11 (10.0.26100), Release preset (MSVC 19.44, Windows SDK 10.0.26100.0 DXC), X2W_D3D12_DEBUG=1 (0 D3D12 debug-layer errors) on both Microsoft Basic Render Driver (WARP) (1414:008c, driver 10.0.26100.9818) and AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010):

cmake --build --preset release --target d3d12_xs_shim startup_stream_consumer
ctest --preset release -j1 --no-tests=error -R "^(startup_compute_root_srv_dispatch_(warp|hardware)|startup_tools_lint|docs_links|bidi_controls|startup_compute_root|startup_list_dispatch_native_.*|startup_compute_binding_trace_.*|startup_compute_global_load_.*|startup_compute_dispatch_(warp|hardware)|startup_compute_dispatch_input_(warp|hardware)|startup_compute_dispatch_entry_(warp|hardware)|startup_compute_dispatch_heap_(warp|hardware))$" --output-on-failure
  • startup_compute_root_srv_dispatch_warp: PASS (1- and 2-root-SRV dispatches, +16 / +32 placed 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): PASS
  • Full 21-test compute dispatch + hygiene regression suite: 21/21 PASS

AI-assisted.

…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 KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 215934b into R0Y00:main Nov 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants