Add version to Entry
This commit is contained in:
parent
45936ae6bb
commit
0c0b147502
6 changed files with 35 additions and 29 deletions
|
@ -17,7 +17,7 @@ use std::ptr;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
pub use ash::instance::{V1_0, InstanceV1_0};
|
pub use ash::instance::{V1_0, InstanceV1_0};
|
||||||
pub use ash::device::{DeviceV1_0};
|
pub use ash::device::DeviceV1_0;
|
||||||
|
|
||||||
// Simple offset_of macro akin to C++ offsetof
|
// Simple offset_of macro akin to C++ offsetof
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -82,7 +82,7 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device<V1_0>, vk::CommandBuffer)>(
|
||||||
|
|
||||||
#[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(instance: &Instance<V1_0>,
|
||||||
entry: &Entry,
|
entry: &Entry<V1_0>,
|
||||||
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;
|
||||||
|
@ -187,7 +187,7 @@ fn resize_callback(width: u32, height: u32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExampleBase {
|
pub struct ExampleBase {
|
||||||
pub entry: Entry,
|
pub entry: Entry<V1_0>,
|
||||||
pub instance: Instance<V1_0>,
|
pub instance: Instance<V1_0>,
|
||||||
pub device: Device<V1_0>,
|
pub device: Device<V1_0>,
|
||||||
pub surface_loader: Surface,
|
pub surface_loader: Surface,
|
||||||
|
|
50
src/entry.rs
50
src/entry.rs
|
@ -6,6 +6,8 @@ use instance::{Instance, V1_0, InstanceFpV1_0};
|
||||||
use shared_library::dynamic_library::DynamicLibrary;
|
use shared_library::dynamic_library::DynamicLibrary;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use ::RawPtr;
|
use ::RawPtr;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use instance::VkVersion;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn get_path() -> &'static Path {
|
fn get_path() -> &'static Path {
|
||||||
|
@ -27,9 +29,11 @@ lazy_static!{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Entry {
|
pub struct Entry<V: VkVersion> {
|
||||||
static_fn: vk::StaticFn,
|
static_fn: vk::StaticFn,
|
||||||
entry_fn: vk::EntryFn,
|
entry_fn: vk::EntryFn,
|
||||||
|
_v: PhantomData<V>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -45,8 +49,28 @@ pub enum InstanceError {
|
||||||
VkError(vk::Result),
|
VkError(vk::Result),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry<V1_0>{
|
||||||
pub fn load_vulkan() -> Result<Entry, LoadingError> {
|
pub fn create_instance(&self,
|
||||||
|
create_info: &vk::InstanceCreateInfo,
|
||||||
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
|
-> Result<Instance<V1_0>, InstanceError> {
|
||||||
|
unsafe {
|
||||||
|
let mut instance: vk::Instance = mem::uninitialized();
|
||||||
|
let err_code = self.entry_fn.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_fn = vk::InstanceFn::load(|name| {
|
||||||
|
mem::transmute(self.static_fn.get_instance_proc_addr(instance, name.as_ptr()))
|
||||||
|
}).map_err(|err| InstanceError::LoadError(err))?;
|
||||||
|
Ok(Instance::from_raw(instance, InstanceFpV1_0 { instance_fn: instance_fn }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<V: VkVersion> Entry<V> {
|
||||||
|
pub fn load_vulkan() -> Result<Entry<V>, LoadingError> {
|
||||||
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 {
|
||||||
|
@ -67,28 +91,10 @@ impl Entry {
|
||||||
Ok(Entry {
|
Ok(Entry {
|
||||||
static_fn: static_fn,
|
static_fn: static_fn,
|
||||||
entry_fn: entry_fn,
|
entry_fn: entry_fn,
|
||||||
|
_v: PhantomData
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_instance(&self,
|
|
||||||
create_info: &vk::InstanceCreateInfo,
|
|
||||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
|
||||||
-> Result<Instance<V1_0>, InstanceError> {
|
|
||||||
unsafe {
|
|
||||||
let mut instance: vk::Instance = mem::uninitialized();
|
|
||||||
let err_code = self.entry_fn.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_fn = vk::InstanceFn::load(|name| {
|
|
||||||
mem::transmute(self.static_fn.get_instance_proc_addr(instance, name.as_ptr()))
|
|
||||||
}).map_err(|err| InstanceError::LoadError(err))?;
|
|
||||||
Ok(Instance::from_raw(instance, InstanceFpV1_0 { instance_fn: instance_fn }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
|
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut num = 0;
|
let mut num = 0;
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct DebugReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugReport {
|
impl DebugReport {
|
||||||
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<DebugReport, Vec<&'static str>> {
|
pub fn new(entry: &Entry<V1_0>, instance: &Instance<V1_0>) -> Result<DebugReport, Vec<&'static str>> {
|
||||||
let debug_report_fn = vk::DebugReportFn::load(|name| {
|
let debug_report_fn = vk::DebugReportFn::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()))
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct Surface {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Surface {
|
impl Surface {
|
||||||
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<Surface, Vec<&'static str>> {
|
pub fn new(entry: &Entry<V1_0>, instance: &Instance<V1_0>) -> 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()))
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct Win32Surface {
|
||||||
|
|
||||||
|
|
||||||
impl Win32Surface {
|
impl Win32Surface {
|
||||||
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<Win32Surface, Vec<&'static str>> {
|
pub fn new(entry: &Entry<V1_0>, instance: &Instance<V1_0>) -> 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()))
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub struct XlibSurface {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XlibSurface {
|
impl XlibSurface {
|
||||||
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<XlibSurface, Vec<&'static str>> {
|
pub fn new(entry: &Entry<V1_0>, instance: &Instance<V1_0>) -> 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()))
|
||||||
|
|
Loading…
Add table
Reference in a new issue