Skip to content

extensions/ext: Add VK_EXT_host_image_copy #779

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

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
Comment on lines +26 to +29
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still unsure if this is an OR or AND... Maybe an AND in the case that vk::Image lives on the host?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it's an OR. In vk.xml both extensions have this command inside a <require> block, without extra depends="the_other_extension" attribute.

#[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