| 1 | #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)] |
| 2 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 3 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 4 | pub struct XY<T> { |
| 5 | pub x: T, |
| 6 | pub y: T, |
| 7 | } |
| 8 | |
| 9 | #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)] |
| 10 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 11 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 12 | pub struct XYZ<T> { |
| 13 | pub x: T, |
| 14 | pub y: T, |
| 15 | pub z: T, |
| 16 | } |
| 17 | |
| 18 | #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)] |
| 19 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 20 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 21 | pub struct XYZW<T> { |
| 22 | pub x: T, |
| 23 | pub y: T, |
| 24 | pub z: T, |
| 25 | pub w: T, |
| 26 | } |
| 27 | |
| 28 | #[derive(Clone, Copy, Default, PartialEq, PartialOrd)] |
| 29 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 30 | pub struct Columns2<V> { |
| 31 | pub x_axis: V, |
| 32 | pub y_axis: V, |
| 33 | } |
| 34 | |
| 35 | #[derive(Clone, Copy, Default, PartialEq, PartialOrd)] |
| 36 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 37 | pub struct Columns3<V> { |
| 38 | pub x_axis: V, |
| 39 | pub y_axis: V, |
| 40 | pub z_axis: V, |
| 41 | } |
| 42 | |
| 43 | #[derive(Clone, Copy, Default, PartialEq, PartialOrd)] |
| 44 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 45 | pub struct Columns4<V> { |
| 46 | pub x_axis: V, |
| 47 | pub y_axis: V, |
| 48 | pub z_axis: V, |
| 49 | pub w_axis: V, |
| 50 | } |
| 51 | |
| 52 | /// The `XYZF32A16` is used for the `Vec3A` type, that is a 16 btye aligned `XYZ<f32>` type. |
| 53 | #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)] |
| 54 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 55 | #[cfg_attr(not(target_arch = "spirv"), repr(C, align(16)))] |
| 56 | pub struct XYZF32A16 { |
| 57 | pub x: f32, |
| 58 | pub y: f32, |
| 59 | pub z: f32, |
| 60 | } |
| 61 | |
| 62 | impl From<XYZW<f32>> for XYZF32A16 { |
| 63 | #[inline(always)] |
| 64 | fn from(v: XYZW<f32>) -> Self { |
| 65 | Self { |
| 66 | x: v.x, |
| 67 | y: v.y, |
| 68 | z: v.z, |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | impl From<XYZ<f32>> for XYZF32A16 { |
| 74 | #[inline(always)] |
| 75 | fn from(v: XYZ<f32>) -> Self { |
| 76 | Self { |
| 77 | x: v.x, |
| 78 | y: v.y, |
| 79 | z: v.z, |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl From<XYZF32A16> for XYZ<f32> { |
| 85 | #[inline(always)] |
| 86 | fn from(v: XYZF32A16) -> Self { |
| 87 | Self { |
| 88 | x: v.x, |
| 89 | y: v.y, |
| 90 | z: v.z, |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl From<XYZF32A16> for XY<f32> { |
| 96 | #[inline(always)] |
| 97 | fn from(v: XYZF32A16) -> Self { |
| 98 | Self { x: v.x, y: v.y } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | #[derive(Clone, Copy, Default, PartialEq, PartialOrd)] |
| 103 | #[repr(C, align(16))] |
| 104 | pub(crate) struct Align16<T>(pub T); |
| 105 | |
| 106 | impl<T> Align16<T> { |
| 107 | #[allow(dead_code)] |
| 108 | pub fn as_ptr(&self) -> *const T { |
| 109 | &self.0 |
| 110 | } |
| 111 | |
| 112 | #[allow(dead_code)] |
| 113 | pub fn as_mut_ptr(&mut self) -> *mut T { |
| 114 | &mut self.0 |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | #[test] |
| 119 | fn test_align16() { |
| 120 | use core::{mem, ptr}; |
| 121 | let mut a = Align16::<f32>(1.0); |
| 122 | assert_eq!(mem::align_of_val(&a), 16); |
| 123 | unsafe { |
| 124 | assert_eq!(ptr::read(a.as_ptr()).to_bits(), f32::to_bits(1.0)); |
| 125 | ptr::write(a.as_mut_ptr(), -1.0); |
| 126 | } |
| 127 | assert_eq!(a.0.to_bits(), f32::to_bits(-1.0)); |
| 128 | } |