Clamp the window surface to the device's largest texture (#869) (#905)

Moving a window between monitors of different scale can briefly ask for a
surface larger than the device's largest texture (11512 x 6808 against 8192 in
the report), and Surface::configure failed validation, which wgpu turns into a
panic. The surface is now clamped to the device limit with its aspect ratio
kept, and egui draws the whole window at the matching smaller scale, so the
frame is only softer until the size settles. The device also asks for the
adapter's own texture limit (16384 on most desktop GPUs) instead of 8192, and
the resize path and an unsupported surface log instead of unwrapping.

Fixes #869

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruckandClaude Opus 5.5 authored and GitHub committed 2026-10-13 21:19:40 -04:00
1 parent 897b7d93b5
commit d23593d3eb
6 files changed
+115 -12

No files matched your search

+20
View File
@@ -670,3 +670,23 @@ mod msaa_tests {
assert_eq!(super::clamp_msaa_samples(&[], 8), 1);
}
}
/// SolidCraft: the surface size for a window of `width` x `height` pixels on a device whose
/// textures are at most `max_side` on a side, and the scale it is drawn at. A window that fits is
/// unchanged (scale 1); a larger one shrinks uniformly, keeping its aspect ratio, so the image
/// the compositor stretches back over the window is not distorted. Never zero on a side.
pub fn clamp_surface_extent(width: u32, height: u32, max_side: u32) -> (u32, u32, f32) {
let max_side = max_side.max(1);
let (width, height) = (width.max(1), height.max(1));
let longest = width.max(height);
if longest <= max_side {
return (width, height, 1.0);
}
let scale = f64::from(max_side) / f64::from(longest);
let fit = |side: u32| -> u32 {
let scaled = (f64::from(side) * scale).floor() as u32;
scaled.clamp(1, max_side)
};
let scale_f32 = scale as f32;
(fit(width), fit(height), scale_f32)
}