From b05e61f5c8ae61c9f3c7cc08cded53901ebbccfd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 3 Apr 2024 21:07:54 +0200 Subject: Redesign `iced_wgpu` layering architecture --- wgpu/src/engine.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 wgpu/src/engine.rs (limited to 'wgpu/src/engine.rs') diff --git a/wgpu/src/engine.rs b/wgpu/src/engine.rs new file mode 100644 index 00000000..e45b62b2 --- /dev/null +++ b/wgpu/src/engine.rs @@ -0,0 +1,79 @@ +use crate::buffer; +use crate::graphics::Antialiasing; +use crate::primitive::pipeline; +use crate::quad; +use crate::text; +use crate::triangle; + +#[allow(missing_debug_implementations)] +pub struct Engine { + pub(crate) quad_pipeline: quad::Pipeline, + pub(crate) text_pipeline: text::Pipeline, + pub(crate) triangle_pipeline: triangle::Pipeline, + pub(crate) _pipeline_storage: pipeline::Storage, + #[cfg(any(feature = "image", feature = "svg"))] + pub(crate) image_pipeline: crate::image::Pipeline, + pub(crate) staging_belt: wgpu::util::StagingBelt, +} + +impl Engine { + pub fn new( + _adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + format: wgpu::TextureFormat, + antialiasing: Option, // TODO: Initialize AA pipelines lazily + ) -> Self { + let text_pipeline = text::Pipeline::new(device, queue, format); + let quad_pipeline = quad::Pipeline::new(device, format); + let triangle_pipeline = + triangle::Pipeline::new(device, format, antialiasing); + + #[cfg(any(feature = "image", feature = "svg"))] + let image_pipeline = { + let backend = _adapter.get_info().backend; + + crate::image::Pipeline::new(device, format, backend) + }; + + Self { + // 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( + buffer::MAX_WRITE_SIZE as u64, + ), + quad_pipeline, + text_pipeline, + triangle_pipeline, + _pipeline_storage: pipeline::Storage::default(), + + #[cfg(any(feature = "image", feature = "svg"))] + image_pipeline, + } + } + + #[cfg(any(feature = "image", feature = "svg"))] + pub fn image_cache(&self) -> &crate::image::cache::Shared { + self.image_pipeline.cache() + } + + pub fn submit( + &mut self, + queue: &wgpu::Queue, + encoder: wgpu::CommandEncoder, + ) -> wgpu::SubmissionIndex { + self.staging_belt.finish(); + let index = queue.submit(Some(encoder.finish())); + self.staging_belt.recall(); + + self.quad_pipeline.end_frame(); + self.text_pipeline.end_frame(); + self.triangle_pipeline.end_frame(); + + #[cfg(any(feature = "image", feature = "svg"))] + self.image_pipeline.end_frame(); + + index + } +} -- cgit From d922b478156488a7bc03c6e791e05c040d702634 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 8 Apr 2024 15:04:35 +0200 Subject: Reintroduce support for custom primitives in `iced_wgpu` --- wgpu/src/engine.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'wgpu/src/engine.rs') diff --git a/wgpu/src/engine.rs b/wgpu/src/engine.rs index e45b62b2..96cd6db8 100644 --- a/wgpu/src/engine.rs +++ b/wgpu/src/engine.rs @@ -1,19 +1,21 @@ use crate::buffer; use crate::graphics::Antialiasing; -use crate::primitive::pipeline; +use crate::primitive; use crate::quad; use crate::text; use crate::triangle; #[allow(missing_debug_implementations)] pub struct Engine { + pub(crate) staging_belt: wgpu::util::StagingBelt, + pub(crate) format: wgpu::TextureFormat, + pub(crate) quad_pipeline: quad::Pipeline, pub(crate) text_pipeline: text::Pipeline, pub(crate) triangle_pipeline: triangle::Pipeline, - pub(crate) _pipeline_storage: pipeline::Storage, #[cfg(any(feature = "image", feature = "svg"))] pub(crate) image_pipeline: crate::image::Pipeline, - pub(crate) staging_belt: wgpu::util::StagingBelt, + pub(crate) primitive_storage: primitive::Storage, } impl Engine { @@ -43,13 +45,16 @@ impl Engine { staging_belt: wgpu::util::StagingBelt::new( buffer::MAX_WRITE_SIZE as u64, ), + format, + quad_pipeline, text_pipeline, triangle_pipeline, - _pipeline_storage: pipeline::Storage::default(), #[cfg(any(feature = "image", feature = "svg"))] image_pipeline, + + primitive_storage: primitive::Storage::default(), } } -- cgit From 547446f0de076149a4c61e6a4179308b266fd9fd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 6 May 2024 12:14:42 +0200 Subject: Fix windows fighting over shared `image::Cache` Image caches are local to each window now. --- wgpu/src/engine.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'wgpu/src/engine.rs') diff --git a/wgpu/src/engine.rs b/wgpu/src/engine.rs index 96cd6db8..782fd58c 100644 --- a/wgpu/src/engine.rs +++ b/wgpu/src/engine.rs @@ -59,8 +59,11 @@ impl Engine { } #[cfg(any(feature = "image", feature = "svg"))] - pub fn image_cache(&self) -> &crate::image::cache::Shared { - self.image_pipeline.cache() + pub fn create_image_cache( + &self, + device: &wgpu::Device, + ) -> crate::image::Cache { + self.image_pipeline.create_cache(device) } pub fn submit( -- cgit