Shaders: hold the --precompile DXC compiles to a share of the RAM #1752
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1762"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Pardok on 2026-11-24T20:22:00Z.
Precompile: hold the DXC compiles to a share of the RAM
xcl shaders --precompileon a retail pack (26 503 programs) ran to ~100 GB of commit, most of it in the page file, and stalled for tens of minutes on the compute programs near the end of the pack.wait_for_memoryadmits a compile when the free commit is at least 6 GB plus 1 GB per running compile, and an auto-growing page file keeps that true however much the compiles hold. It also assumes a compile takes at most ~0.7 GB; the pack'sCS_RaytracingResolve_*programs take 2 – 15 GB each in DXC, and four translated compute programs (CS_ScreenProbes_*,CS_Primary_Shade_*; 4.6 – 155 MB of HLSL) do not compile at all within 24 GB.This is a mitigation, not a fix for those four programs: a compile already running keeps growing, and the cap only stops further ones from starting.
What is in it
gpu/recomp/dxc.rs:set_memory_cap/default_memory_cap(XCL_DXC_MEMORY_GB, default half of the RAM, 0 = none),private_bytes(the process's private commit),cap_admits, andwait_for_memoryusing it when a cap is set. Under a cap a compile starts at once below a quarter of the cap, one per 500 ms up to the cap, and not while another runs at the cap (one alone always goes, so nothing deadlocks); the 60 s wait no longer lets one through. Without a cap (a running title) nothing changes.shaders.rs:--precompilesets the cap and prints it.private_bytesreading this process.Tested
cargo test --release -p xcl --lib -- memory_cap private_bytes: 2 passed, 0 failed, 0 ignored (on this PR's commit, rebased ontomainb9b6ea62).xcl shaders <pack> --precompile --only cs, 15 compile threads, run inside a 24 GB job object so a runaway would be killed: peak ~24 GB (before, with the same threads and no cap: over 100 GB, 20 GB of it resident), the process was not killed, and 2 685 compute programs compiled in 40 min with 4 errors (DXC "not enough memory" on the four programs above).--precompileof the same pack, same limits, finished (25 134 compiled, 10 434 already cached, 22 errors, 390 GS programs skipped).Regression run
Not run yet (draft):
scripts/smoke.ps1onmainand on this commit. The change does not run in a title:--precompileis the only caller ofset_memory_cap.Not tested
cargo test --workspace -- --test-threads=4(only the two new tests were run).scripts/smoke.ps1on a title (see above).AI use
wait_for_memory, traced which programs grew), wrote the change, the tests and this description. The runs above were done on the author's machine under the author's direction.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T23:14:22Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:36:21Z.
Regression run of
3cd15cb7on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 101 % of
main's frames, 100 % 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; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:41:58Z.
Triage (#1607) – head
3cd15cbOther PRs work on the same
--precompilememory problem in different ways. #1756 is a script that kills the precompile at a private-commit budget. #2950 reserves an estimated amount of memory per DXC job based on its HLSL size. #1638 runs DXC in worker processes, each with its own cap. None of them caps the process's private bytes insidewait_for_memorythe way this PR does.The PR is built on the old
wait_for_memory. Main has since replaced it withMemoryGate::wait_withingpu/recomp/dxc.rs, so the cap has to be ported to that before this can merge. Under a cap, a compile admitted by the fallbackWORKING.compare_exchange(0, 1)does not updateLAST_ADMIT_MS. That is minor.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T22:15:38Z.
Code review location:
crates/xcl/src/gpu/recomp/dxc.rs; line 441Low: Returning
0whenK32GetProcessMemoryInfofails makes the cap fail open:cap_admitstreats any usage below one quarter of the cap as safe, so a failed measurement can admit more precompile workers while the actual usage is unknown. Could this return anOptionand handle an unavailable reading conservatively (or stop with a diagnostic), with a test for the API-failure path? AI-assisted review: GPT-6 helped inspect the admission path; I traced the failed query throughcap_admits.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T22:15:38Z.
Review: COMMENTED
AI-assisted review: GPT-6 helped inspect the memory-cap admission path; I checked the API failure path and its current caller.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T22:16:51Z.
Code review location:
crates/xcl/src/gpu/recomp/dxc.rs; line 503Medium: This timestamp CAS does not reserve the admission slot before
WORKINGis incremented. Whenworking == 0,cap_admitsreturns true regardless ofused; concurrent waiters can therefore all reach this line before any of them incrementsWORKING. If they observe the same millisecond value, eachcompare_exchange(last, now)can succeed (the later CAS may comparenowwith itself), allowing several large DXC jobs to start above the quarter-cap threshold. Could admission reserve the first worker atomically before returning, with a barrier-based concurrency test? AI-assisted review: GPT-6 helped trace the admission race; I checked the predicate and ordering in the current diff.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T22:16:51Z.
Review: COMMENTED
AI-assisted review: GPT-6 helped inspect the capped admission race; I verified the predicate, timestamp CAS, and worker-count ordering.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.