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

Merged
consolelogkyo merged 1 commit from upstream-pr/2953 into main 2026-11-27 05:26:45 +00:00
consolelogkyo commented 2026-11-26 23:11:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-26T23:11:39Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518397200 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2953). Originally posted by [consolelogkyo](https://github.com/consolelogkyo) on 2026-11-26T23:11:39Z. --- ## 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`): ```powershell 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.
KelboLive commented 2026-11-27 05:14:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:14:22Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083774169 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2953#pullrequestreview-6083774169). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T05:14:22Z. **Review:** COMMENTED --- 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 commented 2026-11-27 05:26:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:26:38Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083855425 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2953#pullrequestreview-6083855425). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T05:26:38Z. **Review:** APPROVED --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2953
No description provided.