Skip to main content

bevy_render/render_resource/
pipeline.rs

1use crate::renderer::WgpuWrapper;
2use bevy_utils::define_atomic_id;
3use core::ops::Deref;
4
5define_atomic_id!(RenderPipelineId);
6
7/// A [`RenderPipeline`] represents a graphics pipeline and its stages (shaders), bindings and vertex buffers.
8///
9/// May be converted from and dereferences to a wgpu [`RenderPipeline`](wgpu::RenderPipeline).
10/// Can be created via [`RenderDevice::create_render_pipeline`](crate::renderer::RenderDevice::create_render_pipeline).
11#[derive(Clone, Debug)]
12pub struct RenderPipeline {
13    id: RenderPipelineId,
14    value: WgpuWrapper<wgpu::RenderPipeline>,
15}
16
17impl RenderPipeline {
18    #[inline]
19    pub fn id(&self) -> RenderPipelineId {
20        self.id
21    }
22}
23
24impl From<wgpu::RenderPipeline> for RenderPipeline {
25    fn from(value: wgpu::RenderPipeline) -> Self {
26        RenderPipeline {
27            id: RenderPipelineId::new(),
28            value: WgpuWrapper::new(value),
29        }
30    }
31}
32
33impl Deref for RenderPipeline {
34    type Target = wgpu::RenderPipeline;
35
36    #[inline]
37    fn deref(&self) -> &Self::Target {
38        &self.value
39    }
40}
41
42define_atomic_id!(ComputePipelineId);
43
44/// A [`ComputePipeline`] represents a compute pipeline and its single shader stage.
45///
46/// May be converted from and dereferences to a wgpu [`ComputePipeline`](wgpu::ComputePipeline).
47/// Can be created via [`RenderDevice::create_compute_pipeline`](crate::renderer::RenderDevice::create_compute_pipeline).
48#[derive(Clone, Debug)]
49pub struct ComputePipeline {
50    id: ComputePipelineId,
51    value: WgpuWrapper<wgpu::ComputePipeline>,
52}
53
54impl ComputePipeline {
55    /// Returns the [`ComputePipelineId`].
56    #[inline]
57    pub fn id(&self) -> ComputePipelineId {
58        self.id
59    }
60}
61
62impl From<wgpu::ComputePipeline> for ComputePipeline {
63    fn from(value: wgpu::ComputePipeline) -> Self {
64        ComputePipeline {
65            id: ComputePipelineId::new(),
66            value: WgpuWrapper::new(value),
67        }
68    }
69}
70
71impl Deref for ComputePipeline {
72    type Target = wgpu::ComputePipeline;
73
74    #[inline]
75    fn deref(&self) -> &Self::Target {
76        &self.value
77    }
78}