xmem: large graphics blocks get write-watched memory of their own #3051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3053"
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 Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T05:35:27Z.
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.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:45:14Z.
Review: APPROVED
Reviewed head
3069e4ffline-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.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:
XMemFreeDefaultacquiresWATCHEDon every free; anAtomicUsizecount fast path when empty would avoid lock traffic on non-graphics frees.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:01:24Z.
Review: APPROVED
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.
WATCHEDmembership 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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:18:31Z.
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
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T06:43:36Z.
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
WATCHEDlookup inXMemFreeDefaultwill only run for allocator-128 attributes, so other frees skip the lock.Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:24:53Z.
Windows 11,
63bcca4+ this PR:cargo test -p victory-hle xmem::: 15 passed, 0 failed, includinglarge_graphics_blocks_are_write_watched.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.Synthetic only. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by djasdh on 2026-11-28T18:09:46Z.
A data point on the "titles with hooks are unaffected" note, from GTA VI.
Setup: RX 6900 XT (RADV, Mesa 26.3.1), Linux, Wine 11.0, 1920x1080, Series S profile.
This build of the title has no
__XMemAllocationHooks__: it reachesXMemAllocDefault, so its committed resources' memory (allocator 128) lands on the host heap. One 21 MB buffer (0x1412200bytes) was copied whole twice a frame:copied whole 2.0x/frame, 42.09 MB/frame;traffic: 21.05 MB up / 21.04 MB fetchedcopied whole (memory not watched)0 ranges;traffic: 0.00 MB up / 21.04 MB fetched; frame copies 109.8 -> 84.5 MBThe fetched side is unchanged (the shaders do write it); only the redundant host-to-card copy goes. So with empty hooks this title does take the path, and the win is on a real frame, not only the demo.
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.