use std::ops::BitOr;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ImageUsage {
pub transfer_source: bool,
pub transfer_destination: bool,
pub sampled: bool,
pub storage: bool,
pub color_attachment: bool,
pub depth_stencil_attachment: bool,
pub transient_attachment: bool,
pub input_attachment: bool,
}
impl ImageUsage {
#[inline]
pub fn all() -> ImageUsage {
ImageUsage {
transfer_source: true,
transfer_destination: true,
sampled: true,
storage: true,
color_attachment: true,
depth_stencil_attachment: true,
transient_attachment: true,
input_attachment: true,
}
}
#[inline]
pub fn none() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: false,
depth_stencil_attachment: false,
transient_attachment: false,
input_attachment: false,
}
}
#[inline]
pub fn color_attachment() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: true,
depth_stencil_attachment: false,
transient_attachment: false,
input_attachment: false,
}
}
#[inline]
pub fn depth_stencil_attachment() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: false,
depth_stencil_attachment: true,
transient_attachment: false,
input_attachment: false,
}
}
#[inline]
pub fn transient_color_attachment() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: true,
depth_stencil_attachment: false,
transient_attachment: true,
input_attachment: false,
}
}
#[inline]
pub fn transient_depth_stencil_attachment() -> ImageUsage {
ImageUsage {
transfer_source: false,
transfer_destination: false,
sampled: false,
storage: false,
color_attachment: false,
depth_stencil_attachment: true,
transient_attachment: true,
input_attachment: false,
}
}
}
impl From<ImageUsage> for ash::vk::ImageUsageFlags {
#[inline]
fn from(val: ImageUsage) -> Self {
let mut result = ash::vk::ImageUsageFlags::empty();
if val.transfer_source {
result |= ash::vk::ImageUsageFlags::TRANSFER_SRC;
}
if val.transfer_destination {
result |= ash::vk::ImageUsageFlags::TRANSFER_DST;
}
if val.sampled {
result |= ash::vk::ImageUsageFlags::SAMPLED;
}
if val.storage {
result |= ash::vk::ImageUsageFlags::STORAGE;
}
if val.color_attachment {
result |= ash::vk::ImageUsageFlags::COLOR_ATTACHMENT;
}
if val.depth_stencil_attachment {
result |= ash::vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT;
}
if val.transient_attachment {
result |= ash::vk::ImageUsageFlags::TRANSIENT_ATTACHMENT;
}
if val.input_attachment {
result |= ash::vk::ImageUsageFlags::INPUT_ATTACHMENT;
}
result
}
}
impl From<ash::vk::ImageUsageFlags> for ImageUsage {
#[inline]
fn from(val: ash::vk::ImageUsageFlags) -> ImageUsage {
ImageUsage {
transfer_source: !(val & ash::vk::ImageUsageFlags::TRANSFER_SRC).is_empty(),
transfer_destination: !(val & ash::vk::ImageUsageFlags::TRANSFER_DST).is_empty(),
sampled: !(val & ash::vk::ImageUsageFlags::SAMPLED).is_empty(),
storage: !(val & ash::vk::ImageUsageFlags::STORAGE).is_empty(),
color_attachment: !(val & ash::vk::ImageUsageFlags::COLOR_ATTACHMENT).is_empty(),
depth_stencil_attachment: !(val & ash::vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT)
.is_empty(),
transient_attachment: !(val & ash::vk::ImageUsageFlags::TRANSIENT_ATTACHMENT)
.is_empty(),
input_attachment: !(val & ash::vk::ImageUsageFlags::INPUT_ATTACHMENT).is_empty(),
}
}
}
impl BitOr for ImageUsage {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self {
ImageUsage {
transfer_source: self.transfer_source || rhs.transfer_source,
transfer_destination: self.transfer_destination || rhs.transfer_destination,
sampled: self.sampled || rhs.sampled,
storage: self.storage || rhs.storage,
color_attachment: self.color_attachment || rhs.color_attachment,
depth_stencil_attachment: self.depth_stencil_attachment || rhs.depth_stencil_attachment,
transient_attachment: self.transient_attachment || rhs.transient_attachment,
input_attachment: self.input_attachment || rhs.input_attachment,
}
}
}