GPU memory budget: read installed RAM on Windows (#3189)

physical_memory() had no Windows implementation, so the wgpu
compositor's budget capped layer textures at a quarter of an assumed
16 GB on every Windows machine: too little on a large one (4 GB of a
62 GB PC's 8 GB Memory Usage allowance) and too much on an 8 GB laptop
whose integrated GPU shares that RAM. Read it with GlobalMemoryStatusEx
through winsafe, the safe binding the desktop app already uses (same
pinned version, kernel feature only).

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Dan HiornsandClaude Opus 5.5 authored and GitHub committed 2026-10-12 01:43:06 -04:00
1 parent f14817a5d2
commit cb1c06fc57
3 files changed
+21 -1

No files matched your search

Generated
+1
View File
@@ -4599,6 +4599,7 @@ dependencies = [
"serde_json",
"sys-locale",
"toml",
"winsafe",
]
[[package]]
+5
View File
@@ -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"] }
+15 -1
View File
@@ -1210,7 +1210,12 @@ fn detect_physical_memory() -> Option<u64> {
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<u64> {
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<u64> {
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).