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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#![warn(missing_docs)]
#![deny(clippy::as_conversions)]
#![deny(clippy::panic)]
#![deny(clippy::unwrap_used)]
use std::sync::Arc;
use erupt::vk;
pub use {
acceleration_structure::AccelerationStructure,
buffer::{Buffer, BufferView},
command::{
CommandBufferSemaphore, CommonCommands, ComputeCommandBuffer, ComputeCommandEncoder,
ComputeCommandPool, GraphicsCommandBuffer, GraphicsCommandEncoder, GraphicsCommandPool,
RenderPassEncoder, TransferCommandBuffer, TransferCommandEncoder, TransferCommandPool,
},
deferred_operation::DeferredOperation,
descriptor::{DescriptorPool, DescriptorSet, DescriptorSetLayout},
device::{BarSupport, Device, DeviceConfiguration, QueueConfiguration, Queues},
error::AscheError,
fence::Fence,
image::{Image, ImageView, Sampler},
instance::{Instance, InstanceConfiguration, Version},
query::QueryPool,
queue::{ComputeQueue, GraphicsQueue, TransferQueue},
semaphore::{
BinarySemaphore, BinarySemaphoreHandle, TimelineSemaphore, TimelineSemaphoreHandle,
},
swapchain::{Swapchain, SwapchainFrame},
vk_alloc::{AllocatorError, Lifetime, MemoryLocation},
};
use crate::context::Context;
mod acceleration_structure;
mod buffer;
mod command;
mod context;
mod deferred_operation;
mod descriptor;
mod device;
mod error;
mod fence;
mod image;
mod instance;
mod memory_allocator;
mod query;
mod queue;
mod semaphore;
mod swapchain;
#[cfg(debug_assertions)]
mod vk_debug;
type Result<T> = std::result::Result<T, AscheError>;
#[derive(Copy, Clone, Debug)]
pub(crate) enum QueueType {
Compute = 0,
Graphics,
Transfer,
}
impl std::fmt::Display for QueueType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
QueueType::Compute => f.write_str("Compute"),
QueueType::Graphics => f.write_str("Graphics"),
QueueType::Transfer => f.write_str("Transfer"),
}
}
}
#[derive(Debug)]
pub struct RenderPass {
raw: vk::RenderPass,
context: Arc<Context>,
}
impl RenderPass {
#[inline]
pub fn raw(&self) -> vk::RenderPass {
self.raw
}
}
impl Drop for RenderPass {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_render_pass(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct PipelineLayout {
raw: vk::PipelineLayout,
context: Arc<Context>,
}
impl PipelineLayout {
#[inline]
pub fn raw(&self) -> vk::PipelineLayout {
self.raw
}
}
impl Drop for PipelineLayout {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_pipeline_layout(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct GraphicsPipeline {
raw: vk::Pipeline,
context: Arc<Context>,
}
impl GraphicsPipeline {
#[inline]
pub fn raw(&self) -> vk::Pipeline {
self.raw
}
}
impl Drop for GraphicsPipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct ComputePipeline {
raw: vk::Pipeline,
context: Arc<Context>,
}
impl ComputePipeline {
#[inline]
pub fn raw(&self) -> vk::Pipeline {
self.raw
}
}
impl Drop for ComputePipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct RayTracingPipeline {
raw: vk::Pipeline,
context: Arc<Context>,
}
impl RayTracingPipeline {
#[inline]
pub fn raw(&self) -> vk::Pipeline {
self.raw
}
}
impl Drop for RayTracingPipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct ShaderModule {
raw: vk::ShaderModule,
context: Arc<Context>,
}
impl ShaderModule {
#[inline]
pub fn raw(&self) -> vk::ShaderModule {
self.raw
}
}
impl Drop for ShaderModule {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_shader_module(Some(self.raw), None);
};
}
}
#[derive(Clone, Debug)]
pub struct BufferDescriptor<'a, LT: Lifetime> {
pub name: &'a str,
pub usage: vk::BufferUsageFlags,
pub memory_location: vk_alloc::MemoryLocation,
pub lifetime: LT,
pub sharing_mode: vk::SharingMode,
pub queues: vk::QueueFlags,
pub size: vk::DeviceSize,
pub flags: Option<vk::BufferCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct BufferViewDescriptor<'a, LT: Lifetime> {
pub name: &'a str,
pub buffer: &'a Buffer<LT>,
pub format: vk::Format,
pub offset: vk::DeviceSize,
pub range: u64,
pub flags: Option<vk::BufferViewCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct ImageDescriptor<'a, LT: Lifetime> {
pub name: &'a str,
pub usage: vk::ImageUsageFlags,
pub memory_location: vk_alloc::MemoryLocation,
pub lifetime: LT,
pub sharing_mode: vk::SharingMode,
pub queues: vk::QueueFlags,
pub image_type: vk::ImageType,
pub format: vk::Format,
pub extent: vk::Extent3D,
pub mip_levels: u32,
pub array_layers: u32,
pub samples: vk::SampleCountFlagBits,
pub tiling: vk::ImageTiling,
pub initial_layout: vk::ImageLayout,
pub flags: Option<vk::ImageCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct ImageViewDescriptor<'a, LT: Lifetime> {
pub name: &'a str,
pub image: &'a Image<LT>,
pub view_type: vk::ImageViewType,
pub format: vk::Format,
pub components: vk::ComponentMapping,
pub subresource_range: vk::ImageSubresourceRange,
pub flags: Option<vk::ImageViewCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct SamplerDescriptor<'a> {
pub name: &'a str,
pub mag_filter: vk::Filter,
pub min_filter: vk::Filter,
pub mipmap_mode: vk::SamplerMipmapMode,
pub address_mode_u: vk::SamplerAddressMode,
pub address_mode_v: vk::SamplerAddressMode,
pub address_mode_w: vk::SamplerAddressMode,
pub mip_lod_bias: vk::SamplerMipmapMode,
pub anisotropy_enable: bool,
pub max_anisotropy: f32,
pub compare_op: Option<vk::CompareOp>,
pub min_lod: f32,
pub max_lod: f32,
pub border_color: Option<vk::BorderColor>,
pub unnormalized_coordinates: bool,
pub flags: Option<vk::SamplerCreateFlags>,
}
impl<'a> Default for SamplerDescriptor<'a> {
fn default() -> Self {
Self {
name: "",
mag_filter: vk::Filter::NEAREST,
min_filter: vk::Filter::NEAREST,
mipmap_mode: vk::SamplerMipmapMode::NEAREST,
address_mode_u: vk::SamplerAddressMode::REPEAT,
address_mode_v: vk::SamplerAddressMode::REPEAT,
address_mode_w: vk::SamplerAddressMode::REPEAT,
mip_lod_bias: vk::SamplerMipmapMode::NEAREST,
anisotropy_enable: false,
max_anisotropy: 0.0,
compare_op: None,
min_lod: 0.0,
max_lod: f32::MAX,
border_color: None,
unnormalized_coordinates: false,
flags: None,
}
}
}
#[derive(Clone, Debug)]
pub struct DescriptorPoolDescriptor<'a> {
pub name: &'a str,
pub max_sets: u32,
pub pool_sizes: &'a [vk::DescriptorPoolSizeBuilder<'a>],
pub flags: Option<vk::DescriptorPoolCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct RenderPassColorAttachmentDescriptor {
pub attachment: vk::ImageView,
pub clear_value: Option<vk::ClearValue>,
}
#[derive(Clone, Debug)]
pub struct RenderPassDepthAttachmentDescriptor {
pub attachment: vk::ImageView,
pub clear_value: Option<vk::ClearValue>,
}