From 42266cfab3a800157f7b2a5606827a58074c9a76 Mon Sep 17 00:00:00 2001 From: earpjonathan <247878535+earpjonathan@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:41:10 +0000 Subject: [PATCH] perf(gpu): alias title buffers by default under Rosetta with D3DMetal VICTORY_ALIAS_BUFFERS is now on unless set to 0, under Rosetta with D3DMetal only (never WARP); the start-up probe still falls back to the host copies where the remap does not work. Aliased buffers need no copy-back after a submission, which otherwise runs under HELD before the submission's bottom-of-pipe writes land. docs/macos.md gives it a section of its own, out of the table of switches that change nothing by default. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/alias.rs | 36 +++++++++++++++++++++------------ docs/macos.md | 5 ++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/crates/victory-gpu/src/alias.rs b/crates/victory-gpu/src/alias.rs index 9c7743b3..16af509c 100644 --- a/crates/victory-gpu/src/alias.rs +++ b/crates/victory-gpu/src/alias.rs @@ -9,7 +9,9 @@ //! `VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE`) point the title's `VirtualAlloc` //! virtual address range directly at the D3DMetal buffer's physical pages. //! -//! Opt-in via `VICTORY_ALIAS_BUFFERS=1` on Rosetta + D3DMetal (never WARP). +//! On by default on Rosetta + D3DMetal (never WARP); `VICTORY_ALIAS_BUFFERS=0` +//! keeps the host copies. The probe at start-up ([`supported`]) still falls +//! back to the copies where the remap does not work. use std::sync::{Mutex, OnceLock}; @@ -221,20 +223,21 @@ mod mach { } } -fn decide_enabled(switch_on: bool, rosetta: bool, warp: bool) -> bool { - switch_on && rosetta && !warp +/// `asked`: `Some(on)` when `VICTORY_ALIAS_BUFFERS` is set (`0` is off, any +/// other value on), `None` when it is not: then on. +fn decide_enabled(asked: Option, rosetta: bool, warp: bool) -> bool { + asked.unwrap_or(true) && rosetta && !warp } -/// Whether `VICTORY_ALIAS_BUFFERS` is enabled on this host (Rosetta + D3DMetal). +/// Whether title buffers are aliased on this host: Rosetta + D3DMetal, +/// unless `VICTORY_ALIAS_BUFFERS=0`. pub fn enabled() -> bool { static ON: OnceLock = OnceLock::new(); *ON.get_or_init(|| { let warp = cfg!(feature = "diagnostics") && crate::switch::on("VICTORY_D3D12_WARP"); - decide_enabled( - crate::switch::on("VICTORY_ALIAS_BUFFERS"), - crate::watch::rosetta(), - warp, - ) + let asked = std::env::var_os("VICTORY_ALIAS_BUFFERS") + .map(|_| crate::switch::on("VICTORY_ALIAS_BUFFERS")); + decide_enabled(asked, crate::watch::rosetta(), warp) }) } @@ -550,10 +553,17 @@ mod tests { #[test] fn switch_respects_rosetta_and_warp() { - assert!(!decide_enabled(false, true, false)); - assert!(!decide_enabled(true, false, false)); - assert!(!decide_enabled(true, true, true)); - assert!(decide_enabled(true, true, false)); + assert!(!decide_enabled(Some(false), true, false)); + assert!(!decide_enabled(Some(true), false, false)); + assert!(!decide_enabled(Some(true), true, true)); + assert!(decide_enabled(Some(true), true, false)); + } + + #[test] + fn unset_is_on_under_rosetta_only() { + assert!(decide_enabled(None, true, false)); + assert!(!decide_enabled(None, false, false)); + assert!(!decide_enabled(None, true, true)); } #[test] diff --git a/docs/macos.md b/docs/macos.md index b4d94480..057d940e 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -226,6 +226,10 @@ The title's tile passes are indirect dispatches of one group per 8x4 tile of the The title has eight loops that write cache lines back with `clwb`, which faults under Rosetta and costs an exception each time (#135). Under Rosetta, the same check that decides fault tracking, `victory` turns the `clwb` of each loop into a NOP when it loads the image. It patches only when it finds exactly eight loops and logs the number it found otherwise. `VICTORY_NOP_CLWB=0` leaves the loops alone and `VICTORY_NOP_CLWB=1` patches them where Rosetta is not detected. +## Title buffers on D3DMetal's pages + +Under Rosetta with D3DMetal, memory the title commits read-write with `XMemVirtualAlloc`, in whole 64 KiB pages, is pointed at the pages of a D3DMetal buffer with `mach_vm_remap` (#204). The GPU then reads and writes the title's own memory, so those buffers need no host copy, no copy-back after a submission that wrote them, and no refresh before one. A probe at start-up falls back to the copies if the remap does not work, and `VICTORY_ALIAS_BUFFERS=0` keeps the copies. + ## Optional switches for slow storage, low memory and speed None of these changes the default. Each is read from the environment when the game starts, and all of them are tools for testers, so please post what you see on #131 or #135 when you try one. @@ -238,6 +242,5 @@ None of these changes the default. Each is read from the environment when the ga | `VICTORY_SPILL_SHADERS=1` | Keeps shader containers on disk until they are translated. The title passes tens of thousands of containers and draws with a few hundred, and holding them all took about 700 MB of an 8 GB Mac (#135). | | `VICTORY_READ_STATS=1` | Logs the requests and bytes read from each file, every 30 seconds, for the 30 most read. It shows which files a slow share serves most, so you can copy those to fast local storage. | | `VICTORY_GPU_BUDGET_MB=` | Sets the budget that host textures are kept under, in place of the device's. | -| `VICTORY_ALIAS_BUFFERS=1` | Under Rosetta with D3DMetal, points title buffers at the pages of a D3DMetal buffer with `mach_vm_remap`, so they need no host copies (#204). A probe at start-up falls back to the copies if the remap does not work. It has only synthetic tests so far, so it needs a run in the game. | | `VICTORY_WINDOW_SECONDARY=1` | Opens the game window on the only non-primary display. | | `VICTORY_WINDOW_SECONDARY=x,y` | Opens the game window on the display that holds the desktop point `x,y`, for layouts with more than one extra display (a Sidecar iPad beside two monitors, say). |