D3D12.X: XCL_UMA_UPLOAD_PRIORITY=1 keeps a mixed window's GPU_UPLOAD segment resident (nvidia-dev) #3007

Open
github-bot wants to merge 7 commits from github-bot/gh-3007 into nvidia-dev AGit
Owner

@⁠Kalmarv on GitHub · 2026-11-27 11:54 UTC · original
Kalmarv:nvd-p4-upload-priority → nvidia-dev · +1075 −16 · 9 files · 7 commits · draft

Stacked on #3006; only the top commit (da9c69f7) belongs here. Part of #2688.

With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb> one range of the coherent window lives in a GPU_UPLOAD heap: video memory the CPU writes through the BAR, which every console program reads its buffers from. When the process is over its video memory budget, Windows demotes heaps to system memory, and it can pick that one. Then every read of the window's hot range goes over PCIe. This switch gives the GPU_UPLOAD segment D3D12_RESIDENCY_PRIORITY_MAXIMUM, so Windows demotes other heaps first. It is opt-in and does nothing without mixed.

Why
On a 16 GB card in a retail title's world (title: ea3b5e4d, Series X profile; the nvidia-dev port with the mixed window), the process ran about 1.9 GB over its budget. A live ETW timeline of the run (locum mem timeline) showed exactly one demoted heap of 1,792 MiB, the size of window 3's GPU_UPLOAD segment (mixed:1536:1792). The same run with this switch, everything else equal (the env differs by this switch only up to the measured frames):

without (run NS7) with (run NS8)
fps in the world, per 300 frames 1.4-1.9 5.1-5.2
frame wall time (GPU_TIMES, 2 frames) 560-577 ms 194-202 ms
top program b78fa10b (one 160x90 dispatch a frame) 214.5 ms/frame 4.4 ms/frame
over the video memory budget 1.9 GB 2.3 GB

The process stays over budget: Windows takes other heaps instead (the 64 MiB pool heaps), which cost far less per frame.

What is in it

  • crates/xcl/src/hle/d3d12x/uma_driver.rs: upload_priority_wanted (the switch, read once); mapped_segment calls ID3D12Device1::SetResidencyPriority(MAXIMUM) on a GPU_UPLOAD segment's heap and logs it (or the error).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), Ryzen 9 9950X, Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug tests, release smoke; DXC 1.9.2609 via XCL_DXC_DIR.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on da9c69f7 (with CARGO_PROFILE_DEV_DEBUG=0: no debug info, for disk space): 1832 passed, 9 failed, 48 ignored. The same command on nvidia-dev a5e2d851: 1822 passed, 10 failed, 48 ignored.
  • Failed here and on a5e2d851 as well: console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly, hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays, hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels, split_compute_prefers_the_offline_whole_pipeline, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.
  • Failed here only: hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark.
    • gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark alone, 10 times on 2fc61b64 (cargo test -p xcl --lib gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark): 10 passed, 0 failed.
    • gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark alone, 10 times on a5e2d851 (cargo test -p xcl --lib gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark): 10 passed, 0 failed.
  • 26 SKIPPED: 8 no wave64; 1 const_mask, wave64: no wave64; 1 f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); 1 f16 arithmetic, wave64: no wave64; 1 f32 arithmetic, wave64: no wave64; 1 f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); 1 f16 packed, wave64: no wave64; 1 f32 compares, wave64: no wave64; 1 integer arithmetic, wave64: no wave64; 1 mask_ff0_flbit, wave64: no wave64; 1 f64, wave64: no wave64; 1 f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); 1 f32 conversions, wave64: no wave64; 1 integer carries, wave64: no wave64; 1 f32 rounding, wave64: no wave64; 1 f32 transcendentals, wave64: no wave64; 1 f32 three-source, wave64: no wave64; 1 no heap windows (opt-in: XCL_HEAP_WINDOWS=1); 1 no heap windows.
  • The two runs in the table: 900 s each from the world's first frame, timed, GPU alone, the same DXIL cache.

Regression run
150 s runs, same title, same env (XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_DIRECT_SPLIT_INSTRUCTIONS=0 XCL_PSO_JOURNAL=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=120000, DXC 1.9), no switch of this PR set. The main run from a hard-link copy of our team branch's DXIL cache; the base and head runs from hard-link copies of one cache warmed on nvidia-dev a5e2d851 (on this branch the title starts after about 75-90 s of startup shader preparation, so 60 s would end inside it).

A commit of main (b49be183, the last one before the shader preparation screen of #2555):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1917 (PresentX 1917)
presents per 2 s (last 3): 0 0 2
device removals: 0
crashes: 0
peak commit: 33080 MB

The base, nvidia-dev a5e2d851:

xcl-smoke v1
commit: a5e2d851a503fc0e04609f773ea53f2d2c4e3269
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 2464 (PresentX 2464)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34597 MB

This PR's head:

xcl-smoke v1
commit: da9c69f7f979c6a3e4b666ab6c24b032c59ab610
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 2463 (PresentX 2463)
presents per 2 s (last 3): 0 0 3
device removals: 0
crashes: 0
peak commit: 38008 MB

Not tested

  • No unit test: D3D12 has no call that reads a heap's residency priority back, so the log line is the check; it appears once per GPU_UPLOAD segment in run NS8.
  • The regression run above has the switch off (and no mixed), so it shows the default path is unchanged; the switch itself ran only in NS8.
  • AMD (a GPU_UPLOAD heap there may already be placed differently), cards with other budgets, titles other than ea3b5e4d, layouts other than mixed:1536:1792.
  • Whether it should be on by default with mixed: left opt-in.

AI use
Claude Code: the change was written with Claude Fable 5; Claude Code (Claude Opus 5.5) ran the suite and the regression runs on the hardware above and wrote this description.

🤖 Generated with Claude Code

**@⁠Kalmarv** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/3007) `Kalmarv:nvd-p4-upload-priority` → `nvidia-dev` · +1075 −16 · 9 files · 7 commits · draft Stacked on #3006; only the top commit (da9c69f7) belongs here. Part of #2688. With `XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>` one range of the coherent window lives in a `GPU_UPLOAD` heap: video memory the CPU writes through the BAR, which every console program reads its buffers from. When the process is over its video memory budget, Windows demotes heaps to system memory, and it can pick that one. Then every read of the window's hot range goes over PCIe. This switch gives the `GPU_UPLOAD` segment `D3D12_RESIDENCY_PRIORITY_MAXIMUM`, so Windows demotes other heaps first. It is opt-in and does nothing without `mixed`. **Why** On a 16 GB card in a retail title's world (title: ea3b5e4d, Series X profile; the nvidia-dev port with the mixed window), the process ran about 1.9 GB over its budget. A live ETW timeline of the run (locum `mem timeline`) showed exactly one demoted heap of 1,792 MiB, the size of window 3's `GPU_UPLOAD` segment (`mixed:1536:1792`). The same run with this switch, everything else equal (the env differs by this switch only up to the measured frames): | | without (run NS7) | with (run NS8) | |---|---|---| | fps in the world, per 300 frames | 1.4-1.9 | 5.1-5.2 | | frame wall time (GPU_TIMES, 2 frames) | 560-577 ms | 194-202 ms | | top program b78fa10b (one 160x90 dispatch a frame) | 214.5 ms/frame | 4.4 ms/frame | | over the video memory budget | 1.9 GB | 2.3 GB | The process stays over budget: Windows takes other heaps instead (the 64 MiB pool heaps), which cost far less per frame. **What is in it** - `crates/xcl/src/hle/d3d12x/uma_driver.rs`: `upload_priority_wanted` (the switch, read once); `mapped_segment` calls `ID3D12Device1::SetResidencyPriority(MAXIMUM)` on a `GPU_UPLOAD` segment's heap and logs it (or the error). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), Ryzen 9 9950X, Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug tests, release smoke; DXC 1.9.2609 via `XCL_DXC_DIR`. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` on da9c69f7 (with `CARGO_PROFILE_DEV_DEBUG=0`: no debug info, for disk space): 1832 passed, 9 failed, 48 ignored. The same command on `nvidia-dev` `a5e2d851`: 1822 passed, 10 failed, 48 ignored. - Failed here and on `a5e2d851` as well: `console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly`, `hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays`, `hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels`, `split_compute_prefers_the_offline_whole_pipeline`, `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs`. - Failed here only: `hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark`. - `gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark` alone, 10 times on `2fc61b64` (`cargo test -p xcl --lib gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark`): 10 passed, 0 failed. - `gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark` alone, 10 times on `a5e2d851` (`cargo test -p xcl --lib gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark`): 10 passed, 0 failed. - 26 `SKIPPED`: 8 no wave64; 1 const_mask, wave64: no wave64; 1 f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); 1 f16 arithmetic, wave64: no wave64; 1 f32 arithmetic, wave64: no wave64; 1 f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); 1 f16 packed, wave64: no wave64; 1 f32 compares, wave64: no wave64; 1 integer arithmetic, wave64: no wave64; 1 mask_ff0_flbit, wave64: no wave64; 1 f64, wave64: no wave64; 1 f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); 1 f32 conversions, wave64: no wave64; 1 integer carries, wave64: no wave64; 1 f32 rounding, wave64: no wave64; 1 f32 transcendentals, wave64: no wave64; 1 f32 three-source, wave64: no wave64; 1 no heap windows (opt-in: XCL_HEAP_WINDOWS=1); 1 no heap windows. - The two runs in the table: 900 s each from the world's first frame, timed, GPU alone, the same DXIL cache. **Regression run** 150 s runs, same title, same env (`XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_DIRECT_SPLIT_INSTRUCTIONS=0 XCL_PSO_JOURNAL=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=120000`, DXC 1.9), no switch of this PR set. The `main` run from a hard-link copy of our team branch's DXIL cache; the base and head runs from hard-link copies of one cache warmed on `nvidia-dev` `a5e2d851` (on this branch the title starts after about 75-90 s of startup shader preparation, so 60 s would end inside it). A commit of `main` (`b49be183`, the last one before the shader preparation screen of #2555): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1917 (PresentX 1917) presents per 2 s (last 3): 0 0 2 device removals: 0 crashes: 0 peak commit: 33080 MB ``` The base, `nvidia-dev` `a5e2d851`: ``` xcl-smoke v1 commit: a5e2d851a503fc0e04609f773ea53f2d2c4e3269 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 2464 (PresentX 2464) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 34597 MB ``` This PR's head: ``` xcl-smoke v1 commit: da9c69f7f979c6a3e4b666ab6c24b032c59ab610 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 2463 (PresentX 2463) presents per 2 s (last 3): 0 0 3 device removals: 0 crashes: 0 peak commit: 38008 MB ``` **Not tested** - No unit test: D3D12 has no call that reads a heap's residency priority back, so the log line is the check; it appears once per `GPU_UPLOAD` segment in run NS8. - The regression run above has the switch off (and no `mixed`), so it shows the default path is unchanged; the switch itself ran only in NS8. - AMD (a `GPU_UPLOAD` heap there may already be placed differently), cards with other budgets, titles other than ea3b5e4d, layouts other than `mixed:1536:1792`. - Whether it should be on by default with `mixed`: left opt-in. **AI use** Claude Code: the change was written with Claude Fable 5; Claude Code (Claude Opus 5.5) ran the suite and the regression runs on the hardware above and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The title's GPU code reads and writes the coherent window (4 GiB of host
memory) through a heap opened with OpenExistingHeapFromAddress. On an
RTX 5070 Ti, GPU loads from such imported pages ran 8-24x and atomics
13-22x slower than from a driver CUSTOM write-back L0 heap in host
memory, at the same CPU caching. A whole-frame replay of a captured
title frame took 172 ms of GPU time with the window in a CUSTOM L0
heap and 1,427 ms with it imported as XCL does, the hot compute
programs 18-39x slower each.

At open_uma the window's written pages are copied out, the window is
released, every other free stretch of 1 GiB or more is reserved for a
moment so that the driver's CPU mapping of a new CUSTOM L0 heap can only
land in the hole the window left, and the pages are copied back. The
title keeps its pointers. If the mapping lands anywhere else, or a step
fails, the window is made again at its address with its pages and
imported as before; if the snapshot of its written pages fails, the
window is not released at all (found in review by thehollowedone, with
the test failed_write_watch_does_not_release_the_original_window).
Buffers placed in it drop ALLOW_CROSS_ADAPTER. The heap is made with
D3D12_HEAP_FLAG_ALLOW_WRITE_WATCH, and GetWriteWatch reads the mapped
window on an RTX 5070 Ti (driver 610.74), so the window stays in the
write-watched regions and the title's CPU writes reach its textures as
with the import; a driver that refuses the flag, or whose mapping
GetWriteWatch cannot read, keeps the import.

On by default for an NVIDIA adapter outside Wine; XCL_UMA_DRIVER=0
turns it off, XCL_UMA_DRIVER=1 (or custom) turns it on elsewhere.

Ported to nvidia-dev (joeypercia): the driver heap is tried in open_uma's
per-window loop before nvidia-dev's import / video-memory shadow, and not
with XCL_UMA_SHADOW=1; a shadowed or driver-heap window gets no
ALLOW_CROSS_ADAPTER.
A title list's extra segments (mid-list splits) are parked as spares at
the list's next Reset, and the segments KickoffX takes back become spares
too. A spare records again only after its own later Reset, but alloc_pool
still counted it as a user of the PC allocator it last recorded on, so that
allocator was never free: each later Reset of the title's allocator while
those were "in use" put another PC allocator aside, and none was ever
reused or released. The previous recording a stand-in replaces at Reset
pinned its allocator the same way.

alloc_pool::park_list drops the list from its allocator's users (its
submit marks stay, so the allocator is reused only once the GPU is past
them). title_list::reset parks the moved segments and the replaced
recording; KickoffX parks its reclaimed segments after both submits.

Measured on the title (RTX 5070 Ti, Series X profile, 240 s untimed runs,
object counts from 100 to 240 s): PC allocators 1,137 -> 1,928 without,
728-753 -> 862-897 with; non-local video memory 6.2 -> 9.6 GB without,
5.0 -> 5.4-5.5 GB with (about 4 GB less at 240 s). Timed pairs showed no
frame-rate cost (late window 11.99 / 10.76 fps without, 10.76 / 11.76 with;
run-to-run spread ~10 %).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...] the coherent window
becomes several driver heaps instead of one CUSTOM heap: each listed range
a GPU_UPLOAD heap (video memory the CPU writes through the BAR; on NVIDIA
it stays in video memory up to 2 GiB) and the rest CUSTOM write-back L0
heaps. Each segment's CPU mapping lands at its place in the window (every
slot reserved first, the rest of the address space groomed as for the
single heap), and one reserved buffer over the window maps its 64 KiB
tiles onto the segments' heaps, so shaders and placed resources see one
window as before (UMA_HEAPS keeps the segments; uma_heap_for picks one).

- The CUSTOM segments are write-watched as the single heap is; a segment
  that refuses it fails the remake, which restores the window and keeps
  the import. The GPU_UPLOAD segments are not write-watched: their
  write-combined pages refuse the watch trap's read-only protection.
  Uma::watch_regions lists only the watched segments.
- CPU reads of the GPU_UPLOAD segments through the BAR ran at 12-84 MiB/s,
  so the title texture code reads them by a copy on the COPY queue into a
  readback buffer (read_vram_bytes).
- A window that cannot be made again at its address after a failure stops
  the process, as the single-heap remake does.

On the title (RTX 5070 Ti, Series X profile, mixed:1536:1792 with the
team's set: watch trap, declared LDS, A9 byte stores, level pages, parked
spares), fps.py over 187-229 s: 25.28 fps (TX1) and 24.15 (CB2m3), against
11.99 with one CUSTOM heap (CB2) in the same set.

Written by reed (57496b69 on our team branch); ported onto #2844's head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With 16 windows the coherent memory can be several windows (4095 + 999 MB
for a retail title's 4582 MB of GPU heaps). The mixed ranges are offsets
in the first one; in a second, smaller window they had no overlap, the
remake failed with "no GPU_UPLOAD range inside the window" and the window
stayed imported. Further coherent windows are one CUSTOM heap each.

Co-Authored-By: Claude Fable 5 <[email protected]>
place_console_buffer returned through '?' when the block it got lay across two
heaps of a mixed window, leaving the block charged to the window. The block is
now held while the next fit is tried and given back either way (hulk's
alloc_in_one_heap from the mixed-window branch, with its test).

Co-Authored-By: Claude Fable 5 <[email protected]>
Port of #2938's fallback (9f992827) onto nv-stack. An adapter without GPU_UPLOAD heaps
(D3D12_OPTIONS16; Resizable BAR off) gets the single CUSTOM heap, asked before the window is
released. A GPU_UPLOAD segment refused anyway becomes a write-watched CUSTOM segment in place:
a mapped segment's pages stay with the driver after its heap is dropped, so the old rollback
could not reserve the window again (Windows error 487) and stopped the process.

The two tests that remake a mixed window take one lock: run side by side (4 test threads), one
remake's release of its reserved stretches let the other's segment map elsewhere, and the
process stopped in 8 of 10 runs of the uma_driver tests (0 of 3 with one thread).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Over its video memory budget, Windows demotes heaps to system memory. On the port (run NS7,
1.9 GB over) a live ETW timeline showed one demoted heap of 1792 MiB, the size of window 3's
GPU_UPLOAD segment. The switch gives that heap D3D12_RESIDENCY_PRIORITY_MAXIMUM so other
heaps go first. Opt-in; not tested beyond a build.

Co-Authored-By: Claude Fable 5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:06:38 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/3007/head:github-bot/gh-3007'
git switch 'github-bot/gh-3007'

Merge

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