Skip to main content

bevy_render/render_resource/
pipeline.rs

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