From 2d76c7165c4a82f27090cbf69f811f8e0f2f28a4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:21:02 +0100 Subject: [wgpu 0.7] Update quad.rs --- wgpu/src/quad.rs | 116 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 54 deletions(-) (limited to 'wgpu/src/quad.rs') 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( -- cgit From bd6b8304bd940c5519fdf705698974994d5d1ca1 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 21:51:11 +0100 Subject: Fix ScissorRect - Breaks `TODO: Address anti-aliasing adjustments properly` --- wgpu/src/quad.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wgpu/src/quad.rs') 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( -- cgit From 7eefad34fc93838a5a3fe976ed0ee47818004b83 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 15:55:03 +0100 Subject: List `color_blend` first in `wgpu::quad` --- wgpu/src/quad.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'wgpu/src/quad.rs') 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, }, -- 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/quad.rs | 76 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index e0a6e043..458679e4 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -62,28 +62,29 @@ impl Pipeline { bind_group_layouts: &[&constant_layout], }); - 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 shader = + device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("iced_wgpu::quad::shader"), + source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( + include_str!("shader/quad.wgsl"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::quad 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, }], }, @@ -93,32 +94,32 @@ 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::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * (2 + 2), }, wgpu::VertexAttribute { shader_location: 4, - format: wgpu::VertexFormat::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * (2 + 2 + 4), }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Float, + format: wgpu::VertexFormat::Float32, offset: 4 * (2 + 2 + 4 + 4), }, wgpu::VertexAttribute { shader_location: 6, - format: wgpu::VertexFormat::Float, + format: wgpu::VertexFormat::Float32, offset: 4 * (2 + 2 + 4 + 4 + 1), }, ], @@ -126,27 +127,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, @@ -237,16 +239,14 @@ 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, - 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/quad.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 458679e4..0f9d7b99 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -47,11 +47,11 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { + resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { buffer: &constants_buffer, offset: 0, size: None, - }, + }), }], }); -- cgit From d91422e345d30f0d33d737a3be8ad1c90f5d14b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 08:09:03 -0700 Subject: temporary up --- wgpu/src/quad.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 0f9d7b99..9b87ef81 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -28,7 +28,7 @@ impl Pipeline { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( - mem::size_of::() as u64, + mem::size_of::() as wgpu::BufferAddress, ), }, count: None, @@ -37,7 +37,7 @@ impl Pipeline { let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::quad uniforms buffer"), - size: mem::size_of::() as u64, + size: mem::size_of::() as wgpu::BufferAddress, usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, mapped_at_creation: false, }); @@ -47,11 +47,7 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { - buffer: &constants_buffer, - offset: 0, - size: None, - }), + resource: constants_buffer.as_entire_binding(), }], }); -- cgit From b40c44164646e853239d1b76fd8e4768eb21d9ac Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 21:04:47 -0700 Subject: Add padding to quad to fix alignment issue --- wgpu/src/quad.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 9b87ef81..b91e3e89 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -305,6 +305,9 @@ const MAX_INSTANCES: usize = 100_000; struct Uniforms { transform: [f32; 16], scale: f32, + // Uniforms must be aligned to their largest member, + // this uses a mat4x4 which aligns to 16, so align to that + _padding: [f32; 3], } impl Uniforms { @@ -312,6 +315,7 @@ impl Uniforms { Self { transform: *transformation.as_ref(), scale, + _padding: [0.0; 3] } } } @@ -321,6 +325,7 @@ impl Default for Uniforms { Self { transform: *Transformation::identity().as_ref(), scale: 1.0, + _padding: [0.0; 3] } } } -- cgit From a70715ad9e41bf133e8e37d43633ffa84ae211b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 22:07:27 -0700 Subject: run format --- wgpu/src/quad.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index b91e3e89..6f221ca3 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -315,7 +315,7 @@ impl Uniforms { Self { transform: *transformation.as_ref(), scale, - _padding: [0.0; 3] + _padding: [0.0; 3], } } } @@ -325,7 +325,7 @@ impl Default for Uniforms { Self { transform: *Transformation::identity().as_ref(), scale: 1.0, - _padding: [0.0; 3] + _padding: [0.0; 3], } } } -- 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/quad.rs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) (limited to 'wgpu/src/quad.rs') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 6f221ca3..93942fba 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -87,38 +87,14 @@ 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::Float32x4, - offset: 4 * (2 + 2), - }, - wgpu::VertexAttribute { - shader_location: 4, - format: wgpu::VertexFormat::Float32x4, - offset: 4 * (2 + 2 + 4), - }, - wgpu::VertexAttribute { - shader_location: 5, - format: wgpu::VertexFormat::Float32, - offset: 4 * (2 + 2 + 4 + 4), - }, - wgpu::VertexAttribute { - shader_location: 6, - format: wgpu::VertexFormat::Float32, - offset: 4 * (2 + 2 + 4 + 4 + 1), - }, - ], + attributes: &wgpu::vertex_attr_array!( + 1 => Float32x2, + 2 => Float32x2, + 3 => Float32x4, + 4 => Float32x4, + 5 => Float32, + 6 => Float32, + ), }, ], }, -- cgit