create_device as default impl
This commit is contained in:
parent
61b574bcdf
commit
aaff6c2383
1 changed files with 15 additions and 16 deletions
|
@ -8,14 +8,12 @@ use ::RawPtr;
|
||||||
use version::{FunctionPointers, V1_0, InstanceFpV1_0, DeviceFpV1_0};
|
use version::{FunctionPointers, V1_0, InstanceFpV1_0, DeviceFpV1_0};
|
||||||
use version::{InstanceLoader, DeviceLoader};
|
use version::{InstanceLoader, DeviceLoader};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DeviceError {
|
pub enum DeviceError {
|
||||||
LoadError(Vec<&'static str>),
|
LoadError(Vec<&'static str>),
|
||||||
VkError(vk::Result),
|
VkError(vk::Result),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Instance<V: FunctionPointers> {
|
pub struct Instance<V: FunctionPointers> {
|
||||||
handle: vk::Instance,
|
handle: vk::Instance,
|
||||||
|
@ -23,6 +21,7 @@ pub struct Instance<V: FunctionPointers> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InstanceV1_0 for Instance<V1_0> {
|
impl InstanceV1_0 for Instance<V1_0> {
|
||||||
|
type Fp = V1_0;
|
||||||
fn handle(&self) -> vk::Instance {
|
fn handle(&self) -> vk::Instance {
|
||||||
self.handle
|
self.handle
|
||||||
}
|
}
|
||||||
|
@ -44,15 +43,18 @@ impl<V: FunctionPointers> Instance<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: FunctionPointers> Instance<V> {
|
#[warn(non_camel_case_types)]
|
||||||
pub unsafe fn create_device(&self,
|
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,
|
physical_device: vk::PhysicalDevice,
|
||||||
create_info: &vk::DeviceCreateInfo,
|
create_info: &vk::DeviceCreateInfo,
|
||||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
-> Result<Device<V>, DeviceError> {
|
-> Result<Device<Self::Fp>, DeviceError> {
|
||||||
let mut device: vk::Device = mem::uninitialized();
|
let mut device: vk::Device = mem::uninitialized();
|
||||||
let err_code = self.instance_fp
|
let err_code = self.fp_v1_0()
|
||||||
.fp_v1_0()
|
|
||||||
.create_device(physical_device,
|
.create_device(physical_device,
|
||||||
create_info,
|
create_info,
|
||||||
allocation_callbacks.as_raw_ptr(),
|
allocation_callbacks.as_raw_ptr(),
|
||||||
|
@ -60,15 +62,11 @@ impl<V: FunctionPointers> Instance<V> {
|
||||||
if err_code != vk::Result::Success {
|
if err_code != vk::Result::Success {
|
||||||
return Err(DeviceError::VkError(err_code));
|
return Err(DeviceError::VkError(err_code));
|
||||||
}
|
}
|
||||||
let device_fn = V::DeviceFp::load(self.instance_fp.fp_v1_0(), device).map_err(|err| DeviceError::LoadError(err))?;
|
let device_fn =
|
||||||
|
<<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))
|
Ok(Device::from_raw(device, device_fn))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[warn(non_camel_case_types)]
|
|
||||||
pub trait InstanceV1_0 {
|
|
||||||
fn handle(&self) -> vk::Instance;
|
|
||||||
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0;
|
|
||||||
fn get_device_proc_addr(&self,
|
fn get_device_proc_addr(&self,
|
||||||
device: vk::Device,
|
device: vk::Device,
|
||||||
p_name: *const vk::c_char)
|
p_name: *const vk::c_char)
|
||||||
|
@ -91,6 +89,7 @@ pub trait InstanceV1_0 {
|
||||||
format_prop
|
format_prop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_physical_device_memory_properties(&self,
|
fn get_physical_device_memory_properties(&self,
|
||||||
physical_device: vk::PhysicalDevice)
|
physical_device: vk::PhysicalDevice)
|
||||||
-> vk::PhysicalDeviceMemoryProperties {
|
-> vk::PhysicalDeviceMemoryProperties {
|
||||||
|
|
Loading…
Add table
Reference in a new issue