From 2bb53ad6e7ea2689f2f56662e5840a8d363b3108 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 29 Mar 2024 04:02:24 +0100 Subject: Use a `StagingBelt` in `iced_wgpu` for regular buffer uploads --- wgpu/src/backend.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'wgpu/src/backend.rs') diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 5019191c..129e9bca 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -30,6 +30,7 @@ pub struct Backend { pipeline_storage: pipeline::Storage, #[cfg(any(feature = "image", feature = "svg"))] image_pipeline: image::Pipeline, + staging_belt: wgpu::util::StagingBelt, } impl Backend { @@ -61,6 +62,11 @@ impl Backend { #[cfg(any(feature = "image", feature = "svg"))] image_pipeline, + + // TODO: Resize belt smartly (?) + // It would be great if the `StagingBelt` API exposed methods + // for introspection to detect when a resize may be worth it. + staging_belt: wgpu::util::StagingBelt::new(1024 * 100), } } @@ -105,6 +111,8 @@ impl Backend { &layers, ); + self.staging_belt.finish(); + self.render( device, encoder, @@ -123,12 +131,17 @@ impl Backend { self.image_pipeline.end_frame(); } + /// + pub fn recall(&mut self) { + self.staging_belt.recall(); + } + fn prepare( &mut self, device: &wgpu::Device, queue: &wgpu::Queue, format: wgpu::TextureFormat, - _encoder: &mut wgpu::CommandEncoder, + encoder: &mut wgpu::CommandEncoder, scale_factor: f32, target_size: Size, transformation: Transformation, @@ -144,7 +157,8 @@ impl Backend { if !layer.quads.is_empty() { self.quad_pipeline.prepare( device, - queue, + encoder, + &mut self.staging_belt, &layer.quads, transformation, scale_factor, @@ -157,7 +171,8 @@ impl Backend { self.triangle_pipeline.prepare( device, - queue, + encoder, + &mut self.staging_belt, &layer.meshes, scaled, ); @@ -171,8 +186,8 @@ impl Backend { self.image_pipeline.prepare( device, - queue, - _encoder, + encoder, + &mut self.staging_belt, &layer.images, scaled, scale_factor, @@ -184,6 +199,7 @@ impl Backend { self.text_pipeline.prepare( device, queue, + encoder, &layer.text, layer.bounds, scale_factor, -- cgit From 0a97b9e37ae115bb0db33193c8a6b62590a3cd2c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 29 Mar 2024 09:57:11 +0100 Subject: Add documentation to `Backend::recall` in `iced_wgpu` --- wgpu/src/backend.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'wgpu/src/backend.rs') diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 129e9bca..20809373 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -131,7 +131,10 @@ impl Backend { self.image_pipeline.end_frame(); } + /// Recalls staging memory for future uploads. /// + /// This method should be called after the command encoder + /// has been submitted. pub fn recall(&mut self) { self.staging_belt.recall(); } -- cgit From 5f1eb43161d70b4ef157aae1ebc2b5fb25eb5b27 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 29 Mar 2024 14:29:31 +0100 Subject: Split big `Buffer` writes into multiple chunks --- wgpu/src/backend.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'wgpu/src/backend.rs') diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 20809373..6ccf4111 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -1,3 +1,4 @@ +use crate::buffer; use crate::core::{Color, Size, Transformation}; use crate::graphics::backend; use crate::graphics::color; @@ -66,7 +67,9 @@ impl Backend { // TODO: Resize belt smartly (?) // It would be great if the `StagingBelt` API exposed methods // for introspection to detect when a resize may be worth it. - staging_belt: wgpu::util::StagingBelt::new(1024 * 100), + staging_belt: wgpu::util::StagingBelt::new( + buffer::MAX_WRITE_SIZE as u64, + ), } } -- cgit