Skip to content

Commit

Permalink
extensions/ext: Add VK_EXT_host_image_copy device extension
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jul 31, 2023
1 parent f558761 commit 23de7d6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_ANDROID_external_memory_android_hardware_buffer` device extension (#769)
- Added `VK_AMD_buffer_marker` device extension (#772)
- Added `VK_AMD_shader_info` device extension (#773)
- Added `VK_EXT_host_image_copy` device extension (#778)

### Changed

Expand Down
93 changes: 93 additions & 0 deletions ash/src/extensions/ext/host_image_copy.rs
Original file line number Diff line number Diff line change
@@ -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;

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_host_image_copy.html>
#[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 }
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCopyMemoryToImageEXT.html>
#[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()
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCopyImageToMemoryEXT.html>
#[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()
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCopyImageToImageEXT.html>
#[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()
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkTransitionImageLayoutEXT.html>
#[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()
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetImageSubresourceLayout2EXT.html>
///
/// 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
}
}
7 changes: 7 additions & 0 deletions ash/src/extensions/ext/image_compression_control.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(doc)]
use super::HostImageCopy;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
Expand All @@ -20,6 +22,11 @@ impl ImageCompressionControl {
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageSubresourceLayout2EXT.html>
///
/// 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,
Expand Down
2 changes: 2 additions & 0 deletions ash/src/extensions/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 23de7d6

Please sign in to comment.