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.
use ash::{version::EntryV1_0, vk};
use ash::vk;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {

View file

@ -1,9 +1,4 @@
use ash::{
extensions::khr,
prelude::*,
version::{EntryV1_0, InstanceV1_0},
vk,
};
use ash::{extensions::khr, prelude::*, vk, EntryCustom, Instance};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
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
/// usage, the `Instance` this was called on must be dropped later than the
/// resulting `SurfaceKHR`.
pub unsafe fn create_surface<E, I>(
entry: &E,
instance: &I,
pub unsafe fn create_surface<L>(
entry: &EntryCustom<L>,
instance: &Instance,
window_handle: &dyn HasRawWindowHandle,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR>
where
E: EntryV1_0,
I: InstanceV1_0,
{
) -> VkResult<vk::SurfaceKHR> {
match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")]
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,
}
#[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 {}
/// Vulkan core 1.0
#[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> {
pub fn new_custom<Load>(
mut lib: L,
@ -173,18 +32,12 @@ impl<L> EntryCustom<L> {
{
// Bypass the normal StaticFn::load so we can return an error
let static_fn = vk::StaticFn::load_checked(|name| load(&mut lib, name))?;
let entry_fn_1_0 = vk::EntryFnV1_0::load(|name| unsafe {
let load_fn = |name: &std::ffi::CStr| unsafe {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
});
let entry_fn_1_1 = vk::EntryFnV1_1::load(|name| unsafe {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
});
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()))
});
};
let entry_fn_1_0 = vk::EntryFnV1_0::load(load_fn);
let entry_fn_1_1 = vk::EntryFnV1_1::load(load_fn);
let entry_fn_1_2 = vk::EntryFnV1_2::load(load_fn);
Ok(EntryCustom {
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>"]
/// ```no_run
/// # use ash::{Entry, vk};
@ -218,7 +79,7 @@ impl<L> EntryCustom<L> {
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
let name = b"vkEnumerateInstanceVersion\0".as_ptr() as *const _;
mem::transmute(
self.static_fn()
self.static_fn
.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 {
pub fn load_checked<F>(mut _f: F) -> Result<Self, MissingEntryPoint>
where

View file

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

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::{vk, RawPtr};
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -12,7 +12,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -12,7 +12,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
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>(
instance: &I,
pub unsafe fn get_properties(
instance: &Instance,
pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceAccelerationStructurePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default();

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -12,7 +12,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -13,7 +13,7 @@ pub struct 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 =
vk::KhrGetPhysicalDeviceProperties2Fn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -11,7 +11,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -13,7 +13,7 @@ pub struct 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 =
vk::KhrPipelineExecutablePropertiesFn::load(|name| unsafe {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::c_void;
use std::ffi::CStr;
use std::mem;
@ -12,7 +12,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
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>(
instance: &I,
pub unsafe fn get_properties(
instance: &Instance,
pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceRayTracingPipelinePropertiesKHR::default();

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -14,7 +14,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
@ -14,7 +14,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,7 +1,7 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -12,7 +12,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{EntryV1_0, InstanceV1_0};
use crate::vk;
use crate::RawPtr;
use crate::{EntryCustom, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
});

View file

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

View file

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -10,7 +10,7 @@ pub struct 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 {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});

View file

@ -1,8 +1,8 @@
#![allow(dead_code)]
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0, InstanceV1_1};
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
@ -13,7 +13,7 @@ pub struct 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 {
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>(
instance: &I,
pub unsafe fn get_properties(
instance: &Instance,
pdevice: vk::PhysicalDevice,
) -> vk::PhysicalDeviceRayTracingPropertiesNV {
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>"]
#[derive(Clone)]
pub struct Instance {
handle: vk::Instance,
instance_fn_1_0: vk::InstanceFnV1_0,
instance_fn_1_1: vk::InstanceFnV1_1,
instance_fn_1_2: vk::InstanceFnV1_2,
pub(crate) handle: vk::Instance,
pub(crate) instance_fn_1_0: vk::InstanceFnV1_0,
pub(crate) instance_fn_1_1: vk::InstanceFnV1_1,
pub(crate) instance_fn_1_2: vk::InstanceFnV1_2,
}
impl Instance {
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()))
});
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 {
handle: instance,
instance_fn_1_0,
instance_fn_1_1,
instance_fn_1_2,
instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn),
instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn),
instance_fn_1_2: vk::InstanceFnV1_2::load(load_fn),
}
}
}
impl InstanceV1_0 for Instance {
type Device = Device;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"]
///
/// # 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
}
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
&self.instance_fn_1_0
}
}
impl InstanceV1_1 for Instance {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 {
&self.instance_fn_1_1
}
}
impl InstanceV1_2 for Instance {
fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
/// Vulkan core 1.2
#[allow(non_camel_case_types)]
impl Instance {
pub fn fp_v1_2(&self) -> &vk::InstanceFnV1_2 {
&self.instance_fn_1_2
}
}
/// Vulkan core 1.1
#[allow(non_camel_case_types)]
pub trait InstanceV1_2: InstanceV1_1 {
fn fp_v1_2(&self) -> &vk::InstanceFnV1_2;
}
impl Instance {
pub fn fp_v1_1(&self) -> &vk::InstanceFnV1_1 {
&self.instance_fn_1_1
}
#[allow(non_camel_case_types)]
pub trait InstanceV1_1: InstanceV1_0 {
fn fp_v1_1(&self) -> &vk::InstanceFnV1_1;
unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult<usize> {
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())
.result_with_success(group_count as usize)
}
#[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,
out: &mut [vk::PhysicalDeviceGroupProperties],
) -> VkResult<()> {
unsafe {
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())
.into()
}
}
#[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,
physical_device: vk::PhysicalDevice,
features: &mut vk::PhysicalDeviceFeatures2,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_features2(physical_device, features);
}
#[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,
physical_device: vk::PhysicalDevice,
prop: &mut vk::PhysicalDeviceProperties2,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_properties2(physical_device, prop);
}
#[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,
physical_device: vk::PhysicalDevice,
format: vk::Format,
out: &mut vk::FormatProperties2,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_format_properties2(physical_device, format, out);
}
#[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,
physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceImageFormatInfo2,
image_format_prop: &mut vk::ImageFormatProperties2,
) -> VkResult<()> {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_image_format_properties2(
physical_device,
format_info,
@ -158,50 +119,52 @@ pub trait InstanceV1_1: InstanceV1_0 {
.into()
}
unsafe fn get_physical_device_queue_family_properties2_len(
pub unsafe fn get_physical_device_queue_family_properties2_len(
&self,
physical_device: vk::PhysicalDevice,
) -> usize {
let mut queue_count = 0;
self.fp_v1_1().get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
self.instance_fn_1_1
.get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
queue_count as usize
}
#[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,
physical_device: vk::PhysicalDevice,
queue_family_props: &mut [vk::QueueFamilyProperties2],
) {
let mut queue_count = queue_family_props.len() as u32;
self.fp_v1_1().get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
queue_family_props.as_mut_ptr(),
);
self.instance_fn_1_1
.get_physical_device_queue_family_properties2(
physical_device,
&mut queue_count,
queue_family_props.as_mut_ptr(),
);
}
#[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,
physical_device: vk::PhysicalDevice,
out: &mut vk::PhysicalDeviceMemoryProperties2,
) {
self.fp_v1_1()
self.instance_fn_1_1
.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,
physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
) -> usize {
let mut format_count = 0;
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_sparse_image_format_properties2(
physical_device,
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>"]
unsafe fn get_physical_device_sparse_image_format_properties2(
pub unsafe fn get_physical_device_sparse_image_format_properties2(
&self,
physical_device: vk::PhysicalDevice,
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
out: &mut [vk::SparseImageFormatProperties2],
) {
let mut format_count = out.len() as u32;
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_sparse_image_format_properties2(
physical_device,
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>"]
unsafe fn get_physical_device_external_buffer_properties(
pub unsafe fn get_physical_device_external_buffer_properties(
&self,
physical_device: vk::PhysicalDevice,
external_buffer_info: &vk::PhysicalDeviceExternalBufferInfo,
out: &mut vk::ExternalBufferProperties,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_external_buffer_properties(
physical_device,
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>"]
unsafe fn get_physical_device_external_fence_properties(
pub unsafe fn get_physical_device_external_fence_properties(
&self,
physical_device: vk::PhysicalDevice,
external_fence_info: &vk::PhysicalDeviceExternalFenceInfo,
out: &mut vk::ExternalFenceProperties,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_external_fence_properties(
physical_device,
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>"]
unsafe fn get_physical_device_external_semaphore_properties(
pub unsafe fn get_physical_device_external_semaphore_properties(
&self,
physical_device: vk::PhysicalDevice,
external_semaphore_info: &vk::PhysicalDeviceExternalSemaphoreInfo,
out: &mut vk::ExternalSemaphoreProperties,
) {
self.fp_v1_1()
self.instance_fn_1_1
.get_physical_device_external_semaphore_properties(
physical_device,
external_semaphore_info,
@ -274,47 +237,60 @@ pub trait InstanceV1_1: InstanceV1_0 {
}
}
/// Vulkan core 1.0
#[allow(non_camel_case_types)]
pub trait InstanceV1_0 {
type Device;
fn handle(&self) -> vk::Instance;
fn fp_v1_0(&self) -> &vk::InstanceFnV1_0;
impl Instance {
pub fn fp_v1_0(&self) -> &vk::InstanceFnV1_0 {
&self.instance_fn_1_0
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDevice.html>"]
///
/// # 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(
pub unsafe fn create_device(
&self,
physical_device: vk::PhysicalDevice,
create_info: &vk::DeviceCreateInfo,
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>"]
unsafe fn get_device_proc_addr(
pub unsafe fn get_device_proc_addr(
&self,
device: vk::Device,
p_name: *const c_char,
) -> 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>"]
unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0()
pub unsafe fn destroy_instance(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.instance_fn_1_0
.destroy_instance(self.handle(), allocation_callbacks.as_raw_ptr());
}
#[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,
physical_device: vk::PhysicalDevice,
format: vk::Format,
) -> vk::FormatProperties {
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,
format,
&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>"]
unsafe fn get_physical_device_image_format_properties(
pub unsafe fn get_physical_device_image_format_properties(
&self,
physical_device: vk::PhysicalDevice,
format: vk::Format,
@ -333,7 +309,7 @@ pub trait InstanceV1_0 {
flags: vk::ImageCreateFlags,
) -> VkResult<vk::ImageFormatProperties> {
let mut image_format_prop = mem::zeroed();
self.fp_v1_0()
self.instance_fn_1_0
.get_physical_device_image_format_properties(
physical_device,
format,
@ -347,67 +323,69 @@ pub trait InstanceV1_0 {
}
#[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,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceMemoryProperties {
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);
memory_prop
}
#[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,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceProperties {
let mut prop = mem::zeroed();
self.fp_v1_0()
self.instance_fn_1_0
.get_physical_device_properties(physical_device, &mut prop);
prop
}
#[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,
physical_device: vk::PhysicalDevice,
) -> Vec<vk::QueueFamilyProperties> {
let mut queue_count = 0;
self.fp_v1_0().get_physical_device_queue_family_properties(
physical_device,
&mut queue_count,
ptr::null_mut(),
);
self.instance_fn_1_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.fp_v1_0().get_physical_device_queue_family_properties(
physical_device,
&mut queue_count,
queue_families_vec.as_mut_ptr(),
);
self.instance_fn_1_0
.get_physical_device_queue_family_properties(
physical_device,
&mut queue_count,
queue_families_vec.as_mut_ptr(),
);
queue_families_vec.set_len(queue_count as usize);
queue_families_vec
}
#[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,
physical_device: vk::PhysicalDevice,
) -> vk::PhysicalDeviceFeatures {
let mut prop = mem::zeroed();
self.fp_v1_0()
self.instance_fn_1_0
.get_physical_device_features(physical_device, &mut prop);
prop
}
#[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();
self.fp_v1_0()
self.instance_fn_1_0
.enumerate_physical_devices(self.handle(), &mut num, ptr::null_mut())
.result()?;
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(),
&mut num,
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>"]
unsafe fn enumerate_device_extension_properties(
pub unsafe fn enumerate_device_extension_properties(
&self,
device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::ExtensionProperties>> {
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())
.result()?;
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,
ptr::null(),
&mut num,

View file

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

View file

@ -24,7 +24,6 @@ fn assert_struct_field_is_array() {
#[test]
#[allow(dead_code)]
fn assert_ffi_array_param_is_pointer() {
use ash::version::DeviceV1_0;
// don't run it, just make sure it compiles
unsafe fn dummy(device: &ash::Device, cmd_buffer: ash::vk::CommandBuffer) {
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},
};
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
use ash::{vk, Device, Entry, Instance};
use ash::{vk, Entry};
pub use ash::{Device, EntryCustom, Instance};
use std::borrow::Cow;
use std::cell::RefCell;
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.
/// Make sure to create the fence in a signaled state on the first use.
#[allow(clippy::too_many_arguments)]
pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffer)>(
device: &D,
pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
device: &Device,
command_buffer: vk::CommandBuffer,
command_buffer_reuse_fence: vk::Fence,
submit_queue: vk::Queue,
@ -279,7 +279,7 @@ impl ExampleBase {
})
.next()
})
.filter_map(|v| v)
.flatten()
.next()
.expect("Couldn't find suitable device.");
let queue_family_index = queue_family_index as u32;