From 95ff15ff724260d13278c2e38d87c3ef40692ddd Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 14 Aug 2023 15:56:42 +0200 Subject: [PATCH] extensions/ext: Add VK_EXT_host_image_copy (#779) --- Changelog.md | 1 + ash/src/extensions/ext/host_image_copy.rs | 93 +++++++++++++++++++ .../ext/image_compression_control.rs | 7 ++ ash/src/extensions/ext/mod.rs | 2 + 4 files changed, 103 insertions(+) create mode 100644 ash/src/extensions/ext/host_image_copy.rs diff --git a/Changelog.md b/Changelog.md index 9ac3f0b..ae1de9e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `VK_AMD_buffer_marker` device extension (#772) - Added `VK_AMD_shader_info` device extension (#773) - Added `VK_AMDX_shader_enqueue` device extension (#776) +- Added `VK_EXT_host_image_copy` device extension (#779) ### Changed diff --git a/ash/src/extensions/ext/host_image_copy.rs b/ash/src/extensions/ext/host_image_copy.rs new file mode 100644 index 0000000..1049411 --- /dev/null +++ b/ash/src/extensions/ext/host_image_copy.rs @@ -0,0 +1,93 @@ +#[cfg(doc)] +use super::ImageCompressionControl; +use crate::prelude::*; +use crate::vk; +use crate::{Device, Instance}; +use std::ffi::CStr; +use std::mem; + +/// +#[derive(Clone)] +pub struct HostImageCopy { + handle: vk::Device, + fp: vk::ExtHostImageCopyFn, +} + +impl HostImageCopy { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::ExtHostImageCopyFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// + #[inline] + pub unsafe fn copy_memory_to_image( + &self, + copy_memory_to_image_info: &vk::CopyMemoryToImageInfoEXT, + ) -> VkResult<()> { + (self.fp.copy_memory_to_image_ext)(self.handle, copy_memory_to_image_info).result() + } + + /// + #[inline] + pub unsafe fn copy_image_to_memory( + &self, + copy_image_to_memory_info: &vk::CopyImageToMemoryInfoEXT, + ) -> VkResult<()> { + (self.fp.copy_image_to_memory_ext)(self.handle, copy_image_to_memory_info).result() + } + + /// + #[inline] + pub unsafe fn copy_image_to_image( + &self, + copy_image_to_image_info: &vk::CopyImageToImageInfoEXT, + ) -> VkResult<()> { + (self.fp.copy_image_to_image_ext)(self.handle, copy_image_to_image_info).result() + } + + /// + #[inline] + pub unsafe fn transition_image_layout( + &self, + transitions: &[vk::HostImageLayoutTransitionInfoEXT], + ) -> VkResult<()> { + (self.fp.transition_image_layout_ext)( + self.handle, + transitions.len() as u32, + transitions.as_ptr(), + ) + .result() + } + + /// + /// + /// Also available as [`ImageCompressionControl::get_image_subresource_layout2()`] + /// when [`VK_EXT_image_compression_control`] is enabled. + /// + /// [`VK_EXT_image_compression_control`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_compression_control.html + #[inline] + pub unsafe fn get_image_subresource_layout2( + &self, + image: vk::Image, + subresource: &vk::ImageSubresource2EXT, + layout: &mut vk::SubresourceLayout2EXT, + ) { + (self.fp.get_image_subresource_layout2_ext)(self.handle, image, subresource, layout) + } + + pub const NAME: &'static CStr = vk::ExtHostImageCopyFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::ExtHostImageCopyFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} diff --git a/ash/src/extensions/ext/image_compression_control.rs b/ash/src/extensions/ext/image_compression_control.rs index ce436b1..59315ee 100644 --- a/ash/src/extensions/ext/image_compression_control.rs +++ b/ash/src/extensions/ext/image_compression_control.rs @@ -1,3 +1,5 @@ +#[cfg(doc)] +use super::HostImageCopy; use crate::vk; use crate::{Device, Instance}; use std::ffi::CStr; @@ -20,6 +22,11 @@ impl ImageCompressionControl { } /// + /// + /// Also available as [`HostImageCopy::get_image_subresource_layout2()`] + /// when [`VK_EXT_host_image_copy`] is enabled. + /// + /// [`VK_EXT_host_image_copy`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_host_image_copy.html #[inline] pub unsafe fn get_image_subresource_layout2( &self, diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index 9d27e79..b545ed1 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -12,6 +12,7 @@ pub use self::extended_dynamic_state2::ExtendedDynamicState2; pub use self::extended_dynamic_state3::ExtendedDynamicState3; pub use self::full_screen_exclusive::FullScreenExclusive; pub use self::headless_surface::HeadlessSurface; +pub use self::host_image_copy::HostImageCopy; pub use self::image_compression_control::ImageCompressionControl; pub use self::image_drm_format_modifier::ImageDrmFormatModifier; pub use self::mesh_shader::MeshShader; @@ -36,6 +37,7 @@ mod extended_dynamic_state2; mod extended_dynamic_state3; mod full_screen_exclusive; mod headless_surface; +mod host_image_copy; mod image_compression_control; mod image_drm_format_modifier; mod mesh_shader;