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_semaphore_win32 #581

Merged
merged 1 commit into from
Feb 16, 2022
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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `VK_KHR_external_semaphore_win32` device extension (#581)
- Added `VK_KHR_external_memory_win32` device extension (#579)
- Added `VK_EXT_extended_dynamic_state2` device extension (#572)
- Added `VK_KHR_copy_commands2` device extension (#571)
Expand Down
56 changes: 56 additions & 0 deletions ash/src/extensions/khr/external_semaphore_win32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_win32.html>
#[derive(Clone)]
pub struct ExternalSemaphoreWin32 {
handle: vk::Device,
fp: vk::KhrExternalSemaphoreWin32Fn,
}

impl ExternalSemaphoreWin32 {
pub fn new(instance: &Instance, device: &Device) -> Self {
let handle = device.handle();
let fp = vk::KhrExternalSemaphoreWin32Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
});
Self { handle, fp }
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkImportSemaphoreWin32HandleKHR.html>
pub unsafe fn import_semaphore_win32_handle(
&self,
import_info: &vk::ImportSemaphoreWin32HandleInfoKHR,
) -> VkResult<()> {
self.fp
.import_semaphore_win32_handle_khr(self.handle, import_info)
.result()
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSemaphoreWin32HandleKHR.html>
pub unsafe fn get_semaphore_win32_handle(
&self,
get_info: &vk::SemaphoreGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
let mut handle = ptr::null_mut();
self.fp
.get_semaphore_win32_handle_khr(self.handle, get_info, &mut handle)
.result_with_success(handle)
}

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

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

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 @@ -12,6 +12,7 @@ pub use self::external_fence_fd::ExternalFenceFd;
pub use self::external_memory_fd::ExternalMemoryFd;
pub use self::external_memory_win32::ExternalMemoryWin32;
pub use self::external_semaphore_fd::ExternalSemaphoreFd;
pub use self::external_semaphore_win32::ExternalSemaphoreWin32;
pub use self::get_memory_requirements2::GetMemoryRequirements2;
pub use self::get_physical_device_properties2::GetPhysicalDeviceProperties2;
pub use self::get_surface_capabilities2::GetSurfaceCapabilities2;
Expand Down Expand Up @@ -45,6 +46,7 @@ mod external_fence_fd;
mod external_memory_fd;
mod external_memory_win32;
mod external_semaphore_fd;
mod external_semaphore_win32;
mod get_memory_requirements2;
mod get_physical_device_properties2;
mod get_surface_capabilities2;
Expand Down