kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #1999
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2009"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Ariorh1337 on 2026-11-25T00:40:48Z.
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 #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):2f49088, on #19930a755f0andmain06055a7): 1419 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 + #1329 + the earlier prototype of #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.2f49088alone (main06055a7+ #1993 + this PR,XCL_COHERENT_HEAPS=sparse:1024 XCL_HEAP_WINDOWS=1, release): both big heaps moved (sparse pools 5.4 GB, local video memory 17.7 GB). The world's first burst ran (7861 dispatches after the first#101) with no GPU wait or copy back running out and no crash or device removal in 438 s. Presents stopped 8 s after the first#101while the title waited on cold driver builds of compute pipelines (68 with no driver blob formain's HLSL on this machine). So this shows the switch's path up to there, not the world running with it.7c18bc4in #2057) go at that cost; #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 #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+ #1993 + this PR with the switch: the run above stops on cold compute builds first. The smoke run does not set the switch.sparsewithout:N(every heap, the fences included) in a title run on top of #1993. On my prototype, moving every heap made the readbacks of fence writes the bottleneck.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T01:05:48Z.
Full-suite run, since this PR has no test report yet. Tested exact head
5370f4b(on its base8e87fc7).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 981 passed, 0 failed, 43 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.a_copy_back_does_not_wait_for_the_title_queue,sparse_heaps_setting.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 991 passed, 0 failed, 45 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on main7994cd1too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests andconst_and_null_mask_operands_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:12:55Z.
Code review on
5370f4b:crates/xcl/src/hle/kernelx.rs,sparse_heaps_min()/parse_sparse_heaps(XCL_COHERENT_HEAPS=sparse[:N], overflow-safechecked_mul(1 << 20), andsparse_heaps_settingunit tests) cleanly routes graphics heaps>= N MiBintod3d12x::sparse::alloc.CIworkflow approved (currently running).crates/xcl/src/hle/d3d12x/sparse.rsasync-readback changes from#1993— so please keep the shared monotonicrb_fencemulti-queue ordering note from#1993in mind (or rebase onto#1993once settled).Remaining before merge: Settling the
#1993sparse.rsoverlap / multi-queuerb_fencenote,Build and testfinishing green, and an AMD verification pass.Imported from ivall/xcl. Originally posted by Filip722 on 2026-11-25T01:40:47Z.
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.
bf9eebd5370f4bintegrated on the same mainBoth offline Series X runs used fresh copies of the same prefix/cache seeds and
XCL_COHERENT_MB=2048 XCL_COHERENT_HEAPS=sparse:1024 XCL_HEAP_WINDOWS=1. I retained main’s internal-wait diagnostics when integrating the stack. The 2 GiB free-VRAM guard stopped each run around 30 s, before account input. I added 100 ms VRAM sampling for the second run after seeing a >1 GiB drop between baseline samples. Each had seven black captures, zero scope swap and zero reported storage failures. World entry remains unverified here.Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112, local vkd3d-proton 3.1.0 (
4522cc1a8b1347fwith dxil-spirv compatibility changes). Focused Windows release tests under Proton, including sparse GPU readback, passed 5/5 on main and 7/7 with the stack. No reported skips.OpenAI Codex (GPT-6.2-Sol) integrated the PRs locally, ran the comparison and wrote this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T03:51:33Z.
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T11:00:42Z.
Code review on
783ac15(top commit incrates/xcl/src/hle/kernelx.rs, stacked on#1993):sparse_heaps_min+parse_sparse_heaps(checked_mul(1 << 20)guardingusize::MAXoverflow, tested insparse_heaps_setting) cleanly routes opt-inXCL_COHERENT_HEAPS=sparse[:N]PAGE_GRAPHICS_*allocations intod3d12x::sparse::allocbeforenote_coherent_need.45598152814).Remaining before merge: Land
#1993first (or rebase once#1993merges),Build and testgreen, and independent AMD + NVIDIA verification exercising the opt-in switch on783ac15.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T11:06:07Z.
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).Imported from ivall/xcl. Originally posted by Ariorh1337 on 2026-11-25T11:44:44Z.
@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.
Imported from ivall/xcl. Originally posted by STmihan on 2026-11-25T13:19:53Z.
#2009 on an 8 GB Ampere card:
sparse:2048makes the world compute passes 27–36× faster, but local VRAM then runs to 17–21 GB and the 5 s timeouts come back past ~16 GB.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
mainf087b99+ #2009 + #1993 and other open PRs,XCL_DIRECT_DXIL=all XCL_HEAP_WINDOWS=1 XCL_PAGE_BUDGET_MB=3584, warm caches,XCL_GPU_PROFILE=1.Per-call GPU time from
XCL_GPU_PROFILE(median of the "longest" field over all windows), without and withXCL_COHERENT_HEAPS=sparse:2048(moves the 2199 MB heap only):| program | without | with
sparse:2048||
Imported from ivall/xcl. Originally posted by Ariorh1337 on 2026-11-25T16:51:18Z.
@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 (
sparse:2048) made the world's compute passes 27–36× faster, and then video memory ran to 17–21 GB and the 5 s timeouts came back past ~16 GB. With @mgrein's and @joeypercia's 12 GB runs, the picture is the same on all three: a large gain while the heaps fit, worse than without the switch once they don't. So the next step for this switch is a limit by the adapter's video-memory budget: move a heap only while it fits, instead of a fixed size in MB. I've added your run to the description.AI use: Claude Code (Claude Opus 5.5) drafted this.
Imported from ivall/xcl. Originally posted by STmihan on 2026-11-25T16:57:23Z.
@Ariorh1337 thanks, my earlier comment got cut off at the table when I posted it and I didn't notice. Here is the rest:
sparse:20486da1f38b06d6c735(wave64 split)19a1c1ba0b567618(wave64 split)b78fa10b425b8e5424de2aef6c31d55e(wave32)3429c04607b00016, 119 instructions, 57600 groups) take 0.3–1.7 s per call; their output buffers are in the coherent window (0x7…), which fits the ~0.1 GB/s store rate in #505.XCL_TEXTURE_PAGES_SYSTEM_MEMORY=1alongside it kept local at ~5 GB, but menu draws went to ~40 ms each and the device hung (0x887a0006) at world entry with a DRED page fault at VA 0x0. One run.Not tested:
sparse:1024(all four heaps) on this card, other drivers, AMD.AI use: Claude Code ran the runs and wrote this.
Imported from ivall/xcl. Originally posted by lucsoft on 2026-11-25T19:27:58Z.
Test report: Linux / RADV, RX 7800 XT (RDNA3). Head
99a7e4f, in a stack, not alone. Two runs reached gameplay with no device removal.main50a9fdeplus about 20 other PRs, including #1993 at69903fcon top of this one. The full list is in https://github.com/xcl-dev/xcl/issues/505#issuecomment-7170904791.XCL_COHERENT_HEAPS=sparse:1024 XCL_COHERENT_MB=1024 XCL_HEAP_WINDOWS=1.AI use: Claude Code (Claude Opus 5.5) ran the analysis and drafted this. The runs were real, on the hardware above.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:40:00Z.
Review: COMMENTED
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.
Imported from ivall/xcl. Originally posted by Ariorh1337 on 2026-11-25T21:16:55Z.
@bmjask the fence hooks are fixed in #1993's
0a755f0(details there). This PR is restacked on it as2f49088.About the other two points:
CIworkflow waits for a maintainer's approval on PRs from forks. I can't start it myself. The full suite on this machine is in the description:cargo test --workspace --no-fail-fast -- --test-threads=4on2f49088, 1419 passed, 4 failed, 46 ignored (the same 4fuzz_validate_and_gpu_0..3and SKIPPED tests asmain06055a7, 1409 passed).main+ #1993 + this PR with the switch on: done on2f49088alone (RTX 5090, release,XCL_COHERENT_HEAPS=sparse:1024 XCL_HEAP_WINDOWS=1, through the menus by controller):a GPU heap of 1172 MBandof 2199 MB in the sparse windows); sparse pools at 5.4 GB, local video memory 17.7 GB;#101). There was nodid not complete within, nohas not reached fenceand no copy-back line, and no crash or device removal in the 438 s watched;#101, because the title then waited on cold driver builds of compute pipelines (68 of them with no driver blob, asmain's HLSL is new to this machine's cache). So the run shows the switch's path working up to that point. It doesn't show the world running with it.AI use: Claude Code (Claude Opus 5.5) drafted this.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:49:43Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by grahamster2 on 2026-11-26T16:57:06Z.
Data point from a 10 GB card, in case it helps decide the default.
RTX 3080 10 GB, 31 GB RAM, Windows 11. Austin's Build 15 plus a merge of current nvidia-dev,
XCL_UMA_WINDOWS=16,XCL_HEAP_WINDOWS=1,XCL_COHERENT_MB=1024, Series S mode.sparse:1024: those skips went to 0 and the world renders. The best run reached the first playable section at about 9.5 min with 0 skipped draws.E_OUTOFMEMORYand no device removal from it in 4 runs of 6 to 11 min. Runs ended on system commit at 33 to 35 GB, not on video memory.XCL_COHERENT_MB=5120(so the heaps fit coherent) made the title fault with a null read at 112 s in the one run I tried.One related thing for anyone trying this: heaps that end up outside the coherent window are still added to the stored coherent need (
note_coherent_needruns before the placement decision in the default route). So the next run withoutXCL_COHERENT_MBpinned builds a window of several GB. Mine had a stored 4582 MB from an earlier run. Yoursparse_firstbranch avoids this by returning beforeASKEDis counted. I have a local change that does the same for a fallback that places non-fitting heaps in the sparse windows automatically. I'm not posting it as a PR since this one is the place for that decision.Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-26T20:42:00Z.
RTX 3090 24 GB, retail 1.0.2.1 on
nvidia-dev: withsparse:2048the world ran at 3.03 fps against 1.37 fps without it (PresentMon, no profiler, one back-to-back pair). On a card with room for the moved heap, this is a data point for the default question next to @STmihan's 8 GB and @grahamster2's 10 GB runs above. Frames are GPU-bound in both arms.Setup
nvidia-devaf2cecc4(which has this switch as4c14c537) + #2551, merged locally.xcl.exein a 2 GiB shader-heap profile (#2590).XCL_DIRECT_DXIL=1, A pressed by script, compute pipelines precompiled.sparse:2048moves one heap here:a GPU heap of 2199 MB in the sparse windows.Frame times (PresentMon 2.6, 60 s from 150 s into the run; the world had started at 105 s and 96 s; the two runs back to back):
sparse:2048Where the GPU time goes (
XCL_GPU_PROFILE=1, 240 s runs; the profiler runs each queue's ops one at a time, so absolute times are inflated):CS b78fa10b425b8e54(8x8 threads, split wave64, 160x90 groups;CS_DepthProcessingHBOper #1597) runs once a frame for 256 ms on average (200 calls, longest 481 ms). That is 51.2 s of the 181 s profiled in total, and in an in-world 2 s window 902 of 2,518 ms.sparse:2048: the same program 9.2 ms on average (186 calls, longest 22.7 ms); 67 s profiled in total. Other top programs dropped too, e.g.24de2aef6c31d55elongest 461 → 19 ms,680b8917303ae7df432 → 84 ms.image_stores plus abuffer_store_formatin the 8-pass loop. So it looks like the coherent-window store cost this PR describes, not a long-running loop.Two things to know when trying it
sparse(every heap) got stuck before the world here: 1,104 frames in 240 s, the GPU almost idle and no world start.sparse:2048reached the world in all three runs.Not tested: video memory and commit use with the switch (not logged in these runs; @STmihan's and @grahamster2's runs show the cost on smaller cards); more than one PresentMon pair;
main+ this PR alone; AMD; other values of N.AI use: Claude Code (Claude Opus 5.5) ran the runs on my machine, read the PresentMon captures, the profiler logs and the program's disassembly, and drafted this. Checked by me before posting.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:11:38Z.
Triage (#1607) – head
2f49088Stacked on #1993; its own commit (kernelx.rs
XCL_COHERENT_HEAPS=sparse[:N]) is on main as4c14c537with the same patch (identical patch-id). The base commit from #1993 is on main in an earlier form ascbba2d9d.Recommendation: close (superseded by main commit
4c14c537).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:50:16Z.
Closing as superseded: this change is already on
main(4c14c537). PR is stacked on #1993 (its other commit0a755f0cis the readback commit, on main ascbba2d9d); its own commit2f490889has the same patch-id as main4c14c537(XCL_COHERENT_HEAPS=sparse:N)Two independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed