From 7b81085a51df9e35b20f56c2d37dba14969133bb Mon Sep 17 00:00:00 2001 From: Gruzzberry <48861646+Gruzzberry@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:24:32 +0000 Subject: [PATCH] D3D12.X: warn when the title's memory budget is larger than the GPU's (#1337) With `title_memory_mb = 0` the title is given the console's budget (13,824 MiB Series X, 8,192 Series S). On a GPU with less dedicated video memory its streaming manager plans against more than fits, and the failure shows up as a runtime death a minute or more after the start, with nothing in the log. Log one startup warning naming the budget, the adapter's DedicatedVideoMemory and the `title_memory_mb` setting. Nothing is clamped. A budget the user set (anything but the console default), an unknown VRAM (WARP) and enough VRAM do not warn. The decision is a pure function with unit tests. Part of #1337. Assisted-by: Claude Code (Claude Sonnet 5.5) --- crates/xcl/src/config.rs | 12 +++++-- crates/xcl/src/hle/d3d12x/real.rs | 52 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/config.rs b/crates/xcl/src/config.rs index 1503e550a6..756f02fa5b 100644 --- a/crates/xcl/src/config.rs +++ b/crates/xcl/src/config.rs @@ -116,11 +116,19 @@ impl Config { /// TitleMemoryStatus budget (MiB): `title_memory_mb`, 0 = the device's standard budget. pub fn title_memory_budget_mb(&self) -> u64 { match self.title_memory_mb { - 0 if self.is_series_s() => 8_192, - 0 => 13_824, + 0 => self.console_title_memory_mb(), v => v, } } + + /// The console's own title memory budget (MiB) for `device_type`. + pub fn console_title_memory_mb(&self) -> u64 { + if self.is_series_s() { + 8_192 + } else { + 13_824 + } + } } /// Mount target of the persistent local storage drive (`XPersistentLocalStorageGetPath`). diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 3ff2a9793b..6354bfc1b0 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -499,6 +499,7 @@ pub fn init() -> Result { let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).map_err(|e| format!("DXGI: {e}"))?; let mut device: Option = None; let mut name = String::new(); + let mut vram_mb = 0u64; // 0 = unknown (WARP) let sel = crate::gpu::adapter::Selector::from_env_or(&cfg.d3d12_adapter); if sel != crate::gpu::adapter::Selector::Warp { let mut list = crate::gpu::adapter::candidates(&factory, &sel); @@ -510,6 +511,7 @@ pub fn init() -> Result { if let Ok(dev) = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0) { device = Some(dev); name = format!("{} ({} MiB VRAM)", crate::gpu::adapter::name(&desc), desc.DedicatedVideoMemory >> 20); + vram_mb = (desc.DedicatedVideoMemory >> 20) as u64; break; } } @@ -524,6 +526,11 @@ pub fn init() -> Result { d } }; + // the resolved `title_memory_mb` is the console's budget unless the user set another one + let explicit = cfg.title_memory_mb != cfg.console_title_memory_mb(); + if let Some(w) = title_memory_over_vram_warning(cfg.title_memory_budget_mb(), vram_mb, explicit) { + crate::xlog_warn!("{w}"); + } if debug { // the debug layer's messages into XCL's log (they otherwise go to a debugger only) if let Ok(q) = device.cast::() { @@ -541,6 +548,51 @@ pub fn init() -> Result { } } +/// The startup warning when the console's default title memory budget (`title_memory_mb = 0`) +/// is larger than the adapter's dedicated video memory: the title plans its streaming against +/// that budget and can run the GPU out of memory long after the start. `None` for a budget +/// the user set, for enough VRAM and for an unknown VRAM (0, WARP). Nothing is clamped. +fn title_memory_over_vram_warning(budget_mb: u64, vram_mb: u64, explicit: bool) -> Option { + if explicit || vram_mb == 0 || budget_mb <= vram_mb { + return None; + } + Some(format!( + "title memory budget {budget_mb} MiB (the console's) is larger than the GPU's {vram_mb} MiB of dedicated video memory: \ + the title may plan its streaming beyond what fits; set `title_memory_mb` in xcl.toml (e.g. {}) to lower it", + vram_mb * 3 / 4 + )) +} + +#[cfg(test)] +mod title_memory_warning_tests { + use super::title_memory_over_vram_warning as warn; + + #[test] + fn the_default_budget_over_the_vram_warns_with_both_numbers_and_the_setting() { + let w = warn(13_824, 12_282, false).expect("Series X budget on a 12 GB GPU"); + assert!(w.contains("13824") && w.contains("12282") && w.contains("title_memory_mb"), "{w}"); + } + + #[test] + fn a_budget_the_user_set_never_warns() { + assert_eq!(warn(13_824, 8_192, true), None); + assert_eq!(warn(20_000, 8_192, true), None); + } + + #[test] + fn enough_or_unknown_vram_does_not_warn() { + assert_eq!(warn(13_824, 16_303, false), None); + assert_eq!(warn(13_824, 13_824, false), None); + assert_eq!(warn(13_824, 0, false), None); + } + + #[test] + fn the_series_s_budget_warns_on_a_smaller_gpu_only() { + assert!(warn(8_192, 6_144, false).is_some()); + assert_eq!(warn(8_192, 12_282, false), None); + } +} + /// A debug layer message: errors and warnings into the log – the first 8 of each message id /// (3 000 in all). One cap for all of them (200) was used up in seconds by two per-frame state /// errors of a retail game, long before the message that came with its device removal.