Allow building Entry/Instance/Device from handle+fns (#748)

* ash/device: Allow building device from handle+fns

Adds a constructor to build a device from a handle + functions.
Helps with interoperability with other vulkan wrappers

* ash/instance: Allow building instance from handle+fns

Adds a constructor to build an instance from a handle + functions.
Helps with interoperability with other vulkan wrappers

* ash/entry: Allow building entry from handle+fns

Adds a constructor to build an entry from a handle + functions.
Helps with interoperability with other vulkan wrappers

* changelog: Document #748 addition of `from_parts` constructors
This commit is contained in:
antonino maniscalco 2023-05-07 21:44:34 +02:00 committed by GitHub
parent fca01159ab
commit 53c395b6b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 14 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_EXT_shader_object` device extension (#732) - Added `VK_EXT_shader_object` device extension (#732)
- Added missing `Device::get_device_queue2()` wrapper (#736) - Added missing `Device::get_device_queue2()` wrapper (#736)
- Exposed `FramebufferCreateInfo::attachment_count()` builder for `vk::FramebufferCreateFlags::IMAGELESS` (#747) - Exposed `FramebufferCreateInfo::attachment_count()` builder for `vk::FramebufferCreateFlags::IMAGELESS` (#747)
- Allow building `Entry`/`Instance`/`Device` from handle+fns (#748)
### Changed ### Changed

View file

@ -23,13 +23,30 @@ impl Device {
mem::transmute((instance_fn.get_device_proc_addr)(device, name.as_ptr())) mem::transmute((instance_fn.get_device_proc_addr)(device, name.as_ptr()))
}; };
Self { Self::from_parts_1_3(
handle: device, device,
vk::DeviceFnV1_0::load(load_fn),
vk::DeviceFnV1_1::load(load_fn),
vk::DeviceFnV1_2::load(load_fn),
vk::DeviceFnV1_3::load(load_fn),
)
}
device_fn_1_0: vk::DeviceFnV1_0::load(load_fn), #[inline]
device_fn_1_1: vk::DeviceFnV1_1::load(load_fn), pub fn from_parts_1_3(
device_fn_1_2: vk::DeviceFnV1_2::load(load_fn), handle: vk::Device,
device_fn_1_3: vk::DeviceFnV1_3::load(load_fn), device_fn_1_0: vk::DeviceFnV1_0,
device_fn_1_1: vk::DeviceFnV1_1,
device_fn_1_2: vk::DeviceFnV1_2,
device_fn_1_3: vk::DeviceFnV1_3,
) -> Self {
Self {
handle,
device_fn_1_0,
device_fn_1_1,
device_fn_1_2,
device_fn_1_3,
} }
} }

View file

@ -140,15 +140,26 @@ impl Entry {
/// `static_fn` must contain valid function pointers that comply with the semantics specified by /// `static_fn` must contain valid function pointers that comply with the semantics specified by
/// Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`]. /// Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`].
pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self { pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self {
let load_fn = |name: &std::ffi::CStr| { let load_fn = move |name: &std::ffi::CStr| {
mem::transmute((static_fn.get_instance_proc_addr)( mem::transmute((static_fn.get_instance_proc_addr)(
vk::Instance::null(), vk::Instance::null(),
name.as_ptr(), 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);
Self::from_parts_1_1(
static_fn,
vk::EntryFnV1_0::load(load_fn),
vk::EntryFnV1_1::load(load_fn),
)
}
#[inline]
pub fn from_parts_1_1(
static_fn: vk::StaticFn,
entry_fn_1_0: vk::EntryFnV1_0,
entry_fn_1_1: vk::EntryFnV1_1,
) -> Self {
Self { Self {
static_fn, static_fn,
entry_fn_1_0, entry_fn_1_0,

View file

@ -22,12 +22,27 @@ impl Instance {
mem::transmute((static_fn.get_instance_proc_addr)(instance, name.as_ptr())) mem::transmute((static_fn.get_instance_proc_addr)(instance, name.as_ptr()))
}; };
Self { Self::from_parts_1_3(
handle: instance, instance,
vk::InstanceFnV1_0::load(load_fn),
vk::InstanceFnV1_1::load(load_fn),
vk::InstanceFnV1_3::load(load_fn),
)
}
instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn), #[inline]
instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn), pub fn from_parts_1_3(
instance_fn_1_3: vk::InstanceFnV1_3::load(load_fn), handle: vk::Instance,
instance_fn_1_0: vk::InstanceFnV1_0,
instance_fn_1_1: vk::InstanceFnV1_1,
instance_fn_1_3: vk::InstanceFnV1_3,
) -> Self {
Self {
handle,
instance_fn_1_0,
instance_fn_1_1,
instance_fn_1_3,
} }
} }