87 lines
3.5 KiB
Rust
87 lines
3.5 KiB
Rust
#![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, RuntimeArray};
|
|
#[cfg(not(target_arch = "spirv"))]
|
|
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};
|
|
|
|
type Iso3R1<R> = IsoConductorOr<R, Ferroxcube3R1MH>;
|
|
|
|
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")
|
|
),
|
|
];
|
|
|
|
for (id, names) in mappings {
|
|
if id == TypeId::of::<M>() {
|
|
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: &RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &RuntimeArray<$mat>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut RuntimeArray<Vec3<$flt>>,
|
|
) {
|
|
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: &RuntimeArray<Vec3<$flt>>,
|
|
// XXX: delete this input?
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &RuntimeArray<$mat>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &mut RuntimeArray<Vec3<$flt>>,
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &RuntimeArray<Vec3<$flt>>,
|
|
// XXX: can/should this m input be deleted?
|
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &RuntimeArray<Vec3<$flt>>,
|
|
) {
|
|
adapt::step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h)
|
|
}
|
|
};
|
|
}
|
|
|
|
steps!(f32, FullyGenericMaterial<f32>, step_h_generic_material, step_e_generic_material);
|
|
steps!(f32, Iso3R1<f32>, step_h_iso_3r1, step_e_iso_3r1);
|