ash/vk/
prelude.rs

1use 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)]
14pub struct Packed24_8(u32);
15
16impl Packed24_8 {
17    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
22    pub fn low_24(&self) -> u32 {
23        self.0 & 0xffffff
24    }
25
26    /// Extracts the most significant 8 bits (single byte) of this integer
27    pub fn high_8(&self) -> u8 {
28        (self.0 >> 24) as u8
29    }
30}
31
32// Intradoc `Self::` links refuse to resolve if `ColorComponentFlags`
33// isn't directly in scope: https://github.com/rust-lang/rust/issues/93205
34use vk::ColorComponentFlags;
35
36impl ColorComponentFlags {
37    /// Contraction of [`R`][Self::R] | [`G`][Self::G] | [`B`][Self::B] | [`A`][Self::A]
38    pub const RGBA: Self = Self(Self::R.0 | Self::G.0 | Self::B.0 | Self::A.0);
39}
40
41impl From<vk::Extent2D> for vk::Extent3D {
42    fn from(value: vk::Extent2D) -> Self {
43        Self {
44            width: value.width,
45            height: value.height,
46            depth: 1,
47        }
48    }
49}
50
51impl From<vk::Extent2D> for vk::Rect2D {
52    fn from(extent: vk::Extent2D) -> Self {
53        Self {
54            offset: Default::default(),
55            extent,
56        }
57    }
58}