From e6415a91df88b279a70e73128609831f45006365 Mon Sep 17 00:00:00 2001 From: maik klein Date: Wed, 28 Dec 2016 10:20:12 +0100 Subject: [PATCH] Marks all functions that take an allocator as 'unsafe' --- src/device.rs | 112 ++++++++++++++++---------------- src/entry.rs | 2 +- src/extensions/debug_report.rs | 15 +++-- src/extensions/swapchain.rs | 22 +++++-- src/extensions/win32_surface.rs | 15 +++-- src/extensions/xlibsurface.rs | 10 +-- src/instance.rs | 2 +- 7 files changed, 98 insertions(+), 80 deletions(-) diff --git a/src/device.rs b/src/device.rs index 1925f6c..835cdd3 100644 --- a/src/device.rs +++ b/src/device.rs @@ -144,10 +144,10 @@ impl Device { descriptor_copies.as_ptr()); } - pub fn create_sampler(&self, - create_info: &vk::SamplerCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_sampler(&self, + create_info: &vk::SamplerCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut sampler = mem::uninitialized(); let err_code = self.device_fn @@ -219,7 +219,7 @@ impl Device { } } - pub fn create_descriptor_set_layout(&self, + pub unsafe fn create_descriptor_set_layout(&self, create_info: &vk::DescriptorSetLayoutCreateInfo, allocation_callbacks: Option<&vk::AllocationCallbacks>) -> VkResult { @@ -247,10 +247,10 @@ impl Device { } } - pub fn create_descriptor_pool(&self, - create_info: &vk::DescriptorPoolCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_descriptor_pool(&self, + create_info: &vk::DescriptorPoolCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut pool = mem::uninitialized(); let err_code = self.device_fn @@ -388,10 +388,10 @@ impl Device { viewports.as_ptr()); } - pub fn create_semaphore(&self, - create_info: &vk::SemaphoreCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_semaphore(&self, + create_info: &vk::SemaphoreCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut semaphore = mem::uninitialized(); let err_code = self.device_fn @@ -406,7 +406,7 @@ impl Device { } } - pub fn create_graphics_pipelines(&self, + pub unsafe fn create_graphics_pipelines(&self, pipeline_cache: vk::PipelineCache, create_infos: &[vk::GraphicsPipelineCreateInfo], allocation_callbacks: Option<&vk::AllocationCallbacks>) @@ -428,10 +428,10 @@ impl Device { } } - pub fn create_buffer(&self, - create_info: &vk::BufferCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_buffer(&self, + create_info: &vk::BufferCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut buffer = mem::uninitialized(); let err_code = self.device_fn @@ -505,10 +505,10 @@ impl Device { } } - pub fn get_device_queue(&self, - queue_family_index: vk::uint32_t, - queue_index: vk::uint32_t) - -> vk::Queue { + pub unsafe fn get_device_queue(&self, + queue_family_index: vk::uint32_t, + queue_index: vk::uint32_t) + -> vk::Queue { unsafe { let mut queue = mem::uninitialized(); self.device_fn @@ -537,10 +537,10 @@ impl Device { image_memory_barriers.as_ptr()); } - pub fn create_render_pass(&self, - create_info: &vk::RenderPassCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_render_pass(&self, + create_info: &vk::RenderPassCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut renderpass = mem::uninitialized(); let err_code = self.device_fn @@ -576,11 +576,11 @@ impl Device { } } - pub fn wait_for_fences(&self, - fences: &[vk::Fence], - wait_all: bool, - timeout: vk::uint64_t) - -> VkResult<()> { + pub unsafe fn wait_for_fences(&self, + fences: &[vk::Fence], + wait_all: bool, + timeout: vk::uint64_t) + -> VkResult<()> { unsafe { let err_code = self.device_fn .wait_for_fences(self.handle, @@ -595,7 +595,7 @@ impl Device { } } - pub fn queue_wait_idle(&self, queue: vk::Queue) -> VkResult<()> { + pub unsafe fn queue_wait_idle(&self, queue: vk::Queue) -> VkResult<()> { unsafe { let err_code = self.device_fn.queue_wait_idle(queue); match err_code { @@ -633,10 +633,10 @@ impl Device { } } - pub fn create_image_view(&self, - create_info: &vk::ImageViewCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_image_view(&self, + create_info: &vk::ImageViewCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut image_view = mem::uninitialized(); let err_code = self.device_fn @@ -665,10 +665,10 @@ impl Device { } } - pub fn create_command_pool(&self, - create_info: &vk::CommandPoolCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_command_pool(&self, + create_info: &vk::CommandPoolCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut pool = mem::uninitialized(); let err_code = self.device_fn @@ -683,10 +683,10 @@ impl Device { } } - pub fn create_image(&self, - create_info: &vk::ImageCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_image(&self, + create_info: &vk::ImageCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut image = mem::uninitialized(); let err_code = self.device_fn @@ -719,10 +719,10 @@ impl Device { } } - pub fn allocate_memory(&self, - create_info: &vk::MemoryAllocateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn allocate_memory(&self, + create_info: &vk::MemoryAllocateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut memory = mem::uninitialized(); let err_code = self.device_fn @@ -737,10 +737,10 @@ impl Device { } } - pub fn create_shader_module(&self, - create_info: &vk::ShaderModuleCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_shader_module(&self, + create_info: &vk::ShaderModuleCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut shader = mem::uninitialized(); let err_code = self.device_fn @@ -755,10 +755,10 @@ impl Device { } } - pub fn create_fence(&self, - create_info: &vk::FenceCreateInfo, - allocation_callbacks: Option<&vk::AllocationCallbacks>) - -> VkResult { + pub unsafe fn create_fence(&self, + create_info: &vk::FenceCreateInfo, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut fence = mem::uninitialized(); let err_code = self.device_fn diff --git a/src/entry.rs b/src/entry.rs index 83e3f03..b988870 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -5,6 +5,7 @@ use vk; use instance::Instance; use shared_library::dynamic_library::DynamicLibrary; use std::path::Path; +use ::RawPtr; #[cfg(windows)] fn get_path() -> &'static Path { @@ -73,7 +74,6 @@ impl Entry { allocation_callbacks: Option<&vk::AllocationCallbacks>) -> Result { unsafe { - use ::RawPtr; let mut instance: vk::Instance = mem::uninitialized(); let err_code = self.entry_fn.create_instance(create_info, allocation_callbacks.as_raw_ptr(), diff --git a/src/extensions/debug_report.rs b/src/extensions/debug_report.rs index 0162eaa..04d8449 100644 --- a/src/extensions/debug_report.rs +++ b/src/extensions/debug_report.rs @@ -5,6 +5,7 @@ use instance::Instance; use entry::Entry; use vk; use std::ffi::CStr; +use ::RawPtr; pub struct DebugReport { handle: vk::Instance, @@ -24,23 +25,25 @@ impl DebugReport { }) } - pub fn name() -> &'static CStr{ + pub fn name() -> &'static CStr { CStr::from_bytes_with_nul(b"VK_EXT_debug_report\0").expect("Wrong extension string") } - pub unsafe fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) { - self.debug_report_fn.destroy_debug_report_callback_ext(self.handle, debug, ptr::null()); + pub unsafe fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>) { + self.debug_report_fn.destroy_debug_report_callback_ext(self.handle, + debug, + allocation_callbacks.as_raw_ptr()); } - pub fn create_debug_report_callback_ext(&self, - create_info: &vk::DebugReportCallbackCreateInfoEXT) + pub unsafe fn create_debug_report_callback_ext(&self, + create_info: &vk::DebugReportCallbackCreateInfoEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>) -> VkResult { unsafe { let mut debug_cb = mem::uninitialized(); let err_code = self.debug_report_fn .create_debug_report_callback_ext(self.handle, create_info, - ptr::null(), + allocation_callbacks.as_raw_ptr(), &mut debug_cb); match err_code { vk::Result::Success => Ok(debug_cb), diff --git a/src/extensions/swapchain.rs b/src/extensions/swapchain.rs index 08ac2c4..4198bc1 100644 --- a/src/extensions/swapchain.rs +++ b/src/extensions/swapchain.rs @@ -5,6 +5,7 @@ use instance::Instance; use device::Device; use vk; use std::ffi::CStr; +use ::RawPtr; pub struct Swapchain { handle: vk::Device, @@ -22,12 +23,15 @@ impl Swapchain { }) } - pub fn name() -> &'static CStr{ + pub fn name() -> &'static CStr { CStr::from_bytes_with_nul(b"VK_KHR_swapchain\0").expect("Wrong extension string") } - pub unsafe fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) { - self.swapchain_fn.destroy_swapchain_khr(self.handle, swapchain, ptr::null()); + pub unsafe fn destroy_swapchain_khr(&self, + swapchain: vk::SwapchainKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) { + self.swapchain_fn + .destroy_swapchain_khr(self.handle, swapchain, allocation_callbacks.as_raw_ptr()); } pub unsafe fn acquire_next_image_khr(&self, @@ -50,13 +54,17 @@ impl Swapchain { } } - pub fn create_swapchain_khr(&self, - create_info: &vk::SwapchainCreateInfoKHR) - -> VkResult { + pub unsafe fn create_swapchain_khr(&self, + create_info: &vk::SwapchainCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut swapchain = mem::uninitialized(); let err_code = self.swapchain_fn - .create_swapchain_khr(self.handle, create_info, ptr::null(), &mut swapchain); + .create_swapchain_khr(self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut swapchain); match err_code { vk::Result::Success => Ok(swapchain), _ => Err(err_code), diff --git a/src/extensions/win32_surface.rs b/src/extensions/win32_surface.rs index 212fb99..c85ea29 100644 --- a/src/extensions/win32_surface.rs +++ b/src/extensions/win32_surface.rs @@ -5,6 +5,7 @@ use instance::Instance; use entry::Entry; use vk; use std::ffi::CStr; +use ::RawPtr; pub struct Win32Surface { pub handle: vk::Instance, @@ -24,17 +25,21 @@ impl Win32Surface { }) } - pub fn name() -> &'static CStr{ + pub fn name() -> &'static CStr { CStr::from_bytes_with_nul(b"VK_KHR_win32_surface\0").expect("Wrong extension string") } - pub fn create_win32_surface_khr(&self, - create_info: &vk::Win32SurfaceCreateInfoKHR) - -> VkResult { + pub unsafe fn create_win32_surface_khr(&self, + create_info: &vk::Win32SurfaceCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { unsafe { let mut surface = mem::uninitialized(); let err_code = self.win32_surface_fn - .create_win32_surface_khr(self.handle, create_info, ptr::null(), &mut surface); + .create_win32_surface_khr(self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface); match err_code { vk::Result::Success => Ok(surface), _ => Err(err_code), diff --git a/src/extensions/xlibsurface.rs b/src/extensions/xlibsurface.rs index c419c10..d834bdb 100644 --- a/src/extensions/xlibsurface.rs +++ b/src/extensions/xlibsurface.rs @@ -5,6 +5,7 @@ use instance::Instance; use entry::Entry; use vk; use std::ffi::CStr; +use ::RawPtr; pub struct XlibSurface { pub handle: vk::Instance, @@ -24,17 +25,18 @@ impl XlibSurface { }) } - pub fn name() -> &'static CStr{ + pub fn name() -> &'static CStr { CStr::from_bytes_with_nul(b"VK_KHR_xlib_surface\0").expect("Wrong extension string") } - pub fn create_xlib_surface_khr(&self, - create_info: &vk::XlibSurfaceCreateInfoKHR) + pub unsafe fn create_xlib_surface_khr(&self, + create_info: &vk::XlibSurfaceCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) -> VkResult { unsafe { let mut surface = mem::uninitialized(); let err_code = self.xlib_surface_fn - .create_xlib_surface_khr(self.handle, create_info, ptr::null(), &mut surface); + .create_xlib_surface_khr(self.handle, create_info, allocation_callbacks.as_raw_ptr(), &mut surface); match err_code { vk::Result::Success => Ok(surface), _ => Err(err_code), diff --git a/src/instance.rs b/src/instance.rs index 2ff3726..fe9699d 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -30,7 +30,7 @@ impl Instance { } } - pub fn create_device(&self, + pub unsafe fn create_device(&self, physical_device: vk::PhysicalDevice, create_info: &vk::DeviceCreateInfo, allocation_callbacks: Option<&vk::AllocationCallbacks>)