Cleanup unsued unsafe

This commit is contained in:
maik klein 2016-12-26 00:24:06 +01:00
parent 3047ed9fad
commit 87ee2af220
7 changed files with 223 additions and 308 deletions

16
clippy.json Normal file
View file

@ -0,0 +1,16 @@
Compiling ash v0.2.0 (file:///home/maik/projects/engine/ash)
Compiling ash v0.2.0 (file:///home/maik/projects/engine/ash)
error: unknown debugging option: `--error-format`
thread 'main' panicked at 'Box<Any>', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:731
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: unknown debugging option: `--error-format`
thread 'main' panicked at 'Box<Any>', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:731
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `ash`.
To learn more, run the command again with --verbose.
error: Could not compile `ash`.
To learn more, run the command again with --verbose.

View file

@ -1,3 +1,4 @@
#![allow(dead_code)]
use vk;
use std::ptr;
pub trait VkAllocation {
@ -37,32 +38,32 @@ pub trait VkAllocation {
pub struct DefaultAllocatorCallback;
impl VkAllocation for DefaultAllocatorCallback {
unsafe extern "system" fn allocation(user: *mut (),
a: vk::size_t,
b: vk::size_t,
c: vk::SystemAllocationScope)
unsafe extern "system" fn allocation(_: *mut (),
_: vk::size_t,
_: vk::size_t,
_: vk::SystemAllocationScope)
-> *mut () {
ptr::null_mut()
}
unsafe extern "system" fn reallocation(a: *mut vk::c_void,
b: *mut vk::c_void,
c: vk::size_t,
d: vk::size_t,
e: vk::SystemAllocationScope)
unsafe extern "system" fn reallocation(_: *mut vk::c_void,
_: *mut vk::c_void,
_: vk::size_t,
_: vk::size_t,
_: vk::SystemAllocationScope)
-> *mut vk::c_void {
ptr::null_mut()
}
unsafe extern "system" fn free(a: *mut vk::c_void, b: *mut vk::c_void) {}
unsafe extern "system" fn internal_allocation(a: *mut vk::c_void,
b: vk::size_t,
c: vk::InternalAllocationType,
d: vk::SystemAllocationScope) {
unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {}
unsafe extern "system" fn internal_allocation(_: *mut vk::c_void,
_: vk::size_t,
_: vk::InternalAllocationType,
_: vk::SystemAllocationScope) {
}
unsafe extern "system" fn internal_free(a: *mut vk::c_void,
b: vk::size_t,
c: vk::InternalAllocationType,
d: vk::SystemAllocationScope) {
unsafe extern "system" fn internal_free(_: *mut vk::c_void,
_: vk::size_t,
_: vk::InternalAllocationType,
_: vk::SystemAllocationScope) {
}
fn create_allocation_callback() -> Option<vk::AllocationCallbacks> {
None

View file

@ -2,7 +2,6 @@
use prelude::*;
use std::ptr;
use std::mem;
use instance::Instance;
use vk;
unsafe impl Sync for Device {}
@ -26,124 +25,88 @@ impl Device {
}
pub unsafe fn destroy_device(&self) {
unsafe {
self.device_fn.destroy_device(self.handle, ptr::null());
}
}
pub unsafe fn destroy_sampler(&self, sampler: vk::Sampler) {
unsafe {
self.device_fn.destroy_sampler(self.handle, sampler, ptr::null());
}
}
pub unsafe fn free_memory(&self, memory: vk::DeviceMemory) {
unsafe {
self.device_fn.free_memory(self.handle, memory, ptr::null());
}
}
pub unsafe fn destroy_fence(&self, fence: vk::Fence) {
unsafe {
self.device_fn.destroy_fence(self.handle, fence, ptr::null());
}
}
pub unsafe fn destroy_image(&self, image: vk::Image) {
unsafe {
self.device_fn.destroy_image(self.handle, image, ptr::null());
}
}
pub unsafe fn destroy_command_pool(&self, pool: vk::CommandPool) {
unsafe {
self.device_fn.destroy_command_pool(self.handle, pool, ptr::null());
}
}
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 unsafe fn destroy_render_pass(&self, renderpass: vk::RenderPass) {
unsafe {
self.device_fn.destroy_render_pass(self.handle, renderpass, ptr::null());
}
}
pub unsafe fn destroy_framebuffer(&self, framebuffer: vk::Framebuffer) {
unsafe {
self.device_fn.destroy_framebuffer(self.handle, framebuffer, ptr::null());
}
}
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 unsafe fn destroy_buffer(&self, buffer: vk::Buffer) {
unsafe {
self.device_fn.destroy_buffer(self.handle, buffer, ptr::null());
}
}
pub unsafe fn destroy_shader_module(&self, shader: vk::ShaderModule) {
unsafe {
self.device_fn.destroy_shader_module(self.handle, shader, ptr::null());
}
}
pub unsafe fn destroy_pipeline(&self, pipeline: vk::Pipeline) {
unsafe {
self.device_fn.destroy_pipeline(self.handle, pipeline, ptr::null());
}
}
pub unsafe fn destroy_semaphore(&self, semaphore: vk::Semaphore) {
unsafe {
self.device_fn.destroy_semaphore(self.handle, semaphore, ptr::null());
}
}
pub unsafe fn destroy_descriptor_pool(&self, pool: vk::DescriptorPool) {
unsafe {
self.device_fn.destroy_descriptor_pool(self.handle, pool, ptr::null());
}
}
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 unsafe fn free_descriptor_sets(&self,
pool: vk::DescriptorPool,
descriptor_sets: &[vk::DescriptorSet]) {
unsafe {
self.device_fn.free_descriptor_sets(self.handle,
pool,
descriptor_sets.len() as u32,
descriptor_sets.as_ptr());
}
}
pub unsafe fn update_descriptor_sets(&self,
descriptor_writes: &[vk::WriteDescriptorSet],
descriptor_copies: &[vk::CopyDescriptorSet]) {
unsafe {
self.device_fn.update_descriptor_sets(self.handle,
descriptor_writes.len() as u32,
descriptor_writes.as_ptr(),
descriptor_copies.len() as u32,
descriptor_copies.as_ptr());
}
}
pub fn create_sampler(&self, create_info: &vk::SamplerCreateInfo) -> VkResult<vk::Sampler> {
unsafe {
@ -163,21 +126,18 @@ impl Device {
dst_buffer: vk::Buffer,
regions: &[vk::BufferCopy]) {
unsafe {
self.device_fn.cmd_copy_buffer(command_buffer,
src_buffer,
dst_buffer,
regions.len() as u32,
regions.as_ptr());
}
}
pub unsafe fn cmd_copy_buffer_to_image(&self,
command_buffer: vk::CommandBuffer,
src_buffer: vk::Buffer,
dst_image: vk::Image,
dst_image_layout: vk::ImageLayout,
regions: &[vk::BufferImageCopy]) {
unsafe {
self.device_fn.cmd_copy_buffer_to_image(command_buffer,
src_buffer,
dst_image,
@ -185,7 +145,6 @@ impl Device {
regions.len() as u32,
regions.as_ptr());
}
}
pub unsafe fn cmd_copy_image(&self,
command_buffer: vk::CommandBuffer,
@ -194,7 +153,6 @@ impl Device {
dst_image: vk::Image,
dst_image_layout: vk::ImageLayout,
regions: &[vk::ImageCopy]) {
unsafe {
self.device_fn.cmd_copy_image(command_buffer,
src_image,
src_image_layout,
@ -203,12 +161,10 @@ impl Device {
regions.len() as u32,
regions.as_ptr());
}
}
pub unsafe fn allocate_descriptor_sets(&self,
create_info: &vk::DescriptorSetAllocateInfo)
-> VkResult<Vec<vk::DescriptorSet>> {
unsafe {
let mut desc_set = Vec::with_capacity(create_info.descriptor_set_count as usize);
let err_code = self.device_fn
.allocate_descriptor_sets(self.handle, create_info, desc_set.as_mut_ptr());
@ -219,7 +175,6 @@ impl Device {
_ => Err(err_code),
}
}
}
pub fn create_descriptor_set_layout(&self,
create_info: &vk::DescriptorSetLayoutCreateInfo)
-> VkResult<vk::DescriptorSetLayout> {
@ -261,7 +216,6 @@ impl Device {
command_buffer: vk::CommandBuffer,
flags: vk::CommandBufferResetFlags)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.reset_command_buffer(command_buffer, flags);
match err_code {
@ -269,10 +223,8 @@ impl Device {
_ => Err(err_code),
}
}
}
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());
match err_code {
@ -280,17 +232,14 @@ impl Device {
_ => Err(err_code),
}
}
}
pub unsafe fn cmd_bind_index_buffer(&self,
command_buffer: vk::CommandBuffer,
buffer: vk::Buffer,
offset: vk::DeviceSize,
index_type: vk::IndexType) {
unsafe {
self.device_fn.cmd_bind_index_buffer(command_buffer, buffer, offset, index_type);
}
}
pub unsafe fn cmd_draw_indexed(&self,
command_buffer: vk::CommandBuffer,
@ -300,7 +249,6 @@ impl Device {
vertex_offset: vk::int32_t,
first_instance: vk::uint32_t) {
unsafe {
self.device_fn.cmd_draw_indexed(command_buffer,
index_count,
instance_count,
@ -308,7 +256,6 @@ impl Device {
vertex_offset,
first_instance);
}
}
pub unsafe fn cmd_bind_descriptor_sets(&self,
command_buffer: vk::CommandBuffer,
@ -317,7 +264,6 @@ impl Device {
first_set: vk::uint32_t,
descriptor_sets: &[vk::DescriptorSet],
dynamic_offsets: &[vk::uint32_t]) {
unsafe {
self.device_fn.cmd_bind_descriptor_sets(command_buffer,
pipeline_bind_point,
layout,
@ -327,56 +273,45 @@ impl Device {
dynamic_offsets.len() as vk::uint32_t,
dynamic_offsets.as_ptr())
}
}
pub unsafe fn cmd_begin_render_pass(&self,
command_buffer: vk::CommandBuffer,
create_info: &vk::RenderPassBeginInfo,
contents: vk::SubpassContents) {
unsafe {
self.device_fn.cmd_begin_render_pass(command_buffer, create_info, contents);
}
}
pub unsafe fn cmd_bind_pipeline(&self,
command_buffer: vk::CommandBuffer,
pipeline_bind_point: vk::PipelineBindPoint,
pipeline: vk::Pipeline) {
unsafe {
self.device_fn.cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline);
}
}
pub unsafe fn cmd_set_scissor(&self,
command_buffer: vk::CommandBuffer,
scissors: &[vk::Rect2D]) {
unsafe {
self.device_fn
.cmd_set_scissor(command_buffer,
0,
scissors.len() as vk::uint32_t,
scissors.as_ptr());
}
}
pub unsafe fn cmd_bind_vertex_buffers(&self,
command_buffer: vk::CommandBuffer,
buffers: &[vk::Buffer],
offsets: &vk::DeviceSize) {
unsafe {
self.device_fn.cmd_bind_vertex_buffers(command_buffer,
0,
buffers.len() as vk::uint32_t,
buffers.as_ptr(),
offsets);
}
}
pub unsafe fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) {
unsafe {
self.device_fn.cmd_end_render_pass(command_buffer);
}
}
pub unsafe fn cmd_draw(&self,
command_buffer: vk::CommandBuffer,
@ -384,28 +319,24 @@ impl Device {
instance_count: vk::uint32_t,
first_vertex: vk::uint32_t,
first_instance: vk::uint32_t) {
unsafe {
self.device_fn.cmd_draw(command_buffer,
vertex_count,
instance_count,
first_vertex,
first_instance);
}
}
pub unsafe fn cmd_set_viewport(&self,
command_buffer: vk::CommandBuffer,
viewports: &[vk::Viewport]) {
unsafe {
self.device_fn.cmd_set_viewport(command_buffer,
0,
viewports.len() as vk::uint32_t,
viewports.as_ptr());
}
}
pub unsafe fn create_semaphore(&self,
pub fn create_semaphore(&self,
create_info: &vk::SemaphoreCreateInfo)
-> VkResult<vk::Semaphore> {
unsafe {
@ -475,26 +406,21 @@ impl Device {
flags: vk::MemoryMapFlags)
-> VkResult<&mut [T]> {
unsafe {
let mut data: *mut () = mem::uninitialized();
let err_code = self.device_fn
.map_memory(self.handle, memory, offset, size, flags, &mut data);
let x: *mut T = data as *mut T;
match err_code {
vk::Result::Success => {
Ok(::std::slice::from_raw_parts_mut(x,
size as vk::size_t / mem::size_of::<T>()))
Ok(::std::slice::from_raw_parts_mut(x, size as vk::size_t / mem::size_of::<T>()))
}
_ => Err(err_code),
}
}
}
pub unsafe fn unmap_memory(&self, memory: vk::DeviceMemory) {
unsafe {
self.device_fn.unmap_memory(self.handle, memory);
}
}
pub fn create_framebuffer(&self,
create_info: &vk::FramebufferCreateInfo)
@ -530,7 +456,6 @@ impl Device {
memory_barriers: &[vk::MemoryBarrier],
buffer_memory_barriers: &[vk::BufferMemoryBarrier],
image_memory_barriers: &[vk::ImageMemoryBarrier]) {
unsafe {
self.device_fn.cmd_pipeline_barrier(command_buffer,
src_stage_mask,
dst_stage_mask,
@ -542,7 +467,6 @@ impl Device {
image_memory_barriers.len() as vk::uint32_t,
image_memory_barriers.as_ptr());
}
}
pub fn create_render_pass(&self,
create_info: &vk::RenderPassCreateInfo)
@ -562,7 +486,6 @@ impl Device {
command_buffer: vk::CommandBuffer,
create_info: &vk::CommandBufferBeginInfo)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.begin_command_buffer(command_buffer, create_info);
match err_code {
@ -570,10 +493,8 @@ impl Device {
_ => Err(err_code),
}
}
}
pub unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> {
unsafe {
let err_code = self.device_fn
.end_command_buffer(command_buffer);
match err_code {
@ -581,7 +502,6 @@ impl Device {
_ => Err(err_code),
}
}
}
pub fn wait_for_fences(&self,
fences: &[vk::Fence],
@ -616,7 +536,6 @@ impl Device {
queue: vk::Queue,
create_info: &vk::PresentInfoKHR)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.queue_present_khr(queue, create_info);
match err_code {
@ -624,14 +543,12 @@ impl Device {
_ => Err(err_code),
}
}
}
pub unsafe fn queue_submit(&self,
queue: vk::Queue,
submits: &[vk::SubmitInfo],
fence: vk::Fence)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.queue_submit(queue,
submits.len() as vk::uint32_t,
@ -642,7 +559,6 @@ impl Device {
_ => Err(err_code),
}
}
}
pub fn create_image_view(&self,
create_info: &vk::ImageViewCreateInfo)
@ -662,7 +578,6 @@ impl Device {
pub unsafe fn allocate_command_buffers(&self,
create_info: &vk::CommandBufferAllocateInfo)
-> VkResult<Vec<vk::CommandBuffer>> {
unsafe {
let mut buffers = Vec::with_capacity(create_info.command_buffer_count as vk::size_t);
let err_code = self.device_fn
.allocate_command_buffers(self.handle, create_info, buffers.as_mut_ptr());
@ -672,7 +587,6 @@ impl Device {
_ => Err(err_code),
}
}
}
pub fn create_command_pool(&self,
create_info: &vk::CommandPoolCreateInfo)
@ -764,7 +678,6 @@ impl Device {
device_memory: vk::DeviceMemory,
offset: vk::DeviceSize)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.bind_buffer_memory(self.handle, buffer, device_memory, offset);
match err_code {
@ -772,14 +685,12 @@ impl Device {
_ => Err(err_code),
}
}
}
pub unsafe fn bind_image_memory(&self,
image: vk::Image,
device_memory: vk::DeviceMemory,
offset: vk::DeviceSize)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.bind_image_memory(self.handle, image, device_memory, offset);
match err_code {
@ -788,4 +699,3 @@ impl Device {
}
}
}
}

View file

@ -5,7 +5,6 @@ use instance::Instance;
use entry::Entry;
use vk;
pub struct DebugReport {
handle: vk::Instance,
debug_report_fn: vk::DebugReportFn,
@ -25,10 +24,8 @@ impl DebugReport {
}
pub unsafe fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) {
unsafe {
self.debug_report_fn.destroy_debug_report_callback_ext(self.handle, debug, ptr::null());
}
}
pub fn create_debug_report_callback_ext(&self,
create_info: &vk::DebugReportCallbackCreateInfoEXT)

View file

@ -13,7 +13,9 @@ pub struct Surface {
impl Surface {
pub fn new(entry: &Entry, instance: &Instance) -> Result<Surface, String> {
let surface_fn = vk::SurfaceFn::load(|name| {
unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }
unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
}
})?;
Ok(Surface {
handle: instance.handle(),
@ -102,8 +104,6 @@ impl Surface {
}
pub unsafe fn destroy_surface_khr(&self, surface: vk::SurfaceKHR) {
unsafe {
self.surface_fn.destroy_surface_khr(self.handle, surface, ptr::null());
}
}
}

View file

@ -13,9 +13,7 @@ pub struct Swapchain {
impl Swapchain {
pub fn new(instance: &Instance, device: &Device) -> Result<Swapchain, String> {
let swapchain_fn = vk::SwapchainFn::load(|name| {
unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
})?;
Ok(Swapchain {
handle: device.handle(),
@ -23,19 +21,16 @@ impl Swapchain {
})
}
pub fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) {
unsafe {
pub unsafe fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) {
self.swapchain_fn.destroy_swapchain_khr(self.handle, swapchain, ptr::null());
}
}
pub fn acquire_next_image_khr(&self,
pub unsafe fn acquire_next_image_khr(&self,
swapchain: vk::SwapchainKHR,
timeout: vk::uint64_t,
semaphore: vk::Semaphore,
fence: vk::Fence)
-> VkResult<vk::uint32_t> {
unsafe {
let mut index = mem::uninitialized();
let err_code = self.swapchain_fn
.acquire_next_image_khr(self.handle,
@ -49,7 +44,6 @@ impl Swapchain {
_ => Err(err_code),
}
}
}
pub fn create_swapchain_khr(&self,
create_info: &vk::SwapchainCreateInfoKHR)

View file

@ -4,8 +4,6 @@ use std::ptr;
use std::mem;
use vk;
use device::Device;
use entry::Entry;
use shared_library::dynamic_library::DynamicLibrary;
#[derive(Debug)]
pub enum DeviceError {
@ -23,7 +21,8 @@ impl Instance {
pub fn handle(&self) -> vk::Instance {
self.handle
}
pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
pub fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
Instance {
handle: handle,
instance_fn: instance_fn,
@ -56,10 +55,8 @@ impl Instance {
}
pub unsafe fn destroy_instance(&self) {
unsafe {
self.instance_fn.destroy_instance(self.handle, ptr::null());
}
}
pub fn get_physical_device_format_properties(&self,
physical_device: vk::PhysicalDevice,