From 4a6db30d47683110663bc610c9ef9c7a9c9ac184 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:24:48 +0100 Subject: [wgpu 0.7] Update image.rs --- wgpu/src/image.rs | 121 +++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 55 deletions(-) (limited to 'wgpu/src/image.rs') 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(..)); -- cgit From 1fb60c5dcbea77bf36934f243bb0832c3e5a116e Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 22:26:53 +0100 Subject: 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(-) (limited to 'wgpu/src/image.rs') 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, -- cgit From ffdf87fbe2cf132b63d0a5af46c8ec1aead9af12 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 15:37:05 +0100 Subject: Use lowercase in `wgpu` labels for consistency --- wgpu/src/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/image.rs') 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, -- cgit From 74b9ea520f0f861bda82bbf79a6d4327e42a62fc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 16:04:43 +0100 Subject: Enable filtering in `wgpu::image` --- wgpu/src/image.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/image.rs') 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, -- cgit From 8f126c212b887b2621cd8220bc4a52ba4febb1eb Mon Sep 17 00:00:00 2001 From: Greg V Date: Fri, 5 Jun 2020 21:18:22 +0300 Subject: Add image format options to reduce code bloat, fixes #376 --- wgpu/src/image.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 70bfe586..5511565e 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -1,6 +1,6 @@ mod atlas; -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] mod raster; #[cfg(feature = "svg")] @@ -16,7 +16,7 @@ use std::mem; use bytemuck::{Pod, Zeroable}; -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] use iced_native::image; #[cfg(feature = "svg")] @@ -24,7 +24,7 @@ use iced_native::svg; #[derive(Debug)] pub struct Pipeline { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] raster_cache: RefCell, #[cfg(feature = "svg")] vector_cache: RefCell, @@ -259,7 +259,7 @@ impl Pipeline { }); Pipeline { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] raster_cache: RefCell::new(raster::Cache::new()), #[cfg(feature = "svg")] @@ -278,7 +278,7 @@ impl Pipeline { } } - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) { let mut cache = self.raster_cache.borrow_mut(); let memory = cache.load(&handle); @@ -307,7 +307,7 @@ impl Pipeline { ) { let instances: &mut Vec = &mut Vec::new(); - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] let mut raster_cache = self.raster_cache.borrow_mut(); #[cfg(feature = "svg")] @@ -315,7 +315,7 @@ impl Pipeline { for image in images { match &image { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] layer::Image::Raster { handle, bounds } => { if let Some(atlas_entry) = raster_cache.upload( handle, @@ -331,7 +331,7 @@ impl Pipeline { ); } } - #[cfg(not(feature = "image"))] + #[cfg(not(feature = "image_rs"))] layer::Image::Raster { .. } => {} #[cfg(feature = "svg")] @@ -464,7 +464,7 @@ impl Pipeline { } pub fn trim_cache(&mut self) { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] self.raster_cache.borrow_mut().trim(&mut self.texture_atlas); #[cfg(feature = "svg")] -- cgit From 9a2c78c4059d2be37d10adda397fb6e64f38ac02 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Sun, 11 Apr 2021 18:55:57 -0700 Subject: Upgrade wgpu --- wgpu/src/image.rs | 59 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 5511565e..713af209 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -134,28 +134,26 @@ impl Pipeline { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/image.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/image.frag.spv" - )); + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("iced_wgpu::image::shader"), + source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader/image.wgsl"))), + flags: wgpu::ShaderFlags::all() + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::image pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[ wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[wgpu::VertexAttribute { shader_location: 0, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }], }, @@ -165,27 +163,27 @@ impl Pipeline { attributes: &[ wgpu::VertexAttribute { shader_location: 1, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }, wgpu::VertexAttribute { shader_location: 2, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 2, }, wgpu::VertexAttribute { shader_location: 3, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 4, }, wgpu::VertexAttribute { shader_location: 4, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 6, }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Uint, + format: wgpu::VertexFormat::Uint32, offset: 4 * 8, }, ], @@ -193,27 +191,28 @@ impl Pipeline { ], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -424,8 +423,8 @@ impl Pipeline { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::image render pass"), color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment: target, + wgpu::RenderPassColorAttachment { + view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, -- cgit From 0722d5e3ec307fd82a1cc76593d17d83cf828943 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:07:58 -0700 Subject: add temporary fix for image wgsl --- wgpu/src/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 713af209..45b63701 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -183,7 +183,7 @@ impl Pipeline { }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Uint32, + format: wgpu::VertexFormat::Sint32, offset: 4 * 8, }, ], -- cgit From 983aa1b3665c6b546700767d21d73de72372ddad Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:23:47 -0700 Subject: Run cargo fmt --- wgpu/src/image.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 45b63701..78f70dd8 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -134,11 +134,14 @@ impl Pipeline { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { - label: Some("iced_wgpu::image::shader"), - source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader/image.wgsl"))), - flags: wgpu::ShaderFlags::all() - }); + let shader = + device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("iced_wgpu::image::shader"), + source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( + include_str!("shader/image.wgsl"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -422,16 +425,14 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::image render pass"), - color_attachments: &[ - wgpu::RenderPassColorAttachment { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, - }, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, }, - ], + }], depth_stencil_attachment: None, }); -- cgit From cf6af4c2560f5996bc533402ac3e4289c0c94702 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 19 May 2021 17:11:51 +0700 Subject: Use latest `wgpu` releases instead of patched sources --- wgpu/src/image.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 78f70dd8..cd7b3d23 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -97,11 +97,13 @@ impl Pipeline { entries: &[ wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { - buffer: &uniforms_buffer, - offset: 0, - size: None, - }, + resource: wgpu::BindingResource::Buffer( + wgpu::BufferBinding { + buffer: &uniforms_buffer, + offset: 0, + size: None, + }, + ), }, wgpu::BindGroupEntry { binding: 1, -- cgit From a53e7559fe01ee072d4f0533ecf1facec741b9e4 Mon Sep 17 00:00:00 2001 From: Poly Date: Sun, 20 Jun 2021 11:29:23 +0200 Subject: Use vertex_attr_array macro --- wgpu/src/image.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'wgpu/src/image.rs') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index cd7b3d23..85663bf5 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -165,33 +165,13 @@ impl Pipeline { wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, - attributes: &[ - wgpu::VertexAttribute { - shader_location: 1, - format: wgpu::VertexFormat::Float32x2, - offset: 0, - }, - wgpu::VertexAttribute { - shader_location: 2, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 2, - }, - wgpu::VertexAttribute { - shader_location: 3, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 4, - }, - wgpu::VertexAttribute { - shader_location: 4, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 6, - }, - wgpu::VertexAttribute { - shader_location: 5, - format: wgpu::VertexFormat::Sint32, - offset: 4 * 8, - }, - ], + attributes: &wgpu::vertex_attr_array!( + 1 => Float32x2, + 2 => Float32x2, + 3 => Float32x2, + 4 => Float32x2, + 5 => Sint32, + ), }, ], }, -- cgit