From ae8fa94135c099a7e1cacdc2f23f9b0850394488 Mon Sep 17 00:00:00 2001 From: Davide Date: Sun, 29 Nov 2026 12:24:45 +0100 Subject: [PATCH] Windows in card memory the CPU maps on 16 GB cards too, not only on small hosts (VICTORY_WINDOWS_BAR_MB=4096 unset) With VICTORY_WINDOWS_BAR_MB unset, hosts with 24 GB of RAM or more kept windows outside buffers in shared GPU memory. Those whose card has a budget of 14 GiB or more (16 GB cards) now get the 4096 MiB cap that hosts with a small shared budget already get. Small hosts keep 4096/3072 as before (#1520), other cards keep it off, and an explicit value, 0 included, decides as before. window_mapped_for also returns at once without card memory the CPU maps, instead of counting the window and asking the host for a buffer it cannot make. RTX 5080 16 GB, 32 GB RAM, Series X 1440p DLSS Quality, 3-minute runs: shared GPU memory of the process 6.72/6.54 GB without, 4.36/4.95 GB with the switch and 4.47/4.66 GB with this default; the card's own 9.76/9.62 -> 11.62-11.87 GB; picture unchanged in the saved frames. --- crates/victory-gpu/src/shadow.rs | 79 +++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index 0c572f4ee7..bc8cb0b44d 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -763,8 +763,8 @@ fn window_card_for(size: u64) -> Option { } /// The most bytes of windows outside buffers that lie in the card's memory -/// and are filled by the CPU through the bus (`VICTORY_WINDOWS_BAR_MB`; 0, the -/// default, none): one buffer (`D3D12_HEAP_TYPE_GPU_UPLOAD`), no CPU's side, no +/// and are filled by the CPU through the bus (`VICTORY_WINDOWS_BAR_MB`; unset, +/// [`window_mapped_default`]): one buffer (`D3D12_HEAP_TYPE_GPU_UPLOAD`), no CPU's side, no /// copy to send and no list of changes, unlike [`window_card_most`]. The CPU /// only writes them, as no shader is declared to write a window; if one were, /// its snapshot and compare would read through the bus, right but slow. In a @@ -776,25 +776,66 @@ fn window_card_for(size: u64) -> Option { fn window_mapped_most() -> u64 { static MOST: std::sync::OnceLock = std::sync::OnceLock::new(); *MOST.get_or_init(|| { - // Unset: 4096 when the shared budget is small and card memory can be - // mapped; else 3072 on a small host, by itself: Windows lets a card - // share at most half the RAM, and the windows filled that on a 16 GB - // PC (RTX 3060) about a minute into the world: `0x8007000E` on a host - // command list, then a driver fault (issue #1520; PR #6, the - // launcher's auto of 85a529b, lost when the script became a shim). - // An explicit `VICTORY_WINDOWS_BAR_MB` (0 included) decides as before. - // Bigger machines keep it off, as before. - let unset = if crate::residency::shared_is_small() { - 4096 - } else if crate::residency::small_host_ram() { - 3072 - } else { - 0 - }; + let big_card = host() + .and_then(|host| host.video_memory()) + .is_some_and(|[budget, ..]| budget >= WINDOW_MAPPED_BIG_CARD); + let unset = window_mapped_default( + crate::residency::shared_is_small(), + crate::residency::small_host_ram(), + big_card, + ); std::env::var("VICTORY_WINDOWS_BAR_MB").ok().and_then(|v| v.trim().parse::().ok()).unwrap_or(unset) << 20 }) } +/// The card's own budget from which a host that is neither of the small ones +/// puts windows in card memory the CPU maps by itself: 16 GB cards (an RTX +/// 5080 reports 15,209 MB), not 12 or 8 GB ones, whose render targets, +/// texture floor and card copies arrive after the windows and need the room. +const WINDOW_MAPPED_BIG_CARD: u64 = 14 << 30; + +/// [`window_mapped_most`] in MiB when `VICTORY_WINDOWS_BAR_MB` is unset. +/// 4096 when the shared budget is small and card memory can be mapped; else +/// 3072 on a small host, by itself: Windows lets a card share at most half +/// the RAM, and the windows filled that on a 16 GB PC (RTX 3060) about a +/// minute into the world: `0x8007000E` on a host command list, then a driver +/// fault (issue #1520; PR #6, the launcher's auto of 85a529b, lost when the +/// script became a shim). Else 4096 on a card with a big budget +/// ([`WINDOW_MAPPED_BIG_CARD`]): on an RTX 5080 16 GB with 32 GB of RAM the +/// process's shared GPU memory was 1.6-2.4 GB lower in the world and the +/// card's own 1.9-2.2 GB higher, with the picture unchanged. Other machines +/// keep them off, as before. An explicit +/// `VICTORY_WINDOWS_BAR_MB` (0 included) decides as before. +fn window_mapped_default(shared_small: bool, small_ram: bool, big_card: bool) -> u64 { + if shared_small { + 4096 + } else if small_ram { + 3072 + } else if big_card { + 4096 + } else { + 0 + } +} + +#[cfg(test)] +mod window_mapped_default_tests { + use super::window_mapped_default; + + #[test] + fn big_cards_get_windows_in_card_memory_small_hosts_as_before() { + // The small hosts, whatever the card: as before. + for big_card in [false, true] { + assert_eq!(window_mapped_default(true, true, big_card), 4096); + assert_eq!(window_mapped_default(true, false, big_card), 4096); + assert_eq!(window_mapped_default(false, true, big_card), 3072); + } + // A bigger host: only with a big card. + assert_eq!(window_mapped_default(false, false, true), 4096); + assert_eq!(window_mapped_default(false, false, false), 0); + } +} + /// Bytes alive of windows in card memory the CPU maps. static WINDOW_MAPPED_BYTES: AtomicU64 = AtomicU64::new(0); @@ -806,6 +847,10 @@ fn window_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> { return None; } let host = host()?; + // Nothing to ask for without card memory the CPU maps (no resizable BAR). + if !host.mapped_card_memory() { + return None; + } if let Some([budget, used, ..]) = host.video_memory() && used + size > budget / 10 * 8 {