Skip to content

D3D12.X: enforce hard concurrency cap on wanted >= 256 KB huge PSO compiles - #1996

Open
raylitebull wants to merge 1 commit into
xcl-dev:mainfrom
raylitebull:fix/big-compile-hard-cap
Open

raylitebull wants to merge 1 commit into
xcl-dev:mainfrom
raylitebull:fix/big-compile-hard-cap

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Enforces a hard concurrency cap on concurrent wanted huge (>= 256 KB DXIL) driver PSO compiles (Slots::wanted_most, configured via XCL_HUGE_PSO_WANTED_CONCURRENCY, default 2, clamped to XCL_HUGE_PSO_CONCURRENCY..=64) while capping >= 4 MiB (GIANT_COMPILES) at 1, preventing bursts of lazy compute binds from stacking driver-compiler commit into OOM.

Part of #1833.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs (+127 / -68):
    • huge_pso_wanted_concurrency() & Slots::wanted_most(): wanted huge builds still bypass the 3 GiB commit headroom wait and can overtake an unwanted background compile (up to wanted_most), while bursts above wanted_most queue cleanly without stacking memory.
    • big_compile_turn: checks commit_free() in the wait loop before acquiring SlotGuard (*n += 1) so an unwanted commit-blocked compile never holds a GIANT_COMPILES slot while sleeping under low free commit.
    • SlotGuard::drop: switches to notify_all() so waiting wanted compiles wake even behind unwanted waiters.
    • big_compile_tests (11/11 pass, including unwanted_commit_waiter_does_not_starve_wanted_compile, wanted_builds_bypass_commit_and_unwanted_slot_but_respect_hard_cap, and wanted_burst_is_hard_capped_to_wanted_most).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto 656c0e8 (ae00ec7).
  • cargo check --workspace --tests: passed.
  • cargo test -p xcl --lib big_compile_tests: 11 passed, 0 failed.

Regression run

  • Standalone scripts/smoke.ps1 pair on ae00ec7 vs 656c0e8 has not been run locally. AMD and NVIDIA reviewers are invited to test on ae00ec7 vs 656c0e8 (including scripts/smoke.ps1 and XCL_HUGE_PSO_WANTED_CONCURRENCY=1 / 2 under multi-thread PSO bursts) and post results in the comments.

Not tested

  • 60 s scripts/smoke.ps1 pair on ae00ec7, full cargo test --workspace suite, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation and unit tests; the author reviewed the diff and test output.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Overlap note, from reading the diffs (not run): #1924 (Rednaxeh, opened earlier) changes the same huge-compile gate in real.rs. Both PRs rework gate_compute_driver_compile and big_compile_turn, and git merge-tree of this head with #1924's reports a conflict there. The approaches differ. #1924 makes a background compile wait for commit in proportion to the program's size. This PR caps how many large compiles run at once (2, or 1 at 4 MiB or more). Settling on one, or rebasing one onto the other, would avoid the gate being rewritten twice.

AI-assisted (Claude Code).

anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for flagging the overlap, @upipibi! Full credit to #1924 (@Rednaxeh) for the commit-size / XCL_HUGE_PSO_RAM_SHARE background admission gate.

#1996 addresses an orthogonal axis in big_compile_turn: enforcing a hard concurrency cap on bursts of wanted >= 256 KB compiles (XCL_HUGE_PSO_WANTED_CONCURRENCY, slots.wanted_most()) so concurrent lazy binds cannot spike driver commit into OOM. If #1924 lands first, we will rebase #1996 cleanly on top of it so both protections compose together.

@gsucristo

Copy link
Copy Markdown
Contributor

Technical review findings:

Blocking

  1. Deadlock / starvation of wanted compiles behind commit-blocked unwanted compiles (real.rs, big_compile_turn):
    • An unwanted background compile acquires a SlotGuard (*n += 1) before entering while !commit_free() { if wanted() { return Some(slot); } std::thread::sleep(LOOK); }.
    • Under low free commit (< 3 GiB), an unwanted compile holds its slot indefinitely while sleeping.
    • For GIANT_COMPILES (most: 1, wanted_most: 1), a single commit-blocked unwanted giant compile fills *n == 1 == wanted_most, so any wanted giant compile blocks forever in *n < cap (1 < 1). The same deadlock happens on BIG_COMPILES whenever XCL_HUGE_PSO_CONCURRENCY == XCL_HUGE_PSO_WANTED_CONCURRENCY.
    • Fix: Check commit_free() inside the wait loop before incrementing *n for !wanted() builds so an unwanted compile never holds a slot while waiting for commit headroom.

Minor

  • big_compile_turn now always returns Some(SlotGuard), making the (true, true, false) => ", huge, wanted at once (no slot)" arm in gate_note unreachable.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head c969032 (on its base 6567c5f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, 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 gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 987 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: wanted_burst_is_hard_capped_to_wanted_most.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 997 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (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), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

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.

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
)

Brings main to full parity with upstream/main (de36462):
- xcl-dev#1969: official upstream merge of 64-bit icmp 32-bit lowering and MIMG heap guards
- xcl-dev#1774: size-based commit headroom admission for big driver compiles and
  XCL_PIPELINE_MAX_KB cap for offline --pipelines precompile

Conflicts resolved by keeping HEAD's already-merged xcl-dev#1969 emit.rs (with heap_index),
combining xcl-dev#1996 + xcl-dev#1774 comments in real.rs, and combining xcl-dev#1871 + xcl-dev#1774 in shaders.rs.

Assisted-by: Antigravity (Gemini 4)
…ving wanted slots

Hard-cap concurrent huge (>= 256 KB) wanted driver compiles via XCL_HUGE_PSO_WANTED_CONCURRENCY (default 2; giant >= 4 MiB capped at 1) to prevent bursts of lazy binds from spiking commit into OOM. Check commit_free() inside the wait loop before taking SlotGuard so an unwanted commit-blocked compile never holds a slot and deadlocks wanted builds under low free commit, and remove the unreachable no-slot arm in gate_note. Rebased onto xcl-dev#1774 (656c0e8).
@raylitebull
raylitebull force-pushed the fix/big-compile-hard-cap branch from c969032 to ae00ec7 Compare November 25, 2026 01:14
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased cleanly onto 656c0e8 (ae00ec7, including #1774) and fixed the blocking deadlock caught by @gsucristo:

  • big_compile_turn now checks commit_free() inside its wait loop before acquiring SlotGuard (*n += 1), so an unwanted commit-blocked compile never holds a GIANT_COMPILES (1/1) slot while sleeping under low free commit.
  • Removed the unreachable no-slot arm in gate_note.
  • Verified with cargo check --workspace --tests and cargo test -p xcl --lib big_compile_tests (11 passed, 0 failed, including unwanted_commit_waiter_does_not_starve_wanted_compile and wanted_burst_is_hard_capped_to_wanted_most).

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head c969032, based on main 80f4819. 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 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: c9690321247c348885c40fdc1d2f556a4ae1a7c6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1521 (PresentX 1521)
presents per 2 s (last 3): 48 11 3
device removals: 0
crashes: 0
peak commit: 28972 MB

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

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

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

@Anon64

Anon64 commented Nov 25, 2026 •

Copy link
Copy Markdown

A data point on how many huge compiles at once help, from a world-loading run on a 12 GB 32-lane card. RTX 3060 12 GB (581.80), Windows 11 26200, 64 GB RAM, release build of main 3da2abb (not this PR). Retail title, A pressed every 4 s, 420 s. XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PSO_PRELOAD=0, XCL_HUGE_PSO_CONCURRENCY=4.

  • Same stop as with the default of 1: presents stop at ~74 s and stay 0 to the end. No crash, no device removal, peak commit 32.0 GB.
  • Huge driver compiles (driver compile finish lines) per 100 s: 11 (45 s of driver time), 29 (69 s), 18 (98 s), 11 (206 s), then 3 in the last 20 s. So about two overlap in the later windows, and they are still going at 420 s.
  • Compared with the default: a run of main 80f4819 + D3D12.X: a draw does not wait for a graphics pipeline still being built #1798 with the same settings and the default of 1 had a single pipeline gated (waited 37588 ms) for the slot.

More slots let several of these compiles overlap on this machine, but they did not get the title further: what it waits for is the next pipeline it binds, and there are many of them, each taking seconds. One run.

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

@JJAutoCompare

Copy link
Copy Markdown

Empirical verification — PR #1996 (ae00ec73ed21cc4d266a8f42649eaeae3387ae84)

Tested clean detached PR head ae00ec73ed21cc4d266a8f42649eaeae3387ae84 on STOR-WINLAB.

Environment

  • Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8–32, DoublePrecisionFloatShaderOps=0, XCL_ADAPTER=A770, d3d12SDKLayers.dll absent).
  • rustc 1.100.0 (0ef1bc386 2026-11-09) (CARGO_INCREMENTAL=0, debug info 0). Standalone DXC/DXIL 1.9.2609.5 was on PATH; the suite logged Windows SDK DXC/DXIL 1.9.2602.17.

Tested

  • cargo build --workspace and cargo test --workspace --no-run exited 0 outside the GPU lock.
  • cargo test -p xcl --lib big_compile_tests -- --nocapture: 11 passed, 0 failed, 0 ignored, 0 skipped (also passed in full suite; verified 12 wanted workers peaked at 2 concurrent entrants, a 3rd waited for a slot, and a commit-blocked unwanted compile left the 1-slot lane open to a wanted compile).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (under Invoke-ArcTest.ps1, exited 101): 1,038 passed, 26 failed, 45 ignored across 20 test targets, with 23 SKIPPED lines across 13 tests (excluded from coverage; 18 wave64, 3 refused wave32 f16 lowerings, 1 driver-cache disable unavailable, 1 heap-window fallback; libtest pass counts include captured early returns).
    • Failures (26): 25 in xcl --lib shader/DXIL tests (21 CreateComputePipelineState 0x80070057 + 4 shader output assertions) and 1 in e2e (test_title_runs_and_game_folder_is_untouched, RSSetDepthBiasX Split wave64: masks read only lane by lane stay in their half #94 blue vs green). All unrelated to the big-compile gate (no matched main baseline).

Not tested

  • Retail Xbox title smoke run, main A/B baseline, live driver bursts of large PSOs under low commit, D3D12 debug layer, release profile, and forcing DXC 1.9.2609.5.

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 pr1996-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of ae00ec73 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on cbc296ab, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14648 MB
xcl-smoke v1
commit: ae00ec73ed21cc4d266a8f42649eaeae3387ae84
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14811 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 101 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

@akimfomin

Copy link
Copy Markdown

I used PortBridge to check a separate admission case on your exact ae00ec73 head. The wanted cap and the same-lane change are working as intended in the extracted gate. The two size lanes can still independently see the same available commit before either driver call grows memory.

With 3,328 MiB reported free, the exact #1996 gate let two background jobs overlap (1,536 + 2,048 MiB in the model). A shared reservation on both PSO paths deferred the second until the first released. Controls kept the wanted cap and bypass, still allowed overlap with enough budget, and verified unwind release.

Source patch, exact gate extraction and CPU results. This is a concurrency reproduction with controlled estimates. I have no driver-memory or startup comparison for the patch. The estimate can count memory already committed by an active job, analogous to the growth-accounting concern in #139. AI-assisted PortBridge research (OpenAI Codex).

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/real.rs
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