diff --git a/Changelog.md b/Changelog.md index 8b0e402..c86651d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `VK_EXT_mesh_shader` device extension (#657) - Added `VK_EXT_acquire_drm_display` instance extension (#668) - Added `VK_EXT_extended_dynamic_state3` device extension (#671) +- Added `VK_EXT_descriptor_buffer` instance extension (#679) ### Fixed diff --git a/ash/src/extensions/ext/descriptor_buffer.rs b/ash/src/extensions/ext/descriptor_buffer.rs new file mode 100644 index 0000000..4503f5b --- /dev/null +++ b/ash/src/extensions/ext/descriptor_buffer.rs @@ -0,0 +1,211 @@ +use crate::prelude::*; +use crate::vk; +use crate::{Device, Instance}; +use std::ffi::CStr; +use std::mem; + +/// +#[derive(Clone)] +pub struct DescriptorBuffer { + handle: vk::Device, + fp: vk::ExtDescriptorBufferFn, +} + +impl DescriptorBuffer { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::ExtDescriptorBufferFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// + #[inline] + pub unsafe fn get_descriptor_set_layout_size( + &self, + layout: vk::DescriptorSetLayout, + ) -> vk::DeviceSize { + let mut count = 0; + (self.fp.get_descriptor_set_layout_size_ext)(self.handle, layout, &mut count); + count + } + + /// + #[inline] + pub unsafe fn get_descriptor_set_layout_binding_offset( + &self, + layout: vk::DescriptorSetLayout, + binding: u32, + ) -> vk::DeviceSize { + let mut offset = 0; + (self.fp.get_descriptor_set_layout_binding_offset_ext)( + self.handle, + layout, + binding, + &mut offset, + ); + offset + } + + /// + #[inline] + pub unsafe fn get_descriptor( + &self, + descriptor_info: &vk::DescriptorGetInfoEXT, + descriptor: &mut [u8], + ) { + (self.fp.get_descriptor_ext)( + self.handle, + descriptor_info, + descriptor.len(), + descriptor.as_mut_ptr().cast(), + ) + } + + /// + #[inline] + pub unsafe fn cmd_bind_descriptor_buffers( + &self, + command_buffer: vk::CommandBuffer, + binding_info: &[vk::DescriptorBufferBindingInfoEXT], + ) { + (self.fp.cmd_bind_descriptor_buffers_ext)( + command_buffer, + binding_info.len() as u32, + binding_info.as_ptr(), + ) + } + + /// + #[inline] + pub unsafe fn cmd_set_descriptor_buffer_offsets( + &self, + command_buffer: vk::CommandBuffer, + pipeline_bind_point: vk::PipelineBindPoint, + layout: vk::PipelineLayout, + first_set: u32, + buffer_indices: &[u32], + offsets: &[vk::DeviceSize], + ) { + assert_eq!(buffer_indices.len(), offsets.len()); + (self.fp.cmd_set_descriptor_buffer_offsets_ext)( + command_buffer, + pipeline_bind_point, + layout, + first_set, + buffer_indices.len() as u32, + buffer_indices.as_ptr(), + offsets.as_ptr(), + ) + } + + /// + #[inline] + pub unsafe fn cmd_bind_descriptor_buffer_embedded_samplers( + &self, + command_buffer: vk::CommandBuffer, + pipeline_bind_point: vk::PipelineBindPoint, + layout: vk::PipelineLayout, + set: u32, + ) { + (self.fp.cmd_bind_descriptor_buffer_embedded_samplers_ext)( + command_buffer, + pipeline_bind_point, + layout, + set, + ) + } + + /// + #[inline] + pub unsafe fn get_buffer_opaque_capture_descriptor_data( + &self, + info: &vk::BufferCaptureDescriptorDataInfoEXT, + data: &mut [u8], + ) -> VkResult<()> { + (self.fp.get_buffer_opaque_capture_descriptor_data_ext)( + self.handle, + info, + data.as_mut_ptr().cast(), + ) + .result() + } + + /// + #[inline] + pub unsafe fn get_image_opaque_capture_descriptor_data( + &self, + info: &vk::ImageCaptureDescriptorDataInfoEXT, + data: &mut [u8], + ) -> VkResult<()> { + (self.fp.get_image_opaque_capture_descriptor_data_ext)( + self.handle, + info, + data.as_mut_ptr().cast(), + ) + .result() + } + + /// + #[inline] + pub unsafe fn get_image_view_opaque_capture_descriptor_data( + &self, + info: &vk::ImageViewCaptureDescriptorDataInfoEXT, + data: &mut [u8], + ) -> VkResult<()> { + (self.fp.get_image_view_opaque_capture_descriptor_data_ext)( + self.handle, + info, + data.as_mut_ptr().cast(), + ) + .result() + } + + /// + #[inline] + pub unsafe fn get_sampler_opaque_capture_descriptor_data( + &self, + info: &vk::SamplerCaptureDescriptorDataInfoEXT, + data: &mut [u8], + ) -> VkResult<()> { + (self.fp.get_sampler_opaque_capture_descriptor_data_ext)( + self.handle, + info, + data.as_mut_ptr().cast(), + ) + .result() + } + + /// + #[inline] + pub unsafe fn get_acceleration_structure_opaque_capture_descriptor_data( + &self, + info: &vk::AccelerationStructureCaptureDescriptorDataInfoEXT, + data: &mut [u8], + ) -> VkResult<()> { + (self + .fp + .get_acceleration_structure_opaque_capture_descriptor_data_ext)( + self.handle, + info, + data.as_mut_ptr().cast(), + ) + .result() + } + + #[inline] + pub const fn name() -> &'static CStr { + vk::ExtDescriptorBufferFn::name() + } + + #[inline] + pub fn fp(&self) -> &vk::ExtDescriptorBufferFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index 4e53e95..26a78f7 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -6,6 +6,7 @@ pub use self::debug_marker::DebugMarker; #[allow(deprecated)] pub use self::debug_report::DebugReport; pub use self::debug_utils::DebugUtils; +pub use self::descriptor_buffer::DescriptorBuffer; pub use self::extended_dynamic_state::ExtendedDynamicState; pub use self::extended_dynamic_state2::ExtendedDynamicState2; pub use self::extended_dynamic_state3::ExtendedDynamicState3; @@ -28,6 +29,7 @@ mod debug_marker; #[deprecated(note = "Please use the [DebugUtils](struct.DebugUtils.html) extension instead.")] mod debug_report; mod debug_utils; +mod descriptor_buffer; mod extended_dynamic_state; mod extended_dynamic_state2; mod extended_dynamic_state3;