Repository navigation
feat(gpu): add opt-in mach_vm_remap zero-copy title buffer aliasing - #207
Conversation
|
A first in-game data point for The aliasing came up: But the run never got past the loading artwork:
The same build without the switch reaches the world in about 6 minutes. So GPU reads through the remapped pages may be very slow under D3DMetal (uncached, or faulting per page?). I'm happy to rerun with any extra logging you'd like. 🤖 Generated with Claude Code |
|
@derz92 thanks for running it in game, that's the test this needed. My best guess is the guards. On main, a GPU write into aliased memory goes through The version I have that works in game does it differently. A GPU write into aliased memory only marks the blocks as written in the trackers: no guard opened, no bytes saved (the write already happened, there's no "before" to keep), and the CPU side keeps its protection, so the title's own writes are still seen. That's the same idea as Marvisak/VIctory@29decb3 ( Cheap way to check before changing anything: a diagnostics run with the switch on that counts protection changes per frame. If they jump with |
|
A correction to my run above. That build included #279, and I later found that #279 alone stops this title on the loading artwork here: three runs froze with it, including one with no experimental switches, and runs with it reverted reach the world (details on #279). So the loading freeze I reported is most likely #279, not aliasing. The 10-11 s loading-screen frames with 2-5 s on the GPU are the only part I can't attribute yet. I'm rerunning 🤖 Generated with Claude Code |
Summary
Implements opt-in zero-copy title buffer aliasing on Apple Silicon + D3DMetal using raw
mach_msg2_trap/mach_vm_remap(VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE,copy = FALSE), based on the probe and approach documented by @Ahmet-Dedeler in #204.No game files were used for any of this.
What changed
crates/victory-gpu/src/alias.rs:machmodule callingmach_task_self,mach_reply_port(cached inOnceLockto avoid leaking ports), andmach_vm_remap(msgh_id = 4813) viamach_msg2_trapwithMACH64_SEND_KOBJECT_CALLonx86_64.enabled()gated behindVICTORY_ALIAS_BUFFERS=1on Rosetta + non-WARP, plus a one-timesupported()probe that verifiesmach_vm_remaponto a write-back L0shared_bufferand checks whether fresh buffers are zero-initialized (falling back cleanly to shadow copies if unsupported).alias_region(base, len, preserve_contents)andunalias_region(base)plus 6 synthetic tests covering CPU↔GPU coherence, overlapping texture tracker notification, widened RGB32 view refresh,VirtualQuery+VirtualProtectwrite-guard VEH,unalias_region+VirtualFree, and switch gating.crates/victory-gpu/src/shadow.rs:Shadow::new_aliasedand anALIASEDregion registry wired intofind,all, andnear.clean,update,writing,copy_back_or_not,copy_back_marked, andcopy_back_pagewhile preserving widened RGB32 view refreshes and notifying overlapping texture trackers.crates/victory-gpu/src/watch.rs: Addednotify_writtento mark overlapping texture/alias trackers when GPU shaders write aliased title memory.crates/victory-gpu/src/bindless.rs&crates/victory-gpu/src/memory.rs: Skip clean shadows (!shadow.clean()) before queuing refreshes.crates/victory-gpu/src/lib.rs&crates/victory-hle/src/modules/xmem.rs: Exportedalias_buffers,alias_region,unalias_regionand hookedXMemVirtualAlloc/XMemFreeDefaultwhenVICTORY_ALIAS_BUFFERS=1.Testing
Tested on Apple M4 (16 GB), macOS 27.2.1, CrossOver 26.2 + D3DMetal 3.0 (no game files used):
cargo xtask policy:244 files okcargo clippy --target x86_64-pc-windows-gnullvm -p victory-gpu -p victory-hle --all-targets: 0 warnings in touched filescargo test --workspace(native): 519 passed, 0 failed, 17 ignoredtools/macos/test-wine.sh -p victory-gpu --lib -- --test-threads=1: 305 passed, 0 failed, 9 ignored (all 6 newalias::testspassed)VICTORY_ALIAS_BUFFERS=1 tools/macos/test-wine.sh -p victory-hle --lib xmem -- --test-threads=1: 16 passed, 0 failed, 0 ignoredMentioning #204 without closing words so testers with a game dump can validate in-game under
VICTORY_ALIAS_BUFFERS=1first.