Skip to content

D3D12.X: reuse split dispatch scratch when growth fails - #2469

Open
razormontana wants to merge 1 commit into
xcl-dev:mainfrom
razormontana:d3d12x/reuse-split-scratch-on-growth-failure
Open

razormontana wants to merge 1 commit into
xcl-dev:mainfrom
razormontana:d3d12x/reuse-split-scratch-on-growth-failure

Conversation

@razormontana

@razormontana razormontana commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

A split compute dispatch can use smaller slabs when a command list’s scratch buffer holds at least one thread group. If allocating a larger buffer failed, XCL discarded that option and built or bound the whole compute pipeline. Reusing the buffer avoids bringing an additional whole pipeline into use on this path. Part of #2403.

What is in it

  • In real/dispatch_chain.rs, reuse the same recording’s scratch after a failed growth request if one group fits. Report reuse to the command recorder so it issues its UAV barrier. Only a successful allocation updates scratch usage and replaces the shared buffer.
  • The CPU regression test injects an allocation failure and checks the returned buffer and reuse flag. It covers an exact-fit group, a buffer one byte too small, a missing buffer, successful growth and an already adequate buffer.
  • README.md describes when split dispatches can continue with the recording’s existing scratch buffer.

Tested

  • Windows 11 Pro build 22631, Core i7-10700K, RTX 3070 8 GB (driver 617.42), Rust 1.100.0 MSVC.
  • Two focused CPU tests passed on the rebased head. The original allocation-failure fixture failed without the reuse change. The rebase preserves the upstream GPU scratch-sharing test and the existing UAV barrier on reuse.
  • Debug workspace build passed. On f2062cda, cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output reported 1,443 passed, 0 failed and 47 ignored. The pass count includes 26 explicit GPU skip notices.
  • cargo build --offline --locked --release -p xcl succeeded.

Regression run

Both release builds ran the same retail title offline for 60 seconds on the RTX 3070. Both used the Series S profile, direct DXIL and copies of the same starting cache. This pair uses e120925, the preceding main commit. At 8b957be, smoke reached its startup deadline during #2555 shader preparation. The PR merges cleanly into 8b957be; the combined retail run remains unverified. The initial pair showed 703 frames on main and 378 on the PR. For this repeat, both started from copies of the cache left by the first main run, after builds completed.

Main

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 3070
title: 80ea98f7
seconds: 60
exit: 0x0
frames shown: 445 (PresentX 446)
presents per 2 s (last 3): 18 18 18
device removals: 0
crashes: 0
peak commit: 17596 MB

PR head

xcl-smoke v1
commit: f2062cdaeb31bbf83e442cce27066409b8162cb4
gpu: NVIDIA GeForce RTX 3070
title: 80ea98f7
seconds: 60
exit: 0x0
frames shown: 450 (PresentX 450)
presents per 2 s (last 3): 18 18 18
device removals: 0
crashes: 0
peak commit: 17630 MB

Not tested

The CPU test injects scratch allocation failure. The retail smoke checks startup and presents. It does not establish a reduction in shader-code usage during world loading.

AI use

Codex GPT-6.2 wrote and reviewed the code and tests, rebased the branch, ran the checks, and updated this description.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026

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

No concrete defect found. Fallback reuse is capacity-safe, slabbed within its existing allocation, and inserts the required UAV barrier; current Windows CI is green. Nonblocking coverage gap: the test injects select_scratch failure rather than exercising the real D3D12 allocation-failure -> command-recording/slab path. A seam/integration test would strengthen it, but I found no blocker.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…ry (port upstream xcl-dev#2469 + xcl-dev#2532 + xcl-dev#2543 + xcl-dev#2629)

(cherry picked from commit bc14f1d8b191b3935c9829a539454b6226c542d0)
@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
A recording can dispatch a split program in smaller slabs if its current scratch holds at least one group. Keep that buffer and request the reuse barrier when creating a larger resource fails, so dispatch does not build a whole pipeline for this case.

Assisted-by: Codex (GPT-6.2 Astra)
Assisted-by: Codex GPT-6.2
@razormontana
razormontana force-pushed the d3d12x/reuse-split-scratch-on-growth-failure branch from 44a66e6 to f2062cd Compare November 26, 2026 17:41
@Ritolino

Copy link
Copy Markdown
Contributor

Independent Windows 11 x64 + NVIDIA GeForce RTX 4080 (wave32) verification of #2469 head f2062cda merged cleanly onto current main (8b957bec):

Tested

  • Windows 11 x64, AMD Ryzen 9 7950X, NVIDIA GeForce RTX 4080 (wave32), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), debug
  • cargo build --workspace: succeeded
  • hle::d3d12x::real::dispatch_chain::tests::failed_scratch_growth_reuses_a_buffer_that_fits_a_group: ok
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip blob_enumeration_sees_one_submitted_update:
    • xcl --lib: 1318 passed, 0 failed, 27 ignored, 1 filtered out
    • All 37 other workspace test targets: 128 passed, 0 failed, 20 ignored
    • Total: 1446 passed, 0 failed, 47 ignored, 1 filtered out (blob_enumeration_sees_one_submitted_update skipped due to pre-existing #2421 / #2373).

AI use: Antigravity with Gemini 4 Hydrogen (Medium) ran the merge/build/test pass and drafted this report; reviewed by human.

@a-DuckGod

Copy link
Copy Markdown

Independent Windows 11 / NVIDIA test report on exact PR head f2062cdaeb31bbf83e442cce27066409b8162cb4 (clean detached checkout; merge-base e120925e).

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 Ti (12 GB, wave32, mesh shaders), driver 32.0.16.2114; Intel Core i7-8700K, 32 GB RAM; Windows 11 Pro (Version Dev 29708.1003); rustc 1.100.0 (0ef1bc386 2026-11-09) (x86_64-pc-windows-msvc), Windows SDK DXC 1.8.2502.11, D3D12 debug layer installed, debug build.
  • cargo build --workspace: succeeded.
  • cargo test -p xcl --lib failed_scratch_growth_reuses_a_buffer_that_fits_a_group -- --nocapture: 1 passed, 0 failed, 0 ignored, 0 skipped.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1442 passed, 1 failed, 47 ignored (including all e2e tests under the D3D12 debug layer and DRED).
    • The 1 failure was hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory (vram.rs:2040:26, HRESULT(0x80004005) under parallel GPU load).
    • Standalone rerun cargo test -p xcl --lib d32s8_targets_take_their_own_size_of_video_memory -- --nocapture: 1 passed, 0 failed, 0 ignored (2.83 s).
  • SKIPPED GPU tests (26): 21 no wave64 (RTX 3080 Ti is 32-lane waves only), 3 per-lane gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 refused forms (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache; Windows Developer Mode required), 1 heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Not tested

  • Release build, retail title / scripts/smoke.ps1 run, XCL_SAMPLE_* tests, live OOM scratch-growth fallback during a game dispatch, AMD / Intel / native wave64 GPUs.

AI use

  • Antigravity (Gemini 4 Neon) checked out the PR, read commit f2062cda (dispatch_chain.rs and README.md), ran the build and tests, and drafted this report. I checked it before posting.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2469 rebased head f2062cdaeb31bbf83e442cce27066409b8162cb4 (exact parent & merge-base e120925e3abc9956a8b9bae631969d32e8ccd43c). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0, default flags, no input)

Targeted RTX 4060 release unit & GPU tests (f2062cda)

  • cargo test --release -p xcl --lib failed_scratch_growth_reuses_a_buffer_that_fits_a_group -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s, 0 SKIPPED).
  • cargo test --release -p xcl --lib hle::d3d12x::real::dispatch_chain:: (3 consecutive parallel passes): 3 passed, 0 failed, 0 ignored on all 3 passes (0.25 s / 0.17 s / 0.17 s, 0 SKIPPED).
  • cargo test --release -p xcl --lib hle::d3d12x::real::: 64 passed, 0 failed, 0 ignored (0.36 s, 0 SKIPPED).

Paired 60 s RTX 4060 smoke (exact parent e120925e vs f2062cda)

Both runs completed cleanly at steady 60/2 s pacing with 0 device removals and 0 crashes (f2062cda vs e120925e xcl.log: 6,176 / 6,115 MB vs 6,114 / 6,114 MB peak/end local VRAM, 4,651 MB end non-local VRAM on both, 19,450 vs 19,588 translated draws / 1,024 dispatches with 0 skipped).

Exact parent (e120925e):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13979 MB

PR #2469 head (f2062cda):

xcl-smoke v1
commit: f2062cdaeb31bbf83e442cce27066409b8162cb4
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 13997 MB

Limits of coverage

  • Full workspace test suite was not run on f2062cda (only failed_scratch_growth_reuses_a_buffer_that_fits_a_group, 3 parallel passes of dispatch_chain::, hle::d3d12x::real::, release build, and exact-parent paired 60 s smokes).
  • The 60 s no-input menu/intro smoke hit 0 split-compute programs (compute split: 0 programs split, 0 pieces built, 0 chained dispatches issued in 0 slabs; scratch 0 MiB), so scratch-growth failure fallback and buffer reuse were exercised by the targeted release unit test above rather than live split-compute OOM pressure.
  • Single discrete NVIDIA 8 GB GPU (RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.

AI use

Ran the targeted release unit/GPU tests, release build, and exact-parent paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts, timings, memory figures, and smoke blocks were extracted directly from cargo test, xcl.log, and scripts/smoke.ps1 outputs.

@thiagocalile

Copy link
Copy Markdown

Independent test and smoke report for head f2062cdaeb31bbf83e442cce27066409b8162cb4 on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- dispatch_chain --test-threads=4: 11 passed, 0 failed, 0 ignored (0 skipped).

Not tested: full workspace suite, 60 s smoke run on this head, NVIDIA/Intel GPUs, or Linux/Wine.

AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.

@UncommonDLL

UncommonDLL commented Nov 27, 2026 •

Copy link
Copy Markdown

merge-check
base: 6089122
head: f2062cd
merge: clean
build: cargo build --workspace -> ok, exit 0 in 29.45 s
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1462 passed, 4 failed, 47 ignored, 0 filtered. Exit 101 in 87.92 s. All 38 targets completed. The logs contained 26 explicit runtime skip notices, including subcases within passing tests.
review: No blocking finding after reviewing both changed files on local merge c27cf681baed24ecc9a0e017de1979d86d6f07da. Source inspection confirmed that failed growth preserves the recording’s existing scratch buffer and allocation counters. Reuse requires capacity for at least one thread group. The recorder bounds each slab to that capacity and issues a UAV barrier before reuse. The injected allocation-failure test passed. The suite exercised the physical RTX on other checks. A real D3D12 scratch-growth allocation failure remains untested.
performance: Assessed from source. Successful growth retains its allocation behavior. After failed growth, reuse can avoid building or binding a whole pipeline. Smaller slabs can require additional dispatches and barriers. Frame time and memory were unmeasured.
verdict: safe to merge
hardware / tool and model: Windows 11 Pro build 26200, Ryzen 7 7800X3D, RTX 5070 Ti, NVIDIA 621.40. OpenAI Codex ran the build, tests and source review using Git, PowerShell and Cargo. Rust/Cargo 1.100.0 MSVC x64, DXC 1.9.2609.5. Exact Codex variant and reasoning setting: not recorded.

Baseline comparison: cargo test -p xcl --lib -- --test-threads=4 reproduced all four failures on the pinned base. On both revisions, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0, _1, _2 and _3 failed at seeds 70, 545, 1019 and 1507 respectively. Each stopped at CreateComputePipelineState with 0x8007000E before reaching the scratch-buffer path changed by this PR.

@Decodere

Decodere commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 6089122
head: f2062cd
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1466 passed, 0 failed, 47 ignored; failing: none (including the new dispatch_chain test failed_scratch_growth_reuses_a_buffer_that_fits_a_group; base 6089122 passes 1465 passed, 0 failed, 47 ignored across 38 test binaries)
review: none (read the full 2-file merged diff, +42/-10 across README.md and crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs, and the full dispatch_chain.rs file: select_scratch preserves the normal allocation and no-growth reuse paths, keeps LIVE/PEAK/SHARED untouched when scratch_buffer returns None, falls back to the recording's existing scratch buffer only when capacity >= group with used = true so record_dispatch_chain emits the required UAV barrier and dispatch_slabs sizes slabs to (s.bytes / group).max(1), falls through cleanly to chain.whole() when no usable buffer exists, holds no lock across CreateCommittedResource, and covers all branches in the new unit test)
performance: No default frame-time or memory regression (reasoned from the full diff): when scratch allocation succeeds or no growth is needed, runtime behavior is identical to base 6089122. The fallback only activates after a CreateCommittedResource failure during split-dispatch scratch growth, where reusing the recording's existing buffer in smaller slabs avoids both additional VRAM allocation and lazy compilation of the unsplit whole compute PSO.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 (driver 32.0.16.2114), Intel Core i5-11400F, Windows 11, Rust 1.100.0; Google Antigravity (Gemini 4 Neon)

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head f2062cd

No open or merged PR makes this change: main's scratch_for in real/dispatch_chain.rs still returns None when scratch_buffer fails, so the chain falls back to the whole pipeline. The PRs sharing #2403 (#2496, #2526, #2590, #2641) change other things.
select_scratch falls back to the list's existing buffer only when it holds one group, and returns it with used = true so the recorder keeps its UAV barrier; dispatch sizes the slabs from the returned buffer's bytes. On the !make path the new filter is a no-op (scratch_bytes only returns make = false when the buffer holds at least one group). No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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.

10 participants