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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
use std::ops::BitOr;
use vk;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ImageUsage {
pub transfer_source: bool,
pub transfer_destination: bool,
pub sampled: bool,
pub storage: bool,
pub color_attachment: bool,
pub depth_stencil_attachment: bool,
pub transient_attachment: bool,
pub input_attachment: bool,
}
impl ImageUsage {
#[inline]
pub fn all() -> ImageUsage {
ImageUsage {
transfer_source: true,
transfer_destination: true,
sampled: true,
storage: true,
color_attachment: true,
depth_stencil_attachment: true,
transient_attachment: true,
input_attachment: true,
}
}
#[inline]
pub fn none() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: false,
depth_stencil_attachment: false,
transient_attachment: false,
input_attachment: false,
}
}
#[inline]
pub(crate) fn to_usage_bits(&self) -> vk::ImageUsageFlagBits {
let mut result = 0;
if self.transfer_source {
result |= vk::IMAGE_USAGE_TRANSFER_SRC_BIT;
}
if self.transfer_destination {
result |= vk::IMAGE_USAGE_TRANSFER_DST_BIT;
}
if self.sampled {
result |= vk::IMAGE_USAGE_SAMPLED_BIT;
}
if self.storage {
result |= vk::IMAGE_USAGE_STORAGE_BIT;
}
if self.color_attachment {
result |= vk::IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
}
if self.depth_stencil_attachment {
result |= vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
if self.transient_attachment {
result |= vk::IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
}
if self.input_attachment {
result |= vk::IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
}
result
}
#[inline]
pub(crate) fn from_bits(val: u32) -> ImageUsage {
ImageUsage {
transfer_source: (val & vk::IMAGE_USAGE_TRANSFER_SRC_BIT) != 0,
transfer_destination: (val & vk::IMAGE_USAGE_TRANSFER_DST_BIT) != 0,
sampled: (val & vk::IMAGE_USAGE_SAMPLED_BIT) != 0,
storage: (val & vk::IMAGE_USAGE_STORAGE_BIT) != 0,
color_attachment: (val & vk::IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0,
depth_stencil_attachment: (val & vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0,
transient_attachment: (val & vk::IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0,
input_attachment: (val & vk::IMAGE_USAGE_INPUT_ATTACHMENT_BIT) != 0,
}
}
}
impl BitOr for ImageUsage {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self {
ImageUsage {
transfer_source: self.transfer_source || rhs.transfer_source,
transfer_destination: self.transfer_destination || rhs.transfer_destination,
sampled: self.sampled || rhs.sampled,
storage: self.storage || rhs.storage,
color_attachment: self.color_attachment || rhs.color_attachment,
depth_stencil_attachment: self.depth_stencil_attachment || rhs.depth_stencil_attachment,
transient_attachment: self.transient_attachment || rhs.transient_attachment,
input_attachment: self.input_attachment || rhs.input_attachment,
}
}
}