wde_renderer/passes/
pipeline_types.rs

1use bevy::{asset::Handle, ecs::prelude::*};
2use wde_wgpu::{
3    bind_group::BindGroupLayout,
4    pipelines::BlendState,
5    render_pipeline::{DepthDescriptor, Face, RenderTopology, ShaderStages},
6    texture::TextureFormat
7};
8
9use crate::assets::Shader;
10
11/// Describes a push constant that will be available to a shader.
12/// Note: the size of the push constant must be a multiple of 4 and must not exceed 128 bytes.
13#[derive(Clone)]
14pub struct PushConstantDescriptor {
15    /// Shader stages that can read the push constant.
16    pub stages: ShaderStages,
17    /// Byte offset from the start of the push constant buffer.
18    pub offset: u32,
19    /// Size in bytes (multiple of 4, up to 128).
20    pub size: u32
21}
22
23/// Describes a render pipeline, including its shaders, resources and states.
24#[derive(Resource, Clone)]
25pub struct RenderPipelineDescriptor {
26    pub label: &'static str,
27    pub vert: Option<Handle<Shader>>,
28    pub frag: Option<Handle<Shader>>,
29
30    /// Depth/stencil state for the pipeline.
31    pub depth: DepthDescriptor,
32    /// Formats of the render targets this pipeline will render to. If `None`, the pipeline will render to the swapchain format.
33    pub render_targets: Option<Vec<TextureFormat>>,
34
35    /// Bind group layouts describing all resource bindings.
36    pub bind_group_layouts: Vec<Option<BindGroupLayout>>,
37    /// Push constant ranges exposed to shaders.
38    pub push_constants: Vec<PushConstantDescriptor>,
39
40    /// Primitive topology (default: TriangleList).
41    pub topology: RenderTopology,
42    /// Face culling mode (default: Back). `None` disables culling.
43    pub cull_mode: Option<Face>,
44    /// Blend state for the fragment shader (default: None, i.e. no blending).
45    pub fragment_blend: Option<BlendState>,
46    /// The sample count for multisampling (default: 1).
47    pub sample_count: u32,
48    /// Whether the pipeline should expect a vertex buffer. Useful for pipelines that render fullscreen quads without vertex buffers (default: true).
49    pub vertex_buffer: bool
50}
51impl Default for RenderPipelineDescriptor {
52    fn default() -> Self {
53        Self {
54            label: "Unknown Render Pipeline",
55            vert: None,
56            frag: None,
57            depth: DepthDescriptor::default(),
58            render_targets: None,
59            bind_group_layouts: vec![],
60            push_constants: vec![],
61            topology: RenderTopology::TriangleList,
62            cull_mode: Some(Face::Back),
63            fragment_blend: Some(BlendState::REPLACE),
64            sample_count: 1,
65            vertex_buffer: true
66        }
67    }
68}
69
70/// Describes a compute pipeline, including its shader and resources.
71#[derive(Resource, Clone)]
72pub struct ComputePipelineDescriptor {
73    pub label: &'static str,
74    pub comp: Option<Handle<Shader>>,
75
76    /// Bind group layouts describing all resource bindings.
77    pub bind_group_layouts: Vec<Option<BindGroupLayout>>,
78    /// Push constant ranges exposed to the compute shader.
79    pub push_constants: Vec<PushConstantDescriptor>
80}
81impl Default for ComputePipelineDescriptor {
82    fn default() -> Self {
83        Self {
84            label: "Unknown Compute Pipeline",
85            comp: None,
86            bind_group_layouts: vec![],
87            push_constants: vec![]
88        }
89    }
90}