From df5780ab515564c1b6cd0086b6b94b5b65830bdf Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Sun, 29 Nov 2026 15:28:55 +0100 Subject: [PATCH 1/2] d3d12: LEONIDA_WINDOWS_BAR_MB says once that it does nothing without resizable BAR (D3D12-BAR-WINDOWS-WARNING) Title memory windows can only go to card memory the CPU maps when the card has GPU upload heaps (resizable BAR, and a system and driver that offer it). Without them the launcher still set 3072 on PCs under 48 GB of RAM and printed "up to 3 GB", and every window asked the card's budget (two QueryVideoMemoryInfo calls) before finding out the heap was not there. window_mapped_for now checks for that memory first and logs once that the cap does nothing. The launcher's line says the cap needs resizable BAR, and its header and the README give the real default (under 48 GB of RAM, a card of 6 GB or more) instead of "under 24 GB". --- d3d12/README.md | 6 ++- d3d12/crates/leonida-gpu/src/shadow.rs | 54 ++++++++++++++++++++++++++ d3d12/scripts/play-nvidia.ps1 | 7 ++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/d3d12/README.md b/d3d12/README.md index 2e69a1da65..7fb1799554 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -511,8 +511,10 @@ 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) and a card of 6 GB or more, and leaves it off + otherwise. It only takes effect with resizable BAR: without it 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..ded7a4427f 100644 --- a/d3d12/crates/leonida-gpu/src/shadow.rs +++ b/d3d12/crates/leonida-gpu/src/shadow.rs @@ -1009,6 +1009,29 @@ 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 when the card +/// does or does not have memory the CPU maps (`supported`: a resizable BAR, +/// and a system and driver that offer it). +#[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: bool) -> MappedWindows { + match (most, supported) { + (0, _) => MappedWindows::Off, + (_, false) => MappedWindows::Unsupported, + (_, true) => MappedWindows::Try, + } +} + /// 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)> { @@ -1017,6 +1040,21 @@ fn window_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> { 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::warn!( + mb = most >> 20, + "LEONIDA_WINDOWS_BAR_MB is set, but the card has no memory the CPU maps (no resizable BAR): \ + title memory windows stay out of it 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; + assert_eq!(mapped_windows(0, false), MappedWindows::Off); + assert_eq!(mapped_windows(0, true), MappedWindows::Off); + // Without a resizable BAR the launcher's cap is said once and skipped, + // 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 5b871aadf5..bbf9e758ee 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -46,8 +46,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 and a card of 6 GB or more, else 0; -WindowsBarMB 0 turns it off). # -More other settings: -More @{LEONIDA_PANEL='1'} # -DryRun prints the settings this start would run with (after the F1 menu's saved ones) and stops: nothing # is built or started @@ -409,7 +409,8 @@ 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 resizable BAR has that memory; without it 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)" } } From 877c0d14a8e2c43e809f5f913bcb929ba3694f1f Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Sun, 29 Nov 2026 17:36:49 +0100 Subject: [PATCH 2/2] d3d12: BAR-windows note at info level, names GPU upload heaps, and the decision covers the off case (review) - The note is info, not a warning: the launcher sets the cap by default on PCs under 48 GB, so it shows on every one without resizable BAR. - It names the real condition (GPU upload heaps: resizable BAR, and a Windows and driver that offer them), as the doc comments do. - mapped_windows asks for support only when a cap is set, so its "off" case is the one the code takes, and the test checks that support is not asked. - The launcher's history comment and the README say "unless the card has under 6 GB" (an unknown size counts as large). --- d3d12/README.md | 7 +++-- d3d12/crates/leonida-gpu/src/shadow.rs | 42 +++++++++++++------------- d3d12/scripts/play-nvidia.ps1 | 7 +++-- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/d3d12/README.md b/d3d12/README.md index 7fb1799554..b1e5d35f0a 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -512,9 +512,10 @@ What to expect: 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 48 GB of RAM (Windows lets - the card share half the RAM) and a card of 6 GB or more, and leaves it off - otherwise. It only takes effect with resizable BAR: without it the runtime - logs once that the cap does nothing. Pass a cap in + 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 ded7a4427f..6c00c7d5e7 100644 --- a/d3d12/crates/leonida-gpu/src/shadow.rs +++ b/d3d12/crates/leonida-gpu/src/shadow.rs @@ -1009,9 +1009,9 @@ 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 when the card -/// does or does not have memory the CPU maps (`supported`: a resizable BAR, -/// and a system and driver that offer it). +/// 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. @@ -1024,11 +1024,13 @@ enum MappedWindows { Try, } -fn mapped_windows(most: u64, supported: bool) -> MappedWindows { - match (most, supported) { - (0, _) => MappedWindows::Off, - (_, false) => MappedWindows::Unsupported, - (_, true) => MappedWindows::Try, +fn mapped_windows(most: u64, supported: impl FnOnce() -> bool) -> MappedWindows { + if most == 0 { + MappedWindows::Off + } else if supported() { + MappedWindows::Try + } else { + MappedWindows::Unsupported } } @@ -1036,19 +1038,17 @@ fn mapped_windows(most: u64, supported: bool) -> MappedWindows { /// 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()) { + 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::warn!( + tracing::info!( mb = most >> 20, - "LEONIDA_WINDOWS_BAR_MB is set, but the card has no memory the CPU maps (no resizable BAR): \ - title memory windows stay out of it and the setting does nothing" + "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; @@ -7509,12 +7509,12 @@ mod mapped_windows_tests { #[test] fn a_cap_does_nothing_on_a_card_without_memory_the_cpu_maps() { let cap = 3072 << 20; - assert_eq!(mapped_windows(0, false), MappedWindows::Off); - assert_eq!(mapped_windows(0, true), MappedWindows::Off); - // Without a resizable BAR the launcher's cap is said once and skipped, - // before any window asks the card's budget. - assert_eq!(mapped_windows(cap, false), MappedWindows::Unsupported); - assert_eq!(mapped_windows(cap, true), MappedWindows::Try); + // 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); } } diff --git a/d3d12/scripts/play-nvidia.ps1 b/d3d12/scripts/play-nvidia.ps1 index bbf9e758ee..363a8d80b5 100644 --- a/d3d12/scripts/play-nvidia.ps1 +++ b/d3d12/scripts/play-nvidia.ps1 @@ -47,7 +47,7 @@ # -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, which needs resizable BAR (by default -# 3072 on PCs with under 48 GB of RAM and a card of 6 GB or more, else 0; -WindowsBarMB 0 turns it off). +# 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'} # -DryRun prints the settings this start would run with (after the F1 menu's saved ones) and stops: nothing # is built or started @@ -400,7 +400,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 @@ -409,7 +409,8 @@ 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' - # Only a card with resizable BAR has that memory; without it the runtime says so once and the cap does nothing. + # 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)" } }