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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
//! Voodoo - Vulkan, but rustier.

extern crate libloading as lib;
extern crate smallvec;
extern crate vks as vks_;
extern crate libc;
#[macro_use]
extern crate bitflags as bitflags_;
#[macro_use]
extern crate enum_primitive_derive;
extern crate num_traits;

mod error;
mod version;
mod loader;
mod instance;
mod physical_device;
mod swapchain;
mod image_view;
mod pipeline_layout;
mod shader_module;
mod render_pass;
mod graphics_pipeline;
mod framebuffer;
mod surface;
mod queue;
mod command_pool;
mod command_buffer;
mod semaphore;
mod buffer;
mod image;
mod sampler;
mod device_memory;
mod descriptor_set_layout;
mod descriptor_pool;
mod structs;
mod enums;
mod bitflags;
mod event;
mod fence;
mod device;
pub mod util;

pub mod vks {
    pub use vks_::*;
    pub use vks_::vk::*;
    pub use vks_::amd_draw_indirect_count::*;
    pub use vks_::amd_gcn_shader::*;
    pub use vks_::amd_gpu_shader_half_float::*;
    pub use vks_::amd_gpu_shader_int16::*;
    pub use vks_::amd_mixed_attachment_samples::*;
    pub use vks_::amd_negative_viewport_height::*;
    pub use vks_::amd_rasterization_order::*;
    pub use vks_::amd_shader_ballot::*;
    pub use vks_::amd_shader_explicit_vertex_parameter::*;
    pub use vks_::amd_shader_trinary_minmax::*;
    pub use vks_::amd_texture_gather_bias_lod::*;
    pub use vks_::ext_acquire_xlib_display::*;
    pub use vks_::ext_blend_operation_advanced::*;
    pub use vks_::ext_debug_marker::*;
    pub use vks_::ext_debug_report::*;
    pub use vks_::ext_depth_range_unrestricted::*;
    pub use vks_::ext_direct_mode_display::*;
    pub use vks_::ext_discard_rectangles::*;
    pub use vks_::ext_display_control::*;
    pub use vks_::ext_display_surface_counter::*;
    pub use vks_::ext_hdr_metadata::*;
    pub use vks_::ext_post_depth_coverage::*;
    pub use vks_::ext_sampler_filter_minmax::*;
    pub use vks_::ext_shader_stencil_export::*;
    pub use vks_::ext_shader_subgroup_ballot::*;
    pub use vks_::ext_shader_subgroup_vote::*;
    pub use vks_::ext_shader_viewport_index_layer::*;
    pub use vks_::ext_swapchain_colorspace::*;
    pub use vks_::ext_validation_flags::*;
    pub use vks_::google_display_timing::*;
    pub use vks_::img_filter_cubic::*;
    pub use vks_::img_format_pvrtc::*;
    pub use vks_::khr_16bit_storage::*;
    pub use vks_::khr_android_surface::*;
    pub use vks_::khr_dedicated_allocation::*;
    pub use vks_::khr_descriptor_update_template::*;
    pub use vks_::khr_display::*;
    pub use vks_::khr_display_swapchain::*;
    pub use vks_::khr_external_fence::*;
    pub use vks_::khr_external_fence_capabilities::*;
    pub use vks_::khr_external_fence_fd::*;
    pub use vks_::khr_external_fence_win32::*;
    pub use vks_::khr_external_memory::*;
    pub use vks_::khr_external_memory_capabilities::*;
    pub use vks_::khr_external_memory_fd::*;
    pub use vks_::khr_external_memory_win32::*;
    pub use vks_::khr_external_semaphore::*;
    pub use vks_::khr_external_semaphore_capabilities::*;
    pub use vks_::khr_external_semaphore_fd::*;
    pub use vks_::khr_external_semaphore_win32::*;
    pub use vks_::khr_get_memory_requirements2::*;
    pub use vks_::khr_get_physical_device_properties2::*;
    pub use vks_::khr_get_surface_capabilities2::*;
    pub use vks_::khr_incremental_present::*;
    pub use vks_::khr_maintenance1::*;
    pub use vks_::khr_mir_surface::*;
    pub use vks_::khr_push_descriptor::*;
    pub use vks_::khr_relaxed_block_layout::*;
    pub use vks_::khr_sampler_mirror_clamp_to_edge::*;
    pub use vks_::khr_shader_draw_parameters::*;
    pub use vks_::khr_shared_presentable_image::*;
    pub use vks_::khr_storage_buffer_storage_class::*;
    pub use vks_::khr_surface::*;
    pub use vks_::khr_swapchain::*;
    pub use vks_::khr_variable_pointers::*;
    pub use vks_::khr_wayland_surface::*;
    pub use vks_::khr_win32_keyed_mutex::*;
    pub use vks_::khr_win32_surface::*;
    pub use vks_::khr_xcb_surface::*;
    pub use vks_::khr_xlib_surface::*;
    pub use vks_::mvk_ios_surface::*;
    pub use vks_::mvk_macos_surface::*;
    pub use vks_::nn_vi_surface::*;
    pub use vks_::nv_clip_space_w_scaling::*;
    pub use vks_::nv_dedicated_allocation::*;
    pub use vks_::nv_external_memory::*;
    pub use vks_::nv_external_memory_capabilities::*;
    pub use vks_::nv_external_memory_win32::*;
    pub use vks_::nv_fill_rectangle::*;
    pub use vks_::nv_fragment_coverage_to_color::*;
    pub use vks_::nv_framebuffer_mixed_samples::*;
    pub use vks_::nv_geometry_shader_passthrough::*;
    pub use vks_::nv_glsl_shader::*;
    pub use vks_::nv_sample_mask_override_coverage::*;
    pub use vks_::nv_viewport_array2::*;
    pub use vks_::nv_viewport_swizzle::*;
    pub use vks_::nv_win32_keyed_mutex::*;
    pub use vks_::android_types::*;
    pub use vks_::mir_types::*;
    pub use vks_::wayland_types::*;
    pub use vks_::win32_types::*;
    pub use vks_::xcb_types::*;
    pub use vks_::xlib_types::*;

    #[cfg(feature = "experimental")]
    pub use vks_::experimental::*;
    #[cfg(feature = "experimental")]
    pub use vks_::experimental::khx_device_group::*;
    #[cfg(feature = "experimental")]
    pub use vks_::experimental::khx_device_group_creation::*;
    #[cfg(feature = "experimental")]
    pub use vks_::experimental::khx_multiview::*;
    #[cfg(feature = "experimental")]
    pub use vks_::experimental::nvx_device_generated_commands::*;
    #[cfg(feature = "experimental")]
    pub use vks_::experimental::nvx_multiview_per_view_attributes::*;
}


use error::{Result as VdResult};
pub use util::{CharStr, CharStrs};
pub use loader::Loader;
pub use error::{Error, ErrorKind, Result};
pub use version::Version;
pub use instance::{InstanceHandle, Instance, InstanceBuilder};
pub use physical_device::{PhysicalDeviceHandle, PhysicalDevice};
pub use device::{DeviceHandle, Device, DeviceBuilder};
pub use surface::{SurfaceKhrHandle, SurfaceKhr, SurfaceKhrBuilder};
pub use queue::{QueueHandle, Queue};
pub use swapchain::{SwapchainKhrHandle, SwapchainKhr, SwapchainKhrBuilder, SwapchainSupportDetails};
pub use image_view::{ImageViewHandle, ImageView, ImageViewBuilder};
pub use shader_module::{ShaderModuleHandle, ShaderModule};
pub use pipeline_layout::{PipelineLayoutHandle, PipelineLayout, PipelineLayoutBuilder};
pub use render_pass::{RenderPassHandle, RenderPass, RenderPassBuilder};
pub use graphics_pipeline::{GraphicsPipeline, GraphicsPipelineBuilder};
pub use framebuffer::{FramebufferHandle, Framebuffer, FramebufferBuilder};
pub use command_pool::{CommandPoolHandle, CommandPool, CommandPoolBuilder};
pub use command_buffer::{CommandBufferHandle, CommandBuffer};
pub use semaphore::{SemaphoreHandle, Semaphore};
pub use buffer::{BufferHandle, Buffer, BufferBuilder};
pub use image::{ImageHandle, Image, ImageBuilder};
pub use sampler::{SamplerHandle, Sampler, SamplerBuilder};
pub use device_memory::{DeviceMemoryHandle, DeviceMemory, DeviceMemoryBuilder};
pub use descriptor_set_layout::{DescriptorSetLayoutHandle, DescriptorSetLayout,
    DescriptorSetLayoutBuilder};
pub use descriptor_pool::{DescriptorPoolHandle, DescriptorPool, DescriptorPoolBuilder};
pub use fence::{FenceHandle, Fence, FenceStatus};
pub use event::{EventHandle, Event, EventStatus};
pub use structs::*;
pub use enums::*;
pub use bitflags::*;


#[macro_export]
macro_rules! offset_of {
    ($ty:ty, $field:ident) => {
        unsafe { &(*(0 as *const $ty)).$field as *const _ as usize } as u32
    }
}


pub static VALIDATION_LAYER_NAMES: &[&[u8]] = &[
    b"VK_LAYER_LUNARG_standard_validation\0"
];


const PRINT: bool = false;
pub const LOD_CLAMP_NONE: f32 = 1000.0f32;
pub const REMAINING_MIP_LEVELS: u32 = !0;
pub const REMAINING_ARRAY_LAYERS: u32= !0;
pub const WHOLE_SIZE: u64 = !0;
pub const ATTACHMENT_UNUSED: u32 = !0;
pub const TRUE: i32 = 1;
pub const FALSE: i32 = 0;
pub const QUEUE_FAMILY_IGNORED: u32 = !0;
pub const SUBPASS_EXTERNAL: u32 = !0;
pub const MAX_PHYSICAL_DEVICE_NAME_SIZE: usize = 256;
pub const UUID_SIZE: usize = 16;
pub const MAX_MEMORY_TYPES: usize = 32;
pub const MAX_MEMORY_HEAPS: usize = 16;
pub const MAX_EXTENSION_NAME_SIZE: usize = 256;
pub const MAX_DESCRIPTION_SIZE: usize = 256;


pub unsafe trait Handle {
    type Target;

    fn handle(&self) -> Self::Target;
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct QueryPoolHandle(pub(crate) vks::VkQueryPool);

impl QueryPoolHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkQueryPool {
        self.0
    }
}

unsafe impl Handle for QueryPoolHandle {
    type Target = QueryPoolHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct BufferViewHandle(pub(crate) vks::VkBufferView);

impl BufferViewHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkBufferView {
        self.0
    }
}

unsafe impl Handle for BufferViewHandle {
    type Target = BufferViewHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct PipelineCacheHandle(pub(crate) vks::VkPipelineCache);

impl PipelineCacheHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkPipelineCache {
        self.0
    }
}

unsafe impl Handle for PipelineCacheHandle {
    type Target = PipelineCacheHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct PipelineHandle(pub(crate) vks::VkPipeline);

impl PipelineHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkPipeline {
        self.0
    }
}

unsafe impl Handle for PipelineHandle {
    type Target = PipelineHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DescriptorSetHandle(pub(crate) vks::VkDescriptorSet);

impl DescriptorSetHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkDescriptorSet {
        self.0
    }
}

unsafe impl Handle for DescriptorSetHandle {
    type Target = DescriptorSetHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DisplayKhrHandle(pub(crate) vks::VkDisplayKHR);

impl DisplayKhrHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkDisplayKHR {
        self.0
    }
}

unsafe impl Handle for DisplayKhrHandle {
    type Target = DisplayKhrHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DisplayModeKhrHandle(pub(crate) vks::VkDisplayModeKHR);

impl DisplayModeKhrHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkDisplayModeKHR {
        self.0
    }
}

unsafe impl Handle for DisplayModeKhrHandle {
    type Target = DisplayModeKhrHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DescriptorUpdateTemplateHandle(pub(crate) vks::VkDescriptorUpdateTemplateKHR);

impl DescriptorUpdateTemplateHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkDescriptorUpdateTemplateKHR {
        self.0
    }
}

unsafe impl Handle for DescriptorUpdateTemplateHandle {
    type Target = DescriptorUpdateTemplateHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DebugReportCallbackExtHandle(pub(crate) vks::VkDebugReportCallbackEXT);

impl DebugReportCallbackExtHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> vks::VkDebugReportCallbackEXT {
        self.0
    }
}

unsafe impl Handle for DebugReportCallbackExtHandle {
    type Target = DebugReportCallbackExtHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct SamplerYcbcrConversionKhrHandle(pub(crate) u64);

impl SamplerYcbcrConversionKhrHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> u64 {
        self.0
    }
}

unsafe impl Handle for SamplerYcbcrConversionKhrHandle {
    type Target = SamplerYcbcrConversionKhrHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct ObjectTableNvxHandle(pub(crate) u64);

impl ObjectTableNvxHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> u64 {
        self.0
    }
}

unsafe impl Handle for ObjectTableNvxHandle {
    type Target = ObjectTableNvxHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct IndirectCommandsLayoutNvxHandle(pub(crate) u64);

impl IndirectCommandsLayoutNvxHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> u64 {
        self.0
    }
}

unsafe impl Handle for IndirectCommandsLayoutNvxHandle {
    type Target = IndirectCommandsLayoutNvxHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct ValidationCacheExtHandle(pub(crate) u64);

impl ValidationCacheExtHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> u64 {
        self.0
    }
}

unsafe impl Handle for ValidationCacheExtHandle {
    type Target = ValidationCacheExtHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
#[cfg(feature = "experimental")]
pub struct DescriptorUpdateTemplateKhrHandle(pub(crate) u64);

#[cfg(feature = "experimental")]
impl DescriptorUpdateTemplateKhrHandle {
    #[inline(always)]
    pub fn to_raw(&self) -> u64 {
        self.0
    }
}

#[cfg(feature = "experimental")]
unsafe impl Handle for DescriptorUpdateTemplateKhrHandle {
    type Target = DescriptorUpdateTemplateKhrHandle;

    fn handle(&self) -> Self::Target {
        *self
    }
}


#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct DescriptorSet(pub(crate) DescriptorSetHandle);

impl DescriptorSet {
    pub fn handle(&self) -> DescriptorSetHandle {
        self.0
    }
}

unsafe impl Handle for DescriptorSet {
    type Target = DescriptorSetHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}

unsafe impl<'h> Handle for &'h DescriptorSet {
    type Target = DescriptorSetHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


#[derive(Clone, Debug)]
pub struct BufferView(BufferViewHandle);

impl BufferView {
    pub fn handle(&self) -> BufferViewHandle {
        self.0
    }
}

unsafe impl<'h> Handle for &'h BufferView {
    type Target = BufferViewHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


#[derive(Clone, Debug)]
pub struct Pipeline(PipelineHandle);

impl Pipeline {
    pub fn handle(&self) -> PipelineHandle {
        self.0
    }
}

unsafe impl<'h> Handle for &'h Pipeline {
    type Target = PipelineHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


#[derive(Clone, Debug)]
pub struct QueryPool(QueryPoolHandle);

impl QueryPool {
    pub fn handle(&self) -> QueryPoolHandle {
        self.0
    }
}

unsafe impl<'h> Handle for &'h QueryPool {
    type Target = QueryPoolHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


#[derive(Clone, Debug)]
pub struct DisplayModeKhr(DisplayModeKhrHandle);

impl DisplayModeKhr {
    pub fn handle(&self) -> DisplayModeKhrHandle {
        self.0
    }
}

unsafe impl<'h> Handle for &'h DisplayModeKhr {
    type Target = DisplayModeKhrHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


#[derive(Clone, Debug)]
pub struct DisplayKhr(DisplayKhrHandle);

impl DisplayKhr {
    pub fn handle(&self) -> DisplayKhrHandle {
        self.0
    }
}

unsafe impl<'h> Handle for &'h DisplayKhr {
    type Target = DisplayKhrHandle;

    fn handle(&self) -> Self::Target {
        self.0
    }
}


pub type ClearValue = vks::VkClearValue;
pub type ClearColorValue = vks::VkClearColorValue;

pub type DeviceSize = vks::VkDeviceSize;
pub type Display = vks::Display;

pub type Window = vks::Window;
pub type VisualID = vks::VisualID;
pub type RROutput = vks::RROutput;

pub type MirConnection = vks::MirConnection;
pub type MirSurface = vks::MirSurface;
pub type ANativeWindow = vks::ANativeWindow;
#[allow(non_camel_case_types)]
pub type wl_display = vks::wl_display;
#[allow(non_camel_case_types)]
pub type wl_surface = vks::wl_surface;
#[allow(non_camel_case_types)]
pub type HINSTANCE = vks::HINSTANCE;
#[allow(non_camel_case_types)]
pub type HWND = vks::HWND;
#[allow(non_camel_case_types)]
pub type xcb_connection_t = vks::xcb_connection_t;

#[allow(non_camel_case_types)]
pub type xcb_window_t = vks::xcb_window_t;
#[allow(non_camel_case_types)]
pub type xcb_visualid_t = vks::xcb_visualid_t;
#[allow(non_camel_case_types)]
pub type HANDLE = vks::HANDLE;
#[allow(non_camel_case_types)]
pub type SECURITY_ATTRIBUTES = vks::SECURITY_ATTRIBUTES;
#[allow(non_camel_case_types)]
pub type DWORD = vks::DWORD;
#[allow(non_camel_case_types)]
pub type LPCWSTR = vks::LPCWSTR;
pub type CommandPoolTrimFlagsKhr = vks::VkCommandPoolTrimFlagsKHR;