summaryrefslogtreecommitdiffstats
path: root/wgpu/src/engine.rs
diff options
context:
space:
mode:
authorLibravatar Gigas002 <24297712+Gigas002@users.noreply.github.com>2024-04-16 00:08:17 +0900
committerLibravatar GitHub <noreply@github.com>2024-04-16 00:08:17 +0900
commit0ebe0629cef37aee5c48b9409fc36618a3a3e60d (patch)
tree909d9ecf28e7c491bae3afc81928c118517fa7a9 /wgpu/src/engine.rs
parent13bd106fc585034a7aba17b9c17589113274aaf5 (diff)
parent105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a (diff)
downloadiced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.tar.gz
iced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.tar.bz2
iced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.zip
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to 'wgpu/src/engine.rs')
-rw-r--r--wgpu/src/engine.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/wgpu/src/engine.rs b/wgpu/src/engine.rs
new file mode 100644
index 00000000..96cd6db8
--- /dev/null
+++ b/wgpu/src/engine.rs
@@ -0,0 +1,84 @@
+use crate::buffer;
+use crate::graphics::Antialiasing;
+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,
+ #[cfg(any(feature = "image", feature = "svg"))]
+ pub(crate) image_pipeline: crate::image::Pipeline,
+ pub(crate) primitive_storage: primitive::Storage,
+}
+
+impl Engine {
+ pub fn new(
+ _adapter: &wgpu::Adapter,
+ device: &wgpu::Device,
+ queue: &wgpu::Queue,
+ format: wgpu::TextureFormat,
+ antialiasing: Option<Antialiasing>, // 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,
+ ),
+ format,
+
+ quad_pipeline,
+ text_pipeline,
+ triangle_pipeline,
+
+ #[cfg(any(feature = "image", feature = "svg"))]
+ image_pipeline,
+
+ primitive_storage: primitive::Storage::default(),
+ }
+ }
+
+ #[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
+ }
+}