#![cfg_attr( target_arch = "spirv", feature(register_attr), register_attr(spirv), no_std )] #![feature(const_fn_floating_point_arithmetic)] extern crate spirv_std; pub use spirv_std::glam; #[cfg(not(target_arch = "spirv"))] use spirv_std::macros::spirv; mod adapt; pub mod support; pub use support::UnsizedArray; use coremem_types::compound::Optional; use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr}; use coremem_types::step::SimMeta; use coremem_types::vec::{Vec3, Vec3u}; type Iso3R1 = IsoConductorOr; 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() -> Optional<(&'static str, &'static str)> { use core::any::TypeId; let mappings = [ (TypeId::of::>(), ("step_h_generic_material", "step_e_generic_material") ), (TypeId::of::>(), ("step_h_iso_3r1", "step_e_iso_3r1") ), ]; for (id, names) in mappings { if id == TypeId::of::() { return Optional::some(names); } } Optional::none() } macro_rules! steps { ($flt:ty, $mat:ty, $step_h:ident, $step_e:ident) => { // LocalSize/numthreads #[spirv(compute(threads(4, 4, 4)))] pub fn $step_h( #[spirv(global_invocation_id)] id: glam::UVec3, #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SimMeta<$flt>, // XXX: delete this input? #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] _unused_stimulus_e: &UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>, #[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut UnsizedArray>, ) { adapt::step_h(glam_vec_to_internal(id), meta, stimulus_h, material, e, h, m) } #[spirv(compute(threads(4, 4, 4)))] pub fn $step_e( #[spirv(global_invocation_id)] id: glam::UVec3, #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SimMeta<$flt>, #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] stimulus_e: &UnsizedArray>, // XXX: delete this input? #[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>, #[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &mut UnsizedArray>, #[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &UnsizedArray>, // XXX: can/should this m input be deleted? #[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &UnsizedArray>, ) { adapt::step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h) } }; } steps!(f32, FullyGenericMaterial, step_h_generic_material, step_e_generic_material); steps!(f32, Iso3R1, step_h_iso_3r1, step_e_iso_3r1);