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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@ use std::ptr;
use std::mem;
use vk;
use std::ffi::CStr;
use ::RawPtr;
use RawPtr;
use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)]
@ -14,13 +14,15 @@ pub struct Surface {
}
impl Surface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
instance: &I)
-> Result<Surface, Vec<&'static str>> {
let surface_fn = vk::SurfaceFn::load(|name| {
unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
}
pub fn new<E: EntryV1_0, I: InstanceV1_0>(
entry: &E,
instance: &I,
) -> Result<Surface, Vec<&'static str>> {
let surface_fn = vk::SurfaceFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(
instance.handle(),
name.as_ptr(),
))
})?;
Ok(Surface {
handle: instance.handle(),
@ -32,37 +34,45 @@ impl Surface {
CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string")
}
pub fn get_physical_device_surface_support_khr(&self,
physical_device: vk::PhysicalDevice,
queue_index: vk::uint32_t,
surface: vk::SurfaceKHR)
-> bool {
pub fn get_physical_device_surface_support_khr(
&self,
physical_device: vk::PhysicalDevice,
queue_index: vk::uint32_t,
surface: vk::SurfaceKHR,
) -> bool {
unsafe {
let mut b = mem::uninitialized();
self.surface_fn
.get_physical_device_surface_support_khr(physical_device,
queue_index,
surface,
&mut b);
self.surface_fn.get_physical_device_surface_support_khr(
physical_device,
queue_index,
surface,
&mut b,
);
b > 0
}
}
pub fn get_physical_device_surface_present_modes_khr(&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR)
-> VkResult<Vec<vk::PresentModeKHR>> {
pub fn get_physical_device_surface_present_modes_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe {
let mut count = 0;
self.surface_fn.get_physical_device_surface_present_modes_khr(physical_device,
surface,
&mut count,
ptr::null_mut());
self.surface_fn
.get_physical_device_surface_present_modes_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as usize);
let err_code = self.surface_fn
.get_physical_device_surface_present_modes_khr(physical_device,
surface,
&mut count,
v.as_mut_ptr());
.get_physical_device_surface_present_modes_khr(
physical_device,
surface,
&mut count,
v.as_mut_ptr(),
);
v.set_len(count as usize);
match err_code {
vk::Result::Success => Ok(v),
@ -71,16 +81,19 @@ impl Surface {
}
}
pub fn get_physical_device_surface_capabilities_khr(&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR)
-> VkResult<vk::SurfaceCapabilitiesKHR> {
pub fn get_physical_device_surface_capabilities_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe {
let mut surface_capabilities = mem::uninitialized();
let err_code = self.surface_fn
.get_physical_device_surface_capabilities_khr(physical_device,
surface,
&mut surface_capabilities);
.get_physical_device_surface_capabilities_khr(
physical_device,
surface,
&mut surface_capabilities,
);
match err_code {
vk::Result::Success => Ok(surface_capabilities),
_ => Err(err_code),
@ -88,22 +101,26 @@ impl Surface {
}
}
pub fn get_physical_device_surface_formats_khr(&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR)
-> VkResult<Vec<vk::SurfaceFormatKHR>> {
pub fn get_physical_device_surface_formats_khr(
&self,
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe {
let mut count = 0;
self.surface_fn.get_physical_device_surface_formats_khr(physical_device,
surface,
&mut count,
ptr::null_mut());
self.surface_fn.get_physical_device_surface_formats_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as usize);
let err_code = self.surface_fn
.get_physical_device_surface_formats_khr(physical_device,
surface,
&mut count,
v.as_mut_ptr());
let err_code = self.surface_fn.get_physical_device_surface_formats_khr(
physical_device,
surface,
&mut count,
v.as_mut_ptr(),
);
v.set_len(count as usize);
match err_code {
vk::Result::Success => Ok(v),
@ -112,10 +129,15 @@ impl Surface {
}
}
pub unsafe fn destroy_surface_khr(&self,
surface: vk::SurfaceKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.surface_fn
.destroy_surface_khr(self.handle, surface, allocation_callbacks.as_raw_ptr());
pub unsafe fn destroy_surface_khr(
&self,
surface: vk::SurfaceKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) {
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 vk;
use std::ffi::CStr;
use ::RawPtr;
use RawPtr;
use version::{InstanceV1_0, DeviceV1_0};
#[derive(Clone)]
@ -14,11 +14,15 @@ pub struct Swapchain {
}
impl Swapchain {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I,
device: &D)
-> 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())) }
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(
instance: &I,
device: &D,
) -> 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(),
))
})?;
Ok(Swapchain {
handle: device.handle(),
@ -30,72 +34,90 @@ impl Swapchain {
CStr::from_bytes_with_nul(b"VK_KHR_swapchain\0").expect("Wrong extension string")
}
pub unsafe fn destroy_swapchain_khr(&self,
swapchain: vk::SwapchainKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.swapchain_fn
.destroy_swapchain_khr(self.handle, swapchain, allocation_callbacks.as_raw_ptr());
pub unsafe fn destroy_swapchain_khr(
&self,
swapchain: vk::SwapchainKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) {
self.swapchain_fn.destroy_swapchain_khr(
self.handle,
swapchain,
allocation_callbacks.as_raw_ptr(),
);
}
pub unsafe fn acquire_next_image_khr(&self,
swapchain: vk::SwapchainKHR,
timeout: vk::uint64_t,
semaphore: vk::Semaphore,
fence: vk::Fence)
-> VkResult<vk::uint32_t> {
pub unsafe fn acquire_next_image_khr(
&self,
swapchain: vk::SwapchainKHR,
timeout: vk::uint64_t,
semaphore: vk::Semaphore,
fence: vk::Fence,
) -> VkResult<vk::uint32_t> {
let mut index = mem::uninitialized();
let err_code = self.swapchain_fn
.acquire_next_image_khr(self.handle,
swapchain,
timeout,
semaphore,
fence,
&mut index);
let err_code = self.swapchain_fn.acquire_next_image_khr(
self.handle,
swapchain,
timeout,
semaphore,
fence,
&mut index,
);
match err_code {
vk::Result::Success => Ok(index),
_ => Err(err_code),
}
}
pub unsafe fn create_swapchain_khr(&self,
create_info: &vk::SwapchainCreateInfoKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> VkResult<vk::SwapchainKHR> {
pub unsafe fn create_swapchain_khr(
&self,
create_info: &vk::SwapchainCreateInfoKHR,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SwapchainKHR> {
let mut swapchain = mem::uninitialized();
let err_code = self.swapchain_fn
.create_swapchain_khr(self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut swapchain);
let err_code = self.swapchain_fn.create_swapchain_khr(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut swapchain,
);
match err_code {
vk::Result::Success => Ok(swapchain),
_ => Err(err_code),
}
}
pub unsafe fn queue_present_khr(&self,
queue: vk::Queue,
create_info: &vk::PresentInfoKHR)
-> VkResult<()> {
let err_code = self.swapchain_fn
.queue_present_khr(queue, create_info);
pub unsafe fn queue_present_khr(
&self,
queue: vk::Queue,
create_info: &vk::PresentInfoKHR,
) -> VkResult<()> {
let err_code = self.swapchain_fn.queue_present_khr(queue, create_info);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
pub fn get_swapchain_images_khr(&self,
swapchain: vk::SwapchainKHR)
-> VkResult<Vec<vk::Image>> {
pub fn get_swapchain_images_khr(
&self,
swapchain: vk::SwapchainKHR,
) -> VkResult<Vec<vk::Image>> {
unsafe {
let mut count = 0;
self.swapchain_fn
.get_swapchain_images_khr(self.handle, swapchain, &mut count, ptr::null_mut());
self.swapchain_fn.get_swapchain_images_khr(
self.handle,
swapchain,
&mut count,
ptr::null_mut(),
);
let mut v = Vec::with_capacity(count as vk::size_t);
let err_code = self.swapchain_fn
.get_swapchain_images_khr(self.handle, swapchain, &mut count, v.as_mut_ptr());
let err_code = self.swapchain_fn.get_swapchain_images_khr(
self.handle,
swapchain,
&mut count,
v.as_mut_ptr(),
);
v.set_len(count as vk::size_t);
match err_code {
vk::Result::Success => Ok(v),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,15 +15,15 @@ pub mod extensions;
pub mod version;
pub mod util;
pub trait RawPtr<T>{
pub trait RawPtr<T> {
fn as_raw_ptr(&self) -> *const T;
}
impl<'r, T> RawPtr<T> for Option<&'r T>{
fn as_raw_ptr(&self) -> *const T{
match self{
impl<'r, T> RawPtr<T> for Option<&'r T> {
fn as_raw_ptr(&self) -> *const T {
match self {
&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>> {
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 })
}
@ -49,21 +52,24 @@ pub trait EntryLoader: Sized {
pub trait InstanceLoader: Sized {
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0;
unsafe fn load(static_fn: &vk::StaticFn,
instance: vk::Instance)
-> Result<Self, Vec<&'static str>>;
unsafe fn load(
static_fn: &vk::StaticFn,
instance: vk::Instance,
) -> Result<Self, Vec<&'static str>>;
}
pub trait DeviceLoader: Sized {
unsafe fn load(instance_fn: &vk::InstanceFnV1_0,
device: vk::Device)
-> Result<Self, Vec<&'static str>>;
unsafe fn load(
instance_fn: &vk::InstanceFnV1_0,
device: vk::Device,
) -> Result<Self, Vec<&'static str>>;
}
impl DeviceLoader for DeviceFpV1_0 {
unsafe fn load(instance_fn: &vk::InstanceFnV1_0,
device: vk::Device)
-> Result<Self, Vec<&'static str>> {
unsafe fn load(
instance_fn: &vk::InstanceFnV1_0,
device: vk::Device,
) -> Result<Self, Vec<&'static str>> {
let device_fn = vk::DeviceFnV1_0::load(|name| {
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 {
&self.instance_fn
}
unsafe fn load(static_fn: &vk::StaticFn,
instance: vk::Instance)
-> Result<Self, Vec<&'static str>> {
unsafe fn load(
static_fn: &vk::StaticFn,
instance: vk::Instance,
) -> Result<Self, Vec<&'static str>> {
let instance_fn = vk::InstanceFnV1_0::load(|name| {
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_reallocation", &(self.pfn_reallocation as *const ()))
.field("pfn_free", &(self.pfn_free as *const ()))
.field("pfn_internal_allocation",
&(self.pfn_internal_allocation as *const ()))
.field(
"pfn_internal_allocation",
&(self.pfn_internal_allocation as *const ()),
)
.field("pfn_internal_free", &(self.pfn_internal_free as *const ()))
.finish()
}
@ -513,8 +515,9 @@ pub mod types {
.field("vendor_id", &self.vendor_id)
.field("device_id", &self.device_id)
.field("device_type", &self.device_type)
.field("device_name",
&unsafe { CStr::from_ptr(&self.device_name[0]) })
.field("device_name", &unsafe {
CStr::from_ptr(&self.device_name[0])
})
.field("pipeline_cache_uuid", &&self.pipeline_cache_uuid[..])
.field("limits", &self.limits)
.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_storage_buffer_range", &self.max_storage_buffer_range)
.field("max_push_constants_size", &self.max_push_constants_size)
.field("max_memory_allocation_count",
&self.max_memory_allocation_count)
.field("max_sampler_allocation_count",
&self.max_sampler_allocation_count)
.field(
"max_memory_allocation_count",
&self.max_memory_allocation_count,
)
.field(
"max_sampler_allocation_count",
&self.max_sampler_allocation_count,
)
.field("buffer_image_granularity", &self.buffer_image_granularity)
.field("sparse_address_space_size", &self.sparse_address_space_size)
.field("max_bound_descriptor_sets", &self.max_bound_descriptor_sets)
.field("max_per_stage_descriptor_samplers",
&self.max_per_stage_descriptor_samplers)
.field("max_per_stage_descriptor_uniform_buffers",
&self.max_per_stage_descriptor_uniform_buffers)
.field("max_per_stage_descriptor_storage_buffers",
&self.max_per_stage_descriptor_storage_buffers)
.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_descriptor_samplers",
&self.max_per_stage_descriptor_samplers,
)
.field(
"max_per_stage_descriptor_uniform_buffers",
&self.max_per_stage_descriptor_uniform_buffers,
)
.field(
"max_per_stage_descriptor_storage_buffers",
&self.max_per_stage_descriptor_storage_buffers,
)
.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_descriptor_set_samplers",
&self.max_descriptor_set_samplers)
.field("max_descriptor_set_uniform_buffers",
&self.max_descriptor_set_uniform_buffers)
.field("max_descriptor_set_uniform_buffers_dynamic",
&self.max_descriptor_set_uniform_buffers_dynamic)
.field("max_descriptor_set_storage_buffers",
&self.max_descriptor_set_storage_buffers)
.field("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_descriptor_set_samplers",
&self.max_descriptor_set_samplers,
)
.field(
"max_descriptor_set_uniform_buffers",
&self.max_descriptor_set_uniform_buffers,
)
.field(
"max_descriptor_set_uniform_buffers_dynamic",
&self.max_descriptor_set_uniform_buffers_dynamic,
)
.field(
"max_descriptor_set_storage_buffers",
&self.max_descriptor_set_storage_buffers,
)
.field(
"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_attribute_offset",
&self.max_vertex_input_attribute_offset)
.field("max_vertex_input_binding_stride",
&self.max_vertex_input_binding_stride)
.field("max_vertex_output_components",
&self.max_vertex_output_components)
.field("max_tessellation_generation_level",
&self.max_tessellation_generation_level)
.field("max_tessellation_patch_size",
&self.max_tessellation_patch_size)
.field("max_tessellation_control_per_vertex_input_components",
&self.max_tessellation_control_per_vertex_input_components)
.field("max_tessellation_control_per_vertex_output_components",
&self.max_tessellation_control_per_vertex_output_components)
.field("max_tessellation_control_per_patch_output_components",
&self.max_tessellation_control_per_patch_output_components)
.field("max_tessellation_control_total_output_components",
&self.max_tessellation_control_total_output_components)
.field("max_tessellation_evaluation_input_components",
&self.max_tessellation_evaluation_input_components)
.field("max_tessellation_evaluation_output_components",
&self.max_tessellation_evaluation_output_components)
.field("max_geometry_shader_invocations",
&self.max_geometry_shader_invocations)
.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(
"max_vertex_input_attribute_offset",
&self.max_vertex_input_attribute_offset,
)
.field(
"max_vertex_input_binding_stride",
&self.max_vertex_input_binding_stride,
)
.field(
"max_vertex_output_components",
&self.max_vertex_output_components,
)
.field(
"max_tessellation_generation_level",
&self.max_tessellation_generation_level,
)
.field(
"max_tessellation_patch_size",
&self.max_tessellation_patch_size,
)
.field(
"max_tessellation_control_per_vertex_input_components",
&self.max_tessellation_control_per_vertex_input_components,
)
.field(
"max_tessellation_control_per_vertex_output_components",
&self.max_tessellation_control_per_vertex_output_components,
)
.field(
"max_tessellation_control_per_patch_output_components",
&self.max_tessellation_control_per_patch_output_components,
)
.field(
"max_tessellation_control_total_output_components",
&self.max_tessellation_control_total_output_components,
)
.field(
"max_tessellation_evaluation_input_components",
&self.max_tessellation_evaluation_input_components,
)
.field(
"max_tessellation_evaluation_output_components",
&self.max_tessellation_evaluation_output_components,
)
.field(
"max_geometry_shader_invocations",
&self.max_geometry_shader_invocations,
)
.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_texel_precision_bits", &self.sub_texel_precision_bits)
.field("mipmap_precision_bits", &self.mipmap_precision_bits)
.field("max_draw_indexed_index_value",
&self.max_draw_indexed_index_value)
.field(
"max_draw_indexed_index_value",
&self.max_draw_indexed_index_value,
)
.field("max_draw_indirect_count", &self.max_draw_indirect_count)
.field("max_sampler_lod_bias", &self.max_sampler_lod_bias)
.field("max_sampler_anisotropy", &self.max_sampler_anisotropy)
.field("max_viewports", &self.max_viewports)
.field("max_viewport_dimensions",
&&self.max_viewport_dimensions[..])
.field(
"max_viewport_dimensions",
&&self.max_viewport_dimensions[..],
)
.field("viewport_bounds_range", &&self.viewport_bounds_range[..])
.field("viewport_sub_pixel_bits", &self.viewport_sub_pixel_bits)
.field("min_memory_map_alignment", &self.min_memory_map_alignment)
.field("min_texel_buffer_offset_alignment",
&self.min_texel_buffer_offset_alignment)
.field("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_buffer_offset_alignment",
&self.min_texel_buffer_offset_alignment,
)
.field(
"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("max_texel_offset", &self.max_texel_offset)
.field("min_texel_gather_offset", &self.min_texel_gather_offset)
.field("max_texel_gather_offset", &self.max_texel_gather_offset)
.field("min_interpolation_offset", &self.min_interpolation_offset)
.field("max_interpolation_offset", &self.max_interpolation_offset)
.field("sub_pixel_interpolation_offset_bits",
&self.sub_pixel_interpolation_offset_bits)
.field(
"sub_pixel_interpolation_offset_bits",
&self.sub_pixel_interpolation_offset_bits,
)
.field("max_framebuffer_width", &self.max_framebuffer_width)
.field("max_framebuffer_height", &self.max_framebuffer_height)
.field("max_framebuffer_layers", &self.max_framebuffer_layers)
.field("framebuffer_color_sample_counts",
&self.framebuffer_color_sample_counts)
.field("framebuffer_depth_sample_counts",
&self.framebuffer_depth_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(
"framebuffer_color_sample_counts",
&self.framebuffer_color_sample_counts,
)
.field(
"framebuffer_depth_sample_counts",
&self.framebuffer_depth_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("sampled_image_color_sample_counts",
&self.sampled_image_color_sample_counts)
.field("sampled_image_integer_sample_counts",
&self.sampled_image_integer_sample_counts)
.field("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(
"sampled_image_color_sample_counts",
&self.sampled_image_color_sample_counts,
)
.field(
"sampled_image_integer_sample_counts",
&self.sampled_image_integer_sample_counts,
)
.field(
"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("timestamp_compute_and_graphics",
&self.timestamp_compute_and_graphics)
.field(
"timestamp_compute_and_graphics",
&self.timestamp_compute_and_graphics,
)
.field("timestamp_period", &self.timestamp_period)
.field("max_clip_distances", &self.max_clip_distances)
.field("max_cull_distances", &self.max_cull_distances)
.field("max_combined_clip_and_cull_distances",
&self.max_combined_clip_and_cull_distances)
.field(
"max_combined_clip_and_cull_distances",
&self.max_combined_clip_and_cull_distances,
)
.field("discrete_queue_priorities", &self.discrete_queue_priorities)
.field("point_size_range", &&self.point_size_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("strict_lines", &self.strict_lines)
.field("standard_sample_locations", &self.standard_sample_locations)
.field("optimal_buffer_copy_offset_alignment",
&self.optimal_buffer_copy_offset_alignment)
.field("optimal_buffer_copy_row_pitch_alignment",
&self.optimal_buffer_copy_row_pitch_alignment)
.field(
"optimal_buffer_copy_offset_alignment",
&self.optimal_buffer_copy_offset_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)
.finish()
}
@ -1127,8 +1250,9 @@ pub mod types {
impl fmt::Debug for ExtensionProperties {
fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
fmt.debug_struct("ExtensionProperties")
.field("extension_name",
&unsafe { CStr::from_ptr(&self.extension_name[0]) })
.field("extension_name", &unsafe {
CStr::from_ptr(&self.extension_name[0])
})
.field("spec_version", &self.spec_version)
.finish()
}
@ -1173,12 +1297,15 @@ pub mod types {
impl fmt::Debug for LayerProperties {
fn fmt(&self, fmt: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
fmt.debug_struct("LayerProperties")
.field("layer_name",
&unsafe { CStr::from_ptr(&self.layer_name[0]) })
.field(
"layer_name",
&unsafe { CStr::from_ptr(&self.layer_name[0]) },
)
.field("spec_version", &self.spec_version)
.field("implementation_version", &self.implementation_version)
.field("description",
&unsafe { CStr::from_ptr(&self.description[0]) })
.field("description", &unsafe {
CStr::from_ptr(&self.description[0])
})
.finish()
}
}
@ -2670,8 +2797,10 @@ pub mod types {
Result::Success => write!(fmt, "Command successfully completed"),
Result::NotReady => write!(fmt, "A fence or query has not yet completed"),
Result::Timeout => {
write!(fmt,
"A wait operation has not completed in the specified time")
write!(
fmt,
"A wait operation has not completed in the specified time"
)
}
Result::EventSet => write!(fmt, "An event is signaled"),
Result::EventReset => write!(fmt, "An event is unsignaled"),
@ -2681,19 +2810,25 @@ pub mod types {
write!(fmt, "A device memory allocation has failed.")
}
Result::ErrorInitializationFailed => {
write!(fmt,
"Initialization of an object could not be completed for implementation-specific reasons.")
write!(
fmt,
"Initialization of an object could not be completed for implementation-specific reasons."
)
}
Result::ErrorDeviceLost => {
write!(fmt,
"The logical or physical device has been lost. See Lost Device")
write!(
fmt,
"The logical or physical device has been lost. See Lost Device"
)
}
Result::ErrorMemoryMapFailed => {
write!(fmt, "Mapping of a memory object has failed.")
}
Result::ErrorLayerNotPresent => {
write!(fmt,
"A requested layer is not present or could not be loaded.")
write!(
fmt,
"A requested layer is not present or could not be loaded."
)
}
Result::ErrorExtensionNotPresent => {
write!(fmt, "A requested extension is not supported.")
@ -2702,20 +2837,26 @@ pub mod types {
write!(fmt, "A requested feature is not supported.")
}
Result::ErrorIncompatibleDriver => {
write!(fmt,
"The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons.")
write!(
fmt,
"The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons."
)
}
Result::ErrorTooManyObjects => {
write!(fmt,
"Too many objects of the type have already been created.")
write!(
fmt,
"Too many objects of the type have already been created."
)
}
Result::ErrorFormatNotSupported => {
write!(fmt, "A requested format is not supported on this device.")
}
Result::ErrorFragmentedPool => {
write!(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,
"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, ""),
}