Repository navigation
xmem: large graphics blocks get write-watched memory of their own - #3053
0xkn0wh3r3 wants to merge 1 commit into
Conversation
Without the title's allocation hooks, XMemAllocDefault served every block from the host heap, graphics memory included: committed resources' memory (allocator 128, victory_gpu::resource) was private memory the GPU side cannot watch, so their host copies were refreshed whole at every submission that used them (decision 0007 copies only the pages the title wrote since the last copy, which XMemVirtualAlloc's write-watched reservations make possible). Graphics blocks of 64 KiB and up, aligned to 64 KiB at most, now get a reservation of their own from XMemVirtualAlloc, as the runtime's memory is; XMemFreeDefault releases them. Other blocks come from the host heap as before. Titles with hooks are unaffected. large_graphics_blocks_are_write_watched checks the reservation, its alignment and release, and that small and non-graphics blocks stay on the heap.
- `cargo demo` is a synthwave drive into the sunset: a neon car, the camera following, spinning shapes along the highway (the stress scale), and it reports where each frame's time in VIctory goes, by call and by submission phase (victory_gpu::submission_totals). - Read-mark scans stop at the end of the view slots in use, dynamic slots counted (as Marvisak#3052 on main). - Large graphics blocks get write-watched memory of their own, so their host copies refresh only the pages written (as Marvisak#3053 on main).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed head 3069e4ff line-by-line (CI green):
graphics_blockroutesD3D_ALLOCATOR(128) allocations of>= 64 KiBwithalign <= 64 KiBtoXMemVirtualAlloc(..., MEM_RESERVE | MEM_COMMIT, GRAPHICS, PAGE_READWRITE), which setsMEM_WRITE_WATCHand satisfies<= 64 KiBalignment via Windows allocation granularity.- Lock/free ordering is sound:
WATCHED.insertruns before returning the address, andWATCHED.removeruns beforeVirtualFree(address, 0, MEM_RELEASE), avoiding any address-reuse ABA race.ALLOC_32BITstill takes precedence beforegraphics_block, andxmem.rshas noXMemSizeDefaultthat would read a missing block header. large_graphics_blocks_are_write_watchedverifiesGetWriteWatch, 64 KiB alignment,MEM_FREEafter release, and that smaller or non-graphics allocations stay on the host heap.
Minor non-blocking note: XMemFreeDefault acquires WATCHED on every free; an AtomicUsize count fast path when empty would avoid lock traffic on non-graphics frees.
kotekompotek
left a comment
There was a problem hiding this comment.
Verified: gating on allocator id 128 + size ≥64KiB + alignment ≤64KiB confines the new path to committed-resource blocks that fit a reservation; everything else keeps the heap path. WATCHED membership decides MEM_RELEASE so mixed frees can't misfree, and the write-watch flag means the GPU side now copies only written pages rather than the whole block per submission — the real win. The test verifies GetWriteWatch, 64KiB alignment, and MEM_FREE after release.
|
Automated triage for the maintainers. Thanks, agreed. This stays as is until #3021 lands and the net effect can be measured there. Generated by Claude Code |
|
Fair. The title this project runs takes its allocation hooks, so it never reaches this path, and the only numbers come from #3021's demo, where copy-back per submission went up. Without a case on main that benefits, I'll leave this waiting for #3021. Then it can be measured there with the copy-back cost included, or closed if that doesn't come out ahead. If it goes in, the |
…ebased onto upstream; its reworded test note)
|
Windows 11,
Synthetic only. AI-assisted. |
Without the title's allocation hooks, XMemAllocDefault served every block from the host heap, graphics memory included: committed resources' memory (allocator 128, victory_gpu::resource) was private memory the GPU side cannot watch, so their host copies were refreshed whole at every submission that used them (decision 0007 copies only the pages the title wrote since the last copy, which XMemVirtualAlloc's write-watched reservations make possible). Graphics blocks of 64 KiB and up, aligned to 64 KiB at most, now get a reservation of their own from XMemVirtualAlloc, as the runtime's memory is; XMemFreeDefault releases them. Other blocks come from the host heap as before. Titles with hooks are unaffected. large_graphics_blocks_are_write_watched checks the reservation, its alignment and release, and that small and non-graphics blocks stay on the heap. Port of Marvisak/VIctory#3053 (commit 3069e4ff).
For a title without allocation hooks,
XMemAllocDefaultserves every block from the host heap, graphics memory included. Committed resources' memory (allocator 128, fromvictory_gpu::resource) therefore lands in private memory the GPU side can't write-watch, so its host copies are refreshed whole at every submission that uses them. Decision 0007 is to copy only the pages written since the last copy, whichXMemVirtualAlloc's write-watched reservations make possible.Changes
XMemVirtualAlloc, write-watched like the runtime's memory.XMemFreeDefaultreleases them.Testing
large_graphics_blocks_are_write_watched. It checks the reservation is write-watched and 64 KiB aligned, that it's released on free, and that small and non-graphics blocks stay on the heap.xmemtests pass: cross-compiled for Windows in release and run under Wine and CrossOver on macOS. Not run on Windows.demo). The refresh phase fell 80–98% a submission: from 0.697 to 0.014 ms when a 14.7 MB compute output buffer is in use, and from 0.058 to 0.009 ms with 129 small submissions a frame.