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

View file

@ -31,13 +31,12 @@ impl Surface {
CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string") 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, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
queue_index: u32, queue_index: u32,
surface: vk::SurfaceKHR, surface: vk::SurfaceKHR,
) -> bool { ) -> bool {
unsafe {
let mut b = mem::uninitialized(); let mut b = mem::uninitialized();
self.surface_fn.get_physical_device_surface_support_khr( self.surface_fn.get_physical_device_surface_support_khr(
physical_device, physical_device,
@ -47,13 +46,12 @@ impl Surface {
); );
b > 0 b > 0
} }
}
pub fn get_physical_device_surface_present_modes_khr( pub unsafe fn get_physical_device_surface_present_modes_khr(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR, surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::PresentModeKHR>> { ) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe {
let mut count = 0; let mut count = 0;
self.surface_fn self.surface_fn
.get_physical_device_surface_present_modes_khr( .get_physical_device_surface_present_modes_khr(
@ -77,14 +75,12 @@ impl Surface {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
pub fn get_physical_device_surface_capabilities_khr( pub unsafe fn get_physical_device_surface_capabilities_khr(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR, surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> { ) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe {
let mut surface_capabilities = mem::uninitialized(); let mut surface_capabilities = mem::uninitialized();
let err_code = self let err_code = self
.surface_fn .surface_fn
@ -98,14 +94,12 @@ impl Surface {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
pub fn get_physical_device_surface_formats_khr( pub unsafe fn get_physical_device_surface_formats_khr(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR, surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::SurfaceFormatKHR>> { ) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe {
let mut count = 0; let mut count = 0;
self.surface_fn.get_physical_device_surface_formats_khr( self.surface_fn.get_physical_device_surface_formats_khr(
physical_device, physical_device,
@ -126,7 +120,6 @@ impl Surface {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
pub unsafe fn destroy_surface_khr( pub unsafe fn destroy_surface_khr(
&self, &self,

View file

@ -95,11 +95,10 @@ impl Swapchain {
} }
} }
pub fn get_swapchain_images_khr( pub unsafe fn get_swapchain_images_khr(
&self, &self,
swapchain: vk::SwapchainKHR, swapchain: vk::SwapchainKHR,
) -> VkResult<Vec<vk::Image>> { ) -> VkResult<Vec<vk::Image>> {
unsafe {
let mut count = 0; let mut count = 0;
self.swapchain_fn.get_swapchain_images_khr( self.swapchain_fn.get_swapchain_images_khr(
self.handle, self.handle,
@ -121,5 +120,4 @@ impl Swapchain {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
} }

View file

@ -87,8 +87,7 @@ impl<V: FunctionPointers> Instance<V> {
pub trait InstanceV1_1: InstanceV1_0 { pub trait InstanceV1_1: InstanceV1_0 {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1; fn fp_v1_1(&self) -> &vk::InstanceFnV1_1;
fn enumerate_physical_device_groups(&self) -> VkResult<Vec<vk::PhysicalDeviceGroupProperties>> { unsafe fn enumerate_physical_device_groups(&self) -> VkResult<Vec<vk::PhysicalDeviceGroupProperties>> {
unsafe {
let mut group_count = mem::uninitialized(); let mut group_count = mem::uninitialized();
self.fp_v1_1().enumerate_physical_device_groups( self.fp_v1_1().enumerate_physical_device_groups(
self.handle(), self.handle(),
@ -107,7 +106,6 @@ pub trait InstanceV1_1: InstanceV1_0 {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
unsafe fn get_physical_device_properties2( unsafe fn get_physical_device_properties2(
&self, &self,
@ -118,12 +116,11 @@ pub trait InstanceV1_1: InstanceV1_0 {
.get_physical_device_properties2(physical_device, prop); .get_physical_device_properties2(physical_device, prop);
} }
fn get_physical_device_format_properties2( unsafe fn get_physical_device_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
) -> vk::FormatProperties2 { ) -> vk::FormatProperties2 {
unsafe {
let mut format_prop = mem::uninitialized(); let mut format_prop = mem::uninitialized();
self.fp_v1_1().get_physical_device_format_properties2( self.fp_v1_1().get_physical_device_format_properties2(
physical_device, physical_device,
@ -132,7 +129,6 @@ pub trait InstanceV1_1: InstanceV1_0 {
); );
format_prop format_prop
} }
}
unsafe fn get_physical_device_image_format_properties2( unsafe fn get_physical_device_image_format_properties2(
&self, &self,
@ -152,11 +148,10 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
} }
fn get_physical_device_queue_family_properties2_len( unsafe fn get_physical_device_queue_family_properties2_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> usize { ) -> usize {
unsafe {
let mut queue_count = 0; let mut queue_count = 0;
self.fp_v1_1().get_physical_device_queue_family_properties2( self.fp_v1_1().get_physical_device_queue_family_properties2(
physical_device, physical_device,
@ -165,7 +160,6 @@ pub trait InstanceV1_1: InstanceV1_0 {
); );
queue_count as usize queue_count as usize
} }
}
unsafe fn get_physical_device_queue_family_properties2( unsafe fn get_physical_device_queue_family_properties2(
&self, &self,
@ -180,17 +174,15 @@ pub trait InstanceV1_1: InstanceV1_0 {
); );
} }
fn get_physical_device_memory_properties2( unsafe fn get_physical_device_memory_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties2 { ) -> vk::PhysicalDeviceMemoryProperties2 {
unsafe {
let mut memory_prop = mem::uninitialized(); let mut memory_prop = mem::uninitialized();
self.fp_v1_1() self.fp_v1_1()
.get_physical_device_memory_properties2(physical_device, &mut memory_prop); .get_physical_device_memory_properties2(physical_device, &mut memory_prop);
memory_prop memory_prop
} }
}
unsafe fn get_physical_device_sparse_image_format_properties2( unsafe fn get_physical_device_sparse_image_format_properties2(
&self, &self,
@ -291,12 +283,12 @@ pub trait InstanceV1_0 {
Ok(Device::from_raw(device, device_fn)) Ok(Device::from_raw(device, device_fn))
} }
fn get_device_proc_addr( unsafe fn get_device_proc_addr(
&self, &self,
device: vk::Device, device: vk::Device,
p_name: *const c_char, p_name: *const c_char,
) -> vk::PFN_vkVoidFunction { ) -> 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>) { unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
@ -304,12 +296,11 @@ pub trait InstanceV1_0 {
.destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr()); .destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr());
} }
fn get_physical_device_format_properties( unsafe fn get_physical_device_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
) -> vk::FormatProperties { ) -> vk::FormatProperties {
unsafe {
let mut format_prop = mem::uninitialized(); let mut format_prop = mem::uninitialized();
self.fp_v1_0().get_physical_device_format_properties( self.fp_v1_0().get_physical_device_format_properties(
physical_device, physical_device,
@ -318,9 +309,8 @@ pub trait InstanceV1_0 {
); );
format_prop format_prop
} }
}
fn get_physical_device_image_format_properties( unsafe fn get_physical_device_image_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
@ -329,7 +319,6 @@ pub trait InstanceV1_0 {
usage: vk::ImageUsageFlags, usage: vk::ImageUsageFlags,
flags: vk::ImageCreateFlags, flags: vk::ImageCreateFlags,
) -> VkResult<vk::ImageFormatProperties> { ) -> VkResult<vk::ImageFormatProperties> {
unsafe {
let mut image_format_prop = mem::uninitialized(); let mut image_format_prop = mem::uninitialized();
let err_code = self.fp_v1_0().get_physical_device_image_format_properties( let err_code = self.fp_v1_0().get_physical_device_image_format_properties(
physical_device, physical_device,
@ -346,37 +335,31 @@ pub trait InstanceV1_0 {
Err(err_code) Err(err_code)
} }
} }
}
fn get_physical_device_memory_properties( unsafe fn get_physical_device_memory_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties { ) -> vk::PhysicalDeviceMemoryProperties {
unsafe {
let mut memory_prop = mem::uninitialized(); let mut memory_prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0()
.get_physical_device_memory_properties(physical_device, &mut memory_prop); .get_physical_device_memory_properties(physical_device, &mut memory_prop);
memory_prop memory_prop
} }
}
fn get_physical_device_properties( unsafe fn get_physical_device_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceProperties { ) -> vk::PhysicalDeviceProperties {
unsafe {
let mut prop = mem::uninitialized(); let mut prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0()
.get_physical_device_properties(physical_device, &mut prop); .get_physical_device_properties(physical_device, &mut prop);
prop prop
} }
}
fn get_physical_device_queue_family_properties( unsafe fn get_physical_device_queue_family_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> Vec<vk::QueueFamilyProperties> { ) -> Vec<vk::QueueFamilyProperties> {
unsafe {
let mut queue_count = 0; let mut queue_count = 0;
self.fp_v1_0().get_physical_device_queue_family_properties( self.fp_v1_0().get_physical_device_queue_family_properties(
physical_device, physical_device,
@ -392,22 +375,18 @@ pub trait InstanceV1_0 {
queue_families_vec.set_len(queue_count as usize); queue_families_vec.set_len(queue_count as usize);
queue_families_vec queue_families_vec
} }
}
fn get_physical_device_features( unsafe fn get_physical_device_features(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceFeatures { ) -> vk::PhysicalDeviceFeatures {
unsafe {
let mut prop = mem::uninitialized(); let mut prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0()
.get_physical_device_features(physical_device, &mut prop); .get_physical_device_features(physical_device, &mut prop);
prop prop
} }
}
fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> { unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
unsafe {
let mut num = mem::uninitialized(); let mut num = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0()
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut()); .enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut());
@ -423,13 +402,11 @@ pub trait InstanceV1_0 {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
fn enumerate_device_extension_properties( unsafe fn enumerate_device_extension_properties(
&self, &self,
device: vk::PhysicalDevice, device: vk::PhysicalDevice,
) -> Result<Vec<vk::ExtensionProperties>, vk::Result> { ) -> Result<Vec<vk::ExtensionProperties>, vk::Result> {
unsafe {
let mut num = 0; let mut num = 0;
self.fp_v1_0().enumerate_device_extension_properties( self.fp_v1_0().enumerate_device_extension_properties(
device, device,
@ -450,5 +427,4 @@ pub trait InstanceV1_0 {
_ => Err(err_code), _ => Err(err_code),
} }
} }
}
} }