Skip to content

D3D12.X: cap eager translate-ahead backlog and gate build-ahead on physical RAM - #3615

Open
saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:d3d12x/pso-warm-ahead-cap-and-phys-ram
Open

saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:d3d12x/pso-warm-ahead-cap-and-phys-ram

Conversation

@saintwolf

@saintwolf saintwolf commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

During heavy pipeline registration bursts, the eager translate-ahead lane (next_with_warm) could drain and translate thousands of unused shaders ahead of first use, inflating DXIL/driver-cache commit and pushing 32 GB hosts into the SSD pagefile even while virtual commit headroom (AHEAD_FREE) still looked sufficient.

This PR adds:

  1. A cap on eager translate-ahead work (XCL_PSO_WARM_AHEAD, default 2 * XCL_PSO_AHEAD) passed through next_with_warm.
  2. A physical-RAM floor in ahead_room() via existing crate::ram_budget::available(), configurable via XCL_PSO_AHEAD_MIN_PHYS_MB (default 2048 MiB; 0 disables the physical-RAM gate).

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs:
    • warm_ahead_cap() (XCL_PSO_WARM_AHEAD, default ahead_cap().saturating_mul(2)).
    • ahead_min_phys_bytes() (XCL_PSO_AHEAD_MIN_PHYS_MB, default 2048 MiB; 0 disables) + phys_ram_room() using crate::ram_budget::available().
    • ahead_room() checks both big_compile_commit_free(AHEAD_FREE) and phys_ram_room(ahead_min_phys_bytes()).
    • Updated ahead_room() test skip messages to say "short of commit/RAM".
    • Unit tests: warm_ahead_cap_stops_eager_translations_without_stopping_cold_builds and ahead_min_phys_bytes_parses_default_zero_and_override.

Tested

  • Hardware: NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver 32.0.16.2140), AMD Ryzen 7 7800X3D, 31.1 GB RAM, Windows 11 build 26300, rustc 1.100.0, DXC 1.8.2502.11.
  • cargo test -p xcl --lib ahead_min_phys_bytes_parses_default_zero_and_override on adeec387: 1 passed, 0 failed.
  • cargo test -p xcl --lib hle::d3d12x::pso_async:: -- --test-threads=4: 194 passed, 0 failed.

Regression run
Matched 60 s smoke runs with identical settings (XCL_DIRECT_DXIL=1, default XCL_PSO_PRELOAD enabled so send_ahead / next_with_warm / ahead_room() run, smoke.ps1 default XCL_PREPARE=0):

main (f07e426d):

xcl-smoke v1
commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1668 (PresentX 1668)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16731 MB

this PR (adeec387):

xcl-smoke v1
commit: adeec387742f5786852472d5b6625d3ae3d3a8fe
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17568 MB

Not tested

  • 16 GB RAM hosts, AMD / Intel GPUs, Linux / Wine, and full workspace test suite locally (covered by CI).

AI use

  • Antigravity (Gemini 4 Neon) assisted with implementing the warm-ahead cap, reusing ram_budget::available(), adding XCL_PSO_AHEAD_MIN_PHYS_MB, writing unit tests, running matched smokes, and drafting this description. Reviewed by me.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head 875576c, diff read, not a merge-check):

  • The regression run does not reach the change. The head's smoke run used XCL_PSO_PRELOAD=0, with which preload_backlog() returns None (pso_async.rs ~5007) and send_ahead returns before pushing anything (~5093), so no xcl-pso-ahead-* worker starts and next_with_warm, warm_ahead_cap and the new phys_ram_free gate never run. The main block lists no such variables and shows a different frame count (1045 vs 1697), so the two blocks are not a comparison of this change; both need the same default settings.
  • The physical-RAM gate is on by default, with no switch and no measurement on smaller hosts. ahead_room() (~4978) now also needs 4 GiB of ullAvailPhys, and when it is false next_with_warm returns None before the compute-ahead, warm and cold lanes, so all ahead work stops, not only driver builds. On a 16 GB host with a title committing ~15 GB, available RAM can stay under 4 GiB for most of a session, and new pipelines are then built at first bind, the stalls the backlog exists to prevent. No XCL_* variable turns the gate off or changes the threshold, and only a 32 GB host was measured.
  • An existing helper already does this. phys_ram_free (~4966) repeats crate::ram_budget::available() (ram_budget.rs ~78). The existing tests that check ahead_room() (~10427, ~12874, ~12940) now also skip when physical RAM is short, with a message that still says "short of commit".

Fine: the warm-ahead cap is a clean flag on next_with_warm; with warm_allowed false, warmed pipelines already in cold still build and the rest stay queued; XCL_PSO_AHEAD=0 still turns off both; the new unit test covers the backlog side.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@saintwolf

Copy link
Copy Markdown
Contributor Author

Thanks for the review — addressed all three points in 0b561a2:

  1. Reused existing helper: Replaced the duplicate \GlobalMemoryStatusEx\ helper with \crate::ram_budget::available()\ and updated the three \�head_room()\ test skip messages to say \short of commit/RAM.
  2. Configurable physical-RAM floor: Added \XCL_PSO_AHEAD_MIN_PHYS_MB\ (default lowered from 4096 MiB to \2048\ MiB so 16 GB hosts aren't prematurely gated; \

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 0b561a2, since 875576c, diff read, not a merge-check):

  • The regression run does not reach the change: fixed. Both blocks now use the same settings (XCL_DIRECT_DXIL=1, default XCL_PSO_PRELOAD), so the backlog path is on and the runs compare (1668 vs 1624 frames, peak commit 16731 vs 16018 MB).
  • The physical-RAM gate is on by default, with no switch and no measurement on smaller hosts: partly fixed. XCL_PSO_AHEAD_MIN_PHYS_MB now sets the threshold and 0 turns it off (pso_async.rs ~4966-4984), and the default dropped to 2 GiB. It is still on by default in ahead_room() (~4990), still stops the compute-ahead, warm and cold lanes when it trips (next_with_warm ~4890, ~4899), and 16 GB hosts are still under Not tested.
  • An existing helper already does this: fixed. phys_ram_room (~4979) calls crate::ram_budget::available(), and the three ahead_room() tests say "short of commit/RAM".

New:

  • Whole suite not run at the head. Tested lists one unit test at 0b561a29 and the pso_async module at 875576ca; Not tested leaves the workspace suite to CI, which has no GPU.
  • Fixup commit, and the first commit's message is now wrong. 0b561a29 (no body) changes code 875576ca added, and 875576ca still says ahead work needs "at least 4 GiB of free physical RAM (GlobalMemoryStatusEx::ullAvailPhys)". The two should be squashed into one commit with a correct message.

Fine: the warm-ahead cap is still a separate flag and translated pipelines already in cold still build; XCL_PSO_AHEAD=0 still turns off both lanes; phys_ram_room lets work through when available() returns 0 or the threshold is 0, and the parse helper has a test.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

…ysical RAM

Add XCL_PSO_WARM_AHEAD (default 2 * XCL_PSO_AHEAD) to cap eager translate-ahead work in next_with_warm, and gate ahead_room() on available physical RAM via crate::ram_budget::available() (XCL_PSO_AHEAD_MIN_PHYS_MB, default 2048 MiB; 0 disables) in addition to virtual commit headroom.
@saintwolf
saintwolf force-pushed the d3d12x/pso-warm-ahead-cap-and-phys-ram branch from 0b561a2 to adeec38 Compare December 1, 2026 21:48
@saintwolf

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up review — squashed into a single clean commit (adeec387) on main (f07e426d) with an accurate commit message documenting XCL_PSO_WARM_AHEAD, crate::ram_budget::available(), and XCL_PSO_AHEAD_MIN_PHYS_MB (default 2048 MiB; 0 disables).

(Sorry for the truncated previous comment — PowerShell mangled inline backticks.)

AI use: Antigravity (Gemini 4 Neon) assisted with squashing the commits and drafting this reply.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head adeec38, since 0b561a2, diff read, not a merge-check; checks red):

  • Fixup commit and stale message: fixed. The PR is one commit, adeec387, whose message describes ram_budget::available() and XCL_PSO_AHEAD_MIN_PHYS_MB (default 2048 MiB, 0 off). Its tree is identical to 0b561a29, so no code changed.
  • The physical-RAM gate is on by default and unmeasured on smaller hosts: partly fixed, unchanged. The 2 GiB gate is still on by default in ahead_room() (pso_async.rs ~4987-4992) and still stops the compute-ahead, warm and cold lanes when it trips (~4891, ~4899); 16 GB hosts are still under Not tested.
  • Whole suite not run at the head: still open.

New:

  • The smoke block names 0b561a29, not the head. PR description now fails ("needs an xcl-smoke block made on this PR's head commit adeec38"); the run has to be redone on adeec387 even though the tree is the same.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@saintwolf

Copy link
Copy Markdown
Contributor Author

Updated the PR description with a fresh 60 s smoke on head commit adeec387 (1674 frames, 60 61 60, 0 removals/crashes).

All substantive review points are addressed (reused ram_budget::available(), added XCL_PSO_AHEAD_MIN_PHYS_MB with a conservative 2048 MiB default and 0 to disable, squashed to one clean commit, matched head smoke). The remaining items (16 GB hardware testing and running the full workspace suite locally beyond CI) are explicitly documented under Not tested; leaving this as-is for human maintainer review.

AI use: Antigravity (Gemini 4 Neon) ran the head smoke and drafted this reply.

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: f07e426
head: adeec38
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2906 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (pso_async.rs, +87 -13). No correctness problem found.

  • next_with_warm skips the warm (translate-ahead) queue once WARMED reaches XCL_PSO_WARM_AHEAD (default 2 x ahead_cap = 8192). Pipelines already warmed still build ahead. WARMED only grows, so like AHEAD_BUILDS this is a per-run total, not a cap on work in flight.
  • ahead_room also needs ram_budget::available() of at least XCL_PSO_AHEAD_MIN_PHYS_MB (default 2048, 0 off; an unknown value, 0 from available(), lets it through).
  • hle::d3d12x::pso_async:: (195 tests): 3 of 3 runs passed.
  • Mutation: if true || warm_allowed (the cap ignored) fails backlog_tests::warm_ahead_cap_stops_eager_translation_without_blocking_builds. Good.
  • Not tested by any test: the RAM gate in ahead_room (only its parser is tested), and the cap through the real worker loop.
  • No retail title on this machine. In the PR's own smoke pair the peak commit went from 16731 MB (main) to 17568 MB (this PR), which a 60 s run may not reach the cap in. So the commit saving the description aims at is not shown by that pair.
  • Added 2026-12-02, after bmjask's review (from reading, not measured):
    • After the warm cap, entries do stay in the warm queue. Main already does the same with cold once ahead_cap is reached, and those entries hold finished translations. A pipeline that is built or released drops its closure, so what stays for it is the small Build.
    • After the cap, later pipelines are translated at first use for the rest of the run. That is the trade this PR makes; whether 8192 is the right number needs a long title run.
      performance: by default, translate-ahead stops after 8192 programs per run, and build-ahead pauses below 2 GB of available physical RAM: less background work on small machines, more translations at first use there. Not measured here.
      verdict: safe to merge
      hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@jsalzy

jsalzy commented Dec 1, 2026

Copy link
Copy Markdown

merge-check claim
head: adeec38

@jsalzy

jsalzy commented Dec 1, 2026

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: adeec38
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none
review: whole diff read (pso_async.rs, +87/-13). No correctness problem found; both new tests pass (warm_ahead_cap_stops_eager_translation_without_blocking_builds, ahead_min_phys_bytes_parses_default_zero_and_override). Agree with the first check: WARMED only grows, so XCL_PSO_WARM_AHEAD (default 8192) is a per-run total of translations ahead rather than a cap on the backlog – after it, no pipeline is translated ahead for the rest of the run, even with commit and RAM to spare; worth saying in the title or doc comment. The RAM gate costs one GlobalMemoryStatusEx per backlog loop and lets an unknown value (0) through. Not covered by a test: the cap's wiring to WARMED in the worker loop and the RAM gate in ahead_room (only the parser). Minor: the description names the test warm_ahead_cap_stops_eager_translations_without_stopping_cold_builds; in the code it is warm_ahead_cap_stops_eager_translation_without_blocking_builds. No duplicate found (searched open and merged PRs for translate-ahead, build-ahead and XCL_PSO_AHEAD).
performance: not measured.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of adeec387: 4 finding(s) (3 high, 1 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/pso_async.rs:5048: WARMED only ever goes up, so once it reaches warm_ahead_cap() translate-ahead is off for the rest of the process, and pipelines translated after that are never built ahead. (inline)
  2. High crates/xcl/src/hle/d3d12x/pso_async.rs:4902: Once the warm cap is reached nothing pops Backlog::warm any more, so entries pile up for the life of the process together with their Warm closures, including builds already claimed, released or completed. (inline)
  3. High crates/xcl/src/hle/d3d12x/pso_async.rs:4990: Not certain about this one, because it depends on typical free RAM on 16 GB hosts, which wasn't tested: the physical-RAM floor is put into ahead_room(), which turns off all build-ahead work, not just speculative DXC translation. (inline)
  4. Medium crates/xcl/src/hle/d3d12x/pso_async.rs:5065: see below.

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/pso_async.rs:5065: WARMED is incremented only after a translation finishes, while the cap is checked earlier under the lock, so concurrent workers can all pass the check. With 2-4 backlog workers and WARMED == cap-1, each takes a Step::Warm (translations take milliseconds to seconds) before any increments, so up to cap + workers - 1 translations run. Incrementing when the step is handed out, under the list lock, would make the cap a real bound.

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

let next = g.next(ahead_room(), AHEAD_BUILDS.load(Ordering::Relaxed) < ahead_cap());
let next = g.next_with_warm(
ahead_room(),
WARMED.load(Ordering::Relaxed) < warm_ahead_cap(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: WARMED only ever goes up, so once it reaches warm_ahead_cap() translate-ahead is off for the rest of the process, and pipelines translated after that are never built ahead. A retail title makes ~51,000 lazy pipelines in its first seconds. The workers translate 8,192 (WARMED also counts translations a bind later claimed, and ones that panicked), and from then on warm_allowed is false for good. The remaining graphics pipelines stay in warm and never reach cold, even while AHEAD_BUILDS is far below ahead_cap(), so their first binds go back to the 7-15 s driver-build stalls (the 156 s no-frame case) that build-ahead exists to prevent. Gating on outstanding work instead (e.g. allow warm only while AHEAD_BUILDS + cold.len() < ahead_cap()) bounds memory without turning it off.

match warm {
Some(w) => return Some((build, Step::Warm(w))),
None => self.cold.push_back(build),
if warm_allowed {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: Once the warm cap is reached nothing pops Backlog::warm any more, so entries pile up for the life of the process together with their Warm closures, including builds already claimed, released or completed. Before this PR the drain loop also discarded entries that were no longer unclaimed. After the cap, every new lazy graphics pipeline send_ahead pushes stays there: a bound-and-built one keeps its Arc, and an unused one also keeps its closure and captured shader data. g.len() and the BACKLOG stat keep growing and memory goes up, the opposite of the PR's aim. Still draining claimed/finished entries when the cap is reached would stop the growth.

ahead_room_for(
ahead_cap() > 0,
|| super::real::big_compile_commit_free(AHEAD_FREE),
|| super::real::big_compile_commit_free(AHEAD_FREE) && phys_ram_room(ahead_min_phys_bytes()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: Not certain about this one, because it depends on typical free RAM on 16 GB hosts, which wasn't tested: the physical-RAM floor is put into ahead_room(), which turns off all build-ahead work, not just speculative DXC translation. That includes driver builds of pipelines that are already translated (cold) and the new-compute lane. On a 16 GB host running a title, available physical RAM often drops below 2048 MiB, so ahead_room() returns false and next_with_warm returns None at if !ahead. Cheap, already-translated pipelines stay unbuilt and the title stalls at first bind. Applying the RAM gate only to the warm (translate) lane would keep the protection where it matters.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@throny throny added needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed ready-to-merge Has 2 independent safe merge-checks on current head (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants