Disable quad::gradient pipeline on Wasm

This commit is contained in:
Héctor Ramón Jiménez 2024-02-20 02:51:02 +01:00
parent 0fe265adb0
commit ff011e5dfd
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -1,4 +1,3 @@
use crate::graphics::color;
use crate::graphics::gradient; use crate::graphics::gradient;
use crate::quad::{self, Quad}; use crate::quad::{self, Quad};
use crate::Buffer; use crate::Buffer;
@ -59,33 +58,43 @@ impl Layer {
#[derive(Debug)] #[derive(Debug)]
pub struct Pipeline { pub struct Pipeline {
#[cfg(not(target_arch = "wasm32"))]
pipeline: wgpu::RenderPipeline, pipeline: wgpu::RenderPipeline,
} }
impl Pipeline { impl Pipeline {
#[allow(unused_variables)]
pub fn new( pub fn new(
device: &wgpu::Device, device: &wgpu::Device,
format: wgpu::TextureFormat, format: wgpu::TextureFormat,
constants_layout: &wgpu::BindGroupLayout, constants_layout: &wgpu::BindGroupLayout,
) -> Self { ) -> Self {
let layout = #[cfg(not(target_arch = "wasm32"))]
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { {
use crate::graphics::color;
let layout = device.create_pipeline_layout(
&wgpu::PipelineLayoutDescriptor {
label: Some("iced_wgpu.quad.gradient.pipeline"), label: Some("iced_wgpu.quad.gradient.pipeline"),
push_constant_ranges: &[], push_constant_ranges: &[],
bind_group_layouts: &[constants_layout], bind_group_layouts: &[constants_layout],
}); },
);
let shader = let shader =
device.create_shader_module(wgpu::ShaderModuleDescriptor { device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu.quad.gradient.shader"), label: Some("iced_wgpu.quad.gradient.shader"),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( source: wgpu::ShaderSource::Wgsl(
std::borrow::Cow::Borrowed(
if color::GAMMA_CORRECTION { if color::GAMMA_CORRECTION {
concat!( concat!(
include_str!("../shader/quad.wgsl"), include_str!("../shader/quad.wgsl"),
"\n", "\n",
include_str!("../shader/vertex.wgsl"), include_str!("../shader/vertex.wgsl"),
"\n", "\n",
include_str!("../shader/quad/gradient.wgsl"), include_str!(
"../shader/quad/gradient.wgsl"
),
"\n", "\n",
include_str!("../shader/color/oklab.wgsl") include_str!("../shader/color/oklab.wgsl")
) )
@ -95,23 +104,29 @@ impl Pipeline {
"\n", "\n",
include_str!("../shader/vertex.wgsl"), include_str!("../shader/vertex.wgsl"),
"\n", "\n",
include_str!("../shader/quad/gradient.wgsl"), include_str!(
"../shader/quad/gradient.wgsl"
),
"\n", "\n",
include_str!("../shader/color/linear_rgb.wgsl") include_str!(
"../shader/color/linear_rgb.wgsl"
)
) )
}, },
)), ),
),
}); });
let pipeline = let pipeline = device.create_render_pipeline(
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { &wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu.quad.gradient.pipeline"), label: Some("iced_wgpu.quad.gradient.pipeline"),
layout: Some(&layout), layout: Some(&layout),
vertex: wgpu::VertexState { vertex: wgpu::VertexState {
module: &shader, module: &shader,
entry_point: "gradient_vs_main", entry_point: "gradient_vs_main",
buffers: &[wgpu::VertexBufferLayout { buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Gradient>() as u64, array_stride: std::mem::size_of::<Gradient>()
as u64,
step_mode: wgpu::VertexStepMode::Instance, step_mode: wgpu::VertexStepMode::Instance,
attributes: &wgpu::vertex_attr_array!( attributes: &wgpu::vertex_attr_array!(
// Colors 1-2 // Colors 1-2
@ -154,11 +169,17 @@ impl Pipeline {
alpha_to_coverage_enabled: false, 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>( pub fn render<'a>(
&'a self, &'a self,
render_pass: &mut wgpu::RenderPass<'a>, render_pass: &mut wgpu::RenderPass<'a>,
@ -169,6 +190,8 @@ impl Pipeline {
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
let _ = tracing::info_span!("Wgpu::Quad::Gradient", "DRAW").entered(); let _ = tracing::info_span!("Wgpu::Quad::Gradient", "DRAW").entered();
#[cfg(not(target_arch = "wasm32"))]
{
render_pass.set_pipeline(&self.pipeline); render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, constants, &[]); render_pass.set_bind_group(0, constants, &[]);
render_pass.set_vertex_buffer(0, layer.instances.slice(..)); render_pass.set_vertex_buffer(0, layer.instances.slice(..));
@ -176,3 +199,4 @@ impl Pipeline {
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);
} }
} }
}