1 use crate::vk;
2 
3 /// Holds 24 bits in the least significant bits of memory,
4 /// and 8 bytes in the most significant bits of that memory,
5 /// occupying a single [`u32`] in total. This is commonly used in
6 /// [acceleration structure instances] such as
7 /// [`vk::AccelerationStructureInstanceKHR`],
8 /// [`vk::AccelerationStructureSRTMotionInstanceNV`] and
9 /// [`vk::AccelerationStructureMatrixMotionInstanceNV`].
10 ///
11 /// [acceleration structure instances]: https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VkAccelerationStructureInstanceKHR.html#_description
12 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
13 #[repr(transparent)]
14 pub struct Packed24_8(u32);
15 
16 impl Packed24_8 {
new(low_24: u32, high_8: u8) -> Self17     pub fn new(low_24: u32, high_8: u8) -> Self {
18         Self((low_24 & 0x00ff_ffff) | (u32::from(high_8) << 24))
19     }
20 
21     /// Extracts the least-significant 24 bits (3 bytes) of this integer
low_24(&self) -> u3222     pub fn low_24(&self) -> u32 {
23         self.0 & 0xffffff
24     }
25 
26     /// Extracts the most significant 8 bits (single byte) of this integer
high_8(&self) -> u827     pub fn high_8(&self) -> u8 {
28         (self.0 >> 24) as u8
29     }
30 }
31 
32 impl vk::ColorComponentFlags {
33     /// Contraction of [`R`][Self::R] | [`G`][Self::G] | [`B`][Self::B] | [`A`][Self::A]
34     pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0);
35 }
36 
37 impl From<vk::Extent2D> for vk::Extent3D {
from(value: vk::Extent2D) -> Self38     fn from(value: vk::Extent2D) -> Self {
39         Self {
40             width: value.width,
41             height: value.height,
42             depth: 1,
43         }
44     }
45 }
46 
47 impl From<vk::Extent2D> for vk::Rect2D {
from(extent: vk::Extent2D) -> Self48     fn from(extent: vk::Extent2D) -> Self {
49         Self {
50             offset: Default::default(),
51             extent,
52         }
53     }
54 }
55 
56 /// Structures implementing this trait are layout-compatible with [`vk::BaseInStructure`] and
57 /// [`vk::BaseOutStructure`]. Such structures have an `s_type` field indicating its type, which
58 /// must always match the value of [`TaggedStructure::STRUCTURE_TYPE`].
59 pub unsafe trait TaggedStructure {
60     const STRUCTURE_TYPE: vk::StructureType;
61 }
62