Impl trait functions directly on EntryCustom/Instance/Device (#412)

* Implement EntryV1_x, InstanceV1_x, DeviceV1_x functions directly
This commit is contained in:
Rua 2021-04-30 17:13:23 +02:00 committed by GitHub
parent 3fe13fafa6
commit f5e7cfe896
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 729 additions and 764 deletions

View file

@ -5,7 +5,7 @@
//! //!
//! On instance extensions platform specific extensions need to be enabled. //! On instance extensions platform specific extensions need to be enabled.
use ash::{version::EntryV1_0, vk}; use ash::vk;
use std::error::Error; use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {

View file

@ -1,9 +1,4 @@
use ash::{ use ash::{extensions::khr, prelude::*, vk, EntryCustom, Instance};
extensions::khr,
prelude::*,
version::{EntryV1_0, InstanceV1_0},
vk,
};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::ffi::CStr; use std::ffi::CStr;
@ -19,16 +14,12 @@ use ash::extensions::ext; // portability extensions
/// In order for the created `SurfaceKHR` to be valid for the duration of its /// In order for the created `SurfaceKHR` to be valid for the duration of its
/// usage, the `Instance` this was called on must be dropped later than the /// usage, the `Instance` this was called on must be dropped later than the
/// resulting `SurfaceKHR`. /// resulting `SurfaceKHR`.
pub unsafe fn create_surface<E, I>( pub unsafe fn create_surface<L>(
entry: &E, entry: &EntryCustom<L>,
instance: &I, instance: &Instance,
window_handle: &dyn HasRawWindowHandle, window_handle: &dyn HasRawWindowHandle,
allocation_callbacks: Option<&vk::AllocationCallbacks>, allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> ) -> VkResult<vk::SurfaceKHR> {
where
E: EntryV1_0,
I: InstanceV1_0,
{
match window_handle.raw_window_handle() { match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
RawWindowHandle::Windows(handle) => { RawWindowHandle::Windows(handle) => {

File diff suppressed because it is too large Load diff

View file

@ -20,149 +20,8 @@ pub struct EntryCustom<L> {
lib: L, lib: L,
} }
#[derive(Clone, Debug)] /// Vulkan core 1.0
pub enum InstanceError {
LoadError(Vec<&'static str>),
VkError(vk::Result),
}
impl fmt::Display for InstanceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InstanceError::LoadError(e) => write!(f, "{}", e.join("; ")),
InstanceError::VkError(e) => write!(f, "{}", e),
}
}
}
impl Error for InstanceError {}
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub trait EntryV1_0 {
type Instance;
fn fp_v1_0(&self) -> &vk::EntryFnV1_0;
fn static_fn(&self) -> &vk::StaticFn;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateInstance.html>"]
///
/// # Safety
/// In order for the created `Instance` to be valid for the duration of its
/// usage, the `Entry` this was called on must be dropped later than the
/// resulting `Instance`.
unsafe fn create_instance(
&self,
create_info: &vk::InstanceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Self::Instance, InstanceError>;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceLayerProperties.html>"]
fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
unsafe {
let mut num = 0;
self.fp_v1_0()
.enumerate_instance_layer_properties(&mut num, ptr::null_mut())
.result()?;
let mut v = Vec::with_capacity(num as usize);
let err_code = self
.fp_v1_0()
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr());
v.set_len(num as usize);
err_code.result_with_success(v)
}
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceExtensionProperties.html>"]
fn enumerate_instance_extension_properties(&self) -> VkResult<Vec<vk::ExtensionProperties>> {
unsafe {
let mut num = 0;
self.fp_v1_0()
.enumerate_instance_extension_properties(ptr::null(), &mut num, ptr::null_mut())
.result()?;
let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_instance_extension_properties(
ptr::null(),
&mut num,
data.as_mut_ptr(),
);
data.set_len(num as usize);
err_code.result_with_success(data)
}
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetInstanceProcAddr.html>"]
unsafe fn get_instance_proc_addr(
&self,
instance: vk::Instance,
p_name: *const c_char,
) -> vk::PFN_vkVoidFunction {
self.static_fn().get_instance_proc_addr(instance, p_name)
}
}
impl<L> EntryV1_0 for EntryCustom<L> {
type Instance = Instance;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateInstance.html>"]
///
/// # Safety
/// In order for the created `Instance` to be valid for the duration of its
/// usage, the `Entry` this was called on must be dropped later than the
/// resulting `Instance`.
unsafe fn create_instance(
&self,
create_info: &vk::InstanceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Self::Instance, InstanceError> {
let mut instance: vk::Instance = mem::zeroed();
self.fp_v1_0()
.create_instance(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
)
.result()
.map_err(InstanceError::VkError)?;
Ok(Instance::load(&self.static_fn, instance))
}
fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
&self.entry_fn_1_0
}
fn static_fn(&self) -> &vk::StaticFn {
&self.static_fn
}
}
#[allow(non_camel_case_types)]
pub trait EntryV1_1: EntryV1_0 {
fn fp_v1_1(&self) -> &vk::EntryFnV1_1;
#[deprecated = "This function is unavailable and therefore panics on Vulkan 1.0, please use `try_enumerate_instance_version` instead"]
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceVersion.html>"]
fn enumerate_instance_version(&self) -> VkResult<u32> {
unsafe {
let mut api_version = 0;
self.fp_v1_1()
.enumerate_instance_version(&mut api_version)
.result_with_success(api_version)
}
}
}
impl<L> EntryV1_1 for EntryCustom<L> {
fn fp_v1_1(&self) -> &vk::EntryFnV1_1 {
&self.entry_fn_1_1
}
}
#[allow(non_camel_case_types)]
pub trait EntryV1_2: EntryV1_1 {
fn fp_v1_2(&self) -> &vk::EntryFnV1_2;
}
impl<L> EntryV1_2 for EntryCustom<L> {
fn fp_v1_2(&self) -> &vk::EntryFnV1_2 {
&self.entry_fn_1_2
}
}
impl<L> EntryCustom<L> { impl<L> EntryCustom<L> {
pub fn new_custom<Load>( pub fn new_custom<Load>(
mut lib: L, mut lib: L,
@ -173,18 +32,12 @@ impl<L> EntryCustom<L> {
{ {
// Bypass the normal StaticFn::load so we can return an error // Bypass the normal StaticFn::load so we can return an error
let static_fn = vk::StaticFn::load_checked(|name| load(&mut lib, name))?; let static_fn = vk::StaticFn::load_checked(|name| load(&mut lib, name))?;
let load_fn = |name: &std::ffi::CStr| unsafe {
let entry_fn_1_0 = vk::EntryFnV1_0::load(|name| unsafe {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr())) mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
}); };
let entry_fn_1_0 = vk::EntryFnV1_0::load(load_fn);
let entry_fn_1_1 = vk::EntryFnV1_1::load(|name| unsafe { let entry_fn_1_1 = vk::EntryFnV1_1::load(load_fn);
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr())) let entry_fn_1_2 = vk::EntryFnV1_2::load(load_fn);
});
let entry_fn_1_2 = vk::EntryFnV1_2::load(|name| unsafe {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
});
Ok(EntryCustom { Ok(EntryCustom {
static_fn, static_fn,
@ -195,6 +48,14 @@ impl<L> EntryCustom<L> {
}) })
} }
pub fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
&self.entry_fn_1_0
}
pub fn static_fn(&self) -> &vk::StaticFn {
&self.static_fn
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceVersion.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceVersion.html>"]
/// ```no_run /// ```no_run
/// # use ash::{Entry, vk}; /// # use ash::{Entry, vk};
@ -218,7 +79,7 @@ impl<L> EntryCustom<L> {
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = { let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
let name = b"vkEnumerateInstanceVersion\0".as_ptr() as *const _; let name = b"vkEnumerateInstanceVersion\0".as_ptr() as *const _;
mem::transmute( mem::transmute(
self.static_fn() self.static_fn
.get_instance_proc_addr(vk::Instance::null(), name), .get_instance_proc_addr(vk::Instance::null(), name),
) )
}; };
@ -230,8 +91,120 @@ impl<L> EntryCustom<L> {
} }
} }
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateInstance.html>"]
///
/// # Safety
/// In order for the created `Instance` to be valid for the duration of its
/// usage, the `Entry` this was called on must be dropped later than the
/// resulting `Instance`.
pub unsafe fn create_instance(
&self,
create_info: &vk::InstanceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Instance, InstanceError> {
let mut instance: vk::Instance = mem::zeroed();
self.entry_fn_1_0
.create_instance(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
)
.result()
.map_err(InstanceError::VkError)?;
Ok(Instance::load(&self.static_fn, instance))
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceLayerProperties.html>"]
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
unsafe {
let mut num = 0;
self.entry_fn_1_0
.enumerate_instance_layer_properties(&mut num, ptr::null_mut())
.result()?;
let mut v = Vec::with_capacity(num as usize);
let err_code = self
.entry_fn_1_0
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr());
v.set_len(num as usize);
err_code.result_with_success(v)
}
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceExtensionProperties.html>"]
pub fn enumerate_instance_extension_properties(
&self,
) -> VkResult<Vec<vk::ExtensionProperties>> {
unsafe {
let mut num = 0;
self.entry_fn_1_0
.enumerate_instance_extension_properties(ptr::null(), &mut num, ptr::null_mut())
.result()?;
let mut data = Vec::with_capacity(num as usize);
let err_code = self.entry_fn_1_0.enumerate_instance_extension_properties(
ptr::null(),
&mut num,
data.as_mut_ptr(),
);
data.set_len(num as usize);
err_code.result_with_success(data)
}
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetInstanceProcAddr.html>"]
pub unsafe fn get_instance_proc_addr(
&self,
instance: vk::Instance,
p_name: *const c_char,
) -> vk::PFN_vkVoidFunction {
self.static_fn.get_instance_proc_addr(instance, p_name)
}
} }
/// Vulkan core 1.1
#[allow(non_camel_case_types)]
impl<L> EntryCustom<L> {
pub fn fp_v1_1(&self) -> &vk::EntryFnV1_1 {
&self.entry_fn_1_1
}
#[deprecated = "This function is unavailable and therefore panics on Vulkan 1.0, please use `try_enumerate_instance_version` instead"]
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceVersion.html>"]
pub fn enumerate_instance_version(&self) -> VkResult<u32> {
unsafe {
let mut api_version = 0;
self.entry_fn_1_1
.enumerate_instance_version(&mut api_version)
.result_with_success(api_version)
}
}
}
/// Vulkan core 1.2
#[allow(non_camel_case_types)]
impl<L> EntryCustom<L> {
pub fn fp_v1_2(&self) -> &vk::EntryFnV1_2 {
&self.entry_fn_1_2
}
}
#[derive(Clone, Debug)]
pub enum InstanceError {
LoadError(Vec<&'static str>),
VkError(vk::Result),
}
impl fmt::Display for InstanceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InstanceError::LoadError(e) => write!(f, "{}", e.join("; ")),
InstanceError::VkError(e) => write!(f, "{}", e),
}
}
}
impl Error for InstanceError {}
impl vk::StaticFn { impl vk::StaticFn {
pub fn load_checked<F>(mut _f: F) -> Result<Self, MissingEntryPoint> pub fn load_checked<F>(mut _f: F) -> Result<Self, MissingEntryPoint>
where where

View file

@ -63,7 +63,7 @@ impl EntryCustom<Arc<Library>> {
/// for [`Library::new`] and [`Library::get`] apply here. /// for [`Library::new`] and [`Library::get`] apply here.
/// ///
/// ```no_run /// ```no_run
/// use ash::{vk, Entry, version::EntryV1_0}; /// use ash::{vk, Entry};
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let entry = unsafe { Entry::new() }?; /// let entry = unsafe { Entry::new() }?;
/// let app_info = vk::ApplicationInfo { /// let app_info = vk::ApplicationInfo {

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct BufferDeviceAddress {
} }
impl BufferDeviceAddress { impl BufferDeviceAddress {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let fns = vk::ExtBufferDeviceAddressFn::load(|name| unsafe { let fns = vk::ExtBufferDeviceAddressFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct DebugMarker {
} }
impl DebugMarker { impl DebugMarker {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let debug_marker_fn = vk::ExtDebugMarkerFn::load(|name| unsafe { let debug_marker_fn = vk::ExtDebugMarkerFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct DebugReport {
} }
impl DebugReport { impl DebugReport {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let debug_report_fn = vk::ExtDebugReportFn::load(|name| unsafe { let debug_report_fn = vk::ExtDebugReportFn::load(|name| 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()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::{vk, RawPtr}; use crate::{vk, RawPtr};
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -12,7 +12,7 @@ pub struct DebugUtils {
} }
impl DebugUtils { impl DebugUtils {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let debug_utils_fn = vk::ExtDebugUtilsFn::load(|name| unsafe { let debug_utils_fn = vk::ExtDebugUtilsFn::load(|name| 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()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -12,7 +12,7 @@ pub struct ExtendedDynamicState {
} }
impl ExtendedDynamicState { impl ExtendedDynamicState {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let extended_dynamic_state_fn = vk::ExtExtendedDynamicStateFn::load(|name| unsafe { let extended_dynamic_state_fn = vk::ExtExtendedDynamicStateFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -13,7 +13,7 @@ pub struct FullScreenExclusive {
} }
impl FullScreenExclusive { impl FullScreenExclusive {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let full_screen_exclusive_fn = vk::ExtFullScreenExclusiveFn::load(|name| unsafe { let full_screen_exclusive_fn = vk::ExtFullScreenExclusiveFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct MetalSurface {
} }
impl MetalSurface { impl MetalSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::ExtMetalSurfaceFn::load(|name| unsafe { let surface_fn = vk::ExtMetalSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -13,7 +13,7 @@ pub struct ToolingInfo {
} }
impl ToolingInfo { impl ToolingInfo {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let tooling_info_fn = vk::ExtToolingInfoFn::load(|name| unsafe { let tooling_info_fn = vk::ExtToolingInfoFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct AccelerationStructure {
} }
impl AccelerationStructure { impl AccelerationStructure {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let acceleration_structure_fn = vk::KhrAccelerationStructureFn::load(|name| unsafe { let acceleration_structure_fn = vk::KhrAccelerationStructureFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });
@ -23,8 +23,8 @@ impl AccelerationStructure {
} }
} }
pub unsafe fn get_properties<I: InstanceV1_1>( pub unsafe fn get_properties(
instance: &I, instance: &Instance,
pdevice: vk::PhysicalDevice, pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceAccelerationStructurePropertiesKHR { ) -> vk::PhysicalDeviceAccelerationStructurePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default(); let mut props_rt = vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default();

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct AndroidSurface {
} }
impl AndroidSurface { impl AndroidSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrAndroidSurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrAndroidSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct BufferDeviceAddress {
} }
impl BufferDeviceAddress { impl BufferDeviceAddress {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let fns = vk::KhrBufferDeviceAddressFn::load(|name| unsafe { let fns = vk::KhrBufferDeviceAddressFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct CreateRenderPass2 {
} }
impl CreateRenderPass2 { impl CreateRenderPass2 {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let khr_create_renderpass2_fn = vk::KhrCreateRenderpass2Fn::load(|name| unsafe { let khr_create_renderpass2_fn = vk::KhrCreateRenderpass2Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct DeferredHostOperations {
} }
impl DeferredHostOperations { impl DeferredHostOperations {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let deferred_host_operations_fn = vk::KhrDeferredHostOperationsFn::load(|name| unsafe { let deferred_host_operations_fn = vk::KhrDeferredHostOperationsFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -13,7 +13,7 @@ pub struct Display {
} }
impl Display { impl Display {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let display_fn = vk::KhrDisplayFn::load(|name| unsafe { let display_fn = vk::KhrDisplayFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct DisplaySwapchain {
} }
impl DisplaySwapchain { impl DisplaySwapchain {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let swapchain_fn = vk::KhrDisplaySwapchainFn::load(|name| unsafe { let swapchain_fn = vk::KhrDisplaySwapchainFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct DrawIndirectCount {
} }
impl DrawIndirectCount { impl DrawIndirectCount {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let draw_indirect_count_fn = vk::KhrDrawIndirectCountFn::load(|name| unsafe { let draw_indirect_count_fn = vk::KhrDrawIndirectCountFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct ExternalFenceFd {
} }
impl ExternalFenceFd { impl ExternalFenceFd {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let external_fence_fd_fn = vk::KhrExternalFenceFdFn::load(|name| unsafe { let external_fence_fd_fn = vk::KhrExternalFenceFdFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct ExternalMemoryFd {
} }
impl ExternalMemoryFd { impl ExternalMemoryFd {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let external_memory_fd_fn = vk::KhrExternalMemoryFdFn::load(|name| unsafe { let external_memory_fd_fn = vk::KhrExternalMemoryFdFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct ExternalSemaphoreFd {
} }
impl ExternalSemaphoreFd { impl ExternalSemaphoreFd {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let external_semaphore_fd_fn = vk::KhrExternalSemaphoreFdFn::load(|name| unsafe { let external_semaphore_fd_fn = vk::KhrExternalSemaphoreFdFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -12,7 +12,7 @@ pub struct GetMemoryRequirements2 {
} }
impl GetMemoryRequirements2 { impl GetMemoryRequirements2 {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let get_memory_requirements2_fn = vk::KhrGetMemoryRequirements2Fn::load(|name| unsafe { let get_memory_requirements2_fn = vk::KhrGetMemoryRequirements2Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -13,7 +13,7 @@ pub struct GetPhysicalDeviceProperties2 {
} }
impl GetPhysicalDeviceProperties2 { impl GetPhysicalDeviceProperties2 {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let get_physical_device_properties2_fn = let get_physical_device_properties2_fn =
vk::KhrGetPhysicalDeviceProperties2Fn::load(|name| unsafe { vk::KhrGetPhysicalDeviceProperties2Fn::load(|name| 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()))

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct Maintenance1 {
} }
impl Maintenance1 { impl Maintenance1 {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let fns = vk::KhrMaintenance1Fn::load(|name| unsafe { let fns = vk::KhrMaintenance1Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -11,7 +11,7 @@ pub struct Maintenance3 {
} }
impl Maintenance3 { impl Maintenance3 {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let fns = vk::KhrMaintenance3Fn::load(|name| unsafe { let fns = vk::KhrMaintenance3Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -13,7 +13,7 @@ pub struct PipelineExecutableProperties {
} }
impl PipelineExecutableProperties { impl PipelineExecutableProperties {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let pipeline_executable_properties_fn = let pipeline_executable_properties_fn =
vk::KhrPipelineExecutablePropertiesFn::load(|name| unsafe { vk::KhrPipelineExecutablePropertiesFn::load(|name| 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()))

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::c_void; use std::ffi::c_void;
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -12,7 +12,7 @@ pub struct PushDescriptor {
} }
impl PushDescriptor { impl PushDescriptor {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let push_descriptors_fn = vk::KhrPushDescriptorFn::load(|name| unsafe { let push_descriptors_fn = vk::KhrPushDescriptorFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct RayTracingPipeline {
} }
impl RayTracingPipeline { impl RayTracingPipeline {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let ray_tracing_fn = vk::KhrRayTracingPipelineFn::load(|name| unsafe { let ray_tracing_fn = vk::KhrRayTracingPipelineFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });
@ -23,8 +23,8 @@ impl RayTracingPipeline {
} }
} }
pub unsafe fn get_properties<I: InstanceV1_1>( pub unsafe fn get_properties(
instance: &I, instance: &Instance,
pdevice: vk::PhysicalDevice, pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR { ) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceRayTracingPipelinePropertiesKHR::default(); let mut props_rt = vk::PhysicalDeviceRayTracingPipelinePropertiesKHR::default();

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -14,7 +14,7 @@ pub struct Surface {
} }
impl Surface { impl Surface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrSurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -14,7 +14,7 @@ pub struct Swapchain {
} }
impl Swapchain { impl Swapchain {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let swapchain_fn = vk::KhrSwapchainFn::load(|name| unsafe { let swapchain_fn = vk::KhrSwapchainFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -12,7 +12,7 @@ pub struct TimelineSemaphore {
} }
impl TimelineSemaphore { impl TimelineSemaphore {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let timeline_semaphore_fn = vk::KhrTimelineSemaphoreFn::load(|name| unsafe { let timeline_semaphore_fn = vk::KhrTimelineSemaphoreFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct WaylandSurface {
} }
impl WaylandSurface { impl WaylandSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrWaylandSurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrWaylandSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct Win32Surface {
} }
impl Win32Surface { impl Win32Surface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrWin32SurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrWin32SurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct XcbSurface {
} }
impl XcbSurface { impl XcbSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrXcbSurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrXcbSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct XlibSurface {
} }
impl XlibSurface { impl XlibSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::KhrXlibSurfaceFn::load(|name| unsafe { let surface_fn = vk::KhrXlibSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct IOSSurface {
} }
impl IOSSurface { impl IOSSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::MvkIosSurfaceFn::load(|name| unsafe { let surface_fn = vk::MvkIosSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct MacOSSurface {
} }
impl MacOSSurface { impl MacOSSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::MvkMacosSurfaceFn::load(|name| unsafe { let surface_fn = vk::MvkMacosSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct ViSurface {
} }
impl ViSurface { impl ViSurface {
pub fn new<E: EntryV1_0, I: InstanceV1_0>(entry: &E, instance: &I) -> Self { pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
let surface_fn = vk::NnViSurfaceFn::load(|name| unsafe { let surface_fn = vk::NnViSurfaceFn::load(|name| 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()))
}); });

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
use std::os::raw::c_void; use std::os::raw::c_void;
@ -11,7 +11,7 @@ pub struct DeviceDiagnosticCheckpoints {
} }
impl DeviceDiagnosticCheckpoints { impl DeviceDiagnosticCheckpoints {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let device_diagnostic_checkpoints_fn = let device_diagnostic_checkpoints_fn =
vk::NvDeviceDiagnosticCheckpointsFn::load(|name| unsafe { vk::NvDeviceDiagnosticCheckpointsFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk; use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -10,7 +10,7 @@ pub struct MeshShader {
} }
impl MeshShader { impl MeshShader {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let mesh_shader_fn = vk::NvMeshShaderFn::load(|name| unsafe { let mesh_shader_fn = vk::NvMeshShaderFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });

View file

@ -1,8 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::prelude::*; use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk; use crate::vk;
use crate::RawPtr; use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -13,7 +13,7 @@ pub struct RayTracing {
} }
impl RayTracing { impl RayTracing {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self { pub fn new(instance: &Instance, device: &Device) -> Self {
let ray_tracing_fn = vk::NvRayTracingFn::load(|name| unsafe { let ray_tracing_fn = vk::NvRayTracingFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
}); });
@ -23,8 +23,8 @@ impl RayTracing {
} }
} }
pub unsafe fn get_properties<I: InstanceV1_1>( pub unsafe fn get_properties(
instance: &I, instance: &Instance,
pdevice: vk::PhysicalDevice, pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceRayTracingPropertiesNV { ) -> vk::PhysicalDeviceRayTracingPropertiesNV {
let mut props_rt = vk::PhysicalDeviceRayTracingPropertiesNV::default(); let mut props_rt = vk::PhysicalDeviceRayTracingPropertiesNV::default();

View file

@ -10,146 +10,107 @@ use std::ptr;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkInstance.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkInstance.html>"]
#[derive(Clone)] #[derive(Clone)]
pub struct Instance { pub struct Instance {
handle: vk::Instance, pub(crate) handle: vk::Instance,
instance_fn_1_0: vk::InstanceFnV1_0,
instance_fn_1_1: vk::InstanceFnV1_1, pub(crate) instance_fn_1_0: vk::InstanceFnV1_0,
instance_fn_1_2: vk::InstanceFnV1_2, pub(crate) instance_fn_1_1: vk::InstanceFnV1_1,
pub(crate) instance_fn_1_2: vk::InstanceFnV1_2,
} }
impl Instance { impl Instance {
pub unsafe fn load(static_fn: &vk::StaticFn, instance: vk::Instance) -> Self { pub unsafe fn load(static_fn: &vk::StaticFn, instance: vk::Instance) -> Self {
let instance_fn_1_0 = vk::InstanceFnV1_0::load(|name| { let load_fn = |name: &std::ffi::CStr| {
mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr())) mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr()))
}); };
let instance_fn_1_1 = vk::InstanceFnV1_1::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr()))
});
let instance_fn_1_2 = vk::InstanceFnV1_2::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(instance, name.as_ptr()))
});
Instance { Instance {
handle: instance, handle: instance,
instance_fn_1_0,
instance_fn_1_1,
instance_fn_1_2,
}
}
}
impl InstanceV1_0 for Instance { instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn),
type Device = Device; instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn),
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"] instance_fn_1_2: vk::InstanceFnV1_2::load(load_fn),
///
/// # Safety
/// In order for the created `Device` to be valid for the duration of its
/// usage, the `Instance` this was called on must be dropped later than the
/// resulting `Device`.
unsafe fn create_device(
&self,
physical_device: vk::PhysicalDevice,
create_info: &vk::DeviceCreateInfo,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<Self::Device> {
let mut device: vk::Device = mem::zeroed();
self.fp_v1_0()
.create_device(
physical_device,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut device,
)
.result()?;
Ok(Device::load(&self.instance_fn_1_0, device))
} }
fn handle(&self) -> vk::Instance { }
pub fn handle(&self) -> vk::Instance {
self.handle self.handle
} }
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
&self.instance_fn_1_0
}
} }
impl InstanceV1_1 for Instance { /// Vulkan core 1.2
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 { #[allow(non_camel_case_types)]
&self.instance_fn_1_1 impl Instance {
} pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
}
impl InstanceV1_2 for Instance {
fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
&self.instance_fn_1_2 &self.instance_fn_1_2
} }
} }
/// Vulkan core 1.1
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub trait InstanceV1_2: InstanceV1_1 { impl Instance {
fn fp_v1_2(&self) -> &vk::InstanceFnV1_2; pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 {
} &self.instance_fn_1_1
}
#[allow(non_camel_case_types)] pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
pub trait InstanceV1_1: InstanceV1_0 {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1;
unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
let mut group_count = mem::zeroed(); let mut group_count = mem::zeroed();
self.fp_v1_1() self.instance_fn_1_1
.enumerate_physical_device_groups(self.handle(), &mut group_count, ptr::null_mut()) .enumerate_physical_device_groups(self.handle(), &mut group_count, ptr::null_mut())
.result_with_success(group_count as usize) .result_with_success(group_count as usize)
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDeviceGroups.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDeviceGroups.html>"]
fn enumerate_physical_device_groups( pub fn enumerate_physical_device_groups(
&self, &self,
out: &mut [vk::PhysicalDeviceGroupProperties], out: &mut [vk::PhysicalDeviceGroupProperties],
) -> VkResult<()> { ) -> VkResult<()> {
unsafe { unsafe {
let mut group_count = out.len() as u32; let mut group_count = out.len() as u32;
self.fp_v1_1() self.instance_fn_1_1
.enumerate_physical_device_groups(self.handle(), &mut group_count, out.as_mut_ptr()) .enumerate_physical_device_groups(self.handle(), &mut group_count, out.as_mut_ptr())
.into() .into()
} }
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"]
unsafe fn get_physical_device_features2( pub unsafe fn get_physical_device_features2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
features: &mut vk::PhysicalDeviceFeatures2, features: &mut vk::PhysicalDeviceFeatures2,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_features2(physical_device, features); .get_physical_device_features2(physical_device, features);
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties2.html>"]
unsafe fn get_physical_device_properties2( pub unsafe fn get_physical_device_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
prop: &mut vk::PhysicalDeviceProperties2, prop: &mut vk::PhysicalDeviceProperties2,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_properties2(physical_device, prop); .get_physical_device_properties2(physical_device, prop);
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties2.html>"]
unsafe fn get_physical_device_format_properties2( pub unsafe fn get_physical_device_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
out: &mut vk::FormatProperties2, out: &mut vk::FormatProperties2,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_format_properties2(physical_device, format, out); .get_physical_device_format_properties2(physical_device, format, out);
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties2.html>"]
unsafe fn get_physical_device_image_format_properties2( pub unsafe fn get_physical_device_image_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceImageFormatInfo2, format_info: &vk::PhysicalDeviceImageFormatInfo2,
image_format_prop: &mut vk::ImageFormatProperties2, image_format_prop: &mut vk::ImageFormatProperties2,
) -> VkResult<()> { ) -> VkResult<()> {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_image_format_properties2( .get_physical_device_image_format_properties2(
physical_device, physical_device,
format_info, format_info,
@ -158,12 +119,13 @@ pub trait InstanceV1_1: InstanceV1_0 {
.into() .into()
} }
unsafe fn get_physical_device_queue_family_properties2_len( pub unsafe fn get_physical_device_queue_family_properties2_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> usize { ) -> usize {
let mut queue_count = 0; let mut queue_count = 0;
self.fp_v1_1().get_physical_device_queue_family_properties2( self.instance_fn_1_1
.get_physical_device_queue_family_properties2(
physical_device, physical_device,
&mut queue_count, &mut queue_count,
ptr::null_mut(), ptr::null_mut(),
@ -172,13 +134,14 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2.html>"]
unsafe fn get_physical_device_queue_family_properties2( pub unsafe fn get_physical_device_queue_family_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
queue_family_props: &mut [vk::QueueFamilyProperties2], queue_family_props: &mut [vk::QueueFamilyProperties2],
) { ) {
let mut queue_count = queue_family_props.len() as u32; let mut queue_count = queue_family_props.len() as u32;
self.fp_v1_1().get_physical_device_queue_family_properties2( self.instance_fn_1_1
.get_physical_device_queue_family_properties2(
physical_device, physical_device,
&mut queue_count, &mut queue_count,
queue_family_props.as_mut_ptr(), queue_family_props.as_mut_ptr(),
@ -186,22 +149,22 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"]
unsafe fn get_physical_device_memory_properties2( pub unsafe fn get_physical_device_memory_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
out: &mut vk::PhysicalDeviceMemoryProperties2, out: &mut vk::PhysicalDeviceMemoryProperties2,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_memory_properties2(physical_device, out); .get_physical_device_memory_properties2(physical_device, out);
} }
unsafe fn get_physical_device_sparse_image_format_properties2_len( pub unsafe fn get_physical_device_sparse_image_format_properties2_len(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
) -> usize { ) -> usize {
let mut format_count = 0; let mut format_count = 0;
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_sparse_image_format_properties2( .get_physical_device_sparse_image_format_properties2(
physical_device, physical_device,
format_info, format_info,
@ -212,14 +175,14 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2.html>"]
unsafe fn get_physical_device_sparse_image_format_properties2( pub unsafe fn get_physical_device_sparse_image_format_properties2(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
out: &mut [vk::SparseImageFormatProperties2], out: &mut [vk::SparseImageFormatProperties2],
) { ) {
let mut format_count = out.len() as u32; let mut format_count = out.len() as u32;
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_sparse_image_format_properties2( .get_physical_device_sparse_image_format_properties2(
physical_device, physical_device,
format_info, format_info,
@ -229,13 +192,13 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"]
unsafe fn get_physical_device_external_buffer_properties( pub unsafe fn get_physical_device_external_buffer_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo, external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo,
out: &mut vk::ExternalBufferProperties, out: &mut vk::ExternalBufferProperties,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_external_buffer_properties( .get_physical_device_external_buffer_properties(
physical_device, physical_device,
external_buffer_info, external_buffer_info,
@ -244,13 +207,13 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalFenceProperties.html>"]
unsafe fn get_physical_device_external_fence_properties( pub unsafe fn get_physical_device_external_fence_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
external_fence_info: &vk::PhysicalDeviceExternalFenceInfo, external_fence_info: &vk::PhysicalDeviceExternalFenceInfo,
out: &mut vk::ExternalFenceProperties, out: &mut vk::ExternalFenceProperties,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_external_fence_properties( .get_physical_device_external_fence_properties(
physical_device, physical_device,
external_fence_info, external_fence_info,
@ -259,13 +222,13 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalSemaphoreProperties.html>"]
unsafe fn get_physical_device_external_semaphore_properties( pub unsafe fn get_physical_device_external_semaphore_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo, external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo,
out: &mut vk::ExternalSemaphoreProperties, out: &mut vk::ExternalSemaphoreProperties,
) { ) {
self.fp_v1_1() self.instance_fn_1_1
.get_physical_device_external_semaphore_properties( .get_physical_device_external_semaphore_properties(
physical_device, physical_device,
external_semaphore_info, external_semaphore_info,
@ -274,47 +237,60 @@ pub trait InstanceV1_1: InstanceV1_0 {
} }
} }
/// Vulkan core 1.0
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub trait InstanceV1_0 { impl Instance {
type Device; pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
fn handle(&self) -> vk::Instance; &self.instance_fn_1_0
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0; }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"]
/// ///
/// # Safety /// # Safety
/// In order for the created `Device` to be valid for the duration of its /// In order for the created `Device` to be valid for the duration of its
/// usage, the `Instance` this was called on must be dropped later than the /// usage, the `Instance` this was called on must be dropped later than the
/// resulting `Device`. /// resulting `Device`.
unsafe fn create_device( pub unsafe fn create_device(
&self, &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>,
) -> VkResult<Self::Device>; ) -> VkResult<Device> {
let mut device: vk::Device = mem::zeroed();
self.instance_fn_1_0
.create_device(
physical_device,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut device,
)
.result()?;
Ok(Device::load(&self.instance_fn_1_0, device))
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceProcAddr.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceProcAddr.html>"]
unsafe fn get_device_proc_addr( pub unsafe fn get_device_proc_addr(
&self, &self,
device: vk::Device, device: vk::Device,
p_name: *const c_char, p_name: *const c_char,
) -> vk::PFN_vkVoidFunction { ) -> vk::PFN_vkVoidFunction {
self.fp_v1_0().get_device_proc_addr(device, p_name) self.instance_fn_1_0.get_device_proc_addr(device, p_name)
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroyInstance.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroyInstance.html>"]
unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) { pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0() self.instance_fn_1_0
.destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr()); .destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr());
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFormatProperties.html>"]
unsafe fn get_physical_device_format_properties( pub unsafe fn get_physical_device_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
) -> vk::FormatProperties { ) -> vk::FormatProperties {
let mut format_prop = mem::zeroed(); let mut format_prop = mem::zeroed();
self.fp_v1_0().get_physical_device_format_properties( self.instance_fn_1_0.get_physical_device_format_properties(
physical_device, physical_device,
format, format,
&mut format_prop, &mut format_prop,
@ -323,7 +299,7 @@ pub trait InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>"]
unsafe fn get_physical_device_image_format_properties( pub unsafe fn get_physical_device_image_format_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
format: vk::Format, format: vk::Format,
@ -333,7 +309,7 @@ pub trait InstanceV1_0 {
flags: vk::ImageCreateFlags, flags: vk::ImageCreateFlags,
) -> VkResult<vk::ImageFormatProperties> { ) -> VkResult<vk::ImageFormatProperties> {
let mut image_format_prop = mem::zeroed(); let mut image_format_prop = mem::zeroed();
self.fp_v1_0() self.instance_fn_1_0
.get_physical_device_image_format_properties( .get_physical_device_image_format_properties(
physical_device, physical_device,
format, format,
@ -347,40 +323,42 @@ pub trait InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>"]
unsafe fn get_physical_device_memory_properties( pub unsafe fn get_physical_device_memory_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties { ) -> vk::PhysicalDeviceMemoryProperties {
let mut memory_prop = mem::zeroed(); let mut memory_prop = mem::zeroed();
self.fp_v1_0() self.instance_fn_1_0
.get_physical_device_memory_properties(physical_device, &mut memory_prop); .get_physical_device_memory_properties(physical_device, &mut memory_prop);
memory_prop memory_prop
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceProperties.html>"]
unsafe fn get_physical_device_properties( pub unsafe fn get_physical_device_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceProperties { ) -> vk::PhysicalDeviceProperties {
let mut prop = mem::zeroed(); let mut prop = mem::zeroed();
self.fp_v1_0() self.instance_fn_1_0
.get_physical_device_properties(physical_device, &mut prop); .get_physical_device_properties(physical_device, &mut prop);
prop prop
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties.html>"]
unsafe fn get_physical_device_queue_family_properties( pub unsafe fn get_physical_device_queue_family_properties(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> Vec<vk::QueueFamilyProperties> { ) -> Vec<vk::QueueFamilyProperties> {
let mut queue_count = 0; let mut queue_count = 0;
self.fp_v1_0().get_physical_device_queue_family_properties( self.instance_fn_1_0
.get_physical_device_queue_family_properties(
physical_device, physical_device,
&mut queue_count, &mut queue_count,
ptr::null_mut(), ptr::null_mut(),
); );
let mut queue_families_vec = Vec::with_capacity(queue_count as usize); let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
self.fp_v1_0().get_physical_device_queue_family_properties( self.instance_fn_1_0
.get_physical_device_queue_family_properties(
physical_device, physical_device,
&mut queue_count, &mut queue_count,
queue_families_vec.as_mut_ptr(), queue_families_vec.as_mut_ptr(),
@ -390,24 +368,24 @@ pub trait InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures.html>"]
unsafe fn get_physical_device_features( pub unsafe fn get_physical_device_features(
&self, &self,
physical_device: vk::PhysicalDevice, physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceFeatures { ) -> vk::PhysicalDeviceFeatures {
let mut prop = mem::zeroed(); let mut prop = mem::zeroed();
self.fp_v1_0() self.instance_fn_1_0
.get_physical_device_features(physical_device, &mut prop); .get_physical_device_features(physical_device, &mut prop);
prop prop
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumeratePhysicalDevices.html>"]
unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> { pub unsafe fn enumerate_physical_devices(&self) -> VkResult<Vec<vk::PhysicalDevice>> {
let mut num = mem::zeroed(); let mut num = mem::zeroed();
self.fp_v1_0() self.instance_fn_1_0
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut()) .enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut())
.result()?; .result()?;
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize); let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_physical_devices( let err_code = self.instance_fn_1_0.enumerate_physical_devices(
self.handle(), self.handle(),
&mut num, &mut num,
physical_devices.as_mut_ptr(), physical_devices.as_mut_ptr(),
@ -417,16 +395,16 @@ pub trait InstanceV1_0 {
} }
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateDeviceExtensionProperties.html>"]
unsafe fn enumerate_device_extension_properties( pub unsafe fn enumerate_device_extension_properties(
&self, &self,
device: vk::PhysicalDevice, device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::ExtensionProperties>> { ) -> VkResult<Vec<vk::ExtensionProperties>> {
let mut num = 0; let mut num = 0;
self.fp_v1_0() self.instance_fn_1_0
.enumerate_device_extension_properties(device, ptr::null(), &mut num, ptr::null_mut()) .enumerate_device_extension_properties(device, ptr::null(), &mut num, ptr::null_mut())
.result()?; .result()?;
let mut data = Vec::with_capacity(num as usize); let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_device_extension_properties( let err_code = self.instance_fn_1_0.enumerate_device_extension_properties(
device, device,
ptr::null(), ptr::null(),
&mut num, &mut num,

View file

@ -10,7 +10,7 @@
//! ## Examples //! ## Examples
//! //!
//! ```no_run //! ```no_run
//! use ash::{vk, Entry, version::EntryV1_0}; //! use ash::{vk, Entry};
//! # fn main() -> Result<(), Box<dyn std::error::Error>> { //! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let entry = unsafe { Entry::new() }?; //! let entry = unsafe { Entry::new() }?;
//! let app_info = vk::ApplicationInfo { //! let app_info = vk::ApplicationInfo {
@ -39,7 +39,6 @@ mod entry_libloading;
mod instance; mod instance;
pub mod prelude; pub mod prelude;
pub mod util; pub mod util;
pub mod version;
#[macro_use] #[macro_use]
pub mod vk; pub mod vk;

View file

@ -24,7 +24,6 @@ fn assert_struct_field_is_array() {
#[test] #[test]
#[allow(dead_code)] #[allow(dead_code)]
fn assert_ffi_array_param_is_pointer() { fn assert_ffi_array_param_is_pointer() {
use ash::version::DeviceV1_0;
// don't run it, just make sure it compiles // don't run it, just make sure it compiles
unsafe fn dummy(device: &ash::Device, cmd_buffer: ash::vk::CommandBuffer) { unsafe fn dummy(device: &ash::Device, cmd_buffer: ash::vk::CommandBuffer) {
let blend_constants: [f32; 4] = [0.0, 0.0, 0.0, 0.0]; let blend_constants: [f32; 4] = [0.0, 0.0, 0.0, 0.0];

View file

@ -6,8 +6,8 @@ use ash::extensions::{
khr::{Surface, Swapchain}, khr::{Surface, Swapchain},
}; };
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0}; use ash::{vk, Entry};
use ash::{vk, Device, Entry, Instance}; pub use ash::{Device, EntryCustom, Instance};
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
use std::default::Default; use std::default::Default;
@ -29,8 +29,8 @@ macro_rules! offset_of {
/// is executed. That way we can delay the waiting for the fences by 1 frame which is good for performance. /// is executed. That way we can delay the waiting for the fences by 1 frame which is good for performance.
/// Make sure to create the fence in a signaled state on the first use. /// Make sure to create the fence in a signaled state on the first use.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffer)>( pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
device: &D, device: &Device,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
command_buffer_reuse_fence: vk::Fence, command_buffer_reuse_fence: vk::Fence,
submit_queue: vk::Queue, submit_queue: vk::Queue,
@ -279,7 +279,7 @@ impl ExampleBase {
}) })
.next() .next()
}) })
.filter_map(|v| v) .flatten()
.next() .next()
.expect("Couldn't find suitable device."); .expect("Couldn't find suitable device.");
let queue_family_index = queue_family_index as u32; let queue_family_index = queue_family_index as u32;