diff --git a/Cargo.lock b/Cargo.lock index a197330ab4..34f537eb40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4599,6 +4599,7 @@ dependencies = [ "serde_json", "sys-locale", "toml", + "winsafe", ] [[package]] diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index a9af622286..568727163b 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -43,6 +43,11 @@ rayon = { workspace = true } # Safe native UI-language APIs (Windows/macOS); no subprocess or web dependency. sys-locale = "=0.3.2" +# Installed RAM for the GPU memory budget (`gpu_canvas::physical_memory`): the safe binding the +# desktop app already uses, pinned to the same version. +[target.'cfg(target_os = "windows")'.dependencies] +winsafe = { version = "=0.0.29", default-features = false, features = ["kernel"] } + [dev-dependencies] # Synthetic raw files for the open-time Camera Raw dialog tests. photocraft-raw = { workspace = true, features = ["testgen"] } diff --git a/crates/ui-egui/src/gpu_canvas.rs b/crates/ui-egui/src/gpu_canvas.rs index 702970dac3..e73c59985a 100644 --- a/crates/ui-egui/src/gpu_canvas.rs +++ b/crates/ui-egui/src/gpu_canvas.rs @@ -1210,7 +1210,12 @@ fn detect_physical_memory() -> Option { String::from_utf8(out.stdout).ok()?.trim().parse().ok() } -#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "freebsd")))] +#[cfg(windows)] +fn detect_physical_memory() -> Option { + winsafe::GlobalMemoryStatusEx().map(|m| m.ullTotalPhys).ok().filter(|b| *b > 0) +} + +#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "freebsd", windows)))] fn detect_physical_memory() -> Option { None } @@ -2160,6 +2165,15 @@ mod tests { assert!(physical_memory().is_none_or(|b| b >= 256 << 20)); } + /// Windows used to report no RAM at all, so the budget assumed 16 GB on every machine. + #[cfg(windows)] + #[test] + fn windows_reports_installed_ram() { + let ram = detect_physical_memory().unwrap_or(0); + assert!(ram >= 256 << 20, "{ram} bytes"); + assert!(ram < 1 << 50, "{ram} bytes"); + } + #[test] fn canvas_texture_bytes_price_every_tile_and_mip_level() { // The same sum DocTextures builds tile by tile (and texture_info reports).