kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #2009
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2009
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Ariorh1337 on GitHub · 2026-11-25 00:40 UTC · original
Ariorh1337:kernelx/coherent-heaps-sparse→main· +1101 −36 · 5 files · 2 commits · openStacked 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
@raylitebull on GitHub · 2026-11-25 01:12 UTC · original
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.@futurepro62 on GitHub · 2026-11-25 01:05 UTC · original · edited 2026-11-25 01:26 UTC
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
@Filip722 on GitHub · 2026-11-25 01:40 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-25 03:51 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.@raylitebull on GitHub · 2026-11-25 11:00 UTC · original
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.@raylitebull on GitHub · 2026-11-25 11:06 UTC · original
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).
@Ariorh1337 on GitHub · 2026-11-25 11:44 UTC · original · edited 2026-11-25 11:48 UTC
@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.
@STmihan on GitHub · 2026-11-25 13:19 UTC · original
#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||
@Ariorh1337 on GitHub · 2026-11-25 16:51 UTC · original
@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.
@STmihan on GitHub · 2026-11-25 16:57 UTC · original
@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.
@lucsoft on GitHub · 2026-11-25 19:27 UTC · original
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 #505.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.
@Ariorh1337 on GitHub · 2026-11-25 21:16 UTC · original
@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.
@DavidM1911 on GitHub · 2026-11-26 00:49 UTC · original
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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.