Skip to content

Commit

Permalink
Add VK_EXT_image_drm_format_modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Mar 27, 2022
1 parent e537e0b commit b3d8036
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Added

- Added `VK_EXT_image_drm_format_modifier` (#603)

## [0.37.0] - 2022-03-23

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

#[derive(Clone)]
pub struct DrmFormatModifier {
handle: vk::Device,
fp: vk::ExtImageDrmFormatModifierFn,
}

impl DrmFormatModifier {
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()
}

pub unsafe fn get_drm_format_properties_list(
instance: &Instance,
pdevice: vk::PhysicalDevice,
format: vk::Format,
format_properties: vk::FormatProperties,
) -> Vec<vk::DrmFormatModifierPropertiesEXT> {
let mut list = vk::DrmFormatModifierPropertiesListEXT::default();

// Get count of DRM format modifiers for the format.
{
let mut format_properties_2 = vk::FormatProperties2::builder()
.format_properties(format_properties)
.push_next(&mut list);

instance.get_physical_device_format_properties2(
pdevice,
format,
&mut format_properties_2,
);
}

let mut data = Vec::with_capacity(list.drm_format_modifier_count as usize);
list.p_drm_format_modifier_properties = data.as_mut_ptr();

{
let mut format_properties_2 = vk::FormatProperties2::builder()
.format_properties(format_properties)
.push_next(&mut list);

instance.get_physical_device_format_properties2(
pdevice,
format,
&mut format_properties_2,
);
}

data.set_len(list.drm_format_modifier_count as usize);
data
}

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
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use self::debug_marker::DebugMarker;
#[allow(deprecated)]
pub use self::debug_report::DebugReport;
pub use self::debug_utils::DebugUtils;
pub use self::drm_format_modifier::DrmFormatModifier;
pub use self::extended_dynamic_state::ExtendedDynamicState;
pub use self::extended_dynamic_state2::ExtendedDynamicState2;
pub use self::full_screen_exclusive::FullScreenExclusive;
Expand All @@ -21,6 +22,7 @@ mod debug_marker;
#[deprecated(note = "Please use the [DebugUtils](struct.DebugUtils.html) extension instead.")]
mod debug_report;
mod debug_utils;
mod drm_format_modifier;
mod extended_dynamic_state;
mod extended_dynamic_state2;
mod full_screen_exclusive;
Expand Down

0 comments on commit b3d8036

Please sign in to comment.