extensions/khr: Add ExternalSemaphoreFd safe wrapper (#395)
* extensions/khr: Add ExternalSemaphoreFd safe wrapper Implement the two small import and export and functions, part of the VK_KHR_external_semaphore_fd extension. * device: Pass ImageSubresource by immutable reference It is only used as pointer by the native function, and should not (need to) be moved.
This commit is contained in:
parent
d8d742348e
commit
1cea46359f
|
@ -1902,15 +1902,11 @@ pub trait DeviceV1_0 {
|
|||
unsafe fn get_image_subresource_layout(
|
||||
&self,
|
||||
image: vk::Image,
|
||||
subresource: vk::ImageSubresource,
|
||||
subresource: &vk::ImageSubresource,
|
||||
) -> vk::SubresourceLayout {
|
||||
let mut layout = mem::zeroed();
|
||||
self.fp_v1_0().get_image_subresource_layout(
|
||||
self.handle(),
|
||||
image,
|
||||
&subresource,
|
||||
&mut layout,
|
||||
);
|
||||
self.fp_v1_0()
|
||||
.get_image_subresource_layout(self.handle(), image, subresource, &mut layout);
|
||||
layout
|
||||
}
|
||||
|
||||
|
|
54
ash/src/extensions/khr/external_semaphore_fd.rs
Normal file
54
ash/src/extensions/khr/external_semaphore_fd.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use crate::prelude::*;
|
||||
use crate::version::{DeviceV1_0, InstanceV1_0};
|
||||
use crate::vk;
|
||||
use std::ffi::CStr;
|
||||
use std::mem;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ExternalSemaphoreFd {
|
||||
handle: vk::Device,
|
||||
external_semaphore_fd_fn: vk::KhrExternalSemaphoreFdFn,
|
||||
}
|
||||
|
||||
impl ExternalSemaphoreFd {
|
||||
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self {
|
||||
let external_semaphore_fd_fn = vk::KhrExternalSemaphoreFdFn::load(|name| unsafe {
|
||||
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
|
||||
});
|
||||
Self {
|
||||
handle: device.handle(),
|
||||
external_semaphore_fd_fn,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name() -> &'static CStr {
|
||||
vk::KhrExternalSemaphoreFdFn::name()
|
||||
}
|
||||
|
||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkImportSemaphoreFdKHR.html>"]
|
||||
pub unsafe fn import_semaphore_fd(
|
||||
&self,
|
||||
import_info: &vk::ImportSemaphoreFdInfoKHR,
|
||||
) -> VkResult<()> {
|
||||
self.external_semaphore_fd_fn
|
||||
.import_semaphore_fd_khr(self.handle, import_info)
|
||||
.result()
|
||||
}
|
||||
|
||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetSemaphoreFdKHR.html>"]
|
||||
pub unsafe fn get_semaphore_fd(&self, get_info: &vk::SemaphoreGetFdInfoKHR) -> VkResult<i32> {
|
||||
let mut fd = -1;
|
||||
|
||||
self.external_semaphore_fd_fn
|
||||
.get_semaphore_fd_khr(self.handle, get_info, &mut fd)
|
||||
.result_with_success(fd)
|
||||
}
|
||||
|
||||
pub fn fp(&self) -> &vk::KhrExternalSemaphoreFdFn {
|
||||
&self.external_semaphore_fd_fn
|
||||
}
|
||||
|
||||
pub fn device(&self) -> vk::Device {
|
||||
self.handle
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ pub use self::display::Display;
|
|||
pub use self::display_swapchain::DisplaySwapchain;
|
||||
pub use self::draw_indirect_count::DrawIndirectCount;
|
||||
pub use self::external_memory_fd::ExternalMemoryFd;
|
||||
pub use self::external_semaphore_fd::ExternalSemaphoreFd;
|
||||
pub use self::get_memory_requirements2::GetMemoryRequirements2;
|
||||
pub use self::maintenance1::Maintenance1;
|
||||
pub use self::maintenance3::Maintenance3;
|
||||
|
@ -28,6 +29,7 @@ mod display;
|
|||
mod display_swapchain;
|
||||
mod draw_indirect_count;
|
||||
mod external_memory_fd;
|
||||
mod external_semaphore_fd;
|
||||
mod get_memory_requirements2;
|
||||
mod maintenance1;
|
||||
mod maintenance3;
|
||||
|
|
Loading…
Reference in a new issue