Swtich device to the new extension version format

This commit is contained in:
maik klein 2016-12-30 05:42:34 +01:00
parent d964453d2d
commit 45936ae6bb
5 changed files with 419 additions and 394 deletions

View file

@ -16,7 +16,8 @@ use ash::device::Device;
use std::ptr;
use std::ffi::{CStr, CString};
use std::ops::Drop;
use ash::instance::{V1_0, InstanceV1_0};
pub use ash::instance::{V1_0, InstanceV1_0};
pub use ash::device::{DeviceV1_0};
// Simple offset_of macro akin to C++ offsetof
#[macro_export]
@ -32,7 +33,7 @@ macro_rules! offset_of{
}
}
pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(device: &Device,
pub fn record_submit_commandbuffer<F: FnOnce(&Device<V1_0>, vk::CommandBuffer)>(device: &Device<V1_0>,
command_buffer: vk::CommandBuffer,
submit_queue: vk::Queue,
wait_mask: &[vk::PipelineStageFlags],
@ -188,7 +189,7 @@ fn resize_callback(width: u32, height: u32) {
pub struct ExampleBase {
pub entry: Entry,
pub instance: Instance<V1_0>,
pub device: Device,
pub device: Device<V1_0>,
pub surface_loader: Surface,
pub swapchain_loader: Swapchain,
pub debug_report_loader: DebugReport,
@ -334,7 +335,7 @@ impl ExampleBase {
pp_enabled_extension_names: device_extension_names_raw.as_ptr(),
p_enabled_features: &features,
};
let device: Device = instance.create_device(pdevice, &device_create_info, None)
let device: Device<V1_0> = instance.create_device(pdevice, &device_create_info, None)
.unwrap();
let present_queue = device.get_device_queue(queue_family_index as u32, 0);

View file

@ -4,153 +4,149 @@ use std::mem;
use vk;
use ::RawPtr;
unsafe impl Sync for Device {}
unsafe impl Send for Device {}
use instance::{VkVersion, V1_0};
#[derive(Clone)]
pub struct Device {
handle: vk::Device,
device_fn: vk::DeviceFn,
// unsafe impl Sync for Device {}
// unsafe impl Send for Device {}
pub struct DeviceFpV1_0 {
pub device_fn: vk::DeviceFn,
}
impl Device {
pub fn handle(&self) -> vk::Device {
self.handle
pub trait DeviceV1_0 {
fn handle(&self) -> vk::Device;
fn fp_v1_0(&self) -> &vk::DeviceFn;
unsafe fn destroy_device(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_device(self.handle(), allocation_callbacks.as_raw_ptr());
}
pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self {
Device {
handle: handle,
device_fn: device_fn,
}
}
pub unsafe fn destroy_device(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_device(self.handle, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_sampler(&self,
unsafe fn destroy_sampler(&self,
sampler: vk::Sampler,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_sampler(self.handle, sampler, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_sampler(self.handle(), sampler, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn free_memory(&self,
unsafe fn free_memory(&self,
memory: vk::DeviceMemory,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.free_memory(self.handle, memory, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().free_memory(self.handle(), memory, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_fence(&self,
unsafe fn destroy_fence(&self,
fence: vk::Fence,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_fence(self.handle, fence, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_fence(self.handle(), fence, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_image(&self,
unsafe fn destroy_image(&self,
image: vk::Image,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_image(self.handle, image, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_image(self.handle(), image, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_command_pool(&self,
unsafe fn destroy_command_pool(&self,
pool: vk::CommandPool,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_command_pool(self.handle, pool, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_command_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_image_view(&self,
unsafe fn destroy_image_view(&self,
image_view: vk::ImageView,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_image_view(self.handle, image_view, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_image_view(self.handle(), image_view, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_render_pass(&self,
unsafe fn destroy_render_pass(&self,
renderpass: vk::RenderPass,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_render_pass(self.handle, renderpass, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_render_pass(self.handle(), renderpass, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_framebuffer(&self,
unsafe fn destroy_framebuffer(&self,
framebuffer: vk::Framebuffer,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_framebuffer(self.handle, framebuffer, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_framebuffer(self.handle(),
framebuffer,
allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_pipeline_layout(&self,
unsafe fn destroy_pipeline_layout(&self,
pipeline_layout: vk::PipelineLayout,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_pipeline_layout(self.handle,
self.fp_v1_0().destroy_pipeline_layout(self.handle(),
pipeline_layout,
allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_buffer(&self,
unsafe fn destroy_buffer(&self,
buffer: vk::Buffer,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_buffer(self.handle, buffer, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_buffer(self.handle(), buffer, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_shader_module(&self,
unsafe fn destroy_shader_module(&self,
shader: vk::ShaderModule,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_shader_module(self.handle, shader, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_shader_module(self.handle(), shader, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_pipeline(&self,
unsafe fn destroy_pipeline(&self,
pipeline: vk::Pipeline,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_pipeline(self.handle, pipeline, allocation_callbacks.as_raw_ptr());
self.fp_v1_0().destroy_pipeline(self.handle(), pipeline, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_semaphore(&self,
unsafe fn destroy_semaphore(&self,
semaphore: vk::Semaphore,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn.destroy_semaphore(self.handle, semaphore, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_semaphore(self.handle(), semaphore, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_descriptor_pool(&self,
unsafe fn destroy_descriptor_pool(&self,
pool: vk::DescriptorPool,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_descriptor_pool(self.handle, pool, allocation_callbacks.as_raw_ptr());
self.fp_v1_0()
.destroy_descriptor_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr());
}
pub unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.device_fn
.destroy_descriptor_set_layout(self.handle, layout, allocation_callbacks.as_raw_ptr());
unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0()
.destroy_descriptor_set_layout(self.handle(),
layout,
allocation_callbacks.as_raw_ptr());
}
pub unsafe fn free_descriptor_sets(&self,
unsafe fn free_descriptor_sets(&self,
pool: vk::DescriptorPool,
descriptor_sets: &[vk::DescriptorSet]) {
self.device_fn.free_descriptor_sets(self.handle,
self.fp_v1_0().free_descriptor_sets(self.handle(),
pool,
descriptor_sets.len() as u32,
descriptor_sets.as_ptr());
}
pub unsafe fn update_descriptor_sets(&self,
unsafe fn update_descriptor_sets(&self,
descriptor_writes: &[vk::WriteDescriptorSet],
descriptor_copies: &[vk::CopyDescriptorSet]) {
self.device_fn.update_descriptor_sets(self.handle,
self.fp_v1_0().update_descriptor_sets(self.handle(),
descriptor_writes.len() as u32,
descriptor_writes.as_ptr(),
descriptor_copies.len() as u32,
descriptor_copies.as_ptr());
}
pub unsafe fn create_sampler(&self,
unsafe fn create_sampler(&self,
create_info: &vk::SamplerCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Sampler> {
let mut sampler = mem::uninitialized();
let err_code = self.device_fn
.create_sampler(self.handle,
let err_code = self.fp_v1_0()
.create_sampler(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut sampler);
@ -160,26 +156,26 @@ impl Device {
}
}
pub unsafe fn cmd_copy_buffer(&self,
unsafe fn cmd_copy_buffer(&self,
command_buffer: vk::CommandBuffer,
src_buffer: vk::Buffer,
dst_buffer: vk::Buffer,
regions: &[vk::BufferCopy]) {
self.device_fn.cmd_copy_buffer(command_buffer,
self.fp_v1_0().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,
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]) {
self.device_fn.cmd_copy_buffer_to_image(command_buffer,
self.fp_v1_0().cmd_copy_buffer_to_image(command_buffer,
src_buffer,
dst_image,
dst_image_layout,
@ -187,14 +183,14 @@ impl Device {
regions.as_ptr());
}
pub unsafe fn cmd_copy_image(&self,
unsafe fn cmd_copy_image(&self,
command_buffer: vk::CommandBuffer,
src_image: vk::Image,
src_image_layout: vk::ImageLayout,
dst_image: vk::Image,
dst_image_layout: vk::ImageLayout,
regions: &[vk::ImageCopy]) {
self.device_fn.cmd_copy_image(command_buffer,
self.fp_v1_0().cmd_copy_image(command_buffer,
src_image,
src_image_layout,
dst_image,
@ -203,12 +199,12 @@ impl Device {
regions.as_ptr());
}
pub unsafe fn allocate_descriptor_sets(&self,
unsafe fn allocate_descriptor_sets(&self,
create_info: &vk::DescriptorSetAllocateInfo)
-> VkResult<Vec<vk::DescriptorSet>> {
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());
let err_code = self.fp_v1_0()
.allocate_descriptor_sets(self.handle(), create_info, desc_set.as_mut_ptr());
desc_set.set_len(create_info.descriptor_set_count as usize);
match err_code {
@ -217,13 +213,13 @@ impl Device {
}
}
pub unsafe fn create_descriptor_set_layout(&self,
unsafe fn create_descriptor_set_layout(&self,
create_info: &vk::DescriptorSetLayoutCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::DescriptorSetLayout> {
let mut layout = mem::uninitialized();
let err_code = self.device_fn
.create_descriptor_set_layout(self.handle,
let err_code = self.fp_v1_0()
.create_descriptor_set_layout(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut layout);
@ -233,9 +229,9 @@ impl Device {
}
}
pub fn device_wait_idle(&self) -> VkResult<()> {
fn device_wait_idle(&self) -> VkResult<()> {
unsafe {
let err_code = self.device_fn.device_wait_idle(self.handle);
let err_code = self.fp_v1_0().device_wait_idle(self.handle());
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
@ -243,13 +239,13 @@ impl Device {
}
}
pub unsafe fn create_descriptor_pool(&self,
unsafe fn create_descriptor_pool(&self,
create_info: &vk::DescriptorPoolCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::DescriptorPool> {
let mut pool = mem::uninitialized();
let err_code = self.device_fn
.create_descriptor_pool(self.handle,
let err_code = self.fp_v1_0()
.create_descriptor_pool(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut pool);
@ -259,11 +255,11 @@ impl Device {
}
}
pub unsafe fn reset_command_buffer(&self,
unsafe fn reset_command_buffer(&self,
command_buffer: vk::CommandBuffer,
flags: vk::CommandBufferResetFlags)
-> VkResult<()> {
let err_code = self.device_fn
let err_code = self.fp_v1_0()
.reset_command_buffer(command_buffer, flags);
match err_code {
vk::Result::Success => Ok(()),
@ -271,24 +267,24 @@ impl Device {
}
}
pub unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> {
let err_code = self.device_fn
.reset_fences(self.handle, fences.len() as vk::uint32_t, fences.as_ptr());
unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> {
let err_code = self.fp_v1_0()
.reset_fences(self.handle(), fences.len() as vk::uint32_t, fences.as_ptr());
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
pub unsafe fn cmd_bind_index_buffer(&self,
unsafe fn cmd_bind_index_buffer(&self,
command_buffer: vk::CommandBuffer,
buffer: vk::Buffer,
offset: vk::DeviceSize,
index_type: vk::IndexType) {
self.device_fn.cmd_bind_index_buffer(command_buffer, buffer, offset, index_type);
self.fp_v1_0().cmd_bind_index_buffer(command_buffer, buffer, offset, index_type);
}
pub unsafe fn cmd_draw_indexed(&self,
unsafe fn cmd_draw_indexed(&self,
command_buffer: vk::CommandBuffer,
index_count: vk::uint32_t,
instance_count: vk::uint32_t,
@ -296,7 +292,7 @@ impl Device {
vertex_offset: vk::int32_t,
first_instance: vk::uint32_t) {
self.device_fn.cmd_draw_indexed(command_buffer,
self.fp_v1_0().cmd_draw_indexed(command_buffer,
index_count,
instance_count,
first_index,
@ -304,14 +300,14 @@ impl Device {
first_instance);
}
pub unsafe fn cmd_bind_descriptor_sets(&self,
unsafe fn cmd_bind_descriptor_sets(&self,
command_buffer: vk::CommandBuffer,
pipeline_bind_point: vk::PipelineBindPoint,
layout: vk::PipelineLayout,
first_set: vk::uint32_t,
descriptor_sets: &[vk::DescriptorSet],
dynamic_offsets: &[vk::uint32_t]) {
self.device_fn.cmd_bind_descriptor_sets(command_buffer,
self.fp_v1_0().cmd_bind_descriptor_sets(command_buffer,
pipeline_bind_point,
layout,
first_set,
@ -321,74 +317,72 @@ impl Device {
dynamic_offsets.as_ptr())
}
pub unsafe fn cmd_begin_render_pass(&self,
unsafe fn cmd_begin_render_pass(&self,
command_buffer: vk::CommandBuffer,
create_info: &vk::RenderPassBeginInfo,
contents: vk::SubpassContents) {
self.device_fn.cmd_begin_render_pass(command_buffer, create_info, contents);
self.fp_v1_0().cmd_begin_render_pass(command_buffer, create_info, contents);
}
pub unsafe fn cmd_bind_pipeline(&self,
unsafe fn cmd_bind_pipeline(&self,
command_buffer: vk::CommandBuffer,
pipeline_bind_point: vk::PipelineBindPoint,
pipeline: vk::Pipeline) {
self.device_fn.cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline);
self.fp_v1_0().cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline);
}
pub unsafe fn cmd_set_scissor(&self,
command_buffer: vk::CommandBuffer,
scissors: &[vk::Rect2D]) {
self.device_fn
unsafe fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) {
self.fp_v1_0()
.cmd_set_scissor(command_buffer,
0,
scissors.len() as vk::uint32_t,
scissors.as_ptr());
}
pub unsafe fn cmd_bind_vertex_buffers(&self,
unsafe fn cmd_bind_vertex_buffers(&self,
command_buffer: vk::CommandBuffer,
buffers: &[vk::Buffer],
offsets: &vk::DeviceSize) {
self.device_fn.cmd_bind_vertex_buffers(command_buffer,
self.fp_v1_0().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) {
self.device_fn.cmd_end_render_pass(command_buffer);
unsafe fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) {
self.fp_v1_0().cmd_end_render_pass(command_buffer);
}
pub unsafe fn cmd_draw(&self,
unsafe fn cmd_draw(&self,
command_buffer: vk::CommandBuffer,
vertex_count: vk::uint32_t,
instance_count: vk::uint32_t,
first_vertex: vk::uint32_t,
first_instance: vk::uint32_t) {
self.device_fn.cmd_draw(command_buffer,
self.fp_v1_0().cmd_draw(command_buffer,
vertex_count,
instance_count,
first_vertex,
first_instance);
}
pub unsafe fn cmd_set_viewport(&self,
unsafe fn cmd_set_viewport(&self,
command_buffer: vk::CommandBuffer,
viewports: &[vk::Viewport]) {
self.device_fn.cmd_set_viewport(command_buffer,
self.fp_v1_0().cmd_set_viewport(command_buffer,
0,
viewports.len() as vk::uint32_t,
viewports.as_ptr());
}
pub unsafe fn create_semaphore(&self,
unsafe fn create_semaphore(&self,
create_info: &vk::SemaphoreCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Semaphore> {
let mut semaphore = mem::uninitialized();
let err_code = self.device_fn
.create_semaphore(self.handle,
let err_code = self.fp_v1_0()
.create_semaphore(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut semaphore);
@ -398,14 +392,14 @@ impl Device {
}
}
pub unsafe fn create_graphics_pipelines(&self,
unsafe fn create_graphics_pipelines(&self,
pipeline_cache: vk::PipelineCache,
create_infos: &[vk::GraphicsPipelineCreateInfo],
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<Vec<vk::Pipeline>> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let err_code = self.device_fn
.create_graphics_pipelines(self.handle,
let err_code = self.fp_v1_0()
.create_graphics_pipelines(self.handle(),
pipeline_cache,
create_infos.len() as vk::uint32_t,
create_infos.as_ptr(),
@ -418,13 +412,13 @@ impl Device {
}
}
pub unsafe fn create_buffer(&self,
unsafe fn create_buffer(&self,
create_info: &vk::BufferCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Buffer> {
let mut buffer = mem::uninitialized();
let err_code = self.device_fn
.create_buffer(self.handle,
let err_code = self.fp_v1_0()
.create_buffer(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut buffer);
@ -434,14 +428,14 @@ impl Device {
}
}
pub fn create_pipeline_layout(&self,
fn create_pipeline_layout(&self,
create_info: &vk::PipelineLayoutCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::PipelineLayout> {
unsafe {
let mut pipeline_layout = mem::uninitialized();
let err_code = self.device_fn
.create_pipeline_layout(self.handle,
let err_code = self.fp_v1_0()
.create_pipeline_layout(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut pipeline_layout);
@ -452,7 +446,7 @@ impl Device {
}
}
pub unsafe fn map_memory<T>(&self,
unsafe fn map_memory<T>(&self,
memory: vk::DeviceMemory,
offset: vk::DeviceSize,
size: vk::DeviceSize,
@ -460,8 +454,8 @@ impl Device {
-> VkResult<&mut [T]> {
let mut data: *mut () = mem::uninitialized();
let err_code = self.device_fn
.map_memory(self.handle, memory, offset, size, flags, &mut data);
let err_code = self.fp_v1_0()
.map_memory(self.handle(), memory, offset, size, flags, &mut data);
let x: *mut T = data as *mut T;
match err_code {
vk::Result::Success => {
@ -471,18 +465,18 @@ impl Device {
}
}
pub unsafe fn unmap_memory(&self, memory: vk::DeviceMemory) {
self.device_fn.unmap_memory(self.handle, memory);
unsafe fn unmap_memory(&self, memory: vk::DeviceMemory) {
self.fp_v1_0().unmap_memory(self.handle(), memory);
}
pub fn create_framebuffer(&self,
fn create_framebuffer(&self,
create_info: &vk::FramebufferCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Framebuffer> {
unsafe {
let mut framebuffer = mem::uninitialized();
let err_code = self.device_fn
.create_framebuffer(self.handle,
let err_code = self.fp_v1_0()
.create_framebuffer(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut framebuffer);
@ -493,17 +487,17 @@ impl Device {
}
}
pub unsafe fn get_device_queue(&self,
unsafe fn get_device_queue(&self,
queue_family_index: vk::uint32_t,
queue_index: vk::uint32_t)
-> vk::Queue {
let mut queue = mem::uninitialized();
self.device_fn
.get_device_queue(self.handle, queue_family_index, queue_index, &mut queue);
self.fp_v1_0()
.get_device_queue(self.handle(), queue_family_index, queue_index, &mut queue);
queue
}
pub unsafe fn cmd_pipeline_barrier(&self,
unsafe fn cmd_pipeline_barrier(&self,
command_buffer: vk::CommandBuffer,
src_stage_mask: vk::PipelineStageFlags,
dst_stage_mask: vk::PipelineStageFlags,
@ -511,7 +505,7 @@ impl Device {
memory_barriers: &[vk::MemoryBarrier],
buffer_memory_barriers: &[vk::BufferMemoryBarrier],
image_memory_barriers: &[vk::ImageMemoryBarrier]) {
self.device_fn.cmd_pipeline_barrier(command_buffer,
self.fp_v1_0().cmd_pipeline_barrier(command_buffer,
src_stage_mask,
dst_stage_mask,
dependency_flags,
@ -523,13 +517,13 @@ impl Device {
image_memory_barriers.as_ptr());
}
pub unsafe fn create_render_pass(&self,
unsafe fn create_render_pass(&self,
create_info: &vk::RenderPassCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::RenderPass> {
let mut renderpass = mem::uninitialized();
let err_code = self.device_fn
.create_render_pass(self.handle,
let err_code = self.fp_v1_0()
.create_render_pass(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut renderpass);
@ -539,11 +533,11 @@ impl Device {
}
}
pub unsafe fn begin_command_buffer(&self,
unsafe fn begin_command_buffer(&self,
command_buffer: vk::CommandBuffer,
create_info: &vk::CommandBufferBeginInfo)
-> VkResult<()> {
let err_code = self.device_fn
let err_code = self.fp_v1_0()
.begin_command_buffer(command_buffer, create_info);
match err_code {
vk::Result::Success => Ok(()),
@ -551,8 +545,8 @@ impl Device {
}
}
pub unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> {
let err_code = self.device_fn
unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> {
let err_code = self.fp_v1_0()
.end_command_buffer(command_buffer);
match err_code {
vk::Result::Success => Ok(()),
@ -560,13 +554,13 @@ impl Device {
}
}
pub unsafe fn wait_for_fences(&self,
unsafe fn wait_for_fences(&self,
fences: &[vk::Fence],
wait_all: bool,
timeout: vk::uint64_t)
-> VkResult<()> {
let err_code = self.device_fn
.wait_for_fences(self.handle,
let err_code = self.fp_v1_0()
.wait_for_fences(self.handle(),
fences.len() as vk::uint32_t,
fences.as_ptr(),
wait_all as vk::uint32_t,
@ -577,20 +571,20 @@ impl Device {
}
}
pub unsafe fn queue_wait_idle(&self, queue: vk::Queue) -> VkResult<()> {
let err_code = self.device_fn.queue_wait_idle(queue);
unsafe fn queue_wait_idle(&self, queue: vk::Queue) -> VkResult<()> {
let err_code = self.fp_v1_0().queue_wait_idle(queue);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
pub unsafe fn queue_submit(&self,
unsafe fn queue_submit(&self,
queue: vk::Queue,
submits: &[vk::SubmitInfo],
fence: vk::Fence)
-> VkResult<()> {
let err_code = self.device_fn
let err_code = self.fp_v1_0()
.queue_submit(queue,
submits.len() as vk::uint32_t,
submits.as_ptr(),
@ -601,13 +595,13 @@ impl Device {
}
}
pub unsafe fn create_image_view(&self,
unsafe fn create_image_view(&self,
create_info: &vk::ImageViewCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::ImageView> {
let mut image_view = mem::uninitialized();
let err_code = self.device_fn
.create_image_view(self.handle,
let err_code = self.fp_v1_0()
.create_image_view(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut image_view);
@ -618,12 +612,12 @@ impl Device {
}
pub unsafe fn allocate_command_buffers(&self,
unsafe fn allocate_command_buffers(&self,
create_info: &vk::CommandBufferAllocateInfo)
-> VkResult<Vec<vk::CommandBuffer>> {
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());
let err_code = self.fp_v1_0()
.allocate_command_buffers(self.handle(), create_info, buffers.as_mut_ptr());
buffers.set_len(create_info.command_buffer_count as vk::size_t);
match err_code {
vk::Result::Success => Ok(buffers),
@ -631,13 +625,13 @@ impl Device {
}
}
pub unsafe fn create_command_pool(&self,
unsafe fn create_command_pool(&self,
create_info: &vk::CommandPoolCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::CommandPool> {
let mut pool = mem::uninitialized();
let err_code = self.device_fn
.create_command_pool(self.handle,
let err_code = self.fp_v1_0()
.create_command_pool(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut pool);
@ -647,13 +641,13 @@ impl Device {
}
}
pub unsafe fn create_image(&self,
unsafe fn create_image(&self,
create_info: &vk::ImageCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Image> {
let mut image = mem::uninitialized();
let err_code = self.device_fn
.create_image(self.handle,
let err_code = self.fp_v1_0()
.create_image(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut image);
@ -663,31 +657,31 @@ impl Device {
}
}
pub fn get_image_memory_requirements(&self, image: vk::Image) -> vk::MemoryRequirements {
fn get_image_memory_requirements(&self, image: vk::Image) -> vk::MemoryRequirements {
unsafe {
let mut mem_req = mem::uninitialized();
self.device_fn
.get_image_memory_requirements(self.handle, image, &mut mem_req);
self.fp_v1_0()
.get_image_memory_requirements(self.handle(), image, &mut mem_req);
mem_req
}
}
pub fn get_buffer_memory_requirements(&self, buffer: vk::Buffer) -> vk::MemoryRequirements {
fn get_buffer_memory_requirements(&self, buffer: vk::Buffer) -> vk::MemoryRequirements {
unsafe {
let mut mem_req = mem::uninitialized();
self.device_fn
.get_buffer_memory_requirements(self.handle, buffer, &mut mem_req);
self.fp_v1_0()
.get_buffer_memory_requirements(self.handle(), buffer, &mut mem_req);
mem_req
}
}
pub unsafe fn allocate_memory(&self,
unsafe fn allocate_memory(&self,
create_info: &vk::MemoryAllocateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::DeviceMemory> {
let mut memory = mem::uninitialized();
let err_code = self.device_fn
.allocate_memory(self.handle,
let err_code = self.fp_v1_0()
.allocate_memory(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut memory);
@ -697,13 +691,13 @@ impl Device {
}
}
pub unsafe fn create_shader_module(&self,
unsafe fn create_shader_module(&self,
create_info: &vk::ShaderModuleCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::ShaderModule> {
let mut shader = mem::uninitialized();
let err_code = self.device_fn
.create_shader_module(self.handle,
let err_code = self.fp_v1_0()
.create_shader_module(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut shader);
@ -713,13 +707,13 @@ impl Device {
}
}
pub unsafe fn create_fence(&self,
unsafe fn create_fence(&self,
create_info: &vk::FenceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::Fence> {
let mut fence = mem::uninitialized();
let err_code = self.device_fn
.create_fence(self.handle,
let err_code = self.fp_v1_0()
.create_fence(self.handle(),
create_info,
allocation_callbacks.as_raw_ptr(),
&mut fence);
@ -729,29 +723,58 @@ impl Device {
}
}
pub unsafe fn bind_buffer_memory(&self,
unsafe fn bind_buffer_memory(&self,
buffer: vk::Buffer,
device_memory: vk::DeviceMemory,
offset: vk::DeviceSize)
-> VkResult<()> {
let err_code = self.device_fn
.bind_buffer_memory(self.handle, buffer, device_memory, offset);
let err_code = self.fp_v1_0()
.bind_buffer_memory(self.handle(), buffer, device_memory, offset);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
pub unsafe fn bind_image_memory(&self,
unsafe fn bind_image_memory(&self,
image: vk::Image,
device_memory: vk::DeviceMemory,
offset: vk::DeviceSize)
-> VkResult<()> {
let err_code = self.device_fn
.bind_image_memory(self.handle, image, device_memory, offset);
let err_code = self.fp_v1_0()
.bind_image_memory(self.handle(), image, device_memory, offset);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
}
#[derive(Clone)]
pub struct Device<V: VkVersion> {
handle: vk::Device,
device_fn: V::DeviceFp,
}
impl DeviceV1_0 for Device<V1_0> {
fn handle(&self) -> vk::Device {
self.handle
}
fn fp_v1_0(&self) -> &vk::DeviceFn {
&self.device_fn.device_fn
}
}
impl<V: VkVersion> Device<V> {
pub fn handle(&self) -> vk::Device {
self.handle
}
pub unsafe fn from_raw(handle: vk::Device, device_fn: V::DeviceFp) -> Self {
Device {
handle: handle,
device_fn: device_fn,
}
}
}

View file

@ -15,7 +15,7 @@ pub struct Swapchain {
}
impl Swapchain {
pub fn new(instance: &Instance<V1_0>, device: &Device) -> Result<Swapchain, Vec<&'static str>> {
pub fn new(instance: &Instance<V1_0>, device: &Device<V1_0>) -> Result<Swapchain, Vec<&'static str>> {
let swapchain_fn = vk::SwapchainFn::load(|name| {
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
})?;

View file

@ -14,6 +14,7 @@ pub struct Win32Surface {
win32_surface_fn: vk::Win32SurfaceFn,
}
impl Win32Surface {
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<Win32Surface, Vec<&'static str>> {
let surface_fn = vk::Win32SurfaceFn::load(|name| {

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::ptr;
use std::mem;
use vk;
use device::Device;
use device::{Device, DeviceFpV1_0};
use ::RawPtr;
#[derive(Debug)]
@ -17,23 +17,22 @@ pub trait VkVersion{
type DeviceFp;
}
#[warn(non_camel_case_types)]
pub struct V1_0;
impl VkVersion for V1_0 {
type InstanceFp = InstanceFpV1_0;
type DeviceFp = ();
type DeviceFp = DeviceFpV1_0;
}
#[warn(non_camel_case_types)]
pub struct InstanceFpV1_0 {
pub instance_fn: vk::InstanceFn
pub instance_fn: vk::InstanceFn,
}
#[derive(Clone)]
pub struct Instance<V: VkVersion> {
handle: vk::Instance,
instance_fp: V::InstanceFp
instance_fp: V::InstanceFp,
}
impl InstanceV1_0 for Instance<V1_0> {
@ -53,21 +52,17 @@ impl<V: VkVersion> Instance<V> {
pub fn from_raw(handle: vk::Instance, version: V::InstanceFp) -> Self {
Instance {
handle: handle,
instance_fp: version
instance_fp: version,
}
}
}
}
#[warn(non_camel_case_types)]
pub trait InstanceV1_0 {
fn handle(&self) -> vk::Instance;
fn fp_v1_0(&self) -> &vk::InstanceFn;
unsafe fn create_device(&self,
impl Instance<V1_0> {
pub unsafe fn create_device(&self,
physical_device: vk::PhysicalDevice,
create_info: &vk::DeviceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> Result<Device, DeviceError> {
-> Result<Device<V1_0>, DeviceError> {
let mut device: vk::Device = mem::uninitialized();
let err_code = self.fp_v1_0()
.create_device(physical_device,
@ -80,8 +75,14 @@ pub trait InstanceV1_0 {
let device_fn = vk::DeviceFn::load(|name| {
mem::transmute(self.fp_v1_0().get_device_proc_addr(device, name.as_ptr()))
}).map_err(|err| DeviceError::LoadError(err))?;
Ok(Device::from_raw(device, device_fn))
Ok(Device::from_raw(device, DeviceFpV1_0 { device_fn: device_fn }))
}
}
#[warn(non_camel_case_types)]
pub trait InstanceV1_0 {
fn handle(&self) -> vk::Instance;
fn fp_v1_0(&self) -> &vk::InstanceFn;
fn get_device_proc_addr(&self,
device: vk::Device,
p_name: *const vk::c_char)
@ -178,4 +179,3 @@ pub trait InstanceV1_0 {
// pub trait InstanceMajor1Minor1: InstanceMajor1Minor0 {}
// pub trait InstanceMajor1Minor2: InstanceMajor1Minor1 {}