2021-03-20 14:30:21 +00:00
|
|
|
use crate::{Error, MaskState, Vertex};
|
2020-10-14 18:25:55 +00:00
|
|
|
use enum_map::{enum_map, EnumMap};
|
2020-04-28 14:10:45 +00:00
|
|
|
use wgpu::vertex_attr_array;
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ShapePipeline {
|
2020-10-14 18:25:55 +00:00
|
|
|
pub mask_pipelines: EnumMap<MaskState, wgpu::RenderPipeline>,
|
2020-04-28 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Pipelines {
|
2020-10-17 19:05:16 +00:00
|
|
|
pub color_pipelines: ShapePipeline,
|
2020-10-17 21:39:24 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
pub bitmap_pipelines: ShapePipeline,
|
|
|
|
pub bitmap_layout: wgpu::BindGroupLayout,
|
2020-10-17 21:39:24 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
pub gradient_pipelines: ShapePipeline,
|
|
|
|
pub gradient_layout: wgpu::BindGroupLayout,
|
2020-04-28 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 20:48:17 +00:00
|
|
|
impl ShapePipeline {
|
2020-10-14 18:25:55 +00:00
|
|
|
pub fn pipeline_for(&self, mask_state: MaskState) -> &wgpu::RenderPipeline {
|
|
|
|
&self.mask_pipelines[mask_state]
|
2020-04-28 20:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
impl Pipelines {
|
2020-10-15 22:55:19 +00:00
|
|
|
pub fn new(
|
|
|
|
device: &wgpu::Device,
|
2021-09-08 01:55:26 +00:00
|
|
|
surface_format: wgpu::TextureFormat,
|
2020-10-15 22:55:19 +00:00
|
|
|
msaa_sample_count: u32,
|
|
|
|
sampler_layout: &wgpu::BindGroupLayout,
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout: &wgpu::BindGroupLayout,
|
2020-10-15 22:55:19 +00:00
|
|
|
) -> Result<Self, Error> {
|
2021-10-20 21:44:06 +00:00
|
|
|
// If the surface is sRGB, the GPU will automatically convert colors from linear to sRGB,
|
|
|
|
// so our shader should output linear colors.
|
|
|
|
let output_srgb = !surface_format.describe().srgb;
|
|
|
|
let color_shader = create_shader(
|
|
|
|
device,
|
|
|
|
"color",
|
|
|
|
include_str!("../shaders/color.wgsl"),
|
|
|
|
output_srgb,
|
|
|
|
);
|
|
|
|
let bitmap_shader = create_shader(
|
|
|
|
device,
|
|
|
|
"bitmap",
|
|
|
|
include_str!("../shaders/bitmap.wgsl"),
|
|
|
|
output_srgb,
|
|
|
|
);
|
|
|
|
let gradient_shader = create_shader(
|
|
|
|
device,
|
|
|
|
"gradient",
|
|
|
|
include_str!("../shaders/gradient.wgsl"),
|
|
|
|
output_srgb,
|
|
|
|
);
|
2020-08-27 10:32:41 +00:00
|
|
|
|
2021-02-03 19:58:53 +00:00
|
|
|
let vertex_buffers_description = [wgpu::VertexBufferLayout {
|
2021-03-20 14:30:21 +00:00
|
|
|
array_stride: std::mem::size_of::<Vertex>() as u64,
|
2021-09-08 07:20:11 +00:00
|
|
|
step_mode: wgpu::VertexStepMode::Vertex,
|
2020-08-27 10:32:41 +00:00
|
|
|
attributes: &vertex_attr_array![
|
2021-04-16 20:55:31 +00:00
|
|
|
0 => Float32x2,
|
|
|
|
1 => Float32x4,
|
2020-08-27 10:32:41 +00:00
|
|
|
],
|
|
|
|
}];
|
2020-04-28 14:34:07 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
let color_pipelines = create_color_pipelines(
|
2021-06-05 10:53:23 +00:00
|
|
|
device,
|
2021-09-08 01:55:26 +00:00
|
|
|
surface_format,
|
2021-10-20 21:44:06 +00:00
|
|
|
&color_shader,
|
2020-10-17 19:05:16 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
globals_layout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout,
|
2020-10-17 19:05:16 +00:00
|
|
|
);
|
|
|
|
|
2020-10-17 21:39:24 +00:00
|
|
|
let bitmap_bind_layout_label = create_debug_label!("Bitmap shape bind group layout");
|
2020-10-17 19:05:16 +00:00
|
|
|
let bitmap_bind_layout =
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
entries: &[
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 0,
|
2021-09-08 07:20:11 +00:00
|
|
|
visibility: wgpu::ShaderStages::VERTEX,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Uniform,
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 1,
|
2021-09-08 07:20:11 +00:00
|
|
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Texture {
|
2020-10-17 19:05:16 +00:00
|
|
|
multisampled: false,
|
2020-12-04 18:47:20 +00:00
|
|
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
|
|
view_dimension: wgpu::TextureViewDimension::D2,
|
2020-10-17 19:05:16 +00:00
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
label: bitmap_bind_layout_label.as_deref(),
|
|
|
|
});
|
|
|
|
|
|
|
|
let bitmap_pipelines = create_bitmap_pipeline(
|
2021-06-05 10:53:23 +00:00
|
|
|
device,
|
2021-09-08 01:55:26 +00:00
|
|
|
surface_format,
|
2021-10-20 21:44:06 +00:00
|
|
|
&bitmap_shader,
|
2020-10-17 19:05:16 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
sampler_layout,
|
|
|
|
globals_layout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout,
|
2020-10-17 19:05:16 +00:00
|
|
|
&bitmap_bind_layout,
|
|
|
|
);
|
|
|
|
|
|
|
|
let gradient_bind_layout_label = create_debug_label!("Gradient shape bind group");
|
|
|
|
let gradient_bind_layout =
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
entries: &[
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 0,
|
2021-09-08 07:20:11 +00:00
|
|
|
visibility: wgpu::ShaderStages::VERTEX,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Uniform,
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 1,
|
2021-09-08 07:20:11 +00:00
|
|
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Storage { read_only: true },
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
label: gradient_bind_layout_label.as_deref(),
|
|
|
|
});
|
|
|
|
|
|
|
|
let gradient_pipelines = create_gradient_pipeline(
|
2021-06-05 10:53:23 +00:00
|
|
|
device,
|
2021-09-08 01:55:26 +00:00
|
|
|
surface_format,
|
2021-10-20 21:44:06 +00:00
|
|
|
&gradient_shader,
|
2020-10-17 19:05:16 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
globals_layout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout,
|
2020-10-17 19:05:16 +00:00
|
|
|
&gradient_bind_layout,
|
|
|
|
);
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
Ok(Self {
|
2020-10-17 19:05:16 +00:00
|
|
|
color_pipelines,
|
|
|
|
bitmap_pipelines,
|
|
|
|
bitmap_layout: bitmap_bind_layout,
|
|
|
|
gradient_pipelines,
|
|
|
|
gradient_layout: gradient_bind_layout,
|
2020-04-28 14:34:07 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 21:44:06 +00:00
|
|
|
/// Builds a `wgpu::ShaderModule` the given WGSL source in `src`.
|
|
|
|
///
|
|
|
|
/// The source is prepended with common code in `common.wgsl` and sRGB/linear conversions in
|
|
|
|
/// `output_srgb.wgsl`/`output_linear.wgsl`, simulating a `#include` preprocessor. We could
|
|
|
|
/// possibly does this as an offline build step instead.
|
|
|
|
fn create_shader(
|
|
|
|
device: &wgpu::Device,
|
|
|
|
name: &'static str,
|
|
|
|
src: &'static str,
|
|
|
|
output_srgb: bool,
|
|
|
|
) -> wgpu::ShaderModule {
|
|
|
|
const COMMON_SRC: &str = include_str!("../shaders/common.wgsl");
|
|
|
|
const OUTPUT_LINEAR_SRC: &str = include_str!("../shaders/output_linear.wgsl");
|
|
|
|
const OUTPUT_SRGB_SRC: &str = include_str!("../shaders/output_srgb.wgsl");
|
|
|
|
|
|
|
|
let src = if output_srgb {
|
|
|
|
[COMMON_SRC, OUTPUT_SRGB_SRC, src].concat()
|
|
|
|
} else {
|
|
|
|
[COMMON_SRC, OUTPUT_LINEAR_SRC, src].concat()
|
|
|
|
};
|
|
|
|
let label = create_debug_label!(
|
|
|
|
"Shader {} ({})",
|
|
|
|
name,
|
|
|
|
if output_srgb { "sRGB" } else { "linear" }
|
|
|
|
);
|
|
|
|
let desc = wgpu::ShaderModuleDescriptor {
|
|
|
|
label: label.as_deref(),
|
|
|
|
source: wgpu::ShaderSource::Wgsl(src.into()),
|
|
|
|
};
|
|
|
|
|
|
|
|
device.create_shader_module(&desc)
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:40:56 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_pipeline_descriptor<'a>(
|
2020-08-27 10:40:56 +00:00
|
|
|
label: Option<&'a str>,
|
2020-04-28 14:10:45 +00:00
|
|
|
vertex_shader: &'a wgpu::ShaderModule,
|
|
|
|
fragment_shader: &'a wgpu::ShaderModule,
|
|
|
|
pipeline_layout: &'a wgpu::PipelineLayout,
|
2021-02-03 19:58:53 +00:00
|
|
|
depth_stencil_state: Option<wgpu::DepthStencilState>,
|
|
|
|
color_target_state: &'a [wgpu::ColorTargetState],
|
|
|
|
vertex_buffer_layout: &'a [wgpu::VertexBufferLayout<'a>],
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2020-04-28 14:10:45 +00:00
|
|
|
) -> wgpu::RenderPipelineDescriptor<'a> {
|
|
|
|
wgpu::RenderPipelineDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label,
|
2021-06-05 10:53:23 +00:00
|
|
|
layout: Some(pipeline_layout),
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex: wgpu::VertexState {
|
2021-06-05 10:53:23 +00:00
|
|
|
module: vertex_shader,
|
2021-10-26 04:36:19 +00:00
|
|
|
entry_point: "main_vertex",
|
2021-02-03 19:58:53 +00:00
|
|
|
buffers: vertex_buffer_layout,
|
2020-04-28 14:10:45 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
fragment: Some(wgpu::FragmentState {
|
2021-06-05 10:53:23 +00:00
|
|
|
module: fragment_shader,
|
2021-10-26 04:36:19 +00:00
|
|
|
entry_point: "main_fragment",
|
2021-02-03 19:58:53 +00:00
|
|
|
targets: color_target_state,
|
2020-04-28 14:10:45 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
primitive: wgpu::PrimitiveState {
|
|
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
2021-04-16 20:55:31 +00:00
|
|
|
strip_index_format: None,
|
2020-04-28 14:10:45 +00:00
|
|
|
front_face: wgpu::FrontFace::Ccw,
|
2021-04-16 20:55:31 +00:00
|
|
|
cull_mode: None,
|
2021-02-03 19:58:53 +00:00
|
|
|
polygon_mode: wgpu::PolygonMode::default(),
|
2022-01-19 18:21:28 +00:00
|
|
|
unclipped_depth: false,
|
2021-04-16 20:55:31 +00:00
|
|
|
conservative: false,
|
2021-02-03 19:58:53 +00:00
|
|
|
},
|
|
|
|
depth_stencil: depth_stencil_state,
|
|
|
|
multisample: wgpu::MultisampleState {
|
|
|
|
count: msaa_sample_count,
|
|
|
|
mask: !0,
|
|
|
|
alpha_to_coverage_enabled: false,
|
2020-04-28 14:10:45 +00:00
|
|
|
},
|
2022-01-19 18:21:28 +00:00
|
|
|
multiview: None,
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 01:55:26 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 20:48:17 +00:00
|
|
|
fn create_color_pipelines(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
2021-09-08 01:55:26 +00:00
|
|
|
format: wgpu::TextureFormat,
|
2021-10-20 21:44:06 +00:00
|
|
|
shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_description: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Color shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2021-09-07 20:25:56 +00:00
|
|
|
bind_group_layouts: &[globals_layout, dynamic_uniforms_layout],
|
|
|
|
push_constant_ranges: &[],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline no mask").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
|
|
|
|
}
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline draw mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline draw masked content").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline clear mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_bitmap_pipeline(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
2021-09-08 01:55:26 +00:00
|
|
|
format: wgpu::TextureFormat,
|
2021-10-20 21:44:06 +00:00
|
|
|
shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-15 22:55:19 +00:00
|
|
|
sampler_layout: &wgpu::BindGroupLayout,
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout: &wgpu::BindGroupLayout,
|
2020-10-17 19:05:16 +00:00
|
|
|
bitmap_bind_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Bitmap shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2021-09-07 20:25:56 +00:00
|
|
|
bind_group_layouts: &[
|
|
|
|
globals_layout,
|
|
|
|
dynamic_uniforms_layout,
|
|
|
|
bitmap_bind_layout,
|
|
|
|
sampler_layout,
|
2020-10-17 21:39:24 +00:00
|
|
|
],
|
2021-09-07 20:25:56 +00:00
|
|
|
push_constant_ranges: &[],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline no mask").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
blend: Some(wgpu::BlendState {
|
|
|
|
color: wgpu::BlendComponent {
|
|
|
|
src_factor: wgpu::BlendFactor::One,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
alpha: wgpu::BlendComponent {
|
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline draw mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline draw masked content").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Equal,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
blend: Some(wgpu::BlendState {
|
|
|
|
color: wgpu::BlendComponent {
|
|
|
|
src_factor: wgpu::BlendFactor::One,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
alpha: wgpu::BlendComponent {
|
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline clear mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:39:24 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_gradient_pipeline(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
2021-09-08 01:55:26 +00:00
|
|
|
format: wgpu::TextureFormat,
|
2021-10-20 21:44:06 +00:00
|
|
|
shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2021-09-07 20:25:56 +00:00
|
|
|
dynamic_uniforms_layout: &wgpu::BindGroupLayout,
|
2020-10-17 19:05:16 +00:00
|
|
|
gradient_bind_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Gradient shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2021-09-07 20:25:56 +00:00
|
|
|
bind_group_layouts: &[
|
|
|
|
globals_layout,
|
|
|
|
dynamic_uniforms_layout,
|
|
|
|
gradient_bind_layout,
|
2020-12-26 00:43:03 +00:00
|
|
|
],
|
2021-09-07 20:25:56 +00:00
|
|
|
push_constant_ranges: &[],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline no mask").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline draw mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
|
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline draw masked content").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Equal,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline clear mask stencil").as_deref(),
|
2021-10-20 21:44:06 +00:00
|
|
|
shader,
|
|
|
|
shader,
|
2020-10-14 18:25:55 +00:00
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2021-09-08 01:55:26 +00:00
|
|
|
format,
|
2021-04-16 20:55:31 +00:00
|
|
|
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::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
}),
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
2020-10-14 18:25:55 +00:00
|
|
|
|
2021-09-08 07:20:11 +00:00
|
|
|
fn mask_render_state(state: MaskState) -> (wgpu::StencilState, wgpu::ColorWrites) {
|
2020-10-14 18:25:55 +00:00
|
|
|
let (stencil_state, color_write) = match state {
|
|
|
|
MaskState::NoMask => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Always,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::Keep,
|
|
|
|
},
|
2021-09-08 07:20:11 +00:00
|
|
|
wgpu::ColorWrites::ALL,
|
2020-10-14 18:25:55 +00:00
|
|
|
),
|
|
|
|
MaskState::DrawMaskStencil => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::IncrementClamp,
|
|
|
|
},
|
2021-09-08 07:20:11 +00:00
|
|
|
wgpu::ColorWrites::empty(),
|
2020-10-14 18:25:55 +00:00
|
|
|
),
|
|
|
|
MaskState::DrawMaskedContent => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::Keep,
|
|
|
|
},
|
2021-09-08 07:20:11 +00:00
|
|
|
wgpu::ColorWrites::ALL,
|
2020-10-14 18:25:55 +00:00
|
|
|
),
|
|
|
|
MaskState::ClearMaskStencil => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::DecrementClamp,
|
|
|
|
},
|
2021-09-08 07:20:11 +00:00
|
|
|
wgpu::ColorWrites::empty(),
|
2020-10-14 18:25:55 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
(
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilState {
|
2021-04-16 20:55:31 +00:00
|
|
|
front: stencil_state,
|
2020-10-14 18:25:55 +00:00
|
|
|
back: stencil_state,
|
|
|
|
read_mask: 0xff,
|
|
|
|
write_mask: 0xff,
|
|
|
|
},
|
|
|
|
color_write,
|
|
|
|
)
|
|
|
|
}
|