Shaders: reserve compiler memory slots atomically #1407

Closed
anakatt wants to merge 1 commit from upstream-pr/1417 into main
anakatt commented 2026-11-24 15:45:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by anakatt on 2026-11-24T15:45:52Z.


I fixed a check-then-increment race in DXC memory admission. Several workers could all see the same remaining slot and increment WORKING afterward, exceeding the wanted-work limit under memory pressure.

What is in it

  • Reserve a slot with compare-exchange against the worker count used for the readiness check; recheck after contention.
  • Preserve the existing timeout override and the rule allowing one idle compiler to make progress without spare budget.
  • Add a deterministic barrier-driven contention regression and an idle-progress test. Update README.

Tested

I ran the checks in a Windows 11 Pro ARM64 UTM VM (10.0.26100.1742, 4 GiB RAM, Red Hat VirtIO GPU DOD 22.7.38.43), with Rust 1.100.0 and x86_64-pc-windows-msvc. The DXC tests loaded DXC/DXIL 1.9.2602.17, compiler commit 21d28f72, from Windows SDK 10.0.26100.0.

  • Before the fix, after extracting the admission operation: cargo test --locked -p xcl --lib gpu::recomp::dxc::memory_tests -- --test-threads=4: 0 passed, 1 failed, 0 ignored, 728 filtered out. Four contenders claimed one remaining slot, increasing the count from five to nine against a limit of six.
  • After: cargo test --locked -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4: 16 passed, 0 failed, 0 ignored, 714 filtered out. No SKIPPED output.

Source: main 930e8b49c1c2ec683d22c724a398b39111cd0e56 archive with the changed dxc.rs copied in before committing 9a3230fa20276918548a30a25237ff002a78f390; not a clean head checkout. Shared target directory cleaned for xcl before reproduction; one build job; dev/test debug info disabled.

Not tested

Full workspace suite, native x64 Windows hardware, GPU execution, real-title loading and actual low-memory stress. The concurrency regression uses an isolated admission counter, not forced system-memory exhaustion. I make no game-performance or peak-memory claim. XCL was not built or run on macOS.

Regression run

The required clean main/head real-title scripts/smoke.ps1 runs have not been performed. No xcl-smoke blocks are available; this remains a draft.

AI use

omp, openai-codex/gpt-6-astra: investigated, wrote the fix and regression tests, ran the Windows checks, and prepared this PR.

<!-- greyfinch-sync:ivall/xcl:issue:5475468338 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417). Originally posted by [anakatt](https://github.com/anakatt) on 2026-11-24T15:45:52Z. --- I fixed a check-then-increment race in DXC memory admission. Several workers could all see the same remaining slot and increment WORKING afterward, exceeding the wanted-work limit under memory pressure. ## What is in it - Reserve a slot with compare-exchange against the worker count used for the readiness check; recheck after contention. - Preserve the existing timeout override and the rule allowing one idle compiler to make progress without spare budget. - Add a deterministic barrier-driven contention regression and an idle-progress test. Update README. ## Tested I ran the checks in a Windows 11 Pro ARM64 UTM VM (10.0.26100.1742, 4 GiB RAM, Red Hat VirtIO GPU DOD 22.7.38.43), with Rust 1.100.0 and x86_64-pc-windows-msvc. The DXC tests loaded DXC/DXIL **1.9.2602.17**, compiler commit `21d28f72`, from Windows SDK `10.0.26100.0`. - Before the fix, after extracting the admission operation: `cargo test --locked -p xcl --lib gpu::recomp::dxc::memory_tests -- --test-threads=4`: **0 passed, 1 failed, 0 ignored, 728 filtered out**. Four contenders claimed one remaining slot, increasing the count from five to nine against a limit of six. - After: `cargo test --locked -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4`: **16 passed, 0 failed, 0 ignored, 714 filtered out**. No `SKIPPED` output. Source: main `930e8b49c1c2ec683d22c724a398b39111cd0e56` archive with the changed dxc.rs copied in before committing `9a3230fa20276918548a30a25237ff002a78f390`; not a clean head checkout. Shared target directory cleaned for xcl before reproduction; one build job; dev/test debug info disabled. ## Not tested Full workspace suite, native x64 Windows hardware, GPU execution, real-title loading and actual low-memory stress. The concurrency regression uses an isolated admission counter, not forced system-memory exhaustion. I make no game-performance or peak-memory claim. XCL was not built or run on macOS. ## Regression run The required clean main/head real-title `scripts/smoke.ps1` runs have not been performed. No `xcl-smoke` blocks are available; this remains a draft. ## AI use omp, openai-codex/gpt-6-astra: investigated, wrote the fix and regression tests, ran the Windows checks, and prepared this PR.
DavidM1911 commented 2026-11-24 18:08:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T17:13:05Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7138862967 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417#issuecomment-7138862967). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T17:13:05Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** (`b7aa9f3`) in `README.md` — needs a rebase before it can be tested.
Swagi-REDACTED commented 2026-11-25 03:06:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Swagi-REDACTED on 2026-11-25T03:04:39Z.


Native x64 Windows validation of exact head 9a3230fa20276918548a30a25237ff002a78f390, clean runtime sources.

Tested

  • RTX 3060 12 GB, driver 621.14; Ryzen 7 9800X3D, 16 GB RAM; Windows 11 Home 26200; Rust 1.95.0 MSVC; DXC/DXIL 1.9.2602.17.
  • cargo build --release --workspace: succeeded.
  • cargo test --locked -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4: 16 passed, 0 failed, 0 ignored, 714 filtered out; no skips.
  • scripts/test.ps1: 753 passed, 0 failed, 41 ignored across all workspace result blocks; two explicit no-wave64 skips. No XCL_SAMPLE_* variables set. Debug test profile.
  • One offline release title run, NVIDIA explicitly selected, XCL_COHERENT_MB=4095, XCL_PRESS_AT=115:A; assets on HDD, runtime/writable data on SSD. Generated block below, using the current upstream smoke harness for an anonymized title label. The harness was copied to a private directory under the exact-head checkout so its Git root/commit remain correct.

Regression run

xcl-smoke v1
commit: 9a3230fa20276918548a30a25237ff002a78f390
gpu: NVIDIA GeForce RTX 3060
title: A newer retail game
seconds: 150
exit: 0x0
frames shown: 4024 (PresentX 4024)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14686 MB

Not tested

  • This is a head run only, not a complete main/head regression pair. No base smoke run is included.
  • AMD/Intel/native wave64, deliberate system-memory exhaustion, or heavy in-world shader compilation. Passing the contention regression and a title run is not a measured game-performance gain from this fix.

AI use

  • Codex, GPT-6 (exact serving variant not exposed): ran native validation and drafted this report. No source edits, game files, raw logs, or screenshots included.
<!-- greyfinch-sync:ivall/xcl:comment:7151566541 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417#issuecomment-7151566541). Originally posted by [Swagi-REDACTED](https://github.com/Swagi-REDACTED) on 2026-11-25T03:04:39Z. --- Native x64 Windows validation of exact head `9a3230fa20276918548a30a25237ff002a78f390`, clean runtime sources. **Tested** - RTX 3060 12 GB, driver 621.14; Ryzen 7 9800X3D, 16 GB RAM; Windows 11 Home 26200; Rust 1.95.0 MSVC; DXC/DXIL 1.9.2602.17. - `cargo build --release --workspace`: succeeded. - `cargo test --locked -p xcl --lib gpu::recomp::dxc:: -- --test-threads=4`: 16 passed, 0 failed, 0 ignored, 714 filtered out; no skips. - `scripts/test.ps1`: 753 passed, 0 failed, 41 ignored across all workspace result blocks; two explicit no-wave64 skips. No `XCL_SAMPLE_*` variables set. Debug test profile. - One offline release title run, NVIDIA explicitly selected, `XCL_COHERENT_MB=4095`, `XCL_PRESS_AT=115:A`; assets on HDD, runtime/writable data on SSD. Generated block below, using the current upstream smoke harness for an anonymized title label. The harness was copied to a private directory under the exact-head checkout so its Git root/commit remain correct. **Regression run** ``` xcl-smoke v1 commit: 9a3230fa20276918548a30a25237ff002a78f390 gpu: NVIDIA GeForce RTX 3060 title: A newer retail game seconds: 150 exit: 0x0 frames shown: 4024 (PresentX 4024) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14686 MB ``` **Not tested** - This is a head run only, **not a complete main/head regression pair**. No base smoke run is included. - AMD/Intel/native wave64, deliberate system-memory exhaustion, or heavy in-world shader compilation. Passing the contention regression and a title run is not a measured game-performance gain from this fix. **AI use** - Codex, GPT-6 (exact serving variant not exposed): ran native validation and drafted this report. No source edits, game files, raw logs, or screenshots included.
throny commented 2026-11-26 14:03:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-26T13:08:29Z.


Two contributors checked independently and found that #2652 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.

<!-- greyfinch-sync:ivall/xcl:comment:7192930439 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417#issuecomment-7192930439). Originally posted by [throny](https://github.com/throny) on 2026-11-26T13:08:29Z. --- <!-- xcl-1607-hint:D126 --> Two contributors checked independently and found that #2652 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.
Foniass commented 2026-12-01 05:40:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:40:46Z.


Triage (#1607) – head 9a3230f

The race this fixes is already fixed on main, the other way: commit a34eaed4 (the commit of #2652, merged in #2959) moves wait_for_memory onto MemoryGate::try_admit, which checks the headroom, WANTED_AT_ONCE and the idle case (cur == 0) and increments working under one mutex. The WORKING static and the code this PR edits are gone, which is also why it conflicts.
The compare-exchange loop itself looks correct; it is just no longer needed.
Recommendation: close (superseded by main commit a34eaed4).

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

<!-- greyfinch-sync:ivall/xcl:comment:7302022341 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417#issuecomment-7302022341). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:40:46Z. --- **Triage (#1607)** – head 9a3230f The race this fixes is already fixed on main, the other way: commit a34eaed4 (the commit of #2652, merged in #2959) moves `wait_for_memory` onto `MemoryGate::try_admit`, which checks the headroom, `WANTED_AT_ONCE` and the idle case (`cur == 0`) and increments `working` under one mutex. The `WORKING` static and the code this PR edits are gone, which is also why it conflicts. The compare-exchange loop itself looks correct; it is just no longer needed. Recommendation: close (superseded by main commit a34eaed4). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:45:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:45:14Z.


Closing as superseded: this change is already on main (a34eaed4). main dxc.rs MemoryGate::try_admit takes a gate mutex and checks headroom / WANTED_AT_ONCE and increments working under it (atomic); commit exists

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311596165 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1417#issuecomment-7311596165). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:45:14Z. --- Closing as superseded: this change is already on `main` (a34eaed4). main dxc.rs MemoryGate::try_admit takes a gate mutex and checks headroom / WANTED_AT_ONCE and increments working under it (atomic); commit exists Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1407
No description provided.