From 76c5306581b3ca13624bf9e9de70808ff956b07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 24 Mar 2025 19:47:25 +0100 Subject: [PATCH] Trim text atlas in `iced_wgpu` after drawing This will need to change to only trim when all windows have finished drawing once we implement concurrent presentation, since there would be glyph fighting otherwise. --- wgpu/src/lib.rs | 3 +++ wgpu/src/text.rs | 50 ++++++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b39defa8..a585782e 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -152,6 +152,9 @@ impl Renderer { self.triangle.end_frame(); self.text.end_frame(); + // TODO: Move to runtime! + self.engine.text_pipeline.trim(); + #[cfg(any(feature = "svg", feature = "image"))] { self.image.end_frame(); diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 7f88cac4..05e99396 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -276,6 +276,33 @@ pub struct Pipeline { atlas: Arc>, } +impl Pipeline { + pub fn new( + device: &wgpu::Device, + queue: &wgpu::Queue, + format: wgpu::TextureFormat, + ) -> Self { + let cache = cryoglyph::Cache::new(device); + let atlas = cryoglyph::TextAtlas::with_color_mode( + device, queue, &cache, format, COLOR_MODE, + ); + + Pipeline { + format, + cache, + atlas: Arc::new(RwLock::new(atlas)), + } + } + + pub fn create_viewport(&self, device: &wgpu::Device) -> Viewport { + Viewport(cryoglyph::Viewport::new(device, &self.cache)) + } + + pub fn trim(&self) { + self.atlas.write().expect("Write text atlas").trim(); + } +} + #[derive(Default)] pub struct State { renderers: Vec, @@ -414,29 +441,6 @@ impl State { } } -impl Pipeline { - pub fn new( - device: &wgpu::Device, - queue: &wgpu::Queue, - format: wgpu::TextureFormat, - ) -> Self { - let cache = cryoglyph::Cache::new(device); - let atlas = cryoglyph::TextAtlas::with_color_mode( - device, queue, &cache, format, COLOR_MODE, - ); - - Pipeline { - format, - cache, - atlas: Arc::new(RwLock::new(atlas)), - } - } - - pub fn create_viewport(&self, device: &wgpu::Device) -> Viewport { - Viewport(cryoglyph::Viewport::new(device, &self.cache)) - } -} - fn prepare( device: &wgpu::Device, queue: &wgpu::Queue,