-
Notifications
You must be signed in to change notification settings - Fork 194
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_pipeline_binary extension #944
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//! <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_pipeline_binary.html> | ||
|
||
use crate::prelude::*; | ||
use crate::vk; | ||
use crate::RawPtr as _; | ||
use alloc::vec::Vec; | ||
use core::mem; | ||
|
||
impl crate::khr::pipeline_binary::Device { | ||
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreatePipelineBinariesKHR.html> | ||
#[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() | ||
} | ||
|
||
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyPipelineBinaryKHR.html> | ||
#[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(), | ||
) | ||
} | ||
|
||
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPipelineKeyKHR.html> | ||
#[inline] | ||
#[doc(alias = "vkGetPipelineKeyKHR")] | ||
pub unsafe fn get_pipeline_key( | ||
&self, | ||
pipeline_create_info: Option<&vk::PipelineCreateInfoKHR<'_>>, | ||
) -> VkResult<vk::PipelineBinaryKeyKHR<'_>> { | ||
let mut pipeline_key = mem::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) | ||
} | ||
|
||
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPipelineBinaryDataKHR.html> | ||
#[inline] | ||
#[doc(alias = "vkGetPipelineBinaryDataKHR")] | ||
pub unsafe fn get_pipeline_binary_data( | ||
&self, | ||
info: &vk::PipelineBinaryDataInfoKHR<'_>, | ||
pipeline_binary_key: &mut vk::PipelineBinaryKeyKHR<'_>, | ||
) -> VkResult<Vec<u8>> { | ||
read_into_uninitialized_binary_vector(|count, data| { | ||
(self.fp.get_pipeline_binary_data_khr)( | ||
self.handle, | ||
info, | ||
pipeline_binary_key, | ||
count, | ||
data, | ||
) | ||
}) | ||
} | ||
|
||
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkReleaseCapturedPipelineDataKHR.html> | ||
#[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() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||
use alloc::vec::Vec; | ||||||||||
use core::convert::TryInto; | ||||||||||
use core::ffi; | ||||||||||
use core::mem; | ||||||||||
use core::ptr; | ||||||||||
|
||||||||||
|
@@ -37,13 +38,13 @@ impl vk::Result { | |||||||||
/// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore, ensuring all | ||||||||||
/// available data has been read into the vector. | ||||||||||
/// | ||||||||||
/// See for example [`vkEnumerateInstanceExtensionProperties`]: the number of available items may | ||||||||||
/// See for example [`vkEnumerateInstanceExtensionProperties()`]: the number of available items may | ||||||||||
/// change between calls; [`vk::Result::INCOMPLETE`] is returned when the count increased (and the | ||||||||||
/// vector is not large enough after querying the initial size), requiring Ash to try again. | ||||||||||
/// | ||||||||||
/// [`vkEnumerateInstanceExtensionProperties`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html | ||||||||||
/// [`vkEnumerateInstanceExtensionProperties()`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html | ||||||||||
pub(crate) unsafe fn read_into_uninitialized_vector<N: Copy + Default + TryInto<usize>, T>( | ||||||||||
f: impl Fn(&mut N, *mut T) -> vk::Result, | ||||||||||
mut f: impl FnMut(&mut N, *mut T) -> vk::Result, | ||||||||||
) -> VkResult<Vec<T>> | ||||||||||
where | ||||||||||
<N as TryInto<usize>>::Error: core::fmt::Debug, | ||||||||||
|
@@ -64,6 +65,40 @@ where | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/// Calls `f` twice until it does not return [`vk::Result::ERROR_NOT_ENOUGH_SPACE_KHR`], ensuring all | ||||||||||
/// available binary data has been read into the vector. | ||||||||||
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "twice until" is weird word choice. Maybe "at most twice"? |
||||||||||
/// | ||||||||||
/// The first call happens with a [`Vec`] of size `4096`. If this is not adequate, `f` is supposed | ||||||||||
/// to return [`vk::Result::ERROR_NOT_ENOUGH_SPACE_KHR`] while also updating `count` to the desired | ||||||||||
/// number of elements, allowing us to try again. | ||||||||||
/// | ||||||||||
/// This function is _not_ designed to be used with [`vk::Result::INCOMPLETE`], see | ||||||||||
/// [`read_into_uninitialized_vector()`] instead. | ||||||||||
/// | ||||||||||
/// See for example [`vkGetPipelineBinaryDataKHR()`], where the new return code was first introduced. | ||||||||||
/// | ||||||||||
/// [`vkGetPipelineBinaryDataKHR()`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPipelineBinaryDataKHR.html | ||||||||||
pub(crate) unsafe fn read_into_uninitialized_binary_vector( | ||||||||||
mut f: impl FnMut(&mut usize, *mut ffi::c_void) -> vk::Result, | ||||||||||
) -> VkResult<Vec<u8>> { | ||||||||||
let mut count = 4096; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know that binaries are, in practice, usually smaller than this? |
||||||||||
let mut data = Vec::<u8>::with_capacity(count); | ||||||||||
Comment on lines
+84
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
(and adjust the |
||||||||||
let mut err_code = f(&mut count, data.as_mut_ptr().cast()); | ||||||||||
if err_code == vk::Result::ERROR_NOT_ENOUGH_SPACE_KHR { | ||||||||||
debug_assert!( | ||||||||||
count > 4096, | ||||||||||
"Implementation should have updated the value to be higher than the initial request" | ||||||||||
); | ||||||||||
err_code = f(&mut count, data.as_mut_ptr().cast()); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be missing the code to actually expand the
Suggested change
|
||||||||||
debug_assert_ne!( | ||||||||||
err_code, | ||||||||||
vk::Result::ERROR_NOT_ENOUGH_SPACE_KHR, | ||||||||||
"Updated count was still not adequate" | ||||||||||
); | ||||||||||
} | ||||||||||
err_code.set_vec_len_on_success(data, count) | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(feature = "debug")] | ||||||||||
pub(crate) fn debug_flags<Value: Into<u64> + Copy>( | ||||||||||
f: &mut core::fmt::Formatter<'_>, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
vk::PipelineBinaryKeyKHR
be an out parameter, to allow for extension? If this is for some reason undesired, then the lifetime should be'static
.