Skip to content
Draft
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
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@ name: CI
jobs:
check:
name: Check
runs-on: ubuntu-latest
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- run: cargo check --workspace --all-targets --all-features

check_msrv:
name: Check ash MSRV (1.60.0)
runs-on: ubuntu-latest
name: Check ash MSRV (1.63.0)
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: dtolnay/rust-toolchain@1.60.0
- uses: dtolnay/rust-toolchain@1.63.0
- run: cargo check -p ash -p ash-rewrite --all-features

check_ash_window_msrv:
name: Check ash-window MSRV (1.64.0)
runs-on: ubuntu-latest
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: dtolnay/[email protected]
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Define `Display` as `c_void` instead of `*mut c_void` to match Xlib (#751)
- `VK_KHR_device_group_creation`: Take borrow of `Entry` in `fn new()` (#753)
- `VK_KHR_device_group_creation`: Rename `vk::Instance`-returning function from `device()` to `instance()` (#759)
- extensions: Use Rust IO-safety types (`OwnedFd`, `BorrowedFd`, `OwnedHandle`, `BorrowedHandle`) in function signatures to signify ownership transfer (#791)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion ash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "../README.md"
keywords = ["vulkan", "graphic"]
documentation = "https://docs.rs/ash"
edition = "2021"
rust-version = "1.60.0"
rust-version = "1.63.0"

[dependencies]
libloading = { version = "0.7", optional = true }
Expand Down
18 changes: 13 additions & 5 deletions ash/src/extensions/ext/acquire_drm_display.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(unix)]

use crate::prelude::*;
use crate::vk;
use crate::{Entry, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::unix::io::{AsRawFd, BorrowedFd};

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_EXT_acquire_drm_display.html>
#[derive(Clone)]
Expand All @@ -24,23 +27,28 @@ impl AcquireDrmDisplay {
pub unsafe fn acquire_drm_display(
&self,
physical_device: vk::PhysicalDevice,
drm_fd: i32,
drm_fd: BorrowedFd<'_>,
display: vk::DisplayKHR,
) -> VkResult<()> {
(self.fp.acquire_drm_display_ext)(physical_device, drm_fd, display).result()
(self.fp.acquire_drm_display_ext)(physical_device, drm_fd.as_raw_fd(), display).result()
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDrmDisplayEXT.html>
#[inline]
pub unsafe fn get_drm_display(
&self,
physical_device: vk::PhysicalDevice,
drm_fd: i32,
drm_fd: BorrowedFd<'_>,
connector_id: u32,
) -> VkResult<vk::DisplayKHR> {
let mut display = mem::MaybeUninit::uninit();
(self.fp.get_drm_display_ext)(physical_device, drm_fd, connector_id, display.as_mut_ptr())
.assume_init_on_success(display)
(self.fp.get_drm_display_ext)(
physical_device,
drm_fd.as_raw_fd(),
connector_id,
display.as_mut_ptr(),
)
.assume_init_on_success(display)
}

pub const NAME: &'static CStr = vk::ExtAcquireDrmDisplayFn::NAME;
Expand Down
1 change: 1 addition & 0 deletions ash/src/extensions/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(unix)]
pub use self::acquire_drm_display::AcquireDrmDisplay;
pub use self::buffer_device_address::BufferDeviceAddress;
pub use self::calibrated_timestamps::CalibratedTimestamps;
Expand Down
18 changes: 16 additions & 2 deletions ash/src/extensions/khr/external_fence_fd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#![cfg(unix)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
// use std::os::fd::OwnedFd;
use std::os::unix::io::{FromRawFd, OwnedFd};

#[derive(Clone)]
pub struct ExternalFenceFd {
Expand All @@ -26,10 +30,20 @@ impl ExternalFenceFd {
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetFenceFdKHR.html>
///
/// May return [`None`] if the fence has already been signaled at the time this function is
/// called.
#[inline]
pub unsafe fn get_fence_fd(&self, get_info: &vk::FenceGetFdInfoKHR) -> VkResult<i32> {
pub unsafe fn get_fence_fd(
&self,
get_info: &vk::FenceGetFdInfoKHR,
) -> VkResult<Option<OwnedFd>> {
Comment on lines +34 to +40
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a little update to denote that this can be None (when Vulkan sets it to -1).

The docs for the equivalent Win32 function don't state this though, perhaps there will always be a fence on Windows.

I'll take a look at the conflicts and remaining comments about polyfilling after getting some other PRs in.

let mut fd = -1;
(self.fp.get_fence_fd_khr)(self.handle, get_info, &mut fd).result_with_success(fd)
(self.fp.get_fence_fd_khr)(self.handle, get_info, &mut fd).result()?;
Ok(match fd {
-1 => None,
fd => Some(OwnedFd::from_raw_fd(fd)),
})
}

pub const NAME: &'static CStr = vk::KhrExternalFenceFdFn::NAME;
Expand Down
9 changes: 6 additions & 3 deletions ash/src/extensions/khr/external_fence_win32.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(windows)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::windows::io::{FromRawHandle, OwnedHandle};
use std::ptr;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence_win32.html>
Expand Down Expand Up @@ -35,10 +38,10 @@ impl ExternalFenceWin32 {
pub unsafe fn get_fence_win32_handle(
&self,
get_info: &vk::FenceGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
) -> VkResult<OwnedHandle> {
let mut handle = ptr::null_mut();
(self.fp.get_fence_win32_handle_khr)(self.handle, get_info, &mut handle)
.result_with_success(handle)
(self.fp.get_fence_win32_handle_khr)(self.handle, get_info, &mut handle).result()?;
Ok(OwnedHandle::from_raw_handle(handle))
}

pub const NAME: &'static CStr = vk::KhrExternalFenceWin32Fn::NAME;
Expand Down
19 changes: 14 additions & 5 deletions ash/src/extensions/khr/external_memory_fd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(unix)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::unix::io::{AsRawFd, BorrowedFd, FromRawFd, OwnedFd};

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory_fd.html>
#[derive(Clone)]
Expand All @@ -22,21 +25,27 @@ impl ExternalMemoryFd {

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryFdKHR.html>
#[inline]
pub unsafe fn get_memory_fd(&self, get_fd_info: &vk::MemoryGetFdInfoKHR) -> VkResult<i32> {
pub unsafe fn get_memory_fd(&self, get_fd_info: &vk::MemoryGetFdInfoKHR) -> VkResult<OwnedFd> {
let mut fd = -1;
(self.fp.get_memory_fd_khr)(self.handle, get_fd_info, &mut fd).result_with_success(fd)
(self.fp.get_memory_fd_khr)(self.handle, get_fd_info, &mut fd).result()?;
Ok(OwnedFd::from_raw_fd(fd))
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryFdPropertiesKHR.html>
#[inline]
pub unsafe fn get_memory_fd_properties(
&self,
handle_type: vk::ExternalMemoryHandleTypeFlags,
fd: i32,
fd: BorrowedFd<'_>,
memory_fd_properties: &mut vk::MemoryFdPropertiesKHR,
) -> VkResult<()> {
(self.fp.get_memory_fd_properties_khr)(self.handle, handle_type, fd, memory_fd_properties)
.result()
(self.fp.get_memory_fd_properties_khr)(
self.handle,
handle_type,
fd.as_raw_fd(),
memory_fd_properties,
)
.result()
}

pub const NAME: &'static CStr = vk::KhrExternalMemoryFdFn::NAME;
Expand Down
13 changes: 8 additions & 5 deletions ash/src/extensions/khr/external_memory_win32.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(windows)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::windows::io::{AsRawHandle, BorrowedHandle, FromRawHandle, OwnedHandle};
use std::ptr;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory_win32.html>
Expand All @@ -26,24 +29,24 @@ impl ExternalMemoryWin32 {
pub unsafe fn get_memory_win32_handle(
&self,
create_info: &vk::MemoryGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
) -> VkResult<OwnedHandle> {
let mut handle = ptr::null_mut();
(self.fp.get_memory_win32_handle_khr)(self.handle, create_info, &mut handle)
.result_with_success(handle)
(self.fp.get_memory_win32_handle_khr)(self.handle, create_info, &mut handle).result()?;
Ok(OwnedHandle::from_raw_handle(handle))
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryWin32HandlePropertiesKHR.html>
#[inline]
pub unsafe fn get_memory_win32_handle_properties(
&self,
handle_type: vk::ExternalMemoryHandleTypeFlags,
handle: vk::HANDLE,
handle: BorrowedHandle<'_>,
memory_win32_handle_properties: &mut vk::MemoryWin32HandlePropertiesKHR,
) -> VkResult<()> {
(self.fp.get_memory_win32_handle_properties_khr)(
self.handle,
handle_type,
handle,
handle.as_raw_handle(),
memory_win32_handle_properties,
)
.result()
Expand Down
11 changes: 9 additions & 2 deletions ash/src/extensions/khr/external_semaphore_fd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(unix)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::unix::io::{FromRawFd, OwnedFd};

#[derive(Clone)]
pub struct ExternalSemaphoreFd {
Expand Down Expand Up @@ -30,9 +33,13 @@ impl ExternalSemaphoreFd {

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSemaphoreFdKHR.html>
#[inline]
pub unsafe fn get_semaphore_fd(&self, get_info: &vk::SemaphoreGetFdInfoKHR) -> VkResult<i32> {
pub unsafe fn get_semaphore_fd(
&self,
get_info: &vk::SemaphoreGetFdInfoKHR,
) -> VkResult<OwnedFd> {
let mut fd = -1;
(self.fp.get_semaphore_fd_khr)(self.handle, get_info, &mut fd).result_with_success(fd)
(self.fp.get_semaphore_fd_khr)(self.handle, get_info, &mut fd).result()?;
Ok(OwnedFd::from_raw_fd(fd))
}

pub const NAME: &'static CStr = vk::KhrExternalSemaphoreFdFn::NAME;
Expand Down
9 changes: 6 additions & 3 deletions ash/src/extensions/khr/external_semaphore_win32.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![cfg(windows)]

use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::os::windows::io::{FromRawHandle, OwnedHandle};
use std::ptr;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_win32.html>
Expand Down Expand Up @@ -35,10 +38,10 @@ impl ExternalSemaphoreWin32 {
pub unsafe fn get_semaphore_win32_handle(
&self,
get_info: &vk::SemaphoreGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
) -> VkResult<OwnedHandle> {
let mut handle = ptr::null_mut();
(self.fp.get_semaphore_win32_handle_khr)(self.handle, get_info, &mut handle)
.result_with_success(handle)
(self.fp.get_semaphore_win32_handle_khr)(self.handle, get_info, &mut handle).result()?;
Ok(OwnedHandle::from_raw_handle(handle))
}

pub const NAME: &'static CStr = vk::KhrExternalSemaphoreWin32Fn::NAME;
Expand Down
6 changes: 6 additions & 0 deletions ash/src/extensions/khr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ pub use self::display::Display;
pub use self::display_swapchain::DisplaySwapchain;
pub use self::draw_indirect_count::DrawIndirectCount;
pub use self::dynamic_rendering::DynamicRendering;
#[cfg(unix)]
pub use self::external_fence_fd::ExternalFenceFd;
#[cfg(windows)]
pub use self::external_fence_win32::ExternalFenceWin32;
#[cfg(unix)]
pub use self::external_memory_fd::ExternalMemoryFd;
#[cfg(windows)]
pub use self::external_memory_win32::ExternalMemoryWin32;
#[cfg(unix)]
pub use self::external_semaphore_fd::ExternalSemaphoreFd;
#[cfg(windows)]
pub use self::external_semaphore_win32::ExternalSemaphoreWin32;
pub use self::get_memory_requirements2::GetMemoryRequirements2;
pub use self::get_physical_device_properties2::GetPhysicalDeviceProperties2;
Expand Down