bevy_render/render_resource/
pipeline.rs1use super::ShaderDefVal;
2use crate::mesh::VertexBufferLayout;
3use crate::renderer::WgpuWrapper;
4use crate::{
5 define_atomic_id,
6 render_resource::{BindGroupLayout, Shader},
7};
8use alloc::borrow::Cow;
9use alloc::sync::Arc;
10use bevy_asset::Handle;
11use core::ops::Deref;
12use wgpu::{
13 ColorTargetState, DepthStencilState, MultisampleState, PrimitiveState, PushConstantRange,
14};
15
16define_atomic_id!(RenderPipelineId);
17
18#[derive(Clone, Debug)]
23pub struct RenderPipeline {
24 id: RenderPipelineId,
25 value: Arc<WgpuWrapper<wgpu::RenderPipeline>>,
26}
27
28impl RenderPipeline {
29 #[inline]
30 pub fn id(&self) -> RenderPipelineId {
31 self.id
32 }
33}
34
35impl From<wgpu::RenderPipeline> for RenderPipeline {
36 fn from(value: wgpu::RenderPipeline) -> Self {
37 RenderPipeline {
38 id: RenderPipelineId::new(),
39 value: Arc::new(WgpuWrapper::new(value)),
40 }
41 }
42}
43
44impl Deref for RenderPipeline {
45 type Target = wgpu::RenderPipeline;
46
47 #[inline]
48 fn deref(&self) -> &Self::Target {
49 &self.value
50 }
51}
52
53define_atomic_id!(ComputePipelineId);
54
55#[derive(Clone, Debug)]
60pub struct ComputePipeline {
61 id: ComputePipelineId,
62 value: Arc<WgpuWrapper<wgpu::ComputePipeline>>,
63}
64
65impl ComputePipeline {
66 #[inline]
68 pub fn id(&self) -> ComputePipelineId {
69 self.id
70 }
71}
72
73impl From<wgpu::ComputePipeline> for ComputePipeline {
74 fn from(value: wgpu::ComputePipeline) -> Self {
75 ComputePipeline {
76 id: ComputePipelineId::new(),
77 value: Arc::new(WgpuWrapper::new(value)),
78 }
79 }
80}
81
82impl Deref for ComputePipeline {
83 type Target = wgpu::ComputePipeline;
84
85 #[inline]
86 fn deref(&self) -> &Self::Target {
87 &self.value
88 }
89}
90
91#[derive(Clone, Debug, PartialEq)]
93pub struct RenderPipelineDescriptor {
94 pub label: Option<Cow<'static, str>>,
96 pub layout: Vec<BindGroupLayout>,
98 pub push_constant_ranges: Vec<PushConstantRange>,
101 pub vertex: VertexState,
103 pub primitive: PrimitiveState,
105 pub depth_stencil: Option<DepthStencilState>,
107 pub multisample: MultisampleState,
109 pub fragment: Option<FragmentState>,
111 pub zero_initialize_workgroup_memory: bool,
114}
115
116#[derive(Clone, Debug, Eq, PartialEq)]
117pub struct VertexState {
118 pub shader: Handle<Shader>,
120 pub shader_defs: Vec<ShaderDefVal>,
121 pub entry_point: Cow<'static, str>,
124 pub buffers: Vec<VertexBufferLayout>,
126}
127
128#[derive(Clone, Debug, PartialEq, Eq)]
130pub struct FragmentState {
131 pub shader: Handle<Shader>,
133 pub shader_defs: Vec<ShaderDefVal>,
134 pub entry_point: Cow<'static, str>,
137 pub targets: Vec<Option<ColorTargetState>>,
139}
140
141#[derive(Clone, Debug)]
143pub struct ComputePipelineDescriptor {
144 pub label: Option<Cow<'static, str>>,
145 pub layout: Vec<BindGroupLayout>,
146 pub push_constant_ranges: Vec<PushConstantRange>,
147 pub shader: Handle<Shader>,
149 pub shader_defs: Vec<ShaderDefVal>,
150 pub entry_point: Cow<'static, str>,
153 pub zero_initialize_workgroup_memory: bool,
156}