Reformat project with the new rustfmt

This commit is contained in:
Maik Klein 2017-07-06 18:00:05 +02:00
parent f32988a0c6
commit e8b726a483
16 changed files with 862 additions and 572 deletions

View file

@ -2,26 +2,32 @@
use vk; use vk;
use std::ptr; use std::ptr;
pub trait VkAllocation { pub trait VkAllocation {
unsafe extern "system" fn allocation(*mut (), unsafe extern "system" fn allocation(
vk::size_t, *mut (),
vk::size_t, vk::size_t,
vk::SystemAllocationScope) vk::size_t,
-> *mut (); vk::SystemAllocationScope,
unsafe extern "system" fn reallocation(*mut vk::c_void, ) -> *mut ();
*mut vk::c_void, unsafe extern "system" fn reallocation(
vk::size_t, *mut vk::c_void,
vk::size_t, *mut vk::c_void,
vk::SystemAllocationScope) vk::size_t,
-> *mut vk::c_void; vk::size_t,
vk::SystemAllocationScope,
) -> *mut vk::c_void;
unsafe extern "system" fn free(*mut vk::c_void, *mut vk::c_void); unsafe extern "system" fn free(*mut vk::c_void, *mut vk::c_void);
unsafe extern "system" fn internal_allocation(*mut vk::c_void, unsafe extern "system" fn internal_allocation(
vk::size_t, *mut vk::c_void,
vk::InternalAllocationType, vk::size_t,
vk::SystemAllocationScope); vk::InternalAllocationType,
unsafe extern "system" fn internal_free(*mut vk::c_void, vk::SystemAllocationScope,
vk::size_t, );
vk::InternalAllocationType, unsafe extern "system" fn internal_free(
vk::SystemAllocationScope); *mut vk::c_void,
vk::size_t,
vk::InternalAllocationType,
vk::SystemAllocationScope,
);
fn create_allocation_callback() -> Option<vk::AllocationCallbacks> { fn create_allocation_callback() -> Option<vk::AllocationCallbacks> {
let alloc = vk::AllocationCallbacks { let alloc = vk::AllocationCallbacks {
p_user_data: ptr::null_mut(), p_user_data: ptr::null_mut(),
@ -39,61 +45,73 @@ pub struct DefaultAllocatorCallback;
pub struct TestAlloc; pub struct TestAlloc;
impl VkAllocation for TestAlloc { impl VkAllocation for TestAlloc {
unsafe extern "system" fn allocation(_: *mut (), unsafe extern "system" fn allocation(
_: vk::size_t, _: *mut (),
_: vk::size_t, _: vk::size_t,
_: vk::SystemAllocationScope) _: vk::size_t,
-> *mut () { _: vk::SystemAllocationScope,
) -> *mut () {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn reallocation(_: *mut vk::c_void, unsafe extern "system" fn reallocation(
_: *mut vk::c_void, _: *mut vk::c_void,
_: vk::size_t, _: *mut vk::c_void,
_: vk::size_t, _: vk::size_t,
_: vk::SystemAllocationScope) _: vk::size_t,
-> *mut vk::c_void { _: vk::SystemAllocationScope,
) -> *mut vk::c_void {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {} unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {}
unsafe extern "system" fn internal_allocation(_: *mut vk::c_void, unsafe extern "system" fn internal_allocation(
_: vk::size_t, _: *mut vk::c_void,
_: vk::InternalAllocationType, _: vk::size_t,
_: vk::SystemAllocationScope) { _: vk::InternalAllocationType,
_: vk::SystemAllocationScope,
) {
} }
unsafe extern "system" fn internal_free(_: *mut vk::c_void, unsafe extern "system" fn internal_free(
_: vk::size_t, _: *mut vk::c_void,
_: vk::InternalAllocationType, _: vk::size_t,
_: vk::SystemAllocationScope) { _: vk::InternalAllocationType,
_: vk::SystemAllocationScope,
) {
} }
} }
impl VkAllocation for DefaultAllocatorCallback { impl VkAllocation for DefaultAllocatorCallback {
unsafe extern "system" fn allocation(_: *mut (), unsafe extern "system" fn allocation(
_: vk::size_t, _: *mut (),
_: vk::size_t, _: vk::size_t,
_: vk::SystemAllocationScope) _: vk::size_t,
-> *mut () { _: vk::SystemAllocationScope,
) -> *mut () {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn reallocation(_: *mut vk::c_void, unsafe extern "system" fn reallocation(
_: *mut vk::c_void, _: *mut vk::c_void,
_: vk::size_t, _: *mut vk::c_void,
_: vk::size_t, _: vk::size_t,
_: vk::SystemAllocationScope) _: vk::size_t,
-> *mut vk::c_void { _: vk::SystemAllocationScope,
) -> *mut vk::c_void {
ptr::null_mut() ptr::null_mut()
} }
unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {} unsafe extern "system" fn free(_: *mut vk::c_void, _: *mut vk::c_void) {}
unsafe extern "system" fn internal_allocation(_: *mut vk::c_void, unsafe extern "system" fn internal_allocation(
_: vk::size_t, _: *mut vk::c_void,
_: vk::InternalAllocationType, _: vk::size_t,
_: vk::SystemAllocationScope) { _: vk::InternalAllocationType,
_: vk::SystemAllocationScope,
) {
} }
unsafe extern "system" fn internal_free(_: *mut vk::c_void, unsafe extern "system" fn internal_free(
_: vk::size_t, _: *mut vk::c_void,
_: vk::InternalAllocationType, _: vk::size_t,
_: vk::SystemAllocationScope) { _: vk::InternalAllocationType,
_: vk::SystemAllocationScope,
) {
} }
fn create_allocation_callback() -> Option<vk::AllocationCallbacks> { fn create_allocation_callback() -> Option<vk::AllocationCallbacks> {
None None

View file

@ -48,8 +48,8 @@ pub enum InstanceError {
VkError(vk::Result), VkError(vk::Result),
} }
impl fmt::Display for InstanceError{ impl fmt::Display for InstanceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "InstanceError::{:?}", self) write!(f, "InstanceError::{:?}", self)
} }
} }
@ -59,8 +59,8 @@ impl Error for InstanceError {
"InstanceError" "InstanceError"
} }
fn cause(&self) -> Option<&Error>{ fn cause(&self) -> Option<&Error> {
if let &InstanceError::VkError(ref err) = self{ if let &InstanceError::VkError(ref err) = self {
return err.cause(); return err.cause();
} }
None None
@ -73,23 +73,26 @@ pub trait EntryV1_0 {
fn fp_v1_0(&self) -> &vk::EntryFnV1_0; fn fp_v1_0(&self) -> &vk::EntryFnV1_0;
fn static_fn(&self) -> &vk::StaticFn; fn static_fn(&self) -> &vk::StaticFn;
fn create_instance(&self, fn create_instance(
create_info: &vk::InstanceCreateInfo, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::InstanceCreateInfo,
-> Result<Instance<Self::Fp>, InstanceError> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Instance<Self::Fp>, InstanceError> {
unsafe { unsafe {
let mut instance: vk::Instance = mem::uninitialized(); let mut instance: vk::Instance = mem::uninitialized();
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0().create_instance(
.create_instance(create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut instance); &mut instance,
);
if err_code != vk::Result::Success { if err_code != vk::Result::Success {
return Err(InstanceError::VkError(err_code)); return Err(InstanceError::VkError(err_code));
} }
let instance_fp = let instance_fp =
<<Self as EntryV1_0>::Fp as FunctionPointers>::InstanceFp::load(&self.static_fn(), <<Self as EntryV1_0>::Fp as FunctionPointers>::InstanceFp::load(
instance) &self.static_fn(),
.map_err(|err| InstanceError::LoadError(err))?; instance,
).map_err(|err| InstanceError::LoadError(err))?;
Ok(Instance::from_raw(instance, instance_fp)) Ok(Instance::from_raw(instance, instance_fp))
} }
} }
@ -97,12 +100,16 @@ pub trait EntryV1_0 {
fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> { fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
unsafe { unsafe {
let mut num = 0; let mut num = 0;
self.fp_v1_0() self.fp_v1_0().enumerate_instance_layer_properties(
.enumerate_instance_layer_properties(&mut num, ptr::null_mut()); &mut num,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(num as usize); let mut v = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0().enumerate_instance_layer_properties(
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr()); &mut num,
v.as_mut_ptr(),
);
v.set_len(num as usize); v.set_len(num as usize);
match err_code { match err_code {
vk::Result::Success => Ok(v), vk::Result::Success => Ok(v),
@ -114,14 +121,17 @@ pub trait EntryV1_0 {
fn enumerate_instance_extension_properties(&self) -> VkResult<Vec<vk::ExtensionProperties>> { fn enumerate_instance_extension_properties(&self) -> VkResult<Vec<vk::ExtensionProperties>> {
unsafe { unsafe {
let mut num = 0; let mut num = 0;
self.fp_v1_0() self.fp_v1_0().enumerate_instance_extension_properties(
.enumerate_instance_extension_properties(ptr::null(), &mut num, ptr::null_mut()); ptr::null(),
&mut num,
ptr::null_mut(),
);
let mut data = Vec::with_capacity(num as usize); let mut data = Vec::with_capacity(num as usize);
let err_code = let err_code = self.fp_v1_0().enumerate_instance_extension_properties(
self.fp_v1_0() ptr::null(),
.enumerate_instance_extension_properties(ptr::null(), &mut num,
&mut num, data.as_mut_ptr(),
data.as_mut_ptr()); );
data.set_len(num as usize); data.set_len(num as usize);
match err_code { match err_code {
vk::Result::Success => Ok(data), vk::Result::Success => Ok(data),
@ -130,10 +140,11 @@ pub trait EntryV1_0 {
} }
} }
fn get_instance_proc_addr(&self, fn get_instance_proc_addr(
instance: vk::Instance, &self,
p_name: *const vk::c_char) instance: vk::Instance,
-> vk::PFN_vkVoidFunction { p_name: *const vk::c_char,
) -> vk::PFN_vkVoidFunction {
unsafe { self.static_fn().get_instance_proc_addr(instance, p_name) } unsafe { self.static_fn().get_instance_proc_addr(instance, p_name) }
} }
} }
@ -153,25 +164,25 @@ impl<V: FunctionPointers> Entry<V> {
let static_fn = match *VK_LIB { let static_fn = match *VK_LIB {
Ok(ref lib) => { Ok(ref lib) => {
let static_fn = vk::StaticFn::load(|name| unsafe { let static_fn = vk::StaticFn::load(|name| unsafe {
let name = name.to_str().unwrap(); let name = name.to_str().unwrap();
let f = match lib.symbol(name) { let f = match lib.symbol(name) {
Ok(s) => s, Ok(s) => s,
Err(_) => ptr::null(), Err(_) => ptr::null(),
}; };
f f
}) }).map_err(|err| LoadingError::StaticLoadError(err))?;
.map_err(|err| LoadingError::StaticLoadError(err))?;
Ok(static_fn) Ok(static_fn)
} }
Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())), Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())),
}?; }?;
let entry_fn = unsafe { let entry_fn = unsafe {
V::EntryFp::load(&static_fn) V::EntryFp::load(&static_fn).map_err(|err| {
.map_err(|err| LoadingError::EntryLoadError(err))? LoadingError::EntryLoadError(err)
})?
}; };
Ok(Entry { Ok(Entry {
static_fn: static_fn, static_fn: static_fn,
entry_fn: entry_fn, entry_fn: entry_fn,
}) })
} }
} }

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct AndroidSurface {
} }
impl AndroidSurface { impl AndroidSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<AndroidSurface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::AndroidSurfaceFn::load(|name| { ) -> Result<AndroidSurface, Vec<&'static str>> {
unsafe { let surface_fn = vk::AndroidSurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(AndroidSurface { Ok(AndroidSurface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl AndroidSurface {
CStr::from_bytes_with_nul(b"VK_KHR_android_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_android_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_android_surface_khr(&self, pub unsafe fn create_android_surface_khr(
create_info: &vk::AndroidSurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::AndroidSurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.android_surface_fn let err_code = self.android_surface_fn.create_android_surface_khr(
.create_android_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct DebugReport {
} }
impl DebugReport { impl DebugReport {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<DebugReport, Vec<&'static str>> { instance: &I,
let debug_report_fn = vk::DebugReportFn::load(|name| { ) -> Result<DebugReport, Vec<&'static str>> {
unsafe { let debug_report_fn = vk::DebugReportFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(DebugReport { Ok(DebugReport {
handle: instance.handle(), handle: instance.handle(),
@ -31,21 +33,30 @@ impl DebugReport {
CStr::from_bytes_with_nul(b"VK_EXT_debug_report\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_EXT_debug_report\0").expect("Wrong extension string")
} }
pub unsafe fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>) { pub unsafe fn destroy_debug_report_callback_ext(
self.debug_report_fn.destroy_debug_report_callback_ext(self.handle, &self,
debug, debug: vk::DebugReportCallbackEXT,
allocation_callbacks.as_raw_ptr()); allocation_callbacks: Option<&vk::AllocationCallbacks>,
) {
self.debug_report_fn.destroy_debug_report_callback_ext(
self.handle,
debug,
allocation_callbacks.as_raw_ptr(),
);
} }
pub unsafe fn create_debug_report_callback_ext(&self, pub unsafe fn create_debug_report_callback_ext(
create_info: &vk::DebugReportCallbackCreateInfoEXT, allocation_callbacks: Option<&vk::AllocationCallbacks>) &self,
-> VkResult<vk::DebugReportCallbackEXT> { create_info: &vk::DebugReportCallbackCreateInfoEXT,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::DebugReportCallbackEXT> {
let mut debug_cb = mem::uninitialized(); let mut debug_cb = mem::uninitialized();
let err_code = self.debug_report_fn let err_code = self.debug_report_fn.create_debug_report_callback_ext(
.create_debug_report_callback_ext(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut debug_cb); &mut debug_cb,
);
match err_code { match err_code {
vk::Result::Success => Ok(debug_cb), vk::Result::Success => Ok(debug_cb),
_ => Err(err_code), _ => Err(err_code),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{InstanceV1_0, DeviceV1_0}; use version::{InstanceV1_0, DeviceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,11 +13,15 @@ pub struct DisplaySwapchain {
} }
impl DisplaySwapchain { impl DisplaySwapchain {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, pub fn new<I: InstanceV1_0, D: DeviceV1_0>(
device: &D) instance: &I,
-> Result<DisplaySwapchain, Vec<&'static str>> { device: &D,
let swapchain_fn = vk::DisplaySwapchainFn::load(|name| { ) -> Result<DisplaySwapchain, Vec<&'static str>> {
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) } let swapchain_fn = vk::DisplaySwapchainFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(
device.handle(),
name.as_ptr(),
))
})?; })?;
Ok(DisplaySwapchain { Ok(DisplaySwapchain {
handle: device.handle(), handle: device.handle(),
@ -33,14 +37,15 @@ impl DisplaySwapchain {
&self, &self,
create_infos: &[vk::SwapchainCreateInfoKHR], create_infos: &[vk::SwapchainCreateInfoKHR],
allocation_callbacks: Option<&vk::AllocationCallbacks>, allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<Vec<vk::SwapchainKHR>>{ ) -> VkResult<Vec<vk::SwapchainKHR>> {
let mut swapchains = Vec::with_capacity(create_infos.len()); let mut swapchains = Vec::with_capacity(create_infos.len());
let err_code = self.swapchain_fn let err_code = self.swapchain_fn.create_shared_swapchains_khr(
.create_shared_swapchains_khr(self.handle, self.handle,
create_infos.len() as u32, create_infos.len() as u32,
create_infos.as_ptr(), create_infos.as_ptr(),
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
swapchains.as_mut_ptr()); swapchains.as_mut_ptr(),
);
swapchains.set_len(create_infos.len()); swapchains.set_len(create_infos.len());
match err_code { match err_code {
vk::Result::Success => Ok(swapchains), vk::Result::Success => Ok(swapchains),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct MirSurface {
} }
impl MirSurface { impl MirSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<MirSurface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::MirSurfaceFn::load(|name| { ) -> Result<MirSurface, Vec<&'static str>> {
unsafe { let surface_fn = vk::MirSurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(MirSurface { Ok(MirSurface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl MirSurface {
CStr::from_bytes_with_nul(b"VK_KHR_mir_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_mir_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_mir_surface_khr(&self, pub unsafe fn create_mir_surface_khr(
create_info: &vk::MirSurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::MirSurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.mir_surface_fn let err_code = self.mir_surface_fn.create_mir_surface_khr(
.create_mir_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -4,7 +4,7 @@ use std::ptr;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -14,13 +14,15 @@ pub struct Surface {
} }
impl Surface { impl Surface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<Surface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::SurfaceFn::load(|name| { ) -> Result<Surface, Vec<&'static str>> {
unsafe { let surface_fn = vk::SurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(Surface { Ok(Surface {
handle: instance.handle(), handle: instance.handle(),
@ -32,37 +34,45 @@ impl Surface {
CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string")
} }
pub fn get_physical_device_surface_support_khr(&self, pub fn get_physical_device_surface_support_khr(
physical_device: vk::PhysicalDevice, &self,
queue_index: vk::uint32_t, physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR) queue_index: vk::uint32_t,
-> bool { surface: vk::SurfaceKHR,
) -> bool {
unsafe { unsafe {
let mut b = mem::uninitialized(); let mut b = mem::uninitialized();
self.surface_fn self.surface_fn.get_physical_device_surface_support_khr(
.get_physical_device_surface_support_khr(physical_device, physical_device,
queue_index, queue_index,
surface, surface,
&mut b); &mut b,
);
b > 0 b > 0
} }
} }
pub fn get_physical_device_surface_present_modes_khr(&self, pub fn get_physical_device_surface_present_modes_khr(
physical_device: vk::PhysicalDevice, &self,
surface: vk::SurfaceKHR) physical_device: vk::PhysicalDevice,
-> VkResult<Vec<vk::PresentModeKHR>> { surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe { unsafe {
let mut count = 0; let mut count = 0;
self.surface_fn.get_physical_device_surface_present_modes_khr(physical_device, self.surface_fn
surface, .get_physical_device_surface_present_modes_khr(
&mut count, physical_device,
ptr::null_mut()); surface,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as usize); let mut v = Vec::with_capacity(count as usize);
let err_code = self.surface_fn let err_code = self.surface_fn
.get_physical_device_surface_present_modes_khr(physical_device, .get_physical_device_surface_present_modes_khr(
surface, physical_device,
&mut count, surface,
v.as_mut_ptr()); &mut count,
v.as_mut_ptr(),
);
v.set_len(count as usize); v.set_len(count as usize);
match err_code { match err_code {
vk::Result::Success => Ok(v), vk::Result::Success => Ok(v),
@ -71,16 +81,19 @@ impl Surface {
} }
} }
pub fn get_physical_device_surface_capabilities_khr(&self, pub fn get_physical_device_surface_capabilities_khr(
physical_device: vk::PhysicalDevice, &self,
surface: vk::SurfaceKHR) physical_device: vk::PhysicalDevice,
-> VkResult<vk::SurfaceCapabilitiesKHR> { surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe { unsafe {
let mut surface_capabilities = mem::uninitialized(); let mut surface_capabilities = mem::uninitialized();
let err_code = self.surface_fn let err_code = self.surface_fn
.get_physical_device_surface_capabilities_khr(physical_device, .get_physical_device_surface_capabilities_khr(
surface, physical_device,
&mut surface_capabilities); surface,
&mut surface_capabilities,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface_capabilities), vk::Result::Success => Ok(surface_capabilities),
_ => Err(err_code), _ => Err(err_code),
@ -88,22 +101,26 @@ impl Surface {
} }
} }
pub fn get_physical_device_surface_formats_khr(&self, pub fn get_physical_device_surface_formats_khr(
physical_device: vk::PhysicalDevice, &self,
surface: vk::SurfaceKHR) physical_device: vk::PhysicalDevice,
-> VkResult<Vec<vk::SurfaceFormatKHR>> { surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe { unsafe {
let mut count = 0; let mut count = 0;
self.surface_fn.get_physical_device_surface_formats_khr(physical_device, self.surface_fn.get_physical_device_surface_formats_khr(
surface, physical_device,
&mut count, surface,
ptr::null_mut()); &mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as usize); let mut v = Vec::with_capacity(count as usize);
let err_code = self.surface_fn let err_code = self.surface_fn.get_physical_device_surface_formats_khr(
.get_physical_device_surface_formats_khr(physical_device, physical_device,
surface, surface,
&mut count, &mut count,
v.as_mut_ptr()); v.as_mut_ptr(),
);
v.set_len(count as usize); v.set_len(count as usize);
match err_code { match err_code {
vk::Result::Success => Ok(v), vk::Result::Success => Ok(v),
@ -112,10 +129,15 @@ impl Surface {
} }
} }
pub unsafe fn destroy_surface_khr(&self, pub unsafe fn destroy_surface_khr(
surface: vk::SurfaceKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { surface: vk::SurfaceKHR,
self.surface_fn allocation_callbacks: Option<&vk::AllocationCallbacks>,
.destroy_surface_khr(self.handle, surface, allocation_callbacks.as_raw_ptr()); ) {
self.surface_fn.destroy_surface_khr(
self.handle,
surface,
allocation_callbacks.as_raw_ptr(),
);
} }
} }

View file

@ -4,7 +4,7 @@ use std::ptr;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{InstanceV1_0, DeviceV1_0}; use version::{InstanceV1_0, DeviceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -14,11 +14,15 @@ pub struct Swapchain {
} }
impl Swapchain { impl Swapchain {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, pub fn new<I: InstanceV1_0, D: DeviceV1_0>(
device: &D) instance: &I,
-> Result<Swapchain, Vec<&'static str>> { device: &D,
let swapchain_fn = vk::SwapchainFn::load(|name| { ) -> Result<Swapchain, Vec<&'static str>> {
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) } let swapchain_fn = vk::SwapchainFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(
device.handle(),
name.as_ptr(),
))
})?; })?;
Ok(Swapchain { Ok(Swapchain {
handle: device.handle(), handle: device.handle(),
@ -30,72 +34,90 @@ impl Swapchain {
CStr::from_bytes_with_nul(b"VK_KHR_swapchain\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_swapchain\0").expect("Wrong extension string")
} }
pub unsafe fn destroy_swapchain_khr(&self, pub unsafe fn destroy_swapchain_khr(
swapchain: vk::SwapchainKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { swapchain: vk::SwapchainKHR,
self.swapchain_fn allocation_callbacks: Option<&vk::AllocationCallbacks>,
.destroy_swapchain_khr(self.handle, swapchain, allocation_callbacks.as_raw_ptr()); ) {
self.swapchain_fn.destroy_swapchain_khr(
self.handle,
swapchain,
allocation_callbacks.as_raw_ptr(),
);
} }
pub unsafe fn acquire_next_image_khr(&self, pub unsafe fn acquire_next_image_khr(
swapchain: vk::SwapchainKHR, &self,
timeout: vk::uint64_t, swapchain: vk::SwapchainKHR,
semaphore: vk::Semaphore, timeout: vk::uint64_t,
fence: vk::Fence) semaphore: vk::Semaphore,
-> VkResult<vk::uint32_t> { fence: vk::Fence,
) -> VkResult<vk::uint32_t> {
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(
.acquire_next_image_khr(self.handle, self.handle,
swapchain, swapchain,
timeout, timeout,
semaphore, semaphore,
fence, fence,
&mut index); &mut index,
);
match err_code { match err_code {
vk::Result::Success => Ok(index), vk::Result::Success => Ok(index),
_ => Err(err_code), _ => Err(err_code),
} }
} }
pub unsafe fn create_swapchain_khr(&self, pub unsafe fn create_swapchain_khr(
create_info: &vk::SwapchainCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::SwapchainCreateInfoKHR,
-> VkResult<vk::SwapchainKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SwapchainKHR> {
let mut swapchain = mem::uninitialized(); let mut swapchain = mem::uninitialized();
let err_code = self.swapchain_fn let err_code = self.swapchain_fn.create_swapchain_khr(
.create_swapchain_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut swapchain); &mut swapchain,
);
match err_code { match err_code {
vk::Result::Success => Ok(swapchain), vk::Result::Success => Ok(swapchain),
_ => Err(err_code), _ => Err(err_code),
} }
} }
pub unsafe fn queue_present_khr(&self, pub unsafe fn queue_present_khr(
queue: vk::Queue, &self,
create_info: &vk::PresentInfoKHR) queue: vk::Queue,
-> VkResult<()> { create_info: &vk::PresentInfoKHR,
let err_code = self.swapchain_fn ) -> VkResult<()> {
.queue_present_khr(queue, create_info); let err_code = self.swapchain_fn.queue_present_khr(queue, create_info);
match err_code { match err_code {
vk::Result::Success => Ok(()), vk::Result::Success => Ok(()),
_ => Err(err_code), _ => Err(err_code),
} }
} }
pub fn get_swapchain_images_khr(&self, pub fn get_swapchain_images_khr(
swapchain: vk::SwapchainKHR) &self,
-> VkResult<Vec<vk::Image>> { swapchain: vk::SwapchainKHR,
) -> VkResult<Vec<vk::Image>> {
unsafe { unsafe {
let mut count = 0; let mut count = 0;
self.swapchain_fn self.swapchain_fn.get_swapchain_images_khr(
.get_swapchain_images_khr(self.handle, swapchain, &mut count, ptr::null_mut()); self.handle,
swapchain,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as vk::size_t); let mut v = Vec::with_capacity(count as vk::size_t);
let err_code = self.swapchain_fn let err_code = self.swapchain_fn.get_swapchain_images_khr(
.get_swapchain_images_khr(self.handle, swapchain, &mut count, v.as_mut_ptr()); self.handle,
swapchain,
&mut count,
v.as_mut_ptr(),
);
v.set_len(count as vk::size_t); v.set_len(count as vk::size_t);
match err_code { match err_code {
vk::Result::Success => Ok(v), vk::Result::Success => Ok(v),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct WaylandSurface {
} }
impl WaylandSurface { impl WaylandSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<WaylandSurface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::WaylandSurfaceFn::load(|name| { ) -> Result<WaylandSurface, Vec<&'static str>> {
unsafe { let surface_fn = vk::WaylandSurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(WaylandSurface { Ok(WaylandSurface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl WaylandSurface {
CStr::from_bytes_with_nul(b"VK_KHR_wayland_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_wayland_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_wayland_surface_khr(&self, pub unsafe fn create_wayland_surface_khr(
create_info: &vk::WaylandSurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::WaylandSurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.wayland_surface_fn let err_code = self.wayland_surface_fn.create_wayland_surface_khr(
.create_wayland_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct Win32Surface {
} }
impl Win32Surface { impl Win32Surface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<Win32Surface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::Win32SurfaceFn::load(|name| { ) -> Result<Win32Surface, Vec<&'static str>> {
unsafe { let surface_fn = vk::Win32SurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(Win32Surface { Ok(Win32Surface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl Win32Surface {
CStr::from_bytes_with_nul(b"VK_KHR_win32_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_win32_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_win32_surface_khr(&self, pub unsafe fn create_win32_surface_khr(
create_info: &vk::Win32SurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::Win32SurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.win32_surface_fn let err_code = self.win32_surface_fn.create_win32_surface_khr(
.create_win32_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct XcbSurface {
} }
impl XcbSurface { impl XcbSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<XcbSurface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::XcbSurfaceFn::load(|name| { ) -> Result<XcbSurface, Vec<&'static str>> {
unsafe { let surface_fn = vk::XcbSurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(XcbSurface { Ok(XcbSurface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl XcbSurface {
CStr::from_bytes_with_nul(b"VK_KHR_xcb_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_xcb_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_xcb_surface_khr(&self, pub unsafe fn create_xcb_surface_khr(
create_info: &vk::XcbSurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::XcbSurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.xcb_surface_fn let err_code = self.xcb_surface_fn.create_xcb_surface_khr(
.create_xcb_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -3,7 +3,7 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use RawPtr;
use version::{EntryV1_0, InstanceV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
@ -13,13 +13,15 @@ pub struct XlibSurface {
} }
impl XlibSurface { impl XlibSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, pub fn new<E: EntryV1_0, I: InstanceV1_0>(
instance: &I) entry: &E,
-> Result<XlibSurface, Vec<&'static str>> { instance: &I,
let surface_fn = vk::XlibSurfaceFn::load(|name| { ) -> Result<XlibSurface, Vec<&'static str>> {
unsafe { let surface_fn = vk::XlibSurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) mem::transmute(entry.get_instance_proc_addr(
} instance.handle(),
name.as_ptr(),
))
})?; })?;
Ok(XlibSurface { Ok(XlibSurface {
handle: instance.handle(), handle: instance.handle(),
@ -31,16 +33,18 @@ impl XlibSurface {
CStr::from_bytes_with_nul(b"VK_KHR_xlib_surface\0").expect("Wrong extension string") CStr::from_bytes_with_nul(b"VK_KHR_xlib_surface\0").expect("Wrong extension string")
} }
pub unsafe fn create_xlib_surface_khr(&self, pub unsafe fn create_xlib_surface_khr(
create_info: &vk::XlibSurfaceCreateInfoKHR, &self,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::XlibSurfaceCreateInfoKHR,
-> VkResult<vk::SurfaceKHR> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::uninitialized(); let mut surface = mem::uninitialized();
let err_code = self.xlib_surface_fn let err_code = self.xlib_surface_fn.create_xlib_surface_khr(
.create_xlib_surface_khr(self.handle, self.handle,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut surface); &mut surface,
);
match err_code { match err_code {
vk::Result::Success => Ok(surface), vk::Result::Success => Ok(surface),
_ => Err(err_code), _ => Err(err_code),

View file

@ -16,8 +16,8 @@ pub enum DeviceError {
VkError(vk::Result), VkError(vk::Result),
} }
impl fmt::Display for DeviceError{ impl fmt::Display for DeviceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DeviceError::{:?}", self) write!(f, "DeviceError::{:?}", self)
} }
} }
@ -27,8 +27,8 @@ impl Error for DeviceError {
"DeviceErrorr" "DeviceErrorr"
} }
fn cause(&self) -> Option<&Error>{ fn cause(&self) -> Option<&Error> {
if let &DeviceError::VkError(ref err) = self{ if let &DeviceError::VkError(ref err) = self {
return err.cause(); return err.cause();
} }
None None
@ -69,97 +69,121 @@ pub trait InstanceV1_0 {
type Fp: FunctionPointers; type Fp: FunctionPointers;
fn handle(&self) -> vk::Instance; fn handle(&self) -> vk::Instance;
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0; fn fp_v1_0(&self) -> &vk::InstanceFnV1_0;
unsafe fn create_device(&self, unsafe fn create_device(
physical_device: vk::PhysicalDevice, &self,
create_info: &vk::DeviceCreateInfo, physical_device: vk::PhysicalDevice,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_info: &vk::DeviceCreateInfo,
-> Result<Device<Self::Fp>, DeviceError> { allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Device<Self::Fp>, DeviceError> {
let mut device: vk::Device = mem::uninitialized(); let mut device: vk::Device = mem::uninitialized();
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0().create_device(
.create_device(physical_device, physical_device,
create_info, create_info,
allocation_callbacks.as_raw_ptr(), allocation_callbacks.as_raw_ptr(),
&mut device); &mut device,
);
if err_code != vk::Result::Success { if err_code != vk::Result::Success {
return Err(DeviceError::VkError(err_code)); return Err(DeviceError::VkError(err_code));
} }
let device_fn = let device_fn =
<<Self as InstanceV1_0>::Fp as FunctionPointers>::DeviceFp::load(self.fp_v1_0(), device).map_err(|err| DeviceError::LoadError(err))?; <<Self as InstanceV1_0>::Fp as FunctionPointers>::DeviceFp::load(
self.fp_v1_0(),
device,
).map_err(|err| DeviceError::LoadError(err))?;
Ok(Device::from_raw(device, device_fn)) Ok(Device::from_raw(device, device_fn))
} }
fn get_device_proc_addr(&self, fn get_device_proc_addr(
device: vk::Device, &self,
p_name: *const vk::c_char) device: vk::Device,
-> vk::PFN_vkVoidFunction { p_name: *const vk::c_char,
) -> vk::PFN_vkVoidFunction {
unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) } unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) }
} }
unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) { unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0() self.fp_v1_0().destroy_instance(
.destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr()); self.handle(),
allocation_callbacks.as_raw_ptr(),
);
} }
fn get_physical_device_format_properties(&self, fn get_physical_device_format_properties(
physical_device: vk::PhysicalDevice, &self,
format: vk::Format) physical_device: vk::PhysicalDevice,
-> vk::FormatProperties { format: vk::Format,
) -> vk::FormatProperties {
unsafe { unsafe {
let mut format_prop = mem::uninitialized(); let mut format_prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0().get_physical_device_format_properties(
.get_physical_device_format_properties(physical_device, format, &mut format_prop); physical_device,
format,
&mut format_prop,
);
format_prop format_prop
} }
} }
fn get_physical_device_memory_properties(&self, fn get_physical_device_memory_properties(
physical_device: vk::PhysicalDevice) &self,
-> vk::PhysicalDeviceMemoryProperties { physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties {
unsafe { unsafe {
let mut memory_prop = mem::uninitialized(); let mut memory_prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0().get_physical_device_memory_properties(
.get_physical_device_memory_properties(physical_device, &mut memory_prop); physical_device,
&mut memory_prop,
);
memory_prop memory_prop
} }
} }
fn get_physical_device_properties(&self, fn get_physical_device_properties(
physical_device: vk::PhysicalDevice) &self,
-> vk::PhysicalDeviceProperties { physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceProperties {
unsafe { unsafe {
let mut prop = mem::uninitialized(); let mut prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0().get_physical_device_properties(
.get_physical_device_properties(physical_device, &mut prop); physical_device,
&mut prop,
);
prop prop
} }
} }
fn get_physical_device_queue_family_properties(&self, fn get_physical_device_queue_family_properties(
physical_device: vk::PhysicalDevice) &self,
-> Vec<vk::QueueFamilyProperties> { physical_device: vk::PhysicalDevice,
) -> Vec<vk::QueueFamilyProperties> {
unsafe { unsafe {
let mut queue_count = 0; let mut queue_count = 0;
self.fp_v1_0() self.fp_v1_0().get_physical_device_queue_family_properties(
.get_physical_device_queue_family_properties(physical_device, physical_device,
&mut queue_count, &mut queue_count,
ptr::null_mut()); ptr::null_mut(),
);
let mut queue_families_vec = Vec::with_capacity(queue_count as usize); let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
self.fp_v1_0() self.fp_v1_0().get_physical_device_queue_family_properties(
.get_physical_device_queue_family_properties(physical_device, physical_device,
&mut queue_count, &mut queue_count,
queue_families_vec.as_mut_ptr()); queue_families_vec.as_mut_ptr(),
);
queue_families_vec.set_len(queue_count as usize); queue_families_vec.set_len(queue_count as usize);
queue_families_vec queue_families_vec
} }
} }
fn get_physical_device_features(&self, fn get_physical_device_features(
physical_device: vk::PhysicalDevice) &self,
-> vk::PhysicalDeviceFeatures { physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceFeatures {
unsafe { unsafe {
let mut prop = mem::uninitialized(); let mut prop = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0().get_physical_device_features(
.get_physical_device_features(physical_device, &mut prop); physical_device,
&mut prop,
);
prop prop
} }
} }
@ -167,14 +191,17 @@ pub trait InstanceV1_0 {
fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> { fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
unsafe { unsafe {
let mut num = mem::uninitialized(); let mut num = mem::uninitialized();
self.fp_v1_0() self.fp_v1_0().enumerate_physical_devices(
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut()); self.handle(),
&mut num,
ptr::null_mut(),
);
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize); let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
let err_code = let err_code = self.fp_v1_0().enumerate_physical_devices(
self.fp_v1_0() self.handle(),
.enumerate_physical_devices(self.handle(), &mut num,
&mut num, physical_devices.as_mut_ptr(),
physical_devices.as_mut_ptr()); );
physical_devices.set_len(num as usize); physical_devices.set_len(num as usize);
match err_code { match err_code {
vk::Result::Success => Ok(physical_devices), vk::Result::Success => Ok(physical_devices),
@ -183,23 +210,25 @@ pub trait InstanceV1_0 {
} }
} }
fn enumerate_device_extension_properties fn enumerate_device_extension_properties(
(&self, &self,
device: vk::PhysicalDevice) device: vk::PhysicalDevice,
-> Result<Vec<vk::ExtensionProperties>, vk::Result> { ) -> Result<Vec<vk::ExtensionProperties>, vk::Result> {
unsafe { unsafe {
let mut num = 0; let mut num = 0;
self.fp_v1_0() self.fp_v1_0().enumerate_device_extension_properties(
.enumerate_device_extension_properties(device, device,
ptr::null(), ptr::null(),
&mut num, &mut num,
ptr::null_mut()); ptr::null_mut(),
);
let mut data = Vec::with_capacity(num as usize); let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0().enumerate_device_extension_properties(
.enumerate_device_extension_properties(device, device,
ptr::null(), ptr::null(),
&mut num, &mut num,
data.as_mut_ptr()); data.as_mut_ptr(),
);
data.set_len(num as usize); data.set_len(num as usize);
match err_code { match err_code {
vk::Result::Success => Ok(data), vk::Result::Success => Ok(data),

View file

@ -15,15 +15,15 @@ pub mod extensions;
pub mod version; pub mod version;
pub mod util; pub mod util;
pub trait RawPtr<T>{ pub trait RawPtr<T> {
fn as_raw_ptr(&self) -> *const T; fn as_raw_ptr(&self) -> *const T;
} }
impl<'r, T> RawPtr<T> for Option<&'r T>{ impl<'r, T> RawPtr<T> for Option<&'r T> {
fn as_raw_ptr(&self) -> *const T{ fn as_raw_ptr(&self) -> *const T {
match self{ match self {
&Some(inner) => inner as *const T, &Some(inner) => inner as *const T,
_ => ::std::ptr::null() _ => ::std::ptr::null(),
} }
} }
} }

View file

@ -36,7 +36,10 @@ impl EntryLoader for EntryFpV1_0 {
} }
unsafe fn load(static_fn: &vk::StaticFn) -> Result<Self, Vec<&'static str>> { unsafe fn load(static_fn: &vk::StaticFn) -> Result<Self, Vec<&'static str>> {
let entry_fn = vk::EntryFnV1_0::load(|name| { let entry_fn = vk::EntryFnV1_0::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr())) mem::transmute(static_fn.get_instance_proc_addr(
vk::Instance::null(),
name.as_ptr(),
))
})?; })?;
Ok(EntryFpV1_0 { entry_fn: entry_fn }) Ok(EntryFpV1_0 { entry_fn: entry_fn })
} }
@ -49,21 +52,24 @@ pub trait EntryLoader: Sized {
pub trait InstanceLoader: Sized { pub trait InstanceLoader: Sized {
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0; fn fp_v1_0(&self) -> &vk::InstanceFnV1_0;
unsafe fn load(static_fn: &vk::StaticFn, unsafe fn load(
instance: vk::Instance) static_fn: &vk::StaticFn,
-> Result<Self, Vec<&'static str>>; instance: vk::Instance,
) -> Result<Self, Vec<&'static str>>;
} }
pub trait DeviceLoader: Sized { pub trait DeviceLoader: Sized {
unsafe fn load(instance_fn: &vk::InstanceFnV1_0, unsafe fn load(
device: vk::Device) instance_fn: &vk::InstanceFnV1_0,
-> Result<Self, Vec<&'static str>>; device: vk::Device,
) -> Result<Self, Vec<&'static str>>;
} }
impl DeviceLoader for DeviceFpV1_0 { impl DeviceLoader for DeviceFpV1_0 {
unsafe fn load(instance_fn: &vk::InstanceFnV1_0, unsafe fn load(
device: vk::Device) instance_fn: &vk::InstanceFnV1_0,
-> Result<Self, Vec<&'static str>> { device: vk::Device,
) -> Result<Self, Vec<&'static str>> {
let device_fn = vk::DeviceFnV1_0::load(|name| { let device_fn = vk::DeviceFnV1_0::load(|name| {
mem::transmute(instance_fn.get_device_proc_addr(device, name.as_ptr())) mem::transmute(instance_fn.get_device_proc_addr(device, name.as_ptr()))
})?; })?;
@ -75,9 +81,10 @@ impl InstanceLoader for InstanceFpV1_0 {
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 { fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
&self.instance_fn &self.instance_fn
} }
unsafe fn load(static_fn: &vk::StaticFn, unsafe fn load(
instance: vk::Instance) static_fn: &vk::StaticFn,
-> Result<Self, Vec<&'static str>> { instance: vk::Instance,
) -> Result<Self, Vec<&'static str>> {
let instance_fn = vk::InstanceFnV1_0::load(|name| { let instance_fn = vk::InstanceFnV1_0::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr())) mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr()))
})?; })?;

View file

@ -366,8 +366,10 @@ pub mod types {
.field("pfn_allocation", &(self.pfn_allocation as *const ())) .field("pfn_allocation", &(self.pfn_allocation as *const ()))
.field("pfn_reallocation", &(self.pfn_reallocation as *const ())) .field("pfn_reallocation", &(self.pfn_reallocation as *const ()))
.field("pfn_free", &(self.pfn_free as *const ())) .field("pfn_free", &(self.pfn_free as *const ()))
.field("pfn_internal_allocation", .field(
&(self.pfn_internal_allocation as *const ())) "pfn_internal_allocation",
&(self.pfn_internal_allocation as *const ()),
)
.field("pfn_internal_free", &(self.pfn_internal_free as *const ())) .field("pfn_internal_free", &(self.pfn_internal_free as *const ()))
.finish() .finish()
} }
@ -513,8 +515,9 @@ pub mod types {
.field("vendor_id", &self.vendor_id) .field("vendor_id", &self.vendor_id)
.field("device_id", &self.device_id) .field("device_id", &self.device_id)
.field("device_type", &self.device_type) .field("device_type", &self.device_type)
.field("device_name", .field("device_name", &unsafe {
&unsafe { CStr::from_ptr(&self.device_name[0]) }) CStr::from_ptr(&self.device_name[0])
})
.field("pipeline_cache_uuid", &&self.pipeline_cache_uuid[..]) .field("pipeline_cache_uuid", &&self.pipeline_cache_uuid[..])
.field("limits", &self.limits) .field("limits", &self.limits)
.field("sparse_properties", &self.sparse_properties) .field("sparse_properties", &self.sparse_properties)
@ -834,151 +837,267 @@ pub mod types {
.field("max_uniform_buffer_range", &self.max_uniform_buffer_range) .field("max_uniform_buffer_range", &self.max_uniform_buffer_range)
.field("max_storage_buffer_range", &self.max_storage_buffer_range) .field("max_storage_buffer_range", &self.max_storage_buffer_range)
.field("max_push_constants_size", &self.max_push_constants_size) .field("max_push_constants_size", &self.max_push_constants_size)
.field("max_memory_allocation_count", .field(
&self.max_memory_allocation_count) "max_memory_allocation_count",
.field("max_sampler_allocation_count", &self.max_memory_allocation_count,
&self.max_sampler_allocation_count) )
.field(
"max_sampler_allocation_count",
&self.max_sampler_allocation_count,
)
.field("buffer_image_granularity", &self.buffer_image_granularity) .field("buffer_image_granularity", &self.buffer_image_granularity)
.field("sparse_address_space_size", &self.sparse_address_space_size) .field("sparse_address_space_size", &self.sparse_address_space_size)
.field("max_bound_descriptor_sets", &self.max_bound_descriptor_sets) .field("max_bound_descriptor_sets", &self.max_bound_descriptor_sets)
.field("max_per_stage_descriptor_samplers", .field(
&self.max_per_stage_descriptor_samplers) "max_per_stage_descriptor_samplers",
.field("max_per_stage_descriptor_uniform_buffers", &self.max_per_stage_descriptor_samplers,
&self.max_per_stage_descriptor_uniform_buffers) )
.field("max_per_stage_descriptor_storage_buffers", .field(
&self.max_per_stage_descriptor_storage_buffers) "max_per_stage_descriptor_uniform_buffers",
.field("max_per_stage_descriptor_sampled_images", &self.max_per_stage_descriptor_uniform_buffers,
&self.max_per_stage_descriptor_sampled_images) )
.field("max_per_stage_descriptor_storage_images", .field(
&self.max_per_stage_descriptor_storage_images) "max_per_stage_descriptor_storage_buffers",
.field("max_per_stage_descriptor_input_attachments", &self.max_per_stage_descriptor_storage_buffers,
&self.max_per_stage_descriptor_input_attachments) )
.field(
"max_per_stage_descriptor_sampled_images",
&self.max_per_stage_descriptor_sampled_images,
)
.field(
"max_per_stage_descriptor_storage_images",
&self.max_per_stage_descriptor_storage_images,
)
.field(
"max_per_stage_descriptor_input_attachments",
&self.max_per_stage_descriptor_input_attachments,
)
.field("max_per_stage_resources", &self.max_per_stage_resources) .field("max_per_stage_resources", &self.max_per_stage_resources)
.field("max_descriptor_set_samplers", .field(
&self.max_descriptor_set_samplers) "max_descriptor_set_samplers",
.field("max_descriptor_set_uniform_buffers", &self.max_descriptor_set_samplers,
&self.max_descriptor_set_uniform_buffers) )
.field("max_descriptor_set_uniform_buffers_dynamic", .field(
&self.max_descriptor_set_uniform_buffers_dynamic) "max_descriptor_set_uniform_buffers",
.field("max_descriptor_set_storage_buffers", &self.max_descriptor_set_uniform_buffers,
&self.max_descriptor_set_storage_buffers) )
.field("max_descriptor_set_storage_buffers_dynamic", .field(
&self.max_descriptor_set_storage_buffers_dynamic) "max_descriptor_set_uniform_buffers_dynamic",
.field("max_descriptor_set_sampled_images", &self.max_descriptor_set_uniform_buffers_dynamic,
&self.max_descriptor_set_sampled_images) )
.field("max_descriptor_set_storage_images", .field(
&self.max_descriptor_set_storage_images) "max_descriptor_set_storage_buffers",
.field("max_descriptor_set_input_attachments", &self.max_descriptor_set_storage_buffers,
&self.max_descriptor_set_input_attachments) )
.field("max_vertex_input_attributes", .field(
&self.max_vertex_input_attributes) "max_descriptor_set_storage_buffers_dynamic",
&self.max_descriptor_set_storage_buffers_dynamic,
)
.field(
"max_descriptor_set_sampled_images",
&self.max_descriptor_set_sampled_images,
)
.field(
"max_descriptor_set_storage_images",
&self.max_descriptor_set_storage_images,
)
.field(
"max_descriptor_set_input_attachments",
&self.max_descriptor_set_input_attachments,
)
.field(
"max_vertex_input_attributes",
&self.max_vertex_input_attributes,
)
.field("max_vertex_input_bindings", &self.max_vertex_input_bindings) .field("max_vertex_input_bindings", &self.max_vertex_input_bindings)
.field("max_vertex_input_attribute_offset", .field(
&self.max_vertex_input_attribute_offset) "max_vertex_input_attribute_offset",
.field("max_vertex_input_binding_stride", &self.max_vertex_input_attribute_offset,
&self.max_vertex_input_binding_stride) )
.field("max_vertex_output_components", .field(
&self.max_vertex_output_components) "max_vertex_input_binding_stride",
.field("max_tessellation_generation_level", &self.max_vertex_input_binding_stride,
&self.max_tessellation_generation_level) )
.field("max_tessellation_patch_size", .field(
&self.max_tessellation_patch_size) "max_vertex_output_components",
.field("max_tessellation_control_per_vertex_input_components", &self.max_vertex_output_components,
&self.max_tessellation_control_per_vertex_input_components) )
.field("max_tessellation_control_per_vertex_output_components", .field(
&self.max_tessellation_control_per_vertex_output_components) "max_tessellation_generation_level",
.field("max_tessellation_control_per_patch_output_components", &self.max_tessellation_generation_level,
&self.max_tessellation_control_per_patch_output_components) )
.field("max_tessellation_control_total_output_components", .field(
&self.max_tessellation_control_total_output_components) "max_tessellation_patch_size",
.field("max_tessellation_evaluation_input_components", &self.max_tessellation_patch_size,
&self.max_tessellation_evaluation_input_components) )
.field("max_tessellation_evaluation_output_components", .field(
&self.max_tessellation_evaluation_output_components) "max_tessellation_control_per_vertex_input_components",
.field("max_geometry_shader_invocations", &self.max_tessellation_control_per_vertex_input_components,
&self.max_geometry_shader_invocations) )
.field("max_geometry_input_components", .field(
&self.max_geometry_input_components) "max_tessellation_control_per_vertex_output_components",
.field("max_geometry_output_components", &self.max_tessellation_control_per_vertex_output_components,
&self.max_geometry_output_components) )
.field("max_geometry_output_vertices", .field(
&self.max_geometry_output_vertices) "max_tessellation_control_per_patch_output_components",
.field("max_geometry_total_output_components", &self.max_tessellation_control_per_patch_output_components,
&self.max_geometry_total_output_components) )
.field("max_fragment_input_components", .field(
&self.max_fragment_input_components) "max_tessellation_control_total_output_components",
.field("max_fragment_output_attachments", &self.max_tessellation_control_total_output_components,
&self.max_fragment_output_attachments) )
.field("max_fragment_dual_src_attachments", .field(
&self.max_fragment_dual_src_attachments) "max_tessellation_evaluation_input_components",
.field("max_fragment_combined_output_resources", &self.max_tessellation_evaluation_input_components,
&self.max_fragment_combined_output_resources) )
.field("max_compute_shared_memory_size", .field(
&self.max_compute_shared_memory_size) "max_tessellation_evaluation_output_components",
.field("max_compute_work_group_count", &self.max_tessellation_evaluation_output_components,
&&self.max_compute_work_group_count[..]) )
.field("max_compute_work_group_invocations", .field(
&self.max_compute_work_group_invocations) "max_geometry_shader_invocations",
.field("max_compute_work_group_size", &self.max_geometry_shader_invocations,
&&self.max_compute_work_group_size[..]) )
.field(
"max_geometry_input_components",
&self.max_geometry_input_components,
)
.field(
"max_geometry_output_components",
&self.max_geometry_output_components,
)
.field(
"max_geometry_output_vertices",
&self.max_geometry_output_vertices,
)
.field(
"max_geometry_total_output_components",
&self.max_geometry_total_output_components,
)
.field(
"max_fragment_input_components",
&self.max_fragment_input_components,
)
.field(
"max_fragment_output_attachments",
&self.max_fragment_output_attachments,
)
.field(
"max_fragment_dual_src_attachments",
&self.max_fragment_dual_src_attachments,
)
.field(
"max_fragment_combined_output_resources",
&self.max_fragment_combined_output_resources,
)
.field(
"max_compute_shared_memory_size",
&self.max_compute_shared_memory_size,
)
.field(
"max_compute_work_group_count",
&&self.max_compute_work_group_count[..],
)
.field(
"max_compute_work_group_invocations",
&self.max_compute_work_group_invocations,
)
.field(
"max_compute_work_group_size",
&&self.max_compute_work_group_size[..],
)
.field("sub_pixel_precision_bits", &self.sub_pixel_precision_bits) .field("sub_pixel_precision_bits", &self.sub_pixel_precision_bits)
.field("sub_texel_precision_bits", &self.sub_texel_precision_bits) .field("sub_texel_precision_bits", &self.sub_texel_precision_bits)
.field("mipmap_precision_bits", &self.mipmap_precision_bits) .field("mipmap_precision_bits", &self.mipmap_precision_bits)
.field("max_draw_indexed_index_value", .field(
&self.max_draw_indexed_index_value) "max_draw_indexed_index_value",
&self.max_draw_indexed_index_value,
)
.field("max_draw_indirect_count", &self.max_draw_indirect_count) .field("max_draw_indirect_count", &self.max_draw_indirect_count)
.field("max_sampler_lod_bias", &self.max_sampler_lod_bias) .field("max_sampler_lod_bias", &self.max_sampler_lod_bias)
.field("max_sampler_anisotropy", &self.max_sampler_anisotropy) .field("max_sampler_anisotropy", &self.max_sampler_anisotropy)
.field("max_viewports", &self.max_viewports) .field("max_viewports", &self.max_viewports)
.field("max_viewport_dimensions", .field(
&&self.max_viewport_dimensions[..]) "max_viewport_dimensions",
&&self.max_viewport_dimensions[..],
)
.field("viewport_bounds_range", &&self.viewport_bounds_range[..]) .field("viewport_bounds_range", &&self.viewport_bounds_range[..])
.field("viewport_sub_pixel_bits", &self.viewport_sub_pixel_bits) .field("viewport_sub_pixel_bits", &self.viewport_sub_pixel_bits)
.field("min_memory_map_alignment", &self.min_memory_map_alignment) .field("min_memory_map_alignment", &self.min_memory_map_alignment)
.field("min_texel_buffer_offset_alignment", .field(
&self.min_texel_buffer_offset_alignment) "min_texel_buffer_offset_alignment",
.field("min_uniform_buffer_offset_alignment", &self.min_texel_buffer_offset_alignment,
&self.min_uniform_buffer_offset_alignment) )
.field("min_storage_buffer_offset_alignment", .field(
&self.min_storage_buffer_offset_alignment) "min_uniform_buffer_offset_alignment",
&self.min_uniform_buffer_offset_alignment,
)
.field(
"min_storage_buffer_offset_alignment",
&self.min_storage_buffer_offset_alignment,
)
.field("min_texel_offset", &self.min_texel_offset) .field("min_texel_offset", &self.min_texel_offset)
.field("max_texel_offset", &self.max_texel_offset) .field("max_texel_offset", &self.max_texel_offset)
.field("min_texel_gather_offset", &self.min_texel_gather_offset) .field("min_texel_gather_offset", &self.min_texel_gather_offset)
.field("max_texel_gather_offset", &self.max_texel_gather_offset) .field("max_texel_gather_offset", &self.max_texel_gather_offset)
.field("min_interpolation_offset", &self.min_interpolation_offset) .field("min_interpolation_offset", &self.min_interpolation_offset)
.field("max_interpolation_offset", &self.max_interpolation_offset) .field("max_interpolation_offset", &self.max_interpolation_offset)
.field("sub_pixel_interpolation_offset_bits", .field(
&self.sub_pixel_interpolation_offset_bits) "sub_pixel_interpolation_offset_bits",
&self.sub_pixel_interpolation_offset_bits,
)
.field("max_framebuffer_width", &self.max_framebuffer_width) .field("max_framebuffer_width", &self.max_framebuffer_width)
.field("max_framebuffer_height", &self.max_framebuffer_height) .field("max_framebuffer_height", &self.max_framebuffer_height)
.field("max_framebuffer_layers", &self.max_framebuffer_layers) .field("max_framebuffer_layers", &self.max_framebuffer_layers)
.field("framebuffer_color_sample_counts", .field(
&self.framebuffer_color_sample_counts) "framebuffer_color_sample_counts",
.field("framebuffer_depth_sample_counts", &self.framebuffer_color_sample_counts,
&self.framebuffer_depth_sample_counts) )
.field("framebuffer_stencil_sample_counts", .field(
&self.framebuffer_stencil_sample_counts) "framebuffer_depth_sample_counts",
.field("framebuffer_no_attachments_sample_counts", &self.framebuffer_depth_sample_counts,
&self.framebuffer_no_attachments_sample_counts) )
.field(
"framebuffer_stencil_sample_counts",
&self.framebuffer_stencil_sample_counts,
)
.field(
"framebuffer_no_attachments_sample_counts",
&self.framebuffer_no_attachments_sample_counts,
)
.field("max_color_attachments", &self.max_color_attachments) .field("max_color_attachments", &self.max_color_attachments)
.field("sampled_image_color_sample_counts", .field(
&self.sampled_image_color_sample_counts) "sampled_image_color_sample_counts",
.field("sampled_image_integer_sample_counts", &self.sampled_image_color_sample_counts,
&self.sampled_image_integer_sample_counts) )
.field("sampled_image_depth_sample_counts", .field(
&self.sampled_image_depth_sample_counts) "sampled_image_integer_sample_counts",
.field("sampled_image_stencil_sample_counts", &self.sampled_image_integer_sample_counts,
&self.sampled_image_stencil_sample_counts) )
.field("storage_image_sample_counts", .field(
&self.storage_image_sample_counts) "sampled_image_depth_sample_counts",
&self.sampled_image_depth_sample_counts,
)
.field(
"sampled_image_stencil_sample_counts",
&self.sampled_image_stencil_sample_counts,
)
.field(
"storage_image_sample_counts",
&self.storage_image_sample_counts,
)
.field("max_sample_mask_words", &self.max_sample_mask_words) .field("max_sample_mask_words", &self.max_sample_mask_words)
.field("timestamp_compute_and_graphics", .field(
&self.timestamp_compute_and_graphics) "timestamp_compute_and_graphics",
&self.timestamp_compute_and_graphics,
)
.field("timestamp_period", &self.timestamp_period) .field("timestamp_period", &self.timestamp_period)
.field("max_clip_distances", &self.max_clip_distances) .field("max_clip_distances", &self.max_clip_distances)
.field("max_cull_distances", &self.max_cull_distances) .field("max_cull_distances", &self.max_cull_distances)
.field("max_combined_clip_and_cull_distances", .field(
&self.max_combined_clip_and_cull_distances) "max_combined_clip_and_cull_distances",
&self.max_combined_clip_and_cull_distances,
)
.field("discrete_queue_priorities", &self.discrete_queue_priorities) .field("discrete_queue_priorities", &self.discrete_queue_priorities)
.field("point_size_range", &&self.point_size_range[..]) .field("point_size_range", &&self.point_size_range[..])
.field("line_width_range", &&self.line_width_range[..]) .field("line_width_range", &&self.line_width_range[..])
@ -986,10 +1105,14 @@ pub mod types {
.field("line_width_granularity", &self.line_width_granularity) .field("line_width_granularity", &self.line_width_granularity)
.field("strict_lines", &self.strict_lines) .field("strict_lines", &self.strict_lines)
.field("standard_sample_locations", &self.standard_sample_locations) .field("standard_sample_locations", &self.standard_sample_locations)
.field("optimal_buffer_copy_offset_alignment", .field(
&self.optimal_buffer_copy_offset_alignment) "optimal_buffer_copy_offset_alignment",
.field("optimal_buffer_copy_row_pitch_alignment", &self.optimal_buffer_copy_offset_alignment,
&self.optimal_buffer_copy_row_pitch_alignment) )
.field(
"optimal_buffer_copy_row_pitch_alignment",
&self.optimal_buffer_copy_row_pitch_alignment,
)
.field("non_coherent_atom_size", &self.non_coherent_atom_size) .field("non_coherent_atom_size", &self.non_coherent_atom_size)
.finish() .finish()
} }
@ -1127,8 +1250,9 @@ pub mod types {
impl fmt::Debug for ExtensionProperties { impl fmt::Debug for ExtensionProperties {
fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
fmt.debug_struct("ExtensionProperties") fmt.debug_struct("ExtensionProperties")
.field("extension_name", .field("extension_name", &unsafe {
&unsafe { CStr::from_ptr(&self.extension_name[0]) }) CStr::from_ptr(&self.extension_name[0])
})
.field("spec_version", &self.spec_version) .field("spec_version", &self.spec_version)
.finish() .finish()
} }
@ -1173,12 +1297,15 @@ pub mod types {
impl fmt::Debug for LayerProperties { impl fmt::Debug for LayerProperties {
fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
fmt.debug_struct("LayerProperties") fmt.debug_struct("LayerProperties")
.field("layer_name", .field(
&unsafe { CStr::from_ptr(&self.layer_name[0]) }) "layer_name",
&unsafe { CStr::from_ptr(&self.layer_name[0]) },
)
.field("spec_version", &self.spec_version) .field("spec_version", &self.spec_version)
.field("implementation_version", &self.implementation_version) .field("implementation_version", &self.implementation_version)
.field("description", .field("description", &unsafe {
&unsafe { CStr::from_ptr(&self.description[0]) }) CStr::from_ptr(&self.description[0])
})
.finish() .finish()
} }
} }
@ -2670,8 +2797,10 @@ pub mod types {
Result::Success => write!(fmt, "Command successfully completed"), Result::Success => write!(fmt, "Command successfully completed"),
Result::NotReady => write!(fmt, "A fence or query has not yet completed"), Result::NotReady => write!(fmt, "A fence or query has not yet completed"),
Result::Timeout => { Result::Timeout => {
write!(fmt, write!(
"A wait operation has not completed in the specified time") fmt,
"A wait operation has not completed in the specified time"
)
} }
Result::EventSet => write!(fmt, "An event is signaled"), Result::EventSet => write!(fmt, "An event is signaled"),
Result::EventReset => write!(fmt, "An event is unsignaled"), Result::EventReset => write!(fmt, "An event is unsignaled"),
@ -2681,19 +2810,25 @@ pub mod types {
write!(fmt, "A device memory allocation has failed.") write!(fmt, "A device memory allocation has failed.")
} }
Result::ErrorInitializationFailed => { Result::ErrorInitializationFailed => {
write!(fmt, write!(
"Initialization of an object could not be completed for implementation-specific reasons.") fmt,
"Initialization of an object could not be completed for implementation-specific reasons."
)
} }
Result::ErrorDeviceLost => { Result::ErrorDeviceLost => {
write!(fmt, write!(
"The logical or physical device has been lost. See Lost Device") fmt,
"The logical or physical device has been lost. See Lost Device"
)
} }
Result::ErrorMemoryMapFailed => { Result::ErrorMemoryMapFailed => {
write!(fmt, "Mapping of a memory object has failed.") write!(fmt, "Mapping of a memory object has failed.")
} }
Result::ErrorLayerNotPresent => { Result::ErrorLayerNotPresent => {
write!(fmt, write!(
"A requested layer is not present or could not be loaded.") fmt,
"A requested layer is not present or could not be loaded."
)
} }
Result::ErrorExtensionNotPresent => { Result::ErrorExtensionNotPresent => {
write!(fmt, "A requested extension is not supported.") write!(fmt, "A requested extension is not supported.")
@ -2702,20 +2837,26 @@ pub mod types {
write!(fmt, "A requested feature is not supported.") write!(fmt, "A requested feature is not supported.")
} }
Result::ErrorIncompatibleDriver => { Result::ErrorIncompatibleDriver => {
write!(fmt, write!(
"The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons.") fmt,
"The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons."
)
} }
Result::ErrorTooManyObjects => { Result::ErrorTooManyObjects => {
write!(fmt, write!(
"Too many objects of the type have already been created.") fmt,
"Too many objects of the type have already been created."
)
} }
Result::ErrorFormatNotSupported => { Result::ErrorFormatNotSupported => {
write!(fmt, "A requested format is not supported on this device.") write!(fmt, "A requested format is not supported on this device.")
} }
Result::ErrorFragmentedPool => { Result::ErrorFragmentedPool => {
write!(fmt, write!(
"A pool allocation has failed due to fragmentation of the pools memory. This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation.") fmt,
"A pool allocation has failed due to fragmentation of the pools memory. This must only be returned if no attempt to allocate host or device memory was made to accomodate the new allocation."
)
} }
_ => write!(fmt, ""), _ => write!(fmt, ""),
} }