Merge pull request #131 from Ralith/unsafety

Add missing unsafe qualifiers
This commit is contained in:
Maik Klein 2018-10-08 11:01:53 +02:00 committed by GitHub
commit ef40f130a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 238 additions and 279 deletions

View file

@ -652,13 +652,11 @@ pub trait DeviceV1_0 {
}
}
fn device_wait_idle(&self) -> VkResult<()> {
unsafe {
let err_code = self.fp_v1_0().device_wait_idle(self.handle());
match err_code {
vk::Result::SUCCESS => Ok(()),
_ => Err(err_code),
}
unsafe fn device_wait_idle(&self) -> VkResult<()> {
let err_code = self.fp_v1_0().device_wait_idle(self.handle());
match err_code {
vk::Result::SUCCESS => Ok(()),
_ => Err(err_code),
}
}
@ -1604,39 +1602,33 @@ pub trait DeviceV1_0 {
}
}
fn get_image_subresource_layout(
unsafe fn get_image_subresource_layout(
&self,
image: vk::Image,
subresource: vk::ImageSubresource,
) -> vk::SubresourceLayout {
unsafe {
let mut layout = mem::uninitialized();
self.fp_v1_0().get_image_subresource_layout(
self.handle(),
image,
&subresource,
&mut layout,
);
layout
}
let mut layout = mem::uninitialized();
self.fp_v1_0().get_image_subresource_layout(
self.handle(),
image,
&subresource,
&mut layout,
);
layout
}
fn get_image_memory_requirements(&self, image: vk::Image) -> vk::MemoryRequirements {
unsafe {
let mut mem_req = mem::uninitialized();
self.fp_v1_0()
.get_image_memory_requirements(self.handle(), image, &mut mem_req);
mem_req
}
unsafe fn get_image_memory_requirements(&self, image: vk::Image) -> vk::MemoryRequirements {
let mut mem_req = mem::uninitialized();
self.fp_v1_0()
.get_image_memory_requirements(self.handle(), image, &mut mem_req);
mem_req
}
fn get_buffer_memory_requirements(&self, buffer: vk::Buffer) -> vk::MemoryRequirements {
unsafe {
let mut mem_req = mem::uninitialized();
self.fp_v1_0()
.get_buffer_memory_requirements(self.handle(), buffer, &mut mem_req);
mem_req
}
unsafe fn get_buffer_memory_requirements(&self, buffer: vk::Buffer) -> vk::MemoryRequirements {
let mut mem_req = mem::uninitialized();
self.fp_v1_0()
.get_buffer_memory_requirements(self.handle(), buffer, &mut mem_req);
mem_req
}
unsafe fn allocate_memory(

View file

@ -31,100 +31,93 @@ impl Surface {
CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string")
}
pub fn get_physical_device_surface_support_khr(
pub unsafe fn get_physical_device_surface_support_khr(
&self,
physical_device: vk::PhysicalDevice,
queue_index: u32,
surface: vk::SurfaceKHR,
) -> bool {
unsafe {
let mut b = mem::uninitialized();
self.surface_fn.get_physical_device_surface_support_khr(
physical_device,
queue_index,
surface,
&mut b,
);
b > 0
}
let mut b = mem::uninitialized();
self.surface_fn.get_physical_device_surface_support_khr(
physical_device,
queue_index,
surface,
&mut b,
);
b > 0
}
pub fn get_physical_device_surface_present_modes_khr(
pub unsafe fn get_physical_device_surface_present_modes_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe {
let mut count = 0;
self.surface_fn
.get_physical_device_surface_present_modes_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
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);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
}
}
pub fn get_physical_device_surface_capabilities_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe {
let mut surface_capabilities = mem::uninitialized();
let err_code = self
.surface_fn
.get_physical_device_surface_capabilities_khr(
physical_device,
surface,
&mut surface_capabilities,
);
match err_code {
vk::Result::SUCCESS => Ok(surface_capabilities),
_ => Err(err_code),
}
}
}
pub fn get_physical_device_surface_formats_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe {
let mut count = 0;
self.surface_fn.get_physical_device_surface_formats_khr(
let mut count = 0;
self.surface_fn
.get_physical_device_surface_present_modes_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as usize);
let err_code = self.surface_fn.get_physical_device_surface_formats_khr(
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);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
v.set_len(count as usize);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
}
pub unsafe fn get_physical_device_surface_capabilities_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
let mut surface_capabilities = mem::uninitialized();
let err_code = self
.surface_fn
.get_physical_device_surface_capabilities_khr(
physical_device,
surface,
&mut surface_capabilities,
);
match err_code {
vk::Result::SUCCESS => Ok(surface_capabilities),
_ => Err(err_code),
}
}
pub unsafe fn get_physical_device_surface_formats_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
let mut count = 0;
self.surface_fn.get_physical_device_surface_formats_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
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);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
}

View file

@ -95,31 +95,29 @@ impl Swapchain {
}
}
pub fn get_swapchain_images_khr(
pub unsafe fn get_swapchain_images_khr(
&self,
swapchain: vk::SwapchainKHR,
) -> VkResult<Vec<vk::Image>> {
unsafe {
let mut count = 0;
self.swapchain_fn.get_swapchain_images_khr(
self.handle,
swapchain,
&mut count,
ptr::null_mut(),
);
let mut count = 0;
self.swapchain_fn.get_swapchain_images_khr(
self.handle,
swapchain,
&mut count,
ptr::null_mut(),
);
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);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
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);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
}
}

View file

@ -87,25 +87,23 @@ impl<V: FunctionPointers> Instance<V> {
pub trait InstanceV1_1: InstanceV1_0 {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1;
fn enumerate_physical_device_groups(&self) -> VkResult<Vec<vk::PhysicalDeviceGroupProperties>> {
unsafe {
let mut group_count = mem::uninitialized();
self.fp_v1_1().enumerate_physical_device_groups(
self.handle(),
&mut group_count,
ptr::null_mut(),
);
let mut physical_device_groups = Vec::with_capacity(group_count as usize);
let err_code = self.fp_v1_1().enumerate_physical_device_groups(
self.handle(),
&mut group_count,
physical_device_groups.as_mut_ptr(),
);
physical_device_groups.set_len(group_count as usize);
match err_code {
vk::Result::SUCCESS => Ok(physical_device_groups),
_ => Err(err_code),
}
unsafe fn enumerate_physical_device_groups(&self) -> VkResult<Vec<vk::PhysicalDeviceGroupProperties>> {
let mut group_count = mem::uninitialized();
self.fp_v1_1().enumerate_physical_device_groups(
self.handle(),
&mut group_count,
ptr::null_mut(),
);
let mut physical_device_groups = Vec::with_capacity(group_count as usize);
let err_code = self.fp_v1_1().enumerate_physical_device_groups(
self.handle(),
&mut group_count,
physical_device_groups.as_mut_ptr(),
);
physical_device_groups.set_len(group_count as usize);
match err_code {
vk::Result::SUCCESS => Ok(physical_device_groups),
_ => Err(err_code),
}
}
@ -118,20 +116,18 @@ pub trait InstanceV1_1: InstanceV1_0 {
.get_physical_device_properties2(physical_device, prop);
}
fn get_physical_device_format_properties2(
unsafe fn get_physical_device_format_properties2(
&self,
physical_device: vk::PhysicalDevice,
format: vk::Format,
) -> vk::FormatProperties2 {
unsafe {
let mut format_prop = mem::uninitialized();
self.fp_v1_1().get_physical_device_format_properties2(
physical_device,
format,
&mut format_prop,
);
format_prop
}
let mut format_prop = mem::uninitialized();
self.fp_v1_1().get_physical_device_format_properties2(
physical_device,
format,
&mut format_prop,
);
format_prop
}
unsafe fn get_physical_device_image_format_properties2(
@ -152,19 +148,17 @@ pub trait InstanceV1_1: InstanceV1_0 {
}
}
fn get_physical_device_queue_family_properties2_len(
unsafe fn get_physical_device_queue_family_properties2_len(
&self,
physical_device: vk::PhysicalDevice,
) -> usize {
unsafe {
let mut queue_count = 0;
self.fp_v1_1().get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
queue_count as usize
}
let mut queue_count = 0;
self.fp_v1_1().get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
queue_count as usize
}
unsafe fn get_physical_device_queue_family_properties2(
@ -180,16 +174,14 @@ pub trait InstanceV1_1: InstanceV1_0 {
);
}
fn get_physical_device_memory_properties2(
unsafe fn get_physical_device_memory_properties2(
&self,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties2 {
unsafe {
let mut memory_prop = mem::uninitialized();
self.fp_v1_1()
.get_physical_device_memory_properties2(physical_device, &mut memory_prop);
memory_prop
}
let mut memory_prop = mem::uninitialized();
self.fp_v1_1()
.get_physical_device_memory_properties2(physical_device, &mut memory_prop);
memory_prop
}
unsafe fn get_physical_device_sparse_image_format_properties2(
@ -291,12 +283,12 @@ pub trait InstanceV1_0 {
Ok(Device::from_raw(device, device_fn))
}
fn get_device_proc_addr(
unsafe fn get_device_proc_addr(
&self,
device: vk::Device,
p_name: *const c_char,
) -> vk::PFN_vkVoidFunction {
unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) }
self.fp_v1_0().get_device_proc_addr(device, p_name)
}
unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
@ -304,23 +296,21 @@ pub trait InstanceV1_0 {
.destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr());
}
fn get_physical_device_format_properties(
unsafe fn get_physical_device_format_properties(
&self,
physical_device: vk::PhysicalDevice,
format: vk::Format,
) -> vk::FormatProperties {
unsafe {
let mut format_prop = mem::uninitialized();
self.fp_v1_0().get_physical_device_format_properties(
physical_device,
format,
&mut format_prop,
);
format_prop
}
let mut format_prop = mem::uninitialized();
self.fp_v1_0().get_physical_device_format_properties(
physical_device,
format,
&mut format_prop,
);
format_prop
}
fn get_physical_device_image_format_properties(
unsafe fn get_physical_device_image_format_properties(
&self,
physical_device: vk::PhysicalDevice,
format: vk::Format,
@ -329,126 +319,112 @@ pub trait InstanceV1_0 {
usage: vk::ImageUsageFlags,
flags: vk::ImageCreateFlags,
) -> VkResult<vk::ImageFormatProperties> {
unsafe {
let mut image_format_prop = mem::uninitialized();
let err_code = self.fp_v1_0().get_physical_device_image_format_properties(
physical_device,
format,
typ,
tiling,
usage,
flags,
&mut image_format_prop,
);
if err_code == vk::Result::SUCCESS {
Ok(image_format_prop)
} else {
Err(err_code)
}
let mut image_format_prop = mem::uninitialized();
let err_code = self.fp_v1_0().get_physical_device_image_format_properties(
physical_device,
format,
typ,
tiling,
usage,
flags,
&mut image_format_prop,
);
if err_code == vk::Result::SUCCESS {
Ok(image_format_prop)
} else {
Err(err_code)
}
}
fn get_physical_device_memory_properties(
unsafe fn get_physical_device_memory_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties {
unsafe {
let mut memory_prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_memory_properties(physical_device, &mut memory_prop);
memory_prop
}
let mut memory_prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_memory_properties(physical_device, &mut memory_prop);
memory_prop
}
fn get_physical_device_properties(
unsafe fn get_physical_device_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceProperties {
unsafe {
let mut prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_properties(physical_device, &mut prop);
prop
}
let mut prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_properties(physical_device, &mut prop);
prop
}
fn get_physical_device_queue_family_properties(
unsafe fn get_physical_device_queue_family_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> Vec<vk::QueueFamilyProperties> {
unsafe {
let mut queue_count = 0;
self.fp_v1_0().get_physical_device_queue_family_properties(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
self.fp_v1_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
}
let mut queue_count = 0;
self.fp_v1_0().get_physical_device_queue_family_properties(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
self.fp_v1_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
}
fn get_physical_device_features(
unsafe fn get_physical_device_features(
&self,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceFeatures {
unsafe {
let mut prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_features(physical_device, &mut prop);
prop
let mut prop = mem::uninitialized();
self.fp_v1_0()
.get_physical_device_features(physical_device, &mut prop);
prop
}
unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
let mut num = mem::uninitialized();
self.fp_v1_0()
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut());
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_physical_devices(
self.handle(),
&mut num,
physical_devices.as_mut_ptr(),
);
physical_devices.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(physical_devices),
_ => Err(err_code),
}
}
fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
unsafe {
let mut num = mem::uninitialized();
self.fp_v1_0()
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut());
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_physical_devices(
self.handle(),
&mut num,
physical_devices.as_mut_ptr(),
);
physical_devices.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(physical_devices),
_ => Err(err_code),
}
}
}
fn enumerate_device_extension_properties(
unsafe fn enumerate_device_extension_properties(
&self,
device: vk::PhysicalDevice,
) -> Result<Vec<vk::ExtensionProperties>, vk::Result> {
unsafe {
let mut num = 0;
self.fp_v1_0().enumerate_device_extension_properties(
device,
ptr::null(),
&mut num,
ptr::null_mut(),
);
let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_device_extension_properties(
device,
ptr::null(),
&mut num,
data.as_mut_ptr(),
);
data.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(data),
_ => Err(err_code),
}
let mut num = 0;
self.fp_v1_0().enumerate_device_extension_properties(
device,
ptr::null(),
&mut num,
ptr::null_mut(),
);
let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_device_extension_properties(
device,
ptr::null(),
&mut num,
data.as_mut_ptr(),
);
data.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(data),
_ => Err(err_code),
}
}
}