Skip to content

D3D12.X: XCL's own heaps get their residency priority by default - #3582

Open
throny wants to merge 1 commit into
xcl-dev:mainfrom
throny:residency-priority-default
Open

throny wants to merge 1 commit into
xcl-dev:mainfrom
throny:residency-priority-default

Conversation

@throny

@throny throny commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

XCL_RESIDENCY_PRIORITY (#3156) gives XCL's own heaps (render-target arenas, window tile pools, texture page pools holding targets) D3D12_RESIDENCY_PRIORITY_HIGH, so that over the video memory budget Windows demotes idle texture pages first. It was off unless XCL_RESIDENCY_PRIORITY=1. This turns it on by default; XCL_RESIDENCY_PRIORITY=0 turns it off. Part of #505.

Evidence: on an RTX 4080 16 GB (Windows), four world runs on #3156 gave 3.37 / 3.49 presents/s with it against 2.22 / 2.39 without (+50 %). lucsoft's A/B on an AMD RX 7800 XT under Linux/RADV (comment on #3156) shows no change. Missing: a Windows + AMD run. If you have one, please run the title in the world with and without XCL_RESIDENCY_PRIORITY=0 and post the presents/s here or on #3156.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: an explicit parse switch_value: unset is on; empty, 0, off, false and no (any case) are off; 1, on, true and yes are on; any other value stays on and is logged. Tests cover each class. XCL_UMA_UPLOAD_PRIORITY keeps main's own parse and default (with XCL_UMA_DRIVER=mixed, the GPU_UPLOAD segment ranks below the HIGH heaps unless it is set to 1; the README says so).
  • README.md: one bullet for the heap priority and the switch.

Tested

  • NVIDIA GeForce RTX 4080, Windows 11 build 26300, Rust stable-x86_64-pc-windows-msvc, debug for the tests, release for the smoke runs. Nothing else was on the GPU.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on head 30ec035c (after bmjask's third review): 3006 passed, 0 failed, 52 ignored, 25 SKIPPED lines.
  • SKIPPED on this adapter: the wave64 variants of the gpu::recomp::lower / lower_dxil tests and dispatch_chain_native_wave64_builds_whole (no wave64); heap_window_out_of_memory_falls_back_to_the_switch_form and hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap (no heap windows); shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (driver cache cannot be disabled).

Regression run

main 817eb1fc9:

xcl-smoke v1
commit: 817eb1fc9fb0763008ae5d8de1f7f586f442b51d
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17215 MB

this PR's head:

xcl-smoke v1
commit: 30ec035c68dac1054db122f3a485898e92af810e
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 17545 MB

Not tested

AI use

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA 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

merge-check
base: b2b1f10
head: 5b8ac52
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+20/-4). #3156's residency priority (HIGH for XCL's render-target arenas, window tile pools and texture-page pools holding targets) is now on unless XCL_RESIDENCY_PRIORITY is 0 (trimmed); any other value, false / off included, keeps it on, like the repo's other default-on switches. Findings: (1) The "HIGH only grows" point from #3156 now applies to everyone. Pools keep HIGH after their target pages are freed (vram.rs ~2187; cleared only when the heap is reclaimed, ~1728), and the window tile pools hold the title's GPU-visible memory by default. Logged HIGH sets were about 12 GiB on a 5070 Ti and at least 7.6 GiB on lucsoft's AMD card, so on an 8 GB card the HIGH set alone would pass the budget (unverified) and the priority could only demote sampled textures. Nobody has an on / off run on the 8 GB card that motivated #3156. (2) Thin evidence for a default. The +50 % is from #3156 on an older base with a local input-timing patch on one RTX 4080, and the 5070 Ti result was a lab cherry-pick. AMD was run only on Linux with vkd3d-proton (no effect). Windows + AMD, 8-12 GB cards and Intel are missing. (3) Peak commit rises with it on in both runs that exist: 16355 -> 17926 MB in this PR's smoke, 17174 -> 18004 MB in my #3156 run with the switch. That's within the gate but unexplained, since neither run went over the budget. (4) The new test (vram.rs ~4162) covers only the env parse; nothing checks that place_on_pages / remap_if_unmapped reach keep_pools. (5) README ~420-422: page pools get HIGH when a target lands on them, not when they're made, and they keep it. Every non-target texture page is NORMAL, not only idle ones. Fine: a failing ID3D12Device1 cast or SetResidencyPriority is logged once and the heap keeps the default (~1038). It never sets MAXIMUM and makes one call per heap, none per frame. Both smoke blocks are present (120 s, 3380 vs 3370 frames). A 60 s run here reaches the calls but stays under the 16 GB budget, so it shows that nothing breaks and the peak-commit delta, not the speed-up or a small-card regression.
performance: 60 s smoke of a retail title, main b2b1f10 vs this merge (5b8ac52): 1671 -> 1657 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 17394 -> 18126 MB, 0 device removals, 0 crashes. With the priority now on by default, the log shows window tile pools getting HIGH from 1 s in. On a 16 GB card a 60 s run stays under the budget, so this shows the calls break nothing (no device removal, frames at 99 %), not the speed-up or a small-card regression. Peak commit is 5.6 % above main here, smaller than the PR's own +9.6 %.
verdict: not yet: the code is fine and passes here, but as a default it needs the evidence #3156 didn't have: an on / off run on an 8-12 GB card (where the HIGH set can pass the budget, finding 1) and a Windows + AMD run; with those it would be safe to merge
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

One correction to the evidence above: the four runs behind "+50 %" used XCL_TWO_PASS_MB=512, which makes XCL skip a share of mesh draws (13–21 % in those runs, similar with and without the switch, so the comparison holds). With the default two-pass reserve and no draws skipped: 1.90 presents/s without XCL_RESIDENCY_PRIORITY (run 362) vs 3.31 with it (run 389, main 6bfb5c51 + #3395 built in, switch of #3395 unset), RTX 4080 16 GB, 900 s each, same save and inputs.

AI use: Claude Code (Claude Opus 5.5).

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Same-build check for the default flip: main 6bfb5c51 + #2987 (its switch unset), RTX 4080 16 GB, default two-pass reserve, no draws skipped: 2.19 presents/s without XCL_RESIDENCY_PRIORITY (run 395) against 3.31 with it on the same main (run 389), and 3.04 / 2.97 with it plus #2987's XCL_SPARSE_SYSMEM=1 (runs 394, 396). No device removal in any of them.

AI use: Claude Code (Claude Opus 5.5).

@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 5b8ac52b: 3 finding(s) (1 high, 2 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/vram.rs:1016: Turning XCL_RESIDENCY_PRIORITY on by default puts XCL's arenas, window pools and target pools at HIGH, while the UMA GPU_UPLOAD segment (uma_driver.rs:336, XCL_UMA_UPLOAD_PRIORITY) still needs =1 and stays at NORMAL by default, which.... (inline)
  2. Medium crates/xcl/src/hle/d3d12x/vram.rs:2192: see below.
  3. Medium crates/xcl/src/hle/d3d12x/vram.rs:1017: The parse has flipped for values other than 0/1: an empty value, false or off now turn the feature on, where before only 1 did. (inline)

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/vram.rs:2192: A pool heap that gets HIGH in keep_pools stays HIGH (and in pools.high) until it's reclaimed, even after its target pages are released and their tiles reused by sampled textures. With the switch now on by default, HIGH spreads to more and more pools over a session. A long session that creates and frees many transient render targets returns their pages to the pool (cooling/idle), sampled textures take them, and the heaps stay HIGH. Eventually most 64 MiB pools are HIGH, so over budget the idle texture pages are no longer demoted first and the #3156 gain shrinks. Dropping a heap back to NORMAL when its last target page is released would keep the ordering meaningful.

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.

/// `XCL_RESIDENCY_PRIORITY=1` (read once, off by default): XCL's own heaps get the residency
/// `XCL_RESIDENCY_PRIORITY` (read once, on unless it is `0`): XCL's own heaps get the residency
/// priority of their role (`role_priority`) when they are made; nothing is called per frame.
fn residency_priority_enabled(v: Option<&str>) -> bool {

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: Turning XCL_RESIDENCY_PRIORITY on by default puts XCL's arenas, window pools and target pools at HIGH, while the UMA GPU_UPLOAD segment (uma_driver.rs:336, XCL_UMA_UPLOAD_PRIORITY) still needs =1 and stays at NORMAL by default, which inverts the order the design assumes. On a default run over the video memory budget, the GPU_UPLOAD segment every console program reads its buffers from becomes the lowest-priority XCL heap, so Windows demotes it to system memory before the HIGH render-target and window pools, and every shader read of title buffers goes over PCIe. The test comment at ~4170 ("nothing gets MAXIMUM (the UMA upload segment's...)") assumes that segment ranks above these heaps. Defaulting XCL_UMA_UPLOAD_PRIORITY on in the same change would keep the order.

Comment thread crates/xcl/src/hle/d3d12x/vram.rs Outdated
/// `XCL_RESIDENCY_PRIORITY` (read once, on unless it is `0`): XCL's own heaps get the residency
/// priority of their role (`role_priority`) when they are made; nothing is called per frame.
fn residency_priority_enabled(v: Option<&str>) -> bool {
v.map_or(true, |v| v.trim() != "0")

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.

Medium: The parse has flipped for values other than 0/1: an empty value, false or off now turn the feature on, where before only 1 did. A user or script that set XCL_RESIDENCY_PRIORITY= or =false to keep it off (which worked before this PR) now silently gets HIGH priorities. residency_priority_is_on_by_default only tests None, "1", "0" and " 0 ". Treating empty/false/off as off, or logging when an unrecognised value is read, would avoid the surprise.

@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 force-pushed the residency-priority-default branch from 5b8ac52 to 6f5eb63 Compare December 2, 2026 18:56
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. Rebased onto current main and amended in 6f5eb630.

1. High: GPU_UPLOAD segment below the HIGH heaps. Fixed. The GPU_UPLOAD segments only exist with XCL_UMA_DRIVER=mixed:..., which is opt-in. The default NVIDIA window is one CUSTOM L0 heap, and other vendors import the title's pages. Both of those are in system memory, so nothing changes for a default run. With mixed, though, the segment would have stayed at NORMAL below the new HIGH heaps, as you say. When XCL_UMA_UPLOAD_PRIORITY is unset it now follows XCL_RESIDENCY_PRIORITY, so the segment gets MAXIMUM whenever the pools get HIGH. An explicit value still overrides it (uma_driver.rs:334-343). Test: upload_priority_follows_residency_priority (uma_driver.rs:721).

2. Medium: pools stay HIGH after their target pages are freed. Not changed in this PR. This is how #3156 worked when it merged (a pool loses HIGH only in take_heap, vram.rs:2069). Setting a pool back to NORMAL when its last target page goes needs a count of target pages per pool, kept up to date through release_tiles, page sharing between aliases, and the idle and reuse paths. That is a separate change with its own test, so I'll open it as a follow-up rather than add it to the default flip. The README now says that a pool keeps HIGH until it is reclaimed.

3. Medium: the parse flipped for values other than 0 and 1. Fixed. The parse is now explicit (switch_value, vram.rs:1345): 0, off, false, no and an empty value turn it off; 1, on, true and yes turn it on (trimmed, any case). Unset, or any other value, keeps it on, and an unrecognised value is logged as a warning. The test residency_priority_is_on_by_default (vram.rs:4649) covers all of these. The README lists the off values.

Tests: cargo build --workspace ok; cargo test -p xcl --lib hle::d3d12x::vram: 86 passed, 0 failed, 1 ignored; hle::d3d12x::uma_driver: 9 passed, 0 failed.

One side effect to know: XCL_UMA_UPLOAD_PRIORITY now reads true / on as on (before, only 1 was on, and true / on / 2 meant off). Values it does not know follow XCL_RESIDENCY_PRIORITY.

Head is now 6f5eb630, rebased on main 817eb1fc. The whole suite: 3006 passed, 0 failed. Smoke blocks are in the description. Could you re-check?

AI use: Claude Code (Claude Opus 5.5).

@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 6f5eb630: 2 finding(s) (2 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:337: XCL_UMA_UPLOAD_PRIORITY follows XCL_RESIDENCY_PRIORITY when it's unset, so flipping the latter on by default also gives every mixed window's GPU_UPLOAD segment D3D12_RESIDENCY_PRIORITY_MAXIMUM by default. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:341: The new parsing changes the meaning of existing settings without saying so. (inline)

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.

Comment thread crates/xcl/src/hle/d3d12x/uma_driver.rs Outdated
fn upload_priority_wanted() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var("XCL_UMA_UPLOAD_PRIORITY").is_ok_and(|v| v.trim() == "1"))
*ON.get_or_init(|| upload_priority_enabled(std::env::var("XCL_UMA_UPLOAD_PRIORITY").ok().as_deref(), super::vram::residency_priority_wanted))

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.

Medium: XCL_UMA_UPLOAD_PRIORITY follows XCL_RESIDENCY_PRIORITY when it's unset, so flipping the latter on by default also gives every mixed window's GPU_UPLOAD segment D3D12_RESIDENCY_PRIORITY_MAXIMUM by default. That change isn't in the PR description, and the #3156 evidence covers only XCL_RESIDENCY_PRIORITY. With XCL_UMA_DRIVER=mixed:1536:1792 and the upload switch unset, the segment was NORMAL before and is now pinned above the HIGH render-target arenas and tile pools, so when over budget Windows demotes the render targets first. Keeping the upload switch's own default (off unless set to 1) would limit the PR to what was measured.

Comment thread crates/xcl/src/hle/d3d12x/uma_driver.rs Outdated
}

/// `upload_priority_wanted` from the switch's value and whether XCL's heaps get their priorities.
fn upload_priority_enabled(v: Option<&str>, residency_on: impl FnOnce() -> bool) -> bool {

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.

Medium: The new parsing changes the meaning of existing settings without saying so. An unknown XCL_UMA_UPLOAD_PRIORITY value (e.g. 2, or a typo like disable) was off before, since only 1 meant on, but now silently falls back to the residency switch, which is on, with no warning (the test upload_priority_enabled(Some("2"), || true) locks this in). And for XCL_RESIDENCY_PRIORITY an empty value counts as off (vram.rs:1347), although the description says 'on unless the value is 0' and other switches (gpu_awake.rs parse_mode) treat empty as unset. A launcher passing XCL_RESIDENCY_PRIORITY= to mean default turns the feature off with nothing logged. Treating empty as unset, and warning and keeping the old meaning on unknown values, would avoid both.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@throny
throny force-pushed the residency-priority-default branch from 6f5eb63 to 8ea8619 Compare December 2, 2026 21:35
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. Both points are addressed in 8ea8619c, which is amended into the PR's single commit.

  1. XCL_UMA_UPLOAD_PRIORITY following XCL_RESIDENCY_PRIORITY gave mixed runs MAXIMUM by default, which was not measured. Agreed. The follow behaviour is removed: crates/xcl/src/hle/d3d12x/uma_driver.rs is back to exactly what it is on main, so the segment gets MAXIMUM only with XCL_UMA_UPLOAD_PRIORITY=1. switch_value and residency_priority_wanted in vram.rs (lines 1345 and 1360) are private again, as uma_driver no longer uses them. The PR now changes only XCL_RESIDENCY_PRIORITY, which is what D3D12.X: XCL's render-target arenas and window pools get a residency priority #3156 measured.

    This brings back the interaction the earlier review raised: a GPU_UPLOAD segment without the upload switch now ranks below the HIGH heaps. XCL_UMA_DRIVER=mixed:... is opt-in (decide in uma_driver.rs), so only runs that set it are affected. Neither order has been measured on a mixed run, so the README now says it directly (README.md lines 418-424): without XCL_UMA_UPLOAD_PRIORITY=1 those segments stay at the default priority and are demoted before the HIGH heaps. The commit message says the same.

  2. The parse changes the meaning of existing values. With the upload switch back to main, its part of this finding is gone: 2, disable and every other value except 1 are off again. The upload_priority_enabled(Some("2"), ..) test is removed with it. For XCL_RESIDENCY_PRIORITY I kept the current parse on purpose:

    • Empty value. It stays off. On main an empty value was off (only 1 was on). Treating it as unset would silently turn the feature on for anyone who set XCL_RESIDENCY_PRIORITY= to keep it off, which is the opposite surprise the previous review raised.
    • off, false, no. These are off.
    • Other values. Any other value keeps the new default (on) and logs a warning that names the value (vram.rs, residency_priority_wanted).
    • Where it is documented. The commit message, the README bullet and residency_priority_is_on_by_default all state this.

    The PR description is out of date: it says "on unless the value is 0" and lists only 0/0 as tested. I will update it to match the code.

Tested on an RTX 4080 (debug build) with cargo build --workspace (ok).

  • cargo test -p xcl --lib uma_driver: 8 passed, 0 failed.
  • cargo test -p xcl --lib residency_priority: 1 passed.
  • cargo test -p xcl --lib vram -- --test-threads=4: 88 passed, 1 failed, 1 ignored. The failure is title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, which the filter also matches. It fails the same way with XCL_RESIDENCY_PRIORITY=0, and passes alone and with --test-threads=1 (89 passed, 0 failed, 1 ignored). That points to interference between tests running in parallel, not to this change.

The whole suite was not rerun for this push.

Pushed as 8ea8619c. The whole suite passes there (see the description), and the smoke blocks are updated. @bmjask could you re-check?

AI use: Claude Code (Claude Opus 5.5).

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 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 8ea8619c: 1 finding(s) (1 medium), most severe first.

Re-review at 8ea8619c. XCL_UMA_UPLOAD_PRIORITY no longer follows XCL_RESIDENCY_PRIORITY, which addresses the unannounced MAXIMUM default from the 6f5eb630 review, but decoupling them causes the issue below.

  1. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:336: see below.

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:336: With XCL_RESIDENCY_PRIORITY on by default and XCL_UMA_UPLOAD_PRIORITY still off by default, the XCL_UMA_DRIVER=mixed GPU_UPLOAD segments, which every console program reads its buffers from, now rank below the new HIGH heaps. With XCL_UMA_DRIVER=mixed, neither variable set, and the process over its video memory budget, all heaps used to be NORMAL. Now the arenas, window pools and target pools are HIGH while the GPU_UPLOAD segments stay NORMAL, so Windows demotes the console's UMA buffers first and every GPU read of title buffers goes over PCIe. That's the opposite of what the role_priority test comment says ('the UMA upload segment's, which every console program reads from'), and the README says it wasn't measured. Raising the upload segments at least to HIGH whenever residency priority is on, unless explicitly turned off, would keep them from being demoted first.

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.

@throny
throny force-pushed the residency-priority-default branch from 8ea8619 to e94f2df Compare December 2, 2026 23:15

@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 e94f2dfe: 2 finding(s) (2 medium), most severe first.

Re-review at e94f2dfe. The GPU_UPLOAD segments now default to HIGH, which addresses the demotion order from the 8ea8619c review. Two new items below.

  1. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:362: Not certain about this one, because it depends on whether the driver allocates VA inside SetResidencyPriority: SetResidencyPriority now runs by default for every GPU_UPLOAD segment inside the critical window between VirtualFree of the pl.... (inline)
  2. Medium crates/xcl/src/hle/d3d12x/uma_driver.rs:339: Any set value of XCL_UMA_UPLOAD_PRIORITY other than "1" (0, on, true, yes, empty) puts the GPU_UPLOAD segments at NORMAL, below XCL's now default-on HIGH heaps. (inline)

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.

Comment thread crates/xcl/src/hle/d3d12x/uma_driver.rs Outdated
device.CreateHeap(&desc, &mut heap).map_err(|e| format!("CreateHeap{}: {e}", if watch { " (write-watched)" } else { "" }))?;
let heap = heap.ok_or("CreateHeap")?;
if upload && upload_priority_wanted() {
if let Some(prio) = upload.then(upload_priority_wanted).flatten() {

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.

Medium: Not certain about this one, because it depends on whether the driver allocates VA inside SetResidencyPriority: SetResidencyPriority now runs by default for every GPU_UPLOAD segment inside the critical window between VirtualFree of the placeholder and CreatePlacedResource/Map, and it also runs on segments that are then thrown away because Map lands at the wrong address. On every default mixed-window remake, after the placeholder at want is released, a driver call (the ID3D12Device1 cast plus SetResidencyPriority) runs before Map. If any driver-internal VA allocation in it takes the freed range, Map returns another address, so the segment is refused and becomes CUSTOM, or the remake fails and stops the process (the test module notes that anything landing in the window meanwhile stops the process). Before this PR it ran only with an opt-in variable. Setting the priority after the p == want check would avoid both the race and the wasted call.

Comment thread crates/xcl/src/hle/d3d12x/uma_driver.rs Outdated
fn upload_priority(upload_env: Option<&str>, residency_on: bool) -> Option<D3D12_RESIDENCY_PRIORITY> {
match upload_env {
Some(v) if v.trim() == "1" => Some(D3D12_RESIDENCY_PRIORITY_MAXIMUM),
Some(_) => None,

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.

Medium: Any set value of XCL_UMA_UPLOAD_PRIORITY other than "1" (0, on, true, yes, empty) puts the GPU_UPLOAD segments at NORMAL, below XCL's now default-on HIGH heaps. That brings back the ordering this change removes and contradicts the README's 'any other value of it keeps them at the default' (the default is HIGH). With XCL_UMA_DRIVER=mixed and XCL_UMA_UPLOAD_PRIORITY=on/true (expecting more priority) or =0 (expecting the default without MAXIMUM), upload_priority returns None, so the segments every console program reads stay NORMAL while the arenas, window pools and target pools are HIGH, and over budget Windows demotes the title's buffers first. Nothing is logged, and the test asserting upload_priority(Some("on"), true) == None locks this in. Parsing it with switch_value like XCL_RESIDENCY_PRIORITY, and keeping HIGH for anything but an explicit off, would match the README.

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
Over its video memory budget a process has heaps demoted to system memory,
and Windows has no hint which matter. XCL_RESIDENCY_PRIORITY (xcl-dev#3156) gives
render-target arenas, window tile pools and texture page pools holding
targets HIGH, so idle texture pages are demoted first. It was off unless
XCL_RESIDENCY_PRIORITY=1.

Measured on an RTX 4080 16 GB (Windows) in four world runs on xcl-dev#3156:
3.37 / 3.49 presents/s with it against 2.22 / 2.39 without (+50 %).
lucsoft's A/B on an AMD RX 7800 XT under Linux/RADV shows no change.
Windows + AMD is not measured yet.

It is now on unless XCL_RESIDENCY_PRIORITY is 0, off, false, no or empty
(empty was off before too); any other unknown value keeps it on and is
logged. The parse (switch_value, residency_priority_enabled) has a unit test.

The GPU_UPLOAD segments of XCL_UMA_DRIVER=mixed:..., the title's buffers
every console program reads, get HIGH along with the heaps while
XCL_RESIDENCY_PRIORITY is on, so they are not demoted before them (bmjask's
review). XCL_UMA_UPLOAD_PRIORITY is read as the same kind of switch: on
(1, on, true, yes) gives them MAXIMUM as before, off (0, off, false, no,
empty) leaves them at NORMAL as on main, and another value keeps the default
and is logged (upload_priority, tested). Their priority is now set once all
segments are mapped in their places, not between the release of a segment's
placeholder and its Map, and not for a segment that is given up.

Part of xcl-dev#505

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 078358a
head: e94f2df
merge: clean
build: ok
tests: 3008 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 4 medium, 3 nits (below)
performance: 60 s smoke run: 1669 → 1650 frames (98 % of main), peak commit 17577 → 17526 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 233 s there, 0 device removals, 0 crashes, 4.1 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: PR description is red; otherwise no blocking finding, the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: Turns XCL_RESIDENCY_PRIORITY on by default with an explicit parse (0/off/false/no/empty off, unknown values kept on and logged). At this head the GPU_UPLOAD segments of an XCL_UMA_DRIVER=mixed window also get HIGH by default while it is on (MAXIMUM with XCL_UMA_UPLOAD_PRIORITY=1). The code is correct for what it does. What held it at Foniass's last check is still open: no on/off run on an 8-12 GB card and no Windows + AMD run for a default-on change.

Medium

  1. Default flip still without the evidence asked for. Earlier finding still open. The +50 % comes from one RTX 4080 16 GB (throny's same-build runs 2.19 vs 3.31 presents/s). There is still no on/off run on an 8-12 GB card, where the HIGH set (window tile pools alone logged about 12 GiB on a 5070 Ti) could exceed the budget by itself (unverified), and no Windows + AMD run.
  2. Pools keep HIGH after their targets are freed. Earlier finding still open: a pool gets HIGH in keep_pools (vram.rs ~2602) and loses it only when the heap is reclaimed, so with the switch on by default HIGH spreads over a long session. The README now says so and the author plans a follow-up; until then the ordering weakens over time.
  3. No test that heaps reach the priority by default. Earlier finding still open: the tests cover the env parse (residency_priority_is_on_by_default) and the upload_priority mapping only; nothing checks that set_heap_priority / keep_pools are reached with the variable unset.
  4. Priority call now runs by default inside the mixed remake window. uma_driver.rs ~362: with XCL_UMA_DRIVER=mixed (opt-in) the cast and SetResidencyPriority now run on every GPU_UPLOAD segment, between VirtualFree of the placeholder and Map at want (remake_mixed ~484-491), and also on segments thrown away because Map lands elsewhere. If the driver takes VA there, the segment becomes CUSTOM or the remake stops the process. Setting the priority after the p == want check avoids both (bmjask's point; "probably", it depends on the driver).

Nit

  1. XCL_UMA_UPLOAD_PRIORITY=on/true/0 rank the segments below the HIGH heaps. uma_driver.rs ~336: any set value other than 1 gives None (NORMAL), so on, true or yes set to ask for more priority get less than leaving it unset (HIGH). The README's "any other value keeps them at the default" now reads ambiguously; parsing it with switch_value (on = MAXIMUM, off = NORMAL, unknown = default) would match what users expect.
  2. Description out of date. It says uma_driver keeps main's parse and default and that GPU_UPLOAD segments rank below the HIGH heaps; at e94f2df they get HIGH by default. The test counts and both smoke blocks are from 8ea8619.
  3. Contradicts README: document XCL_RESIDENCY_PRIORITY #3570. README: document XCL_RESIDENCY_PRIORITY #3570 (README only) documents XCL_RESIDENCY_PRIORITY as off by default with only 1 turning it on. The merge is clean textually, so both bullets would land; README: document XCL_RESIDENCY_PRIORITY #3570 should be closed or adapted if this merges.
Checked and fine
  • Earlier finding fixed: the README now says page pools get HIGH once a target's pages land on them and keep it until reclaimed
  • Earlier finding not reproduced: the current smoke pair shows peak commit 17215 -> 16655 MB, not the rise seen before
  • switch_value trims and lowercases; empty counts as off as on main, unknown values stay on with a warning; the tests cover each class
  • One SetResidencyPriority per heap, none per frame, failures logged once; the default NVIDIA window (one CUSTOM L0 heap) is unaffected by the uma_driver part, which only applies to mixed windows
  • Earlier finding fixed (bmjask's): GPU_UPLOAD segments no longer get MAXIMUM by default, and no longer rank below the HIGH heaps when XCL_UMA_UPLOAD_PRIORITY is unset
How this was tested
  • Merged onto main 078358a0, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 078358a0 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, GameInput: XCL_PRESS_BASE=frame counts scripted presses from the first frame #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@throny
throny force-pushed the residency-priority-default branch from e94f2df to 30ec035 Compare December 3, 2026 01:41
@throny

throny commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the re-review. Both points are addressed in the PR's commit (amended locally to 30ec035c6, not pushed yet when this was written).

1. Medium: SetResidencyPriority between the placeholder's release and Map. Moved. I found no sign that the call allocates VA. It is a residency hint, and CreateHeap/CreatePlacedResource already run in that window and do far more. Still, it runs by default now, so it does not belong in the critical window, and it was wasted on a segment that is then given up. mapped_segment no longer sets it. A new set_upload_priority (crates/xcl/src/hle/d3d12x/uma_driver.rs:359) is called in remake_mixed (:540-546) for each GPU_UPLOAD segment in placed, after the loop, ungroom and the failure check. So it runs only for segments that landed at want, with no free range in the window. The log line and the warning on failure are unchanged.

2. Medium: any set XCL_UMA_UPLOAD_PRIORITY other than 1 gives NORMAL. Changed as you suggest, and documented. upload_priority now parses the variable with vram::switch_value (made pub(super)), the same parser as XCL_RESIDENCY_PRIORITY:

  • on (1, on, true, yes): MAXIMUM, as =1 gave before
  • off (0, off, false, no, empty): no call, so NORMAL, as on main; this is the explicit way back to main's behaviour
  • unset or another value: the default (HIGH while XCL_RESIDENCY_PRIORITY is on); an unknown value is logged once by upload_priority_wanted

The README entry and the commit message say this. upload_segments_are_not_demoted_before_the_high_heaps now checks all three groups, including mixed case, "", and an unknown value with residency priority on and off.

Tests (Windows, debug, RTX 4080):

  • cargo test -p xcl --lib d3d12x::uma_driver -- --test-threads=4: 9 passed, 0 failed, 0 ignored, no SKIPPED. That includes the mixed-window remake tests, which now set the priority after placement.
  • cargo test -p xcl --lib d3d12x::vram -- --test-threads=4: 86 passed, 0 failed, 1 ignored.

The whole suite was not rerun for this amend.

The runtime code changed, so a merge check of e94f2dfe does not cover the new head.

Each round has found new points so far. Would the remaining ones block the merge, or can they be follow-ups once this round is in?

Pushed as 30ec035c. The whole suite passes there (3006 passed, 0 failed), and the smoke block in the description is updated.

AI use: Claude Code (Claude Opus 5.5).

@throny

throny commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

@Foniass thanks. The red PR description isn't about the description: since about 22:47Z every pull_request_target run in this repository ends in startup_failure before it starts (reported on #3041; CI, which runs on pull_request, still passes). The repository's own checker (scripts/pr_check.py --local) passes on this description and head (30ec035c). Our script restarts the check once GitHub runs these workflows again.

AI use: Claude Code (Claude Opus 5.5).

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:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants