Skip to content

Commit

Permalink
extensions/khr: Take the remaining p_next-containing structs as &mut
Browse files Browse the repository at this point in the history
Version 2 of `get_physical_device_surface_capabilities` and the matching
`vk::SurfaceCapabilitiesKHR` struct exist solely to provide an `sType`
and `pNext` field to allow extending the original query with additional
data via extension structs.  However, this API when introduced in #530
only returns the `default()`-initialized struct making it just as
constrained as `get_physical_device_surface_capabilities()`.  Solve this
by taking `vk::SurfaceCapabilities2KHR` as `&mut` just like any similar
API.

And just like this, do the same for the remaining:
- `AccelerationStructure::get_acceleration_structure_build_sizes()`
- `ExternalMemoryFd::get_memory_fd_properties()`
- `ExternalMemoryWin32::get_memory_win32_handle_properties()`

In case these structs get extended somewhere down the line, which the
Vulkan API allows for.
  • Loading branch information
MarijnS95 committed May 2, 2023
1 parent dca1a00 commit ad692aa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Inlined struct setters (#602)
- Bumped MSRV from 1.59 to 1.60 (#709)
- Replaced `const fn name()` with associated `NAME` constants (#715)
- extensions/khr: Take the remaining `p_next`-containing structs as `&mut` to allow chains (#744)
- `AccelerationStructure::get_acceleration_structure_build_sizes()`
- `ExternalMemoryFd::get_memory_fd_properties()`
- `ExternalMemoryWin32::get_memory_win32_handle_properties()`
- `GetSurfaceCapabilities2::get_physical_device_surface_capabilities2()`

### Removed

Expand Down
11 changes: 4 additions & 7 deletions ash/src/extensions/khr/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,17 @@ impl AccelerationStructure {
build_type: vk::AccelerationStructureBuildTypeKHR,
build_info: &vk::AccelerationStructureBuildGeometryInfoKHR,
max_primitive_counts: &[u32],
) -> vk::AccelerationStructureBuildSizesInfoKHR {
size_info: &mut vk::AccelerationStructureBuildSizesInfoKHR,
) {
assert_eq!(max_primitive_counts.len(), build_info.geometry_count as _);

let mut size_info = vk::AccelerationStructureBuildSizesInfoKHR::default();

(self.fp.get_acceleration_structure_build_sizes_khr)(
self.handle,
build_type,
build_info,
max_primitive_counts.as_ptr(),
&mut size_info,
);

size_info
size_info,
)
}

pub const NAME: &'static CStr = vk::KhrAccelerationStructureFn::NAME;
Expand Down
13 changes: 4 additions & 9 deletions ash/src/extensions/khr/external_memory_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ impl ExternalMemoryFd {
&self,
handle_type: vk::ExternalMemoryHandleTypeFlags,
fd: i32,
) -> VkResult<vk::MemoryFdPropertiesKHR> {
let mut memory_fd_properties = Default::default();
(self.fp.get_memory_fd_properties_khr)(
self.handle,
handle_type,
fd,
&mut memory_fd_properties,
)
.result_with_success(memory_fd_properties)
memory_fd_properties: &mut vk::MemoryFdPropertiesKHR,
) -> VkResult<()> {
(self.fp.get_memory_fd_properties_khr)(self.handle, handle_type, fd, memory_fd_properties)
.result()
}

pub const NAME: &'static CStr = vk::KhrExternalMemoryFdFn::NAME;
Expand Down
8 changes: 4 additions & 4 deletions ash/src/extensions/khr/external_memory_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ impl ExternalMemoryWin32 {
&self,
handle_type: vk::ExternalMemoryHandleTypeFlags,
handle: vk::HANDLE,
) -> VkResult<vk::MemoryWin32HandlePropertiesKHR> {
let mut memory_win32_handle_properties = Default::default();
memory_win32_handle_properties: &mut vk::MemoryWin32HandlePropertiesKHR,
) -> VkResult<()> {
(self.fp.get_memory_win32_handle_properties_khr)(
self.handle,
handle_type,
handle,
&mut memory_win32_handle_properties,
memory_win32_handle_properties,
)
.result_with_success(memory_win32_handle_properties)
.result()
}

pub const NAME: &'static CStr = vk::KhrExternalMemoryWin32Fn::NAME;
Expand Down
9 changes: 5 additions & 4 deletions ash/src/extensions/khr/get_surface_capabilities2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{Entry, Instance};
use std::ffi::CStr;
use std::mem;

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_get_surface_capabilities2.html>
#[derive(Clone)]
pub struct GetSurfaceCapabilities2 {
fp: vk::KhrGetSurfaceCapabilities2Fn,
Expand All @@ -23,14 +24,14 @@ impl GetSurfaceCapabilities2 {
&self,
physical_device: vk::PhysicalDevice,
surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR,
) -> VkResult<vk::SurfaceCapabilities2KHR> {
let mut surface_capabilities = Default::default();
surface_capabilities: &mut vk::SurfaceCapabilities2KHR,
) -> VkResult<()> {
(self.fp.get_physical_device_surface_capabilities2_khr)(
physical_device,
surface_info,
&mut surface_capabilities,
surface_capabilities,
)
.result_with_success(surface_capabilities)
.result()
}

/// Retrieve the number of elements to pass to [`get_physical_device_surface_formats2()`][Self::get_physical_device_surface_formats2()]
Expand Down

0 comments on commit ad692aa

Please sign in to comment.