Cleanup warnings and use version traits
This commit is contained in:
parent
afdec21cab
commit
f2b52eb007
|
@ -80,8 +80,8 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
|
|||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
unsafe fn create_surface(instance: &Instance<V1_0>,
|
||||
entry: &Entry<V1_0>,
|
||||
unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
|
||||
instance: &I,
|
||||
window: &winit::Window)
|
||||
-> Result<vk::SurfaceKHR, vk::Result> {
|
||||
use winit::os::unix::WindowExt;
|
||||
|
@ -94,14 +94,14 @@ unsafe fn create_surface(instance: &Instance<V1_0>,
|
|||
window: x11_window as vk::Window,
|
||||
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");
|
||||
xlib_surface_loader.create_xlib_surface_khr(&x11_create_info, None)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
unsafe fn create_surface(instance: &Instance<V1_0>,
|
||||
entry: &Entry<V1_0>,
|
||||
unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(entry: &E,
|
||||
instance: &I,
|
||||
window: &winit::Window)
|
||||
-> Result<vk::SurfaceKHR, vk::Result> {
|
||||
use winit::os::windows::WindowExt;
|
||||
|
@ -114,7 +114,7 @@ unsafe fn create_surface(instance: &Instance<V1_0>,
|
|||
hinstance: hinstance,
|
||||
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");
|
||||
win32_surface_loader.create_win32_surface_khr(&win32_create_info, None)
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ impl ExampleBase {
|
|||
let debug_call_back =
|
||||
debug_report_loader.create_debug_report_callback_ext(&debug_info, None)
|
||||
.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 surface_loader = Surface::new(&entry, &instance)
|
||||
.expect("Unable to load the Surface extension");
|
||||
|
|
|
@ -3,13 +3,9 @@ use prelude::*;
|
|||
use std::mem;
|
||||
use vk;
|
||||
use ::RawPtr;
|
||||
use version::{FunctionPointers, V1_0};
|
||||
|
||||
use version::{FunctionPointers, V1_0, DeviceFpV1_0};
|
||||
|
||||
// unsafe impl Sync for Device {}
|
||||
// unsafe impl Send for Device {}
|
||||
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub trait DeviceV1_0 {
|
||||
fn handle(&self) -> vk::Device;
|
||||
fn fp_v1_0(&self) -> &vk::DeviceFnV1_0;
|
||||
|
|
|
@ -7,7 +7,7 @@ use shared_library::dynamic_library::DynamicLibrary;
|
|||
use std::path::Path;
|
||||
use ::RawPtr;
|
||||
use std::marker::PhantomData;
|
||||
use version::{FunctionPointers, V1_0, InstanceFpV1_0, InstanceLoader, EntryLoader};
|
||||
use version::{FunctionPointers, V1_0, InstanceLoader, EntryLoader};
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_path() -> &'static Path {
|
||||
|
@ -47,6 +47,8 @@ pub enum InstanceError {
|
|||
LoadError(Vec<&'static str>),
|
||||
VkError(vk::Result),
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub trait EntryV1_0 {
|
||||
type Fp: FunctionPointers;
|
||||
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())),
|
||||
}?;
|
||||
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 {
|
||||
static_fn: static_fn,
|
||||
entry_fn: entry_fn,
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
use prelude::*;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use instance::Instance;
|
||||
use entry::Entry;
|
||||
use vk;
|
||||
use std::ffi::CStr;
|
||||
use ::RawPtr;
|
||||
use version::{V1_0, EntryV1_0};
|
||||
use version::{EntryV1_0, InstanceV1_0};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Surface {
|
||||
|
@ -16,8 +14,8 @@ pub struct Surface {
|
|||
}
|
||||
|
||||
impl Surface {
|
||||
pub fn new(entry: &Entry<V1_0>,
|
||||
instance: &Instance<V1_0>)
|
||||
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 {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
use prelude::*;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use instance::Instance;
|
||||
use device::Device;
|
||||
use vk;
|
||||
use std::ffi::CStr;
|
||||
use ::RawPtr;
|
||||
use instance::InstanceV1_0;
|
||||
use version::{V1_0};
|
||||
use version::{InstanceV1_0, DeviceV1_0};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Swapchain {
|
||||
|
@ -16,7 +13,9 @@ pub struct 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| {
|
||||
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
|
||||
})?;
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
#![allow(dead_code)]
|
||||
use prelude::*;
|
||||
use std::mem;
|
||||
use instance::Instance;
|
||||
use entry::Entry;
|
||||
use vk;
|
||||
use std::ffi::CStr;
|
||||
use ::RawPtr;
|
||||
use instance::InstanceV1_0;
|
||||
use version::{V1_0, EntryV1_0};
|
||||
use version::{EntryV1_0, InstanceV1_0};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Win32Surface {
|
||||
|
@ -16,8 +13,8 @@ pub struct Win32Surface {
|
|||
}
|
||||
|
||||
impl Win32Surface {
|
||||
pub fn new(entry: &Entry<V1_0>,
|
||||
instance: &Instance<V1_0>)
|
||||
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 {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
#![allow(dead_code)]
|
||||
use prelude::*;
|
||||
use std::mem;
|
||||
use instance::Instance;
|
||||
use entry::Entry;
|
||||
use vk;
|
||||
use std::ffi::CStr;
|
||||
use ::RawPtr;
|
||||
use instance::InstanceV1_0;
|
||||
use version::{V1_0, EntryV1_0};
|
||||
use version::{EntryV1_0, InstanceV1_0};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct XlibSurface {
|
||||
|
@ -16,8 +13,8 @@ pub struct XlibSurface {
|
|||
}
|
||||
|
||||
impl XlibSurface {
|
||||
pub fn new(entry: &Entry<V1_0>,
|
||||
instance: &Instance<V1_0>)
|
||||
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 {
|
||||
|
|
|
@ -5,8 +5,8 @@ use std::mem;
|
|||
use vk;
|
||||
use device::Device;
|
||||
use ::RawPtr;
|
||||
use version::{FunctionPointers, V1_0, InstanceFpV1_0, DeviceFpV1_0};
|
||||
use version::{InstanceLoader, DeviceLoader};
|
||||
use version::{FunctionPointers, V1_0};
|
||||
use version::DeviceLoader;
|
||||
|
||||
#[derive(Debug)]
|
||||
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 {
|
||||
type Fp: FunctionPointers;
|
||||
fn handle(&self) -> vk::Instance;
|
||||
|
|
Loading…
Reference in a new issue