Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 missing `Device::get_device_queue2()` wrapper (#736)
- Exposed `FramebufferCreateInfo::attachment_count()` builder for `vk::FramebufferCreateFlags::IMAGELESS` (#747)
- Allow building `Entry`/`Instance`/`Device` from handle+fns (#748)

### Changed

Expand Down
27 changes: 22 additions & 5 deletions ash/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ impl Device {
mem::transmute((instance_fn.get_device_proc_addr)(device, name.as_ptr()))
};

Self::from_parts_1_3(
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),
)
}

#[inline]
pub fn from_parts_1_3(
handle: vk::Device,
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,
handle,

device_fn_1_0: vk::DeviceFnV1_0::load(load_fn),
device_fn_1_1: vk::DeviceFnV1_1::load(load_fn),
device_fn_1_2: vk::DeviceFnV1_2::load(load_fn),
device_fn_1_3: vk::DeviceFnV1_3::load(load_fn),
device_fn_1_0,
device_fn_1_1,
device_fn_1_2,
device_fn_1_3,
}
}

Expand Down
17 changes: 14 additions & 3 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,26 @@ impl Entry {
/// `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`].
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)(
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);

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 {
static_fn,
entry_fn_1_0,
Expand Down
23 changes: 19 additions & 4 deletions ash/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,27 @@ impl Instance {
mem::transmute((static_fn.get_instance_proc_addr)(instance, name.as_ptr()))
};

Self::from_parts_1_3(
instance,
vk::InstanceFnV1_0::load(load_fn),
vk::InstanceFnV1_1::load(load_fn),
vk::InstanceFnV1_3::load(load_fn),
)
}

#[inline]
pub fn from_parts_1_3(
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,
handle,

instance_fn_1_0: vk::InstanceFnV1_0::load(load_fn),
instance_fn_1_1: vk::InstanceFnV1_1::load(load_fn),
instance_fn_1_3: vk::InstanceFnV1_3::load(load_fn),
instance_fn_1_0,
instance_fn_1_1,
instance_fn_1_3,
}
}

Expand Down