-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extensions/ext: Add VK_EXT_image_drm_format_modifier
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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() | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters