Skip to content

D3D12.X: clamp ExecuteIndirect argument records and total work on the GPU - #1795

Open
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/d3d12x-indirect-args-bounded-on-gpu
Open

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/d3d12x-indirect-args-bounded-on-gpu

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Adds a small GPU compute clamp pass (indirect_clamp.hlsl / indirect_clamp.rs) that runs before ExecuteIndirect for command signatures without root arguments. Corrupt or garbage indirect draw/dispatch counts can no longer trigger DXGI_ERROR_DEVICE_HUNG (0x887a0006): argument records and total work are bounded on the GPU before the PC reads them.

  • Enabled by default.
  • XCL_INDIRECT_CLAMP=0 disables it.

Tested

Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB.

  • cargo test -p xcl --lib indirect_clamp -- --nocapture --test-threads=1: 4 passed, 0 failed (includes live GPU execution of gpu_records_are_clamped_and_budgeted)
  • cargo test -p xcl --lib execute_indirect -- --test-threads=1: 2 passed, 0 failed
  • cargo test -p xcl --lib -- --test-threads=1: 844 passed, 0 failed, 22 ignored (no new warnings)

Regression run
Smoke run by @Anon64 in comment below: #1795 (comment)
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1591)
presents per 2 s (last 3): 44 53 35
device removals: 0
crashes: 0
peak commit: 25217 MB

PR:

xcl-smoke v1
commit: 201d67da8bee82a099c99fd78ba5626373d6f932
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1617)
presents per 2 s (last 3): 60 40 54
device removals: 0
crashes: 0
peak commit: 23909 MB

Tester's setup: RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

No device removals or crashes; 101 % of main's frames, 94 % of its peak commit.

Tester's AI use: Written with Claude Code (Claude Opus 5.5) from runs on the tester's machine.

Not tested

  • A full cargo test --workspace run by the author: the widest run reported above is the xcl library tests.
  • Reproducing the device removal with and without the clamp in a title: not reported by the author.
  • AMD and Intel GPUs, by the author.
  • Whether the community regression run above reaches the code this PR changes.

AI use

  • Claude Code assisted with the change (the commit's Assisted-by trailer); the model is not recorded there.
  • Claude Code (Claude Sonnet 5.5) added the community regression run to this description and updated the lines that it made out of date or that the PR check requires.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 7b9a1e0 (on its base b9b6ea6).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record: 891 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: signatures_without_root_arguments_are_bounded, a_signature_that_cannot_be_bounded_replaces_one_at_the_same_address, config_words_follow_the_shader, gpu_records_are_clamped_and_budgeted.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 893 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)).
  • Two tests were skipped with --skip on NVIDIA. Both fail on main 7f7e768 too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. heap_window_out_of_memory_falls_back_to_the_switch_form skips when XCL_HEAP_WINDOWS is unset (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record skips because Developer Mode is off on this PC (it cannot disable the driver cache). The AMD run does not set XCL_REQUIRE_GPU, so there both just print SKIPPED.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

…PC reads them

Clean-room XCL implementation.

Assisted-by: Claude Code
@mastrr9
mastrr9 force-pushed the feat/d3d12x-indirect-args-bounded-on-gpu branch from 7b9a1e0 to 201d67d Compare November 24, 2026 22:35
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@ofc0urse

Copy link
Copy Markdown
Contributor

Title run of 7b9a1e0 on an 8 GB NVIDIA card, with the skipping it is meant for. The new head 201d67d has the same indirect_clamp.rs and .hlsl and resolves the bind.rs conflict the way I did below, so this should hold for it too. The clamp builds and runs, but it does not prevent the device removal here: every run with it on still ended in 0x887a0006, at 152 to 269 s.

Tested: main c4d37be + #1798 + #1284 + this PR, release, merged locally. The only conflict was execute_indirect in bind.rs, where main now wraps the PC call in fresh_indirect_arguments; I kept that wrapper around both calls (bounded copy and original). RTX 4060 Ti 8 GB (32-lane waves, split wave64), driver 621.24, i5-14400F, 32 GB, Windows 11 Pro 26300, retail 1.0.2.1. XCL_PSO_WAIT_MS=50 (so dispatches of pipelines still being built are skipped), A pressed at 115, 125 and 150 s, 600 s cap.

run XCL_LOOP_BUDGET clamp device removed at frames
1 256 on 264 s 4,534
2 256 off (XCL_INDIRECT_CLAMP=0, same binary) 206 s 4,449
3 256 on 152 s 4,224
4 unset on 214 s 4,405
5 unset on 236 s 4,451
6 unset on 269 s 4,446
7 unset on, plus #1702 (XCL_TEXTURE_PAGES_SYSTEM_MEMORY=1) 226 s 4,462
8 as run 7, with #1323's markers also around draws on 225 s 4,467

Runs 3 to 8 also had #1323 (XCL_GPU_CULPRIT=1) and a local line that logs its markers at the device removal, not only at a watchdog release. Runs 5 to 8 skipped compute programs by hash (a local test switch, below). In runs 7 and 8 local video memory peaked at 4,433 and 4,846 MB, against 14,000 to 15,000 MB in the others, so on this card the removal does not come from oversubscribed video memory.

  • With the clamp on and off, the removal comes in the same phase, right after the world starts loading. One run per arm is not enough to say whether the clamp moves it.
  • In run 4 D3D12.X: XCL_GPU_CULPRIT names the dispatches a stalled queue has not done #1323 named one dispatch started and not done at the removal: cs df837c748fdf56b8 (CS_ScreenProbes_RadianceSpatialFilter), 14,400 groups, a direct Dispatch, not an ExecuteIndirect. Its loop bounds come from memory.
  • In runs 3, 5, 6 and 7 D3D12.X: XCL_GPU_CULPRIT names the dispatches a stalled queue has not done #1323 found no dispatch in flight (0 of 8, 0 of 263, 0 of 275, 0 of 137 lists). Whatever ran too long there was not a compute dispatch, so a clamp on indirect dispatch arguments could not reach it.
  • For run 8 I put the same markers around DrawInstanced, DrawIndexedInstanced and graphics ExecuteIndirect too (local change). Still nothing in flight at the removal (0 of 236 lists). What is left are the paths without a marker: XCL's own copies and texture uploads, CPU-expanded rect lists, clears and resolves.
  • Run 5 skipped every dispatch of df837c748fdf56b8; runs 6 to 8 also skipped 45a2f1928c4e6f73 (CS_AllocBatchCSCullOutput) and cd4c7be781d7d2df (CS_ComputeHitDetectionSkinnedResults). Those two are the programs VIctory's NVIDIA testers skip with VICTORY_SKIP_PIPELINES=eeed82b877b44b5f,b83629b90cd2b7bc: VIctory names a shader by the first 16 hex digits of the BLAKE3 hash of the same bytes that XCL hashes with FNV-1a, and the two match these records. The device was still removed.
  • One more run with run 6's settings is not in the table: it ended at 180 s in an access violation in gpu::tiling::Chain::detile_level (tiling.rs:438, called from title_textures::subresources), reading title memory that was no longer mapped, before any skipped program had run.

Not tested: more than one run with the clamp off. What was running at the removal in runs 3 and 5 to 8: XCL_DRED=1 made the driver rebuild every pipeline from the start, so the title never got past its first minutes. AMD.

AI use: Claude Code (Claude Opus 5.5) merged the build, ran the title, read the logs and wrote this comment.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 201d67d, based on main 689f2db. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 689f2db:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1591)
presents per 2 s (last 3): 44 53 35
device removals: 0
crashes: 0
peak commit: 25217 MB

this PR:

xcl-smoke v1
commit: 201d67da8bee82a099c99fd78ba5626373d6f932
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1617)
presents per 2 s (last 3): 60 40 54
device removals: 0
crashes: 0
peak commit: 23909 MB

No device removals or crashes; 101 % of main's frames, 94 % of its peak commit.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

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

@JJAutoCompare

Copy link
Copy Markdown

PR #1795 — ExecuteIndirect clamp on Intel Arc A770

Tested commit 201d67da8bee82a099c99fd78ba5626373d6f932 on STOR-WINLAB. Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB with driver 32.0.101.9175, wave sizes 8–32, no double-precision float shader ops or D3D12 debug layers. Rust 1.100.0 and DXC/DXIL 1.9.2609.5.

Tested

  • cargo build --workspace and cargo test --workspace --no-run passed with debug info and incremental compilation disabled.
  • cargo test -p xcl --lib indirect_clamp::tests -- --nocapture passed all 4 tests. Three CPU tests checked signature parsing, signature replacement at a reused address, and shader config packing. The GPU test read back 2,000 indexed-draw records and verified per-record limits, preservation of other fields, and a total-work cutoff at record 1,383 (zero-based) across two shader chunks. It completed without skipping.
  • cargo test -p xcl --lib execute_indirect -- --nocapture passed all 3 existing binding tests, including a GPU check that ExecuteIndirect reads freshly written arguments. Both focused runs had 0 failed, 0 ignored, and 0 skip lines.
  • One Arc-locked cargo test --workspace --no-fail-fast -- --test-threads=4 run exited 1. Summing 20 libtest summaries gives 954 passed, 25 failed, 45 ignored. The log contains 22 SKIPPED lines representing coverage gaps within the reported passes. All 7 focused tests also passed in this run.

Failures and skips

  • 20 shader tests failed at CreateComputePipelineState with 0x80070057. Four shader output checks disagreed on fused FMA, mip sampling, FP16 upper-half preservation, and a pixel wave reduction. The test-title E2E reported a blue pixel where the dynamic depth-bias check expected green.
  • 17 skips were for unavailable wave64, 3 for unsupported per-lane FP16 arithmetic or conversion forms, 1 for unavailable heap windows, and 1 for inability to disable the driver cache.

Not tested

No main baseline or retail-title smoke run, sample-data coverage, or other GPU vendors. The clamp readback exercised indexed draws. GPU dispatch and mesh clamping and the full title-to-clamp path were outside that test.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1795-suite.log and published this report.

@MacieGx

MacieGx commented Nov 25, 2026

Copy link
Copy Markdown

FYI, a lock-order note from running this PR in the newer retail title's world (#505) on an RTX 5080, on a tree based on an older main (689f2db) plus this PR, #1993 and others. On current main it should not happen any more, because 892177b ("a buffer's last release does not wait for the sparse state's lock") removed one half of it; I mention it because allocator_reset depends on that.

There, from a symbolised thread dump when every title thread had stopped:

  • sparse::readback_after_execute held the sparse STATE lock and reset an allocator → indirect_clamp::allocator_reset → waits for SCRATCH;
  • indirect_clamp::allocator_reset held SCRATCH and dropped the buffers over FREE_KEPT (s.free.truncate(FREE_KEPT)) → last Release → real::res_release → sparse::forget_buffer → waits for STATE.

If you want allocator_reset not to rely on what a buffer's Release does: split the extra buffers off inside the lock (let over = s.free.split_off(FREE_KEPT);) and drop them after it. That was 15 lines locally, and the scene then ran 90–100 s of world frames with no stop.

AI use: Claude Code (Claude Opus 5.5; a Claude Fable 5.2 subagent read the dump and wrote the local fix). I checked both call chains and that 892177b is in main.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA, the title, 3 runs with #1795 and 3 without: in each run with it, the clamp bounded each of the first 256 ExecuteIndirect calls that reached it, and none of those 256 ran unbounded. The counter prints at the first 4 calls and then at powers of two; its last line was the 256th, so each run had 256 to 511 such calls, and those after the 256th were not seen one by one. The first bounded call came 0.9 to 1.8 s after the first #101 stub call. Presents stopped 1.4 to 2.3 s after the first #101 with #1795 and 0.6 to 2.4 s after it without. Neither tree had a fault, a device removal or a new kind of warning.

Setup: main f087b99 + #684 e56dbc3 + #1795 201d67d, merged locally, plus one local commit that logs what indirect_clamp::bound returns at its call in bind.rs (8f2b802). Against main f087b99 + #684, merged locally (2f6a4ae); all six runs within one hour. Measured on f087b99; at 201d67d, #1795 conflicts with main 06c9f55 in crates/xcl/src/hle/d3d12x/bind.rs. RTX 4070 12 GB (615.71.09), Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, release, Series X profile, 120 s. The first-run screens were completed once, with no story progress. A was pressed once the title presented steadily (16.0 to 18.3 s). XCL_PSO_PRELOAD=0, WINEDEBUG=err+all,fixme-all.

main + #684 (3 runs) #1795 (3 runs)
ExecuteIndirect calls with a translated pipeline, bounded / not (the count prints at powers of two) – 256 / 0 at the 256th call, the last line (256 to 511 calls per run)
first #101 75.7, 78.4, 86.1 s 78.7, 80.2, 83.5 s
first and 256th bounded call – 79.6–79.9, 81.1–81.3, 85.3–85.7 s
last 2 s with a present 76.3, 80.7, 88.3 s 80.1, 82.5, 85.5 s
ExecuteIndirect arguments run unbounded, ExecuteIndirect … skipped –, 0 0, 0
WARN lines 76, 77, 78 78, 78, 77
  • The counter sits at indirect_clamp::bound's call in bind.rs, so calls on PC pipelines and calls skipped before it are not in it. Each printed line was for a call with MaxCommandCount 1.
  • indirect_clamp and execute_indirect tests under Wine on the same card: 8 passed, 0 SKIPPED lines; gpu_records_are_clamped_and_budgeted ran on the card.
  • The runs give no count of records the shader changed, so whether the clamp cut down any record here was not seen.

Not tested: today's main 06c9f55 (the head conflicts with it); the GPU time of the copy pass; a run with a garbage record (the hang it prevents; neither tree hung here); the rest of the suite; Windows; AMD and Intel.

AI use: Claude Code (Claude Opus 5.5) read the change, wrote the counter, ran the title and the tests, and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants