diff --git a/apps/victory/src/play.rs b/apps/victory/src/play.rs index 2d6beacc3d..504e077213 100644 --- a/apps/victory/src/play.rs +++ b/apps/victory/src/play.rs @@ -1129,6 +1129,36 @@ fn memory_warning(ram: u64, files: &[String]) -> Option { )) } +/// [`memory_warning`] where Windows manages the page file's size, which it says +/// nothing of: programs can commit `limit` bytes now (RAM and the page file at its +/// present size, `streamline::commit_limit`), and Windows makes the file larger +/// only after a commit was refused, the moment the game stops. On a PC of 13.9 GB +/// of RAM, an RTX 5060 Ti 8 GB and a system-managed page file the game stopped at +/// 22.5 GB committed (0x8007000E, then the card removed, 2026-11-29); afterwards +/// the file had grown to 20 GB and Windows allowed 33.9 GB. `None`: the size is +/// not Windows' to manage ([`memory_warning`] speaks of it), or there is enough. +fn managed_page_file_warning(ram: u64, files: &[String], limit: Option) -> Option { + if page_files_most_mb(files).is_some() { + return None; + } + let gb = |bytes: u64| bytes as f64 / (1u64 << 30) as f64; + let limit = limit?; + if gb(limit) >= MEMORY_NEEDED_GB as f64 { + return None; + } + let page_file = gb(limit.saturating_sub(ram)); + let needed_mb = (MEMORY_NEEDED_GB as f64 - gb(ram)).ceil() * 1024.0; + Some(format!( + "Windows can give programs {:.0} GB of memory at the moment: {:.0} GB of RAM and a page file of {page_file:.0} GB that Windows sizes itself.\n\ + While the game runs it can take about 48 GB, and Windows makes its page file larger only after memory has run out:\n\ + that is the moment the game stops (\"Failed to allocate\", or 0x8007000E and a black screen).\n\ + Fix: Start, type \"View advanced system settings\", then Performance: Settings, Advanced, Virtual memory: Change.\n\ + Untick \"Automatically manage\", pick the SSD, Custom size: initial and maximum {needed_mb:.0} MB, Set, then restart Windows.", + gb(limit), + gb(ram), + )) +} + /// The file that says this victory.exe (its bytes) had its first start, where /// every shader was made before the game ran: `%LOCALAPPDATA%\victory\warmed\`. /// `None`: the exe could not be read. @@ -1196,6 +1226,7 @@ pub(crate) fn prepare(o: &Play) -> Result { check_shader_model()?; if let Some((ram, files)) = victory_hle::streamline::ram_and_page_files() && let Some(warning) = memory_warning(ram, &files) + .or_else(|| managed_page_file_warning(ram, &files, victory_hle::streamline::commit_limit())) { println!("{warning}"); } @@ -1925,4 +1956,20 @@ VICTORY_MENU_S_RES=360 assert_eq!(memory_warning(64 * GB, &[]), None); assert_eq!(memory_warning(16 * GB, &files(&[r"?:\pagefile.sys"])), None); } + + /// A page file Windows sizes: the warning reads what programs can have now, and asks + /// for a fixed size of what is missing to 52 GB. + #[test] + fn a_page_file_windows_sizes_is_warned_of_by_what_it_allows_now() { + let files = |f: &[&str]| f.iter().map(|s| (*s).to_owned()).collect::>(); + let managed = files(&[r"C:\pagefile.sys 0 0"]); + let warning = managed_page_file_warning(14 * (1u64 << 30), &managed, Some(22 * (1u64 << 30))).expect("22 GB now"); + assert!(warning.contains("22 GB of memory at the moment") && warning.contains("14 GB of RAM and a page file of 8 GB"), "{warning}"); + assert!(warning.contains("initial and maximum 38912 MB"), "{warning}"); + assert!(managed_page_file_warning(14 * (1u64 << 30), &files(&[r"?:\pagefile.sys"]), Some(22 * (1u64 << 30))).is_some()); + assert_eq!(managed_page_file_warning(14 * (1u64 << 30), &managed, Some(60 * (1u64 << 30))), None, "enough now"); + assert_eq!(managed_page_file_warning(14 * (1u64 << 30), &managed, None), None, "not read"); + // A size of the player's own: `memory_warning` speaks of it. + assert_eq!(managed_page_file_warning(14 * (1u64 << 30), &files(&[r"C:\pagefile.sys 4096 8192"]), Some(22 * (1u64 << 30))), None); + } } diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs index 94ebfcc851..3ec22a7d47 100644 --- a/crates/victory-gpu/src/resource.rs +++ b/crates/victory-gpu/src/resource.rs @@ -2029,6 +2029,57 @@ fn texture_floor_bytes(vram_budget: Option) -> u64 { } } +/// The cap on the bytes of host copies of title textures on a PC of under 24 GB +/// of RAM (`residency::small_host_ram`), `VICTORY_TEXTURE_CAP_MB`: unset, 1024 MB +/// there and none elsewhere; `0`, none; a number of MB, that. Not with +/// `VICTORY_TEXTURE_BUDGET_MB`, whose limit is absolute. +/// +/// There Windows lets the card share at most half the RAM, and past the card's +/// own budget what the layer makes goes into that shared part. On a PC of +/// 13.9 GB with an RTX 5060 Ti 8 GB (a shared budget of 6,502 MB) the textures +/// took 3.4 GB of the card, the host copies of title buffers found it full +/// ("no card copy for a title buffer"), 1,132 MB of them were on the card and +/// some 4.4 GB in the shared memory, and the world's load grew them by 712 MB in +/// 5.6 s: 0x8007000E at the end of the load in four starts of four, whatever +/// the console, picture size or page file (2026-11-29). At the load's peak the +/// card held 2.2 GB of textures, 2.1 GB of buffer copies and 2.4 GB of the rest, +/// and each GB the textures give up the buffer copies take from the shared +/// memory. Held to 2 GB (the face allowance, below, past it) four starts of four +/// still stopped, the shared memory at 6.56 to 6.76 GB; to 1.5 GB one start +/// passed the load with 32 MB to spare; to 1 GB four starts of five played the +/// six minutes measured, the shared memory at most 5,666 to 6,108 MB (the fifth +/// stopped at 6,644 MB, its buffer copies peaking 378 MB higher than a start +/// that played on). +#[cfg(any(windows, test))] +fn texture_cap_for(small_ram: bool, setting: Option<&str>) -> Option { + const SMALL_HOST_CAP: u64 = 1 << 30; + match setting.map(str::trim) { + Some(mb) => mb.parse::().ok().filter(|&mb| mb > 0).map(|mb| mb << 20), + None => small_ram.then_some(SMALL_HOST_CAP), + } +} + +/// [`texture_cap_for`] this PC, said once. +#[cfg(windows)] +fn texture_cap() -> Option { + static CAP: std::sync::OnceLock> = std::sync::OnceLock::new(); + *CAP.get_or_init(|| { + if texture_budget_limit().is_some() { + return None; + } + let setting = std::env::var("VICTORY_TEXTURE_CAP_MB").ok(); + let cap = texture_cap_for(crate::residency::small_host_ram(), setting.as_deref()); + if let Some(cap) = cap { + tracing::info!( + cap_mb = cap >> 20, + "host copies of title textures held to a cap, so that the card keeps room for the copies of title buffers \ + (a PC of under 24 GB of RAM; VICTORY_TEXTURE_CAP_MB=0: none, =: that)" + ); + } + cap + }) +} + /// The byte limit on host copies of title textures, if /// `VICTORY_TEXTURE_BUDGET_MB` is set. #[cfg(windows)] @@ -2070,6 +2121,11 @@ pub(crate) fn room(memory: Option<[u64; 4]>) -> bool { if let Some(limit) = limit { return filled < limit; } + // Before the floor: on a card of 8 GB the floor is a quarter of its budget, + // under the cap; a cap set lower than the floor is what was asked. + if texture_cap().is_some_and(|cap| filled >= cap) { + return false; + } let floor = texture_floor_bytes(memory.map(|[budget, ..]| budget)); if filled < floor { return true; @@ -2194,6 +2250,7 @@ pub(crate) fn room_for_first_upload(memory: Option<[u64; 4]>, reserve: u64) -> b // ponytail: a scan per over-budget decision; keep a running widest in // pool.rs if it shows in a profile. if memory.is_some_and(|[budget, used, ..]| used >= budget) { crate::pool::texture_widest_free() } else { 0 }, + texture_cap(), ); FIRST_UPLOAD_REASONS[why as usize].fetch_add(1, std::sync::atomic::Ordering::Relaxed); why == FirstUpload::Allow @@ -2237,6 +2294,7 @@ fn first_upload_decision( _counted: u64, free_blocks: u64, widest_free: u64, + cap: Option, ) -> FirstUpload { if room_ok { return FirstUpload::Allow; @@ -2250,6 +2308,9 @@ fn first_upload_decision( return FirstUpload::AllowanceOff; } let ceiling = room_line(budget).saturating_add(allowance_mb << 20).min(budget / 100 * 80); + // A small host's cap ([`texture_cap`]) is a line of its own: a face may pass it + // by the same allowance it passes the card's line by, no more. + let ceiling = cap.map_or(ceiling, |cap| ceiling.min(cap.saturating_add(allowance_mb << 20))); // The 80% ceiling is on bytes held by host copies of textures, not on // every byte the title has on the card. Using `used - free texture // blocks` here counted the title's render targets twice: at 22:41:23 @@ -6821,7 +6882,8 @@ float4 lit() : SV_Target { return 1.0; } filled, counted, blocks, - blocks + blocks, + None, ), super::FirstUpload::Allow ); @@ -6863,7 +6925,8 @@ float4 lit() : SV_Target { return 1.0; } filled, counted_old, blocks, - blocks + blocks, + None, ), super::FirstUpload::Allow ); @@ -6877,7 +6940,8 @@ float4 lit() : SV_Target { return 1.0; } filled, counted_new, blocks, - blocks + blocks, + None, ), super::FirstUpload::Allow ); @@ -6895,7 +6959,8 @@ float4 lit() : SV_Target { return 1.0; } filled, counted_new, blocks, - blocks + blocks, + None, ), super::FirstUpload::WholeCard ); @@ -6927,7 +6992,8 @@ float4 lit() : SV_Target { return 1.0; } filled, counted, free_blocks, - free_blocks + free_blocks, + None, ), super::FirstUpload::Allow ); @@ -6969,6 +7035,7 @@ float4 lit() : SV_Target { return 1.0; } 0, free_blocks, widest, + None, ) }; assert_eq!(decide(64 << 10), super::FirstUpload::WholeCard); @@ -6996,6 +7063,37 @@ float4 lit() : SV_Target { return 1.0; } const { assert!(128 * MIB * 7 < 957 * MIB) }; } + /// The cap on texture copies: 1 GB by default on a PC of under 24 GB of RAM, + /// none elsewhere; `VICTORY_TEXTURE_CAP_MB` sets it or (0, or not a number) + /// takes it off. + #[test] + fn small_hosts_hold_texture_copies_to_1_gb() { + const MIB: u64 = 1 << 20; + assert_eq!(super::texture_cap_for(true, None), Some(1024 * MIB)); + assert_eq!(super::texture_cap_for(false, None), None); + assert_eq!(super::texture_cap_for(true, Some("0")), None); + assert_eq!(super::texture_cap_for(true, Some(" 3072 ")), Some(3072 * MIB)); + assert_eq!(super::texture_cap_for(false, Some("1536")), Some(1536 * MIB), "asked on a large PC"); + assert_eq!(super::texture_cap_for(true, Some("lots")), None); + } + + /// A face over the card's line may pass the small host's cap by the allowance + /// and no more: the 2 GB cap, a face of 1 MiB, the card as 2026-11-29's run had it. + #[test] + fn a_first_upload_passes_the_cap_by_the_allowance_alone() { + const MIB: u64 = 1 << 20; + let memory = Some([6901 * MIB, 6612 * MIB, 6502 * MIB, 5562 * MIB]); + let cap = Some(2048 * MIB); + let decide = |filled: u64| super::first_upload_decision(memory, MIB, false, false, 128, filled, 0, 512 * MIB, 512 * MIB, cap); + assert_eq!(decide(2048 * MIB), super::FirstUpload::Allow, "at the cap: the allowance"); + assert_eq!(decide(2175 * MIB), super::FirstUpload::FilledCeiling, "past the cap and its allowance"); + // Without the cap the card's own ceiling (80 % of the budget) is the bound. + assert_eq!( + super::first_upload_decision(memory, MIB, false, false, 128, 2175 * MIB, 0, 512 * MIB, 512 * MIB, None), + super::FirstUpload::Allow + ); + } + /// Each guard that can refuse a never-uploaded slot is named, so a log /// can say whether the ceiling, the whole card, or a switch held it back. #[test] @@ -7005,29 +7103,29 @@ float4 lit() : SV_Target { return 1.0; } let memory = Some([budget, 6172 * MIB, 539 * MIB, 149 * MIB]); let ceiling = super::room_line(budget).saturating_add(128 * MIB).min(budget / 100 * 80); assert_eq!( - super::first_upload_decision(memory, 0, false, true, 128, 0, 0, 0, 0), + super::first_upload_decision(memory, 0, false, true, 128, 0, 0, 0, 0, None), super::FirstUpload::ExplicitBudget ); assert_eq!( - super::first_upload_decision(None, 0, false, false, 128, 0, 0, 0, 0), + super::first_upload_decision(None, 0, false, false, 128, 0, 0, 0, 0, None), super::FirstUpload::NoMemory ); assert_eq!( - super::first_upload_decision(memory, 0, false, false, 0, 0, 0, 0, 0), + super::first_upload_decision(memory, 0, false, false, 0, 0, 0, 0, 0, None), super::FirstUpload::AllowanceOff ); assert_eq!( - super::first_upload_decision(memory, 0, false, false, 128, ceiling, 0, 0, 0), + super::first_upload_decision(memory, 0, false, false, 128, ceiling, 0, 0, 0, None), super::FirstUpload::FilledCeiling ); // 880 MiB past the 6,172 MiB in use needs a new block and reaches the // 7,051 MiB budget; a byte that fits in free blocks would not. assert_eq!( - super::first_upload_decision(memory, 880 * MIB, false, false, 128, 0, 0, 0, 0), + super::first_upload_decision(memory, 880 * MIB, false, false, 128, 0, 0, 0, 0, None), super::FirstUpload::WholeCard ); assert_eq!( - super::first_upload_decision(memory, 0, true, false, 128, ceiling, budget, 0, 0), + super::first_upload_decision(memory, 0, true, false, 128, ceiling, budget, 0, 0, None), super::FirstUpload::Allow ); } diff --git a/crates/victory-gpu/src/streamline.rs b/crates/victory-gpu/src/streamline.rs index d24e040fcf..940354e8a6 100644 --- a/crates/victory-gpu/src/streamline.rs +++ b/crates/victory-gpu/src/streamline.rs @@ -880,6 +880,20 @@ pub fn adapter_name() -> Option { default_adapter().map(|a| a.0) } +/// How much memory Windows lets programs commit now, in bytes: the RAM and the +/// page files at the size they have at this moment (`ullTotalPageFile`). Where +/// Windows manages a page file's size this is the figure a run meets first: the +/// file is made larger only once a commit was refused (#1915, #2453). +pub fn commit_limit() -> Option { + use windows_sys::Win32::System::SystemInformation::{GlobalMemoryStatusEx, MEMORYSTATUSEX}; + // SAFETY: a structure of the size given, filled by the call. + unsafe { + let mut status: MEMORYSTATUSEX = std::mem::zeroed(); + status.dwLength = size_of::() as u32; + (GlobalMemoryStatusEx(&mut status) != 0).then_some(status.ullTotalPageFile) + } +} + /// An NVIDIA RTX card's generation, read from its name, as the GeForce /// series of the same architecture (20 Turing, 30 Ampere, 40 Ada, 50 /// Blackwell), and whether it is a workstation card. `None`: no RTX name.