GPU: probe 4 KiB OS pages in descriptor sync_heaps #2447
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2447
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2447"
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?
@Texbirds on GitHub · 2026-11-25 13:39 UTC · original
Texbirds:fix/gpu-descriptor-sync-heaps-4k-probe→main· +134 −26 · 1 files · 1 commits · closed without mergingProblem
In
crates/victory-gpu/src/descriptor.rs,sync_heaps()iterates dirty ranges returned bywritten.take(start as usize, usize::MAX)incrate::watch::PAGE(64 KiB) steps and probes readability once at the start of each 64 KiB block withcrate::host::read_into(page as *const u8, &mut [0u8; 4])before callinghost.mirror()(which reads each 12-byte slot header directly viaread_unaligned()indescriptor/host.rs).Because Windows commits and unmaps memory at 4 KiB (
0x1000) granularity, a partially committed 64 KiB block fails in both directions onmain:host.mirror()faults with an Access Violation on the unreadable tail.sync_heaps()skips the entire 64 KiB block without mirroring those descriptors.Change
sync_heap(heap: &Heap)(called bysync_heaps()underSHADER_HEAPS) and step inconst OS_PAGE: usize = 4 << 10(4 KiB) chunks.crate::host::read_into(page as *const u8, &mut [0u8; 1])so the probe itself can never cross a page boundary.startis not aligned to the 16- or 32-bytestep), guard the 12-byte record withread_into(handle, &mut [0u8; 12])before callinghost.mirror().Test
sync_heaps_handles_partially_committed_64k_pages(Windows, synthetic write-watched pool viawatch::tests::pool(1)and a 512-slot placed sampler heap spanning two 4 KiB pages within one 64 KiB block, no game data):VirtualFree(..., MEM_DECOMMIT), runssync_heap, and asserts slot 5 is mirrored without faulting on the decommitted second page.watch::title_memory_remapped, runssync_heap, and asserts slot 261 is mirrored.sync_heaps()calls usingSHADER_HEAPSwhile decommitting/recommitting its own test pool, and skips cleanly if no host D3D12 device is present (matching the existingrecords_copied_as_bytes_are_made_at_the_next_synctest).github-bot referenced this pull request2026-11-26 06:27:40 +00:00
@kotekompotek on GitHub · 2026-11-25 14:02 UTC · original
Reviewed — the 4 KiB probing is right and fixes a real fault path:
continuehandles both.written.takeranges unchanged;mirrorcalls now skip indices in unmapped sub-pages, which is the point.MEM_DECOMMIT/MEM_COMMITinside the pool in both directions, and it serializes against parallelsync_heapsvia theSHADER_HEAPSlock.@Texbirds on GitHub · 2026-11-25 16:30 UTC · original
Rebased onto
main(67e8ae1) indac5a4f.mainnow batches each page's slots throughHostHeap::sync_slots(one lock per page instead of two per slot). The fix keeps that: each 4 KiB OS page is probed and its slots go tosync_slotsin one call. Only the at most two edge slots that can straddle a 4 KiB boundary (an unaligned placed heap) get the 12-byte probe beforemirror. TheSyncSlotsdiagnostics count is unchanged, and so issync_heaps_handles_partially_committed_64k_pages.@Marvisak on GitHub · 2026-11-25 16:41 UTC · original · edited 2026-11-26 00:23 UTC
Automated triage for the maintainers.
Needs work (unchanged). The head (
dac5a4f) has not changed since the last review.sync_heapincrates/victory-gpu/src/descriptor.rsstill reads correctly, and CI (check) passes.On your reply: thanks for checking the
VirtualAlloc2behaviour. It confirms that a 64 KiB reservation can be committed in 4 KiB pieces, which was not in doubt. The missing piece is still a title run or trace that shows a placed shader-visible heap on such a reservation with uncommitted pages, or a fault insync_slots/mirror. With that, this becomes a fix for an observed case. Without it, it stays a guard that makes every written range's probe 16 times finer.Generated by Claude Code
@Texbirds on GitHub · 2026-11-25 17:13 UTC · original
Thanks for the question about where this layout can come from. The physical mapping path uses 64 KiB pages. There’s also a path through
XMemVirtualAlloc. An ordinary reservation is write-watched, and a laterMEM_COMMITat a non-null address forwards the requested size toVirtualAlloc2. Placed shader-visible heaps accept caller-provided memory, andwatch::trackcan track that reservation.I checked the Windows calls directly with a 64 KiB reservation. Committing just the first or second 4 KiB page made only that page readable in each case. That confirms the allocation path can produce the layout. The remaining evidence is a retail trace showing a placed shader-visible heap backed by such a reservation, or a crash trace in
sync_slots.@Texbirds on GitHub · 2026-11-25 22:38 UTC · original
Leaving
dac5a4fas-is (still merges cleanly ontof3578e3with CI green) while waiting to see if anyone hits a placed shader-visible heap on a partially committedXMemVirtualAllocreservation or async_slots/mirrorfault in a retail trace.@DenRakEiw on GitHub · 2026-11-25 13:57 UTC · original · approved these changes
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:descriptor::sync_heapscleanly avoids reading unmapped pages inside a partially committed descriptor heap.cargo test -p victory-gpu descriptor::tests: 6/6 passed on RTX 5090, 6/6 passed on WARP.cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 14:11 UTC · original · reviewed
Probe 4 KiB OS pages in descriptor sync_heaps. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
@imjustprism on GitHub · 2026-11-26 19:59 UTC · original · reviewed
ran
dac5a4fin the title to get the two things the triage asks for: whether the world ever shows a heap block with only some of its 4 KiB pages readable, and what the finer probe costs. rx 9070 xt, world, medians per frame:straddling)sync_heaps), ms63bcca4plus #2122 (this card needs it) plus local timers and counters, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run. of the six runs without, two are plain, three have #2051 and one has #3139 merged in; neither changes how often this path probes. no errors and no device removed in any run.so, in 24 minutes of world here: no probe failed and no block was partly readable, the edge path never ran (so the heap starts on a slot boundary), and the 16 times finer probe costs about 1.1 ms a frame in the probes alone. the whole sync per slot was above every run without in both runs, by 3% and by 21% over the highest of them; the two runs differ from each other as much as that, so beyond the probes' 1.1 ms i would not put a number on it.
i also read the title's executable for where such a layout could come from. in what a static read shows, its own calls that free memory release whole regions and none decommits part of one, and its
XMemVirtualAlloccalls reserve and commit in one call or re-reserve the pieces of a split reservation; none commits pieces inside a reservation it already holds. calls through pointers are not resolved by that, so it is not proof, but it agrees with the runs: i found nothing in this title that makes the layout.what i checked from the description:
sync_heaps_handles_partially_committed_64k_pagesand the otherdescriptortests pass here (hardware adapter).SyncSlotsdiagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above.sync_slotsreads the decommitted page raw). i did not run the test on main.points from reading the diff:
watch.rs:666and:701. when guarding a block fails,unmappedasks about the block's first byte only. with the first 4 KiB decommitted the block is counted as taken, dropped from the changed set and never guarded, so no later write to its other pages is seen. i added a second write and a second sync at the end of your test (same state, slot 262, thensync_heap, thenassert!(host.made(262))): it fails here. the cause is older than this pr, but it means the second half of the fix needswatchto keep such a block changed (or count it unmapped only when all of it is), and the test should pin the second sync.title_memory_remappedin the test (descriptor.rs:1118) also stands in for a report the runtime does not make on a 4 KiB decommit.descriptor.rs:174to:208. a fully readable 64 KiB block went from one probe and onesync_slotscall to 16 of each, and each call allocates two vectors and takesVIEWSandmade, all underSHADER_HEAPS.takealready knows which blocks are whole: a block it guarded hadVirtualProtectsucceed over all 64 KiB, which fails if any page is not committed. iftakehanded those back apart, they could keep one call with no probe, and only the blocks it could not guard would need the 4 KiB walk. that keeps your safety and takes the cost off the common case.descriptor.rs:185to:202, has no test (every test heap starts on a 64 KiB boundary, sostraddlingreturns at its first check) and this title never takes it. two things in it: a slot whose record ends beforebaseis still treated as straddling, so with an unaligned start it is mirrored and counted a second time; and the closure is named like a check but probes, mirrors and counts. a heap atpool + 8with the second page decommitted would cover it.descriptor.rs:169says mappings and commits change per 4 KiB page. the runtime maps and unmaps physical pages in whole 64 KiB pages; only a commit at an address throughXMemVirtualAllocor the title's ownVirtualFreecan be finer. worth saying which, since that is the whole case for the change.watch.rs:450gives write access back with oneVirtualProtectover the 64 KiB block and ignores the result. if a guarded block loses one 4 KiB page, the next write to another page of it faults, the reopen fails, the write faults again and is passed on (by reading; i did not run that one). so a title that did decommit this way would hit the write guard before it hitsync_heaps.nothing in
sync_heapitself is a wrong result: for an aligned heap the same slots reachsync_slotsin the same order as on main, and the index arithmetic and casts hold.@Texbirds on GitHub · 2026-11-26 20:11 UTC · original
Thanks a lot for running the 24-minute world measurements and checking the title's allocation paths — that gives a clear answer.
With 0 failed probes, 0 partially readable 64 KiB blocks, 0 straddling slots, and ~1.1 ms/frame of probe overhead (plus
watch.rsitself assuming 64 KiB granularity on reopen/unmapped checks), this guard isn't worth the hot-path cost. Closing this PR — appreciate the thorough review and data!Pull request closed