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 vk;
use std::ptr; use std::ptr;
pub trait VkAllocation { pub trait VkAllocation {
@ -37,32 +38,32 @@ pub trait VkAllocation {
pub struct DefaultAllocatorCallback; pub struct DefaultAllocatorCallback;
impl VkAllocation for DefaultAllocatorCallback { impl VkAllocation for DefaultAllocatorCallback {
unsafe extern "system" fn allocation(user: *mut (), unsafe extern "system" fn allocation(_: *mut (),
a: vk::size_t, _: vk::size_t,
b: vk::size_t, _: vk::size_t,
c: vk::SystemAllocationScope) _: vk::SystemAllocationScope)
-> *mut () { -> *mut () {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn reallocation(a: *mut vk::c_void, unsafe extern "system" fn reallocation(_: *mut vk::c_void,
b: *mut vk::c_void, _: *mut vk::c_void,
c: vk::size_t, _: vk::size_t,
d: vk::size_t, _: vk::size_t,
e: vk::SystemAllocationScope) _: vk::SystemAllocationScope)
-> *mut vk::c_void { -> *mut vk::c_void {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn free(a: *mut vk::c_void, b: *mut vk::c_void) {} unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {}
unsafe extern "system" fn internal_allocation(a: *mut vk::c_void, unsafe extern "system" fn internal_allocation(_: *mut vk::c_void,
b: vk::size_t, _: vk::size_t,
c: vk::InternalAllocationType, _: vk::InternalAllocationType,
d: vk::SystemAllocationScope) { _: vk::SystemAllocationScope) {
} }
unsafe extern "system" fn internal_free(a: *mut vk::c_void, unsafe extern "system" fn internal_free(_: *mut vk::c_void,
b: vk::size_t, _: vk::size_t,
c: vk::InternalAllocationType, _: vk::InternalAllocationType,
d: vk::SystemAllocationScope) { _: vk::SystemAllocationScope) {
} }
fn create_allocation_callback() -> Option<vk::AllocationCallbacks> { fn create_allocation_callback() -> Option<vk::AllocationCallbacks> {
None None

View file

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

View file

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

View file

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

View file

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

View file

@ -4,8 +4,6 @@ use std::ptr;
use std::mem; use std::mem;
use vk; use vk;
use device::Device; use device::Device;
use entry::Entry;
use shared_library::dynamic_library::DynamicLibrary;
#[derive(Debug)] #[derive(Debug)]
pub enum DeviceError { pub enum DeviceError {
@ -20,10 +18,11 @@ pub struct Instance {
} }
impl Instance { impl Instance {
pub fn handle(&self) -> vk::Instance{ pub fn handle(&self) -> vk::Instance {
self.handle 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 { Instance {
handle: handle, handle: handle,
instance_fn: instance_fn, instance_fn: instance_fn,
@ -56,10 +55,8 @@ impl Instance {
} }
pub unsafe fn destroy_instance(&self) { pub unsafe fn destroy_instance(&self) {
unsafe {
self.instance_fn.destroy_instance(self.handle, ptr::null()); self.instance_fn.destroy_instance(self.handle, ptr::null());
} }
}
pub fn get_physical_device_format_properties(&self, pub fn get_physical_device_format_properties(&self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,