1 use crate::device::Device; 2 use crate::prelude::*; 3 use crate::vk; 4 use crate::RawPtr; 5 use std::mem; 6 use std::os::raw::c_char; 7 use std::ptr; 8 9 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkInstance.html>"] 10 #[derive(Clone)] 11 pub struct Instance { 12 pub(crate) handle: vk::Instance, 13 14 pub(crate) instance_fn_1_0: vk::InstanceFnV1_0, 15 pub(crate) instance_fn_1_1: vk::InstanceFnV1_1, 16 pub(crate) instance_fn_1_2: vk::InstanceFnV1_2, 17 } 18 19 impl Instance { load(static_fn: &vk::StaticFn, instance: vk::Instance) -> Self20 pub unsafe fn load(static_fn: &vk::StaticFn, instance: vk::Instance) -> Self { 21 let load_fn = |name: &std::ffi::CStr| { 22 mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr())) 23 }; 24 25 Self { 26 handle: instance, 27 28 instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn), 29 instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn), 30 instance_fn_1_2: vk::InstanceFnV1_2::load(load_fn), 31 } 32 } 33 handle(&self) -> vk::Instance34 pub fn handle(&self) -> vk::Instance { 35 self.handle 36 } 37 } 38 39 /// Vulkan core 1.2 40 #[allow(non_camel_case_types)] 41 impl Instance { fp_v1_2(&self) -> &vk::InstanceFnV1_242 pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 { 43 &self.instance_fn_1_2 44 } 45 } 46 47 /// Vulkan core 1.1 48 #[allow(non_camel_case_types)] 49 impl Instance { fp_v1_1(&self) -> &vk::InstanceFnV1_150 pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 { 51 &self.instance_fn_1_1 52 } 53 54 /// Retrieve the number of elements to pass to [`Self::enumerate_physical_device_groups()`] enumerate_physical_device_groups_len(&self) -> VkResult<usize>55 pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> { 56 let mut group_count = 0; 57 self.instance_fn_1_1 58 .enumerate_physical_device_groups(self.handle(), &mut group_count, ptr::null_mut()) 59 .result_with_success(group_count as usize) 60 } 61 62 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDeviceGroups.html>"] 63 /// 64 /// Call [`Self::enumerate_physical_device_groups_len()`] to query the number of elements to pass to `out`. 65 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. enumerate_physical_device_groups( &self, out: &mut [vk::PhysicalDeviceGroupProperties], ) -> VkResult<()>66 pub unsafe fn enumerate_physical_device_groups( 67 &self, 68 out: &mut [vk::PhysicalDeviceGroupProperties], 69 ) -> VkResult<()> { 70 let mut group_count = out.len() as u32; 71 self.instance_fn_1_1 72 .enumerate_physical_device_groups(self.handle(), &mut group_count, out.as_mut_ptr()) 73 .result() 74 } 75 76 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"] get_physical_device_features2( &self, physical_device: vk::PhysicalDevice, features: &mut vk::PhysicalDeviceFeatures2, )77 pub unsafe fn get_physical_device_features2( 78 &self, 79 physical_device: vk::PhysicalDevice, 80 features: &mut vk::PhysicalDeviceFeatures2, 81 ) { 82 self.instance_fn_1_1 83 .get_physical_device_features2(physical_device, features); 84 } 85 86 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties2.html>"] get_physical_device_properties2( &self, physical_device: vk::PhysicalDevice, prop: &mut vk::PhysicalDeviceProperties2, )87 pub unsafe fn get_physical_device_properties2( 88 &self, 89 physical_device: vk::PhysicalDevice, 90 prop: &mut vk::PhysicalDeviceProperties2, 91 ) { 92 self.instance_fn_1_1 93 .get_physical_device_properties2(physical_device, prop); 94 } 95 96 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html>"] get_physical_device_format_properties2( &self, physical_device: vk::PhysicalDevice, format: vk::Format, out: &mut vk::FormatProperties2, )97 pub unsafe fn get_physical_device_format_properties2( 98 &self, 99 physical_device: vk::PhysicalDevice, 100 format: vk::Format, 101 out: &mut vk::FormatProperties2, 102 ) { 103 self.instance_fn_1_1 104 .get_physical_device_format_properties2(physical_device, format, out); 105 } 106 107 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html>"] get_physical_device_image_format_properties2( &self, physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceImageFormatInfo2, image_format_prop: &mut vk::ImageFormatProperties2, ) -> VkResult<()>108 pub unsafe fn get_physical_device_image_format_properties2( 109 &self, 110 physical_device: vk::PhysicalDevice, 111 format_info: &vk::PhysicalDeviceImageFormatInfo2, 112 image_format_prop: &mut vk::ImageFormatProperties2, 113 ) -> VkResult<()> { 114 self.instance_fn_1_1 115 .get_physical_device_image_format_properties2( 116 physical_device, 117 format_info, 118 image_format_prop, 119 ) 120 .result() 121 } 122 123 /// Retrieve the number of elements to pass to [`Self::get_physical_device_queue_family_properties2()`] get_physical_device_queue_family_properties2_len( &self, physical_device: vk::PhysicalDevice, ) -> usize124 pub unsafe fn get_physical_device_queue_family_properties2_len( 125 &self, 126 physical_device: vk::PhysicalDevice, 127 ) -> usize { 128 let mut queue_count = 0; 129 self.instance_fn_1_1 130 .get_physical_device_queue_family_properties2( 131 physical_device, 132 &mut queue_count, 133 ptr::null_mut(), 134 ); 135 queue_count as usize 136 } 137 138 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2.html>"] 139 /// 140 /// Call [`Self::get_physical_device_queue_family_properties2_len()`] to query the number of elements to pass to `out`. 141 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. get_physical_device_queue_family_properties2( &self, physical_device: vk::PhysicalDevice, out: &mut [vk::QueueFamilyProperties2], )142 pub unsafe fn get_physical_device_queue_family_properties2( 143 &self, 144 physical_device: vk::PhysicalDevice, 145 out: &mut [vk::QueueFamilyProperties2], 146 ) { 147 let mut queue_count = out.len() as u32; 148 self.instance_fn_1_1 149 .get_physical_device_queue_family_properties2( 150 physical_device, 151 &mut queue_count, 152 out.as_mut_ptr(), 153 ); 154 } 155 156 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"] get_physical_device_memory_properties2( &self, physical_device: vk::PhysicalDevice, out: &mut vk::PhysicalDeviceMemoryProperties2, )157 pub unsafe fn get_physical_device_memory_properties2( 158 &self, 159 physical_device: vk::PhysicalDevice, 160 out: &mut vk::PhysicalDeviceMemoryProperties2, 161 ) { 162 self.instance_fn_1_1 163 .get_physical_device_memory_properties2(physical_device, out); 164 } 165 166 /// Retrieve the number of elements to pass to [`Self::get_physical_device_sparse_image_format_properties2()`] get_physical_device_sparse_image_format_properties2_len( &self, physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, ) -> usize167 pub unsafe fn get_physical_device_sparse_image_format_properties2_len( 168 &self, 169 physical_device: vk::PhysicalDevice, 170 format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, 171 ) -> usize { 172 let mut format_count = 0; 173 self.instance_fn_1_1 174 .get_physical_device_sparse_image_format_properties2( 175 physical_device, 176 format_info, 177 &mut format_count, 178 ptr::null_mut(), 179 ); 180 format_count as usize 181 } 182 183 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2.html>"] 184 /// 185 /// Call [`Self::get_physical_device_sparse_image_format_properties2_len()`] to query the number of elements to pass to `out`. 186 /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. get_physical_device_sparse_image_format_properties2( &self, physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, out: &mut [vk::SparseImageFormatProperties2], )187 pub unsafe fn get_physical_device_sparse_image_format_properties2( 188 &self, 189 physical_device: vk::PhysicalDevice, 190 format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, 191 out: &mut [vk::SparseImageFormatProperties2], 192 ) { 193 let mut format_count = out.len() as u32; 194 self.instance_fn_1_1 195 .get_physical_device_sparse_image_format_properties2( 196 physical_device, 197 format_info, 198 &mut format_count, 199 out.as_mut_ptr(), 200 ); 201 } 202 203 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"] get_physical_device_external_buffer_properties( &self, physical_device: vk::PhysicalDevice, external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo, out: &mut vk::ExternalBufferProperties, )204 pub unsafe fn get_physical_device_external_buffer_properties( 205 &self, 206 physical_device: vk::PhysicalDevice, 207 external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo, 208 out: &mut vk::ExternalBufferProperties, 209 ) { 210 self.instance_fn_1_1 211 .get_physical_device_external_buffer_properties( 212 physical_device, 213 external_buffer_info, 214 out, 215 ); 216 } 217 218 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html>"] get_physical_device_external_fence_properties( &self, physical_device: vk::PhysicalDevice, external_fence_info: &vk::PhysicalDeviceExternalFenceInfo, out: &mut vk::ExternalFenceProperties, )219 pub unsafe fn get_physical_device_external_fence_properties( 220 &self, 221 physical_device: vk::PhysicalDevice, 222 external_fence_info: &vk::PhysicalDeviceExternalFenceInfo, 223 out: &mut vk::ExternalFenceProperties, 224 ) { 225 self.instance_fn_1_1 226 .get_physical_device_external_fence_properties( 227 physical_device, 228 external_fence_info, 229 out, 230 ); 231 } 232 233 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html>"] get_physical_device_external_semaphore_properties( &self, physical_device: vk::PhysicalDevice, external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo, out: &mut vk::ExternalSemaphoreProperties, )234 pub unsafe fn get_physical_device_external_semaphore_properties( 235 &self, 236 physical_device: vk::PhysicalDevice, 237 external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo, 238 out: &mut vk::ExternalSemaphoreProperties, 239 ) { 240 self.instance_fn_1_1 241 .get_physical_device_external_semaphore_properties( 242 physical_device, 243 external_semaphore_info, 244 out, 245 ); 246 } 247 } 248 249 /// Vulkan core 1.0 250 #[allow(non_camel_case_types)] 251 impl Instance { fp_v1_0(&self) -> &vk::InstanceFnV1_0252 pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 { 253 &self.instance_fn_1_0 254 } 255 256 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"] 257 /// 258 /// # Safety 259 /// In order for the created [`Device`] to be valid for the duration of its 260 /// usage, the [`Instance`] this was called on must be dropped later than the 261 /// resulting [`Device`]. create_device( &self, physical_device: vk::PhysicalDevice, create_info: &vk::DeviceCreateInfo, allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<Device>262 pub unsafe fn create_device( 263 &self, 264 physical_device: vk::PhysicalDevice, 265 create_info: &vk::DeviceCreateInfo, 266 allocation_callbacks: Option<&vk::AllocationCallbacks>, 267 ) -> VkResult<Device> { 268 let mut device = mem::zeroed(); 269 self.instance_fn_1_0 270 .create_device( 271 physical_device, 272 create_info, 273 allocation_callbacks.as_raw_ptr(), 274 &mut device, 275 ) 276 .result()?; 277 Ok(Device::load(&self.instance_fn_1_0, device)) 278 } 279 280 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceProcAddr.html>"] get_device_proc_addr( &self, device: vk::Device, p_name: *const c_char, ) -> vk::PFN_vkVoidFunction281 pub unsafe fn get_device_proc_addr( 282 &self, 283 device: vk::Device, 284 p_name: *const c_char, 285 ) -> vk::PFN_vkVoidFunction { 286 self.instance_fn_1_0.get_device_proc_addr(device, p_name) 287 } 288 289 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroyInstance.html>"] destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>)290 pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) { 291 self.instance_fn_1_0 292 .destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr()); 293 } 294 295 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html>"] get_physical_device_format_properties( &self, physical_device: vk::PhysicalDevice, format: vk::Format, ) -> vk::FormatProperties296 pub unsafe fn get_physical_device_format_properties( 297 &self, 298 physical_device: vk::PhysicalDevice, 299 format: vk::Format, 300 ) -> vk::FormatProperties { 301 let mut format_prop = mem::zeroed(); 302 self.instance_fn_1_0.get_physical_device_format_properties( 303 physical_device, 304 format, 305 &mut format_prop, 306 ); 307 format_prop 308 } 309 310 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>"] get_physical_device_image_format_properties( &self, physical_device: vk::PhysicalDevice, format: vk::Format, typ: vk::ImageType, tiling: vk::ImageTiling, usage: vk::ImageUsageFlags, flags: vk::ImageCreateFlags, ) -> VkResult<vk::ImageFormatProperties>311 pub unsafe fn get_physical_device_image_format_properties( 312 &self, 313 physical_device: vk::PhysicalDevice, 314 format: vk::Format, 315 typ: vk::ImageType, 316 tiling: vk::ImageTiling, 317 usage: vk::ImageUsageFlags, 318 flags: vk::ImageCreateFlags, 319 ) -> VkResult<vk::ImageFormatProperties> { 320 let mut image_format_prop = mem::zeroed(); 321 self.instance_fn_1_0 322 .get_physical_device_image_format_properties( 323 physical_device, 324 format, 325 typ, 326 tiling, 327 usage, 328 flags, 329 &mut image_format_prop, 330 ) 331 .result_with_success(image_format_prop) 332 } 333 334 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>"] get_physical_device_memory_properties( &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceMemoryProperties335 pub unsafe fn get_physical_device_memory_properties( 336 &self, 337 physical_device: vk::PhysicalDevice, 338 ) -> vk::PhysicalDeviceMemoryProperties { 339 let mut memory_prop = mem::zeroed(); 340 self.instance_fn_1_0 341 .get_physical_device_memory_properties(physical_device, &mut memory_prop); 342 memory_prop 343 } 344 345 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties.html>"] get_physical_device_properties( &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceProperties346 pub unsafe fn get_physical_device_properties( 347 &self, 348 physical_device: vk::PhysicalDevice, 349 ) -> vk::PhysicalDeviceProperties { 350 let mut prop = mem::zeroed(); 351 self.instance_fn_1_0 352 .get_physical_device_properties(physical_device, &mut prop); 353 prop 354 } 355 356 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties.html>"] get_physical_device_queue_family_properties( &self, physical_device: vk::PhysicalDevice, ) -> Vec<vk::QueueFamilyProperties>357 pub unsafe fn get_physical_device_queue_family_properties( 358 &self, 359 physical_device: vk::PhysicalDevice, 360 ) -> Vec<vk::QueueFamilyProperties> { 361 read_into_uninitialized_vector(|count, data| { 362 self.instance_fn_1_0 363 .get_physical_device_queue_family_properties(physical_device, count, data); 364 vk::Result::SUCCESS 365 }) 366 // The closure always returns SUCCESS 367 .unwrap() 368 } 369 370 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures.html>"] get_physical_device_features( &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceFeatures371 pub unsafe fn get_physical_device_features( 372 &self, 373 physical_device: vk::PhysicalDevice, 374 ) -> vk::PhysicalDeviceFeatures { 375 let mut prop = mem::zeroed(); 376 self.instance_fn_1_0 377 .get_physical_device_features(physical_device, &mut prop); 378 prop 379 } 380 381 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html>"] enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>>382 pub unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> { 383 read_into_uninitialized_vector(|count, data| { 384 self.instance_fn_1_0 385 .enumerate_physical_devices(self.handle(), count, data) 386 }) 387 } 388 389 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>"] enumerate_device_extension_properties( &self, device: vk::PhysicalDevice, ) -> VkResult<Vec<vk::ExtensionProperties>>390 pub unsafe fn enumerate_device_extension_properties( 391 &self, 392 device: vk::PhysicalDevice, 393 ) -> VkResult<Vec<vk::ExtensionProperties>> { 394 read_into_uninitialized_vector(|count, data| { 395 self.instance_fn_1_0.enumerate_device_extension_properties( 396 device, 397 ptr::null(), 398 count, 399 data, 400 ) 401 }) 402 } 403 404 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceLayerProperties.html>"] enumerate_device_layer_properties( &self, device: vk::PhysicalDevice, ) -> VkResult<Vec<vk::LayerProperties>>405 pub unsafe fn enumerate_device_layer_properties( 406 &self, 407 device: vk::PhysicalDevice, 408 ) -> VkResult<Vec<vk::LayerProperties>> { 409 read_into_uninitialized_vector(|count, data| { 410 self.instance_fn_1_0 411 .enumerate_device_layer_properties(device, count, data) 412 }) 413 } 414 415 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties.html>"] get_physical_device_sparse_image_format_properties( &self, physical_device: vk::PhysicalDevice, format: vk::Format, typ: vk::ImageType, samples: vk::SampleCountFlags, usage: vk::ImageUsageFlags, tiling: vk::ImageTiling, ) -> Vec<vk::SparseImageFormatProperties>416 pub unsafe fn get_physical_device_sparse_image_format_properties( 417 &self, 418 physical_device: vk::PhysicalDevice, 419 format: vk::Format, 420 typ: vk::ImageType, 421 samples: vk::SampleCountFlags, 422 usage: vk::ImageUsageFlags, 423 tiling: vk::ImageTiling, 424 ) -> Vec<vk::SparseImageFormatProperties> { 425 read_into_uninitialized_vector(|count, data| { 426 self.instance_fn_1_0 427 .get_physical_device_sparse_image_format_properties( 428 physical_device, 429 format, 430 typ, 431 samples, 432 usage, 433 tiling, 434 count, 435 data, 436 ); 437 vk::Result::SUCCESS 438 }) 439 // The closure always returns SUCCESS 440 .unwrap() 441 } 442 } 443