• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::prelude::*;
2 use crate::vk;
3 use crate::{Device, Instance};
4 use std::ffi::CStr;
5 use std::mem;
6 
7 #[derive(Clone)]
8 pub struct ExternalMemoryFd {
9     handle: vk::Device,
10     external_memory_fd_fn: vk::KhrExternalMemoryFdFn,
11 }
12 
13 impl ExternalMemoryFd {
new(instance: &Instance, device: &Device) -> Self14     pub fn new(instance: &Instance, device: &Device) -> Self {
15         let external_memory_fd_fn = vk::KhrExternalMemoryFdFn::load(|name| unsafe {
16             mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
17         });
18         Self {
19             handle: device.handle(),
20             external_memory_fd_fn,
21         }
22     }
23 
name() -> &'static CStr24     pub fn name() -> &'static CStr {
25         vk::KhrExternalMemoryFdFn::name()
26     }
27 
28     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdKHR.html>"]
get_memory_fd(&self, create_info: &vk::MemoryGetFdInfoKHR) -> VkResult<i32>29     pub unsafe fn get_memory_fd(&self, create_info: &vk::MemoryGetFdInfoKHR) -> VkResult<i32> {
30         let mut fd = -1;
31 
32         self.external_memory_fd_fn
33             .get_memory_fd_khr(self.handle, create_info, &mut fd)
34             .result_with_success(fd)
35     }
36 
37     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdPropertiesKHR.html>"]
get_memory_fd_properties_khr( &self, handle_type: vk::ExternalMemoryHandleTypeFlags, fd: i32, ) -> VkResult<vk::MemoryFdPropertiesKHR>38     pub unsafe fn get_memory_fd_properties_khr(
39         &self,
40         handle_type: vk::ExternalMemoryHandleTypeFlags,
41         fd: i32,
42     ) -> VkResult<vk::MemoryFdPropertiesKHR> {
43         let mut memory_fd_properties = Default::default();
44         self.external_memory_fd_fn
45             .get_memory_fd_properties_khr(self.handle, handle_type, fd, &mut memory_fd_properties)
46             .result_with_success(memory_fd_properties)
47     }
48 
fp(&self) -> &vk::KhrExternalMemoryFdFn49     pub fn fp(&self) -> &vk::KhrExternalMemoryFdFn {
50         &self.external_memory_fd_fn
51     }
52 
device(&self) -> vk::Device53     pub fn device(&self) -> vk::Device {
54         self.handle
55     }
56 }
57