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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use std::ops::BitOr;
use vk;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct BufferUsage {
pub transfer_source: bool,
pub transfer_destination: bool,
pub uniform_texel_buffer: bool,
pub storage_texel_buffer: bool,
pub uniform_buffer: bool,
pub storage_buffer: bool,
pub index_buffer: bool,
pub vertex_buffer: bool,
pub indirect_buffer: bool,
}
impl BufferUsage {
pub(crate) fn to_vulkan_bits(&self) -> vk::BufferUsageFlagBits {
let mut result = 0;
if self.transfer_source {
result |= vk::BUFFER_USAGE_TRANSFER_SRC_BIT;
}
if self.transfer_destination {
result |= vk::BUFFER_USAGE_TRANSFER_DST_BIT;
}
if self.uniform_texel_buffer {
result |= vk::BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
}
if self.storage_texel_buffer {
result |= vk::BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
}
if self.uniform_buffer {
result |= vk::BUFFER_USAGE_UNIFORM_BUFFER_BIT;
}
if self.storage_buffer {
result |= vk::BUFFER_USAGE_STORAGE_BUFFER_BIT;
}
if self.index_buffer {
result |= vk::BUFFER_USAGE_INDEX_BUFFER_BIT;
}
if self.vertex_buffer {
result |= vk::BUFFER_USAGE_VERTEX_BUFFER_BIT;
}
if self.indirect_buffer {
result |= vk::BUFFER_USAGE_INDIRECT_BUFFER_BIT;
}
result
}
#[inline]
pub fn none() -> BufferUsage {
BufferUsage {
transfer_source: false,
transfer_destination: false,
uniform_texel_buffer: false,
storage_texel_buffer: false,
uniform_buffer: false,
storage_buffer: false,
index_buffer: false,
vertex_buffer: false,
indirect_buffer: false,
}
}
#[inline]
pub fn all() -> BufferUsage {
BufferUsage {
transfer_source: true,
transfer_destination: true,
uniform_texel_buffer: true,
storage_texel_buffer: true,
uniform_buffer: true,
storage_buffer: true,
index_buffer: true,
vertex_buffer: true,
indirect_buffer: true,
}
}
#[inline]
pub fn transfer_source() -> BufferUsage {
BufferUsage {
transfer_source: true,
..BufferUsage::none()
}
}
#[inline]
pub fn transfer_destination() -> BufferUsage {
BufferUsage {
transfer_destination: true,
..BufferUsage::none()
}
}
#[inline]
pub fn vertex_buffer() -> BufferUsage {
BufferUsage {
vertex_buffer: true,
..BufferUsage::none()
}
}
#[inline]
pub fn vertex_buffer_transfer_destination() -> BufferUsage {
BufferUsage {
vertex_buffer: true,
transfer_destination: true,
..BufferUsage::none()
}
}
#[inline]
pub fn index_buffer() -> BufferUsage {
BufferUsage {
index_buffer: true,
..BufferUsage::none()
}
}
#[inline]
pub fn index_buffer_transfer_destination() -> BufferUsage {
BufferUsage {
index_buffer: true,
transfer_destination: true,
..BufferUsage::none()
}
}
#[inline]
pub fn uniform_buffer() -> BufferUsage {
BufferUsage {
uniform_buffer: true,
..BufferUsage::none()
}
}
#[inline]
pub fn uniform_buffer_transfer_destination() -> BufferUsage {
BufferUsage {
uniform_buffer: true,
transfer_destination: true,
..BufferUsage::none()
}
}
#[inline]
pub fn indirect_buffer() -> BufferUsage {
BufferUsage {
indirect_buffer: true,
..BufferUsage::none()
}
}
#[inline]
pub fn indirect_buffer_transfer_destination() -> BufferUsage {
BufferUsage {
indirect_buffer: true,
transfer_destination: true,
..BufferUsage::none()
}
}
}
impl BitOr for BufferUsage {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self {
BufferUsage {
transfer_source: self.transfer_source || rhs.transfer_source,
transfer_destination: self.transfer_destination || rhs.transfer_destination,
uniform_texel_buffer: self.uniform_texel_buffer || rhs.uniform_texel_buffer,
storage_texel_buffer: self.storage_texel_buffer || rhs.storage_texel_buffer,
uniform_buffer: self.uniform_buffer || rhs.uniform_buffer,
storage_buffer: self.storage_buffer || rhs.storage_buffer,
index_buffer: self.index_buffer || rhs.index_buffer,
vertex_buffer: self.vertex_buffer || rhs.vertex_buffer,
indirect_buffer: self.indirect_buffer || rhs.indirect_buffer,
}
}
}