spirv: add R32 support to the GPU code

This commit is contained in:
2022-07-28 13:18:14 -07:00
parent 15fc7b91dc
commit 07dfb9d852
2 changed files with 53 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ mod adapt;
mod support; mod support;
use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr}; use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr};
use coremem_types::real::R32;
use coremem_types::step::SimMeta; use coremem_types::step::SimMeta;
use coremem_types::vec::{Vec3, Vec3u}; use coremem_types::vec::{Vec3, Vec3u};
@@ -79,5 +80,7 @@ macro_rules! steps {
}; };
} }
steps!(f32, FullyGenericMaterial<f32>, step_h_generic_material, step_e_generic_material); steps!(f32, FullyGenericMaterial<f32>, step_h_generic_material_f32, step_e_generic_material_f32);
steps!(f32, Iso3R1<f32>, step_h_iso_3r1, step_e_iso_3r1); steps!(f32, Iso3R1<f32>, step_h_iso_3r1_f32, step_e_iso_3r1_f32);
steps!(R32, FullyGenericMaterial<R32>, step_h_generic_material_r32, step_e_generic_material_r32);
steps!(R32, Iso3R1<R32>, step_h_iso_3r1_r32, step_e_iso_3r1_r32);

View File

@@ -292,7 +292,7 @@ impl<T: Real> Finite<T> {
} }
#[cfg(not(feature = "fmt"))] #[cfg(not(feature = "fmt"))]
fn handle_non_finite(_inner: T) -> ! { fn handle_non_finite(_inner: T) -> ! {
panic!("Finite<T> is not finite"); panic!(); // expected a finite real
} }
} }
@@ -384,7 +384,6 @@ impl<T: ToFloat> ToFloat for Finite<T> {
impl<T: RealFeatures> RealFeatures for Finite<T> {} impl<T: RealFeatures> RealFeatures for Finite<T> {}
impl<T: Real> Real for Finite<T> { impl<T: Real> Real for Finite<T> {
decl_consts!(Self::from_primitive);
fn from_primitive<P: ToFloat>(p: P) -> Self { fn from_primitive<P: ToFloat>(p: P) -> Self {
Self::new(T::from_primitive(p)) Self::new(T::from_primitive(p))
} }
@@ -422,6 +421,53 @@ impl<T: Real> Real for Finite<T> {
let (s, c) = self.0.sin_cos(); let (s, c) = self.0.sin_cos();
(Self::new(s), Self::new(c)) (Self::new(s), Self::new(c))
} }
// we would ideally use `decl_consts` here, but that produces f64 -> f32 casts for R32 code.
fn zero() -> Self {
Self::from_primitive(T::zero())
}
fn one() -> Self {
Self::from_primitive(T::one())
}
fn two() -> Self {
Self::from_primitive(T::two())
}
fn three() -> Self {
Self::from_primitive(T::three())
}
fn ten() -> Self {
Self::from_primitive(T::ten())
}
fn tenth() -> Self {
Self::from_primitive(T::tenth())
}
fn third() -> Self {
Self::from_primitive(T::third())
}
fn half() -> Self {
Self::from_primitive(T::half())
}
fn pi() -> Self {
Self::from_primitive(T::pi())
}
fn two_pi() -> Self {
Self::from_primitive(T::two_pi())
}
fn c() -> Self {
Self::from_primitive(T::c())
}
fn eps0() -> Self {
Self::from_primitive(T::eps0())
}
fn twice_eps0() -> Self {
Self::from_primitive(T::twice_eps0())
}
fn mu0() -> Self {
Self::from_primitive(T::mu0())
}
fn mu0_inv() -> Self {
Self::from_primitive(T::mu0_inv())
}
} }
impl ToFloat for i32 { impl ToFloat for i32 {