Cleanup warnings and use version traits

This commit is contained in:
maik klein 2017-01-05 09:03:37 +01:00
parent afdec21cab
commit f2b52eb007
8 changed files with 38 additions and 47 deletions

View file

@ -80,10 +80,10 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
} }
#[cfg(all(unix, not(target_os = "android")))] #[cfg(all(unix, not(target_os = "android")))]
unsafe fn create_surface(instance: &Instance<V1_0>, unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
entry: &Entry<V1_0>, instance: &I,
window: &winit::Window) window: &winit::Window)
-> Result<vk::SurfaceKHR, vk::Result> { -> Result<vk::SurfaceKHR, vk::Result> {
use winit::os::unix::WindowExt; use winit::os::unix::WindowExt;
let x11_display = window.get_xlib_display().unwrap(); let x11_display = window.get_xlib_display().unwrap();
let x11_window = window.get_xlib_window().unwrap(); let x11_window = window.get_xlib_window().unwrap();
@ -94,16 +94,16 @@ unsafe fn create_surface(instance: &Instance<V1_0>,
window: x11_window as vk::Window, window: x11_window as vk::Window,
dpy: x11_display as *mut vk::Display, dpy: x11_display as *mut vk::Display,
}; };
let xlib_surface_loader = XlibSurface::new(&entry, &instance) let xlib_surface_loader = XlibSurface::new(entry, instance)
.expect("Unable to load xlib surface"); .expect("Unable to load xlib surface");
xlib_surface_loader.create_xlib_surface_khr(&x11_create_info, None) xlib_surface_loader.create_xlib_surface_khr(&x11_create_info, None)
} }
#[cfg(windows)] #[cfg(windows)]
unsafe fn create_surface(instance: &Instance<V1_0>, unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
entry: &Entry<V1_0>, instance: &I,
window: &winit::Window) window: &winit::Window)
-> Result<vk::SurfaceKHR, vk::Result> { -> Result<vk::SurfaceKHR, vk::Result> {
use winit::os::windows::WindowExt; use winit::os::windows::WindowExt;
let hwnd = window.get_hwnd() as *mut winapi::windef::HWND__; let hwnd = window.get_hwnd() as *mut winapi::windef::HWND__;
let hinstance = unsafe { user32::GetWindow(hwnd, 0) as *const () }; let hinstance = unsafe { user32::GetWindow(hwnd, 0) as *const () };
@ -114,7 +114,7 @@ unsafe fn create_surface(instance: &Instance<V1_0>,
hinstance: hinstance, hinstance: hinstance,
hwnd: hwnd as *const (), hwnd: hwnd as *const (),
}; };
let win32_surface_loader = Win32Surface::new(&entry, &instance) let win32_surface_loader = Win32Surface::new(entry, instance)
.expect("Unable to load win32 surface"); .expect("Unable to load win32 surface");
win32_surface_loader.create_win32_surface_khr(&win32_create_info, None) win32_surface_loader.create_win32_surface_khr(&win32_create_info, None)
} }
@ -284,7 +284,7 @@ impl ExampleBase {
let debug_call_back = let debug_call_back =
debug_report_loader.create_debug_report_callback_ext(&debug_info, None) debug_report_loader.create_debug_report_callback_ext(&debug_info, None)
.unwrap(); .unwrap();
let surface = create_surface(&instance, &entry, &window).unwrap(); let surface = create_surface(&entry, &instance, &window).unwrap();
let pdevices = instance.enumerate_physical_devices().expect("Physical device error"); let pdevices = instance.enumerate_physical_devices().expect("Physical device error");
let surface_loader = Surface::new(&entry, &instance) let surface_loader = Surface::new(&entry, &instance)
.expect("Unable to load the Surface extension"); .expect("Unable to load the Surface extension");

View file

@ -3,13 +3,9 @@ use prelude::*;
use std::mem; use std::mem;
use vk; use vk;
use ::RawPtr; use ::RawPtr;
use version::{FunctionPointers, V1_0};
use version::{FunctionPointers, V1_0, DeviceFpV1_0}; #[allow(non_camel_case_types)]
// unsafe impl Sync for Device {}
// unsafe impl Send for Device {}
pub trait DeviceV1_0 { pub trait DeviceV1_0 {
fn handle(&self) -> vk::Device; fn handle(&self) -> vk::Device;
fn fp_v1_0(&self) -> &vk::DeviceFnV1_0; fn fp_v1_0(&self) -> &vk::DeviceFnV1_0;

View file

@ -7,7 +7,7 @@ use shared_library::dynamic_library::DynamicLibrary;
use std::path::Path; use std::path::Path;
use ::RawPtr; use ::RawPtr;
use std::marker::PhantomData; use std::marker::PhantomData;
use version::{FunctionPointers, V1_0, InstanceFpV1_0, InstanceLoader, EntryLoader}; use version::{FunctionPointers, V1_0, InstanceLoader, EntryLoader};
#[cfg(windows)] #[cfg(windows)]
fn get_path() -> &'static Path { fn get_path() -> &'static Path {
@ -47,6 +47,8 @@ pub enum InstanceError {
LoadError(Vec<&'static str>), LoadError(Vec<&'static str>),
VkError(vk::Result), VkError(vk::Result),
} }
#[allow(non_camel_case_types)]
pub trait EntryV1_0 { pub trait EntryV1_0 {
type Fp: FunctionPointers; type Fp: FunctionPointers;
fn fp_v1_0(&self) -> &vk::EntryFnV1_0; fn fp_v1_0(&self) -> &vk::EntryFnV1_0;
@ -135,7 +137,9 @@ impl<V: FunctionPointers> Entry<V> {
} }
Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())), Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())),
}?; }?;
let entry_fn = unsafe { V::EntryFp::load(&static_fn).map_err(|err| LoadingError::EntryLoadError(err))? }; let entry_fn = unsafe {
V::EntryFp::load(&static_fn).map_err(|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

@ -2,12 +2,10 @@
use prelude::*; use prelude::*;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use instance::Instance;
use entry::Entry;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use ::RawPtr;
use version::{V1_0, EntryV1_0}; use version::{EntryV1_0, InstanceV1_0};
#[derive(Clone)] #[derive(Clone)]
pub struct Surface { pub struct Surface {
@ -16,9 +14,9 @@ pub struct Surface {
} }
impl Surface { impl Surface {
pub fn new(entry: &Entry<V1_0>, pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
instance: &Instance<V1_0>) instance: &I)
-> Result<Surface, Vec<&'static str>> { -> Result<Surface, Vec<&'static str>> {
let surface_fn = vk::SurfaceFn::load(|name| { let surface_fn = vk::SurfaceFn::load(|name| {
unsafe { 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()))

View file

@ -1,13 +1,10 @@
use prelude::*; use prelude::*;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use instance::Instance;
use device::Device;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use ::RawPtr;
use instance::InstanceV1_0; use version::{InstanceV1_0, DeviceV1_0};
use version::{V1_0};
#[derive(Clone)] #[derive(Clone)]
pub struct Swapchain { pub struct Swapchain {
@ -16,7 +13,9 @@ pub struct Swapchain {
} }
impl Swapchain { impl Swapchain {
pub fn new(instance: &Instance<V1_0>, device: &Device<V1_0>) -> Result<Swapchain, Vec<&'static str>> { 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| { let swapchain_fn = vk::SwapchainFn::load(|name| {
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) } unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
})?; })?;

View file

@ -1,13 +1,10 @@
#![allow(dead_code)] #![allow(dead_code)]
use prelude::*; use prelude::*;
use std::mem; use std::mem;
use instance::Instance;
use entry::Entry;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use ::RawPtr;
use instance::InstanceV1_0; use version::{EntryV1_0, InstanceV1_0};
use version::{V1_0, EntryV1_0};
#[derive(Clone)] #[derive(Clone)]
pub struct Win32Surface { pub struct Win32Surface {
@ -16,9 +13,9 @@ pub struct Win32Surface {
} }
impl Win32Surface { impl Win32Surface {
pub fn new(entry: &Entry<V1_0>, pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
instance: &Instance<V1_0>) instance: &I)
-> Result<Win32Surface, Vec<&'static str>> { -> Result<Win32Surface, Vec<&'static str>> {
let surface_fn = vk::Win32SurfaceFn::load(|name| { let surface_fn = vk::Win32SurfaceFn::load(|name| {
unsafe { 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()))

View file

@ -1,13 +1,10 @@
#![allow(dead_code)] #![allow(dead_code)]
use prelude::*; use prelude::*;
use std::mem; use std::mem;
use instance::Instance;
use entry::Entry;
use vk; use vk;
use std::ffi::CStr; use std::ffi::CStr;
use ::RawPtr; use ::RawPtr;
use instance::InstanceV1_0; use version::{EntryV1_0, InstanceV1_0};
use version::{V1_0, EntryV1_0};
#[derive(Clone)] #[derive(Clone)]
pub struct XlibSurface { pub struct XlibSurface {
@ -16,9 +13,9 @@ pub struct XlibSurface {
} }
impl XlibSurface { impl XlibSurface {
pub fn new(entry: &Entry<V1_0>, pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
instance: &Instance<V1_0>) instance: &I)
-> Result<XlibSurface, Vec<&'static str>> { -> Result<XlibSurface, Vec<&'static str>> {
let surface_fn = vk::XlibSurfaceFn::load(|name| { let surface_fn = vk::XlibSurfaceFn::load(|name| {
unsafe { 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()))

View file

@ -5,8 +5,8 @@ use std::mem;
use vk; use vk;
use device::Device; use device::Device;
use ::RawPtr; use ::RawPtr;
use version::{FunctionPointers, V1_0, InstanceFpV1_0, DeviceFpV1_0}; use version::{FunctionPointers, V1_0};
use version::{InstanceLoader, DeviceLoader}; use version::DeviceLoader;
#[derive(Debug)] #[derive(Debug)]
pub enum DeviceError { pub enum DeviceError {
@ -43,7 +43,7 @@ impl<V: FunctionPointers> Instance<V> {
} }
} }
#[warn(non_camel_case_types)] #[allow(non_camel_case_types)]
pub trait InstanceV1_0 { pub trait InstanceV1_0 {
type Fp: FunctionPointers; type Fp: FunctionPointers;
fn handle(&self) -> vk::Instance; fn handle(&self) -> vk::Instance;