xmem: large graphics blocks get write-watched memory of their own #3053
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!3053
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@0xkn0wh3r3 on GitHub · 2026-11-26 05:35 UTC · original
0xkn0wh3r3:xmem/write-watched-graphics-blocks→main· +67 −1 · 1 files · 1 commits · openFor 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.@Marvisak on GitHub · 2026-11-26 06:18 UTC · original · edited 2026-11-26 07:20 UTC
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
@0xkn0wh3r3 on GitHub · 2026-11-26 06:43 UTC · original
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.@fuzeofficlal on GitHub · 2026-11-26 05:45 UTC · original · approved these changes
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.@kotekompotek on GitHub · 2026-11-26 06:01 UTC · original · approved these changes
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.@Jackster on GitHub · 2026-11-26 16:24 UTC · original
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.
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.