Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui/metal: Clamp max texture width/height to 16kB (#10314)
Piotr Osiewicz4fb9f41e6954
diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rsindex 7eec24b2d18..53f83ec78f1 100644--- a/crates/gpui/src/geometry.rs+++ b/crates/gpui/src/geometry.rs@@ -528,6 +528,35 @@ where},}}+ /// Returns a new `Size` with the minimum width and height from `self` and `other`.+ ///+ /// # Arguments+ ///+ /// * `other` - A reference to another `Size` to compare with `self`.+ ///+ /// # Examples+ ///+ /// ```+ /// # use zed::Size;+ /// let size1 = Size { width: 30, height: 40 };+ /// let size2 = Size { width: 50, height: 20 };+ /// let min_size = size1.min(&size2);+ /// assert_eq!(min_size, Size { width: 30, height: 20 });+ /// ```+ pub fn min(&self, other: &Self) -> Self {+ Size {+ width: if self.width >= other.width {+ other.width.clone()+ } else {+ self.width.clone()+ },+ height: if self.height >= other.height {+ other.height.clone()+ } else {+ self.height.clone()+ },+ }+ }}impl<T> Sub for Size<T>diff --git a/crates/gpui/src/platform/mac/metal_atlas.rs b/crates/gpui/src/platform/mac/metal_atlas.rsindex 7c23fafcba1..22401ba6d45 100644--- a/crates/gpui/src/platform/mac/metal_atlas.rs+++ b/crates/gpui/src/platform/mac/metal_atlas.rs@@ -83,6 +83,7 @@ impl MetalAtlasState {AtlasTextureKind::Polychrome => &mut self.polychrome_textures,AtlasTextureKind::Path => &mut self.path_textures,};+textures.iter_mut().rev()@@ -102,8 +103,12 @@ impl MetalAtlasState {width: DevicePixels(1024),height: DevicePixels(1024),};-- let size = min_size.max(&DEFAULT_ATLAS_SIZE);+ // Max texture size on all modern Apple GPUs. Anything bigger than that crashes in validateWithDevice.+ const MAX_ATLAS_SIZE: Size<DevicePixels> = Size {+ width: DevicePixels(16384),+ height: DevicePixels(16384),+ };+ let size = min_size.min(&MAX_ATLAS_SIZE).max(&DEFAULT_ATLAS_SIZE);let texture_descriptor = metal::TextureDescriptor::new();texture_descriptor.set_width(size.width.into());texture_descriptor.set_height(size.height.into());