1use std::{marker::PhantomData, sync::Arc};
2
3use crate::{
4 GpuSamplerSet,
5 mesh::{AttributeDescriptor, MeshBuffer},
6 object::Object,
7 proxies::PipelineProxy,
8};
9
10pub struct ComputeDescriptor {}
12
13impl AttributeDescriptor for ComputeDescriptor {
14 fn get_attributes() -> &'static [crate::mesh::Attribute] {
15 &[]
16 }
17}
18
19pub struct Pipeline<V: AttributeDescriptor> {
21 pub(crate) inner: Arc<dyn PipelineProxy>,
22 _ty: PhantomData<V>,
23}
24
25impl<V: AttributeDescriptor> Pipeline<V> {
26 pub(crate) fn new(proxy: Arc<dyn PipelineProxy>) -> Self {
27 Self {
28 inner: proxy,
29 _ty: PhantomData,
30 }
31 }
32
33 pub fn create_object_with_mesh<I>(&self, index: u32, mesh: &MeshBuffer<V, I>) -> Object {
35 Object {
36 pipeline: self.inner.clone(),
37 mesh_buffer: Some(mesh.inner.clone()),
38 sampler: None,
39 groups: None,
40 index,
41 array: 1,
42 }
43 }
44
45 pub fn create_object_with_mesh_sampled<I>(
47 &self,
48 index: u32,
49 mesh: &MeshBuffer<V, I>,
50 sampler: Arc<GpuSamplerSet>,
51 ) -> Object {
52 Object {
53 pipeline: self.inner.clone(),
54 mesh_buffer: Some(mesh.inner.clone()),
55 sampler: Some(sampler),
56 groups: None,
57 index,
58 array: 1,
59 }
60 }
61
62 pub fn create_object_with_mesh_array<I>(
64 &self,
65 index: u32,
66 mesh: &MeshBuffer<V, I>,
67 array: u32,
68 ) -> Object {
69 Object {
70 pipeline: self.inner.clone(),
71 mesh_buffer: Some(mesh.inner.clone()),
72 sampler: None,
73 groups: None,
74 index,
75 array,
76 }
77 }
78
79 pub fn create_object_with_mesh_sampled_array<I>(
81 &self,
82 index: u32,
83 mesh: &MeshBuffer<V, I>,
84 sampler: Arc<GpuSamplerSet>,
85 array: u32,
86 ) -> Object {
87 Object {
88 pipeline: self.inner.clone(),
89 mesh_buffer: Some(mesh.inner.clone()),
90 sampler: Some(sampler),
91 groups: None,
92 index,
93 array,
94 }
95 }
96}
97
98impl Pipeline<ComputeDescriptor> {
99 pub fn create_object_compute(&self, groups: [u32; 3]) -> Object {
101 Object {
102 pipeline: self.inner.clone(),
103 mesh_buffer: None,
104 sampler: None,
105 groups: Some(groups),
106 index: 0,
107 array: 0,
108 }
109 }
110
111 pub fn create_object_compute_with_samplers(
113 &self,
114 groups: [u32; 3],
115 sampler: Arc<GpuSamplerSet>,
116 ) -> Object {
117 Object {
118 pipeline: self.inner.clone(),
119 mesh_buffer: None,
120 sampler: Some(sampler),
121 groups: Some(groups),
122 index: 0,
123 array: 0,
124 }
125 }
126}