Skip to content

D3D12.X: repack root-changing ExecuteIndirect commands on the GPU - #869

Open
utkarshxdev wants to merge 1 commit into
xcl-dev:mainfrom
utkarshxdev:root-changing-execute-indirect
Open

utkarshxdev wants to merge 1 commit into
xcl-dev:mainfrom
utkarshxdev:root-changing-execute-indirect

Conversation

@utkarshxdev

@utkarshxdev utkarshxdev commented Nov 24, 2026 •

Copy link
Copy Markdown

Translated pipelines use XCL's ABI root signature. A title command signature that changes root arguments cannot run with that ABI directly. This patch repacks each command on the GPU so a translated draw or dispatch sees the root values written for that command.

What is in it

  • Track root constant offsets and root buffer descriptors for translated draw, indexed draw, and compute dispatch signatures.
  • Repack commands from UMA or native upload buffers at execution time. Reuse the caller's count buffer and clear affected shadow root values after the call.
  • Add layout coverage and a D3D12 regression test for per-dispatch values and the count buffer. The two-pass mesh execution work is tracked in D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724.

Regression run

main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

this PR (b1d2ab6):

xcl-smoke v1
commit: b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

Tested

  • AMD Radeon RX 9070 XT (RDNA4), Windows 11: cargo test -p xcl --lib hle::d3d12x -- --test-threads=1 passed (116 passed, 0 failed, 1 ignored).
  • Windows 11 x64, RTX 5070 Ti Laptop: scripts/test.ps1 passed (717 passed, 0 failed, 41 ignored).
  • Verified indirect::tests::root_offsets_follow_inline_registers_and_the_spilled_table and gpu_repack_preserves_per_dispatch_values_and_the_count_buffer.
  • Apple Silicon, macOS: git apply --check --whitespace=error-all on upstream beaa245.

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus.
  • Root-changing mesh dispatch and signatures with indirect vertex or index buffer view changes are outside this patch's scope.

AI use

OpenAI Codex (GPT-6) implemented the patch, added the tests, and verified the changes.

Translated pipelines use XCL's ABI root signature and cannot consume a title's root-changing command signature directly. Repack standard draw and dispatch commands on the GPU so each command sees its own root values and the native call retains the count buffer.
@utkarshxdev
utkarshxdev force-pushed the root-changing-execute-indirect branch from b301550 to b1d2ab6 Compare November 24, 2026 07:09
@utkarshxdev
utkarshxdev marked this pull request as ready for review November 24, 2026 07:12
@badoomtch

badoomtch commented Nov 24, 2026 •

Copy link
Copy Markdown

Ran the two new tests at b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad on native Windows 11 build 26300, Core Ultra 7 265, Rust 1.96.0 MSVC (debug), DXC 1.8.2502.11. The machine has an RTX 5080 (610.88) and Intel integrated graphics. The upstream fixture uses the default D3D12 device and does not print its adapter name.

cargo test --frozen -p xcl --lib hle::d3d12x::indirect::tests:: -- --nocapture --test-threads=1 — 2 passed, 0 failed, 0 ignored, with no GPU or DXC skip.

The GPU fixture verified the per-dispatch values and count buffer together. It supplied three commands, set the count to two, uploaded the arguments after recording, waited for the fence and read back [11, 16, 0, 0]. The layout test for inline and spilled arguments also passed. Retail loading and the draw and indexed-draw paths remain unverified here.

We also counted successful root-changing signature creations and their indirect calls in two longer Windows runs on our integration based on 1ec4c98cd, without this PR. Both reached the fade after the loading artwork and then the title watchdog. Across the sampled windows, the draw, indexed-draw and dispatch counts were all zero in both runs. This covers the path our title took on this machine. Your repack may still be needed on other paths or by other titles.

AI use: Codex (GPT-6) checked the source revision, ran the tests and drafted this comment.

@ettehn

ettehn commented Nov 24, 2026

Copy link
Copy Markdown

Windows 11 x64 (26200.9974), RTX 5070 Ti Laptop 621.24, Rust 1.97.1 MSVC debug. On the unmodified PR head b1d2ab6, a fresh build directory and scripts/test.ps1 gave 717 passed, 0 failed, 41 ignored. Both new tests passed. Two unrelated GPU tests counted as passed reported SKIPPED (no wave64). An earlier suite run hit the #718 cubemap assertion and its two poisoned-lock failures.

I also varied just the count and expected readback in a separate copy of the compute fixture. With three commands and MaxCommandCount=3, counts 0, 1, 3, and 4 produced [0,0,0,0], [11,0,0,0], [11,16,57,0], and [11,16,57,0] respectively, with no skips. This checks the empty and capped cases for compute. Draw, indexed draw, and retail execution were outside my run.

OpenAI Codex (GPT-6.2 Astra) assisted with verification.

@eizispark

Copy link
Copy Markdown

Hardware check of b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad (verified clean merge with main 1ec4c98): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 714 passed, 3 failed, 41 ignored (GPU tests skipped on this adapter: none); the 3 failures were the known concurrent --test-threads=4 VRAM contention flake in hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels plus two downstream mutex PoisonError cascades (transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory)
  • cargo test -p xcl --lib hle::d3d12x -- --test-threads=1: 116 passed, 0 failed, 1 ignored (GPU tests skipped on this adapter: none)
  • Verified hle::d3d12x::indirect::tests::root_offsets_follow_inline_registers_and_the_spilled_table, hle::d3d12x::indirect::tests::gpu_repack_preserves_per_dispatch_values_and_the_count_buffer, and hle::d3d12x::bind::tests::async_compute_pso_success_and_failure_in_dispatch_and_execute_indirect (ok)

Regression run
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (b1d2ab6):

xcl-smoke v1
commit: b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression runs for this PR's head b1d2ab6 and for its base main a1672ef, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

xcl-smoke v1
commit: a1672ef21c396d8edc9c4b0e3747f671bd40f528
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1641)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17660 MB

this PR:

xcl-smoke v1
commit: b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17565 MB

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0

Not tested

  • the unit and e2e tests on this machine
  • world loading, where root-changing ExecuteIndirect calls are most likely: a 60 s run stays in the menus, so this is a regression check only

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

World-loading run to go with the smoke runs above: this PR's head b1d2ab6 merged onto main 1ec4c98 (clean merge), release, XCL_NETWORK=0, A pressed every 4 s from 20 s (XCL_PRESS_A_AT), warm caches, same RTX 3060 12 GB. One run each.

main 1ec4c98 + this PR
world loading from ~55 s ~55 s
frames stop ~80 s ~80 s
title's watchdog (+0x23cf683) 104 s 104 s
Wait64BitValueX timeouts 0 0
device removals 0 0

No regression through world loading, and no change in where this title stops on this machine: it still ends at the watchdog behind slow compute pipeline builds (#156, #754). The log has no line about indirect commands, so I cannot tell from it whether the title took the repack path.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 lane report, head b1d2ab6 merged onto main 1ec4c98 (lane merge 1302047).

The lane crashes with a device-lost on this PR, and it is concurrency-sensitive.

  • Full suite at --test-threads=4 (twice: lane run + isolated rerun): mid-lib-suite the log shows xcl: D3D12 device removed: 0x887a0005, then the D3D12 device was removed (0x887a0005) - the title is stopped, and the test binary exits abnormally; e2e/gpu_compute_e2e/pls_quota/predication targets then all fail to run (lane totals collapse to 38/3/20).
  • Same lib suite at --test-threads=1: clean, 672 passed / 4 failed / 21 ignored (the 4 are the known GPU-f64 + xma2 Wine-lane set from my GPU test results: NVIDIA RTX 3080 (wave32) and AMD RDNA2 iGPU (no mesh shaders) #42 rows), 27 s, no device-lost.

So on RDNA3 + Proton Experimental, your ExecuteIndirect GPU-side repack loses the device under concurrent test load (0x887a0005 = DXGI_ERROR_DEVICE_REMOVED family; no hang notice captured in the log). Deterministic at threads=4 (2/2), absent at threads=1 (1/1).

Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

utkarshxdev added a commit to utkarshxdev/xcl that referenced this pull request Nov 24, 2026
…h rendering)

Consolidate critical engine subsystems required to transition from Stage 5
(2D menus presentation loop) to Stage 6 (ingame 3D world loading, streaming,
and gameplay rendering) on Apple Silicon / macOS via D3DMetal:

1. Two-pass mesh shader execution on DispatchMesh and ExecuteIndirect (PR ivall#724):
   - Hook DispatchMesh (slot 127 / newer 129) on console command list vtable.
   - Execute TwoPassPso (Pass 1 compute -> UAV barrier -> Pass 2 mesh+PS -> UAV barrier).
   - Track console mesh root-argument layout (s[8:9] spill table, inline arguments from s16).
   - Create companion DISPATCH command signature alongside DISPATCH_MESH in device_x.
   - Allocate/recycle DEFAULT-heap UAV record buffer per command list (recycled on allocator reset).
   - Scale indirect DispatchMesh group counts on GPU when mesh_groups_per_record > 1.

2. GPU-side root-changing ExecuteIndirect repack (PR ivall#869):
   - Repack root-changing indirect draw and dispatch commands on the GPU.
   - Allow translated pipelines on XCL ABI root signature to consume title root-changing signatures.
   - Retain native count buffer support and track allocator lifetime for indirect argument buffers.

3. DirectStorage BCPack decompression acceptance (XCL_DSTORAGE_BCPACK_ACCEPT=1):
   - Prevent E_DECOMPRESSION (0x89240030) errors when streaming assets.
   - Maintain since_status = S_OK when solid blocks are filled.

4. Watchdog & fatal crash bypass at 0x23cf683 (eh.rs):
   - Prevent GPU hang watchdog ('GPU Loc Sig') and null write at 0x23cf683 from terminating
     the process when compute PSO compilation or decompression stalls >30s.

5. Sparse buffer lock safety:
   - Use try_lock in forget_buffer and drain deferred GONE queue on forget_gone.
   - Eliminates D3DMetal re-entrancy deadlocks during command list reset/execution.

6. Expanded verification suite:
   - 30 host subsystem checks passing in scripts/verify_mac_build.sh.
@upipibi upipibi mentioned this pull request Nov 24, 2026
@raylitebull

Copy link
Copy Markdown
Member

Holding off on merge until the concurrency-sensitive DEVICE_REMOVED (0x887a0005) reported under --test-threads=4 on RDNA3 is diagnosed and resolved.

@grahamster2

Copy link
Copy Markdown
Collaborator

@utkarshxdev question before I write something that would collide with this: I'd like to add validation of ExecuteIndirect arguments, i.e. clamp the thread-group counts and the record count against the device limits and the argument buffer's size, and honour the count buffer when it's smaller than MaxCommandCount. The reason is a device hang (0x887A0006) on an RTX 3080 that fits argument blocks the title never wrote, and another project reports the same: unwritten blocks making single dispatches run for 100+ ms until a TDR.

Your repack pass already copies every record through a compute shader before ExecuteIndirect, so the clamp would naturally live there, a few lines in the shader plus the limits passed in. Would you rather I:

  1. send it as a small follow-up stacked on this PR, hooking into your pass, or
  2. do a standalone pass that only touches non-root-changing signatures (the ones yours leaves alone), keeping the two independent?

Either works for me. I'd rather not land a second copy-through pass that conflicts with yours.

Written with Claude Code (Claude Opus 5.5).

@utkarshxdev

Copy link
Copy Markdown
Author

Hey @grahamster2, thanks for coordinating! That’s a great catch — unwritten argument blocks causing 100+ ms dispatches and 0x887A0006 TDRs is definitely a critical issue on retail titles.

I'd definitely prefer Option 1 (sending it as a follow-up stacked on this PR / hooking into the repack compute shader).

Running two separate copy-through passes on indirect argument buffers would introduce redundant GPU bandwidth and dispatch overhead. Clamping ThreadCountX/Y/Z (against D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION = 65535) and bounding the record count against the buffer size / count buffer fits naturally into the existing repack compute pass with almost zero extra cost.

For signatures that don't change root arguments, we can either route them through the same lightweight clamp kernel or keep your standalone path for non-repacked ones so both cases are covered cleanly.

Feel free to stack your branch on top of this PR or submit the follow-up against this branch once it lands. Happy to review and test it alongside you!

@grahamster2

Copy link
Copy Markdown
Collaborator

Thanks, option 1 it is: I'll stack the per-record clamp on this PR's repack pass, and keep a small CPU-side bounds check for the signatures you don't repack.

To be upfront about its weight: since asking, I measured on the RTX 3080 and the retail title never hit it. Across 5 world runs (with XCL_PSO_WAIT_MS=50) there were 0 device hangs, and a bounds check that logs any oversized MaxCommandCount, out-of-range count-buffer offset or misaligned argument offset never fired. The one 0x887A0006 I'd seen before happened earlier in the run and doesn't reproduce. So this is a defensive guard rather than a fix for something live here, and I'll send it at low priority once this PR lands, not ahead of it.

Written with Claude Code (Claude Opus 5.5).

@utkarshxdev

Copy link
Copy Markdown
Author

Appreciate the detailed measurements and the update, @grahamster2!

Really glad to hear it ran cleanly across 5 world runs on the 3080 with zero hangs. Keeping it as a defensive follow-up after this PR lands makes total sense and avoids delaying the merge.

Looking forward to reviewing your follow-up once this is in!

@grahamster2

Copy link
Copy Markdown
Collaborator

@utkarshxdev heads up: #1795 (mastrr9) just opened "clamp ExecuteIndirect argument records and total work on the GPU", which overlaps the clamp we said I'd stack on this PR. I'll hold mine; worth checking whether #1795 should build on your repack pass rather than add a second one.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (b1d2ab6)

Hardware / environment

Commit b1d2ab604b848b3d054a66c8b3b55c2dd2c4eaad. Intel Arc A770, driver 32.0.101.9175. Windows 11 Enterprise Evaluation x64, build 26200. AMD Ryzen 7 3800X. Rust and Cargo 1.100.0, host x86_64-pc-windows-msvc, unoptimized test profile. DXC and DXIL 1.9.2609.5.

Commands and results

  • cargo test --workspace --no-run exited 0 and built the workspace test executables without running tests.
  • CPU, outside the Arc lock, with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1: xcl-77aca8ccb20e299f.exe --exact hle::d3d12x::indirect::tests::root_offsets_follow_inline_registers_and_the_spilled_table --test-threads=1. Exit 0. 1 passed, 0 failed, 0 ignored, 0 skipped.
  • GPU, inside Invoke-ArcTest.ps1 -Test, with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1: xcl-77aca8ccb20e299f.exe --exact hle::d3d12x::indirect::tests::gpu_repack_preserves_per_dispatch_values_and_the_count_buffer --test-threads=1. Wrapper and test exit 0. 1 passed, 0 failed, 0 ignored, 0 skipped.

Both runs used the precompiled library test executable. Combined totals were 2 passed, 0 failed, 0 ignored, and zero case-sensitive ^SKIPPED matches.

Observed behavior

The CPU test validated inline and spilled root patch offsets and rejection of unsupported layouts. The GPU test uses the default D3D12 adapter, verified as the Arc A770 via DXGI. The readback assertion passed with expected values [11, 16, 0, 0]. Arguments were written after command recording and the count buffer limited execution to two of three commands.

Not tested

Full GPU workspace suite and game smoke runs.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr869-focused.log and published.

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.

9 participants