restructure this multi-crate project to use Cargo's "workspace" feature

this solves an issue in the Nix build, where managing multiple
Cargo.lock files is otherwise tricky. it causes (or fails to fix?) an adjacent issue where
the spirv builder doesn't seem to have everything it needs vendored.
This commit is contained in:
2022-07-05 17:34:21 -07:00
parent d3cd12aa47
commit 5b99d30cda
64 changed files with 108 additions and 206 deletions

View File

@@ -0,0 +1,116 @@
#![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 glam::{UVec3, Vec3};
use spirv_std::glam;
#[cfg(not(target_arch = "spirv"))]
use spirv_std::macros::spirv;
pub mod mat;
pub mod sim;
pub mod support;
pub use sim::{SerializedSimMeta, SerializedStepE, SerializedStepH};
pub use support::{Optional, UnsizedArray, UVec3Std, Vec3Std};
use mat::{IsoConductorOr, Ferroxcube3R1MH, FullyGenericMaterial, Material};
type Iso3R1 = IsoConductorOr<Ferroxcube3R1MH>;
fn step_h<M: Material>(
id: UVec3,
meta: &SerializedSimMeta,
stimulus_h: &UnsizedArray<Vec3Std>,
material: &UnsizedArray<M>,
e: &UnsizedArray<Vec3Std>,
h: &mut UnsizedArray<Vec3Std>,
m: &mut UnsizedArray<Vec3Std>,
) {
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);
update_state.step_h();
}
}
fn step_e<M: Material>(
id: UVec3,
meta: &SerializedSimMeta,
stimulus_e: &UnsizedArray<Vec3Std>,
material: &UnsizedArray<M>,
e: &mut UnsizedArray<Vec3Std>,
h: &UnsizedArray<Vec3Std>,
) {
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);
update_state.step_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;
let mappings = [
(TypeId::of::<FullyGenericMaterial>(),
("step_h_generic_material", "step_e_generic_material")
),
(TypeId::of::<Iso3R1>(),
("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 {
($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: UVec3,
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
// XXX: delete this input?
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] _unused_stimulus_e: &UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut UnsizedArray<Vec3Std>,
) {
step_h(id, meta, stimulus_h, material, e, h, m)
}
#[spirv(compute(threads(4, 4, 4)))]
pub fn $step_e(
#[spirv(global_invocation_id)] id: UVec3,
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] stimulus_e: &UnsizedArray<Vec3Std>,
// XXX: delete this input?
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 4)] e: &mut UnsizedArray<Vec3Std>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &UnsizedArray<Vec3Std>,
// XXX: can/should this m input be deleted?
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &UnsizedArray<Vec3Std>,
) {
step_e(id, meta, stimulus_e, material, e, h)
}
};
}
steps!(FullyGenericMaterial, step_h_generic_material, step_e_generic_material);
steps!(Iso3R1, step_h_iso_3r1, step_e_iso_3r1);