diff --git a/crates/victory-gpu/src/alias.rs b/crates/victory-gpu/src/alias.rs index 232dc281..85fdb7cb 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}; @@ -224,20 +226,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) }) } @@ -681,10 +684,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 f971a42b..b7bea368 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -246,6 +246,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. @@ -264,6 +268,5 @@ None of these changes the default. Each is read from the environment when the ga | `VICTORY_RENDER_SCALE=` | 0.5 to 1.0: the title's own upscaler's render scale (2/3 by default, Series X). Not yet tested on a Mac. | | `VICTORY_UPSCALER=<6\|7>` | Makes the title pick its own upscaler (6) or FidelityFX (7). Not yet tested on a Mac. | | `VICTORY_STEP_OVER=pool` | Steps over the title's "no free element" traps: an `int3` followed by `xor r, r`, the shape of a full fixed-size pool's allocator, whose caller then gets the NULL it already checks for. Series 1.0.2.1 hits one at `+0x5149aec` (the instance lists' pool, Marvisak/VIctory#698) about 20 minutes into the opening when frames take seconds. A list of hex offsets also works. | -| `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). |