1 // Copyright (c) 2020 The vulkano developers 2 // Licensed under the Apache License, Version 2.0 3 // <LICENSE-APACHE or 4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT 5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 6 // at your option. All files in the project carrying such 7 // notice may not be copied, modified, or distributed except 8 // according to those terms. 9 10 use std::ops::BitOr; 11 12 /// An individual data type within an image. 13 /// 14 /// Most images have only the `Color` aspect, but some may have several. 15 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 16 #[repr(u32)] 17 pub enum ImageAspect { 18 Color = ash::vk::ImageAspectFlags::COLOR.as_raw(), 19 Depth = ash::vk::ImageAspectFlags::DEPTH.as_raw(), 20 Stencil = ash::vk::ImageAspectFlags::STENCIL.as_raw(), 21 Metadata = ash::vk::ImageAspectFlags::METADATA.as_raw(), 22 Plane0 = ash::vk::ImageAspectFlags::PLANE_0.as_raw(), 23 Plane1 = ash::vk::ImageAspectFlags::PLANE_1.as_raw(), 24 Plane2 = ash::vk::ImageAspectFlags::PLANE_2.as_raw(), 25 MemoryPlane0 = ash::vk::ImageAspectFlags::MEMORY_PLANE_0_EXT.as_raw(), 26 MemoryPlane1 = ash::vk::ImageAspectFlags::MEMORY_PLANE_1_EXT.as_raw(), 27 MemoryPlane2 = ash::vk::ImageAspectFlags::MEMORY_PLANE_2_EXT.as_raw(), 28 } 29 30 impl From<ImageAspect> for ash::vk::ImageAspectFlags { 31 #[inline] from(val: ImageAspect) -> Self32 fn from(val: ImageAspect) -> Self { 33 Self::from_raw(val as u32) 34 } 35 } 36 37 /// A mask specifying one or more `ImageAspect`s. 38 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] 39 pub struct ImageAspects { 40 pub color: bool, 41 pub depth: bool, 42 pub stencil: bool, 43 pub metadata: bool, 44 pub plane0: bool, 45 pub plane1: bool, 46 pub plane2: bool, 47 pub memory_plane0: bool, 48 pub memory_plane1: bool, 49 pub memory_plane2: bool, 50 } 51 52 impl ImageAspects { 53 /// Builds an `ImageAspect` with all values set to false. Useful as a default value. 54 #[inline] none() -> ImageAspects55 pub const fn none() -> ImageAspects { 56 ImageAspects { 57 color: false, 58 depth: false, 59 stencil: false, 60 metadata: false, 61 plane0: false, 62 plane1: false, 63 plane2: false, 64 memory_plane0: false, 65 memory_plane1: false, 66 memory_plane2: false, 67 } 68 } 69 } 70 71 impl BitOr for ImageAspects { 72 type Output = Self; 73 74 #[inline] bitor(self, rhs: Self) -> Self75 fn bitor(self, rhs: Self) -> Self { 76 ImageAspects { 77 color: self.color || rhs.color, 78 depth: self.depth || rhs.depth, 79 stencil: self.stencil || rhs.stencil, 80 metadata: self.metadata || rhs.metadata, 81 plane0: self.plane0 || rhs.plane0, 82 plane1: self.plane1 || rhs.plane1, 83 plane2: self.plane2 || rhs.plane2, 84 memory_plane0: self.memory_plane0 || rhs.memory_plane0, 85 memory_plane1: self.memory_plane1 || rhs.memory_plane1, 86 memory_plane2: self.memory_plane2 || rhs.memory_plane2, 87 } 88 } 89 } 90 91 impl From<ImageAspects> for ash::vk::ImageAspectFlags { 92 #[inline] from(value: ImageAspects) -> ash::vk::ImageAspectFlags93 fn from(value: ImageAspects) -> ash::vk::ImageAspectFlags { 94 let mut result = ash::vk::ImageAspectFlags::empty(); 95 if value.color { 96 result |= ash::vk::ImageAspectFlags::COLOR; 97 } 98 if value.depth { 99 result |= ash::vk::ImageAspectFlags::DEPTH; 100 } 101 if value.stencil { 102 result |= ash::vk::ImageAspectFlags::STENCIL; 103 } 104 if value.metadata { 105 result |= ash::vk::ImageAspectFlags::METADATA; 106 } 107 if value.plane0 { 108 result |= ash::vk::ImageAspectFlags::PLANE_0; 109 } 110 if value.plane1 { 111 result |= ash::vk::ImageAspectFlags::PLANE_1; 112 } 113 if value.plane2 { 114 result |= ash::vk::ImageAspectFlags::PLANE_2; 115 } 116 if value.memory_plane0 { 117 result |= ash::vk::ImageAspectFlags::MEMORY_PLANE_0_EXT; 118 } 119 if value.memory_plane1 { 120 result |= ash::vk::ImageAspectFlags::MEMORY_PLANE_1_EXT; 121 } 122 if value.memory_plane2 { 123 result |= ash::vk::ImageAspectFlags::MEMORY_PLANE_2_EXT 124 } 125 result 126 } 127 } 128 129 impl From<ash::vk::ImageAspectFlags> for ImageAspects { 130 #[inline] from(val: ash::vk::ImageAspectFlags) -> ImageAspects131 fn from(val: ash::vk::ImageAspectFlags) -> ImageAspects { 132 ImageAspects { 133 color: !(val & ash::vk::ImageAspectFlags::COLOR).is_empty(), 134 depth: !(val & ash::vk::ImageAspectFlags::DEPTH).is_empty(), 135 stencil: !(val & ash::vk::ImageAspectFlags::STENCIL).is_empty(), 136 metadata: !(val & ash::vk::ImageAspectFlags::METADATA).is_empty(), 137 plane0: !(val & ash::vk::ImageAspectFlags::PLANE_0).is_empty(), 138 plane1: !(val & ash::vk::ImageAspectFlags::PLANE_1).is_empty(), 139 plane2: !(val & ash::vk::ImageAspectFlags::PLANE_2).is_empty(), 140 memory_plane0: !(val & ash::vk::ImageAspectFlags::MEMORY_PLANE_0_EXT).is_empty(), 141 memory_plane1: !(val & ash::vk::ImageAspectFlags::MEMORY_PLANE_1_EXT).is_empty(), 142 memory_plane2: !(val & ash::vk::ImageAspectFlags::MEMORY_PLANE_2_EXT).is_empty(), 143 } 144 } 145 } 146