Memory: size the coherent window by the GPU heaps alive at once #3695
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3695"
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 Prime1997 on 2026-12-02T15:14:33Z.
Requested by Prime
The coherent window (committed, GPU-visible system memory that stays resident) is sized from the title's GPU heaps stored by its last run, plus XCL's 512 MB. kernelx never took a heap off that count when the title released it, so the stored size was the sum of every heap the title ever asked for. A title that makes and frees heaps (streaming, level changes) grew it run after run, and it was never lowered. An oversized window is resident RAM for nothing (estimated 0.3-1.5 GB); RAM was the limit in a run on a 32 GB machine (30.9 of 31.9 GB in use).
What is in it
Memory: size the coherent window by the GPU heaps alive at once: kernelx keeps the heaps counted for the window alive by address, in the window or in plain memory, and takes a heap off when it is released (VirtualFree of a unified-memory block or of plain memory). uma stores the most alive at once, the peak ofnote_coherent_need(hle/kernelx.rs,gpu/uma.rs).Memory: count the coherent window's holes in its stored size: the stored size includes the holes freed heaps leave in the window, so the next run's window still fits the same heaps (gpu/uma.rs).Tested
cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnuon Linux: builds, no new warnings.XCL_COHERENT_MB=512: the title reaches its world, and the window no longer grows between runs.Regression run
main(Prime's call for our PRs; they merge after community testing).Not tested
main.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T16:12:18Z.
Code review location:
crates/xcl/src/hle/kernelx.rs; line 1035Could this counter use the allocated footprint rather than the requested byte count?
Uma::alloc_whererounds each request up toGRAINbefore recording it inused(gpu/uma.rs:846), butCOHERENT_LIVEadds the unroundedsizehere and subtracts that same amount on release. Two simultaneously live 64 KiB + 1 byte heaps therefore occupy 256 KiB while contributing only about 128 KiB to the high-water value used by the 10-minute shrink;holes()cannot account for this padding because it is part ofused. That can persist a window too small for the same live heaps on the next run. Could the live accounting track the rounded UMA block length and include a regression test with multiple unaligned live heaps? AI-assisted review (model: GPT-6); I checked the allocation rounding against the shrink accounting in this diff.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T16:12:18Z.
Review: COMMENTED
AI-assisted review (model: GPT-6). I checked the coherent allocation rounding against the shrink accounting.
Imported from ivall/xcl. Originally posted by Edgaras0404 on 2026-12-02T17:43:48Z.
test report (not a merge-check)
base:
df0cfef638(the last main before #3655; first parent ofd71578f8)head:
e665b42c4b(tested as cherry-picked ontodf0cfef6; git diff base..tree is the PR's own diff, 182+/24-)merge: clean (also clean on current main
5eaadb54, which builds; that base's suite is the #3694 breakage, so the functional run is ondf0cfef6)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> base
df0cfef6: lib aborted (exit 0x80004005) after 1,380 ok / 6 failed / 25 ignored, notest result:; failing:gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form,gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu,gpu::recomp::tests::gpu_f32_compares_with_nan,gpu::recomp::tests::gpu_float_compares_random,hle::d3d12x::alloc_pool::tests::a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads,hle::d3d12x::list_x::tests::a_put_off_call_whose_close_fails_is_not_submitted; integration 147 passed / 2 failed / 20 ignored (gpu_two_pass_cache_e2e0/1 twice, lines 472 and 584); SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. Merge: lib aborted the same way after 1,384 ok / 4 failed / 25 ignored; the 4 are the compact-form test and the three f32 tests, all on base; the base'salloc_poolandlist_xfailures did not recur in either merge (list_xis the known parallel flake;alloc_poolwas not run alone); integration 147/2/20 with the same two-pass failure; the three tests this PR adds/changes pass:gpu::uma::tests::holes_are_the_free_room_below_each_windows_highest_block,gpu::uma::tests::a_long_run_that_freed_heaps_lowers_the_stored_need_of_every_heap,gpu::uma::tests::only_the_sparse_heaps_settings_lower_the_stored_coherent_need(3 passed, 0 failed). Current main5eaadb54: merges clean, build ok, but its suite is the #3694 breakage (lib aborted after 1,153 ok / 278 failed / 26 ignored;gpu_compute_e2eremoved the device 0x887a0020) and was not used for functional evidence. rustc/cargo 1.100.1, debug.review: 1) The change itself is untested:
COHERENT_HEAPS/COHERENT_LIVEandcoherent_heap_releasedhave no test, and the new tests cover onlyholes()andsettled_need(), so the claimed fix (a released heap stops counting) would regress silently. 2)XCL_COHERENT_SHRINKis a new user-facing switch, on by default, and is not inREADME.md; the default behaviour change (after 600 s a run may halve the stored coherent window down to its peak) should be documented. 3) The 600 s rule is a heuristic: a run that reaches 10 min but later loads a heavier level can leave the next run's window too small, and its heaps go to plain memory until the window grows back; the 60 s title run cannot measure this. The rest of the diff is small and follows the existinguma_coherent.txtpattern. No duplicate found: #632 (whole window in the first run), #3546 (commit planning), #3677 (watch ranges) and #3658 (no-buffer window address) are different changes; #3696 is stacked on this PR.performance: 60 s smoke on
df0cfef6with the #3544 workaroundXCL_DIRECT_DXIL=1on both trees: the default (non-direct-DXIL) base run crashed at 48 s with 0xc0000005 in amdxc64.dll (the known #3544 driver crash), so the workaround isolates the memory change; the PRs do not touch shader translation. Base: 1,537 frames shown / 19,779 MB peak / 0 device removals / 0 crashes. Merge #3695: 1,584 frames / 19,550 MB / 0 removals / 0 crashes. Frames are 103.1% of base and peak 98.8% (gate: frames >=80%, peak <=125%), so the pair passes. The 600 s shrink is not reached by a 60 s run, so this checks no regression, not the lowering. Not tested: the default non-direct-DXIL path, which crashes on the base too (#3544).verdict: test report only (not a merge-check): build and merge are clean; on
df0cfef6the merge's suite has four failures, all on the base (the base's other two did not recur), and no new one, and the three new tests pass; the 60 s pair (with the #3544 workaround) is 103.1% frames / 98.8% peak with 0 removals and 0 crashes. The missing test for the release accounting and the undocumented default-on switch are what I would ask for before merge.hardware / tool and model: AMD Radeon RX 6700 XT 12 GB (RDNA2), driver 32.0.21045.29003; AMD Ryzen 5 5600X; Windows 10 build 19045 / OpenCode, DeepSeek V4.1 Flash 1017
Smoke blocks (60 s, XCL_DIRECT_DXIL=1, title 1778c2d9):
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T18:14:02Z.
Test report (not a merge-check:
PR descriptionred)base:
5eaadb54c1head:
e665b42c4bmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2976 passed, 0 failed, 52 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+182/-24). Before this PR, the coherent window's stored size was the sum of every GPU heap the title ever asked for, and on the default route it never went down. Now kernelx tracks the heaps alive at once (
COHERENT_HEAPS/COHERENT_LIVE) and stores the peak alive bytes plus first-fit holes. After 600 s a run can lower the stored size by up to half. This is on by default (XCL_COHERENT_SHRINKunset = on). Findings: (1) Brings back a lowering that was removed on purpose, with no evidence.settled_need/coherent_shrink(uma.rs ~1152/~1166) lower the default route's stored size again.d75c3733cstopped exactly that, after a too-small window sent a retail title's heaps to plain memory, where its shaders read zeros (comment at kernelx.rs ~1005). After a first lowering, theasked >= beforeguard compares against the peak alive bytes. So a long run with less alive (a menu, a small level) can lower the size again, and the next run that loads a bigger level loses its image. The only reported run usedXCL_COHERENT_MB=512, which returns early incoherent_hint_for(uma.rs ~1089) and never touches the stored size. There are no suite counts and no smoke blocks. (2) The second commit is a fixup of the first.e665b42csays it is a "Review fix for 86c5e52b", and thatf4140e5b1alone stores a size below what first-fit placement needs, sof4140e5b1on its own is a regression and the history is not bisect-safe. Squash them. The commit bodies also cite private batch names. (3) A heap that does not fit raises the stored size less reliably than before. The size grows only when alive + holes exceeds it, but the fit check (kernelx.rs ~1041) also counts XCL's own blocks and the 96 MBKEEP. When XCL's own blocks take most of the share, a heap can be refused without raising the stored size, and it then goes to plain memory on every run. (4) Gaps and races in the live bookkeeping. On the plain-memory path,coherent_heap_releasedruns after Windows has freed the address (kernelx.rs ~1335), so another thread can get the same address andinsertover the entry.VirtualFreeExon fallback memory (~1369) is never counted. Both errors overcount, which is the safe side, but they defeat the shrink.COHERENT_LIVEalso adds unrounded sizes whilealloc_whererounds each heap up to 64 KiB (uma.rs ~846). (5) Tests cover only the pure functions.settled_needandholes()are tested. Nothing tests the kernelx accounting: create/free/reuse of an address, the fallback path,VirtualFreeEx, or that a refused heap raises the need. (6) README.XCL_COHERENT_SHRINKis not in it. Fine:holes()counts free room below each window's highest block, 2 MB alignment padding included. The sparse routes still settle at 60 s.XCL_COHERENT_SHRINK=0keeps the old cumulative behaviour. A UMA block's release is counted beforeu.free.performance: 60 s smoke of a retail title, main
5eaadb54vs this merge (e665b42c): 1422 -> 1664 frames shown (117 %; last presents per 2 s: 61 60 60), peak commit 17184 -> 16726 MB, 0 device removals, 0 crashes.assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: On by default it lowers the default route's coherent size again, which
d75c3733cremoved on purpose (a heap that no longer fits loses its image); the only run usedXCL_COHERENT_MB=512, which bypasses the stored size, and there are no smoke blocks or suite counts.hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T18:51:17Z.
Review of
e665b42c4(read against main, not a merge check; our suite, smoke and world runs of a trial merge are queued and follow as a check).gpu/uma.rs~1155settled_need, the 600 s settle ~1194;XCL_COHERENT_SHRINKunset = on). The stored size is now the peak of live heaps plus holes, and a run can lower it by up to half. If a later run places its heaps differently, or reaches an area with a higher peak than the run that set the size, a heap misses the window and goes to plain memory, where shaders read zeros. It heals from the next run (the fallback note grows the file), so it costs one broken run per new peak. On main that can't happen, because the window is sized by everything ever asked. A margin on the stored size, or keeping the shrink opt-in, would close it.COHERENT_HEAPS.insertignores an old entry at a reused address (hle/kernelx.rs~1035/1052).mem::VirtualAllocfallback and is freed throughVirtualFreeExis never released.xcl-smokeblocks. I'll post ours (main and this head, RTX 4080) here when they're done, if they help.Fine: sparse heaps are not counted; no stored file and
=0behave as before; Series S naming is unchanged; the lock is dropped beforeholes().AI use: Claude Code (Claude Opus 5.5) reviewed the diff; posted at throny's request.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T20:37:30Z.
merge-check
base:
c53e969602head:
e665b42c4bmerge: trial merge
721997d52into mainc53e96960: cleanbuild: cargo build --workspace -> ok
tests: cargo test --workspace -- --test-threads=4 -> 3006 passed, 0 failed, 52 ignored; 25 SKIPPED (no wave64 and similar); failing: none
title run: retail title, RTX 4080, 300 s in the world (run 493), no crash, no device removal, 2.79 presents/s
review: the review comment above (whole diff read)
performance: two 900 s warm runs each, main
c53e96960vs this trial merge: 3.00 / (495 hung, a stall seen on main too) vs 2.82 / 2.80 presents/s; video memory peak 18.9 vs 19.1-19.2 GB; peak commit 42.1 vs 42.3-42.4 GBverdict: not yet: the default-on shrink can cost a run its picture (review above, finding 1). Also, on this machine it showed no effect: the stored window (4.9 GB) stayed the same in two 900 s runs, as on main. Our runs set
XCL_UMA_DRIVER=mixed:1536:1792, so this setup may not reach the sizing. The frame rate was 2.80 and 2.82 presents/s against main's 3.00 in the same pair of runs (2 runs each, so it may be noise).hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300 / Claude Code with Claude Opus 5.5 (builds, suite, world runs, review)
Smoke blocks for the description (60 s each, retail title):
main:
this PR's head:
Imported from ivall/xcl. Originally posted by throny on 2026-12-03T06:54:14Z.
Merge check: safe (head
e665b42c4, merged onto main16c2fd082)cargo test --workspace -- --test-threads=4: 3014 passed, 0 failed, 56 ignored; 25 SKIPPED lines, no test binary ended abnormallyXCL_RESIDENCY_PRIORITY=1): reached the world, no device removal, no crash, first frame 11.18 s, 2.89 presents/s (main 2.88 on the same setup today), 0 Aftermath dumpsNot tested: AMD/Intel cards.
AI use: Claude Code (Claude Opus 5.5) ran the checks and wrote this comment.
Imported from ivall/xcl. Originally posted by AAsobu on 2026-12-03T11:41:47Z.
merge-check
base:
16c2fd082ahead:
e665b42c4bmerge: clean (merged tree c1b5153f)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3014 passed, 0 failed, 56 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps, 3 no D3D12 debug layer); failing: none
review: read the whole diff (+182/-24,
uma.rs,kernelx.rs); no finding in the code itself. On this title the window does not come down: 2 s into a run 3998 of its 4095 MB are in use and three more heaps (596, 19 and 33 MB) go to plain memory, so the heaps alive at once (~4.6 GB) are as large as what was stored (4582 MB). Two 660 s runs in the world (pastSETTLED_ALL) wrote no lowering line, and the stored size rose to 4679 MB. In the world this merge ran fine: presents per 2 s 4.79 / 4.85, peak commit 39802 / 39353 MB, peak VRAM 16189 / 15870 MB, no device removal.smoke:
scripts/smoke.ps1 -Game <folder>(60 s), run in alternation at the same time: this merge 2 frames in 3 of 3 runs (peak commit 10255-10286 MB);main16c2fd081571 / 1614 / 1624 frames in 3 of 3 (~30 presents per 2 s at the end, peak commit 14555-14673 MB); this merge withXCL_COHERENT_SHRINK=01600 frames (1 run). Two smoke runs ofmainearlier the same day stopped at 2 frames too, so where the title gets to in 60 s depends on some state I have not pinned down, but in the same hour the switch alone separates the two outcomes. With the switch on, the PR's smoke log has one 1000 ms wait for a graphics pipeline; I have not found why it stays at 2 frames.performance: in-world frames and memory as above; the smoke shows this merge at 2 frames against
main's ~1600 (under the 80 % CONTRIBUTING asks).verdict: not yet: with
XCL_COHERENT_SHRINK=1(the default) the 60 s smoke stops at 2 frames wheremainand this merge with the switch off reach ~1600 (3 of 3 against 4 of 4); the window size itself does not change on this title.hardware / tool and model: NVIDIA GeForce RTX 3090 24 GB (driver 621.24, wave32 only), Intel Core i5-10600K, 32 GB, Windows 11 Home build 26300 / Claude Code (Claude Opus 5.5), results checked by me
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T16:41:27Z.
merge-check
base:
16c2fd082ahead:
e665b42c4bmerge: clean
build: ok
tests: 3014 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 2 high, 4 medium, 2 nits (below)
performance: 60 s smoke run: 1683 → 1657 frames (98 % of main), peak commit 18505 → 18440 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 240 s there, 0 device removals, 0 crashes, 2.8 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet: 2 blocking findings (critical or high, below); also
PR descriptionis redhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: kernelx now tracks the GPU heaps alive at once (COHERENT_HEAPS/COHERENT_LIVE) and stores the peak plus the window's holes. After 600 s a run can lower the stored size by up to half; this is on by default (XCL_COHERENT_SHRINK). The head is the one my earlier test report covered, and its findings are all still open. The default-on lowering and the untested kernelx bookkeeping block it.
High
d75c3733cremoved on purpose. Still open from my earlier report. settled_need with Some(all) (uma.rs ~1152) and the 600 s settle lower the size stored for ALL_HEAPS.d75c3733cstopped exactly that, after a too-small window sent a retail title's heaps to plain memory, where its shaders read zeros. A long run in a smaller area that asked for as much as is stored, but had less alive at once, lowers the size. The next run that reaches a bigger peak then loses the image of the heaps that miss the window, until the fallback note grows the size back. The only run reported used XCL_COHERENT_MB=512, which never reads the stored size. Keep the lowering opt-in, or keep a margin on the stored size.Medium
e665b42cdescribes itself as a "Review fix for 86c5e52b" and saysf4140e5b1alone stores a size below what first-fit placement needs, and that it never heals. Sof4140e5b1on its own is a regression and the history is not bisect-safe. Squash the two. The commit bodies also cite private batch names (own10, own11, 1f5d4d57).Nit
Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 61 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and 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.