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

Fix output structs in command wrappers #214

Merged
merged 2 commits into from
Sep 23, 2023
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 @@ -2,6 +2,7 @@

### Changed
- Added `no_std` compability for `vulkanalia` and `vulkanalia-sys` crates
- Make all extendable output structs parameters in command wrappers (see [#213](https://github.com/KyleMayes/vulkanalia/issues/213) for details)

## [0.22.0] - 2023-09-15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fun Registry.generateCommandWrapper(command: Command): String {
// input when the output type is an extendable struct so that the
// user can provide the extension structs for the information they
// want to be populated in the output parameter.
val extendable = getStructExtensions().containsKey(pointee.getIdentifier())
val extendable = getChainStructs().containsKey(pointee.getIdentifier())

if (output && !extendable) {
// Output pointer parameter (uninit-provided).
Expand All @@ -190,10 +190,15 @@ fun Registry.generateCommandWrapper(command: Command): String {
resultTypes.add(resultType)
resultExprs.add("${current.name}.assume_init()$exprCast")
addArgument("${current.name}.as_mut_ptr()")
} else if (output && extendable) {
} else if (output) {
// Output pointer parameter (user-provided).
params.add("${current.name}: &mut ${pointee.generate()}")
addArgument(current.name.value)
if (current.optional) {
params.add("${current.name}: Option<&mut ${pointee.generate()}>")
addArgument("${current.name}.map_or(ptr::null_mut(), |v| v)")
} else {
params.add("${current.name}: &mut ${pointee.generate()}")
addArgument(current.name.value)
}
} else if (current.type.isOpaquePointer()) {
// Input pointer parameter (opaque).
params.add("${current.name}: ${current.type.generate()}")
Expand Down
21 changes: 13 additions & 8 deletions vulkanalia/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@
//! # use vk::KhrGetPhysicalDeviceProperties2Extension;
//! # let instance: Instance = panic!();
//! # let physical_device: vk::PhysicalDevice = panic!();
//! // Call a command that returns an output pointer chain.
//! // Call a command that populates an output pointer chain.
//!
//! let mut features_11 = vk::PhysicalDeviceVulkan11Features::default();
//! let mut features_12 = vk::PhysicalDeviceVulkan12Features::default();
//! let mut features = vk::PhysicalDeviceFeatures2::builder()
//! .push_next(&mut features_11)
//! .push_next(&mut features_12);
//!
//! let mut features = vk::PhysicalDeviceFeatures2::default();
//! unsafe { instance.get_physical_device_features2_khr(physical_device, &mut features) };
//!
//! // Iterate over the pointers in the output pointer chain.
Expand All @@ -71,14 +76,14 @@
//! // Inspect the pointers in the output pointer chain.
//!
//! let base = unsafe { structs[0].as_base_ref() };
//! assert_eq!(base.s_type, vk::StructureType::PHYSICAL_DEVICE_VULKAN_1_1_FEATURES);
//! let full = unsafe { structs[0].as_ref::<vk::PhysicalDeviceVulkan11Features>() };
//! assert_eq!(full.protected_memory, 1);
//!
//! let base = unsafe { structs[0].as_base_ref() };
//! assert_eq!(base.s_type, vk::StructureType::PHYSICAL_DEVICE_VULKAN_1_2_FEATURES);
//! let full = unsafe { structs[0].as_ref::<vk::PhysicalDeviceVulkan12Features>() };
//! assert_eq!(full.descriptor_indexing, 1);
//! assert_eq!(full.descriptor_indexing, 1);
//!
//! let base = unsafe { structs[1].as_base_ref() };
//! assert_eq!(base.s_type, vk::StructureType::PHYSICAL_DEVICE_VULKAN_1_1_FEATURES);
//! let full = unsafe { structs[1].as_ref::<vk::PhysicalDeviceVulkan11Features>() };
//! assert_eq!(full.protected_memory, 1);
//! ```

use core::ffi::c_void;
Expand Down
Loading
Loading