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
use {
super::{Device, DriverError},
crate::ptr::Shared,
archery::SharedPointerKind,
ash::vk,
std::{ops::Deref, thread::panicking},
};
#[derive(Debug)]
pub struct DescriptorSetLayout<P>
where
P: SharedPointerKind,
{
device: Shared<Device<P>, P>,
descriptor_set_layout: vk::DescriptorSetLayout,
}
impl<P> DescriptorSetLayout<P>
where
P: SharedPointerKind,
{
pub fn create(
device: &Shared<Device<P>, P>,
info: &vk::DescriptorSetLayoutCreateInfo,
) -> Result<Self, DriverError>
where
P: SharedPointerKind,
{
let device = Shared::clone(device);
let descriptor_set_layout = unsafe {
device
.create_descriptor_set_layout(info, None)
.map_err(|_| DriverError::Unsupported)
}?;
Ok(Self {
device,
descriptor_set_layout,
})
}
}
impl<P> Deref for DescriptorSetLayout<P>
where
P: SharedPointerKind,
{
type Target = vk::DescriptorSetLayout;
fn deref(&self) -> &Self::Target {
&self.descriptor_set_layout
}
}
impl<P> Drop for DescriptorSetLayout<P>
where
P: SharedPointerKind,
{
fn drop(&mut self) {
if panicking() {
return;
}
unsafe {
self.device
.destroy_descriptor_set_layout(self.descriptor_set_layout, None);
}
}
}