From 3f467d121229142177ef1b2f417fe87c7bf7fdf2 Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Sun, 24 Sep 2023 15:10:19 +0200 Subject: Compute vertex position in shader --- wgpu/src/quad/gradient.rs | 64 +++++++++++++++++++++-------------------------- wgpu/src/quad/solid.rs | 47 +++++++++++++++------------------- 2 files changed, 48 insertions(+), 63 deletions(-) (limited to 'wgpu/src/quad') diff --git a/wgpu/src/quad/gradient.rs b/wgpu/src/quad/gradient.rs index a8e83d01..312408b7 100644 --- a/wgpu/src/quad/gradient.rs +++ b/wgpu/src/quad/gradient.rs @@ -106,36 +106,32 @@ impl Pipeline { vertex: wgpu::VertexState { module: &shader, entry_point: "gradient_vs_main", - buffers: &[ - quad::Vertex::buffer_layout(), - wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() - as u64, - step_mode: wgpu::VertexStepMode::Instance, - attributes: &wgpu::vertex_attr_array!( - // Colors 1-2 - 1 => Uint32x4, - // Colors 3-4 - 2 => Uint32x4, - // Colors 5-6 - 3 => Uint32x4, - // Colors 7-8 - 4 => Uint32x4, - // Offsets 1-8 - 5 => Uint32x4, - // Direction - 6 => Float32x4, - // Position & Scale - 7 => Float32x4, - // Border color - 8 => Float32x4, - // Border radius - 9 => Float32x4, - // Border width - 10 => Float32 - ), - }, - ], + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as u64, + step_mode: wgpu::VertexStepMode::Instance, + attributes: &wgpu::vertex_attr_array!( + // Colors 1-2 + 1 => Uint32x4, + // Colors 3-4 + 2 => Uint32x4, + // Colors 5-6 + 3 => Uint32x4, + // Colors 7-8 + 4 => Uint32x4, + // Offsets 1-8 + 5 => Uint32x4, + // Direction + 6 => Float32x4, + // Position & Scale + 7 => Float32x4, + // Border color + 8 => Float32x4, + // Border radius + 9 => Float32x4, + // Border width + 10 => Float32 + ), + }], }, fragment: Some(wgpu::FragmentState { module: &shader, @@ -171,12 +167,8 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, constants, &[]); - render_pass.set_vertex_buffer(1, layer.instances.slice(..)); + render_pass.set_vertex_buffer(0, layer.instances.slice(..)); - render_pass.draw_indexed( - 0..quad::INDICES.len() as u32, - 0, - range.start as u32..range.end as u32, - ); + render_pass.draw(0..6, range.start as u32..range.end as u32); } } diff --git a/wgpu/src/quad/solid.rs b/wgpu/src/quad/solid.rs index 9bc6b466..bab7367d 100644 --- a/wgpu/src/quad/solid.rs +++ b/wgpu/src/quad/solid.rs @@ -87,27 +87,24 @@ impl Pipeline { vertex: wgpu::VertexState { module: &shader, entry_point: "solid_vs_main", - buffers: &[ - quad::Vertex::buffer_layout(), - wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, - step_mode: wgpu::VertexStepMode::Instance, - attributes: &wgpu::vertex_attr_array!( - // Color - 1 => Float32x4, - // Position - 2 => Float32x2, - // Size - 3 => Float32x2, - // Border color - 4 => Float32x4, - // Border radius - 5 => Float32x4, - // Border width - 6 => Float32, - ), - }, - ], + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as u64, + step_mode: wgpu::VertexStepMode::Instance, + attributes: &wgpu::vertex_attr_array!( + // Color + 1 => Float32x4, + // Position + 2 => Float32x2, + // Size + 3 => Float32x2, + // Border color + 4 => Float32x4, + // Border radius + 5 => Float32x4, + // Border width + 6 => Float32, + ), + }], }, fragment: Some(wgpu::FragmentState { module: &shader, @@ -143,12 +140,8 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, constants, &[]); - render_pass.set_vertex_buffer(1, layer.instances.slice(..)); + render_pass.set_vertex_buffer(0, layer.instances.slice(..)); - render_pass.draw_indexed( - 0..quad::INDICES.len() as u32, - 0, - range.start as u32..range.end as u32, - ); + render_pass.draw(0..6, range.start as u32..range.end as u32); } } -- cgit From bcc55e6036df0a2f9bdc7a21bf6ac98c03dd29ae Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Sun, 24 Sep 2023 15:12:32 +0200 Subject: Reassign attribute locations --- wgpu/src/quad/gradient.rs | 20 ++++++++++---------- wgpu/src/quad/solid.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'wgpu/src/quad') diff --git a/wgpu/src/quad/gradient.rs b/wgpu/src/quad/gradient.rs index 312408b7..ff30f78f 100644 --- a/wgpu/src/quad/gradient.rs +++ b/wgpu/src/quad/gradient.rs @@ -111,25 +111,25 @@ impl Pipeline { step_mode: wgpu::VertexStepMode::Instance, attributes: &wgpu::vertex_attr_array!( // Colors 1-2 - 1 => Uint32x4, + 0 => Uint32x4, // Colors 3-4 - 2 => Uint32x4, + 1 => Uint32x4, // Colors 5-6 - 3 => Uint32x4, + 2 => Uint32x4, // Colors 7-8 - 4 => Uint32x4, + 3 => Uint32x4, // Offsets 1-8 - 5 => Uint32x4, + 4 => Uint32x4, // Direction - 6 => Float32x4, + 5 => Float32x4, // Position & Scale - 7 => Float32x4, + 6 => Float32x4, // Border color - 8 => Float32x4, + 7 => Float32x4, // Border radius - 9 => Float32x4, + 8 => Float32x4, // Border width - 10 => Float32 + 9 => Float32 ), }], }, diff --git a/wgpu/src/quad/solid.rs b/wgpu/src/quad/solid.rs index bab7367d..96e73ba8 100644 --- a/wgpu/src/quad/solid.rs +++ b/wgpu/src/quad/solid.rs @@ -92,17 +92,17 @@ impl Pipeline { step_mode: wgpu::VertexStepMode::Instance, attributes: &wgpu::vertex_attr_array!( // Color - 1 => Float32x4, + 0 => Float32x4, // Position - 2 => Float32x2, + 1 => Float32x2, // Size - 3 => Float32x2, + 2 => Float32x2, // Border color - 4 => Float32x4, + 3 => Float32x4, // Border radius - 5 => Float32x4, + 4 => Float32x4, // Border width - 6 => Float32, + 5 => Float32, ), }], }, -- cgit From e197abe0aae659742532ff2e2985afc97f041d2a Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Sun, 24 Sep 2023 15:19:07 +0200 Subject: Move vertex position function into own file --- wgpu/src/quad/gradient.rs | 4 ++++ wgpu/src/quad/solid.rs | 2 ++ 2 files changed, 6 insertions(+) (limited to 'wgpu/src/quad') diff --git a/wgpu/src/quad/gradient.rs b/wgpu/src/quad/gradient.rs index ff30f78f..60b170cc 100644 --- a/wgpu/src/quad/gradient.rs +++ b/wgpu/src/quad/gradient.rs @@ -83,6 +83,8 @@ impl Pipeline { concat!( include_str!("../shader/quad.wgsl"), "\n", + include_str!("../shader/vertex.wgsl"), + "\n", include_str!("../shader/quad/gradient.wgsl"), "\n", include_str!("../shader/color/oklab.wgsl") @@ -91,6 +93,8 @@ impl Pipeline { concat!( include_str!("../shader/quad.wgsl"), "\n", + include_str!("../shader/vertex.wgsl"), + "\n", include_str!("../shader/quad/gradient.wgsl"), "\n", include_str!("../shader/color/linear_rgb.wgsl") diff --git a/wgpu/src/quad/solid.rs b/wgpu/src/quad/solid.rs index 96e73ba8..90e7f98e 100644 --- a/wgpu/src/quad/solid.rs +++ b/wgpu/src/quad/solid.rs @@ -75,6 +75,8 @@ impl Pipeline { concat!( include_str!("../shader/quad.wgsl"), "\n", + include_str!("../shader/vertex.wgsl"), + "\n", include_str!("../shader/quad/solid.wgsl"), ), )), -- cgit