Skip to content

Commit

Permalink
cleanup: remove internal type F32x2 for glam::Vec2
Browse files Browse the repository at this point in the history
  • Loading branch information
Firestar99 committed Sep 23, 2024
1 parent 4352066 commit 528fd47
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions crates/spirv-std/src/float.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//! Traits and helper functions related to floats.

use crate::vector::Vector;
use crate::vector::{create_dim, VectorOrScalar};
#[cfg(target_arch = "spirv")]
use core::arch::asm;
use core::num::NonZeroUsize;

/// Abstract trait representing a SPIR-V floating point type.
///
Expand Down Expand Up @@ -63,34 +61,18 @@ pub fn f16x2_to_vec2<V: Vector<f32, 2>>(int: u32) -> V {
result
}

// We don't have access to a concrete vector type (cfg(feature = "glam") might not be enabled), so
// synth up one manually.
#[cfg_attr(target_arch = "spirv", repr(simd))]
// sometimes dead because on cpu, the `gpu_only` macro nukes the method bodies
#[allow(dead_code)]
#[derive(Default)]
struct F32x2 {
x: f32,
y: f32,
}
unsafe impl VectorOrScalar for F32x2 {
type Scalar = f32;
const DIM: NonZeroUsize = create_dim(2);
}
unsafe impl Vector<f32, 2> for F32x2 {}

/// Converts an f32 (float) into an f16 (half). The result is a u32, not a u16, due to GPU support
/// for u16 not being universal - the upper 16 bits will always be zero.
#[spirv_std_macros::gpu_only]
pub fn f32_to_f16(float: f32) -> u32 {
vec2_to_f16x2(F32x2 { x: float, y: 0.0 })
vec2_to_f16x2(glam::Vec2::new(float, 0.))
}

/// Converts an f16 (half) into an f32 (float). The parameter is a u32, due to GPU support for u16
/// not being universal - the upper 16 bits are ignored.
#[spirv_std_macros::gpu_only]
pub fn f16_to_f32(packed: u32) -> f32 {
f16x2_to_vec2::<F32x2>(packed).x
f16x2_to_vec2::<glam::Vec2>(packed).x
}

/// Packs a vec4 into 4 8-bit signed integers. See
Expand Down

0 comments on commit 528fd47

Please sign in to comment.