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

extensions/khr: Add VK_KHR_external_fence_fd wrapper #413

Merged
merged 1 commit into from
Mar 26, 2021
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
51 changes: 51 additions & 0 deletions ash/src/extensions/khr/external_fence_fd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use std::ffi::CStr;
use std::mem;

#[derive(Clone)]
pub struct ExternalFenceFd {
handle: vk::Device,
external_fence_fd_fn: vk::KhrExternalFenceFdFn,
}

impl ExternalFenceFd {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self {
let external_fence_fd_fn = vk::KhrExternalFenceFdFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});
Self {
handle: device.handle(),
external_fence_fd_fn,
}
}

pub fn name() -> &'static CStr {
vk::KhrExternalFenceFdFn::name()
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkImportFenceFdKHR.html>"]
pub unsafe fn import_fence_fd(&self, import_info: &vk::ImportFenceFdInfoKHR) -> VkResult<()> {
self.external_fence_fd_fn
.import_fence_fd_khr(self.handle, import_info)
.result()
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetFenceFdKHR.html>"]
pub unsafe fn get_fence_fd(&self, get_info: &vk::FenceGetFdInfoKHR) -> VkResult<i32> {
let mut fd = -1;

self.external_fence_fd_fn
.get_fence_fd_khr(self.handle, get_info, &mut fd)
.result_with_success(fd)
}

pub fn fp(&self) -> &vk::KhrExternalFenceFdFn {
&self.external_fence_fd_fn
}

pub fn device(&self) -> vk::Device {
self.handle
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/khr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub use self::deferred_host_operations::DeferredHostOperations;
pub use self::display::Display;
pub use self::display_swapchain::DisplaySwapchain;
pub use self::draw_indirect_count::DrawIndirectCount;
pub use self::external_fence_fd::ExternalFenceFd;
pub use self::external_memory_fd::ExternalMemoryFd;
pub use self::external_semaphore_fd::ExternalSemaphoreFd;
pub use self::get_memory_requirements2::GetMemoryRequirements2;
Expand All @@ -30,6 +31,7 @@ mod deferred_host_operations;
mod display;
mod display_swapchain;
mod draw_indirect_count;
mod external_fence_fd;
mod external_memory_fd;
mod external_semaphore_fd;
mod get_memory_requirements2;
Expand Down