-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial YUV and external memory support (#1467)
* vulkano: image: improve formatting Ran cargo fmt --all. Should we use clippy too ? * vk_sys: add additional formats This updates the vk formats enum to the header that's on my system (vk 1.2-ish). * vulkano: image: Add NV12 and YV12 support These formats are commonly used as targets for hardware and software video decode. The common case is the swapchain allocator (gralloc in the Android use case) allocates some memory, the video stack decodes to it, and then memory can be composited by Vulkan or sent directly to the display. * vk_sys: update structure types This updates the structure types to a VK 1.2-ish state. Long term, it makes a ton of sense to autogenerate vk-sys to make adding additional features and enumerations easier [1]. For now, we can hand edit. [1] (#89) * vk_sys: add VK_KHR_external_memory_fd bindings This adds some basic external memory features. Most of these features are core in VK1.1. * vulkano: memory: add and use DeviceMemoryBuilder We'll need to: (a) Create exportable memory (b) import from a OS descriptor to create DeviceMemory (c) Also support dedicated allocations The device memory API is becoming rather complicated. Let's use the common builder pattern to simplify this. * vulkano: memory: implement some external features This change is sufficient to create exportable memory and export it. It's only been tested on Linux platforms and depends on Unix file descriptors, so enable it only there for now. Import support will be added later. Support for external buffers and images can also be added later if someone needs it.
- Loading branch information
1 parent
3113d1f
commit 2d60c08
Showing
12 changed files
with
1,508 additions
and
119 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,132 @@ | ||
// Copyright (c) 2020 The vulkano developers | ||
// Licensed under the Apache License, Version 2.0 | ||
// <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT | ||
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, | ||
// at your option. All files in the project carrying such | ||
// notice may not be copied, modified, or distributed except | ||
// according to those terms. | ||
|
||
use std::ops::BitOr; | ||
use vk; | ||
|
||
/// Describes how an aspect of the image that be used to query Vulkan. This is **not** just a suggestion. | ||
/// Check out VkImageAspectFlagBits in the Vulkan spec. | ||
/// | ||
/// If you specify an aspect of the image that doesn't exist (for example, depth for a YUV image), a panic | ||
/// will happen. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
pub struct ImageAspect { | ||
pub color: bool, | ||
pub depth: bool, | ||
pub stencil: bool, | ||
pub metadata: bool, | ||
pub plane0: bool, | ||
pub plane1: bool, | ||
pub plane2: bool, | ||
pub memory_plane0: bool, | ||
pub memory_plane1: bool, | ||
pub memory_plane2: bool, | ||
} | ||
|
||
impl ImageAspect { | ||
/// Builds a `ImageAspect` with all values set to false. Useful as a default value. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use vulkano::image::ImageAspect as ImageAspect; | ||
/// | ||
/// let _aspect = ImageAspect { | ||
/// color: true, | ||
/// depth: true, | ||
/// .. ImageAspect::none() | ||
/// }; | ||
/// ``` | ||
#[inline] | ||
pub fn none() -> ImageAspect { | ||
ImageAspect { | ||
color: false, | ||
depth: false, | ||
stencil: false, | ||
metadata: false, | ||
plane0: false, | ||
plane1: false, | ||
plane2: false, | ||
memory_plane0: false, | ||
memory_plane1: false, | ||
memory_plane2: false, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn to_aspect_bits(&self) -> vk::ImageAspectFlagBits { | ||
let mut result = 0; | ||
if self.color { | ||
result |= vk::IMAGE_ASPECT_COLOR_BIT; | ||
} | ||
if self.depth { | ||
result |= vk::IMAGE_ASPECT_DEPTH_BIT; | ||
} | ||
if self.stencil { | ||
result |= vk::IMAGE_ASPECT_STENCIL_BIT; | ||
} | ||
if self.metadata { | ||
result |= vk::IMAGE_ASPECT_METADATA_BIT; | ||
} | ||
if self.plane0 { | ||
result |= vk::IMAGE_ASPECT_PLANE_0_BIT; | ||
} | ||
if self.plane1 { | ||
result |= vk::IMAGE_ASPECT_PLANE_1_BIT; | ||
} | ||
if self.plane2 { | ||
result |= vk::IMAGE_ASPECT_PLANE_2_BIT; | ||
} | ||
if self.memory_plane0 { | ||
result |= vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT; | ||
} | ||
if self.memory_plane1 { | ||
result |= vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT; | ||
} | ||
if self.memory_plane2 { | ||
result |= vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT | ||
} | ||
result | ||
} | ||
|
||
pub(crate) fn from_bits(val: u32) -> ImageAspect { | ||
ImageAspect { | ||
color: (val & vk::IMAGE_ASPECT_COLOR_BIT) != 0, | ||
depth: (val & vk::IMAGE_ASPECT_DEPTH_BIT) != 0, | ||
stencil: (val & vk::IMAGE_ASPECT_STENCIL_BIT) != 0, | ||
metadata: (val & vk::IMAGE_ASPECT_METADATA_BIT) != 0, | ||
plane0: (val & vk::IMAGE_ASPECT_PLANE_0_BIT) != 0, | ||
plane1: (val & vk::IMAGE_ASPECT_PLANE_1_BIT) != 0, | ||
plane2: (val & vk::IMAGE_ASPECT_PLANE_2_BIT) != 0, | ||
memory_plane0: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT) != 0, | ||
memory_plane1: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT) != 0, | ||
memory_plane2: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT) != 0, | ||
} | ||
} | ||
} | ||
|
||
impl BitOr for ImageAspect { | ||
type Output = Self; | ||
|
||
#[inline] | ||
fn bitor(self, rhs: Self) -> Self { | ||
ImageAspect { | ||
color: self.color || rhs.color, | ||
depth: self.depth || rhs.depth, | ||
stencil: self.stencil || rhs.stencil, | ||
metadata: self.metadata || rhs.metadata, | ||
plane0: self.plane0 || rhs.plane0, | ||
plane1: self.plane1 || rhs.plane1, | ||
plane2: self.plane2 || rhs.plane2, | ||
memory_plane0: self.memory_plane0 || rhs.memory_plane0, | ||
memory_plane1: self.memory_plane1 || rhs.memory_plane1, | ||
memory_plane2: self.memory_plane2 || rhs.memory_plane2, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.