kernelx: XCL_COHERENT_HEAPS=sparse-wc puts write-combined GPU heaps in video memory #3619
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3619"
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 Royalflamejlh on 2026-12-01T22:11:35Z.
XCL_COHERENT_HEAPS=sparse[:N]moves GPU heaps out of the coherent window by size alone. In the sparse windows the CPU's writes are uploaded before each submission, but what shaders write stays in video memory (only memory operations are copied back), so a heap the CPU reads back would show it stale bytes. This addssparse-wc[:N]: only GPU heaps committed withPAGE_WRITECOMBINE(of at least N MB) go to the sparse windows. Write-combined memory is written by the CPU and not read by it (its reads are uncached on the console; results a title reads come back inPAGE_GRAPHICS_COHERENTmemory with cached pages), so what shaders write there can stay on the card. Off by default.A retail title commits one write-combined GPU heap of 1277 MB (protection
0x2404) beside three GPU-coherent ones. Its shaders read it over the bus: most of the coherent window's reads in a profiling run. The CPU writes about 0.5 MB/s of it after loading.What is in it
crates/xcl/src/hle/kernelx.rs:sparse-wc[:N]in theXCL_COHERENT_HEAPSparse, and the GPU-heap route sends a write-combined heap tosparse_reserveunder it; tests of the parse and of the route (write_combined_heaps_alone_go_to_the_sparse_windows_with_sparse_wc).Tested
masterwith local patches, Rust 1.98.0,x86_64-pc-windows-gnu, release. Headede473ab2(the two comments that described onlysparse[:N]updated; no code change sincec8902b4e) onmainf07e426d.cargo test -p xcl --release --lib -- kernelx:: gpu::umaunder Wine (CPU Vulkan): 87 passed, 0 failed, 1 ignored.XCL_COHERENT_MB=3027, the window's stored need less this heap) and off, 2 each: on, both ran the full 600 s, 2.14 and 2.78 frames a second past their first 1,490 frames; off, one ended on a device removal at 371 s (1,564 frames) and one on an access violation in the title at 261 s (1,489 frames). Two pairs: the difference in how they ended is not settled, and shader builds in the first minutes blur the frame rates.Regression run
RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:14:11Z.
Review (head
c8902b4e, diff read, not a merge-check; checks red):No problems found in the diff. Checked the
sparse-wc[:N]parse and its round trip throughheaps_route(a separateuma_coherent_sparse-wc*.txtsize file), theheap_in_sparsepredicate at the only call site of the oldsparse_heaps_min(kernelx.rs~1016, ~1079), which still sees the title's raw protection so thePAGE_WRITECOMBINE(0x400) test works, thatsparseandsparse:Nbehave as before, and that the default path is untouched whenXCL_COHERENT_HEAPSis unset. The comments at ~1011 and ~1089-1091 still describe onlysparse[:N]. The red check isPR description: Regression run has noxcl-smokeblocks yet, and the tests ran under Wine only.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T22:28:54Z.
@Foniass thanks for the read. The two comments now mention
sparse-wc(headede473ab2, comments only). The smoke pair is still owed: no Windows machine of ours has answered today.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:30:40Z.
Follow-up review (head
ede473ab, sincec8902b4e, diff read, not a merge-check; checks red):kernelx.rs~1012) and theheaps_routedoc (~1091) now describesparse-wc[:N].New: none; only those comments changed since
c8902b4e. Thexcl-smokeblocks are still owed.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T04:13:22Z.
merge-check claim
head:
ede473ab20Imported from ivall/xcl. Originally posted by throny on 2026-12-02T04:13:44Z.
Queued an in-world A/B of this on an RTX 4080 16 GB: current
main+ this headede473ab, same build withXCL_COHERENT_HEAPSdefault vs=sparse-wc, 900 s each withXCL_RESIDENCY_PRIORITY=1andXCL_GPU_PROFILE=1(the write-combined heaps in the coherent window are a lead for our per-pass cost on #505). Also doing a merge check. Numbers here when done.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T04:33:53Z.
First pair, RTX 4080 16 GB (621.40),
main1c8b5514+ this head (plus our local input-timing patch), same build, same save and inputs,XCL_RESIDENCY_PRIORITY=1:XCL_COHERENT_HEAPSsparse-wcWith
sparse-wcthe coherent window shrinks to 512 MB and non-local video memory drops from 4.9 to 1.7 GB, so the heaps do move to video memory as intended; but the run hung early in the world. That is one run; hangs around 100–190 s have also shown up here in other runs that got closer to the budget, so it may be the same in-world hang rather than this change. I'll repeat it once after the merge-check suites and add the result.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T04:39:45Z.
Thanks for running it. Our numbers so far are from Linux only (RTX 4060 Ti 16 GB, Wine + vkd3d-proton, a development tree with this change): 2 of 2 runs with
sparse-wcwent their full 600 s, 2 of 2 without it ended early, so a Windows hang is new information. Running the same A/B in the world on an RTX 5070 Ti 16 GB now (main+ this head, 600 s, 2 runs each way); results here when done.AI use: Claude Code (Claude Opus 5.5) wrote this comment.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T05:09:07Z.
Confirmed on Windows: with
sparse-wcthe device is removed early in the world, 2 of 2 runs; without it the run goes its length. RTX 5070 Ti 16 GB (621.24), Ryzen 7 9800X3D, Windows 11 26300,main1c8b5514+ this headede473ab, release, 600 s,XCL_SKIP_BINK=1:XCL_COHERENT_HEAPSsparse-wcsparse-wcSo it is this change, not the in-world hang seen elsewhere, and on Windows the switch is not usable as it is. Our earlier result (2 of 2 runs better with it) was under Wine + vkd3d-proton only. I am moving this back to draft until the cause is found; the commit figure is the first lead (a guess: the heap's pages in video memory plus the CPU copy the sparse windows keep).
AI use: Claude Code (Claude Opus 5.5) ran the runs and wrote this comment.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:26:11Z.
Follow-up: two more runs with
sparse-wc, each started without a stored window size (uma_coherent_sparse-wc.txtmoved aside; with the stored size, runs crashed at 37 s before the world — that is themixed-range/window-size problem in #3568, not this PR): both ran 900 s with no removal, but at 1.18 and 1.41 presents/s against 3.02 without the switch (run 418), and video memory peaked at 19.3 GB (default: 18.9 GB). So on this RTX 4080 withXCL_UMA_DRIVER=mixed:1536:1792and residency priority it is slower, not faster; the early hang in run 419 did not repeat. It may behave differently withoutmixedor on a card with more headroom.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:26:13Z.
merge-check
base:
1c8b55147(main)head:
ede473ab20merge: clean trial merge into main
1c8b55147(merge_trial_suite.sh 3619).build:
cargo build --workspacepassed.tests:
cargo test --workspace --no-fail-fast -- --test-threads=4on the merged tree: 2910 passed, 0 failed, 51 ignored; 25 SKIPPED notices (no wave64, no heap windows, driver cache); 0 binaries ended abnormally. The new testwrite_combined_heaps_alone_go_to_the_sparse_windows_with_sparse_wcand the extendedsparse_heaps_setting/heaps_routetests pass.review: diff read (one file,
hle/kernelx.rs, +47/-18). Thesparse-wc[:N]parse,heap_in_sparseand the route name for the coherent window's size file are correct; the default path (XCL_COHERENT_HEAPSunset) is unchanged; the earlier reviews' stale-comment point is fixed at this head. The tests cover only the parse and the predicate, not an allocation. It is an opt-in switch, so no default behaviour changes. Problem found by our run below: the switch is not safe in the world on this card.performance: in the world on an RTX 4080 (XCL_UMA_DRIVER=mixed:1536:1792, XCL_RESIDENCY_PRIORITY=1) the switch was slower: 1.18 and 1.41 presents/s vs 3.02 without it; one earlier run lost the device at 101 s, two later runs did not (see the comments above). Default path unchanged.
verdict: safe to merge (opt-in, default unchanged; not a recommendation to turn it on with the mixed driver)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-02T09:58:42Z.
Static review (head
ede473ab, diff and the code around it read onmain1c8b5514; nothing built or run for this comment). The parse, the route and the per-setting size file look right to me as well; below are only points that may bear on the Windows removals above.sparse-wccosts in commit. A heap in the sparse windows keeps the title's own pages committed as the CPU view (sparse.rs: the CPU writes are found by write-watch and uploaded before the nextExecuteCommandLists), and its committed tiles are also mapped onto video-memory heaps. So the write-combined heap is paid twice, plus the staging ring, which fits the 50,046 of 50,661 MB commit at the removal. How big that heap is depends on the console profile: the retail title asked for 2,199 MB of write-combined GPU memory (protection0x2404) in the Series X profile on our machine, against the 1,277 MB quoted for Series S. That size is the title's request, logged on our tree (main493dbd3d+ #3528 + #3517 + local commits), not something XCL chooses. Comparing commit at the removal with the default path at the same moment would show whether this is the cause.uma_coherent_sparse-wc*.txt,coherent_hint_forplans the coherent window atRUNTIME_COMMITTED_CAP(512 MB). The other GPU heaps (about 3 GB in Series S) then do not fit and fall back to ordinary memory until the next run. That may account for some of the difference between runs with and without a stored size in the comments above (a guess, not measured). Seeding the size from theallfile minus the write-combined heaps, or notingXCL_COHERENT_MBin the description, would make first runs comparable.changed_chunkssends whole 64-byte chunks: if the CPU writes into a chunk where the GPU has written other bytes, the upload overwrites them. This heap is the one the title keeps writing from the CPU, so the overlap is more likely here than for the other heaps. If the GPU wrote counters or indirect arguments in those chunks, that could hang the GPU (a guess). A count of chunks uploaded over bytes the GPU wrote since the last upload would rule it in or out.wait_memory) read the CPU view; a GPU write into these tiles reaches that view only through the readback path. A counter of waits or reads that land in a write-combined range would confirm that the assumption holds.sparse-wc:0→sparse-wcroute is not covered (thesparse:0→sparsecase is); easy to add.AI use: Claude Code (Claude Opus 5.5) read the diff and the code and wrote this review; checked and posted at my request.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T10:11:32Z.
Thanks, these line up with what the runs showed.
sparse-wcsize from theallfile minus the write-combined heaps.3 and 4 I will measure rather than guess: a count of 64-byte chunks uploaded over bytes the GPU wrote since the last upload, and of waits or reads landing in a write-combined range.
bec54b80:sparse-wc:0routes assparse-wc.AI use: Claude Code (Claude Opus 5.5) added the test and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:12:56Z.
Follow-up review (head
bec54b80, sinceede473ab, diff read, not a merge-check; draft, checks red):sparse-wc:0routes likesparse-wc.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.