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.
This commit is contained in:
Andrew Hamilton 2026-07-23 06:20:35 +10:00
parent c6d3cb672d
commit fd8a2cc15b
2 changed files with 17 additions and 10 deletions

View file

@ -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 {

View file

@ -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<String> =
@ -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) {