diff --git a/Cargo.toml b/Cargo.toml index 8cfcd49208..4a83344384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ documentation = "https://docs.rs/iced" readme = "README.md" keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] +resolver = "2" [features] default = ["wgpu", "default_system_font"] diff --git a/examples/integration_wgpu/Cargo.toml b/examples/integration_wgpu/Cargo.toml index 743c655eeb..a088dd1bdc 100644 --- a/examples/integration_wgpu/Cargo.toml +++ b/examples/integration_wgpu/Cargo.toml @@ -7,5 +7,5 @@ publish = false [dependencies] iced_winit = { path = "../../winit" } -iced_wgpu = { path = "../../wgpu" } +iced_wgpu = { path = "../../wgpu", features = ["spirv"] } env_logger = "0.8" diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 6f31946649..7ef148bc5d 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -31,7 +31,7 @@ pub fn main() { let mut clipboard = Clipboard::connect(&window); // Initialize wgpu - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); let surface = unsafe { instance.create_surface(&window) }; let (format, (mut device, queue)) = futures::executor::block_on(async { @@ -44,8 +44,8 @@ pub fn main() { .expect("Request adapter"); ( - adapter - .get_swap_chain_preferred_format(&surface) + surface + .get_preferred_format(&adapter) .expect("Get preferred format"), adapter .request_device( @@ -61,13 +61,13 @@ pub fn main() { ) }); - let mut swap_chain = { + { let size = window.inner_size(); - device.create_swap_chain( - &surface, - &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + surface.configure( + &device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format, width: size.width, height: size.height, @@ -158,10 +158,10 @@ pub fn main() { if resized { let size = window.inner_size(); - swap_chain = device.create_swap_chain( - &surface, - &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + surface.configure( + &device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: format, width: size.width, height: size.height, @@ -172,7 +172,7 @@ pub fn main() { resized = false; } - match swap_chain.get_current_frame() { + match surface.get_current_frame() { Ok(frame) => { let mut encoder = device.create_command_encoder( &wgpu::CommandEncoderDescriptor { label: None }, @@ -180,10 +180,12 @@ pub fn main() { let program = state.program(); + let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default()); + { // We clear the frame let mut render_pass = scene.clear( - &frame.output.view, + &view, &mut encoder, program.background_color(), ); @@ -197,7 +199,7 @@ pub fn main() { &mut device, &mut staging_belt, &mut encoder, - &frame.output.view, + &view, &viewport, state.primitive(), &debug.overlay(), @@ -223,7 +225,7 @@ pub fn main() { local_pool.run_until_stalled(); } Err(error) => match error { - wgpu::SwapChainError::OutOfMemory => { + wgpu::SurfaceError::OutOfMemory => { panic!("Swapchain error: {}. Rendering cannot continue.", error) } _ => { diff --git a/examples/integration_wgpu/src/scene.rs b/examples/integration_wgpu/src/scene.rs index 3e8277c8d6..0b2b1fcd40 100644 --- a/examples/integration_wgpu/src/scene.rs +++ b/examples/integration_wgpu/src/scene.rs @@ -79,7 +79,7 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { diff --git a/graphics/src/window.rs b/graphics/src/window.rs index 365ddfbc40..67ec33224c 100644 --- a/graphics/src/window.rs +++ b/graphics/src/window.rs @@ -4,7 +4,7 @@ mod compositor; #[cfg(feature = "opengl")] mod gl_compositor; -pub use compositor::{Compositor, SwapChainError}; +pub use compositor::{Compositor, SurfaceError}; #[cfg(feature = "opengl")] pub use gl_compositor::GLCompositor; diff --git a/graphics/src/window/compositor.rs b/graphics/src/window/compositor.rs index de2a6990b9..37edef1d5e 100644 --- a/graphics/src/window/compositor.rs +++ b/graphics/src/window/compositor.rs @@ -16,9 +16,6 @@ pub trait Compositor: Sized { /// The surface of the backend. type Surface; - /// The swap chain of the backend. - type SwapChain; - /// Creates a new [`Compositor`]. fn new( settings: Self::Settings, @@ -37,12 +34,12 @@ pub trait Compositor: Sized { /// /// [`SwapChain`]: Self::SwapChain /// [`Surface`]: Self::Surface - fn create_swap_chain( + fn configure_surface( &mut self, - surface: &Self::Surface, + surface: &mut Self::Surface, width: u32, height: u32, - ) -> Self::SwapChain; + ); /// Draws the output primitives to the next frame of the given [`SwapChain`]. /// @@ -50,17 +47,17 @@ pub trait Compositor: Sized { fn draw>( &mut self, renderer: &mut Self::Renderer, - swap_chain: &mut Self::SwapChain, + surface: &mut Self::Surface, viewport: &Viewport, background_color: Color, output: &::Output, overlay: &[T], - ) -> Result; + ) -> Result; } /// Result of an unsuccessful call to [`Compositor::draw`]. #[derive(Clone, PartialEq, Eq, Debug, Error)] -pub enum SwapChainError { +pub enum SurfaceError { /// A timeout was encountered while trying to acquire the next frame. #[error( "A timeout was encountered while trying to acquire the next frame" diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 9675797d0a..a904fe87c9 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -24,10 +24,11 @@ farbfeld = ["image_rs/farbfeld"] canvas = ["iced_graphics/canvas"] qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] +spirv = ["wgpu/spirv"] [dependencies] -wgpu = "0.9" -wgpu_glyph = "0.13" +wgpu = "0.10" +wgpu_glyph = "0.14" glyph_brush = "0.7" raw-window-handle = "0.3" log = "0.4" diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 85663bf540..a59dc04b90 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -61,7 +61,7 @@ impl Pipeline { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -73,7 +73,7 @@ impl Pipeline { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -86,7 +86,7 @@ impl Pipeline { let uniforms_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::image uniforms buffer"), size: mem::size_of::() as u64, - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -117,7 +117,7 @@ impl Pipeline { label: Some("iced_wgpu::image texture atlas layout"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { filterable: true, @@ -142,7 +142,6 @@ impl Pipeline { source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/image.wgsl"), )), - flags: wgpu::ShaderFlags::all(), }); let pipeline = @@ -155,7 +154,7 @@ impl Pipeline { buffers: &[ wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float32x2, @@ -164,7 +163,7 @@ impl Pipeline { }, wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &wgpu::vertex_attr_array!( 1 => Float32x2, 2 => Float32x2, @@ -192,7 +191,7 @@ impl Pipeline { operation: wgpu::BlendOperation::Add, }, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -212,20 +211,20 @@ impl Pipeline { device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("iced_wgpu::image vertex buffer"), contents: bytemuck::cast_slice(&QUAD_VERTS), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let indices = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("iced_wgpu::image index buffer"), contents: bytemuck::cast_slice(&QUAD_INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let instances = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::image instance buffer"), size: mem::size_of::() as u64 * Instance::MAX as u64, - usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 4855fa4a20..c1347e550d 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -36,9 +36,9 @@ impl Atlas { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Bgra8UnormSrgb, - usage: wgpu::TextureUsage::COPY_DST - | wgpu::TextureUsage::COPY_SRC - | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::TEXTURE_BINDING, }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor { @@ -107,7 +107,7 @@ impl Atlas { device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("iced_wgpu::image staging buffer"), contents: &padded_data, - usage: wgpu::BufferUsage::COPY_SRC, + usage: wgpu::BufferUsages::COPY_SRC, }); match &entry { @@ -316,6 +316,7 @@ impl Atlas { y, z: layer as u32, }, + aspect: wgpu::TextureAspect::default(), }, extent, ); @@ -342,9 +343,9 @@ impl Atlas { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Bgra8UnormSrgb, - usage: wgpu::TextureUsage::COPY_DST - | wgpu::TextureUsage::COPY_SRC - | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::TEXTURE_BINDING, }); let amount_to_copy = self.layers.len() - amount; @@ -365,6 +366,7 @@ impl Atlas { y: 0, z: i as u32, }, + aspect: wgpu::TextureAspect::default(), }, wgpu::ImageCopyTexture { texture: &new_texture, @@ -374,6 +376,7 @@ impl Atlas { y: 0, z: i as u32, }, + aspect: wgpu::TextureAspect::default(), }, wgpu::Extent3d { width: SIZE, diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 93942fba27..148d0f6af2 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -23,7 +23,7 @@ impl Pipeline { label: Some("iced_wgpu::quad uniforms layout"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -38,7 +38,7 @@ impl Pipeline { let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::quad uniforms buffer"), size: mem::size_of::() as wgpu::BufferAddress, - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -64,7 +64,6 @@ impl Pipeline { source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/quad.wgsl"), )), - flags: wgpu::ShaderFlags::all(), }); let pipeline = @@ -77,7 +76,7 @@ impl Pipeline { buffers: &[ wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float32x2, @@ -86,7 +85,7 @@ impl Pipeline { }, wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &wgpu::vertex_attr_array!( 1 => Float32x2, 2 => Float32x2, @@ -115,7 +114,7 @@ impl Pipeline { operation: wgpu::BlendOperation::Add, }, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -135,20 +134,20 @@ impl Pipeline { device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("iced_wgpu::quad vertex buffer"), contents: bytemuck::cast_slice(&QUAD_VERTS), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let indices = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("iced_wgpu::quad index buffer"), contents: bytemuck::cast_slice(&QUAD_INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let instances = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::quad instance buffer"), size: mem::size_of::() as u64 * MAX_INSTANCES as u64, - usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index dc06b82d36..23b5590479 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -12,7 +12,7 @@ pub struct Settings { pub present_mode: wgpu::PresentMode, /// The internal graphics backend to use. - pub internal_backend: wgpu::BackendBit, + pub internal_backend: wgpu::Backends, /// The bytes of the font that will be used by default. /// @@ -54,7 +54,7 @@ impl Settings { pub fn from_env() -> Self { Settings { internal_backend: backend_from_env() - .unwrap_or(wgpu::BackendBit::PRIMARY), + .unwrap_or(wgpu::Backends::all()), ..Self::default() } } @@ -64,7 +64,7 @@ impl Default for Settings { fn default() -> Settings { Settings { present_mode: wgpu::PresentMode::Mailbox, - internal_backend: wgpu::BackendBit::PRIMARY, + internal_backend: wgpu::Backends::all(), default_font: None, default_text_size: 20, text_multithreading: false, @@ -73,16 +73,16 @@ impl Default for Settings { } } -fn backend_from_env() -> Option { +fn backend_from_env() -> Option { std::env::var("WGPU_BACKEND").ok().map(|backend| { match backend.to_lowercase().as_str() { - "vulkan" => wgpu::BackendBit::VULKAN, - "metal" => wgpu::BackendBit::METAL, - "dx12" => wgpu::BackendBit::DX12, - "dx11" => wgpu::BackendBit::DX11, - "gl" => wgpu::BackendBit::GL, - "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, - "primary" => wgpu::BackendBit::PRIMARY, + "vulkan" => wgpu::Backends::VULKAN, + "metal" => wgpu::Backends::METAL, + "dx12" => wgpu::Backends::DX12, + "dx11" => wgpu::Backends::DX11, + "gl" => wgpu::Backends::GL, + "webgpu" => wgpu::Backends::BROWSER_WEBGPU, + "primary" => wgpu::Backends::PRIMARY, other => panic!("Unknown backend: {}", other), } }) diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 65b2b7b0cc..2aaebe58b0 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -29,7 +29,7 @@ struct Buffer { label: &'static str, raw: wgpu::Buffer, size: usize, - usage: wgpu::BufferUsage, + usage: wgpu::BufferUsages, _type: std::marker::PhantomData, } @@ -38,7 +38,7 @@ impl Buffer { label: &'static str, device: &wgpu::Device, size: usize, - usage: wgpu::BufferUsage, + usage: wgpu::BufferUsages, ) -> Self { let raw = device.create_buffer(&wgpu::BufferDescriptor { label: Some(label), @@ -85,7 +85,7 @@ impl Pipeline { label: Some("iced_wgpu::triangle uniforms layout"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: true, @@ -101,7 +101,7 @@ impl Pipeline { "iced_wgpu::triangle uniforms buffer", device, UNIFORM_BUFFER_SIZE, - wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, ); let constant_bind_group = @@ -137,7 +137,6 @@ impl Pipeline { source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/triangle.wgsl"), )), - flags: wgpu::ShaderFlags::all(), }); let pipeline = @@ -149,7 +148,7 @@ impl Pipeline { entry_point: "vs_main", buffers: &[wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array!( // Position 0 => Float32x2, @@ -175,7 +174,7 @@ impl Pipeline { operation: wgpu::BlendOperation::Add, }, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -203,13 +202,13 @@ impl Pipeline { "iced_wgpu::triangle vertex buffer", device, VERTEX_BUFFER_SIZE, - wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, ), index_buffer: Buffer::new( "iced_wgpu::triangle index buffer", device, INDEX_BUFFER_SIZE, - wgpu::BufferUsage::INDEX | wgpu::BufferUsage::COPY_DST, + wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST, ), } } diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index c099d51863..070d2d930c 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -31,7 +31,7 @@ impl Blit { label: Some("iced_wgpu::triangle:msaa uniforms layout"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: false, @@ -55,7 +55,7 @@ impl Blit { label: Some("iced_wgpu::triangle::msaa texture layout"), entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { filterable: false, @@ -80,7 +80,6 @@ impl Blit { source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("../shader/blit.wgsl"), )), - flags: wgpu::ShaderFlags::all(), }); let pipeline = @@ -109,7 +108,7 @@ impl Blit { operation: wgpu::BlendOperation::Add, }, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -232,7 +231,7 @@ impl Targets { sample_count, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, }); let resolve = device.create_texture(&wgpu::TextureDescriptor { @@ -242,8 +241,8 @@ impl Targets { sample_count: 1, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT - | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::TEXTURE_BINDING, }); let attachment = diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index b60efd25a1..eca54b6f0e 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -45,7 +45,7 @@ impl Compositor { let format = compatible_surface .as_ref() - .and_then(|surf| adapter.get_swap_chain_preferred_format(surf))?; + .and_then(|surface| surface.get_preferred_format(&adapter))?; let (device, queue) = adapter .request_device( @@ -88,7 +88,6 @@ impl iced_graphics::window::Compositor for Compositor { type Settings = Settings; type Renderer = Renderer; type Surface = wgpu::Surface; - type SwapChain = wgpu::SwapChain; fn new( settings: Self::Settings, @@ -115,34 +114,34 @@ impl iced_graphics::window::Compositor for Compositor { } } - fn create_swap_chain( + fn configure_surface( &mut self, - surface: &Self::Surface, + surface: &mut Self::Surface, width: u32, height: u32, - ) -> Self::SwapChain { - self.device.create_swap_chain( - surface, - &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + ) { + surface.configure( + &self.device, + &wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: self.format, present_mode: self.settings.present_mode, width, height, }, - ) + ); } fn draw>( &mut self, renderer: &mut Self::Renderer, - swap_chain: &mut Self::SwapChain, + surface: &mut Self::Surface, viewport: &Viewport, background_color: Color, output: &::Output, overlay: &[T], - ) -> Result { - match swap_chain.get_current_frame() { + ) -> Result { + match surface.get_current_frame() { Ok(frame) => { let mut encoder = self.device.create_command_encoder( &wgpu::CommandEncoderDescriptor { @@ -150,13 +149,18 @@ impl iced_graphics::window::Compositor for Compositor { }, ); + let view = &frame + .output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some( "iced_wgpu::window::Compositor render pass", ), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.output.view, + view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear({ @@ -180,7 +184,7 @@ impl iced_graphics::window::Compositor for Compositor { &mut self.device, &mut self.staging_belt, &mut encoder, - &frame.output.view, + view, viewport, output, overlay, @@ -201,17 +205,17 @@ impl iced_graphics::window::Compositor for Compositor { Ok(mouse_interaction) } Err(error) => match error { - wgpu::SwapChainError::Timeout => { - Err(iced_graphics::window::SwapChainError::Timeout) + wgpu::SurfaceError::Timeout => { + Err(iced_graphics::window::SurfaceError::Timeout) } - wgpu::SwapChainError::Outdated => { - Err(iced_graphics::window::SwapChainError::Outdated) + wgpu::SurfaceError::Outdated => { + Err(iced_graphics::window::SurfaceError::Outdated) } - wgpu::SwapChainError::Lost => { - Err(iced_graphics::window::SwapChainError::Lost) + wgpu::SurfaceError::Lost => { + Err(iced_graphics::window::SurfaceError::Lost) } - wgpu::SwapChainError::OutOfMemory => { - Err(iced_graphics::window::SwapChainError::OutOfMemory) + wgpu::SurfaceError::OutOfMemory => { + Err(iced_graphics::window::SurfaceError::OutOfMemory) } }, } diff --git a/winit/src/application.rs b/winit/src/application.rs index c43eed118f..b683e5921e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -227,20 +227,19 @@ async fn run_instance( use iced_futures::futures::stream::StreamExt; use winit::event; - let surface = compositor.create_surface(&window); + let mut surface = compositor.create_surface(&window); let mut clipboard = Clipboard::connect(&window); let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); - let mut swap_chain = { - let physical_size = state.physical_size(); - compositor.create_swap_chain( - &surface, - physical_size.width, - physical_size.height, - ) - }; + let physical_size = state.physical_size(); + + compositor.configure_surface( + &mut surface, + physical_size.width, + physical_size.height, + ); let mut user_interface = ManuallyDrop::new(build_user_interface( &mut application, @@ -358,8 +357,8 @@ async fn run_instance( .draw(&mut renderer, state.cursor_position()); debug.draw_finished(); - swap_chain = compositor.create_swap_chain( - &surface, + compositor.configure_surface( + &mut surface, physical_size.width, physical_size.height, ); @@ -369,7 +368,7 @@ async fn run_instance( match compositor.draw( &mut renderer, - &mut swap_chain, + &mut surface, state.viewport(), state.background_color(), &primitive, @@ -393,7 +392,7 @@ async fn run_instance( } Err(error) => match error { // This is an unrecoverable error. - window::SwapChainError::OutOfMemory => { + window::SurfaceError::OutOfMemory => { panic!("{}", error); } _ => {