Inline Default impls and trivial instance/device wrapper methods (#606)

This commit is contained in:
Benjamin Saunders 2022-03-29 10:54:38 -07:00 committed by Marijn Suijten
parent e43e9c0c9b
commit 29cf7c2a4c
5 changed files with 886 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,7 @@ impl Instance {
} }
} }
#[inline]
pub fn handle(&self) -> vk::Instance { pub fn handle(&self) -> vk::Instance {
self.handle self.handle
} }
@ -41,11 +42,13 @@ impl Instance {
/// Vulkan core 1.3 /// Vulkan core 1.3
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
impl Instance { impl Instance {
#[inline]
pub fn fp_v1_3(&self) -> &vk::InstanceFnV1_3 { pub fn fp_v1_3(&self) -> &vk::InstanceFnV1_3 {
&self.instance_fn_1_3 &self.instance_fn_1_3
} }
/// Retrieve the number of elements to pass to [`get_physical_device_tool_properties()`][Self::get_physical_device_tool_properties()] /// Retrieve the number of elements to pass to [`get_physical_device_tool_properties()`][Self::get_physical_device_tool_properties()]
#[inline]
pub unsafe fn get_physical_device_tool_properties_len( pub unsafe fn get_physical_device_tool_properties_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -63,6 +66,7 @@ impl Instance {
/// ///
/// Call [`get_physical_device_tool_properties_len()`][Self::get_physical_device_tool_properties_len()] to query the number of elements to pass to `out`. /// Call [`get_physical_device_tool_properties_len()`][Self::get_physical_device_tool_properties_len()] to query the number of elements to pass to `out`.
/// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
#[inline]
pub unsafe fn get_physical_device_tool_properties( pub unsafe fn get_physical_device_tool_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -83,6 +87,7 @@ impl Instance {
/// Vulkan core 1.2 /// Vulkan core 1.2
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
impl Instance { impl Instance {
#[inline]
pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 { pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
&self.instance_fn_1_2 &self.instance_fn_1_2
} }
@ -91,11 +96,13 @@ impl Instance {
/// Vulkan core 1.1 /// Vulkan core 1.1
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
impl Instance { impl Instance {
#[inline]
pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 { pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 {
&self.instance_fn_1_1 &self.instance_fn_1_1
} }
/// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()] /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()]
#[inline]
pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> { pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
let mut group_count = 0; let mut group_count = 0;
(self.instance_fn_1_1.enumerate_physical_device_groups)( (self.instance_fn_1_1.enumerate_physical_device_groups)(
@ -110,6 +117,7 @@ impl Instance {
/// ///
/// Call [`enumerate_physical_device_groups_len()`][Self::enumerate_physical_device_groups_len()] to query the number of elements to pass to `out`. /// Call [`enumerate_physical_device_groups_len()`][Self::enumerate_physical_device_groups_len()] to query the number of elements to pass to `out`.
/// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
#[inline]
pub unsafe fn enumerate_physical_device_groups( pub unsafe fn enumerate_physical_device_groups(
&self, &self,
out: &mut [vk::PhysicalDeviceGroupProperties], out: &mut [vk::PhysicalDeviceGroupProperties],
@ -126,6 +134,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures2.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>
#[inline]
pub unsafe fn get_physical_device_features2( pub unsafe fn get_physical_device_features2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -135,6 +144,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties2.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties2.html>
#[inline]
pub unsafe fn get_physical_device_properties2( pub unsafe fn get_physical_device_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -144,6 +154,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html>
#[inline]
pub unsafe fn get_physical_device_format_properties2( pub unsafe fn get_physical_device_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -154,6 +165,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html>
#[inline]
pub unsafe fn get_physical_device_image_format_properties2( pub unsafe fn get_physical_device_image_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -171,6 +183,7 @@ impl Instance {
} }
/// Retrieve the number of elements to pass to [`get_physical_device_queue_family_properties2()`][Self::get_physical_device_queue_family_properties2()] /// Retrieve the number of elements to pass to [`get_physical_device_queue_family_properties2()`][Self::get_physical_device_queue_family_properties2()]
#[inline]
pub unsafe fn get_physical_device_queue_family_properties2_len( pub unsafe fn get_physical_device_queue_family_properties2_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -190,6 +203,7 @@ impl Instance {
/// ///
/// 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`. /// 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`.
/// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
#[inline]
pub unsafe fn get_physical_device_queue_family_properties2( pub unsafe fn get_physical_device_queue_family_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -207,6 +221,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>
#[inline]
pub unsafe fn get_physical_device_memory_properties2( pub unsafe fn get_physical_device_memory_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -216,6 +231,7 @@ impl Instance {
} }
/// Retrieve the number of elements to pass to [`get_physical_device_sparse_image_format_properties2()`][Self::get_physical_device_sparse_image_format_properties2()] /// Retrieve the number of elements to pass to [`get_physical_device_sparse_image_format_properties2()`][Self::get_physical_device_sparse_image_format_properties2()]
#[inline]
pub unsafe fn get_physical_device_sparse_image_format_properties2_len( pub unsafe fn get_physical_device_sparse_image_format_properties2_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -237,6 +253,7 @@ impl Instance {
/// ///
/// 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`. /// 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`.
/// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
#[inline]
pub unsafe fn get_physical_device_sparse_image_format_properties2( pub unsafe fn get_physical_device_sparse_image_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -256,6 +273,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>
#[inline]
pub unsafe fn get_physical_device_external_buffer_properties( pub unsafe fn get_physical_device_external_buffer_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -272,6 +290,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html>
#[inline]
pub unsafe fn get_physical_device_external_fence_properties( pub unsafe fn get_physical_device_external_fence_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -288,6 +307,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html>
#[inline]
pub unsafe fn get_physical_device_external_semaphore_properties( pub unsafe fn get_physical_device_external_semaphore_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -307,6 +327,7 @@ impl Instance {
/// Vulkan core 1.0 /// Vulkan core 1.0
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
impl Instance { impl Instance {
#[inline]
pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 { pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
&self.instance_fn_1_0 &self.instance_fn_1_0
} }
@ -317,6 +338,7 @@ impl Instance {
/// In order for the created [`Device`] to be valid for the duration of its /// In order for the created [`Device`] to be valid for the duration of its
/// usage, the [`Instance`] this was called on must be dropped later than the /// usage, the [`Instance`] this was called on must be dropped later than the
/// resulting [`Device`]. /// resulting [`Device`].
#[inline]
pub unsafe fn create_device( pub unsafe fn create_device(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -335,6 +357,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceProcAddr.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceProcAddr.html>
#[inline]
pub unsafe fn get_device_proc_addr( pub unsafe fn get_device_proc_addr(
&self, &self,
device: vk::Device, device: vk::Device,
@ -344,11 +367,13 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyInstance.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyInstance.html>
#[inline]
pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) { pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
(self.instance_fn_1_0.destroy_instance)(self.handle(), allocation_callbacks.as_raw_ptr()); (self.instance_fn_1_0.destroy_instance)(self.handle(), allocation_callbacks.as_raw_ptr());
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html>
#[inline]
pub unsafe fn get_physical_device_format_properties( pub unsafe fn get_physical_device_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -364,6 +389,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>
#[inline]
pub unsafe fn get_physical_device_image_format_properties( pub unsafe fn get_physical_device_image_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -389,6 +415,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>
#[inline]
pub unsafe fn get_physical_device_memory_properties( pub unsafe fn get_physical_device_memory_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -402,6 +429,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties.html>
#[inline]
pub unsafe fn get_physical_device_properties( pub unsafe fn get_physical_device_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
@ -429,6 +457,7 @@ impl Instance {
} }
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures.html> /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceFeatures.html>
#[inline]
pub unsafe fn get_physical_device_features( pub unsafe fn get_physical_device_features(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,

View file

@ -6,10 +6,12 @@ use crate::vk;
pub type VkResult<T> = Result<T, vk::Result>; pub type VkResult<T> = Result<T, vk::Result>;
impl vk::Result { impl vk::Result {
#[inline]
pub fn result(self) -> VkResult<()> { pub fn result(self) -> VkResult<()> {
self.result_with_success(()) self.result_with_success(())
} }
#[inline]
pub fn result_with_success<T>(self, v: T) -> VkResult<T> { pub fn result_with_success<T>(self, v: T) -> VkResult<T> {
match self { match self {
Self::SUCCESS => Ok(v), Self::SUCCESS => Ok(v),

File diff suppressed because it is too large Load diff

View file

@ -1429,6 +1429,7 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<TokenStream> {
}); });
let q = quote! { let q = quote! {
impl ::std::default::Default for #name { impl ::std::default::Default for #name {
#[inline]
fn default() -> Self { fn default() -> Self {
Self { Self {
#( #(
@ -2016,6 +2017,7 @@ fn generate_union(union: &vkxml::Union) -> TokenStream {
#(#fields),* #(#fields),*
} }
impl ::std::default::Default for #name { impl ::std::default::Default for #name {
#[inline]
fn default() -> Self { fn default() -> Self {
unsafe { ::std::mem::zeroed() } unsafe { ::std::mem::zeroed() }
} }