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

Open
github-bot wants to merge 1 commit from github-bot/gh-2652 into main AGit
Owner

@⁠fixgep on GitHub · 2026-11-26 05:05 UTC · original
fixgep:fix/dxc-wait-for-memory-race → main · +168 −19 · 1 files · 1 commits · open

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

  • AMD / Intel GPUs, wave64 hardware, and items 1 and 3 of #2463 (covered separately).

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.
**@⁠fixgep** on GitHub · 2026-11-26 05:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2652) `fixgep:fix/dxc-wait-for-memory-race` → `main` · +168 −19 · 1 files · 1 commits · open 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** - AMD / Intel GPUs, wave64 hardware, and items 1 and 3 of #2463 (covered separately). **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 #2463
Part of #1566
Part of #1269
Assisted-by: Antigravity (Gemini 4 Hydrogen)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:38 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 05:06 UTC · original

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.

**@⁠pickles976** on GitHub · 2026-11-26 05:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2652#issuecomment-7183192463) **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.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-26 05:29 UTC · original

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.

**@⁠SlopTart** on GitHub · 2026-11-26 05:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2652#issuecomment-7183539415) **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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 08:31 UTC · original

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

  • Real DXC memory peaks, real commit-pressure behaviour, the 60-second escape under load, the separate title-thread driver-compile bypass of #2463, NVIDIA and Intel, release builds, retail titles, and any FPS or title-safety claim.

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

**@⁠oni-swr** on GitHub · 2026-11-26 08:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/2652#issuecomment-7186707125) 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** - Real DXC memory peaks, real commit-pressure behaviour, the 60-second escape under load, the separate title-thread driver-compile bypass of #2463, NVIDIA and Intel, release builds, retail titles, and any FPS or title-safety claim. **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](https://claude.com/claude-code)
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-26 08:59 UTC · original · edited 2026-11-26 09:05 UTC

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.

**@⁠thehollowedone** on GitHub · 2026-11-26 08:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2652#issuecomment-7187266267) · edited 2026-11-26 09:05 UTC Independent native Windows/NVIDIA test of [PR #2652 head `88d7b0a`](https://github.com/xcl-dev/xcl/commit/88d7b0a19a276f81491e8430acb5d7dd501ebb1e), based on [main `b49be18`](https://github.com/xcl-dev/xcl/commit/b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2652/head:github-bot/gh-2652'
git switch 'github-bot/gh-2652'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2652'
git switch 'github-bot/gh-2652'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2652'
git switch 'github-bot/gh-2652'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2652'
git switch 'main'
git merge --squash 'github-bot/gh-2652'
git switch 'main'
git merge --ff-only 'github-bot/gh-2652'
git switch 'main'
git merge 'github-bot/gh-2652'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.