diff options
author | 2024-02-20 02:51:02 +0100 | |
---|---|---|
committer | 2024-02-20 02:51:02 +0100 | |
commit | ff011e5dfd54bfa1fa566e511977d6a180f6262a (patch) | |
tree | 4b256c36534d10d1875d14daee0068f5a1457925 /wgpu | |
parent | 0fe265adb0a97e64b0c83cbb19c7d0179bb60975 (diff) | |
download | iced-ff011e5dfd54bfa1fa566e511977d6a180f6262a.tar.gz iced-ff011e5dfd54bfa1fa566e511977d6a180f6262a.tar.bz2 iced-ff011e5dfd54bfa1fa566e511977d6a180f6262a.zip |
Disable `quad::gradient` pipeline on Wasm
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/quad/gradient.rs | 206 |
1 files changed, 115 insertions, 91 deletions
diff --git a/wgpu/src/quad/gradient.rs b/wgpu/src/quad/gradient.rs index 60b170cc..560fcad2 100644 --- a/wgpu/src/quad/gradient.rs +++ b/wgpu/src/quad/gradient.rs @@ -1,4 +1,3 @@ -use crate::graphics::color; use crate::graphics::gradient; use crate::quad::{self, Quad}; use crate::Buffer; @@ -59,106 +58,128 @@ impl Layer { #[derive(Debug)] pub struct Pipeline { + #[cfg(not(target_arch = "wasm32"))] pipeline: wgpu::RenderPipeline, } impl Pipeline { + #[allow(unused_variables)] pub fn new( device: &wgpu::Device, format: wgpu::TextureFormat, constants_layout: &wgpu::BindGroupLayout, ) -> Self { - let layout = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("iced_wgpu.quad.gradient.pipeline"), - push_constant_ranges: &[], - bind_group_layouts: &[constants_layout], - }); - - let shader = - device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: Some("iced_wgpu.quad.gradient.shader"), - source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( - if color::GAMMA_CORRECTION { - 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") - ) - } else { - 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") - ) - }, - )), - }); - - let pipeline = - device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("iced_wgpu.quad.gradient.pipeline"), - layout: Some(&layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: "gradient_vs_main", - buffers: &[wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::<Gradient>() as u64, - step_mode: wgpu::VertexStepMode::Instance, - attributes: &wgpu::vertex_attr_array!( - // Colors 1-2 - 0 => Uint32x4, - // Colors 3-4 - 1 => Uint32x4, - // Colors 5-6 - 2 => Uint32x4, - // Colors 7-8 - 3 => Uint32x4, - // Offsets 1-8 - 4 => Uint32x4, - // Direction - 5 => Float32x4, - // Position & Scale - 6 => Float32x4, - // Border color - 7 => Float32x4, - // Border radius - 8 => Float32x4, - // Border width - 9 => Float32 - ), - }], - }, - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: "gradient_fs_main", - targets: &quad::color_target_state(format), - }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - front_face: wgpu::FrontFace::Cw, - ..Default::default() + #[cfg(not(target_arch = "wasm32"))] + { + use crate::graphics::color; + + let layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor { + label: Some("iced_wgpu.quad.gradient.pipeline"), + push_constant_ranges: &[], + bind_group_layouts: &[constants_layout], }, - depth_stencil: None, - multisample: wgpu::MultisampleState { - count: 1, - mask: !0, - alpha_to_coverage_enabled: false, + ); + + let shader = + device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("iced_wgpu.quad.gradient.shader"), + source: wgpu::ShaderSource::Wgsl( + std::borrow::Cow::Borrowed( + if color::GAMMA_CORRECTION { + 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") + ) + } else { + 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" + ) + ) + }, + ), + ), + }); + + let pipeline = device.create_render_pipeline( + &wgpu::RenderPipelineDescriptor { + label: Some("iced_wgpu.quad.gradient.pipeline"), + layout: Some(&layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "gradient_vs_main", + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::<Gradient>() + as u64, + step_mode: wgpu::VertexStepMode::Instance, + attributes: &wgpu::vertex_attr_array!( + // Colors 1-2 + 0 => Uint32x4, + // Colors 3-4 + 1 => Uint32x4, + // Colors 5-6 + 2 => Uint32x4, + // Colors 7-8 + 3 => Uint32x4, + // Offsets 1-8 + 4 => Uint32x4, + // Direction + 5 => Float32x4, + // Position & Scale + 6 => Float32x4, + // Border color + 7 => Float32x4, + // Border radius + 8 => Float32x4, + // Border width + 9 => Float32 + ), + }], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "gradient_fs_main", + targets: &quad::color_target_state(format), + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, + multiview: None, }, - multiview: None, - }); + ); - Self { pipeline } + Self { pipeline } + } + + #[cfg(target_arch = "wasm32")] + Self {} } + #[allow(unused_variables)] pub fn render<'a>( &'a self, render_pass: &mut wgpu::RenderPass<'a>, @@ -169,10 +190,13 @@ impl Pipeline { #[cfg(feature = "tracing")] let _ = tracing::info_span!("Wgpu::Quad::Gradient", "DRAW").entered(); - render_pass.set_pipeline(&self.pipeline); - render_pass.set_bind_group(0, constants, &[]); - render_pass.set_vertex_buffer(0, layer.instances.slice(..)); + #[cfg(not(target_arch = "wasm32"))] + { + render_pass.set_pipeline(&self.pipeline); + render_pass.set_bind_group(0, constants, &[]); + render_pass.set_vertex_buffer(0, layer.instances.slice(..)); - render_pass.draw(0..6, range.start as u32..range.end as u32); + render_pass.draw(0..6, range.start as u32..range.end as u32); + } } } |