diff --git a/Changelog.md b/Changelog.md index 5decd99..f7185f3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update Vulkan-Headers to 1.3.254 (#760) - Added `VK_NV_memory_decompression` device extension (#761) - Added `VK_GOOGLE_display_timing` device extension (#765) +- Added `VK_ANDROID_external_memory_android_hardware_buffer` device extension (#769) ### Changed diff --git a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs new file mode 100644 index 0000000..56954f3 --- /dev/null +++ b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs @@ -0,0 +1,56 @@ +use crate::prelude::*; +use crate::vk; +use crate::{Device, Instance}; +use std::ffi::CStr; +use std::mem; + +/// +#[derive(Clone)] +pub struct ExternalMemoryAndroidHardwareBuffer { + handle: vk::Device, + fp: vk::AndroidExternalMemoryAndroidHardwareBufferFn, +} + +impl ExternalMemoryAndroidHardwareBuffer { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::AndroidExternalMemoryAndroidHardwareBufferFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// + #[inline] + pub unsafe fn get_android_hardware_buffer_properties( + &self, + buffer: *const vk::AHardwareBuffer, + properties: &mut vk::AndroidHardwareBufferPropertiesANDROID, + ) -> VkResult<()> { + (self.fp.get_android_hardware_buffer_properties_android)(self.handle, buffer, properties) + .result() + } + + /// + #[inline] + pub unsafe fn get_memory_android_hardware_buffer( + &self, + info: &vk::MemoryGetAndroidHardwareBufferInfoANDROID, + ) -> VkResult<*mut vk::AHardwareBuffer> { + let mut buffer = std::ptr::null_mut(); + (self.fp.get_memory_android_hardware_buffer_android)(self.handle, info, &mut buffer) + .result_with_success(buffer) + } + + pub const NAME: &'static CStr = vk::AndroidExternalMemoryAndroidHardwareBufferFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::AndroidExternalMemoryAndroidHardwareBufferFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} diff --git a/ash/src/extensions/android/mod.rs b/ash/src/extensions/android/mod.rs new file mode 100644 index 0000000..f5969c5 --- /dev/null +++ b/ash/src/extensions/android/mod.rs @@ -0,0 +1,3 @@ +pub use self::external_memory_android_hardware_buffer::ExternalMemoryAndroidHardwareBuffer; + +mod external_memory_android_hardware_buffer; diff --git a/ash/src/extensions/mod.rs b/ash/src/extensions/mod.rs index 99d0c1f..90f8332 100644 --- a/ash/src/extensions/mod.rs +++ b/ash/src/extensions/mod.rs @@ -1,3 +1,4 @@ +pub mod android; pub mod ext; pub mod google; pub mod khr;