Add VK_KHR_external_memory_fd extension support (#270)

This commit is contained in:
IntrepidPig 2020-02-18 13:58:36 -08:00 committed by GitHub
parent 651462a342
commit 98def0a4e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,66 @@
use crate::prelude::*;
use crate::version::{DeviceV1_0, InstanceV1_0};
use crate::vk;
use std::ffi::CStr;
use std::mem;
#[derive(Clone)]
pub struct ExternalMemoryFd {
handle: vk::Device,
external_memory_fd_fn: vk::KhrExternalMemoryFdFn,
}
impl ExternalMemoryFd {
pub fn new<I: InstanceV1_0, D: DeviceV1_0>(instance: &I, device: &D) -> Self {
let external_memory_fd_fn = vk::KhrExternalMemoryFdFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});
Self {
handle: device.handle(),
external_memory_fd_fn,
}
}
pub fn name() -> &'static CStr {
vk::KhrExternalMemoryFdFn::name()
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdKHR.html>"]
pub unsafe fn get_memory_fd(&self, create_info: &vk::MemoryGetFdInfoKHR) -> VkResult<i32> {
let mut fd = -1;
let err_code =
self.external_memory_fd_fn
.get_memory_fd_khr(self.handle, create_info, &mut fd);
match err_code {
vk::Result::SUCCESS => Ok(fd),
_ => Err(err_code),
}
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdPropertiesKHR.html>"]
pub unsafe fn get_memory_fd_properties_khr(
&self,
handle_type: vk::ExternalMemoryHandleTypeFlags,
fd: i32,
) -> VkResult<vk::MemoryFdPropertiesKHR> {
let mut memory_fd_properties = mem::zeroed();
let err_code = self.external_memory_fd_fn.get_memory_fd_properties_khr(
self.handle,
handle_type,
fd,
&mut memory_fd_properties,
);
match err_code {
vk::Result::SUCCESS => Ok(memory_fd_properties),
_ => Err(err_code),
}
}
pub fn fp(&self) -> &vk::KhrExternalMemoryFdFn {
&self.external_memory_fd_fn
}
pub fn device(&self) -> vk::Device {
self.handle
}
}

View file

@ -1,6 +1,7 @@
pub use self::android_surface::AndroidSurface; pub use self::android_surface::AndroidSurface;
pub use self::display::Display; pub use self::display::Display;
pub use self::display_swapchain::DisplaySwapchain; pub use self::display_swapchain::DisplaySwapchain;
pub use self::external_memory_fd::ExternalMemoryFd;
pub use self::push_descriptor::PushDescriptor; pub use self::push_descriptor::PushDescriptor;
pub use self::surface::Surface; pub use self::surface::Surface;
pub use self::swapchain::Swapchain; pub use self::swapchain::Swapchain;
@ -12,6 +13,7 @@ pub use self::xlib_surface::XlibSurface;
mod android_surface; mod android_surface;
mod display; mod display;
mod display_swapchain; mod display_swapchain;
mod external_memory_fd;
mod push_descriptor; mod push_descriptor;
mod surface; mod surface;
mod swapchain; mod swapchain;