KernelX: GPU-visible title memory outside the windows is write-watched (retail menu text complete) #252
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!252
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/252/head"
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?
@jessenic on GitHub · 2026-11-23 21:53 UTC · original
jessenic:fix/gpu-visible-write-watch→main· +72 −0 · 1 files · 1 commits · merged 2026-11-23 23:18 UTCWhat was wrong
In a retail game's menus the body text lost its x-height letters (a c e m n o r s u v w x z); letters with ascenders, descenders or dots and all capitals were fine.
XCL_DEBUG_MAGENTAwith a colour per UI pixel shader showed two text paths: the letters that drew come from a shader with no texture (vector glyphs), and every missing letter from one shader that samples a single texture, a 2048x2048A8_UNORMglyph atlas the CPU fills as text is laid out. That atlas is kept in step with the title's memory (d3d12x::title_textures). A GPU readback of it was all zeros while its CPU view held the glyphs.The atlas lies in a 24 GB reservation of 64 KiB pages (VirtualAlloc flags
0x20402000). It does not fit a sparse window, so it fell through to plain memory withoutMEM_WRITE_WATCH, whereGetWriteWatchsees nothing: the texture was uploaded once, empty, at its first submit and never again. A second allocation, 2.2 GB of large pages with a graphics protection (flags0x20003000, protection0x2404, too large for the coherent window), had the same problem. Together they held 128+ kept-in-step textures within the first 45 s.Change
kernelx::VirtualAlloc's last fallback addsMEM_WRITE_WATCHfor GPU-visible reservations (MEM_GRAPHICS,MEM_LARGE_PAGES/MEM_64K_PAGES, or aPAGE_GRAPHICS_*protection). It records them with the graphics reservations, whose rangestitle_texturesalready watches andVirtualFreealready forgets. Commits the title makes inside such a reservation later inherit the watch.Relation to open PRs: #203 moves large-page reservations into sparse windows when they fit. This change covers what still falls through (the 24 GB reservation does not fit), so the two are complementary. #211 (merged) covered glyph caches that are render targets; this atlas is a plain texture.
Testing
gpu_visible_fallback_memory_is_write_watched: the three flag combinations land in watched memory, and a write is reported byGetWriteWatch.cargo test --workspace: 652 passed, 0 failed, 40 ignored (RTX 5070 Ti, driver 32.0.16.1088).🤖 Generated with Claude Code
@Kalmarv on GitHub · 2026-11-23 22:02 UTC · original
Review of
862a0d4. The change looks right to me, and its per-submit scan cost is small. Two things I'd fix or check: the test passes without reaching the new code, and writes into write-watched memory cost more than the scan.1. The test does not reach the new branch here. In
gpu_visible_fallback_memory_is_write_watchedall three cases (0x20402000,0x20003000with0x2404,MEM_GRAPHICS | 0x3000) land in a unified-memory window and take thecontinue. I added a print to thatcontinuelocally and ran the test on Windows 11 with an RTX 5070 Ti. The test passes onmainfor the same reason. To make it check the fallback, take the branch's condition out as a function and test that, or have the test fill the windows first.2. The per-submit scan grows with the textures in the new ranges, not with the 24 GB.
GRAPHICS_RESERVATIONSonly letswatch_rangeskeep the kept-in-step textures inside them. Those are merged across gaps under 1 MiB and clipped to the regions, and each look scans only that.GetWriteWatch(WRITE_WATCH_FLAG_RESET), run asrefresh_onceruns it (16,384-entry buffer, called again while full) on committed, resident, write-watched memory. Medians of 5–15 looks, Ryzen 9 9950X:watch_rangesscans only the textures.sparse windows timing: write-watch N ms (M dirty pages)line, before and after #252.3. CPU writes into write-watched memory cost more than the scan.
4. Merges.
git merge-treeof #252 with #254 (097fab4), #236 (03d4a86) and #203 (7cbd008) is clean.main7a033c8+ #252 + #254 + #236 builds, and thehle::kernelxtests pass: 24 passed, 0 failed.An aside, not from #252: in
refresh_once, a full buffer makes the nextGetWriteWatchstart again from the region's base. With every page dirty, a 4 GiB look took 105 ms that way, against 47 ms when each call starts after the last page reported.Tested:
hle::kernelxtests on the merged tree above.Not tested:
hle::kernelxran.🤖 Claude Opus 5.5
@jessenic on GitHub · 2026-11-23 22:35 UTC · original
Thanks for the careful review. Point by point:
1. Test not reaching the fallback: fixed in 065be41. The branch's condition and reservation are now functions (
gpu_visible_fallback,reserve_watched), andgpu_visible_fallback_memory_is_write_watchedcalls them directly, so the unified-memory windows can't take the allocation first. It checks the condition for the three GPU-visible flag combinations and three plain ones (CPU-only reservation, a commit without a reservation, a fixed address), then thatreserve_watchedmemory is watched (GetWriteWatchreports the written page) and recorded and forgotten with the graphics reservations. WithMEM_WRITE_WATCHremoved fromreserve_watched, the test now fails; it passes with it.2. The game's real numbers.
main7a033c8against7a033c8+ #252, same PC (RTX 5070 Ti, Ryzen 7 9700X), same script (XCL_PRESS_AT=45:A, 80 s), from thesparse windows timing: write-watchline (cumulative ms):mainThat's about 0.5 ms a submit on
mainagainst 2.0–2.7 ms with #252 once the menus have loaded. Frames shown in the 80 s: 1297 against 1093.I split the timed section with a temporary probe. Recomputing the ranges is negligible (58 ms over 2048 looks);
GetWriteWatchitself is the cost. The watched ranges grow from 10 ranges / 0.4–0.8 GB (all committed) early on to 65–79 ranges after the menus. At your 0.43 ms/GiB that's roughly 5–6 GB of kept-in-step textures inside these reservations. So the cost scales with the textures, as you said, but in this game those textures are several GB: everythingmainwas leaving stale. I'll look at cutting it in a follow-up rather than in this PR (for example, not rescanning textures nothing has written for a while, or scanning only textures bound since the last look).3. Write cost. The reservation holding the physical pages is this one. A follow-up trace (#283) shows
XMemMapPhysicalPagesinto the 24 GB0x20402000/PAGE_READWRITEreservation about 54,000 times in the first minute (64 KiB pages). At your ~7 µs a 64 KiB page, that's ~0.4 s once, spread over loading.4. Merges: thanks, noted.
Aside (
refresh_oncerestarting from the region's base on a full buffer): agreed, that's real and predates this PR. In this game the buffer never fills per look (about 30 dirty pages a submit), so it doesn't explain the numbers above. Worth its own small fix.Tests:
cargo test --workspace652 passed, 0 failed, 40 ignored (RTX 5070 Ti).🤖 Claude Opus 5.5
@simnJS on GitHub · 2026-11-23 22:39 UTC · original
Tested on Linux (Wine, NVIDIA): the menu text is still incomplete.
Tested commit:
862a0d4(head of #252; its base7a033c8is 4 commits behindmain9ab7d76, none touchingcrates/). Compared withmainat9ab7d76, same machine, same protocol.Tested
x86_64-pc-windows-gnu.cargo build --release --locked --target x86_64-pc-windows-gnu -p xcl: builds.XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=120, one run per build, the account prompt answered with a single A by hand: starts, 130 s without a crash, 60 presents per 2 s (30 fps), draws per 2 s 360 → 1952 (main, same protocol: 360 → 1920). No newWARN/ERRORline againstmain(same 64 distinct lines, 75 total).(0,135,0)) → the "Brightness Level" screen, mean(65,65,65). The text under the "Brightness Level" title is still missing its lowercase letters without ascenders ("us e va ue un e s m o s / are v s e."), the same asmainat9ab7d76, which reaches the same screen with the same gaps in the same run protocol.VirtualAllocpath is taken in this run (noXCL_TRACE_*set), so I cannot say whether the allocation never reaches it under Wine or whether the glyph atlas has another cause here.Not tested
cargo test --workspace) andscripts/smoke.ps1were not run (the crate's tests run on Windows).mainruns stayed on the purple loading screen to the end (A not registered or not pressed in time), so a single run per build is a thin sample.AI use
@simnJS on GitHub · 2026-11-23 22:56 UTC · original
Tested on Linux (Wine, NVIDIA): the menu text is still incomplete, and the glyph caches are not in the memory #252 changes.
Tested commit:
065be41(head of #252; base7a033c8, 4 commits behindmain0e946cf, none touchingcrates/). Compared withmainat0e946cf. This adds to my earlier report on862a0d4.Tested
x86_64-pc-windows-gnu.cargo build --release --locked --target x86_64-pc-windows-gnu -p xcl: builds.XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=120 XCL_TRACE_MEM=400, 70 s, A pressed once by hand.065be41reaches the "Brightness Level" screen (mean(65,65,65), frames 860–1220); the text under the title still reads "us e va ue un e s m o s / are v s e." – the same letters missing as onmain. 60 presents per 2 s (30 fps), no crash, no newWARN/ERROR(57 distinct lines on both).XCL_TRACE_MEMshowsVirtualAlloc (GPU-visible, write-watched)for:0x600000000flags0x20402000protect0x4→0x7ffff0000and protect0x801→0xdffff0000;0x185c00000flags0x20402000protect0x2004→0x13ffff0000;0xd4ac0000flags0x20402000protect0x2404→0x1585bf0000; and three of flags0x20003000. Onmainthe same calls are plainVirtualAllocat the same addresses.0x20003000and protect0x2404/0x22004(0x49400000,0x89700000= 2.2 GB,0x23300000; 3 928 MB together) are served byVirtualAlloc (graphics, coherent window), before the fallback, on bothmainand065be41: Wine's run has a 4095 MB coherent window (UMA: … 4095 MB coherent window at 0x400000000) and they fit in it. Only a fourth,0x25400000(protect0x22004), found no room and reached #252's path. Where the window is smaller (less free commit,uma::coherent_hint) the 2.2 GB request would reach it – I did not test that.0x12000–0x82000bytes, the "glyph cache the CPU fills" oftitle_textures) – all in that coherent window at0x700000000:VirtualQuerysays allocation base0x700000000, allocation protection0x4, stateMEM_COMMIT, typeMEM_PRIVATE; the window is alreadyMEM_WRITE_WATCH(uma.rs) and is inwatch_regions(). So #252 changes nothing for them here, which fits the identical picture.reserve_watched's first call, temporary):VirtualAlloc(MEM_RESERVE | MEM_WRITE_WATCH)of 4 MB → a block,VirtualQuery: stateMEM_RESERVE(0x2000), typeMEM_PRIVATE, allocation protection0x4.GetWriteWatchon it: return 0, 0 pages, granularity0x1000(not 64 KiB). After a 64 KiBMEM_COMMITinside it and writes to three pages: return 0, exactly those 3 pages; with the reset flag the next call returns 0 pages, then 1 page after one more write.MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCHin one call behaves the same. The console's raw flags0x20402000 | MEM_WRITE_WATCHare refused by Wine (NULL,GetLastError87) –sanitize_alloc_typestrips them first, as in the PR.GetWriteWatchnever failed in the 70 s run (0 failures).GetWriteWatchsee the glyph caches' writes? Yes, at the start: three looks between 24.9 s and 25.4 s see a written page in 1, then 69, then 1 of the 71 caches (17 942 – 22 337 dirty pages in all). After that, none in the remaining 45 s – though much more text is drawn then, with letters missing: the "Brightness Level" sentence, and in the run with logging the long photosensitivity-warning page (frame 1220, about 60 s) where most lines lack many letters. In #283's logged run no glyph cache was marked GPU-written either (no GPU copy into them seen). So the missing letters are not a CPU write that the watch missed; the caches' content after 25 s is not the CPU writes this path watches. I did not find what writes them.main, so #252's write-watched fallback is never reached for it and the missing letters come from something else (not found).Not tested
cargo test --workspace) andscripts/smoke.ps1were not run (they need Windows).065be41and once on #283's head (2a64505), with the same result for the glyph caches.AI use
@jessenic on GitHub · 2026-11-23 23:08 UTC · original
@simnJS thanks for testing on Wine, and for tracing where the allocations go there. One correction about which texture to look at: the menu's missing letters don't come from the 71 small two-plane targets (
title_textures' "glyph cache the CPU fills" log, #211). In my runs those stay all zero on both the CPU and the GPU side while the text is on screen.What draws the missing x-height letters on Windows here:
XCL_DEBUG_MAGENTA=b40d9ca24fe3d23d:ff0000,f618f478d0c51397:00ffffcolours the two text shaders. Red (b40d9…, no texture bound) draws the letters that are present. Cyan (f618f…) draws exactly the missing ones.f618f…samples one SRV: a 2048×2048A8_UNORM, one mip, single plane texture kept in step with title memory (here at shared-heap index 204; that index may differ on your build).0x20402000reservation, uploaded once at creation and never again. With #252 it's re-uploaded and the text is complete here.So on Wine the useful checks are: where that
A8_UNORM2048×2048 texture lies (title_textures::register'sva,VirtualQueryof it), whether it's in a rangewatch_rangeskeeps, and whetherGetWriteWatchreports its pages after ~25 s. If it sits in the coherent window under Wine, #252 indeed changes nothing there, and the cause would be elsewhere.🤖 Claude Opus 5.5