diff --git a/d3d12/README.md b/d3d12/README.md index 5ccdb28686..0ace876675 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -530,8 +530,11 @@ What to expect: limit about a minute into the world (`0x8007000E`, then a driver fault). The 3072 MiB cap from [PR #6](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/6) let eligible title memory windows use CPU-mapped VRAM while the card had room. - The launcher sets it by itself on PCs with under 24 GB of RAM (Windows lets - the card share half the RAM) and leaves it off on larger ones. Pass a cap in + The launcher sets it by itself on PCs with under 48 GB of RAM (Windows lets + the card share half the RAM), unless the card has under 6 GB, and leaves it + off otherwise. It only takes effect where the card has GPU upload heaps + (resizable BAR, and a Windows and driver that offer it): without them the + runtime logs once that the cap does nothing. Pass a cap in MiB to `play-nvidia.ps1` or any resolution wrapper to choose for yourself: `-WindowsBarMB 0` disables it, and `-More @{LEONIDA_WINDOWS_BAR_MB='...'}` takes precedence. diff --git a/d3d12/crates/leonida-gpu/src/shadow.rs b/d3d12/crates/leonida-gpu/src/shadow.rs index e7c9cf09b1..6c00c7d5e7 100644 --- a/d3d12/crates/leonida-gpu/src/shadow.rs +++ b/d3d12/crates/leonida-gpu/src/shadow.rs @@ -1009,14 +1009,52 @@ fn window_mapped_most() -> u64 { /// Bytes alive of windows in card memory the CPU maps. static WINDOW_MAPPED_BYTES: AtomicU64 = AtomicU64::new(0); +/// What [`window_mapped_for`] may do with a cap of `most` bytes; `supported` +/// says whether the card has memory the CPU maps (GPU upload heaps: resizable +/// BAR, and a Windows and driver that offer it), asked only for a cap. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum MappedWindows { + /// The cap is 0, the default: windows never go there. + Off, + /// A cap is set but the card has no such memory: it does nothing, which + /// the log says once, and no window asks the card's budget for it. + Unsupported, + /// A cap is set and the card has the memory: windows go there while it + /// has room. + Try, +} + +fn mapped_windows(most: u64, supported: impl FnOnce() -> bool) -> MappedWindows { + if most == 0 { + MappedWindows::Off + } else if supported() { + MappedWindows::Try + } else { + MappedWindows::Unsupported + } +} + /// A buffer for a window of `size` bytes in card memory the CPU maps, if it is /// to be there ([`window_mapped_most`]). fn window_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> { let most = window_mapped_most(); - if most == 0 { - return None; - } let host = host()?; + match mapped_windows(most, || host.mapped_card_memory()) { + MappedWindows::Off => return None, + MappedWindows::Unsupported => { + static SAID: std::sync::Once = std::sync::Once::new(); + SAID.call_once(|| { + tracing::info!( + mb = most >> 20, + "LEONIDA_WINDOWS_BAR_MB is set, but the card has no GPU upload heap (it needs resizable BAR, and a \ + Windows and driver that offer it): title memory windows stay in the PC's memory and the setting \ + does nothing" + ); + }); + return None; + } + MappedWindows::Try => {} + } if let Some([budget, used, ..]) = host.video_memory() && used + size > budget / 10 * 8 { @@ -7464,6 +7502,22 @@ mod refresh_dirty_tests { } } +#[cfg(test)] +mod mapped_windows_tests { + use super::{MappedWindows, mapped_windows}; + + #[test] + fn a_cap_does_nothing_on_a_card_without_memory_the_cpu_maps() { + let cap = 3072 << 20; + // Without a cap the card is not even asked. + assert_eq!(mapped_windows(0, || unreachable!("asked without a cap")), MappedWindows::Off); + // Without GPU upload heaps the launcher's cap is skipped (and said + // once by the caller) before any window asks the card's budget. + assert_eq!(mapped_windows(cap, || false), MappedWindows::Unsupported); + assert_eq!(mapped_windows(cap, || true), MappedWindows::Try); + } +} + #[cfg(test)] mod window_memory_tests { use super::Memory; diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index 4f40e20599..b73dedabc7 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -51,8 +51,8 @@ # half drawn or stall while they are made. # -Log the layer's log goes to a file in %LOCALAPPDATA%\Leonida\logs instead of this window # -Capture F9 in the game saves that frame and the pictures it drew, in %LOCALAPPDATA%\Leonida\captures -# -WindowsBarMB maximum MiB of title memory windows in CPU-mapped VRAM (by default 3072 on PCs with under -# 24 GB of RAM, else 0; -WindowsBarMB 0 turns it off). +# -WindowsBarMB maximum MiB of title memory windows in CPU-mapped VRAM, which needs resizable BAR (by default +# 3072 on PCs with under 48 GB of RAM, unless the card has under 6 GB, else 0; -WindowsBarMB 0 turns it off). # -More other settings: -More @{LEONIDA_PANEL='1'} # -PcGlyphs a folder of your own pictures for the keyboard-and-mouse button prompts (docs/prompt_glyphs.md) # instead of the built-in key caps @@ -479,7 +479,7 @@ if ($Adapter) { $settings.LEONIDA_ADAPTER = $Adapter } if ($PSBoundParameters.ContainsKey('WindowsBarMB')) { $settings.LEONIDA_WINDOWS_BAR_MB = $WindowsBarMB.ToString([Globalization.CultureInfo]::InvariantCulture) } else { - # Without -WindowsBarMB, PCs with under 24 GB of RAM get 3072 (PR #6). Windows lets a card share at most half + # Without -WindowsBarMB, PCs with under 48 GB of RAM get 3072 (under 24 GB at first, PR #6). 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, then # a driver fault). 32 GB and more never got there, so they keep the runtime default (0, off). # Under 48 GB since 2026-11-27: on a 32 GB PC the layer held 28 GB (19 of it in memory), the PC had 745 MB @@ -488,7 +488,9 @@ if ($PSBoundParameters.ContainsKey('WindowsBarMB')) { $ram = try { (Get-CimInstance Win32_ComputerSystem -ErrorAction Stop).TotalPhysicalMemory } catch { 0 } if ($ram -gt 0 -and $ram -lt 48GB -and -not $smallCard) { $settings.LEONIDA_WINDOWS_BAR_MB = '3072' - Write-Host "$([math]::Round($ram / 1GB)) GB of RAM: title memory windows in the card's memory the CPU maps, up to 3 GB (-WindowsBarMB 0 turns this off)" + # Only a card with GPU upload heaps (resizable BAR, and a Windows and driver that offer it) has that memory; + # without them the runtime says so once and the cap does nothing. + Write-Host "$([math]::Round($ram / 1GB)) GB of RAM: title memory windows in the card's memory the CPU maps, up to 3 GB, if the card has resizable BAR (-WindowsBarMB 0 turns this off)" } }