From a97aa7d8292fc74f51ed5236ad841b97adf06559 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 30 Aug 2024 15:22:40 +0200 Subject: [PATCH] extensions/khr: Add VK_KHR_pipeline_binary extension --- Changelog.md | 1 + ash/src/extensions/khr/mod.rs | 1 + ash/src/extensions/khr/pipeline_binary.rs | 94 +++++++++++++++++++++++ ash/src/prelude.rs | 4 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 ash/src/extensions/khr/pipeline_binary.rs diff --git a/Changelog.md b/Changelog.md index 25c0beb62..a53b0883c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update Vulkan-Headers to 1.3.296 (#910) - Added `VK_EXT_metal_objects` device extension (#942) +- Added `VK_KHR_pipeline_binary` device extension (#944) ## [0.38.0] - 2024-04-01 diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index 5552598be..b72eb560c 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -29,6 +29,7 @@ pub mod maintenance4; pub mod maintenance5; pub mod maintenance6; pub mod performance_query; +pub mod pipeline_binary; pub mod pipeline_executable_properties; pub mod present_wait; pub mod push_descriptor; diff --git a/ash/src/extensions/khr/pipeline_binary.rs b/ash/src/extensions/khr/pipeline_binary.rs new file mode 100644 index 000000000..e641b9b2e --- /dev/null +++ b/ash/src/extensions/khr/pipeline_binary.rs @@ -0,0 +1,94 @@ +//! + +use crate::prelude::*; +use crate::vk; +use crate::RawPtr as _; +use core::ffi::c_void; +use core::mem::MaybeUninit; + +impl crate::khr::pipeline_binary::Device { + /// + #[inline] + #[doc(alias = "vkCreatePipelineBinariesKHR")] + pub unsafe fn create_pipeline_binaries( + &self, + create_info: &vk::PipelineBinaryCreateInfoKHR<'_>, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + binaries: &mut vk::PipelineBinaryHandlesInfoKHR<'_>, + ) -> VkResult<()> { + (self.fp.create_pipeline_binaries_khr)( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + binaries, + ) + .result() + } + + /// + #[inline] + #[doc(alias = "vkDestroyPipelineBinaryKHR")] + pub unsafe fn destroy_pipeline_binary( + &self, + pipeline_binary: vk::PipelineBinaryKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) { + (self.fp.destroy_pipeline_binary_khr)( + self.handle, + pipeline_binary, + allocation_callbacks.as_raw_ptr(), + ) + } + + /// + #[inline] + #[doc(alias = "vkGetPipelineKeyKHR")] + pub unsafe fn get_pipeline_key( + &self, + pipeline_create_info: Option<&vk::PipelineCreateInfoKHR<'_>>, + ) -> VkResult> { + let mut pipeline_key = MaybeUninit::uninit(); + (self.fp.get_pipeline_key_khr)( + self.handle, + pipeline_create_info.as_raw_ptr(), + pipeline_key.as_mut_ptr(), + ) + .assume_init_on_success(pipeline_key) + } + + /// + #[inline] + #[doc(alias = "vkGetPipelineBinaryDataKHR")] + pub unsafe fn get_pipeline_binary_data( + &self, + info: &vk::PipelineBinaryDataInfoKHR<'_>, + pipeline_binary_key: &mut vk::PipelineBinaryKeyKHR<'_>, + ) -> VkResult> { + // TODO: This returns NOT_ENOUGH_SPACE_KHR, not INCOMPLETE (because nothing is written, instead of returning an impartial result) + read_into_uninitialized_vector(|count, data| { + (self.fp.get_pipeline_binary_data_khr)( + self.handle, + info, + pipeline_binary_key, + count, + data as *mut c_void, + ) + }) + } + + /// + #[inline] + #[doc(alias = "vkReleaseCapturedPipelineDataKHR")] + pub unsafe fn release_captured_pipeline_data( + &self, + info: &vk::ReleaseCapturedPipelineDataInfoKHR<'_>, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) -> VkResult<()> { + (self.fp.release_captured_pipeline_data_khr)( + self.handle, + info, + allocation_callbacks.as_raw_ptr(), + ) + .result() + } +} diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs index 1341960f4..087f1222c 100644 --- a/ash/src/prelude.rs +++ b/ash/src/prelude.rs @@ -43,7 +43,7 @@ impl vk::Result { /// /// [`vkEnumerateInstanceExtensionProperties`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html pub(crate) unsafe fn read_into_uninitialized_vector, T>( - f: impl Fn(&mut N, *mut T) -> vk::Result, + mut f: impl FnMut(&mut N, *mut T) -> vk::Result, ) -> VkResult> where >::Error: core::fmt::Debug, @@ -81,7 +81,7 @@ pub(crate) unsafe fn read_into_defaulted_vector< N: Copy + Default + TryInto, T: Default + Clone, >( - f: impl Fn(&mut N, *mut T) -> vk::Result, + mut f: impl FnMut(&mut N, *mut T) -> vk::Result, ) -> VkResult> where >::Error: core::fmt::Debug,