Split local state from Engine in iced_wgpu
This commit is contained in:
parent
4b075b9731
commit
576dd22733
22 changed files with 768 additions and 641 deletions
|
|
@ -1,13 +1,16 @@
|
|||
use crate::buffer;
|
||||
use crate::graphics::Antialiasing;
|
||||
use crate::primitive;
|
||||
use crate::quad;
|
||||
use crate::text;
|
||||
use crate::triangle;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Engine {
|
||||
pub(crate) staging_belt: wgpu::util::StagingBelt,
|
||||
pub(crate) device: wgpu::Device,
|
||||
pub(crate) queue: wgpu::Queue,
|
||||
pub(crate) format: wgpu::TextureFormat,
|
||||
|
||||
pub(crate) quad_pipeline: quad::Pipeline,
|
||||
|
|
@ -15,46 +18,41 @@ pub struct Engine {
|
|||
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,
|
||||
pub(crate) primitive_storage: Arc<RwLock<primitive::Storage>>,
|
||||
}
|
||||
|
||||
impl Engine {
|
||||
pub fn new(
|
||||
_adapter: &wgpu::Adapter,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
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,
|
||||
quad_pipeline: quad::Pipeline::new(&device, format),
|
||||
text_pipeline: text::Pipeline::new(&device, &queue, format),
|
||||
triangle_pipeline: triangle::Pipeline::new(
|
||||
&device,
|
||||
format,
|
||||
antialiasing,
|
||||
),
|
||||
|
||||
#[cfg(any(feature = "image", feature = "svg"))]
|
||||
image_pipeline,
|
||||
image_pipeline: {
|
||||
let backend = _adapter.get_info().backend;
|
||||
|
||||
primitive_storage: primitive::Storage::default(),
|
||||
crate::image::Pipeline::new(&device, format, backend)
|
||||
},
|
||||
|
||||
primitive_storage: Arc::new(RwLock::new(
|
||||
primitive::Storage::default(),
|
||||
)),
|
||||
|
||||
device,
|
||||
queue,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,23 +63,4 @@ impl Engine {
|
|||
) -> crate::image::Cache {
|
||||
self.image_pipeline.create_cache(device)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue