Skip to content
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

Import image from dma_buf following VK_EXT_external_memory_dma_buf #2145

Merged
merged 13 commits into from
Apr 1, 2023
Merged
Prev Previous commit
Next Next commit
Add some more VUIDs
Or explanations of why they cannot yet be added
  • Loading branch information
spaghetti-stack committed Mar 27, 2023
commit c1f9cbe568a9874ea082009d9c254e9491d105e9
3 changes: 3 additions & 0 deletions vulkano/src/device/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,9 @@ impl PhysicalDevice {
image_view_type.validate_physical_device(self)?;
}

// TODO: VUID-VkPhysicalDeviceImageFormatInfo2-tiling-02313
// Currently there is nothing in Vulkano for for adding a VkImageFormatListCreateInfo.

Ok(())
}

Expand Down
34 changes: 21 additions & 13 deletions vulkano/src/image/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
image::{sys::ImageCreateInfo, view::ImageView, ImageFormatInfo},
memory::{
allocator::{
AllocationCreateInfo, AllocationType, MemoryAllocatePreference,
MemoryAllocator, MemoryUsage,
AllocationCreateInfo, AllocationType, MemoryAllocatePreference, MemoryAllocator,
MemoryUsage,
},
DedicatedAllocation, DeviceMemoryError, ExternalMemoryHandleType,
ExternalMemoryHandleTypes,
Expand All @@ -30,20 +30,15 @@ use crate::{
};
use smallvec::SmallVec;

#[cfg(target_os = "linux")]
use std::os::unix::prelude::{FromRawFd, IntoRawFd, RawFd};
#[cfg(target_os = "linux")]
use ash::vk::{ImageDrmFormatModifierExplicitCreateInfoEXT, SubresourceLayout};
#[cfg(target_os = "linux")]
use crate::{
image::ImageTiling,
memory::{
allocator::MemoryAlloc,
DeviceMemory,
MemoryAllocateFlags,
MemoryAllocateInfo
}
memory::{allocator::MemoryAlloc, DeviceMemory, MemoryAllocateFlags, MemoryAllocateInfo},
};
#[cfg(target_os = "linux")]
use ash::vk::{ImageDrmFormatModifierExplicitCreateInfoEXT, SubresourceLayout};
#[cfg(target_os = "linux")]
use std::os::unix::prelude::{FromRawFd, IntoRawFd, RawFd};

use std::{
fs::File,
Expand Down Expand Up @@ -258,7 +253,17 @@ impl StorageImage {
) -> Result<Arc<StorageImage>, ImageError> {
let queue_family_indices: SmallVec<[_; 4]> = queue_family_indices.into_iter().collect();

// TODO: Support multiplanar image iimporting from Linux FD
if subresource_data.len() > 1 {
panic!("Only single-planar image importing is currently supported.")
spaghetti-stack marked this conversation as resolved.
Show resolved Hide resolved
}

// Create a vector of the layout of each image plane.

// All of the following are automatically true, since the values are explicitly set as such:
// VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-size-02267
// VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-arrayPitch-02268
// VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-depthPitch-02269
let layout: Vec<SubresourceLayout> = subresource_data
.iter_mut()
.map(
Expand Down Expand Up @@ -364,7 +369,10 @@ impl StorageImage {
.bind_memory_unchecked([x])
.map_err(|(err, _, _)| err)?
});
Ok(Arc::new(StorageImage { inner, layout_initialized: AtomicBool::new(false) }))
Ok(Arc::new(StorageImage {
inner,
layout_initialized: AtomicBool::new(false),
}))
}
/// Allows the creation of a simple 2D general purpose image view from `StorageImage`.
#[inline]
Expand Down
13 changes: 12 additions & 1 deletion vulkano/src/image/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ impl RawImage {
}
};

// TODO: VUID-VkImageCreateInfo-tiling-02353
// Vulkano currently has no high-level way to add or check for VkImageFormatListCreateInfo.

// Format isn't supported at all?
if format_features.is_empty() {
return Err(ImageError::FormatNotSupported);
Expand Down Expand Up @@ -1777,7 +1780,10 @@ impl RawImage {
// Ensured by use of enum `ImageAspect`.

// VUID-vkGetImageSubresourceLayout-image-02270
if !matches!(self.tiling, ImageTiling::Linear) {
if !matches!(
self.tiling,
ImageTiling::DrmFormatModifier | ImageTiling::Linear
) {
return Err(ImageError::OptimalTilingNotSupported);
}

Expand Down Expand Up @@ -1814,6 +1820,11 @@ impl RawImage {
allowed_aspects -= ImageAspects::COLOR;
}

// TODO: VUID-vkGetImageSubresourceLayout-tiling-02271
//if self.tiling == ImageTiling::DrmFormatModifier {
// Only one-plane image importing is possible for now.
//}

// VUID-vkGetImageSubresourceLayout-format-04461
// VUID-vkGetImageSubresourceLayout-format-04462
// VUID-vkGetImageSubresourceLayout-format-04463
Expand Down