|
1 | 1 | //! Traits and helper functions related to floats. |
2 | 2 |
|
3 | 3 | use crate::vector::Vector; |
4 | | -use crate::vector::{create_dim, VectorOrScalar}; |
5 | 4 | #[cfg(target_arch = "spirv")] |
6 | 5 | use core::arch::asm; |
7 | | -use core::num::NonZeroUsize; |
8 | 6 |
|
9 | 7 | /// Abstract trait representing a SPIR-V floating point type. |
10 | 8 | /// |
@@ -63,34 +61,18 @@ pub fn f16x2_to_vec2<V: Vector<f32, 2>>(int: u32) -> V { |
63 | 61 | result |
64 | 62 | } |
65 | 63 |
|
66 | | -// We don't have access to a concrete vector type (cfg(feature = "glam") might not be enabled), so |
67 | | -// synth up one manually. |
68 | | -#[cfg_attr(target_arch = "spirv", repr(simd))] |
69 | | -// sometimes dead because on cpu, the `gpu_only` macro nukes the method bodies |
70 | | -#[allow(dead_code)] |
71 | | -#[derive(Default)] |
72 | | -struct F32x2 { |
73 | | - x: f32, |
74 | | - y: f32, |
75 | | -} |
76 | | -unsafe impl VectorOrScalar for F32x2 { |
77 | | - type Scalar = f32; |
78 | | - const DIM: NonZeroUsize = create_dim(2); |
79 | | -} |
80 | | -unsafe impl Vector<f32, 2> for F32x2 {} |
81 | | - |
82 | 64 | /// Converts an f32 (float) into an f16 (half). The result is a u32, not a u16, due to GPU support |
83 | 65 | /// for u16 not being universal - the upper 16 bits will always be zero. |
84 | 66 | #[spirv_std_macros::gpu_only] |
85 | 67 | pub fn f32_to_f16(float: f32) -> u32 { |
86 | | - vec2_to_f16x2(F32x2 { x: float, y: 0.0 }) |
| 68 | + vec2_to_f16x2(glam::Vec2::new(float, 0.)) |
87 | 69 | } |
88 | 70 |
|
89 | 71 | /// Converts an f16 (half) into an f32 (float). The parameter is a u32, due to GPU support for u16 |
90 | 72 | /// not being universal - the upper 16 bits are ignored. |
91 | 73 | #[spirv_std_macros::gpu_only] |
92 | 74 | pub fn f16_to_f32(packed: u32) -> f32 { |
93 | | - f16x2_to_vec2::<F32x2>(packed).x |
| 75 | + f16x2_to_vec2::<glam::Vec2>(packed).x |
94 | 76 | } |
95 | 77 |
|
96 | 78 | /// Packs a vec4 into 4 8-bit signed integers. See |
|
0 commit comments