ash: Repeatedly call enumeration functions when INCOMPLETE is returned
This commit is contained in:
parent
c6842949de
commit
6fa57a4269
|
@ -1638,24 +1638,14 @@ impl Device {
|
||||||
&self,
|
&self,
|
||||||
pipeline_cache: vk::PipelineCache,
|
pipeline_cache: vk::PipelineCache,
|
||||||
) -> VkResult<Vec<u8>> {
|
) -> VkResult<Vec<u8>> {
|
||||||
let mut data_size: usize = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.device_fn_1_0
|
self.device_fn_1_0.get_pipeline_cache_data(
|
||||||
.get_pipeline_cache_data(
|
|
||||||
self.handle(),
|
self.handle(),
|
||||||
pipeline_cache,
|
pipeline_cache,
|
||||||
&mut data_size,
|
count,
|
||||||
ptr::null_mut(),
|
data as _,
|
||||||
)
|
)
|
||||||
.result()?;
|
})
|
||||||
let mut data: Vec<u8> = Vec::with_capacity(data_size);
|
|
||||||
let err_code = self.device_fn_1_0.get_pipeline_cache_data(
|
|
||||||
self.handle(),
|
|
||||||
pipeline_cache,
|
|
||||||
&mut data_size,
|
|
||||||
data.as_mut_ptr() as _,
|
|
||||||
);
|
|
||||||
data.set_len(data_size);
|
|
||||||
err_code.result_with_success(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkMergePipelineCaches.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkMergePipelineCaches.html>"]
|
||||||
|
@ -2107,21 +2097,16 @@ impl Device {
|
||||||
&self,
|
&self,
|
||||||
image: vk::Image,
|
image: vk::Image,
|
||||||
) -> Vec<vk::SparseImageMemoryRequirements> {
|
) -> Vec<vk::SparseImageMemoryRequirements> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.device_fn_1_0.get_image_sparse_memory_requirements(
|
self.device_fn_1_0.get_image_sparse_memory_requirements(
|
||||||
self.handle(),
|
self.handle(),
|
||||||
image,
|
image,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
);
|
);
|
||||||
let mut data = Vec::with_capacity(count as usize);
|
vk::Result::SUCCESS
|
||||||
self.device_fn_1_0.get_image_sparse_memory_requirements(
|
})
|
||||||
self.handle(),
|
// The closure always returns SUCCESS
|
||||||
image,
|
.unwrap()
|
||||||
&mut count,
|
|
||||||
data.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
data.set_len(count as usize);
|
|
||||||
data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,16 +123,10 @@ impl<L> EntryCustom<L> {
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceLayerProperties.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceLayerProperties.html>"]
|
||||||
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
|
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.entry_fn_1_0
|
self.entry_fn_1_0
|
||||||
.enumerate_instance_layer_properties(&mut count, ptr::null_mut())
|
.enumerate_instance_layer_properties(count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self
|
|
||||||
.entry_fn_1_0
|
|
||||||
.enumerate_instance_layer_properties(&mut count, v.as_mut_ptr());
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,18 +135,10 @@ impl<L> EntryCustom<L> {
|
||||||
&self,
|
&self,
|
||||||
) -> VkResult<Vec<vk::ExtensionProperties>> {
|
) -> VkResult<Vec<vk::ExtensionProperties>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.entry_fn_1_0
|
self.entry_fn_1_0
|
||||||
.enumerate_instance_extension_properties(ptr::null(), &mut count, ptr::null_mut())
|
.enumerate_instance_extension_properties(ptr::null(), count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut data = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.entry_fn_1_0.enumerate_instance_extension_properties(
|
|
||||||
ptr::null(),
|
|
||||||
&mut count,
|
|
||||||
data.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
data.set_len(count as usize);
|
|
||||||
err_code.result_with_success(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::vk;
|
||||||
use crate::{Device, Instance};
|
use crate::{Device, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FullScreenExclusive {
|
pub struct FullScreenExclusive {
|
||||||
|
@ -42,26 +41,15 @@ impl FullScreenExclusive {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR,
|
surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR,
|
||||||
) -> VkResult<Vec<vk::PresentModeKHR>> {
|
) -> VkResult<Vec<vk::PresentModeKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.full_screen_exclusive_fn
|
self.full_screen_exclusive_fn
|
||||||
.get_physical_device_surface_present_modes2_ext(
|
.get_physical_device_surface_present_modes2_ext(
|
||||||
physical_device,
|
physical_device,
|
||||||
surface_info,
|
surface_info,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
)
|
)
|
||||||
.result()?;
|
})
|
||||||
let mut present_modes = Vec::<vk::PresentModeKHR>::with_capacity(count as usize);
|
|
||||||
let err_code = self
|
|
||||||
.full_screen_exclusive_fn
|
|
||||||
.get_physical_device_surface_present_modes2_ext(
|
|
||||||
physical_device,
|
|
||||||
surface_info,
|
|
||||||
&mut count,
|
|
||||||
present_modes.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
present_modes.set_len(count as usize);
|
|
||||||
err_code.result_with_success(present_modes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkReleaseFullScreenExclusiveModeEXT.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkReleaseFullScreenExclusiveModeEXT.html>"]
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::vk;
|
||||||
use crate::{EntryCustom, Instance};
|
use crate::{EntryCustom, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ToolingInfo {
|
pub struct ToolingInfo {
|
||||||
|
@ -31,16 +30,10 @@ impl ToolingInfo {
|
||||||
&self,
|
&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT>> {
|
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.tooling_info_fn
|
self.tooling_info_fn
|
||||||
.get_physical_device_tool_properties_ext(physical_device, &mut count, ptr::null_mut())
|
.get_physical_device_tool_properties_ext(physical_device, count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self
|
|
||||||
.tooling_info_fn
|
|
||||||
.get_physical_device_tool_properties_ext(physical_device, &mut count, v.as_mut_ptr());
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fp(&self) -> &vk::ExtToolingInfoFn {
|
pub fn fp(&self) -> &vk::ExtToolingInfoFn {
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::RawPtr;
|
||||||
use crate::{EntryCustom, Instance};
|
use crate::{EntryCustom, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Display {
|
pub struct Display {
|
||||||
|
@ -32,22 +31,10 @@ impl Display {
|
||||||
&self,
|
&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
) -> VkResult<Vec<vk::DisplayPropertiesKHR>> {
|
) -> VkResult<Vec<vk::DisplayPropertiesKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.display_fn
|
self.display_fn
|
||||||
.get_physical_device_display_properties_khr(
|
.get_physical_device_display_properties_khr(physical_device, count, data)
|
||||||
physical_device,
|
})
|
||||||
&mut count,
|
|
||||||
ptr::null_mut(),
|
|
||||||
)
|
|
||||||
.result()?;
|
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.display_fn.get_physical_device_display_properties_khr(
|
|
||||||
physical_device,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceDisplayPlanePropertiesKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceDisplayPlanePropertiesKHR.html>"]
|
||||||
|
@ -55,27 +42,10 @@ impl Display {
|
||||||
&self,
|
&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
) -> VkResult<Vec<vk::DisplayPlanePropertiesKHR>> {
|
) -> VkResult<Vec<vk::DisplayPlanePropertiesKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
let err_code = self
|
self.display_fn
|
||||||
.display_fn
|
.get_physical_device_display_plane_properties_khr(physical_device, count, data)
|
||||||
.get_physical_device_display_plane_properties_khr(
|
})
|
||||||
physical_device,
|
|
||||||
&mut count,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
if err_code != vk::Result::SUCCESS {
|
|
||||||
return Err(err_code);
|
|
||||||
}
|
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self
|
|
||||||
.display_fn
|
|
||||||
.get_physical_device_display_plane_properties_khr(
|
|
||||||
physical_device,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayPlaneSupportedDisplaysKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayPlaneSupportedDisplaysKHR.html>"]
|
||||||
|
@ -84,24 +54,14 @@ impl Display {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
plane_index: u32,
|
plane_index: u32,
|
||||||
) -> VkResult<Vec<vk::DisplayKHR>> {
|
) -> VkResult<Vec<vk::DisplayKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.display_fn
|
self.display_fn.get_display_plane_supported_displays_khr(
|
||||||
.get_display_plane_supported_displays_khr(
|
|
||||||
physical_device,
|
physical_device,
|
||||||
plane_index,
|
plane_index,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
)
|
)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.display_fn.get_display_plane_supported_displays_khr(
|
|
||||||
physical_device,
|
|
||||||
plane_index,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayModePropertiesKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayModePropertiesKHR.html>"]
|
||||||
|
@ -110,19 +70,10 @@ impl Display {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
display: vk::DisplayKHR,
|
display: vk::DisplayKHR,
|
||||||
) -> VkResult<Vec<vk::DisplayModePropertiesKHR>> {
|
) -> VkResult<Vec<vk::DisplayModePropertiesKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.display_fn
|
self.display_fn
|
||||||
.get_display_mode_properties_khr(physical_device, display, &mut count, ptr::null_mut())
|
.get_display_mode_properties_khr(physical_device, display, count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.display_fn.get_display_mode_properties_khr(
|
|
||||||
physical_device,
|
|
||||||
display,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDisplayModeKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDisplayModeKHR.html>"]
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::vk;
|
||||||
use crate::{EntryCustom, Instance};
|
use crate::{EntryCustom, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PipelineExecutableProperties {
|
pub struct PipelineExecutableProperties {
|
||||||
|
@ -33,27 +32,15 @@ impl PipelineExecutableProperties {
|
||||||
device: vk::Device,
|
device: vk::Device,
|
||||||
executable_info: &vk::PipelineExecutableInfoKHR,
|
executable_info: &vk::PipelineExecutableInfoKHR,
|
||||||
) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR>> {
|
) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR>> {
|
||||||
let mut count = 0;
|
read_into_defaulted_vector(|count, data| {
|
||||||
let err_code = self
|
self.pipeline_executable_properties_fn
|
||||||
.pipeline_executable_properties_fn
|
.get_pipeline_executable_internal_representations_khr(
|
||||||
.get_pipeline_executable_internal_representations_khr(
|
device,
|
||||||
device,
|
executable_info,
|
||||||
executable_info,
|
count,
|
||||||
&mut count,
|
data,
|
||||||
ptr::null_mut(),
|
)
|
||||||
);
|
})
|
||||||
if err_code != vk::Result::SUCCESS {
|
|
||||||
return Err(err_code);
|
|
||||||
}
|
|
||||||
let mut v: Vec<_> = vec![Default::default(); count as usize];
|
|
||||||
self.pipeline_executable_properties_fn
|
|
||||||
.get_pipeline_executable_internal_representations_khr(
|
|
||||||
device,
|
|
||||||
executable_info,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutablePropertiesKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutablePropertiesKHR.html>"]
|
||||||
|
@ -62,27 +49,10 @@ impl PipelineExecutableProperties {
|
||||||
device: vk::Device,
|
device: vk::Device,
|
||||||
pipeline_info: &vk::PipelineInfoKHR,
|
pipeline_info: &vk::PipelineInfoKHR,
|
||||||
) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR>> {
|
) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR>> {
|
||||||
let mut count = 0;
|
read_into_defaulted_vector(|count, data| {
|
||||||
let err_code = self
|
self.pipeline_executable_properties_fn
|
||||||
.pipeline_executable_properties_fn
|
.get_pipeline_executable_properties_khr(device, pipeline_info, count, data)
|
||||||
.get_pipeline_executable_properties_khr(
|
})
|
||||||
device,
|
|
||||||
pipeline_info,
|
|
||||||
&mut count,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
if err_code != vk::Result::SUCCESS {
|
|
||||||
return Err(err_code);
|
|
||||||
}
|
|
||||||
let mut v: Vec<_> = vec![Default::default(); count as usize];
|
|
||||||
self.pipeline_executable_properties_fn
|
|
||||||
.get_pipeline_executable_properties_khr(
|
|
||||||
device,
|
|
||||||
pipeline_info,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableStatisticsKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableStatisticsKHR.html>"]
|
||||||
|
@ -91,27 +61,10 @@ impl PipelineExecutableProperties {
|
||||||
device: vk::Device,
|
device: vk::Device,
|
||||||
executable_info: &vk::PipelineExecutableInfoKHR,
|
executable_info: &vk::PipelineExecutableInfoKHR,
|
||||||
) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR>> {
|
) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR>> {
|
||||||
let mut count = 0;
|
read_into_defaulted_vector(|count, data| {
|
||||||
let err_code = self
|
self.pipeline_executable_properties_fn
|
||||||
.pipeline_executable_properties_fn
|
.get_pipeline_executable_statistics_khr(device, executable_info, count, data)
|
||||||
.get_pipeline_executable_statistics_khr(
|
})
|
||||||
device,
|
|
||||||
executable_info,
|
|
||||||
&mut count,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
if err_code != vk::Result::SUCCESS {
|
|
||||||
return Err(err_code);
|
|
||||||
}
|
|
||||||
let mut v: Vec<_> = vec![Default::default(); count as usize];
|
|
||||||
self.pipeline_executable_properties_fn
|
|
||||||
.get_pipeline_executable_statistics_khr(
|
|
||||||
device,
|
|
||||||
executable_info,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
)
|
|
||||||
.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fp(&self) -> &vk::KhrPipelineExecutablePropertiesFn {
|
pub fn fp(&self) -> &vk::KhrPipelineExecutablePropertiesFn {
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::RawPtr;
|
||||||
use crate::{EntryCustom, Instance};
|
use crate::{EntryCustom, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Surface {
|
pub struct Surface {
|
||||||
|
@ -51,26 +50,15 @@ impl Surface {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
surface: vk::SurfaceKHR,
|
surface: vk::SurfaceKHR,
|
||||||
) -> VkResult<Vec<vk::PresentModeKHR>> {
|
) -> VkResult<Vec<vk::PresentModeKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.surface_fn
|
self.surface_fn
|
||||||
.get_physical_device_surface_present_modes_khr(
|
.get_physical_device_surface_present_modes_khr(
|
||||||
physical_device,
|
physical_device,
|
||||||
surface,
|
surface,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
)
|
)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self
|
|
||||||
.surface_fn
|
|
||||||
.get_physical_device_surface_present_modes_khr(
|
|
||||||
physical_device,
|
|
||||||
surface,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceCapabilitiesKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceCapabilitiesKHR.html>"]
|
||||||
|
@ -95,24 +83,14 @@ impl Surface {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
surface: vk::SurfaceKHR,
|
surface: vk::SurfaceKHR,
|
||||||
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
|
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.surface_fn
|
self.surface_fn.get_physical_device_surface_formats_khr(
|
||||||
.get_physical_device_surface_formats_khr(
|
|
||||||
physical_device,
|
physical_device,
|
||||||
surface,
|
surface,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
)
|
)
|
||||||
.result()?;
|
})
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.surface_fn.get_physical_device_surface_formats_khr(
|
|
||||||
physical_device,
|
|
||||||
surface,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroySurfaceKHR.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroySurfaceKHR.html>"]
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::RawPtr;
|
||||||
use crate::{Device, Instance};
|
use crate::{Device, Instance};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Swapchain {
|
pub struct Swapchain {
|
||||||
|
@ -102,20 +101,10 @@ impl Swapchain {
|
||||||
&self,
|
&self,
|
||||||
swapchain: vk::SwapchainKHR,
|
swapchain: vk::SwapchainKHR,
|
||||||
) -> VkResult<Vec<vk::Image>> {
|
) -> VkResult<Vec<vk::Image>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.swapchain_fn
|
self.swapchain_fn
|
||||||
.get_swapchain_images_khr(self.handle, swapchain, &mut count, ptr::null_mut())
|
.get_swapchain_images_khr(self.handle, swapchain, count, data)
|
||||||
.result()?;
|
})
|
||||||
|
|
||||||
let mut v = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.swapchain_fn.get_swapchain_images_khr(
|
|
||||||
self.handle,
|
|
||||||
swapchain,
|
|
||||||
&mut count,
|
|
||||||
v.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
v.set_len(count as usize);
|
|
||||||
err_code.result_with_success(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fp(&self) -> &vk::KhrSwapchainFn {
|
pub fn fp(&self) -> &vk::KhrSwapchainFn {
|
||||||
|
|
|
@ -348,22 +348,13 @@ impl Instance {
|
||||||
&self,
|
&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
) -> Vec<vk::QueueFamilyProperties> {
|
) -> Vec<vk::QueueFamilyProperties> {
|
||||||
let mut queue_count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.instance_fn_1_0
|
self.instance_fn_1_0
|
||||||
.get_physical_device_queue_family_properties(
|
.get_physical_device_queue_family_properties(physical_device, count, data);
|
||||||
physical_device,
|
vk::Result::SUCCESS
|
||||||
&mut queue_count,
|
})
|
||||||
ptr::null_mut(),
|
// The closure always returns SUCCESS
|
||||||
);
|
.unwrap()
|
||||||
let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
|
|
||||||
self.instance_fn_1_0
|
|
||||||
.get_physical_device_queue_family_properties(
|
|
||||||
physical_device,
|
|
||||||
&mut queue_count,
|
|
||||||
queue_families_vec.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
queue_families_vec.set_len(queue_count as usize);
|
|
||||||
queue_families_vec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures.html>"]
|
||||||
|
@ -379,18 +370,10 @@ impl Instance {
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html>"]
|
||||||
pub unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
|
pub unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.instance_fn_1_0
|
self.instance_fn_1_0
|
||||||
.enumerate_physical_devices(self.handle(), &mut count, ptr::null_mut())
|
.enumerate_physical_devices(self.handle(), count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(count as usize);
|
|
||||||
let err_code = self.instance_fn_1_0.enumerate_physical_devices(
|
|
||||||
self.handle(),
|
|
||||||
&mut count,
|
|
||||||
physical_devices.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
physical_devices.set_len(count as usize);
|
|
||||||
err_code.result_with_success(physical_devices)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>"]
|
||||||
|
@ -398,19 +381,14 @@ impl Instance {
|
||||||
&self,
|
&self,
|
||||||
device: vk::PhysicalDevice,
|
device: vk::PhysicalDevice,
|
||||||
) -> VkResult<Vec<vk::ExtensionProperties>> {
|
) -> VkResult<Vec<vk::ExtensionProperties>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.instance_fn_1_0
|
self.instance_fn_1_0.enumerate_device_extension_properties(
|
||||||
.enumerate_device_extension_properties(device, ptr::null(), &mut count, ptr::null_mut())
|
device,
|
||||||
.result()?;
|
ptr::null(),
|
||||||
let mut data = Vec::with_capacity(count as usize);
|
count,
|
||||||
let err_code = self.instance_fn_1_0.enumerate_device_extension_properties(
|
data,
|
||||||
device,
|
)
|
||||||
ptr::null(),
|
})
|
||||||
&mut count,
|
|
||||||
data.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
data.set_len(count as usize);
|
|
||||||
err_code.result_with_success(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceLayerProperties.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceLayerProperties.html>"]
|
||||||
|
@ -418,18 +396,10 @@ impl Instance {
|
||||||
&self,
|
&self,
|
||||||
device: vk::PhysicalDevice,
|
device: vk::PhysicalDevice,
|
||||||
) -> VkResult<Vec<vk::LayerProperties>> {
|
) -> VkResult<Vec<vk::LayerProperties>> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.instance_fn_1_0
|
self.instance_fn_1_0
|
||||||
.enumerate_device_layer_properties(device, &mut count, ptr::null_mut())
|
.enumerate_device_layer_properties(device, count, data)
|
||||||
.result()?;
|
})
|
||||||
let mut data = Vec::with_capacity(count as usize);
|
|
||||||
let err_code = self.instance_fn_1_0.enumerate_device_layer_properties(
|
|
||||||
device,
|
|
||||||
&mut count,
|
|
||||||
data.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
data.set_len(count as usize);
|
|
||||||
err_code.result_with_success(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties.html>"]
|
||||||
|
@ -442,31 +412,21 @@ impl Instance {
|
||||||
usage: vk::ImageUsageFlags,
|
usage: vk::ImageUsageFlags,
|
||||||
tiling: vk::ImageTiling,
|
tiling: vk::ImageTiling,
|
||||||
) -> Vec<vk::SparseImageFormatProperties> {
|
) -> Vec<vk::SparseImageFormatProperties> {
|
||||||
let mut count = 0;
|
read_into_uninitialized_vector(|count, data| {
|
||||||
self.instance_fn_1_0
|
self.instance_fn_1_0
|
||||||
.get_physical_device_sparse_image_format_properties(
|
.get_physical_device_sparse_image_format_properties(
|
||||||
physical_device,
|
physical_device,
|
||||||
format,
|
format,
|
||||||
typ,
|
typ,
|
||||||
samples,
|
samples,
|
||||||
usage,
|
usage,
|
||||||
tiling,
|
tiling,
|
||||||
&mut count,
|
count,
|
||||||
ptr::null_mut(),
|
data,
|
||||||
);
|
);
|
||||||
let mut data = Vec::with_capacity(count as usize);
|
vk::Result::SUCCESS
|
||||||
self.instance_fn_1_0
|
})
|
||||||
.get_physical_device_sparse_image_format_properties(
|
// The closure always returns SUCCESS
|
||||||
physical_device,
|
.unwrap()
|
||||||
format,
|
|
||||||
typ,
|
|
||||||
samples,
|
|
||||||
usage,
|
|
||||||
tiling,
|
|
||||||
&mut count,
|
|
||||||
data.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
data.set_len(count as usize);
|
|
||||||
data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use crate::vk;
|
use crate::vk;
|
||||||
pub type VkResult<T> = Result<T, vk::Result>;
|
pub type VkResult<T> = Result<T, vk::Result>;
|
||||||
|
|
||||||
|
@ -19,3 +21,69 @@ impl vk::Result {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore,
|
||||||
|
/// ensuring all available data has been read into the vector.
|
||||||
|
///
|
||||||
|
/// See for example [`vkEnumerateInstanceExtensionProperties`]: the number of available
|
||||||
|
/// items may change between calls; [`vk::Result::INCOMPLETE`] is returned when the count
|
||||||
|
/// increased (and the vector is not large enough after querying the initial size),
|
||||||
|
/// requiring Ash to try again.
|
||||||
|
///
|
||||||
|
/// [`vkEnumerateInstanceExtensionProperties`]: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceExtensionProperties.html
|
||||||
|
pub(crate) unsafe fn read_into_uninitialized_vector<N: Copy + Default + TryInto<usize>, T>(
|
||||||
|
f: impl Fn(&mut N, *mut T) -> vk::Result,
|
||||||
|
) -> VkResult<Vec<T>>
|
||||||
|
where
|
||||||
|
<N as TryInto<usize>>::Error: std::fmt::Debug,
|
||||||
|
{
|
||||||
|
loop {
|
||||||
|
let mut count = N::default();
|
||||||
|
f(&mut count, std::ptr::null_mut()).result()?;
|
||||||
|
let mut data =
|
||||||
|
Vec::with_capacity(count.try_into().expect("`N` failed to convert to `usize`"));
|
||||||
|
|
||||||
|
let err_code = f(&mut count, data.as_mut_ptr());
|
||||||
|
if err_code != vk::Result::INCOMPLETE {
|
||||||
|
data.set_len(count.try_into().expect("`N` failed to convert to `usize`"));
|
||||||
|
break err_code.result_with_success(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore,
|
||||||
|
/// ensuring all available data has been read into the vector.
|
||||||
|
///
|
||||||
|
/// Items in the target vector are [`default()`][`Default::default()`]-initialized which
|
||||||
|
/// is required for [`vk::BaseOutStructure`]-like structs where [`vk::BaseOutStructure::s_type`]
|
||||||
|
/// needs to be a valid type and [`vk::BaseOutStructure::p_next`] a valid or
|
||||||
|
/// [`null`][`std::ptr::null_mut()`] pointer.
|
||||||
|
///
|
||||||
|
/// See for example [`vkEnumerateInstanceExtensionProperties`]: the number of available
|
||||||
|
/// items may change between calls; [`vk::Result::INCOMPLETE`] is returned when the count
|
||||||
|
/// increased (and the vector is not large enough after querying the initial size),
|
||||||
|
/// requiring Ash to try again.
|
||||||
|
///
|
||||||
|
/// [`vkEnumerateInstanceExtensionProperties`]: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceExtensionProperties.html
|
||||||
|
pub(crate) unsafe fn read_into_defaulted_vector<
|
||||||
|
N: Copy + Default + TryInto<usize>,
|
||||||
|
T: Default + Clone,
|
||||||
|
>(
|
||||||
|
f: impl Fn(&mut N, *mut T) -> vk::Result,
|
||||||
|
) -> VkResult<Vec<T>>
|
||||||
|
where
|
||||||
|
<N as TryInto<usize>>::Error: std::fmt::Debug,
|
||||||
|
{
|
||||||
|
loop {
|
||||||
|
let mut count = N::default();
|
||||||
|
f(&mut count, std::ptr::null_mut()).result()?;
|
||||||
|
let mut data =
|
||||||
|
vec![Default::default(); count.try_into().expect("`N` failed to convert to `usize`")];
|
||||||
|
|
||||||
|
let err_code = f(&mut count, data.as_mut_ptr());
|
||||||
|
if err_code != vk::Result::INCOMPLETE {
|
||||||
|
data.set_len(count.try_into().expect("`N` failed to convert to `usize`"));
|
||||||
|
break err_code.result_with_success(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue