From c8d2e22b21c9dd8cd57504a63be6800cea9c3ba0 Mon Sep 17 00:00:00 2001 From: maik klein Date: Sat, 24 Dec 2016 00:22:37 +0100 Subject: [PATCH] First unsafe pass --- Cargo.lock | 97 ------------------------------------------------- src/device.rs | 84 +++++++++++++++++++++--------------------- src/instance.rs | 2 +- 3 files changed, 43 insertions(+), 140 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04bb2f3..f664e36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,66 +4,6 @@ version = "0.2.0" dependencies = [ "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cfg-if" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "dbghelp-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "error-chain" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gcc" -version = "0.3.37" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -76,11 +16,6 @@ name = "libc" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc-demangle" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "shared_library" version = "0.1.5" @@ -90,39 +25,7 @@ dependencies = [ "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sharedlib" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [metadata] -"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f" -"checksum backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3602e8d8c43336088a8505fa55cae2b3884a9be29440863a11528a42f46f6bb7" -"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" -"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" -"checksum error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5c82c815138e278b8dcdeffc49f27ea6ffb528403e9dea4194f2e3dd40b143" -"checksum gcc 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)" = "41337e9dc80ebadf36b4f252bf7440f61bcf34f99caa170e50dcd0f9a0cdb5d8" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" "checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8" -"checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc" "checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a" -"checksum sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5182b4b49a0ff319bc69d23ca9e9f8e40dfb3b88abb895805a54e69325a092c7" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/src/device.rs b/src/device.rs index 7c04e6c..c1568dc 100644 --- a/src/device.rs +++ b/src/device.rs @@ -22,104 +22,104 @@ impl Device { } } - pub fn destroy_device(&self) { + pub unsafe fn destroy_device(&self) { unsafe { self.device_fn.destroy_device(self.handle, ptr::null()); } } - pub fn destroy_sampler(&self, sampler: vk::Sampler) { + pub unsafe fn destroy_sampler(&self, sampler: vk::Sampler) { unsafe { self.device_fn.destroy_sampler(self.handle, sampler, ptr::null()); } } - pub fn free_memory(&self, memory: vk::DeviceMemory) { + pub unsafe fn free_memory(&self, memory: vk::DeviceMemory) { unsafe { self.device_fn.free_memory(self.handle, memory, ptr::null()); } } - pub fn destroy_fence(&self, fence: vk::Fence) { + pub unsafe fn destroy_fence(&self, fence: vk::Fence) { unsafe { self.device_fn.destroy_fence(self.handle, fence, ptr::null()); } } - pub fn destroy_image(&self, image: vk::Image) { + pub unsafe fn destroy_image(&self, image: vk::Image) { unsafe { self.device_fn.destroy_image(self.handle, image, ptr::null()); } } - pub fn destroy_command_pool(&self, pool: vk::CommandPool) { + pub unsafe fn destroy_command_pool(&self, pool: vk::CommandPool) { unsafe { self.device_fn.destroy_command_pool(self.handle, pool, ptr::null()); } } - pub fn destroy_image_view(&self, image_view: vk::ImageView) { + pub unsafe fn destroy_image_view(&self, image_view: vk::ImageView) { unsafe { self.device_fn.destroy_image_view(self.handle, image_view, ptr::null()); } } - pub fn destroy_render_pass(&self, renderpass: vk::RenderPass) { + pub unsafe fn destroy_render_pass(&self, renderpass: vk::RenderPass) { unsafe { self.device_fn.destroy_render_pass(self.handle, renderpass, ptr::null()); } } - pub fn destroy_framebuffer(&self, framebuffer: vk::Framebuffer) { + pub unsafe fn destroy_framebuffer(&self, framebuffer: vk::Framebuffer) { unsafe { self.device_fn.destroy_framebuffer(self.handle, framebuffer, ptr::null()); } } - pub fn destroy_pipeline_layout(&self, pipeline_layout: vk::PipelineLayout) { + pub unsafe fn destroy_pipeline_layout(&self, pipeline_layout: vk::PipelineLayout) { unsafe { self.device_fn.destroy_pipeline_layout(self.handle, pipeline_layout, ptr::null()); } } - pub fn destroy_buffer(&self, buffer: vk::Buffer) { + pub unsafe fn destroy_buffer(&self, buffer: vk::Buffer) { unsafe { self.device_fn.destroy_buffer(self.handle, buffer, ptr::null()); } } - pub fn destroy_shader_module(&self, shader: vk::ShaderModule) { + pub unsafe fn destroy_shader_module(&self, shader: vk::ShaderModule) { unsafe { self.device_fn.destroy_shader_module(self.handle, shader, ptr::null()); } } - pub fn destroy_pipeline(&self, pipeline: vk::Pipeline) { + pub unsafe fn destroy_pipeline(&self, pipeline: vk::Pipeline) { unsafe { self.device_fn.destroy_pipeline(self.handle, pipeline, ptr::null()); } } - pub fn destroy_semaphore(&self, semaphore: vk::Semaphore) { + pub unsafe fn destroy_semaphore(&self, semaphore: vk::Semaphore) { unsafe { self.device_fn.destroy_semaphore(self.handle, semaphore, ptr::null()); } } - pub fn destroy_descriptor_pool(&self, pool: vk::DescriptorPool) { + pub unsafe fn destroy_descriptor_pool(&self, pool: vk::DescriptorPool) { unsafe { self.device_fn.destroy_descriptor_pool(self.handle, pool, ptr::null()); } } - pub fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout) { + pub unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout) { unsafe { self.device_fn.destroy_descriptor_set_layout(self.handle, layout, ptr::null()); } } - pub fn free_descriptor_sets(&self, + pub unsafe fn free_descriptor_sets(&self, pool: vk::DescriptorPool, descriptor_sets: &[vk::DescriptorSet]) { unsafe { @@ -130,7 +130,7 @@ impl Device { } } - pub fn update_descriptor_sets(&self, + pub unsafe fn update_descriptor_sets(&self, descriptor_writes: &[vk::WriteDescriptorSet], descriptor_copies: &[vk::CopyDescriptorSet]) { unsafe { @@ -154,7 +154,7 @@ impl Device { } } - pub fn cmd_copy_buffer(&self, + pub unsafe fn cmd_copy_buffer(&self, command_buffer: vk::CommandBuffer, src_buffer: vk::Buffer, dst_buffer: vk::Buffer, @@ -168,7 +168,7 @@ impl Device { regions.as_ptr()); } } - pub fn cmd_copy_buffer_to_image(&self, + pub unsafe fn cmd_copy_buffer_to_image(&self, command_buffer: vk::CommandBuffer, src_buffer: vk::Buffer, dst_image: vk::Image, @@ -184,7 +184,7 @@ impl Device { } } - pub fn cmd_copy_image(&self, + pub unsafe fn cmd_copy_image(&self, command_buffer: vk::CommandBuffer, src_image: vk::Image, src_image_layout: vk::ImageLayout, @@ -254,7 +254,7 @@ impl Device { } } - pub fn reset_command_buffer(&self, + pub unsafe fn reset_command_buffer(&self, command_buffer: vk::CommandBuffer, flags: vk::CommandBufferResetFlags) -> VkResult<()> { @@ -268,7 +268,7 @@ impl Device { } } - pub fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> { + pub unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> { unsafe { let err_code = self.device_fn .reset_fences(self.handle, fences.len() as vk::uint32_t, fences.as_ptr()); @@ -279,7 +279,7 @@ impl Device { } } - pub fn cmd_bind_index_buffer(&self, + pub unsafe fn cmd_bind_index_buffer(&self, command_buffer: vk::CommandBuffer, buffer: vk::Buffer, offset: vk::DeviceSize, @@ -289,7 +289,7 @@ impl Device { } } - pub fn cmd_draw_indexed(&self, + pub unsafe fn cmd_draw_indexed(&self, command_buffer: vk::CommandBuffer, index_count: vk::uint32_t, instance_count: vk::uint32_t, @@ -307,7 +307,7 @@ impl Device { } } - pub fn cmd_bind_descriptor_sets(&self, + pub unsafe fn cmd_bind_descriptor_sets(&self, command_buffer: vk::CommandBuffer, pipeline_bind_point: vk::PipelineBindPoint, layout: vk::PipelineLayout, @@ -326,7 +326,7 @@ impl Device { } } - pub fn cmd_begin_render_pass(&self, + pub unsafe fn cmd_begin_render_pass(&self, command_buffer: vk::CommandBuffer, create_info: &vk::RenderPassBeginInfo, contents: vk::SubpassContents) { @@ -335,7 +335,7 @@ impl Device { } } - pub fn cmd_bind_pipeline(&self, + pub unsafe fn cmd_bind_pipeline(&self, command_buffer: vk::CommandBuffer, pipeline_bind_point: vk::PipelineBindPoint, pipeline: vk::Pipeline) { @@ -344,7 +344,7 @@ impl Device { } } - pub fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) { + pub unsafe fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) { unsafe { self.device_fn .cmd_set_scissor(command_buffer, @@ -354,7 +354,7 @@ impl Device { } } - pub fn cmd_bind_vertex_buffers(&self, + pub unsafe fn cmd_bind_vertex_buffers(&self, command_buffer: vk::CommandBuffer, buffers: &[vk::Buffer], offsets: &vk::DeviceSize) { @@ -367,13 +367,13 @@ impl Device { } } - pub fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) { + pub unsafe fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) { unsafe { self.device_fn.cmd_end_render_pass(command_buffer); } } - pub fn cmd_draw(&self, + pub unsafe fn cmd_draw(&self, command_buffer: vk::CommandBuffer, vertex_count: vk::uint32_t, instance_count: vk::uint32_t, @@ -388,7 +388,7 @@ impl Device { } } - pub fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) { + pub unsafe fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) { unsafe { self.device_fn.cmd_set_viewport(command_buffer, 0, @@ -398,7 +398,7 @@ impl Device { } - pub fn create_semaphore(&self, + pub unsafe fn create_semaphore(&self, create_info: &vk::SemaphoreCreateInfo) -> VkResult { unsafe { @@ -461,7 +461,7 @@ impl Device { } } } - pub fn map_memory(&self, + pub unsafe fn map_memory(&self, memory: vk::DeviceMemory, offset: vk::DeviceSize, size: vk::DeviceSize, @@ -483,7 +483,7 @@ impl Device { } } - pub fn unmap_memory(&self, memory: vk::DeviceMemory) { + pub unsafe fn unmap_memory(&self, memory: vk::DeviceMemory) { unsafe { self.device_fn.unmap_memory(self.handle, memory); } @@ -551,7 +551,7 @@ impl Device { } } - pub fn begin_command_buffer(&self, + pub unsafe fn begin_command_buffer(&self, command_buffer: vk::CommandBuffer, create_info: &vk::CommandBufferBeginInfo) -> VkResult<()> { @@ -565,7 +565,7 @@ impl Device { } } - pub fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> { + pub unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> { unsafe { let err_code = self.device_fn .end_command_buffer(command_buffer); @@ -605,7 +605,7 @@ impl Device { } } - pub fn queue_present_khr(&self, + pub unsafe fn queue_present_khr(&self, queue: vk::Queue, create_info: &vk::PresentInfoKHR) -> VkResult<()> { @@ -619,7 +619,7 @@ impl Device { } } - pub fn queue_submit(&self, + pub unsafe fn queue_submit(&self, queue: vk::Queue, submits: &[vk::SubmitInfo], fence: vk::Fence) @@ -752,7 +752,7 @@ impl Device { } } - pub fn bind_buffer_memory(&self, + pub unsafe fn bind_buffer_memory(&self, buffer: vk::Buffer, device_memory: vk::DeviceMemory, offset: vk::DeviceSize) @@ -767,7 +767,7 @@ impl Device { } } - pub fn bind_image_memory(&self, + pub unsafe fn bind_image_memory(&self, image: vk::Image, device_memory: vk::DeviceMemory, offset: vk::DeviceSize) diff --git a/src/instance.rs b/src/instance.rs index 8a17b70..18cca2a 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -45,7 +45,7 @@ impl Instance { } } - pub fn destroy_instance(&self) { + pub unsafe fn destroy_instance(&self) { unsafe { self.instance_fn.destroy_instance(self.handle, ptr::null()); }