From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- wgpu/src/triangle/gradient.rs | 265 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 wgpu/src/triangle/gradient.rs (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs new file mode 100644 index 00000000..471b204c --- /dev/null +++ b/wgpu/src/triangle/gradient.rs @@ -0,0 +1,265 @@ +use crate::buffers::dynamic_buffers::DynamicBuffer; +use crate::settings; +use crate::triangle::{ + default_fragment_target, default_multisample_state, + default_triangle_primitive_state, vertex_buffer_layout, +}; +use encase::ShaderType; +use glam::{Vec2, Vec4}; +use iced_graphics::gradient::Gradient; +use iced_graphics::Transformation; + +pub(super) struct GradientPipeline { + pipeline: wgpu::RenderPipeline, + pub(super) uniform_buffer: DynamicBuffer, + pub(super) storage_buffer: DynamicBuffer, + color_stop_offset: i32, + //Need to store these and then write them all at once + //or else they will be padded to 256 and cause gaps in the storage buffer + color_stops_pending_write: GradientStorage, + bind_group_layout: wgpu::BindGroupLayout, + bind_group: wgpu::BindGroup, +} + +//TODO I can tightly pack this by rearranging/consolidating some fields +#[derive(Debug, ShaderType)] +pub(super) struct GradientUniforms { + transform: glam::Mat4, + start: Vec2, + #[align(16)] + end: Vec2, + #[align(16)] + start_stop: i32, + #[align(16)] + end_stop: i32, +} + +#[derive(Debug, ShaderType)] +pub(super) struct ColorStop { + color: Vec4, + offset: f32, +} + +#[derive(ShaderType)] +pub(super) struct GradientStorage { + #[size(runtime)] + pub color_stops: Vec, +} + +impl GradientPipeline { + /// Creates a new [GradientPipeline] using `triangle_gradient.wgsl` shader. + pub(super) fn new( + device: &wgpu::Device, + format: wgpu::TextureFormat, + antialiasing: Option, + ) -> Self { + let uniform_buffer = DynamicBuffer::uniform( + device, + "iced_wgpu::triangle [GRADIENT] uniforms", + ); + + //TODO: With a WASM target storage buffers are not supported. Will need to use UBOs & static + // sized array (64 on OpenGL side right now) to make gradients work + let storage_buffer = DynamicBuffer::storage( + device, + "iced_wgpu::triangle [GRADIENT] storage", + ); + + let bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("iced_wgpu::triangle [GRADIENT] bind group layout"), + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX_FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(GradientUniforms::min_size()), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { + read_only: true, + }, + has_dynamic_offset: false, + min_binding_size: Some(GradientStorage::min_size()), + }, + count: None, + }, + ], + }); + + let bind_group = GradientPipeline::bind_group( + device, + uniform_buffer.raw(), + storage_buffer.raw(), + &bind_group_layout, + ); + + let layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("iced_wgpu::triangle [GRADIENT] pipeline layout"), + bind_group_layouts: &[&bind_group_layout], + push_constant_ranges: &[], + }); + + let shader = + device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some( + "iced_wgpu::triangle [GRADIENT] create shader module", + ), + source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( + include_str!("../shader/triangle_gradient.wgsl"), + )), + }); + + let pipeline = + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("iced_wgpu::triangle [GRADIENT] pipeline"), + layout: Some(&layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[vertex_buffer_layout()], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_gradient", + targets: &[default_fragment_target(format)], + }), + primitive: default_triangle_primitive_state(), + depth_stencil: None, + multisample: default_multisample_state(antialiasing), + multiview: None, + }); + + Self { + pipeline, + uniform_buffer, + storage_buffer, + color_stop_offset: 0, + color_stops_pending_write: GradientStorage { color_stops: vec![] }, + bind_group_layout, + bind_group, + } + } + + /// Pushes a new gradient uniform to the CPU buffer. + pub fn push(&mut self, transform: Transformation, gradient: &Gradient) { + match gradient { + Gradient::Linear(linear) => { + let start_offset = self.color_stop_offset; + let end_offset = + (linear.color_stops.len() as i32) + start_offset - 1; + + self.uniform_buffer.push(&GradientUniforms { + transform: transform.into(), + start: Vec2::new(linear.start.x, linear.start.y), + end: Vec2::new(linear.end.x, linear.end.y), + start_stop: start_offset, + end_stop: end_offset, + }); + + self.color_stop_offset = end_offset + 1; + + let stops: Vec = linear + .color_stops + .iter() + .map(|stop| ColorStop { + offset: stop.offset, + color: Vec4::new( + stop.color.r, + stop.color.g, + stop.color.b, + stop.color.a, + ), + }) + .collect(); + + self.color_stops_pending_write.color_stops.extend(stops); + } + } + } + + fn bind_group( + device: &wgpu::Device, + uniform_buffer: &wgpu::Buffer, + storage_buffer: &wgpu::Buffer, + layout: &wgpu::BindGroupLayout, + ) -> wgpu::BindGroup { + device.create_bind_group(&wgpu::BindGroupDescriptor { + label: Some("iced_wgpu::triangle [GRADIENT] bind group"), + layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer( + wgpu::BufferBinding { + buffer: uniform_buffer, + offset: 0, + size: Some(GradientUniforms::min_size()) + } + ) + }, + wgpu::BindGroupEntry { + binding: 1, + resource: storage_buffer.as_entire_binding() + }, + ], + }) + } + + /// Writes the contents of the gradient CPU buffer to the GPU buffer, resizing the GPU buffer + /// beforehand if necessary. + pub fn write( + &mut self, + device: &wgpu::Device, + staging_belt: &mut wgpu::util::StagingBelt, + encoder: &mut wgpu::CommandEncoder, + ) { + //first write the pending color stops to the CPU buffer + self.storage_buffer.push(&self.color_stops_pending_write); + + //resize buffers if needed + let uniforms_resized = self.uniform_buffer.resize(device); + let storage_resized = self.storage_buffer.resize(device); + + if uniforms_resized || storage_resized { + //recreate bind groups if any buffers were resized + self.bind_group = GradientPipeline::bind_group( + device, + self.uniform_buffer.raw(), + self.storage_buffer.raw(), + &self.bind_group_layout, + ); + } + + //write to GPU + self.uniform_buffer.write(device, staging_belt, encoder); + self.storage_buffer.write(device, staging_belt, encoder); + + //cleanup + self.color_stop_offset = 0; + self.color_stops_pending_write.color_stops.clear(); + } + + /// Configures the current render pass to draw the gradient at its offset stored in the + /// [DynamicBuffer] at [index]. + pub fn configure_render_pass<'a>( + &'a self, + render_pass: &mut wgpu::RenderPass<'a>, + index: usize, + ) { + render_pass.set_pipeline(&self.pipeline); + render_pass.set_bind_group( + 0, + &self.bind_group, + &[self.uniform_buffer.offset_at_index(index)], + ); + } +} -- cgit From 6e7b3ced0b1daf368e44e181ecdb4ae529877eb6 Mon Sep 17 00:00:00 2001 From: shan Date: Tue, 4 Oct 2022 18:24:46 -0700 Subject: Reworked wgpu buffers, updated glow side to have proper transform location storage, attempting to fix visibility modifiers, implemented some of the feedback received in initial PR. --- wgpu/src/triangle/gradient.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 471b204c..15b6b7e0 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -253,13 +253,13 @@ impl GradientPipeline { pub fn configure_render_pass<'a>( &'a self, render_pass: &mut wgpu::RenderPass<'a>, - index: usize, + count: usize, ) { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group( 0, &self.bind_group, - &[self.uniform_buffer.offset_at_index(index)], - ); + &[self.uniform_buffer.offset_at_index(count)], + ) } } -- cgit From 30432cbade3d9b25c4df62656a7494db3f4ea82a Mon Sep 17 00:00:00 2001 From: shan Date: Wed, 5 Oct 2022 10:49:58 -0700 Subject: Readjusted namespaces, removed Geometry example as it's no longer relevant. --- wgpu/src/triangle/gradient.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 15b6b7e0..e8c6d7db 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -1,4 +1,4 @@ -use crate::buffers::dynamic_buffers::DynamicBuffer; +use crate::buffers::dynamic::DynamicBuffer; use crate::settings; use crate::triangle::{ default_fragment_target, default_multisample_state, -- cgit From f7ce7244d017ec16545a3e52b6e7cf634bbffd4a Mon Sep 17 00:00:00 2001 From: shan Date: Wed, 5 Oct 2022 11:32:59 -0700 Subject: Adjusted gradient uniforms to be more tightly packed. --- wgpu/src/triangle/gradient.rs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index e8c6d7db..c647e6af 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -5,7 +5,7 @@ use crate::triangle::{ default_triangle_primitive_state, vertex_buffer_layout, }; use encase::ShaderType; -use glam::{Vec2, Vec4}; +use glam::{IVec4, Vec4}; use iced_graphics::gradient::Gradient; use iced_graphics::Transformation; @@ -21,17 +21,13 @@ pub(super) struct GradientPipeline { bind_group: wgpu::BindGroup, } -//TODO I can tightly pack this by rearranging/consolidating some fields #[derive(Debug, ShaderType)] pub(super) struct GradientUniforms { transform: glam::Mat4, - start: Vec2, - #[align(16)] - end: Vec2, - #[align(16)] - start_stop: i32, - #[align(16)] - end_stop: i32, + //xy = start, zw = end + direction: Vec4, + //x = start, y = end, zw = padding + stop_range: IVec4, } #[derive(Debug, ShaderType)] @@ -58,7 +54,7 @@ impl GradientPipeline { "iced_wgpu::triangle [GRADIENT] uniforms", ); - //TODO: With a WASM target storage buffers are not supported. Will need to use UBOs & static + //TODO: With a WASM target storage buffers are not supported. Will need to use UBOs & static // sized array (64 on OpenGL side right now) to make gradients work let storage_buffer = DynamicBuffer::storage( device, @@ -143,7 +139,9 @@ impl GradientPipeline { uniform_buffer, storage_buffer, color_stop_offset: 0, - color_stops_pending_write: GradientStorage { color_stops: vec![] }, + color_stops_pending_write: GradientStorage { + color_stops: vec![], + }, bind_group_layout, bind_group, } @@ -159,10 +157,13 @@ impl GradientPipeline { self.uniform_buffer.push(&GradientUniforms { transform: transform.into(), - start: Vec2::new(linear.start.x, linear.start.y), - end: Vec2::new(linear.end.x, linear.end.y), - start_stop: start_offset, - end_stop: end_offset, + direction: Vec4::new( + linear.start.x, + linear.start.y, + linear.end.x, + linear.end.y, + ), + stop_range: IVec4::new(start_offset, end_offset, 0, 0), }); self.color_stop_offset = end_offset + 1; @@ -202,13 +203,13 @@ impl GradientPipeline { wgpu::BufferBinding { buffer: uniform_buffer, offset: 0, - size: Some(GradientUniforms::min_size()) - } - ) + size: Some(GradientUniforms::min_size()), + }, + ), }, wgpu::BindGroupEntry { binding: 1, - resource: storage_buffer.as_entire_binding() + resource: storage_buffer.as_entire_binding(), }, ], }) -- cgit From 1eb8d972ba60592da7bfc27fe7ec80138e64dd7b Mon Sep 17 00:00:00 2001 From: shan Date: Wed, 5 Oct 2022 16:07:43 -0700 Subject: Reduced memory transfer of OpenGL gradient uniform upload. Rearranged gradient uniforms on OpenGL side to be more performant. --- wgpu/src/triangle/gradient.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index c647e6af..b6553708 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -54,8 +54,8 @@ impl GradientPipeline { "iced_wgpu::triangle [GRADIENT] uniforms", ); - //TODO: With a WASM target storage buffers are not supported. Will need to use UBOs & static - // sized array (64 on OpenGL side right now) to make gradients work + //Note: with a WASM target storage buffers are not supported. Will need to use UBOs & static + // sized array (eg like the 64-sized array on OpenGL side right now) to make gradients work let storage_buffer = DynamicBuffer::storage( device, "iced_wgpu::triangle [GRADIENT] storage", -- cgit From cb7c4676543cd508dfae8d4dcbd9cc8b61b1a94e Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 07:28:05 -0700 Subject: Fixed lint issues & cleaned up some documentation. --- wgpu/src/triangle/gradient.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index b6553708..11c072ca 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -9,7 +9,7 @@ use glam::{IVec4, Vec4}; use iced_graphics::gradient::Gradient; use iced_graphics::Transformation; -pub(super) struct GradientPipeline { +pub struct GradientPipeline { pipeline: wgpu::RenderPipeline, pub(super) uniform_buffer: DynamicBuffer, pub(super) storage_buffer: DynamicBuffer, -- cgit From f9a6efcaa03728f43aaa105af8936c1ed4778388 Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 19:41:00 -0700 Subject: Fixed some more imports/documentation. --- wgpu/src/triangle/gradient.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 11c072ca..07551368 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -26,7 +26,7 @@ pub(super) struct GradientUniforms { transform: glam::Mat4, //xy = start, zw = end direction: Vec4, - //x = start, y = end, zw = padding + //x = start stop, y = end stop, zw = padding stop_range: IVec4, } @@ -55,7 +55,7 @@ impl GradientPipeline { ); //Note: with a WASM target storage buffers are not supported. Will need to use UBOs & static - // sized array (eg like the 64-sized array on OpenGL side right now) to make gradients work + // sized array (eg like the 32-sized array on OpenGL side right now) to make gradients work let storage_buffer = DynamicBuffer::storage( device, "iced_wgpu::triangle [GRADIENT] storage", -- cgit From c4565759e4294540f54a81e4d91ddea7a769d3d4 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 18 Oct 2022 15:18:37 -0700 Subject: Cleaned up namespaces re: PR comments. --- wgpu/src/triangle/gradient.rs | 67 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 07551368..92c176af 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -1,28 +1,25 @@ -use crate::buffers::dynamic::DynamicBuffer; +use crate::buffers::dynamic; use crate::settings; -use crate::triangle::{ - default_fragment_target, default_multisample_state, - default_triangle_primitive_state, vertex_buffer_layout, -}; +use crate::triangle; use encase::ShaderType; use glam::{IVec4, Vec4}; use iced_graphics::gradient::Gradient; use iced_graphics::Transformation; -pub struct GradientPipeline { +pub struct Pipeline { pipeline: wgpu::RenderPipeline, - pub(super) uniform_buffer: DynamicBuffer, - pub(super) storage_buffer: DynamicBuffer, + pub(super) uniform_buffer: dynamic::Buffer, + pub(super) storage_buffer: dynamic::Buffer, color_stop_offset: i32, //Need to store these and then write them all at once //or else they will be padded to 256 and cause gaps in the storage buffer - color_stops_pending_write: GradientStorage, + color_stops_pending_write: Storage, bind_group_layout: wgpu::BindGroupLayout, bind_group: wgpu::BindGroup, } #[derive(Debug, ShaderType)] -pub(super) struct GradientUniforms { +pub(super) struct Uniforms { transform: glam::Mat4, //xy = start, zw = end direction: Vec4, @@ -37,33 +34,33 @@ pub(super) struct ColorStop { } #[derive(ShaderType)] -pub(super) struct GradientStorage { +pub(super) struct Storage { #[size(runtime)] pub color_stops: Vec, } -impl GradientPipeline { - /// Creates a new [GradientPipeline] using `triangle_gradient.wgsl` shader. +impl Pipeline { + /// Creates a new [GradientPipeline] using `gradient.wgsl` shader. pub(super) fn new( device: &wgpu::Device, format: wgpu::TextureFormat, antialiasing: Option, ) -> Self { - let uniform_buffer = DynamicBuffer::uniform( + let uniform_buffer = dynamic::Buffer::uniform( device, - "iced_wgpu::triangle [GRADIENT] uniforms", + "iced_wgpu::triangle::gradient uniforms", ); //Note: with a WASM target storage buffers are not supported. Will need to use UBOs & static // sized array (eg like the 32-sized array on OpenGL side right now) to make gradients work - let storage_buffer = DynamicBuffer::storage( + let storage_buffer = dynamic::Buffer::storage( device, - "iced_wgpu::triangle [GRADIENT] storage", + "iced_wgpu::triangle::gradient storage", ); let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: Some("iced_wgpu::triangle [GRADIENT] bind group layout"), + label: Some("iced_wgpu::triangle::gradient bind group layout"), entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, @@ -71,7 +68,7 @@ impl GradientPipeline { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: true, - min_binding_size: Some(GradientUniforms::min_size()), + min_binding_size: Some(Uniforms::min_size()), }, count: None, }, @@ -83,14 +80,14 @@ impl GradientPipeline { read_only: true, }, has_dynamic_offset: false, - min_binding_size: Some(GradientStorage::min_size()), + min_binding_size: Some(Storage::min_size()), }, count: None, }, ], }); - let bind_group = GradientPipeline::bind_group( + let bind_group = Pipeline::bind_group( device, uniform_buffer.raw(), storage_buffer.raw(), @@ -99,7 +96,7 @@ impl GradientPipeline { let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("iced_wgpu::triangle [GRADIENT] pipeline layout"), + label: Some("iced_wgpu::triangle::gradient pipeline layout"), bind_group_layouts: &[&bind_group_layout], push_constant_ranges: &[], }); @@ -107,30 +104,30 @@ impl GradientPipeline { let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some( - "iced_wgpu::triangle [GRADIENT] create shader module", + "iced_wgpu::triangle::gradient create shader module", ), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( - include_str!("../shader/triangle_gradient.wgsl"), + include_str!("../shader/gradient.wgsl"), )), }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("iced_wgpu::triangle [GRADIENT] pipeline"), + label: Some("iced_wgpu::triangle::gradient pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", - buffers: &[vertex_buffer_layout()], + buffers: &[triangle::vertex_buffer_layout()], }, fragment: Some(wgpu::FragmentState { module: &shader, - entry_point: "fs_gradient", - targets: &[default_fragment_target(format)], + entry_point: "fs_main", + targets: &[triangle::fragment_target(format)], }), - primitive: default_triangle_primitive_state(), + primitive: triangle::primitive_state(), depth_stencil: None, - multisample: default_multisample_state(antialiasing), + multisample: triangle::multisample_state(antialiasing), multiview: None, }); @@ -139,7 +136,7 @@ impl GradientPipeline { uniform_buffer, storage_buffer, color_stop_offset: 0, - color_stops_pending_write: GradientStorage { + color_stops_pending_write: Storage { color_stops: vec![], }, bind_group_layout, @@ -155,7 +152,7 @@ impl GradientPipeline { let end_offset = (linear.color_stops.len() as i32) + start_offset - 1; - self.uniform_buffer.push(&GradientUniforms { + self.uniform_buffer.push(&Uniforms { transform: transform.into(), direction: Vec4::new( linear.start.x, @@ -194,7 +191,7 @@ impl GradientPipeline { layout: &wgpu::BindGroupLayout, ) -> wgpu::BindGroup { device.create_bind_group(&wgpu::BindGroupDescriptor { - label: Some("iced_wgpu::triangle [GRADIENT] bind group"), + label: Some("iced_wgpu::triangle::gradient bind group"), layout, entries: &[ wgpu::BindGroupEntry { @@ -203,7 +200,7 @@ impl GradientPipeline { wgpu::BufferBinding { buffer: uniform_buffer, offset: 0, - size: Some(GradientUniforms::min_size()), + size: Some(Uniforms::min_size()), }, ), }, @@ -232,7 +229,7 @@ impl GradientPipeline { if uniforms_resized || storage_resized { //recreate bind groups if any buffers were resized - self.bind_group = GradientPipeline::bind_group( + self.bind_group = Pipeline::bind_group( device, self.uniform_buffer.raw(), self.storage_buffer.raw(), -- cgit From 9a02d60ba51a91049466caa46db73d741520e051 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 04:41:27 +0100 Subject: Convert colors to linear RGB in `gradient` pipelines --- wgpu/src/triangle/gradient.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 92c176af..6698bb4e 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -168,14 +168,13 @@ impl Pipeline { let stops: Vec = linear .color_stops .iter() - .map(|stop| ColorStop { - offset: stop.offset, - color: Vec4::new( - stop.color.r, - stop.color.g, - stop.color.b, - stop.color.a, - ), + .map(|stop| { + let [r, g, b, a] = stop.color.into_linear(); + + ColorStop { + offset: stop.offset, + color: Vec4::new(r, g, b, a), + } }) .collect(); -- cgit From 99cf98971dae22ae65adb2104c5a3eec578649f1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:00:35 +0100 Subject: Rename `buffers` module to `buffer` ... and move `StaticBuffer` to nested `static` module --- wgpu/src/triangle/gradient.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 6698bb4e..03332234 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -1,4 +1,4 @@ -use crate::buffers::dynamic; +use crate::buffer::dynamic; use crate::settings; use crate::triangle; use encase::ShaderType; -- cgit From 93e309f491a8941bafb919e75d660e65071475f4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:06:09 +0100 Subject: Reuse last set pipeline for `triangle` in `iced_wgpu` --- wgpu/src/triangle/gradient.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'wgpu/src/triangle/gradient.rs') diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs index 03332234..b06cbac6 100644 --- a/wgpu/src/triangle/gradient.rs +++ b/wgpu/src/triangle/gradient.rs @@ -245,6 +245,13 @@ impl Pipeline { self.color_stops_pending_write.color_stops.clear(); } + pub fn set_render_pass_pipeline<'a>( + &'a self, + render_pass: &mut wgpu::RenderPass<'a>, + ) { + render_pass.set_pipeline(&self.pipeline); + } + /// Configures the current render pass to draw the gradient at its offset stored in the /// [DynamicBuffer] at [index]. pub fn configure_render_pass<'a>( @@ -252,7 +259,6 @@ impl Pipeline { render_pass: &mut wgpu::RenderPass<'a>, count: usize, ) { - render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group( 0, &self.bind_group, -- cgit