lift SimMeta from spirv_backend -> coremem_types
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::geom::Index;
|
||||
use coremem_types::compound::Optional;
|
||||
use coremem_types::vec::{Vec3, Vec3u};
|
||||
|
||||
/// hide the actual spirv backend structures inside a submodule to make their use/boundary clear.
|
||||
mod ffi {
|
||||
pub use spirv_backend::{entry_points, SerializedSimMeta};
|
||||
pub use spirv_backend::entry_points;
|
||||
}
|
||||
|
||||
// conversion traits for types defined cross-lib
|
||||
@@ -63,29 +60,6 @@ impl<F: Copy + IntoLib> IntoLib for Optional<F> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: if we lift this type out of the spirv crate we can derive serde based on a feature flag
|
||||
// this is bitwise- and type-compatible with the spirv SimMeta, except we need serde traits
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
pub struct SimMeta<R> {
|
||||
pub(crate) dim: Index,
|
||||
pub(crate) inv_feature_size: R,
|
||||
pub(crate) time_step: R,
|
||||
pub(crate) feature_size: R,
|
||||
}
|
||||
|
||||
impl<R: IntoFfi> IntoFfi for SimMeta<R> {
|
||||
type Ffi = ffi::SerializedSimMeta<R::Ffi>;
|
||||
fn into_ffi(self) -> Self::Ffi {
|
||||
Self::Ffi {
|
||||
dim: self.dim.0.into_ffi(),
|
||||
inv_feature_size: self.inv_feature_size.into_ffi(),
|
||||
time_step: self.time_step.into_ffi(),
|
||||
feature_size: self.feature_size.into_ffi(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION BINDINGS
|
||||
pub fn entry_points<L: 'static>() -> Option<(&'static str, &'static str)>
|
||||
{
|
||||
|
@@ -14,9 +14,10 @@ use crate::sim::{CellStateWithM, GenericSim, MaterialSim, Sample, SampleableSim}
|
||||
use crate::stim::AbstractStimulus;
|
||||
use crate::types::vec::Vec3;
|
||||
use coremem_types::mat::{FullyGenericMaterial, Material};
|
||||
use coremem_types::step::SimMeta;
|
||||
|
||||
mod bindings;
|
||||
pub use bindings::{entry_points, IntoFfi as _, SimMeta};
|
||||
pub use bindings::entry_points;
|
||||
|
||||
/// Wrapper around an inner state object which offloads stepping onto a spirv backend (e.g. GPU).
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
@@ -114,7 +115,7 @@ where
|
||||
}
|
||||
|
||||
fn size(&self) -> Index {
|
||||
self.meta.dim
|
||||
Index(self.meta.dim)
|
||||
}
|
||||
fn feature_size(&self) -> f32 {
|
||||
self.meta.feature_size
|
||||
@@ -182,7 +183,7 @@ impl<M> SpirvSim<M>
|
||||
mat.resize_with(flat_size, Default::default);
|
||||
Self {
|
||||
meta: SimMeta {
|
||||
dim: size,
|
||||
dim: *size,
|
||||
inv_feature_size: 1.0/feature_size,
|
||||
time_step,
|
||||
feature_size,
|
||||
@@ -258,7 +259,7 @@ where
|
||||
let (stim_cpu_e, stim_cpu_h) = self.eval_stimulus(stim);
|
||||
let field_bytes = size.product_sum() * 12;
|
||||
|
||||
let sim_meta = [self.meta.clone().into_ffi()];
|
||||
let sim_meta = [self.meta.clone()];
|
||||
|
||||
self.wgpu.get_or_insert_with(
|
||||
|| Arc::new(WgpuData::new::<M>(size.volume()))
|
||||
|
@@ -3,11 +3,12 @@ use crate::support::{Array3, Array3Mut, UnsizedArray};
|
||||
use coremem_types::compound::Optional;
|
||||
use coremem_types::mat::Material;
|
||||
use coremem_types::real::Real;
|
||||
use coremem_types::step::SimMeta;
|
||||
use coremem_types::vec::{Vec3, Vec3u};
|
||||
|
||||
pub(crate) fn step_h<R: Real, M: Material<R>>(
|
||||
id: Vec3u,
|
||||
meta: &SerializedSimMeta<R>,
|
||||
meta: &SimMeta<R>,
|
||||
stimulus_h: &UnsizedArray<Vec3<R>>,
|
||||
material: &UnsizedArray<M>,
|
||||
e: &UnsizedArray<Vec3<R>>,
|
||||
@@ -24,7 +25,7 @@ pub(crate) fn step_h<R: Real, M: Material<R>>(
|
||||
|
||||
pub(crate) fn step_e<R: Real, M: Material<R>>(
|
||||
id: Vec3u,
|
||||
meta: &SerializedSimMeta<R>,
|
||||
meta: &SimMeta<R>,
|
||||
stimulus_e: &UnsizedArray<Vec3<R>>,
|
||||
material: &UnsizedArray<M>,
|
||||
e: &mut UnsizedArray<Vec3<R>>,
|
||||
@@ -39,18 +40,10 @@ pub(crate) fn step_e<R: Real, M: Material<R>>(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct SerializedSimMeta<R> {
|
||||
pub dim: Vec3u,
|
||||
pub inv_feature_size: R,
|
||||
pub time_step: R,
|
||||
pub feature_size: R,
|
||||
}
|
||||
|
||||
|
||||
/// Whatever data we received from the host in their call to step_h
|
||||
struct SerializedStepH<'a, R, M> {
|
||||
meta: &'a SerializedSimMeta<R>,
|
||||
meta: &'a SimMeta<R>,
|
||||
stimulus_h: &'a UnsizedArray<Vec3<R>>,
|
||||
material: &'a UnsizedArray<M>,
|
||||
e: &'a UnsizedArray<Vec3<R>>,
|
||||
@@ -60,7 +53,7 @@ struct SerializedStepH<'a, R, M> {
|
||||
|
||||
impl<'a, R, M> SerializedStepH<'a, R, M> {
|
||||
fn new(
|
||||
meta: &'a SerializedSimMeta<R>,
|
||||
meta: &'a SimMeta<R>,
|
||||
stimulus_h: &'a UnsizedArray<Vec3<R>>,
|
||||
material: &'a UnsizedArray<M>,
|
||||
e: &'a UnsizedArray<Vec3<R>>,
|
||||
@@ -118,7 +111,7 @@ impl<'a, R: Real, M> SerializedStepH<'a, R, M> {
|
||||
|
||||
/// Whatever data we received from the host in their call to step_e
|
||||
struct SerializedStepE<'a, R, M> {
|
||||
meta: &'a SerializedSimMeta<R>,
|
||||
meta: &'a SimMeta<R>,
|
||||
stimulus_e: &'a UnsizedArray<Vec3<R>>,
|
||||
material: &'a UnsizedArray<M>,
|
||||
e: &'a mut UnsizedArray<Vec3<R>>,
|
||||
@@ -127,7 +120,7 @@ struct SerializedStepE<'a, R, M> {
|
||||
|
||||
impl<'a, R, M> SerializedStepE<'a, R, M> {
|
||||
pub fn new(
|
||||
meta: &'a SerializedSimMeta<R>,
|
||||
meta: &'a SimMeta<R>,
|
||||
stimulus_e: &'a UnsizedArray<Vec3<R>>,
|
||||
material: &'a UnsizedArray<M>,
|
||||
e: &'a mut UnsizedArray<Vec3<R>>,
|
||||
|
@@ -15,11 +15,11 @@ use spirv_std::macros::spirv;
|
||||
mod adapt;
|
||||
pub mod support;
|
||||
|
||||
pub use adapt::SerializedSimMeta;
|
||||
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<R> = IsoConductorOr<R, Ferroxcube3R1MH>;
|
||||
@@ -54,7 +54,7 @@ macro_rules! steps {
|
||||
#[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: &SerializedSimMeta<$flt>,
|
||||
#[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<Vec3<$flt>>,
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &UnsizedArray<Vec3<$flt>>,
|
||||
@@ -69,7 +69,7 @@ macro_rules! steps {
|
||||
#[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: &SerializedSimMeta<$flt>,
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SimMeta<$flt>,
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] stimulus_e: &UnsizedArray<Vec3<$flt>>,
|
||||
// XXX: delete this input?
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &UnsizedArray<Vec3<$flt>>,
|
||||
|
@@ -1,7 +1,20 @@
|
||||
use crate::compound::Optional;
|
||||
use crate::mat::Material;
|
||||
use crate::real::Real;
|
||||
use crate::vec::Vec3;
|
||||
use crate::vec::{Vec3, Vec3u};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
#[cfg_attr(feature = "fmt", derive(Debug))]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct SimMeta<R> {
|
||||
pub dim: Vec3u,
|
||||
pub inv_feature_size: R,
|
||||
pub time_step: R,
|
||||
pub feature_size: R,
|
||||
}
|
||||
|
||||
/// Package the field vectors adjacent to some particular location.
|
||||
/// Particular those at negative offsets from the midpoint.
|
||||
|
Reference in New Issue
Block a user