Swtich device to the new extension version format
This commit is contained in:
parent
d964453d2d
commit
45936ae6bb
|
@ -16,7 +16,8 @@ use ash::device::Device;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use ash::instance::{V1_0, InstanceV1_0};
|
pub use ash::instance::{V1_0, InstanceV1_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]
|
||||||
|
@ -32,7 +33,7 @@ macro_rules! offset_of{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(device: &Device,
|
pub fn record_submit_commandbuffer<F: FnOnce(&Device<V1_0>, vk::CommandBuffer)>(device: &Device<V1_0>,
|
||||||
command_buffer: vk::CommandBuffer,
|
command_buffer: vk::CommandBuffer,
|
||||||
submit_queue: vk::Queue,
|
submit_queue: vk::Queue,
|
||||||
wait_mask: &[vk::PipelineStageFlags],
|
wait_mask: &[vk::PipelineStageFlags],
|
||||||
|
@ -188,7 +189,7 @@ fn resize_callback(width: u32, height: u32) {
|
||||||
pub struct ExampleBase {
|
pub struct ExampleBase {
|
||||||
pub entry: Entry,
|
pub entry: Entry,
|
||||||
pub instance: Instance<V1_0>,
|
pub instance: Instance<V1_0>,
|
||||||
pub device: Device,
|
pub device: Device<V1_0>,
|
||||||
pub surface_loader: Surface,
|
pub surface_loader: Surface,
|
||||||
pub swapchain_loader: Swapchain,
|
pub swapchain_loader: Swapchain,
|
||||||
pub debug_report_loader: DebugReport,
|
pub debug_report_loader: DebugReport,
|
||||||
|
@ -334,7 +335,7 @@ impl ExampleBase {
|
||||||
pp_enabled_extension_names: device_extension_names_raw.as_ptr(),
|
pp_enabled_extension_names: device_extension_names_raw.as_ptr(),
|
||||||
p_enabled_features: &features,
|
p_enabled_features: &features,
|
||||||
};
|
};
|
||||||
let device: Device = instance.create_device(pdevice, &device_create_info, None)
|
let device: Device<V1_0> = instance.create_device(pdevice, &device_create_info, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let present_queue = device.get_device_queue(queue_family_index as u32, 0);
|
let present_queue = device.get_device_queue(queue_family_index as u32, 0);
|
||||||
|
|
||||||
|
|
729
src/device.rs
729
src/device.rs
File diff suppressed because it is too large
Load diff
|
@ -15,7 +15,7 @@ pub struct Swapchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Swapchain {
|
impl Swapchain {
|
||||||
pub fn new(instance: &Instance<V1_0>, device: &Device) -> Result<Swapchain, Vec<&'static str>> {
|
pub fn new(instance: &Instance<V1_0>, device: &Device<V1_0>) -> Result<Swapchain, Vec<&'static str>> {
|
||||||
let swapchain_fn = vk::SwapchainFn::load(|name| {
|
let swapchain_fn = vk::SwapchainFn::load(|name| {
|
||||||
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
|
unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct Win32Surface {
|
||||||
win32_surface_fn: vk::Win32SurfaceFn,
|
win32_surface_fn: vk::Win32SurfaceFn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Win32Surface {
|
impl Win32Surface {
|
||||||
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<Win32Surface, Vec<&'static str>> {
|
pub fn new(entry: &Entry, instance: &Instance<V1_0>) -> Result<Win32Surface, Vec<&'static str>> {
|
||||||
let surface_fn = vk::Win32SurfaceFn::load(|name| {
|
let surface_fn = vk::Win32SurfaceFn::load(|name| {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use prelude::*;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use vk;
|
use vk;
|
||||||
use device::Device;
|
use device::{Device, DeviceFpV1_0};
|
||||||
use ::RawPtr;
|
use ::RawPtr;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -12,36 +12,35 @@ pub enum DeviceError {
|
||||||
VkError(vk::Result),
|
VkError(vk::Result),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VkVersion{
|
pub trait VkVersion {
|
||||||
type InstanceFp;
|
type InstanceFp;
|
||||||
type DeviceFp;
|
type DeviceFp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[warn(non_camel_case_types)]
|
#[warn(non_camel_case_types)]
|
||||||
pub struct V1_0;
|
pub struct V1_0;
|
||||||
impl VkVersion for V1_0{
|
impl VkVersion for V1_0 {
|
||||||
type InstanceFp = InstanceFpV1_0;
|
type InstanceFp = InstanceFpV1_0;
|
||||||
type DeviceFp = ();
|
type DeviceFp = DeviceFpV1_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[warn(non_camel_case_types)]
|
#[warn(non_camel_case_types)]
|
||||||
pub struct InstanceFpV1_0{
|
pub struct InstanceFpV1_0 {
|
||||||
pub instance_fn: vk::InstanceFn
|
pub instance_fn: vk::InstanceFn,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Instance<V: VkVersion> {
|
pub struct Instance<V: VkVersion> {
|
||||||
handle: vk::Instance,
|
handle: vk::Instance,
|
||||||
instance_fp: V::InstanceFp
|
instance_fp: V::InstanceFp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InstanceV1_0 for Instance<V1_0>{
|
impl InstanceV1_0 for Instance<V1_0> {
|
||||||
fn handle(&self) -> vk::Instance{
|
fn handle(&self) -> vk::Instance {
|
||||||
self.handle
|
self.handle
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fp_v1_0(&self) -> &vk::InstanceFn{
|
fn fp_v1_0(&self) -> &vk::InstanceFn {
|
||||||
&self.instance_fp.instance_fn
|
&self.instance_fp.instance_fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,21 +52,17 @@ impl<V: VkVersion> Instance<V> {
|
||||||
pub fn from_raw(handle: vk::Instance, version: V::InstanceFp) -> Self {
|
pub fn from_raw(handle: vk::Instance, version: V::InstanceFp) -> Self {
|
||||||
Instance {
|
Instance {
|
||||||
handle: handle,
|
handle: handle,
|
||||||
instance_fp: version
|
instance_fp: version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[warn(non_camel_case_types)]
|
impl Instance<V1_0> {
|
||||||
pub trait InstanceV1_0 {
|
pub unsafe fn create_device(&self,
|
||||||
fn handle(&self) -> vk::Instance;
|
physical_device: vk::PhysicalDevice,
|
||||||
fn fp_v1_0(&self) -> &vk::InstanceFn;
|
create_info: &vk::DeviceCreateInfo,
|
||||||
unsafe fn create_device(&self,
|
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
||||||
physical_device: vk::PhysicalDevice,
|
-> Result<Device<V1_0>, DeviceError> {
|
||||||
create_info: &vk::DeviceCreateInfo,
|
|
||||||
allocation_callbacks: Option<&vk::AllocationCallbacks>)
|
|
||||||
-> Result<Device, DeviceError> {
|
|
||||||
let mut device: vk::Device = mem::uninitialized();
|
let mut device: vk::Device = mem::uninitialized();
|
||||||
let err_code = self.fp_v1_0()
|
let err_code = self.fp_v1_0()
|
||||||
.create_device(physical_device,
|
.create_device(physical_device,
|
||||||
|
@ -80,12 +75,18 @@ pub trait InstanceV1_0 {
|
||||||
let device_fn = vk::DeviceFn::load(|name| {
|
let device_fn = vk::DeviceFn::load(|name| {
|
||||||
mem::transmute(self.fp_v1_0().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))?;
|
}).map_err(|err| DeviceError::LoadError(err))?;
|
||||||
Ok(Device::from_raw(device, device_fn))
|
Ok(Device::from_raw(device, DeviceFpV1_0 { device_fn: device_fn }))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[warn(non_camel_case_types)]
|
||||||
|
pub trait InstanceV1_0 {
|
||||||
|
fn handle(&self) -> vk::Instance;
|
||||||
|
fn fp_v1_0(&self) -> &vk::InstanceFn;
|
||||||
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)
|
||||||
-> vk::PFN_vkVoidFunction {
|
-> vk::PFN_vkVoidFunction {
|
||||||
unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) }
|
unsafe { self.fp_v1_0().get_device_proc_addr(device, p_name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +95,9 @@ pub trait InstanceV1_0 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_physical_device_format_properties(&self,
|
fn get_physical_device_format_properties(&self,
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
format: vk::Format)
|
format: vk::Format)
|
||||||
-> vk::FormatProperties {
|
-> vk::FormatProperties {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut format_prop = mem::uninitialized();
|
let mut format_prop = mem::uninitialized();
|
||||||
self.fp_v1_0()
|
self.fp_v1_0()
|
||||||
|
@ -105,8 +106,8 @@ pub trait InstanceV1_0 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut memory_prop = mem::uninitialized();
|
let mut memory_prop = mem::uninitialized();
|
||||||
self.fp_v1_0()
|
self.fp_v1_0()
|
||||||
|
@ -116,8 +117,8 @@ pub trait InstanceV1_0 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_physical_device_queue_family_properties(&self,
|
fn get_physical_device_queue_family_properties(&self,
|
||||||
physical_device: vk::PhysicalDevice)
|
physical_device: vk::PhysicalDevice)
|
||||||
-> Vec<vk::QueueFamilyProperties> {
|
-> Vec<vk::QueueFamilyProperties> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut queue_count = 0;
|
let mut queue_count = 0;
|
||||||
self.fp_v1_0()
|
self.fp_v1_0()
|
||||||
|
@ -176,6 +177,5 @@ pub trait InstanceV1_0 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub trait InstanceMajor1Minor1: InstanceMajor1Minor0 {}
|
// pub trait InstanceMajor1Minor1: InstanceMajor1Minor0 {}
|
||||||
//pub trait InstanceMajor1Minor2: InstanceMajor1Minor1 {}
|
// pub trait InstanceMajor1Minor2: InstanceMajor1Minor1 {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue