spirv_backend: split out some of the spirv entry point adapters into adapt.rs

This commit is contained in:
2022-07-25 00:21:20 -07:00
parent ebd2762d7a
commit 8ab89640f2
2 changed files with 45 additions and 39 deletions

View File

@@ -12,14 +12,14 @@ pub use spirv_std::glam;
#[cfg(not(target_arch = "spirv"))]
use spirv_std::macros::spirv;
mod adapt;
pub mod sim;
pub mod support;
pub use sim::{SerializedSimMeta, SerializedStepE, SerializedStepH};
pub use sim::SerializedSimMeta;
pub use support::{Optional, UnsizedArray};
use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr, Material};
use coremem_types::real::Real;
use coremem_types::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr};
use coremem_types::vec::{Vec3, Vec3u};
type Iso3R1<R> = IsoConductorOr<R, Ferroxcube3R1MH>;
@@ -28,40 +28,6 @@ fn glam_vec_to_internal(v: glam::UVec3) -> Vec3u {
Vec3u::new(v.x, v.y, v.z)
}
fn step_h<R: Real, M: Material<R>>(
id: Vec3u,
meta: &SerializedSimMeta<R>,
stimulus_h: &UnsizedArray<Vec3<R>>,
material: &UnsizedArray<M>,
e: &UnsizedArray<Vec3<R>>,
h: &mut UnsizedArray<Vec3<R>>,
m: &mut UnsizedArray<Vec3<R>>,
) {
if id.x() < meta.dim.x() && id.y() < meta.dim.y() && id.z() < meta.dim.z() {
let sim_state = SerializedStepH::new(meta, stimulus_h, material, e, h, m);
let update_state = sim_state.index(id);
let (new_h, new_m) = update_state.step_h();
sim_state.write_output(id, new_h, new_m);
}
}
fn step_e<R: Real, M: Material<R>>(
id: Vec3u,
meta: &SerializedSimMeta<R>,
stimulus_e: &UnsizedArray<Vec3<R>>,
material: &UnsizedArray<M>,
e: &mut UnsizedArray<Vec3<R>>,
h: &UnsizedArray<Vec3<R>>,
) {
if id.x() < meta.dim.x() && id.y() < meta.dim.y() && id.z() < meta.dim.z() {
let sim_state = SerializedStepE::new(meta, stimulus_e, material, e, h);
let update_state = sim_state.index(id);
let new_e = update_state.step_e();
sim_state.write_output(id, new_e);
}
}
/// 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;
@@ -97,7 +63,7 @@ macro_rules! steps {
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut UnsizedArray<Vec3<$flt>>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut UnsizedArray<Vec3<$flt>>,
) {
step_h(glam_vec_to_internal(id), meta, stimulus_h, material, e, h, m)
adapt::step_h(glam_vec_to_internal(id), meta, stimulus_h, material, e, h, m)
}
#[spirv(compute(threads(4, 4, 4)))]
@@ -113,7 +79,7 @@ macro_rules! steps {
// XXX: can/should this m input be deleted?
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &UnsizedArray<Vec3<$flt>>,
) {
step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h)
adapt::step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h)
}
};
}