Skip to content

Recompiler: serialize dxc::wait_for_memory slot admission (#2463) - #2652

Open
fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/dxc-wait-for-memory-race
Open

fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/dxc-wait-for-memory-race

Conversation

@fixgep

@fixgep fixgep commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes the TOCTOU admission race in dxc::wait_for_memory (crates/xcl/src/gpu/recomp/dxc.rs) where concurrent DXC worker wakeups read WORKING without synchronization before calling fetch_add(1), admitting bursts past both the commit headroom check and WANTED_AT_ONCE. Part of #2463, Part of #1566, Part of #1269.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: wrap WORKING admission checks (plenty, timed_out, cur == 0, and cur < WANTED_AT_ONCE && wanted()) and fetch_add(1) in a MemoryGate mutex while keeping MemorySlot::drop lock-free and sleeping outside the mutex; add synthetic multi-threaded unit tests in memory_gate_tests.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 3060 (driver 32.0.15.9144), AMD Ryzen 5 7500F, Windows 11 Pro 10.0.26200, rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), debug & release builds on commit 88d7b0a1.
  • cargo test -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4: 24 passed, 0 failed, 0 ignored (0 SKIPPED); also 24 passed, 0 failed under XCL_ADAPTER=warp.
  • cargo test -p xcl --lib -- --test-threads=4: 1312 passed, 1 failed (gpu::recomp::tests::gpu_clamp_and_omod_per_instruction, v_pk_add_i16 clamp mismatch on RTX 3060), 27 ignored (25 SKIPPED: 21 no wave64, 3 wave32 per-lane refused, 1 cannot disable the driver cache).
  • XCL_ADAPTER=warp cargo test -p xcl --lib -- --test-threads=4: 1312 passed, 1 failed (hle::d3d12x::list_x::tests::mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares under parallel adapter/UMA init; passed on default GPU), 27 ignored.
  • cargo test -p xcl --test '*' -- --test-threads=4: 126 passed, 0 failed, 20 ignored across 33 integration test suites (1 SKIPPED: no heap windows).

Regression run


xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1600 (PresentX 1600)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14006 MB


xcl-smoke v1
commit: 88d7b0a19a276f81491e8430acb5d7dd501ebb1e
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13964 MB

Not tested

AI use

  • Antigravity (Gemini 4 Hydrogen): GitHub REST API pre-flight check, root-cause inspection, implementation of MemoryGate and memory_gate_tests, test/smoke execution, and PR description drafting.

wait_for_memory previously checked WORKING against commit headroom and WANTED_AT_ONCE with an unlocked load before calling fetch_add(1), allowing concurrent worker wakeups to admit an unbounded burst past both limits.

Wrap the admission check and working-slot increment in a MemoryGate mutex while keeping MemorySlot::drop lock-free and sleeping outside the mutex, and add multi-threaded unit tests verifying tight-headroom, WANTED_AT_ONCE, low-commit single-slot, and timeout behavior.

Part of xcl-dev#2463
Part of xcl-dev#1566
Part of xcl-dev#1269
Assisted-by: Antigravity (Gemini 4 Hydrogen)
@pickles976

Copy link
Copy Markdown

Tested: exact clean head 88d7b0a19a276f81491e8430acb5d7dd501ebb1e, Windows MSVC target under Wine 11.0 on Linux, 16 GiB RAM / RTX 4060 Laptop GPU host. Fresh Compiling xcl .../xcl-pr2652/crates/xcl provenance confirmed.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib memory_gate_tests -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored, 0.14 s. This covers tight synthetic commit headroom, the wanted burst limit, draining concurrent waiters, and the single unwanted progress slot. Tests internally spawn concurrent callers despite the serial test harness. Run through the local Wine wrapper in a scope with MemoryMax=9G / MemorySwapMax=512M.

Not tested: real compiler-memory peaks, Windows-native execution, GPU dispatch, retail title, or matched-parent regression. These are CPU synchronization tests with supplied memory values, not proof of Wine's commit telemetry or a hard memory budget. The existing 60-second escape remains; this addresses #2463 item 2, not its separate title-thread driver-compile bypass. No title-safety or FPS claim.

Local log: .compat-xcl/logs/verify-pr2652-wine-memory-gate.log. AI use: omp / OpenAI Codex GPT-6 Astra, test execution and report; no source changes.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.
Targeted run of low_commit_unwanted_admits_only_one_progress_slot, tight_commit_headroom_bounds_concurrent_admissions, wait_for_memory_drains_concurrent_waiters_within_cap, wanted_burst_never_exceeds_wanted_at_once: 4 passed.

Not tested: retail titles (no title data on this lane, counts only).

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

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent native AMD test report for #2652 (issue #2463, item 2) on exact head 88d7b0a19a276f81491e8430acb5d7dd501ebb1e, against its exact parent b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 (main, also the merge base). Both were clean detached checkouts with no local changes; PR head and comments were rechecked before posting. This is a test report only, not a source review.

Tested

  • Hardware and software: AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug build. The suite log names AMD Radeon RX 7800 XT as the adapter (D3D12.X: backend 'real'). No other xcl process was using the GPU.
  • Every build and test used cargo --locked -j 4. Workspace binaries were built before the tests (cargo build --workspace, then cargo test --workspace --no-run).
  • Focused synthetic admission tests, head: cargo test -p xcl --lib memory_gate -- --test-threads=1: 4 passed, 0 failed, 0 ignored (low_commit_unwanted_admits_only_one_progress_slot, tight_commit_headroom_bounds_concurrent_admissions, wait_for_memory_drains_concurrent_waiters_within_cap, wanted_burst_never_exceeds_wanted_at_once). I ran them 10 more times with --test-threads=4: 4 passed each time. The tests use supplied memory values, not real compiler memory peaks.
  • cargo test -p xcl --lib dxc -- --test-threads=4: head 48 passed, 0 failed, 3 ignored. Parent 44 passed, 0 failed, 3 ignored. The difference is the 4 new tests, which do not exist on the parent (memory_gate on the parent runs 0 tests).
  • Whole suite, head: cargo test --workspace --no-fail-fast -- --test-threads=4: 1438 passed, 1 failed, 47 ignored (lib: 1312 passed, 1 failed, 27 ignored).
  • Whole suite, parent (same command): 1434 passed, 1 failed, 47 ignored (lib: 1308 passed, 1 failed, 27 ignored). Head minus parent is +4 passed, which is the 4 new tests.
  • The single failure is the same on both: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, seed 722: res[30] = 0x1, CPU 0x7fffffff. It is a baseline failure on this adapter, not caused by the PR.
  • SKIPPED lines are identical on head and parent (7 each): 6 f16_programs_on_the_gpu / f32_programs_on_the_gpu cases (refused ... its #1426 semantics differ) and heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. None of them touches dxc.rs. I do not count skips as coverage.
  • The first parent attempt reused the head's test binary because of shared-target file timestamps. I noticed it from the identical exe hash and 4 memory_gate tests, discarded it, rebuilt the parent from its own path (Compiling xcl ... xcl-2652-src-parent) and reran. The parent counts above come from that rerun.

Regression run

  • Not run. I ran no scripts/smoke.ps1 and used no title or game data.

Not tested

AI use

  • The test run and this report were written by Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol). The commands and counts above come from my runs; no source changes.

🤖 Generated with Claude Code

@thehollowedone

thehollowedone commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Independent native Windows/NVIDIA test of PR #2652 head 88d7b0a, based on main b49be18. Clean exact-head checkout; RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, DXC/DXIL 1.8.2502.11. DXIL cache was isolated under this checkout's target directory.

Tested

  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked -p xcl --lib memory_gate_tests -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored, 0 skips. The tests internally spawn concurrent callers for commit headroom, wanted-burst admission, draining, and the one-progress-slot rule.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quiet: 1,439 passed, 0 failed, 47 ignored across 37 test targets, with 25 explicit GPU skip notices. Skips are not counted as GPU coverage.

Not tested: a measured DXC memory peak under retail world load, deliberate system commit exhaustion, AMD/Intel hardware, or my own paired title smoke. These results verify the synthetic admission tests and workspace behavior on this machine; they do not establish a title-level memory or frame-rate improvement.

AI-assisted: Codex (GPT-6.2 Sol) ran the tests and drafted this report.

@throny

throny commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1417 solves the same problem (for #2463) in a different way: #1607, group D126. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@fixgep

fixgep commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for flagging #1417, @throny

I checked #1417 (9a3230fa) against this PR (88d7b0a1) and think it makes sense to keep #2652 open unless maintainers prefer rebasing #1417:

Happy to defer to whichever approach maintainers prefer.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2652 at head 88d7b0a19a276f81491e8430acb5d7dd501ebb1e (1 commit; exact parent & merge-base: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, pre-#2555 ancestor of main).

Environment

  • 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 (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (88d7b0a1)

Command Result
cargo test --release -p xcl --lib tight_commit_headroom_bounds_concurrent_admissions -- --nocapture 1 passed; 0 failed; 0 ignored; 1339 filtered out (0.04s)
cargo test --release -p xcl --lib wanted_burst_never_exceeds_wanted_at_once -- --nocapture 1 passed; 0 failed; 0 ignored; 1339 filtered out (0.01s)
cargo test --release -p xcl --lib wait_for_memory_drains_concurrent_waiters_within_cap -- --nocapture 1 passed; 0 failed; 0 ignored; 1339 filtered out (0.08s)
cargo test --release -p xcl --lib low_commit_unwanted_admits_only_one_progress_slot -- --nocapture 1 passed; 0 failed; 0 ignored; 1339 filtered out (0.00s)
cargo test --release -p xcl --lib gpu::recomp::dxc:: (3 consecutive runs) 24 passed; 0 failed; 0 ignored; 1316 filtered out × 3 (0.44s, 0.44s, 0.43s)
cargo build --release -p xcl --bin xcl Clean build (1m 07s, exit 0)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, cached baseline on the same machine):

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

PR #2652 (88d7b0a19a276f81491e8430acb5d7dd501ebb1e):

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

Runtime log observations (xcl.log)

  • 9220 log lines, 0 [ERROR] / device-removal / panic lines.
  • Final draw/memory telemetry in log: 19621 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14016 MB committed by the process; video memory 6114 MB local, 4683 MB non-local.

Limits of coverage

  • Serialized dxc::wait_for_memory slot admission under tight commit headroom, concurrent waiter draining, wanted bursts, and single-slot unwanted progress were verified via all 4 new memory_gate_tests and 3× gpu::recomp::dxc:: (24/0/0).
  • The 60 s retail smoke ran on a 32 GB RAM host with the existing warm shader cache, so it confirms zero runtime regression on title: 29640639 rather than reproducing cold DXC commit-pressure bursts (frame-count delta vs. cached parent smoke reflects single-run startup variance, not this PR).

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

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.

7 participants