Repository navigation
kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory - #2009
Ariorh1337 wants to merge 2 commits into
Conversation
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Code review on
Remaining before merge: Settling the |
|
On the RTX 5060 Laptop GPU (8 GiB), the first sample with zero render-target pages showed 256 MiB of sparse pools on main and 3,584 MiB with #1993 + #2009 (197 and 3,527 MiB mapped). The cost was already visible before render-target streaming.
Both offline Series X runs used fresh copies of the same prefix/cache seeds and Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112, local vkd3d-proton 3.1.0 ( OpenAI Codex (GPT-6.2-Sol) integrated the PRs locally, ran the comparison and wrote this report. |
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
5370f4b to
783ac15
Compare
|
Code review on
Remaining before merge: Land |
|
CI \45598152814\ on \783ac15\ reported \1154 passed; 1 failed: the lone failure is pre-existing \hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa\ (\device_x.rs:1376), unrelated to #2009\ (\sparse_heaps_setting\ passed). |
|
@mgrein, @joeypercia thanks for running the switch on 12 GB cards. Both runs show what it costs there: the heaps fill video memory, and textures go to system memory early. I've added both to the description, along with where the switch does not pay (16 GB or less) and how it relates to #1329 and #2090. It stays off by default. AI use: Claude Code (Claude Opus 5.5) drafted this. |
|
#2009 on an 8 GB Ampere card: RTX 3070 Ti 8 GB, driver 621.14, Ryzen 7 5800X, 64 GB RAM, Windows 11 26100, release. Retail 1.0.2.1, local tree on Per-call GPU time from | program | without | with |
783ac15 to
3d836e9
Compare
3d836e9 to
99a7e4f
Compare
|
@STmihan thanks for the 8 GB run. Your comment ends at the table's header row, so if the per-program numbers got cut off when pasting, they would still be useful here. What it adds: on a card that small, moving only the 2199 MB heap ( AI use: Claude Code (Claude Opus 5.5) drafted this. |
|
@Ariorh1337 thanks, my earlier comment got cut off at the table when I posted it and I didn't notice. Here is the rest:
Not tested: AI use: Claude Code ran the runs and wrote this. |
|
Test report: Linux / RADV, RX 7800 XT (RDNA3). Head
AI use: Claude Code (Claude Opus 5.5) ran the analysis and drafted this. The runs were real, on the hardware above. |
`readback_after_execute` made the sparse queue GPU-wait for the title's queue and then waited on the CPU for the copy, on the thread that was submitting. The title's queues can wait for work that same thread submits next (four compute queues waiting for a Write64 on q1 whose list is recorded but not submitted yet). So the copy waited its 5 s on every such submission, and the uploads queued behind it on the sparse queue waited too (`before_execute` waiting for ring room). In thread dumps of a retail title on an RTX 5090, the submitting thread is in `readback_ranges` -> `wait_for` while another title thread waits for the sparse state's lock in `commit_range`. lucsoft found the same cycle on RDNA3 / Linux (xcl-dev#505). The copies now run on a lane per title queue: a fence the title's queue signals after its lists, and a queue of its own that GPU-waits for that fence. The submitting thread returns. With one fence for all title queues, a later signal on another queue let a copy start before its own queue's lists ran (CharlyRien); with one queue for all, a title queue waiting for work still to come held back the copies of the others. The lanes (8) are made in `init`, before the device's methods are hooked: made later, a lane's queue was adopted as one of the title's, and the e2e title under the debug layer read 0 for what its lists wrote. A copy back's allocator and list are made with the device's own methods, past its hooks (`real::create_own_list`), as `init`'s objects are: made through the adopted device, the list took XCL's list hooks on the lane's queue, and vkd3d-proton crashed at its Close (St5sz2Jk, RDNA4 / Wine). Tiles quarantined behind the title queues' marks (xcl-dev#2345) also wait for the copies back still to run on a lane: they read the windows after the title's work. A lane serves a title queue while that queue has copies back in flight; with all lanes busy (or none made), the old path runs. Readback buffers are sized to the copy (64 KiB and up) and reused; idle ones above 256 MB are given back (each holds commit, and with the title's queues stalled every submit's copies wait, one buffer each; found by Chrysana's RDNA4 run). Each time the buffers pass another doubling from 64 MB, their size is logged. The data lands in the title's memory once the copy is done, before the title can see the work it follows is done: - on the next submit, and from a thread that looks every 0.5 ms; - before Map's readback (waiting for the copy once the title's lists it follows are done), and in the CPU memory waits of Wait64BitValueX, which only try the sparse state's lock: its holder can be waiting for work the waiting thread is to submit; - in the title's fence observations: `GetCompletedValue` settles the copies first. `SetEventOnCompletion` hands the fence an event of XCL's own, and a thread-pool wait on it settles them, then sets the title's event. These only try the lock; a copy whose title work is done but which still runs is waited for with the lock let go, then landed. Waiting for it with the lock held stood every submit behind a copy that stood behind a stalled GPU (lucsoft, RDNA3). Lanes land in their own order, so an older copy back of one lane can land after a newer one of another: it leaves the bytes the newer one landed. A CPU wait for a copy uses its lane's event, not the sparse state's: a wait that gave up leaves its registration behind, which set the shared event later and ended a tile-queue wait early (theaustinayers, in xcl-dev#2057). Tests: - `a_copy_back_does_not_wait_for_the_title_queue` waits 5.0 s on the old path and under 1 s with this change; - `a_copy_back_waits_for_its_own_title_queue`: two title queues, the first blocked; with one lane for both, the first one's copy lands before its list ran; - `an_older_copy_back_does_not_overwrite_a_newer_one`. - `a_copy_still_running_after_its_title_work_is_waited_for_outside_the_lock`. - `idle_copy_back_buffers_above_the_cap_are_given_back`. - `a_copy_back_list_of_an_adopted_device_is_not_adopted`. - `quarantined_tiles_wait_for_copies_back_still_to_run`. They run on a WARP device of their own: they block a queue on purpose, and on the GPU's device, which the tests in the process share, other queue tests then hung in the driver releasing resources (upipibi; reproduced in 3 of 3 runs of the d3d12x queue tests). Without the fence hooks, the e2e test title read 0 for its Write32BitValueBottomOfPipeX after its fence wait. With them, both e2e tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title's GPU heaps (committed with a PAGE_GRAPHICS_* protection) go to the coherent window, process memory the GPU reaches over the bus. On an RTX 5090 a shader's dependent reads there are ~30x slower than from video memory (no L2 hits, about 2.4 us each). Its store instructions whose lanes leave gaps (per-lane dwordx2/x4, 8- and 16-byte formats) run at ~0.1 GB/s, against ~50 GB/s for lane-contiguous ones and >1 TB/s in video memory. The retail title of xcl-dev#505 keeps 4.4 GB of heaps there (1172, 2199, 563 and 596 MB), and its world passes take 0.4-2.7 s each. Keeping the heaps out of the window was reproduced as removing the stall on an RTX 5080, an RTX 3080 and RDNA3 / Linux (xcl-dev#505), but there the shaders read zeros. With `XCL_COHERENT_HEAPS=sparse` every such heap, with `sparse:N` those of at least N MB, goes to the sparse windows instead: video memory, with the CPU's writes uploaded before each submission, like the title's other graphics memory. A heap that goes there is not counted in the coherent window's size for the next run (`note_coherent_need`). Off by default: it costs a second copy in video memory and the write-watch scan of it, and it needs the asynchronous copies back of the commit below. Without them, the copies back of the title's lists' writes into these heaps wait for the submitting thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99a7e4f to
beb21c1
Compare
bmjask
left a comment
There was a problem hiding this comment.
P1, inherited/extended from #1993: adopted fence hooks promise read coherence but call settle_readbacks_try and then expose completion even if bounded STATE locking fails. The title event can fire (and GetCompletedValue can return complete) before GPU->CPU sparse copyback lands. before_execute can hold STATE across sparse submission/setup, so the contention path is reachable. Do not signal/return visibility until relevant copies land, or use a deferred retry path; add a lock-contention fence-wait test. This stacked PR also lacks current Windows CI and an isolated switch-enabled title run for the #1993+#2009 stack.
Stacked on #1993; only the top commit belongs here.
An opt-in switch,
XCL_COHERENT_HEAPS=sparse[:N], that puts a title's GPU heaps (committed with aPAGE_GRAPHICS_*protection) in the sparse windows (video memory) instead of the coherent window (process memory the GPU reaches over the bus). Withsparseevery heap moves, withsparse:Nthose of at least N MB. Part of #505.Why. In the coherent window, on an RTX 5090:
dwordx2/x4, 8- and 16-byte formats) run at about 0.1 GB/s. Lane-contiguous ones run at about 50 GB/s, and the same stores in video memory at over 1 TB/s. Micro-benchmark in my Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505 comments.The retail title of #505 keeps 4.4 GB of heaps there (1172, 2199, 563 and 596 MB), and its world passes take 0.4–2.7 s each.
Keeping the heaps out of the window (
XCL_COHERENT_HEAPS=0) removed the GPU stall on an RTX 5090, an RTX 5080 (@kanade333), an RTX 3080 (@not-rex) and RDNA3 / Linux (@lucsoft). But there the shaders read zeros, and the 3D picture is black. This switch keeps them GPU-visible at the same addresses.Where it does not pay. The moved heaps cost their size in video memory. On 12 GB cards two people measured it:
mgrein (RTX 4070 12 GB, #1773): with
sparse:1024the world-load stall is gone, but local video memory reaches 20 GB by 256 s andCreatePlacedResourceXfails withE_OUTOFMEMORY. Without the switch the world load stalls at once (queue.Waittime-outs from 132 s, device removed at 575 s).joeypercia (RTX 4070 Ti 12 GB, with a page budget, #1773): with
sparse:512the device went at 184.6 s instead of 304 s. Texture pools went to system memory from 23 s on, and compute passes slowed to ~0.5 s a dispatch.STmihan (RTX 3070 Ti 8 GB, on this PR):
sparse:2048(the 2199 MB heap only) made the world's compute passes 27–36× faster, and then local video memory ran to 17–21 GB and the 5 s timeouts came back past ~16 GB.So the switch is for cards whose video memory holds the heaps on top of the title's textures (24–32 GB). It stays off by default. The next step is a limit by the adapter's video-memory budget instead of a fixed size.
Other ways at the same problem:
XCL_UMA_SHADOW=1) keeps a copy of the whole committed window in video memory. This switch moves only the big heaps.XCL_SPARSE_DIRECT=1) goes the other way: the sparse windows become memory the GPU reads where it is, which ends the write-watch scan and the copies back. With it, this switch has nothing to gain, since the heaps would land in system memory again. Which way is faster on a card with enough video memory is not measured yet; I'll run both on the RTX 5090.What is in it (
crates/xcl/src/hle/kernelx.rs, one commit)VirtualAlloc, a heap the switch selects goes tod3d12x::sparse::alloc, as the title'sMEM_GRAPHICScommits already do. A heap that goes there is not counted in the coherent window's size for the next run (note_coherent_need).parse_sparse_heapsand the testsparse_heaps_setting.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4(debug):beb21c1, on D3D12.X: a copy back after a submission does not wait for the title #1993e8d597bandmain06055a7): 1417 passed, 4 failed, 46 ignored;main(06055a7): 1409 passed, 4 failed, 46 ignored.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(0x8007000E), the same onmain. SKIPPED: 26 lines, the same tests as onmain.mainb9b6ea6+ open PRs + D3D12.X: the committed window gets a copy in video memory #1329 + the earlier prototype of D3D12.X: a copy back after a submission does not wait for the title #1993 + this switch, withXCL_COHERENT_HEAPS=sparse:1024 XCL_HEAP_WINDOWS=1. That moves the 1172 and 2199 MB heaps; the 563 and 596 MB ones, which hold the fences, stay in the window.#101with 0 draws and 0 dispatches skipped.#101.main+ D3D12.X: a copy back after a submission does not wait for the title #1993 + this PR alone needs the whole shader cache rebuilt formain's HLSL; not done.7c18bc4in D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057) go at that cost; D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057 runs this switch assparse:16.Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60(start screen, no input, switch not set, so this checks the default path),XCL_HEAP_WINDOWS=1, same machine. Themainblock is the one from #1993.Not tested
sparse:1024on99a7e4fwith D3D12.X: a copy back after a submission does not wait for the title #1993 and about 20 other PRs; two runs reached the prologue with no device removal and no GPU-wait timeout, at about 1 fps, with the write-watch scan taking 215 s by 811 s.main+ D3D12.X: a copy back after a submission does not wait for the title #1993 + this PR alone (see above). The smoke run does not set the switch.sparsewithout:N(every heap, the fences included) in a title run on top of D3D12.X: a copy back after a submission does not wait for the title #1993. On my prototype, moving every heap made the readbacks of fence writes the bottleneck.AI use
🤖 Generated with Claude Code