spirv: remove the Optionality around entry points: compute them statically with traits

This commit is contained in:
2022-07-27 12:32:43 -07:00
parent baaeeb9463
commit 568d61c598
3 changed files with 27 additions and 31 deletions

View File

@@ -15,7 +15,6 @@ use spirv_std::macros::spirv;
mod adapt;
mod support;
use coremem_types::compound::Optional;
use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr};
use coremem_types::step::SimMeta;
use coremem_types::vec::{Vec3, Vec3u};
@@ -26,28 +25,26 @@ fn glam_vec_to_internal(v: glam::UVec3) -> Vec3u {
Vec3u::new(v.x, v.y, v.z)
}
/// Return the step_h/step_e entry point names for the provided material
pub fn entry_points<M: 'static>() -> Optional<(&'static str, &'static str)> {
use core::any::TypeId;
let mappings = [
(TypeId::of::<FullyGenericMaterial<f32>>(),
("step_h_generic_material", "step_e_generic_material")
),
(TypeId::of::<Iso3R1<f32>>(),
("step_h_iso_3r1", "step_e_iso_3r1")
),
];
mod private {
pub trait Sealed {}
}
for (id, names) in mappings {
if id == TypeId::of::<M>() {
return Optional::some(names);
}
}
Optional::none()
pub trait HasEntryPoints<R>: private::Sealed {
fn step_h() -> &'static str;
fn step_e() -> &'static str;
}
macro_rules! steps {
($flt:ty, $mat:ty, $step_h:ident, $step_e:ident) => {
impl private::Sealed for $mat { }
impl HasEntryPoints<$flt> for $mat {
fn step_h() -> &'static str {
stringify!($step_h)
}
fn step_e() -> &'static str {
stringify!($step_e)
}
}
// LocalSize/numthreads
#[spirv(compute(threads(4, 4, 4)))]
pub fn $step_h(