Skip to content

d3d12: forward compute root bindings and Dispatch on console lists - #2491

Open
Holastor wants to merge 1 commit into
R0Y00:mainfrom
Holastor:d3d12/compute-dispatch-root-bindings
Open

Holastor wants to merge 1 commit into
R0Y00:mainfrom
Holastor:d3d12/compute-dispatch-root-bindings

Conversation

@Holastor

@Holastor Holastor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rebased onto current main and updated to match the existing shared dispatch and compute root infrastructure (#1974, #1975, #2532):

  • Root Constants (slots 37 / 39): Extended x2w_root_constants::Store to support capacity up to 32 words per parameter for native slot 86 roots while preserving the 8-word default for translated compute. Forward valid 32-bit root constants to the desktop command list when desktop_compute_root is bound.
  • Root UAV (slot 45): Implemented list_compute_root_uav with placed buffer subrange offset translation to desktop GPU virtual addresses, routed through bind_compute_root_view so restore_compute_root replays it after shim passes.
  • Dispatch (slot 14) & Root Signature (slot 33): Kept main's canonical list_dispatch with decide_dispatch validation, updating parameter forwarding classification in Device::CreateRootSignature and checking that all declared compute parameters (SRV, UAV, constants) are bound prior to forwarding.
  • Fixture: Added synthetic fixture tests/startup_compute_dispatch.cpp (startup_compute_dispatch_root_<backend>) testing WARP and hardware backends, verifying 32-word native root constants with range checking, placed buffer subrange UAV dispatch, sentinel preservation at byte 0, readback of 57 at byte 256, and zero debug layer errors.

Verification & Evidence

Unit tests and linters:

python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check upstream/main..HEAD
  • Markdown links: 27 files, 541 links checked, all passed.
  • Bidirectional controls: 2035 tracked files checked, no issues.
  • Git whitespace/diff check: clean.

dev preset test results:

ctest --preset dev --no-tests=error -R '^(startup_root_constant_store|startup_compute_dispatch_root|startup_list_dispatch)' -V
The following tests passed:
	startup_root_constant_store
	startup_compute_dispatch_root_warp
	startup_compute_dispatch_root_hardware
	startup_list_dispatch
	startup_list_dispatch_no-limit_control
	startup_list_dispatch_no-state_control
	startup_list_dispatch_no-root-args_control
	startup_list_dispatch_no-pairing_control
	startup_list_dispatch_no-bound_control
	startup_list_dispatch_native_warp
	startup_list_dispatch_native_hardware
	startup_list_dispatch_native_skip_srv_warp_control

100% tests passed, 0 tests failed out of 12

release preset test results:

ctest --preset release --no-tests=error -R '^(startup_root_constant_store|startup_compute_dispatch_root)' -V
The following tests passed:
	startup_root_constant_store
	startup_compute_dispatch_root_warp
	startup_compute_dispatch_root_hardware

100% tests passed, 0 tests failed out of 3
  • WARP: readback 57, sentinel 0x11111111, debug errors: 0, removed: S_OK.
  • Hardware (AMD Radeon RX 6600M, driver 32.0.12033.1030, Windows 10.0.26100, D3D12 debug layer enabled): readback 57, sentinel 0x11111111, debug errors: 0, removed: S_OK.

@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.

This branch also carries the three slot 70 backing commits from #2395, which the slot 86 native compute fixture does not need. Please put the final compute commit on current main or name the actual dependency if one exists. #2470 and #2490 work on translated slot 67 pipelines, while this fixture uses a real slot 86 compute PSO. Please coordinate the common command-list slots and test both paths after choosing the order. Keep the 57 readback and no-bound-pipeline controls on the native path.

@Holastor
Holastor force-pushed the d3d12/compute-dispatch-root-bindings branch from f90ed35 to 9ad7cb3 Compare November 25, 2026 19:24
@Holastor

Copy link
Copy Markdown
Contributor Author

Done — the branch now carries only the single compute dispatch commit (9ad7cb3f) on top of current main (6d2d3bed). The three slot 70 backing commits are no longer present.

On coordination with #2470 and #2490: those PRs operate on a translated slot 67 (placeholder) compute pipeline through dispatch_translated, which is called at the top of list_dispatch before the native path runs. This PR handles the native path only: a slot 86 desktop compute PSO is bound via list_pipeline (slot 25), which sets pass.compute_pipeline = true, and list_dispatch then calls list->Dispatch() directly. The two paths share the same argument-binding slots (14/35/37/39/45) but are entirely independent in execution — the translated path refuses when dispatch_translated returns true regardless of a native pipeline being present, and the native path runs only when no translated dispatch was recorded. No ordering dependency exists between the two PRs for these shared slots; whichever merges first, the other's handlers remain intact.

The 57 readback and no-bound-pipeline controls are both present on the native path:

startup_compute_dispatch_warp     Passed
startup_compute_dispatch_hardware Passed   adapter=AMD Radeon RX 6600M
read back value: 57 (expected 57)
compute stats: dispatches=1, skipped=1
device removed reason: 0x00000000, debug layer errors: 0

Command: ctest --preset dev --no-tests=error -R '^startup_compute_dispatch' -V

@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Built and run here: both cases pass, and four mutations separate into the two that matter and the two the fixture never reaches

ctest --preset dev -R 'compute_dispatch_(warp|hardware)'
    1/2 startup_compute_dispatch_warp .......  Passed   0.67 sec
    2/2 startup_compute_dispatch_hardware ...  Passed   3.66 sec
    100% tests passed, 0 tests failed out of 2

startup_compute_dispatch built from this branch with cmake --build --preset dev --target startup_compute_dispatch
(individual targets build here; the full target set stops in DXC on this host).

Four mutations of src/startup_stubs/d3d12_xs_device.cpp

mutation result
zero-sized Dispatch no longer rejected (if (!x || !y || !z) return; → if (false) return;) caught
if (parameter >= 16) return; → >= 17 survived
heap-type test relaxed (if (heap.type != … CBV_SRV_UAV) continue; → if (false) continue;) survived
dispatch whenever a pass exists (pass.pipeline_real && pass.compute_pipeline → true) caught

The two caught ones are exactly the halves I would want asserted. Zero-sized dispatches are illegal in D3D12 and must
not reach ID3D12GraphicsCommandList::Dispatch; and "only dispatch through a real compute pipeline" is the entire
point of the change — making it unconditional would dispatch through a placeholder and the fixture notices.

The two survivors are invalid-input guards the fixture never feeds

  • parameter >= 16: the fixture builds a two-entry root signature and touches parameters 0 and 1
    (root_params[0] UAV, root_params[1] 32-bit constants), so index 16 is never presented. A call with parameter = 16
    should be dropped without touching compute_root_address[16]; one case would pin it.
  • heap type: the fixture creates D3D12_HEAP_TYPE_DEFAULT and READBACK committed resources and registers a
    CBV/SRV/UAV heap, so a SAMPLER or RTV heap never reaches the descriptor-table path. A call with a SAMPLER heap
    should be ignored rather than resolved against a descriptor range it does not own.

Neither survivor is a defect I can demonstrate — both guards look correct, they simply have no case whose behaviour
would change if they were removed. Both are cheap to add and both protect against an index or heap-kind mistake from
the title side, which is precisely the sort of thing a stand-in has to get right.

One thing I checked while reading

x2w_d3d12_compute_stats reports render_dispatches and render_dispatches_skipped separately, and the counters are
bumped before the early-return branches (if (n <= 3) log(...)). That means a skipped dispatch is countable without a
log line, which is what lets a fixture assert "one recorded, one skipped" rather than parsing logs. Worth keeping.

Environment

Windows 11 build 26300.9974; WARP (Microsoft Basic Render Driver) and the installed physical GPU; two cases as
registered in the branch's CMakeLists.txt. Each mutation was built, run, reverted and rebuilt; final state 2/2 green.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment review of head 9ad7cb3 (code read against origin/main, no Windows run by me).

Checked on Linux: git diff --check origin/main...HEAD, python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py all clean. I could not build the C++ fixture here, so I did not run the code mutations; the mutation results already posted in this thread by ChazY11 are the only mutation evidence.

What looks right:

  • src/startup_stubs/d3d12_xs_device.cpp: slots 14, 35, 37, 39, 45 are forwarded only when a real compute pipeline / desktop compute root is bound, and the root-parameter type is checked before forwarding. Zero-size Dispatch is ignored and counted as skipped.
  • The fixture tests/startup_compute_dispatch.cpp reads back the UAV value (57) and has two negative controls, registered for warp and hardware in CMakeLists.txt.

Open question for @R0Y00 (design, not a bug):

  • Several open PRs edit the same compute slots in the same file: #1975 (slots 37 and 39 root constants), #2470 and #2490 (translated compute Dispatch), #1441 (draft, desktop DXIL compute). This PR adds list_dispatch (slot 14) and the compute root constant handlers (37, 39) too, so whichever lands second will conflict and may register a second handler for the same slot.
  • Please pick the order or the one owner of each slot. I am not merging this while the overlap is open.
  • Also: the diff moves some existing list_typed[...] lines (13, 36, 40, 42), which is churn unrelated to compute; consider leaving those lines where they were to ease the rebase.

Merge stays with @R0Y00 / MasterDomino. Win2025 WARP receipt for this head is still missing.

AI-assisted; commands listed were executed locally.

@Makto94

Makto94 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Hardware run and Windows 11 MSVC build at head 9ad7cb3f.

Environment: Windows 11 Pro build 26300.9974, Debug (dev preset), MSVC toolset 14.44.35207 (cl 19.44.35230.0). The hardware test prints adapter=NVIDIA GeForce RTX 3070 Ti and device removed reason: 0x00000000, debug layer errors: 0 (x2w-d3d12 debug layer: 0x00000000 enabled). Driver 32.0.16.2101 (not printed by this test; from the other hardware logs of this session on the same machine). The runs were serial (-j1).

Build: cmake --build --preset dev exited 0 (this PR changes C++ in src/startup_stubs/ and tests/, so the build was rerun at this head).

Tests:

  • ctest --preset dev --no-tests=error -j1 -R '^startup_compute_dispatch_warp$' -E hardware -V: 1/1 passed (startup_compute_dispatch_warp).
  • ctest --preset dev --no-tests=error -j1 -R '^startup_compute_dispatch_hardware$' -V: 1/1 passed. 0 capability skips (77).

Both tests print read back value: 57 (expected 57) and compute stats: dispatches=1, skipped=1. The log shows the first Dispatch(1, 1, 1) as skipped (pipeline_real=0 compute=0) and the second as recorded, after compute root UAV 0 was forwarded from the title address to a desktop address. The WARP run uses adapter=Microsoft Basic Render Driver and also reports debug layer errors: 0.

On the PR so far: the hardware run in the author's comment names AMD Radeon RX 6600M. A further comment reports a run on "the installed physical GPU" without naming the adapter. I found no run that names an NVIDIA adapter on this head.

Not covered by this run: NVIDIA only (RTX 3070 Ti); no AMD or Intel GPU; no Release build; the wider ctest -R '^startup_' suite was not run; the code mutations reported earlier in the thread were not rerun here; the fail-first run on main was not repeated; no negative control for this test appears in the log.

@Holastor
Holastor force-pushed the d3d12/compute-dispatch-root-bindings branch from 9ad7cb3 to 8cdc558 Compare November 25, 2026 20:42
@Holastor

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (99af3da0), resolving the CMakeLists.txt conflict with merged #2473.

Verified on Windows 11 x64 (AMD Radeon RX 6600M & WARP):

  • Build commit: 8cdc5589
  • ctest --preset dev --no-tests=error -R '^startup_compute_dispatch' -V: 2/2 passed
  • ctest --preset release --no-tests=error -R '^startup_compute_dispatch' -V: 2/2 passed
read back value: 57 (expected 57)
compute stats: dispatches=1, skipped=1
device removed reason: 0x00000000, debug layer errors: 0

PR is mergeable.

@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.

Re-reviewed 8cdc5589 after the branch was narrowed to the native slot 86 path. The exact 57 readback and the missing-pipeline case are useful. Two root-binding cases still need coverage before this can merge.

  • Slot 45 finds the owning placed buffer for an interior guest address and binds the desktop resource's base GPU VA in both branches. A valid subrange therefore writes the beginning of the buffer. Reuse the validated placement and add the guest byte offset to the desktop GPU VA. Check reject before considering any desktop-address path. Please dispatch into a nonzero aligned subrange and read back both it and the sentinel before it.
  • Slot 39 uses the original count in 1u << count after storing only the first eight words, and forwards the original count to the desktop root. A legal native root with 32 DWORDs can reach a shift outside the width, and a count past the bound of the active parameter gets forwarded. Keep the native and translated constant capacity explicit and check the active parameter's declared range. Exercise a native root with 32 constants and an out-of-range write.

Please also add a real slot-35 descriptor-table readback if keeping slot 35 in this PR. The current fixture uses root constants and a root UAV only. The handler resolves a view table but sends the original handle to D3D12, so a distinct guest and desktop handle is the useful comparison. This is a source review finding; I did not run those three new cases.

@Holastor
Holastor force-pushed the d3d12/compute-dispatch-root-bindings branch from 8cdc558 to cc447ed Compare November 25, 2026 20:56
@Holastor

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (e9ae884f), resolving the CMakeLists.txt conflict with merged #2451.

  • Build commit: cc447ed4
  • ctest --preset dev --no-tests=error -R '^startup_compute_dispatch' -V: 2/2 passed (0.22s)
read back value: 57 (expected 57)
compute stats: dispatches=1, skipped=1
device removed reason: 0x00000000, debug layer errors: 0

PR is mergeable.

@Holastor

Copy link
Copy Markdown
Contributor Author

Updated in commit d037e27 against upstream/main (e9ae884f):

1. Slot 45 (list_compute_root_uav)

  • Placed buffer subrange translation: When placed_buffer_range resolves an owning placed allocation (owner), computes offset = address - base where base = reinterpret_cast<u64>(owner->own().title_memory) and adds the offset to the desktop resource virtual address: desktop = res->GetGPUVirtualAddress() + offset.
  • Rejection check: Checks !placed.reject before considering any desktop-address path, ensuring rejected placed subranges do not fall through to raw desktop GPU VAs.
  • Fixture verification: Allocates a 512-byte placed buffer, initializing byte 0 with sentinel 0x11111111 and byte 256 with 0x22222222. Dispatches into the nonzero aligned subrange at offset 256 (guest_mem + 256). Verified readback asserts that offset 0 sentinel 0x11111111 remains untouched and offset 256 is updated to 57.

2. Slots 37 & 39 (list_compute_root_constant and list_compute_root_constants)

  • Capacity separation: Explicitly separates translated constants limits (translated_compute_constant_parameters = 16, translated_compute_constant_words = 8) from native parameter bounds (max_native_root_constants = 64).
  • Declared range validation: When pass.compute_params is active, checks p.type == D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, offset < p.constants_count, and count <= p.constants_count - offset, dropping out-of-range writes before forwarding to the desktop list.
  • Bit shift overflow guard: Bounds translated storage masking to bound = std::min(count, 8 - offset) with ((1u << bound) - 1u) << offset, preventing shifts outside 32-bit width.
  • Fixture verification: Shader and root signature declare 32 root DWORD constants (scale, bias, pad[29], extra). Includes negative controls verifying out-of-range writes are dropped (count = 33, offset = 32, and offset = 31, count = 2). Writes full 32 constants via slot 39, followed by slot 37 updating offset 0 (scale = 5), yielding 5 * 10 + 7 + 0 = 57.

3. Slot 35 (list_compute_table)

  • Dropped slot 35 and related tables/state from this PR. Resolving guest and desktop descriptor tables requires command list descriptor heap binding (SetDescriptorHeaps, slot 32) and descriptor table virtualization, which will be covered together with table fixtures rather than in direct root binding dispatch.

Test Receipts

ctest --preset dev --no-tests=error -R '^startup_compute_dispatch' -V
  • WARP: Passed (readback 57, sentinel 0x11111111, dispatches=1, skipped=1, debug_errors=0, removed=S_OK)
  • Hardware (AMD Radeon RX 6600M, driver 32.0.12033.1030, Windows 10.0.26100, D3D12 debug layer enabled): Passed (readback 57, sentinel 0x11111111, dispatches=1, skipped=1, debug_errors=0, removed=S_OK)
ctest --preset release --no-tests=error -R '^startup_compute_dispatch' -V
  • WARP & Hardware: Passed (2/2)
ctest --preset dev --no-tests=error -R 'desktop_root_signature|era_heap_allocation|offscreen_warp' -V
  • Regression suite: Passed (3/3)

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I reran d037e277 in Windows Release. WARP and RTX 4060 Laptop both kept 0x11111111 at byte 0 and wrote 57 at byte 256 using the 32-DWORD native root. The range guards passed and slot 35 is out of this diff. That addresses the native binding findings on the prior head. I also checked the current #2470 stack; the two candidates conflict in d3d12_xs_device.cpp over the compute slot and root-state wiring. Keep the native subrange fixture and reapply the native forwarding delta on the shared compute root/dispatch base after its existing prerequisites land.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment review of head d037e277, as @R0Y00 asked: what this PR still adds after #1974, #1975 and the #2470 work that landed through #2532. Code read against current main. I did not build it.

The branch conflicts with main in src/startup_stubs/d3d12_xs_device.cpp (git merge-tree --write-tree origin/main d037e277). Most of it is now on main in a different shape:

  • Slot 14 Dispatch: already on main (#1974). list_dispatch first tries the translated slot 67 path (dispatch_translated). Then it forwards only after x2w_startup::decide_dispatch accepts the bound desktop compute pipeline and root, the root/pipeline match and the bound root arguments, and it logs a reason when it refuses. The PR's list_dispatch (pipeline_real / compute_pipeline plus a skip counter) duplicates this and should be dropped.
  • Slots 37 / 39 compute root constants: on main (#1975), with one difference. list_compute_constant(s) store the words in pass.compute_constants through store_root_constants. That keeps 16 parameters of 8 words and logs anything dropped or truncated. The 32-DWORD native root that R0Y00 verified on d037e277 (57 at byte 256) would be truncated to 8 words on main. So the PR's real remaining delta here is native capacity: a native slot 86 root needs its declared constants_count (up to 32), not the translated store's 8. That fits best as an extension of store_root_constants / x2w_root_constants::Store, checked against the active parameter's declared range, not as a second handler.
  • Slot 45 compute root UAV: not on main. main records root UAVs only from the fixture hook x2w_d3d12_fixture_compute_root_uav, and its comment at bind_compute_root_view says slot 45 is not forwarded. The PR's slot 45 forwarding, with the placed-buffer subrange offset that R0Y00 checked (byte 0 kept at 0x11111111, 57 at byte 256), is new. It should go through bind_compute_root_view so restore_compute_root replays it after a shim compute pass.
  • Fixture tests/startup_compute_dispatch.cpp (native slot 86 path): new and still useful. Keep the subrange and the 32-DWORD cases. They are the only device evidence for the two deltas above.

Suggested shape after updating to main: drop the PR's slot 14 / 37 / 39 handlers, raise the native constant capacity in the shared store, add slot 45 through bind_compute_root_view, and keep the fixture. R0Y00's changes-requested stays until R0Y00 clears it. No merge from our side.

Commands: git merge-tree --write-tree origin/main d037e277 (1 conflict, d3d12_xs_device.cpp), git show origin/main:src/startup_stubs/d3d12_xs_device.cpp and git show origin/main:src/startup_stubs/d3d12_draw.inl (list_dispatch, list_compute_constant(s), store_root_constants, bind_compute_root_view), git log -S decide_dispatch / -S list_compute_constants (#1974, #1975).

AI-assisted; commands listed were executed locally.

Extend x2w_root_constants::Store to support capacity up to 32 words per
parameter for native slot 86 roots while preserving the 8-word default for
translated compute. In list_compute_constant and list_compute_constants, forward
valid 32-bit root constants to the desktop command list when desktop_compute_root
is bound.

Implement list slot 45 (SetComputeRootUnorderedAccessView) in d3d12_xs.dll,
translating guest placed buffer subrange offsets to desktop GPU virtual addresses
and routing through bind_compute_root_view so restore_compute_root replays it.

Update CreateRootSignature and list_dispatch to consider compute root parameters
forwarded and check that all declared root parameters are bound before dispatch.

Add synthetic fixture tests/startup_compute_dispatch.cpp exercising WARP and
hardware backends, verifying root constant bounds checking, full 32-word native
root constants, and placed buffer subrange UAV dispatch with sentinel preservation.
@Holastor
Holastor force-pushed the d3d12/compute-dispatch-root-bindings branch from d037e27 to 61f0e76 Compare November 26, 2026 11:52
@Holastor

Copy link
Copy Markdown
Contributor Author

Updated head to 61f0e76e following @tedin7's review and rebased onto current main (410f6004):

  1. Dropped redundant slot 14 / 37 / 39 handlers and skip counters: Aligned with main's canonical list_dispatch and decide_dispatch path from startup: implement command-list slot 14 Dispatch (Part of #870) #1974.
  2. Extended root constant capacity: x2w_root_constants::Store now supports capacity up to 32 words per parameter for native slot 86 roots while preserving the 8-word default for translated compute. In list_compute_constant and list_compute_constants, forwarded calls reach list->SetComputeRoot32BitConstant(s) when desktop_compute_root is bound. Added unit test cases for 32-word capacity in tests/startup_root_constant_store.cpp.
  3. Implemented slot 45 compute root UAV: Bound through bind_compute_root_view with placed buffer subrange offset translation so restore_compute_root replays it after shim passes.
  4. Compute dispatch verification: list_dispatch validates that all declared compute parameters (SRV, UAV, constants) are bound. Renamed fixture tests to startup_compute_dispatch_root_<backend> to avoid test name collision with startup_compute_dispatch_<adapter> from startup: compute input named by a resource heap record a root constant indexes #2532.

Receipts

ctest --preset dev --no-tests=error -R '^(startup_root_constant_store|startup_compute_dispatch_root|startup_list_dispatch)' -V
  • 12/12 passed (100%): startup_root_constant_store, startup_compute_dispatch_root_warp, startup_compute_dispatch_root_hardware, plus all 9 startup_list_dispatch canonical and mutation checks.
ctest --preset release --no-tests=error -R '^(startup_root_constant_store|startup_compute_dispatch_root)' -V
  • WARP & Hardware (AMD Radeon RX 6600M): Passed. Sentinel at byte 0 preserved (0x11111111), 32-DWORD root constant update correctly evaluated to 57 at byte 256, 0 debug layer errors, device removed reason S_OK.

@Holastor
Holastor requested a review from tedin7 November 26, 2026 11:53
@Holastor

Copy link
Copy Markdown
Contributor Author

@R0Y00 — gentle ping on this PR. Main is merged cleanly and all CI / Win2025 WARP checks (dev & release) are green; it's just waiting on the matched baseline/candidate title run when one of you has a window.

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.

5 participants