Integration extensible versions
This commit is contained in:
parent
a95572af4a
commit
9e2d28b301
5 changed files with 93 additions and 56 deletions
|
@ -16,6 +16,7 @@ use ash::device::Device;
|
|||
use std::ptr;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ops::Drop;
|
||||
use ash::instance::InstanceMajor1Minor0;
|
||||
|
||||
// Simple offset_of macro akin to C++ offsetof
|
||||
#[macro_export]
|
||||
|
|
|
@ -2,7 +2,7 @@ use prelude::*;
|
|||
use std::mem;
|
||||
use std::ptr;
|
||||
use vk;
|
||||
use instance::Instance;
|
||||
use instance::{Instance, V1_0, InstanceFpV1_0};
|
||||
use shared_library::dynamic_library::DynamicLibrary;
|
||||
use std::path::Path;
|
||||
use ::RawPtr;
|
||||
|
@ -73,7 +73,7 @@ impl Entry {
|
|||
pub fn create_instance(&self,
|
||||
create_info: &vk::InstanceCreateInfo,
|
||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||
-> Result<Instance, InstanceError> {
|
||||
-> Result<Instance<V1_0>, InstanceError> {
|
||||
unsafe {
|
||||
let mut instance: vk::Instance = mem::uninitialized();
|
||||
let err_code = self.entry_fn.create_instance(create_info,
|
||||
|
@ -85,7 +85,7 @@ impl Entry {
|
|||
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, instance_fn))
|
||||
Ok(Instance::from_raw(instance, InstanceFpV1_0 { instance_fn: instance_fn }))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
pub use self::swapchain::Swapchain;
|
||||
pub use self::surface::Surface;
|
||||
pub use self::xlib_surface::XlibSurface;
|
||||
pub use self::debug_report::DebugReport;
|
||||
pub use self::win32_surface::Win32Surface;
|
||||
pub use self::mir_surface::MirSurface;
|
||||
pub use self::xcb_surface::XcbSurface;
|
||||
pub use self::wayland_surface::WaylandSurface;
|
||||
pub use self::android_surface::AndroidSurface;
|
||||
|
||||
mod swapchain;
|
||||
mod surface;
|
||||
mod xlib_surface;
|
||||
mod win32_surface;
|
||||
mod debug_report;
|
||||
mod mir_surface;
|
||||
mod android_surface;
|
||||
mod wayland_surface;
|
||||
mod xcb_surface;
|
||||
//pub use self::swapchain::Swapchain;
|
||||
//pub use self::surface::Surface;
|
||||
//pub use self::xlib_surface::XlibSurface;
|
||||
//pub use self::debug_report::DebugReport;
|
||||
//pub use self::win32_surface::Win32Surface;
|
||||
//pub use self::mir_surface::MirSurface;
|
||||
//pub use self::xcb_surface::XcbSurface;
|
||||
//pub use self::wayland_surface::WaylandSurface;
|
||||
//pub use self::android_surface::AndroidSurface;
|
||||
//
|
||||
//mod swapchain;
|
||||
//mod surface;
|
||||
//mod xlib_surface;
|
||||
//mod win32_surface;
|
||||
//mod debug_report;
|
||||
//mod mir_surface;
|
||||
//mod android_surface;
|
||||
//mod wayland_surface;
|
||||
//mod xcb_surface;
|
||||
|
|
|
@ -6,6 +6,7 @@ use device::Device;
|
|||
use vk;
|
||||
use std::ffi::CStr;
|
||||
use ::RawPtr;
|
||||
use instance::InstanceMajor1Minor0;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Swapchain {
|
||||
|
|
103
src/instance.rs
103
src/instance.rs
|
@ -12,31 +12,63 @@ pub enum DeviceError {
|
|||
VkError(vk::Result),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Instance {
|
||||
handle: vk::Instance,
|
||||
instance_fn: vk::InstanceFn,
|
||||
pub trait VkVersion{
|
||||
type InstanceFp;
|
||||
type DeviceFp;
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
#[warn(non_camel_case_types)]
|
||||
pub struct V1_0;
|
||||
impl VkVersion for V1_0{
|
||||
type InstanceFp = InstanceFpV1_0;
|
||||
type DeviceFp = ();
|
||||
}
|
||||
|
||||
#[warn(non_camel_case_types)]
|
||||
pub struct InstanceFpV1_0{
|
||||
pub instance_fn: vk::InstanceFn
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Instance<V: VkVersion> {
|
||||
handle: vk::Instance,
|
||||
instance_fp: V::InstanceFp
|
||||
}
|
||||
|
||||
impl InstanceV1_0 for Instance<V1_0>{
|
||||
fn handle(&self) -> vk::Instance{
|
||||
self.handle
|
||||
}
|
||||
|
||||
fn fp_v1_0(&self) -> &vk::InstanceFn{
|
||||
&self.instance_fp.instance_fn
|
||||
}
|
||||
}
|
||||
impl<V: VkVersion> Instance<V> {
|
||||
pub fn handle(&self) -> vk::Instance {
|
||||
self.handle
|
||||
}
|
||||
|
||||
pub fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
|
||||
pub fn from_raw(handle: vk::Instance, version: V::InstanceFp) -> Self {
|
||||
Instance {
|
||||
handle: handle,
|
||||
instance_fn: instance_fn,
|
||||
instance_fp: version
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn create_device(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
create_info: &vk::DeviceCreateInfo,
|
||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||
-> Result<Device, DeviceError> {
|
||||
}
|
||||
|
||||
#[warn(non_camel_case_types)]
|
||||
pub trait InstanceV1_0 {
|
||||
fn handle(&self) -> vk::Instance;
|
||||
fn fp_v1_0(&self) -> &vk::InstanceFn;
|
||||
unsafe fn create_device(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
create_info: &vk::DeviceCreateInfo,
|
||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||
-> Result<Device, DeviceError> {
|
||||
let mut device: vk::Device = mem::uninitialized();
|
||||
let err_code = self.instance_fn
|
||||
let err_code = self.fp_v1_0()
|
||||
.create_device(physical_device,
|
||||
create_info,
|
||||
allocation_callbacks.as_raw_ptr(),
|
||||
|
@ -45,55 +77,54 @@ impl Instance {
|
|||
return Err(DeviceError::VkError(err_code));
|
||||
}
|
||||
let device_fn = vk::DeviceFn::load(|name| {
|
||||
mem::transmute(self.instance_fn.get_device_proc_addr(device, name.as_ptr()))
|
||||
mem::transmute(self.fp_v1_0().get_device_proc_addr(device, name.as_ptr()))
|
||||
}).map_err(|err| DeviceError::LoadError(err))?;
|
||||
Ok(Device::from_raw(device, device_fn))
|
||||
}
|
||||
|
||||
pub fn get_device_proc_addr(&self,
|
||||
fn get_device_proc_addr(&self,
|
||||
device: vk::Device,
|
||||
p_name: *const vk::c_char)
|
||||
-> vk::PFN_vkVoidFunction {
|
||||
unsafe { self.instance_fn.get_device_proc_addr(device, p_name) }
|
||||
unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) }
|
||||
}
|
||||
|
||||
pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||
self.instance_fn.destroy_instance(self.handle, allocation_callbacks.as_raw_ptr());
|
||||
unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
|
||||
self.fp_v1_0().destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr());
|
||||
}
|
||||
|
||||
pub fn get_physical_device_format_properties(&self,
|
||||
fn get_physical_device_format_properties(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
format: vk::Format)
|
||||
-> vk::FormatProperties {
|
||||
unsafe {
|
||||
let mut format_prop = mem::uninitialized();
|
||||
self.instance_fn
|
||||
self.fp_v1_0()
|
||||
.get_physical_device_format_properties(physical_device, format, &mut format_prop);
|
||||
format_prop
|
||||
}
|
||||
}
|
||||
pub fn get_physical_device_memory_properties(&self,
|
||||
fn get_physical_device_memory_properties(&self,
|
||||
physical_device: vk::PhysicalDevice)
|
||||
-> vk::PhysicalDeviceMemoryProperties {
|
||||
unsafe {
|
||||
let mut memory_prop = mem::uninitialized();
|
||||
self.instance_fn
|
||||
self.fp_v1_0()
|
||||
.get_physical_device_memory_properties(physical_device, &mut memory_prop);
|
||||
memory_prop
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_queue_family_properties(&self,
|
||||
fn get_physical_device_queue_family_properties(&self,
|
||||
physical_device: vk::PhysicalDevice)
|
||||
-> Vec<vk::QueueFamilyProperties> {
|
||||
unsafe {
|
||||
let mut queue_count = 0;
|
||||
self.instance_fn
|
||||
self.fp_v1_0()
|
||||
.get_physical_device_queue_family_properties(physical_device,
|
||||
&mut queue_count,
|
||||
ptr::null_mut());
|
||||
let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
|
||||
self.instance_fn
|
||||
self.fp_v1_0()
|
||||
.get_physical_device_queue_family_properties(physical_device,
|
||||
&mut queue_count,
|
||||
queue_families_vec.as_mut_ptr());
|
||||
|
@ -102,14 +133,14 @@ impl Instance {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
|
||||
fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
|
||||
unsafe {
|
||||
let mut num = mem::uninitialized();
|
||||
self.instance_fn
|
||||
.enumerate_physical_devices(self.handle, &mut num, ptr::null_mut());
|
||||
self.fp_v1_0()
|
||||
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut());
|
||||
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
|
||||
let err_code = self.instance_fn
|
||||
.enumerate_physical_devices(self.handle, &mut num, physical_devices.as_mut_ptr());
|
||||
let err_code = self.fp_v1_0()
|
||||
.enumerate_physical_devices(self.handle(), &mut num, physical_devices.as_mut_ptr());
|
||||
physical_devices.set_len(num as usize);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(physical_devices),
|
||||
|
@ -118,19 +149,19 @@ impl Instance {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn enumerate_device_extension_properties
|
||||
fn enumerate_device_extension_properties
|
||||
(&self,
|
||||
device: vk::PhysicalDevice)
|
||||
-> Result<Vec<vk::ExtensionProperties>, vk::Result> {
|
||||
unsafe {
|
||||
let mut num = 0;
|
||||
self.instance_fn
|
||||
self.fp_v1_0()
|
||||
.enumerate_device_extension_properties(device,
|
||||
ptr::null(),
|
||||
&mut num,
|
||||
ptr::null_mut());
|
||||
let mut data = Vec::with_capacity(num as usize);
|
||||
let err_code = self.instance_fn
|
||||
let err_code = self.fp_v1_0()
|
||||
.enumerate_device_extension_properties(device,
|
||||
ptr::null(),
|
||||
&mut num,
|
||||
|
@ -143,3 +174,7 @@ impl Instance {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pub trait InstanceMajor1Minor1: InstanceMajor1Minor0 {}
|
||||
//pub trait InstanceMajor1Minor2: InstanceMajor1Minor1 {}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue