From 4a727dfb8b5b418d88e225a8b1164c865345124f Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:20:23 +0100 Subject: [PATCH 01/16] The beginning of wgpu 0.7 update hecrj/iced#723 --- wgpu/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index d469da0a..b4b2a42b 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -14,8 +14,8 @@ qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] [dependencies] -wgpu = "0.6" -wgpu_glyph = "0.10" +wgpu = "0.7.0" +wgpu_glyph = {git="https://github.com/hecrj/wgpu_glyph.git"} glyph_brush = "0.7" raw-window-handle = "0.3" log = "0.4" From 2d76c7165c4a82f27090cbf69f811f8e0f2f28a4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:21:02 +0100 Subject: [PATCH 02/16] [wgpu 0.7] Update quad.rs --- wgpu/src/quad.rs | 116 +++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 24d20cfa..c1399d53 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -24,8 +24,9 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: false, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -46,9 +47,11 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - constants_buffer.slice(..), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &constants_buffer, + offset: 0, + size: None, + }, }], }); @@ -59,87 +62,61 @@ impl Pipeline { bind_group_layouts: &[&constant_layout], }); - let vs_module = device - .create_shader_module(wgpu::include_spirv!("shader/quad.vert.spv")); + let vs_module = device.create_shader_module(&wgpu::include_spirv!( + "shader/quad.vert.spv" + )); - let fs_module = device - .create_shader_module(wgpu::include_spirv!("shader/quad.frag.spv")); + let fs_module = device.create_shader_module(&wgpu::include_spirv!( + "shader/quad.frag.spv" + )); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::quad pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[ - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[ + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[wgpu::VertexAttributeDescriptor { + attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }], }, - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, attributes: &[ - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float2, offset: 0, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 2, format: wgpu::VertexFormat::Float2, offset: 4 * 2, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 3, format: wgpu::VertexFormat::Float4, offset: 4 * (2 + 2), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 4, format: wgpu::VertexFormat::Float4, offset: 4 * (2 + 2 + 4), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 5, format: wgpu::VertexFormat::Float, offset: 4 * (2 + 2 + 4 + 4), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 6, format: wgpu::VertexFormat::Float, offset: 4 * (2 + 2 + 4 + 4 + 1), @@ -148,9 +125,36 @@ impl Pipeline { }, ], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + cull_mode: wgpu::CullMode::None, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, }); let vertices = @@ -232,6 +236,7 @@ impl Pipeline { { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::quad render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -247,7 +252,10 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, &self.constants, &[]); - render_pass.set_index_buffer(self.indices.slice(..)); + render_pass.set_index_buffer( + self.indices.slice(..), + wgpu::IndexFormat::Uint16, + ); render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..)); render_pass.set_scissor_rect( From 98d108d2b73b994a63140361110dec6401a80ae4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:32:30 +0100 Subject: [PATCH 03/16] [wgpu 0.7] Update window/compositor.rs Notes: - wgpu::PowerPreference::Default no longer exists, maybe there is another way to replicate its behavior. --- wgpu/src/window/compositor.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 492efb42..492cb955 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -27,7 +27,7 @@ impl Compositor { let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { - wgpu::PowerPreference::Default + wgpu::PowerPreference::default() } else { wgpu::PowerPreference::HighPerformance }, @@ -38,12 +38,14 @@ impl Compositor { let (device, queue) = adapter .request_device( &wgpu::DeviceDescriptor { + label: Some( + "iced_wgpu::window::Compositor Device Descriptor", + ), features: wgpu::Features::empty(), limits: wgpu::Limits { max_bind_groups: 2, ..wgpu::Limits::default() }, - shader_validation: false, }, None, ) @@ -103,7 +105,7 @@ impl iced_graphics::window::Compositor for Compositor { self.device.create_swap_chain( surface, &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, format: self.settings.format, present_mode: self.settings.present_mode, width, @@ -130,6 +132,7 @@ impl iced_graphics::window::Compositor for Compositor { ); let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::window::Compositor Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.output.view, resolve_target: None, From 5f935c34fdd23a99e39ea80fef3845d476fc78f4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:05:37 +0100 Subject: [PATCH 04/16] [wgpu 0.7] Update triangle/msaa.rs Notes: - not sure if `filtering sampler` should be used, so for now it is not used . --- wgpu/src/triangle/msaa.rs | 74 +++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index db86f748..13c2a3c4 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -32,7 +32,10 @@ impl Blit { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler { comparison: false }, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: true, + }, count: None, }], }); @@ -53,9 +56,11 @@ impl Blit { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::SampledTexture { - dimension: wgpu::TextureViewDimension::D2, - component_type: wgpu::TextureComponentType::Float, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, + }, + view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, count: None, @@ -69,11 +74,11 @@ impl Blit { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "../shader/blit.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "../shader/blit.frag.spv" )); @@ -81,42 +86,42 @@ impl Blit { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle::msaa pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", + buffers: &[], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment: Some(wgpu::FragmentState { module: &fs_module, entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, front_face: wgpu::FrontFace::Cw, cull_mode: wgpu::CullMode::None, ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + depth_stencil: None, + + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, }); Blit { @@ -172,6 +177,7 @@ impl Blit { ) { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::triangle::msaa Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -227,7 +233,7 @@ impl Targets { sample_count, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, }); let resolve = device.create_texture(&wgpu::TextureDescriptor { @@ -237,7 +243,7 @@ impl Targets { sample_count: 1, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT + usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, }); From e2595ac0aa53448feb421c1591178b748814055a Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:06:07 +0100 Subject: [PATCH 05/16] [wgpu 0.7] Update triangle.rs --- wgpu/src/triangle.rs | 112 +++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 61a771d8..d23ce29e 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -86,8 +86,9 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: true, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -109,11 +110,13 @@ impl Pipeline { layout: &constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - constants_buffer - .raw - .slice(0..std::mem::size_of::() as u64), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &constants_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new( + std::mem::size_of::() as u64, + ), + }, }], }); @@ -124,11 +127,11 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.frag.spv" )); @@ -136,49 +139,21 @@ impl Pipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint32, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[ // Position - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }, // Color - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float4, offset: 4 * 2, @@ -186,11 +161,38 @@ impl Pipeline { ], }], }, - sample_count: u32::from( - antialiasing.map(|a| a.sample_count()).unwrap_or(1), - ), - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + cull_mode: wgpu::CullMode::None, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: u32::from( + antialiasing.map(|a| a.sample_count()).unwrap_or(1), + ), + mask: !0, + alpha_to_coverage_enabled: false, + }, }); Pipeline { @@ -252,11 +254,15 @@ impl Pipeline { layout: &self.constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - self.uniforms_buffer.raw.slice( - 0..std::mem::size_of::() as u64, - ), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &self.uniforms_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new(std::mem::size_of::< + Uniforms, + >( + ) + as u64), + }, }], }); } @@ -356,6 +362,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::triangle Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment, @@ -390,6 +397,7 @@ impl Pipeline { self.index_buffer .raw .slice(index_offset * mem::size_of::() as u64..), + wgpu::IndexFormat::Uint32, ); render_pass.set_vertex_buffer( From 4a6db30d47683110663bc610c9ef9c7a9c9ac184 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:24:48 +0100 Subject: [PATCH 06/16] [wgpu 0.7] Update image.rs --- wgpu/src/image.rs | 121 +++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index c256ca7e..b44d621b 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -62,8 +62,9 @@ impl Pipeline { wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: false, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -73,7 +74,10 @@ impl Pipeline { wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler { comparison: false }, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: false, + }, count: None, }, ], @@ -93,9 +97,11 @@ impl Pipeline { entries: &[ wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - uniforms_buffer.slice(..), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &uniforms_buffer, + offset: 0, + size: None, + }, }, wgpu::BindGroupEntry { binding: 1, @@ -110,9 +116,11 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::SampledTexture { - dimension: wgpu::TextureViewDimension::D2, - component_type: wgpu::TextureComponentType::Float, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: false, + }, + view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, count: None, @@ -126,11 +134,11 @@ impl Pipeline { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/image.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/image.frag.spv" )); @@ -138,72 +146,44 @@ impl Pipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::image pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[ - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[ + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[wgpu::VertexAttributeDescriptor { + attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }], }, - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, attributes: &[ - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float2, offset: 0, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 2, format: wgpu::VertexFormat::Float2, offset: 4 * 2, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 3, format: wgpu::VertexFormat::Float2, offset: 4 * 4, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 4, format: wgpu::VertexFormat::Float2, offset: 4 * 6, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 5, format: wgpu::VertexFormat::Uint, offset: 4 * 8, @@ -212,9 +192,36 @@ impl Pipeline { }, ], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + cull_mode: wgpu::CullMode::None, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, }); let vertices = @@ -415,6 +422,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::image Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -431,7 +439,10 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, &self.constants, &[]); render_pass.set_bind_group(1, &self.texture, &[]); - render_pass.set_index_buffer(self.indices.slice(..)); + render_pass.set_index_buffer( + self.indices.slice(..), + wgpu::IndexFormat::Uint16, + ); render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..)); From c5d6ddc1264a294cab8e41e05828ece3e7df5945 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 21:13:51 +0100 Subject: [PATCH 07/16] [wgpu 0.7] triangle/msaa disable filtering --- wgpu/src/triangle/msaa.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 13c2a3c4..0a5a703e 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -34,7 +34,7 @@ impl Blit { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, - filtering: true, + filtering: false, }, count: None, }], @@ -58,7 +58,7 @@ impl Blit { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { - filterable: true, + filterable: false, }, view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, From bd6b8304bd940c5519fdf705698974994d5d1ca1 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 21:51:11 +0100 Subject: [PATCH 08/16] Fix ScissorRect - Breaks `TODO: Address anti-aliasing adjustments properly` --- wgpu/src/quad.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index c1399d53..f8531992 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -258,12 +258,13 @@ impl Pipeline { ); render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..)); + render_pass.set_scissor_rect( bounds.x, bounds.y, bounds.width, // TODO: Address anti-aliasing adjustments properly - bounds.height + 1, + bounds.height, ); render_pass.draw_indexed( From 1fb60c5dcbea77bf36934f243bb0832c3e5a116e Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 22:26:53 +0100 Subject: [PATCH 09/16] Fix TextureViewDimension for image wgpu validation helped to find this long standing type error --- wgpu/src/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index b44d621b..32843828 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -120,7 +120,7 @@ impl Pipeline { sample_type: wgpu::TextureSampleType::Float { filterable: false, }, - view_dimension: wgpu::TextureViewDimension::D2, + view_dimension: wgpu::TextureViewDimension::D2Array, multisampled: false, }, count: None, From 09a5348740803329c98f6422700569595c2be8c5 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 22:38:45 +0100 Subject: [PATCH 10/16] [wgpu 0.7] Update integration example --- examples/integration/src/main.rs | 8 +++---- examples/integration/src/scene.rs | 40 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 9b52f3a5..ec01c4e6 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -36,7 +36,7 @@ pub fn main() { let (mut device, queue) = futures::executor::block_on(async { let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::Default, + power_preference: wgpu::PowerPreference::HighPerformance, compatible_surface: Some(&surface), }) .await @@ -45,9 +45,9 @@ pub fn main() { adapter .request_device( &wgpu::DeviceDescriptor { + label: None, features: wgpu::Features::empty(), limits: wgpu::Limits::default(), - shader_validation: false, }, None, ) @@ -63,7 +63,7 @@ pub fn main() { device.create_swap_chain( &surface, &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, format: format, width: size.width, height: size.height, @@ -157,7 +157,7 @@ pub fn main() { swap_chain = device.create_swap_chain( &surface, &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, format: format, width: size.width, height: size.height, diff --git a/examples/integration/src/scene.rs b/examples/integration/src/scene.rs index 03a338c6..36c0a41d 100644 --- a/examples/integration/src/scene.rs +++ b/examples/integration/src/scene.rs @@ -19,6 +19,7 @@ impl Scene { background_color: Color, ) -> wgpu::RenderPass<'a> { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: target, resolve_target: None, @@ -48,10 +49,10 @@ impl Scene { fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline { let vs_module = - device.create_shader_module(wgpu::include_spirv!("shader/vert.spv")); + device.create_shader_module(&wgpu::include_spirv!("shader/vert.spv")); let fs_module = - device.create_shader_module(wgpu::include_spirv!("shader/frag.spv")); + device.create_shader_module(&wgpu::include_spirv!("shader/frag.spv")); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -64,34 +65,33 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", + buffers: &[], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment: Some(wgpu::FragmentState { module: &fs_module, entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: wgpu::TextureFormat::Bgra8UnormSrgb, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::None, ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: wgpu::TextureFormat::Bgra8UnormSrgb, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, }); pipeline From b0d1be69d679444e7d0957e1b619720705e03107 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 23:50:03 +0100 Subject: [PATCH 11/16] Change `PowerPreference` from `default()` to `LowPower` There is no reason to hide the fact that this is always in `LowPower` mode --- wgpu/src/window/compositor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 492cb955..361b9ecf 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -27,7 +27,7 @@ impl Compositor { let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { - wgpu::PowerPreference::default() + wgpu::PowerPreference::LowPower } else { wgpu::PowerPreference::HighPerformance }, From 5fc4210270852d8d633a63168d8a166a235236c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Feb 2021 15:27:27 +0100 Subject: [PATCH 12/16] Use the latest release of `wgpu_glyph` --- wgpu/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index b4b2a42b..bdd9e65a 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -14,8 +14,8 @@ qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] [dependencies] -wgpu = "0.7.0" -wgpu_glyph = {git="https://github.com/hecrj/wgpu_glyph.git"} +wgpu = "0.7" +wgpu_glyph = "0.11" glyph_brush = "0.7" raw-window-handle = "0.3" log = "0.4" From ffdf87fbe2cf132b63d0a5af46c8ec1aead9af12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Feb 2021 15:37:05 +0100 Subject: [PATCH 13/16] Use lowercase in `wgpu` labels for consistency --- wgpu/src/image.rs | 2 +- wgpu/src/triangle.rs | 2 +- wgpu/src/triangle/msaa.rs | 2 +- wgpu/src/window/compositor.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 32843828..e34cbb0a 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -422,7 +422,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::image Render Pass"), + label: Some("iced_wgpu::image render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index d23ce29e..2f255940 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -362,7 +362,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::triangle Render Pass"), + label: Some("iced_wgpu::triangle render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment, diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 0a5a703e..4c8fe20c 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -177,7 +177,7 @@ impl Blit { ) { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::triangle::msaa Render Pass"), + label: Some("iced_wgpu::triangle::msaa render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 361b9ecf..36d6ab1a 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -39,7 +39,7 @@ impl Compositor { .request_device( &wgpu::DeviceDescriptor { label: Some( - "iced_wgpu::window::Compositor Device Descriptor", + "iced_wgpu::window::compositor device descriptor", ), features: wgpu::Features::empty(), limits: wgpu::Limits { @@ -132,7 +132,7 @@ impl iced_graphics::window::Compositor for Compositor { ); let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::window::Compositor Render Pass"), + label: Some("iced_wgpu::window::Compositor render pass"), color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.output.view, resolve_target: None, From 15c4901aba7fbcc5373b68e0d1a52ad446b64b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Feb 2021 15:38:02 +0100 Subject: [PATCH 14/16] Remove unnecessary line break in `triangle::msaa` --- wgpu/src/triangle/msaa.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 4c8fe20c..d964f815 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -116,7 +116,6 @@ impl Blit { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState { count: 1, mask: !0, From 7eefad34fc93838a5a3fe976ed0ee47818004b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Feb 2021 15:55:03 +0100 Subject: [PATCH 15/16] List `color_blend` first in `wgpu::quad` --- wgpu/src/quad.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index f8531992..e0a6e043 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -130,13 +130,13 @@ impl Pipeline { entry_point: "main", targets: &[wgpu::ColorTargetState { format, - alpha_blend: wgpu::BlendState { - src_factor: wgpu::BlendFactor::One, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, operation: wgpu::BlendOperation::Add, }, - color_blend: wgpu::BlendState { - src_factor: wgpu::BlendFactor::SrcAlpha, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, operation: wgpu::BlendOperation::Add, }, From 74b9ea520f0f861bda82bbf79a6d4327e42a62fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 6 Feb 2021 16:04:43 +0100 Subject: [PATCH 16/16] Enable filtering in `wgpu::image` --- wgpu/src/image.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index e34cbb0a..70bfe586 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -76,7 +76,7 @@ impl Pipeline { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, - filtering: false, + filtering: true, }, count: None, }, @@ -118,7 +118,7 @@ impl Pipeline { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { - filterable: false, + filterable: true, }, view_dimension: wgpu::TextureViewDimension::D2Array, multisampled: false,