Skip to content

Commit

Permalink
extensions/ext: Add VK_EXT_image_drm_format_modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Apr 5, 2022
1 parent 3121816 commit 4805666
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Update Vulkan-Headers to 1.3.210 (#605)
- Added `VK_EXT_image_drm_format_modifier` device extension (#603)

### Removed

Expand Down
126 changes: 126 additions & 0 deletions ash/src/extensions/ext/image_drm_format_modifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use crate::extensions::khr::GetPhysicalDeviceProperties2;
use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html>
#[derive(Clone)]
pub struct ImageDrmFormatModifier {
handle: vk::Device,
fp: vk::ExtImageDrmFormatModifierFn,
}

impl ImageDrmFormatModifier {
pub fn new(instance: &Instance, device: &Device) -> Self {
let handle = device.handle();
let fp = vk::ExtImageDrmFormatModifierFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
});
Self { handle, fp }
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageDrmFormatModifierPropertiesEXT.html>
pub unsafe fn get_image_drm_format_modifier_properties(
&self,
image: vk::Image,
properties: &mut vk::ImageDrmFormatModifierPropertiesEXT,
) -> VkResult<()> {
(self.fp.get_image_drm_format_modifier_properties_ext)(self.handle, image, properties)
.result()
}

/// Retrieve a list of DRM format modifiers the supported for a format on the physical device.
///
/// This is equivalent to calling [`Instance::get_physical_device_format_properties2`] with
/// [`DrmFormatModifierPropertiesListEXT`](vk::DrmFormatModifierPropertiesListEXT) extending [`FormatProperties2`](vk::FormatProperties2).
///
/// # Safety
///
/// * This function requires the [`VK_EXT_image_drm_format_modifier`] extension.
/// * This function requires Vulkan 1.1.
///
/// If you use Vulkan 1.0, use [`GetPhysicalDeviceProperties2::get_drm_format_properties_list`]
/// instead.
///
/// [`VK_EXT_image_drm_format_modifier`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html
pub unsafe fn get_drm_format_properties_list(
instance: &Instance,
pdevice: vk::PhysicalDevice,
format: vk::Format,
mut format_properties: &mut vk::FormatProperties2,
) -> Vec<vk::DrmFormatModifierPropertiesEXT> {
let mut list = vk::DrmFormatModifierPropertiesListEXT::default();
format_properties.push_next(&mut list);

read_into_uninitialized_vector(|count, data| {
// The data pointer will always be null on the first invocation of the closure.
list.p_drm_format_modifier_properties = data;

instance.get_physical_device_format_properties2(
pdevice,
format,
&mut format_properties,
);

*count = list.drm_format_modifier_count;

vk::Result::SUCCESS
})
// The closure always returns SUCCESS
.unwrap()
}

pub const fn name() -> &'static CStr {
vk::ExtImageDrmFormatModifierFn::name()
}

pub fn fp(&self) -> &vk::ExtImageDrmFormatModifierFn {
&self.fp
}

pub fn device(&self) -> vk::Device {
self.handle
}
}

// Vulkan 1.0
impl GetPhysicalDeviceProperties2 {
/// Retrieve a list of DRM format modifiers the supported for a format on the physical device.
///
/// This is equivalent to calling [`GetPhysicalDeviceProperties2::get_physical_device_format_properties2`] with
/// [`DrmFormatModifierPropertiesListEXT`](vk::DrmFormatModifierPropertiesListEXT) extending [`FormatProperties2KHR`](vk::FormatProperties2KHR).
///
/// # Safety
///
/// This function requires the [`VK_EXT_image_drm_format_modifier`] extension.
///
/// [`VK_EXT_image_drm_format_modifier`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html
pub unsafe fn get_drm_format_properties_list(
&self,
pdevice: vk::PhysicalDevice,
format: vk::Format,
mut format_properties: &mut vk::FormatProperties2KHR,
) -> Vec<vk::DrmFormatModifierPropertiesEXT> {
let mut list = vk::DrmFormatModifierPropertiesListEXT::default();
format_properties.push_next(&mut list);

read_into_uninitialized_vector(|count, data| {
// The data pointer will always be null on the first invocation of the closure.
list.p_drm_format_modifier_properties = data;

self.get_physical_device_format_properties2(
pdevice,
format,
&mut format_properties,
);

*count = list.drm_format_modifier_count;

vk::Result::SUCCESS
})
// The closure always returns SUCCESS
.unwrap()
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use self::extended_dynamic_state::ExtendedDynamicState;
pub use self::extended_dynamic_state2::ExtendedDynamicState2;
pub use self::full_screen_exclusive::FullScreenExclusive;
pub use self::headless_surface::HeadlessSurface;
pub use self::image_drm_format_modifier::ImageDrmFormatModifier;
pub use self::metal_surface::MetalSurface;
pub use self::physical_device_drm::PhysicalDeviceDrm;
pub use self::private_data::PrivateData;
Expand All @@ -25,6 +26,7 @@ mod extended_dynamic_state;
mod extended_dynamic_state2;
mod full_screen_exclusive;
mod headless_surface;
mod image_drm_format_modifier;
mod metal_surface;
mod physical_device_drm;
mod private_data;
Expand Down
4 changes: 2 additions & 2 deletions ash/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl vk::Result {
///
/// [`vkEnumerateInstanceExtensionProperties`]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceExtensionProperties.html
pub(crate) unsafe fn read_into_uninitialized_vector<N: Copy + Default + TryInto<usize>, T>(
f: impl Fn(&mut N, *mut T) -> vk::Result,
mut f: impl FnMut(&mut N, *mut T) -> vk::Result,
) -> VkResult<Vec<T>>
where
<N as TryInto<usize>>::Error: std::fmt::Debug,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) unsafe fn read_into_defaulted_vector<
N: Copy + Default + TryInto<usize>,
T: Default + Clone,
>(
f: impl Fn(&mut N, *mut T) -> vk::Result,
mut f: impl FnMut(&mut N, *mut T) -> vk::Result,
) -> VkResult<Vec<T>>
where
<N as TryInto<usize>>::Error: std::fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion generator/Vulkan-Headers
Submodule Vulkan-Headers updated 45 files
+0 −32 .github/ISSUE_TEMPLATE/bug_report.md
+6 −13 BUILD.gn
+53 −50 include/vk_video/vulkan_video_codec_h264std.h
+7 −12 include/vk_video/vulkan_video_codec_h264std_decode.h
+28 −63 include/vk_video/vulkan_video_codec_h264std_encode.h
+120 −119 include/vk_video/vulkan_video_codec_h265std.h
+6 −12 include/vk_video/vulkan_video_codec_h265std_decode.h
+51 −61 include/vk_video/vulkan_video_codec_h265std_encode.h
+1 −1 include/vk_video/vulkan_video_codecs_common.h
+1 −1 include/vulkan/vk_platform.h
+1 −1 include/vulkan/vulkan.h
+3,283 −2,797 include/vulkan/vulkan.hpp
+3 −3 include/vulkan/vulkan_android.h
+134 −190 include/vulkan/vulkan_beta.h
+993 −1,736 include/vulkan/vulkan_core.h
+1 −1 include/vulkan/vulkan_directfb.h
+6,969 −3,550 include/vulkan/vulkan_enums.hpp
+0 −7,333 include/vulkan/vulkan_format_traits.hpp
+1 −1 include/vulkan/vulkan_fuchsia.h
+8,406 −7,348 include/vulkan/vulkan_funcs.hpp
+1 −1 include/vulkan/vulkan_ggp.h
+5,087 −3,971 include/vulkan/vulkan_handles.hpp
+2,211 −1,768 include/vulkan/vulkan_hash.hpp
+1 −1 include/vulkan/vulkan_ios.h
+1 −1 include/vulkan/vulkan_macos.h
+1 −1 include/vulkan/vulkan_metal.h
+6,804 −6,287 include/vulkan/vulkan_raii.hpp
+1 −1 include/vulkan/vulkan_screen.h
+25,768 −28,441 include/vulkan/vulkan_structs.hpp
+1 −1 include/vulkan/vulkan_vi.h
+1 −1 include/vulkan/vulkan_wayland.h
+1 −1 include/vulkan/vulkan_win32.h
+1 −1 include/vulkan/vulkan_xcb.h
+1 −1 include/vulkan/vulkan_xlib.h
+1 −1 include/vulkan/vulkan_xlib_xrandr.h
+1 −1 registry/apiconventions.py
+2 −6 registry/cgenerator.py
+1 −1 registry/conventions.py
+2 −5 registry/generator.py
+3 −3 registry/genvk.py
+1 −1 registry/reg.py
+1 −1 registry/spec_tools/util.py
+3,294 −4,584 registry/validusage.json
+941 −1,744 registry/vk.xml
+2 −2 registry/vkconventions.py

0 comments on commit 4805666

Please sign in to comment.