1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use std::sync::Arc;
use std::marker::PhantomData;
use vks;
use ::{VdResult, Device, DescriptorSetLayoutHandle, Handle,
PipelineLayoutCreateInfo, PushConstantRange};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct PipelineLayoutHandle(pub(crate) vks::VkPipelineLayout);
impl PipelineLayoutHandle {
#[inline(always)]
pub fn to_raw(&self) -> vks::VkPipelineLayout {
self.0
}
}
unsafe impl Handle for PipelineLayoutHandle {
type Target = PipelineLayoutHandle;
#[inline(always)]
fn handle(&self) -> Self::Target {
*self
}
}
#[derive(Debug)]
struct Inner {
handle: PipelineLayoutHandle,
device: Device,
}
#[derive(Debug, Clone)]
pub struct PipelineLayout {
inner: Arc<Inner>,
}
impl PipelineLayout {
pub fn builder<'b>() -> PipelineLayoutBuilder<'b> {
PipelineLayoutBuilder::new()
}
pub fn handle(&self) -> PipelineLayoutHandle {
self.inner.handle
}
pub fn device(&self) -> &Device {
&self.inner.device
}
}
unsafe impl<'h> Handle for &'h PipelineLayout {
type Target = PipelineLayoutHandle;
#[inline(always)]
fn handle(&self) -> Self::Target {
self.inner.handle
}
}
impl Drop for Inner {
fn drop(&mut self) {
unsafe {
self.device.destroy_pipeline_layout(self.handle, None);
}
}
}
#[derive(Debug, Clone)]
pub struct PipelineLayoutBuilder<'b> {
create_info: PipelineLayoutCreateInfo<'b>,
_p: PhantomData<&'b ()>,
}
impl<'b> PipelineLayoutBuilder<'b> {
pub fn new() -> PipelineLayoutBuilder<'b> {
PipelineLayoutBuilder {
create_info: PipelineLayoutCreateInfo::default(),
_p: PhantomData,
}
}
pub fn set_layouts<'s, 'p>(&'s mut self,
set_layouts: &'p [DescriptorSetLayoutHandle])
-> &'s mut PipelineLayoutBuilder<'b>
where 'p: 'b {
self.create_info.set_set_layouts(set_layouts);
self
}
pub fn push_constant_ranges<'s, 'p>(&'s mut self,
push_constant_ranges: &'p [PushConstantRange])
-> &'s mut PipelineLayoutBuilder<'b>
where 'p: 'b {
self.create_info.set_push_constant_ranges(push_constant_ranges);
self
}
pub fn build(&self, device: Device) -> VdResult<PipelineLayout> {
let handle = unsafe { device.create_pipeline_layout(&self.create_info, None)? };
Ok(PipelineLayout {
inner: Arc::new(Inner {
handle,
device,
})
})
}
}