3 use crate::device::Device;
8 use std::os::raw::c_char;
11 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VkInstance.html>
14 pub(crate) handle: vk::Instance,
16 pub(crate) instance_fn_1_0: vk::InstanceFnV1_0,
17 pub(crate) instance_fn_1_1: vk::InstanceFnV1_1,
18 pub(crate) instance_fn_1_2: vk::InstanceFnV1_2,
19 pub(crate) instance_fn_1_3: vk::InstanceFnV1_3,
23 pub unsafe fn load(static_fn: &vk::StaticFn, instance: vk::Instance) -> Self {
24 let load_fn = |name: &std::ffi::CStr| {
25 mem::transmute((static_fn.get_instance_proc_addr)(instance, name.as_ptr()))
31 instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn),
32 instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn),
33 instance_fn_1_2: vk::InstanceFnV1_2::load(load_fn),
34 instance_fn_1_3: vk::InstanceFnV1_3::load(load_fn),
39 pub fn handle(&self) -> vk::Instance {
45 #[allow(non_camel_case_types)]
48 pub fn fp_v1_3(&self) -> &vk::InstanceFnV1_3 {
52 /// Retrieve the number of elements to pass to [`get_physical_device_tool_properties()`][Self::get_physical_device_tool_properties()]
54 pub unsafe fn get_physical_device_tool_properties_len(
56 physical_device: vk::PhysicalDevice,
57 ) -> VkResult<usize> {
59 (self.instance_fn_1_3.get_physical_device_tool_properties)(
64 .result_with_success(count as usize)
67 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceToolProperties.html>
69 /// Call [`get_physical_device_tool_properties_len()`][Self::get_physical_device_tool_properties_len()] to query the number of elements to pass to `out`.
70 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
72 pub unsafe fn get_physical_device_tool_properties(
74 physical_device: vk::PhysicalDevice,
75 out: &mut [vk::PhysicalDeviceToolProperties],
77 let mut count = out.len() as u32;
78 (self.instance_fn_1_3.get_physical_device_tool_properties)(
84 assert_eq!(count as usize, out.len());
90 #[allow(non_camel_case_types)]
93 pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
99 #[allow(non_camel_case_types)]
102 pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 {
103 &self.instance_fn_1_1
106 /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()]
108 pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
109 let mut group_count = 0;
110 (self.instance_fn_1_1.enumerate_physical_device_groups)(
115 .result_with_success(group_count as usize)
118 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDeviceGroups.html>
120 /// Call [`enumerate_physical_device_groups_len()`][Self::enumerate_physical_device_groups_len()] to query the number of elements to pass to `out`.
121 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
123 pub unsafe fn enumerate_physical_device_groups(
125 out: &mut [vk::PhysicalDeviceGroupProperties],
127 let mut count = out.len() as u32;
128 (self.instance_fn_1_1.enumerate_physical_device_groups)(
134 assert_eq!(count as usize, out.len());
138 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>
140 pub unsafe fn get_physical_device_features2(
142 physical_device: vk::PhysicalDevice,
143 features: &mut vk::PhysicalDeviceFeatures2,
145 (self.instance_fn_1_1.get_physical_device_features2)(physical_device, features);
148 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties2.html>
150 pub unsafe fn get_physical_device_properties2(
152 physical_device: vk::PhysicalDevice,
153 prop: &mut vk::PhysicalDeviceProperties2,
155 (self.instance_fn_1_1.get_physical_device_properties2)(physical_device, prop);
158 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html>
160 pub unsafe fn get_physical_device_format_properties2(
162 physical_device: vk::PhysicalDevice,
164 out: &mut vk::FormatProperties2,
166 (self.instance_fn_1_1.get_physical_device_format_properties2)(physical_device, format, out);
169 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html>
171 pub unsafe fn get_physical_device_image_format_properties2(
173 physical_device: vk::PhysicalDevice,
174 format_info: &vk::PhysicalDeviceImageFormatInfo2,
175 image_format_prop: &mut vk::ImageFormatProperties2,
179 .get_physical_device_image_format_properties2)(
187 /// Retrieve the number of elements to pass to [`get_physical_device_queue_family_properties2()`][Self::get_physical_device_queue_family_properties2()]
189 pub unsafe fn get_physical_device_queue_family_properties2_len(
191 physical_device: vk::PhysicalDevice,
193 let mut queue_count = 0;
196 .get_physical_device_queue_family_properties2)(
204 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2.html>
206 /// Call [`get_physical_device_queue_family_properties2_len()`][Self::get_physical_device_queue_family_properties2_len()] to query the number of elements to pass to `out`.
207 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
209 pub unsafe fn get_physical_device_queue_family_properties2(
211 physical_device: vk::PhysicalDevice,
212 out: &mut [vk::QueueFamilyProperties2],
214 let mut count = out.len() as u32;
217 .get_physical_device_queue_family_properties2)(
222 assert_eq!(count as usize, out.len());
225 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>
227 pub unsafe fn get_physical_device_memory_properties2(
229 physical_device: vk::PhysicalDevice,
230 out: &mut vk::PhysicalDeviceMemoryProperties2,
232 (self.instance_fn_1_1.get_physical_device_memory_properties2)(physical_device, out);
235 /// Retrieve the number of elements to pass to [`get_physical_device_sparse_image_format_properties2()`][Self::get_physical_device_sparse_image_format_properties2()]
237 pub unsafe fn get_physical_device_sparse_image_format_properties2_len(
239 physical_device: vk::PhysicalDevice,
240 format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
242 let mut format_count = 0;
245 .get_physical_device_sparse_image_format_properties2)(
251 format_count as usize
254 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2.html>
256 /// Call [`get_physical_device_sparse_image_format_properties2_len()`][Self::get_physical_device_sparse_image_format_properties2_len()] to query the number of elements to pass to `out`.
257 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
259 pub unsafe fn get_physical_device_sparse_image_format_properties2(
261 physical_device: vk::PhysicalDevice,
262 format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
263 out: &mut [vk::SparseImageFormatProperties2],
265 let mut count = out.len() as u32;
268 .get_physical_device_sparse_image_format_properties2)(
274 assert_eq!(count as usize, out.len());
277 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>
279 pub unsafe fn get_physical_device_external_buffer_properties(
281 physical_device: vk::PhysicalDevice,
282 external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo,
283 out: &mut vk::ExternalBufferProperties,
287 .get_physical_device_external_buffer_properties)(
289 external_buffer_info,
294 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html>
296 pub unsafe fn get_physical_device_external_fence_properties(
298 physical_device: vk::PhysicalDevice,
299 external_fence_info: &vk::PhysicalDeviceExternalFenceInfo,
300 out: &mut vk::ExternalFenceProperties,
304 .get_physical_device_external_fence_properties)(
311 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html>
313 pub unsafe fn get_physical_device_external_semaphore_properties(
315 physical_device: vk::PhysicalDevice,
316 external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo,
317 out: &mut vk::ExternalSemaphoreProperties,
321 .get_physical_device_external_semaphore_properties)(
323 external_semaphore_info,
330 #[allow(non_camel_case_types)]
333 pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
334 &self.instance_fn_1_0
337 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDevice.html>
341 /// There is a [parent/child relation] between [`Instance`] and the resulting [`Device`]. The
342 /// application must not [destroy][Instance::destroy_instance()] the parent [`Instance`] object
343 /// before first [destroying][Device::destroy_device()] the returned [`Device`] child object.
344 /// [`Device`] does _not_ implement [drop][drop()] semantics and can only be destroyed via
345 /// [`destroy_device()`][Device::destroy_device()].
347 /// See the [`Entry::create_instance()`] documentation for more destruction ordering rules on
350 /// [parent/child relation]: https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#fundamentals-objectmodel-lifetime
352 pub unsafe fn create_device(
354 physical_device: vk::PhysicalDevice,
355 create_info: &vk::DeviceCreateInfo,
356 allocation_callbacks: Option<&vk::AllocationCallbacks>,
357 ) -> VkResult<Device> {
358 let mut device = mem::zeroed();
359 (self.instance_fn_1_0.create_device)(
362 allocation_callbacks.as_raw_ptr(),
366 Ok(Device::load(&self.instance_fn_1_0, device))
369 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceProcAddr.html>
371 pub unsafe fn get_device_proc_addr(
374 p_name: *const c_char,
375 ) -> vk::PFN_vkVoidFunction {
376 (self.instance_fn_1_0.get_device_proc_addr)(device, p_name)
379 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyInstance.html>
381 pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
382 (self.instance_fn_1_0.destroy_instance)(self.handle(), allocation_callbacks.as_raw_ptr());
385 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html>
387 pub unsafe fn get_physical_device_format_properties(
389 physical_device: vk::PhysicalDevice,
391 ) -> vk::FormatProperties {
392 let mut format_prop = mem::zeroed();
393 (self.instance_fn_1_0.get_physical_device_format_properties)(
401 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>
403 pub unsafe fn get_physical_device_image_format_properties(
405 physical_device: vk::PhysicalDevice,
408 tiling: vk::ImageTiling,
409 usage: vk::ImageUsageFlags,
410 flags: vk::ImageCreateFlags,
411 ) -> VkResult<vk::ImageFormatProperties> {
412 let mut image_format_prop = mem::zeroed();
415 .get_physical_device_image_format_properties)(
422 &mut image_format_prop,
424 .result_with_success(image_format_prop)
427 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>
429 pub unsafe fn get_physical_device_memory_properties(
431 physical_device: vk::PhysicalDevice,
432 ) -> vk::PhysicalDeviceMemoryProperties {
433 let mut memory_prop = mem::zeroed();
434 (self.instance_fn_1_0.get_physical_device_memory_properties)(
441 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties.html>
443 pub unsafe fn get_physical_device_properties(
445 physical_device: vk::PhysicalDevice,
446 ) -> vk::PhysicalDeviceProperties {
447 let mut prop = mem::zeroed();
448 (self.instance_fn_1_0.get_physical_device_properties)(physical_device, &mut prop);
452 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties.html>
454 pub unsafe fn get_physical_device_queue_family_properties(
456 physical_device: vk::PhysicalDevice,
457 ) -> Vec<vk::QueueFamilyProperties> {
458 read_into_uninitialized_vector(|count, data| {
461 .get_physical_device_queue_family_properties)(
462 physical_device, count, data
466 // The closure always returns SUCCESS
470 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures.html>
472 pub unsafe fn get_physical_device_features(
474 physical_device: vk::PhysicalDevice,
475 ) -> vk::PhysicalDeviceFeatures {
476 let mut prop = mem::zeroed();
477 (self.instance_fn_1_0.get_physical_device_features)(physical_device, &mut prop);
481 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDevices.html>
483 pub unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
484 read_into_uninitialized_vector(|count, data| {
485 (self.instance_fn_1_0.enumerate_physical_devices)(self.handle(), count, data)
489 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>
491 pub unsafe fn enumerate_device_extension_properties(
493 device: vk::PhysicalDevice,
494 ) -> VkResult<Vec<vk::ExtensionProperties>> {
495 read_into_uninitialized_vector(|count, data| {
496 (self.instance_fn_1_0.enumerate_device_extension_properties)(
505 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumerateDeviceLayerProperties.html>
507 pub unsafe fn enumerate_device_layer_properties(
509 device: vk::PhysicalDevice,
510 ) -> VkResult<Vec<vk::LayerProperties>> {
511 read_into_uninitialized_vector(|count, data| {
512 (self.instance_fn_1_0.enumerate_device_layer_properties)(device, count, data)
516 /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties.html>
518 pub unsafe fn get_physical_device_sparse_image_format_properties(
520 physical_device: vk::PhysicalDevice,
523 samples: vk::SampleCountFlags,
524 usage: vk::ImageUsageFlags,
525 tiling: vk::ImageTiling,
526 ) -> Vec<vk::SparseImageFormatProperties> {
527 read_into_uninitialized_vector(|count, data| {
530 .get_physical_device_sparse_image_format_properties)(
542 // The closure always returns SUCCESS