Repository navigation
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:
- Probing 4 KiB OS pages in
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).
|
Reviewed — the 4 KiB probing is right and fixes a real fault path:
|
catminou4
left a comment
There was a problem hiding this comment.
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.
89f093a to
dac5a4f
Compare
|
Rebased onto |
|
Automated triage for the maintainers. Needs work (unchanged). The head ( On your reply: thanks for checking the Generated by Claude Code |
|
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 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 |
|
Leaving |
imjustprism
left a comment
There was a problem hiding this comment.
ran dac5a4f in 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:
| per frame | without, 6 runs | with this pr, run 1 | run 2 |
|---|---|---|---|
| 4 KiB probes | 2,715 | 2,348 | |
| probes that failed | 0 | 0 | |
| 64 KiB blocks with both readable and unreadable pages | 0 | 0 | |
slots that took the edge path (straddling) |
not counted | 0 | |
| time in the probes, ms | not timed | 1.1 | |
heap sync (sync_heaps), ms |
10.6 to 14.3 | 16.4 | 12.0 |
| slots scanned | 308,000 to 379,000 | 347,000 | 301,000 |
| heap sync, ms per 100,000 slots | 3.0 to 3.9 | 4.7 | 4.0 |
63bcca4 plus #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 XMemVirtualAlloc calls 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).- "the
SyncSlotsdiagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above. - "faults on main" for case 1: by reading, yes (
sync_slotsreads the decommitted page raw). i did not run the test on main. - case 2, "skips the entire block without mirroring those descriptors": fixed for the first sync only, see the first point.
points from reading the diff:
- case 2 holds for one sync,
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. - cost,
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. - the edge path,
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. - the comment at
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. - not this pr's, but on the same premise:
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_heap itself is a wrong result: for an aligned heap the same slots reach sync_slots in the same order as on main, and the index arithmetic and casts hold.
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 |
Problem
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).