add create_instance to EntryV1_0
This commit is contained in:
parent
0531d67e99
commit
3dbb81735f
2 changed files with 31 additions and 33 deletions
|
@ -12,7 +12,7 @@ use std::default::Default;
|
||||||
use ash::Entry;
|
use ash::Entry;
|
||||||
use ash::Instance;
|
use ash::Instance;
|
||||||
use ash::Device;
|
use ash::Device;
|
||||||
pub use ash::version::{FunctionPointers, V1_0, InstanceV1_0, DeviceV1_0};
|
pub use ash::version::{V1_0, InstanceV1_0, DeviceV1_0, EntryV1_0};
|
||||||
use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport, Win32Surface};
|
use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport, Win32Surface};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
|
62
src/entry.rs
62
src/entry.rs
|
@ -47,17 +47,34 @@ pub enum InstanceError {
|
||||||
LoadError(Vec<&'static str>),
|
LoadError(Vec<&'static str>),
|
||||||
VkError(vk::Result),
|
VkError(vk::Result),
|
||||||
}
|
}
|
||||||
pub trait EntryV1_0{
|
pub trait EntryV1_0 {
|
||||||
|
type Fp: FunctionPointers;
|
||||||
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,
|
||||||
|
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);
|
||||||
|
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))?;
|
||||||
|
Ok(Instance::from_raw(instance, instance_fp))
|
||||||
|
}
|
||||||
|
}
|
||||||
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().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 mut v = Vec::with_capacity(num as usize);
|
||||||
let err_code = self
|
let err_code = self.fp_v1_0()
|
||||||
.fp_v1_0()
|
|
||||||
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr());
|
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr());
|
||||||
v.set_len(num as usize);
|
v.set_len(num as usize);
|
||||||
match err_code {
|
match err_code {
|
||||||
|
@ -67,16 +84,13 @@ pub trait EntryV1_0{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enumerate_instance_extension_properties(&self)
|
fn enumerate_instance_extension_properties(&self) -> VkResult<Vec<vk::ExtensionProperties>> {
|
||||||
-> VkResult<Vec<vk::ExtensionProperties>> {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut num = 0;
|
let mut num = 0;
|
||||||
self
|
self.fp_v1_0()
|
||||||
.fp_v1_0()
|
|
||||||
.enumerate_instance_extension_properties(ptr::null(), &mut num, ptr::null_mut());
|
.enumerate_instance_extension_properties(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 = self
|
let err_code = self.fp_v1_0()
|
||||||
.fp_v1_0()
|
|
||||||
.enumerate_instance_extension_properties(ptr::null(), &mut num, data.as_mut_ptr());
|
.enumerate_instance_extension_properties(ptr::null(), &mut num, data.as_mut_ptr());
|
||||||
data.set_len(num as usize);
|
data.set_len(num as usize);
|
||||||
match err_code {
|
match err_code {
|
||||||
|
@ -87,40 +101,24 @@ pub trait EntryV1_0{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_instance_proc_addr(&self,
|
fn get_instance_proc_addr(&self,
|
||||||
instance: vk::Instance,
|
instance: vk::Instance,
|
||||||
p_name: *const vk::c_char)
|
p_name: *const vk::c_char)
|
||||||
-> vk::PFN_vkVoidFunction {
|
-> 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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EntryV1_0 for Entry<V1_0>{
|
impl EntryV1_0 for Entry<V1_0> {
|
||||||
fn fp_v1_0(&self) -> &vk::EntryFnV1_0{
|
type Fp = V1_0;
|
||||||
|
fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
|
||||||
self.entry_fn.fp_v1_0()
|
self.entry_fn.fp_v1_0()
|
||||||
}
|
}
|
||||||
fn static_fn(&self) -> &vk::StaticFn{
|
fn static_fn(&self) -> &vk::StaticFn {
|
||||||
&self.static_fn
|
&self.static_fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: FunctionPointers> Entry<V> {
|
impl<V: FunctionPointers> Entry<V> {
|
||||||
pub fn create_instance(&self,
|
|
||||||
create_info: &vk::InstanceCreateInfo,
|
|
||||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
|
||||||
-> Result<Instance<V>, InstanceError> {
|
|
||||||
unsafe {
|
|
||||||
let mut instance: vk::Instance = mem::uninitialized();
|
|
||||||
let err_code =
|
|
||||||
self.entry_fn.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 = V::InstanceFp::load(&self.static_fn, instance).map_err(|err| InstanceError::LoadError(err))?;
|
|
||||||
Ok(Instance::from_raw(instance, instance_fp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn new() -> Result<Entry<V>, LoadingError> {
|
pub fn new() -> Result<Entry<V>, LoadingError> {
|
||||||
let static_fn = match *VK_LIB {
|
let static_fn = match *VK_LIB {
|
||||||
Ok(ref lib) => {
|
Ok(ref lib) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue