From fd8a2cc15b9c4d49afeed12879d05b8457c95bd9 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Thu, 23 Jul 2026 06:20:35 +1000 Subject: [PATCH] Cap atlas size to device max_texture_dimension_2d RPi5 GPU limits max texture dimension to 2048, but atlas was hardcoded to 2560. Now clamps to device.limits().max_texture_dimension_2d. --- src/atlas.rs | 19 +++++++++++++------ src/renderer.rs | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/atlas.rs b/src/atlas.rs index f427e64..5b3bdaa 100644 --- a/src/atlas.rs +++ b/src/atlas.rs @@ -14,6 +14,7 @@ pub(crate) struct GlyphAtlas { scale: f32, cell_width: u32, cell_height: u32, + atlas_size: u32, rasterizer: GlyphRasterizer, next_slot: u32, glyph_map: HashMap<(char, u8), u32>, @@ -30,10 +31,11 @@ impl GlyphAtlas { color_font_path: Option<&str>, ) -> Self { let color_font = color_font_path.map(font::load_color_font); + let atlas_size = ATLAS_SIZE.min(device.limits().max_texture_dimension_2d); let size = wgpu::Extent3d { - width: ATLAS_SIZE, - height: ATLAS_SIZE, + width: atlas_size, + height: atlas_size, depth_or_array_layers: 1, }; let texture = device.create_texture(&wgpu::TextureDescriptor { @@ -77,6 +79,7 @@ impl GlyphAtlas { scale, cell_width, cell_height, + atlas_size, rasterizer: GlyphRasterizer::new(), next_slot: 1, glyph_map: HashMap::new(), @@ -95,16 +98,20 @@ impl GlyphAtlas { self.cell_height } + pub fn atlas_size(&self) -> u32 { + self.atlas_size + } + pub fn scale(&self) -> f32 { self.scale } pub fn atlas_cols(&self) -> u32 { - ATLAS_SIZE / self.cell_width + self.atlas_size / self.cell_width } pub fn atlas_rows(&self) -> u32 { - ATLAS_SIZE / self.cell_height + self.atlas_size / self.cell_height } pub fn max_glyphs(&self) -> u32 { @@ -119,8 +126,8 @@ impl GlyphAtlas { self.cell_height = h; let size = wgpu::Extent3d { - width: ATLAS_SIZE, - height: ATLAS_SIZE, + width: self.atlas_size, + height: self.atlas_size, depth_or_array_layers: 1, }; self.texture = device.create_texture(&wgpu::TextureDescriptor { diff --git a/src/renderer.rs b/src/renderer.rs index 932de33..a3b4ebf 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -225,7 +225,7 @@ pub fn start( }) } - write_uniform(&queue, &uniform_buffer, cols, rows, cell_w as f32, cell_h as f32, fb_w, fb_h, atlas.atlas_cols(), atlas.atlas_rows(), crate::atlas::ATLAS_SIZE as f32); + write_uniform(&queue, &uniform_buffer, cols, rows, cell_w as f32, cell_h as f32, fb_w, fb_h, atlas.atlas_cols(), atlas.atlas_rows(), atlas.atlas_size() as f32); // ----- Sampler ----- let sampler = device.create_sampler(&wgpu::SamplerDescriptor { @@ -357,7 +357,7 @@ pub fn start( let a_rows = atlas.atlas_rows(); write_uniform(&queue, &uniform_buffer, cols, rows, atlas.cell_width() as f32, atlas.cell_height() as f32, - fb_w, fb_h, a_cols, a_rows, crate::atlas::ATLAS_SIZE as f32); + fb_w, fb_h, a_cols, a_rows, atlas.atlas_size() as f32); needs_render.store(true, Ordering::Release); } else { let s: Option = @@ -445,7 +445,7 @@ pub fn start( let a_rows = atlas.atlas_rows(); write_uniform(&queue, &uniform_buffer, cols, rows, atlas.cell_width() as f32, atlas.cell_height() as f32, - fbw, fbh, a_cols, a_rows, crate::atlas::ATLAS_SIZE as f32); + fbw, fbh, a_cols, a_rows, atlas.atlas_size() as f32); } } _ => {} @@ -493,7 +493,7 @@ pub fn start( let a_rows = atlas.atlas_rows(); write_uniform(&queue, &uniform_buffer, cols, rows, atlas.cell_width() as f32, atlas.cell_height() as f32, - fb_w, fb_h, a_cols, a_rows, crate::atlas::ATLAS_SIZE as f32); + fb_w, fb_h, a_cols, a_rows, atlas.atlas_size() as f32); } if needs_render.load(Ordering::Acquire) {