spirv_backend: remove Vec3Std and use coremem_types::Vec3 everywhere
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::geom::{Index, Vec3, Vec3u};
|
|||||||
mod ffi {
|
mod ffi {
|
||||||
pub use spirv_backend::entry_points;
|
pub use spirv_backend::entry_points;
|
||||||
pub use spirv_backend::sim::SerializedSimMeta;
|
pub use spirv_backend::sim::SerializedSimMeta;
|
||||||
pub use spirv_backend::support::{Optional, Vec3Std};
|
pub use spirv_backend::support::Optional;
|
||||||
pub use spirv_backend::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr, Material, MBPgram, MHPgram};
|
pub use spirv_backend::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr, Material, MBPgram, MHPgram};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,9 +53,11 @@ macro_rules! identity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: should work for any other lifetime, not just 'static
|
// XXX: should work for any other lifetime, not just 'static
|
||||||
|
identity!(=> f32);
|
||||||
identity!(=> &'static str);
|
identity!(=> &'static str);
|
||||||
identity!(T0, T1, => (T0, T1));
|
identity!(T0, T1, => (T0, T1));
|
||||||
identity!(=> Vec3u);
|
identity!(=> Vec3u);
|
||||||
|
identity!(T, => Vec3<T>);
|
||||||
|
|
||||||
impl<L: IntoFfi> IntoFfi for Option<L>
|
impl<L: IntoFfi> IntoFfi for Option<L>
|
||||||
where L::Ffi: Default
|
where L::Ffi: Default
|
||||||
@@ -80,19 +82,6 @@ impl<F: Copy + IntoLib> IntoLib for ffi::Optional<F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoFfi for Vec3<f32> {
|
|
||||||
type Ffi = ffi::Vec3Std;
|
|
||||||
fn into_ffi(self) -> Self::Ffi {
|
|
||||||
Self::Ffi::new(self.x(), self.y(), self.z())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl IntoLib for ffi::Vec3Std {
|
|
||||||
type Lib = Vec3<f32>;
|
|
||||||
fn into_lib(self) -> Self::Lib {
|
|
||||||
Self::Lib::new(self.x(), self.y(), self.z())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoFfi for MBPgram<f32> {
|
impl IntoFfi for MBPgram<f32> {
|
||||||
type Ffi = ffi::MBPgram;
|
type Ffi = ffi::MBPgram;
|
||||||
fn into_ffi(self) -> Self::Ffi {
|
fn into_ffi(self) -> Self::Ffi {
|
||||||
|
@@ -744,7 +744,7 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::sim::Meters;
|
use crate::sim::Meters;
|
||||||
use crate::stim::{NoopStimulus, RngStimulus};
|
use crate::stim::{NoopStimulus, RngStimulus};
|
||||||
use spirv_backend::{step_e_generic_material as step_e, step_h_generic_material as step_h, UVec3};
|
use spirv_backend::{step_e_generic_material as step_e, step_h_generic_material as step_h, glam};
|
||||||
|
|
||||||
fn do_step<S: AbstractStimulus>(state: &mut SpirvSim, stim: &S) {
|
fn do_step<S: AbstractStimulus>(state: &mut SpirvSim, stim: &S) {
|
||||||
let meta = state.meta.clone();
|
let meta = state.meta.clone();
|
||||||
@@ -766,7 +766,7 @@ mod test {
|
|||||||
for z in 0..meta.dim.z() {
|
for z in 0..meta.dim.z() {
|
||||||
for y in 0..meta.dim.y() {
|
for y in 0..meta.dim.y() {
|
||||||
for x in 0..meta.dim.x() {
|
for x in 0..meta.dim.x() {
|
||||||
step_e(UVec3::new(x, y, z), meta_for_step, stim_e, stim_h, mat, e, h, m);
|
step_e(glam::UVec3::new(x, y, z), meta_for_step, stim_e, stim_h, mat, e, h, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -774,7 +774,7 @@ mod test {
|
|||||||
for z in 0..meta.dim.z() {
|
for z in 0..meta.dim.z() {
|
||||||
for y in 0..meta.dim.y() {
|
for y in 0..meta.dim.y() {
|
||||||
for x in 0..meta.dim.x() {
|
for x in 0..meta.dim.x() {
|
||||||
step_h(UVec3::new(x, y, z), meta_for_step, stim_e, stim_h, mat, e, h, m);
|
step_h(glam::UVec3::new(x, y, z), meta_for_step, stim_e, stim_h, mat, e, h, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
extern crate spirv_std;
|
extern crate spirv_std;
|
||||||
|
|
||||||
pub use spirv_std::glam::{UVec3, Vec3};
|
pub use spirv_std::glam;
|
||||||
#[cfg(not(target_arch = "spirv"))]
|
#[cfg(not(target_arch = "spirv"))]
|
||||||
use spirv_std::macros::spirv;
|
use spirv_std::macros::spirv;
|
||||||
|
|
||||||
@@ -17,26 +17,27 @@ pub mod sim;
|
|||||||
pub mod support;
|
pub mod support;
|
||||||
|
|
||||||
pub use sim::{SerializedSimMeta, SerializedStepE, SerializedStepH};
|
pub use sim::{SerializedSimMeta, SerializedStepE, SerializedStepH};
|
||||||
pub use support::{Optional, UnsizedArray, Vec3Std};
|
pub use support::{Optional, UnsizedArray};
|
||||||
|
|
||||||
use mat::{IsoConductorOr, Ferroxcube3R1MH, FullyGenericMaterial, Material};
|
use mat::{IsoConductorOr, Ferroxcube3R1MH, FullyGenericMaterial, Material};
|
||||||
|
|
||||||
use coremem_types::vecu::Vec3u;
|
use coremem_types::vecu::Vec3u;
|
||||||
|
use coremem_types::vec::Vec3;
|
||||||
|
|
||||||
type Iso3R1 = IsoConductorOr<Ferroxcube3R1MH>;
|
type Iso3R1 = IsoConductorOr<Ferroxcube3R1MH>;
|
||||||
|
|
||||||
fn glam_vec_to_internal(v: UVec3) -> Vec3u {
|
fn glam_vec_to_internal(v: glam::UVec3) -> Vec3u {
|
||||||
Vec3u::new(v.x, v.y, v.z)
|
Vec3u::new(v.x, v.y, v.z)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step_h<M: Material>(
|
fn step_h<M: Material>(
|
||||||
id: Vec3u,
|
id: Vec3u,
|
||||||
meta: &SerializedSimMeta,
|
meta: &SerializedSimMeta,
|
||||||
stimulus_h: &UnsizedArray<Vec3Std>,
|
stimulus_h: &UnsizedArray<Vec3<f32>>,
|
||||||
material: &UnsizedArray<M>,
|
material: &UnsizedArray<M>,
|
||||||
e: &UnsizedArray<Vec3Std>,
|
e: &UnsizedArray<Vec3<f32>>,
|
||||||
h: &mut UnsizedArray<Vec3Std>,
|
h: &mut UnsizedArray<Vec3<f32>>,
|
||||||
m: &mut UnsizedArray<Vec3Std>,
|
m: &mut UnsizedArray<Vec3<f32>>,
|
||||||
) {
|
) {
|
||||||
if id.x() < meta.dim.x() && id.y() < meta.dim.y() && id.z() < meta.dim.z() {
|
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 sim_state = SerializedStepH::new(meta, stimulus_h, material, e, h, m);
|
||||||
@@ -48,10 +49,10 @@ fn step_h<M: Material>(
|
|||||||
fn step_e<M: Material>(
|
fn step_e<M: Material>(
|
||||||
id: Vec3u,
|
id: Vec3u,
|
||||||
meta: &SerializedSimMeta,
|
meta: &SerializedSimMeta,
|
||||||
stimulus_e: &UnsizedArray<Vec3Std>,
|
stimulus_e: &UnsizedArray<Vec3<f32>>,
|
||||||
material: &UnsizedArray<M>,
|
material: &UnsizedArray<M>,
|
||||||
e: &mut UnsizedArray<Vec3Std>,
|
e: &mut UnsizedArray<Vec3<f32>>,
|
||||||
h: &UnsizedArray<Vec3Std>,
|
h: &UnsizedArray<Vec3<f32>>,
|
||||||
) {
|
) {
|
||||||
if id.x() < meta.dim.x() && id.y() < meta.dim.y() && id.z() < meta.dim.z() {
|
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 sim_state = SerializedStepE::new(meta, stimulus_e, material, e, h);
|
||||||
@@ -86,31 +87,31 @@ macro_rules! steps {
|
|||||||
// LocalSize/numthreads
|
// LocalSize/numthreads
|
||||||
#[spirv(compute(threads(4, 4, 4)))]
|
#[spirv(compute(threads(4, 4, 4)))]
|
||||||
pub fn $step_h(
|
pub fn $step_h(
|
||||||
#[spirv(global_invocation_id)] id: UVec3,
|
#[spirv(global_invocation_id)] id: glam::UVec3,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
|
||||||
// XXX: delete this input?
|
// XXX: delete this input?
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] _unused_stimulus_e: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] _unused_stimulus_e: &UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] stimulus_h: &UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>,
|
#[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 = 4)] e: &UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &mut UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] m: &mut UnsizedArray<Vec3<f32>>,
|
||||||
) {
|
) {
|
||||||
step_h(glam_vec_to_internal(id), meta, stimulus_h, material, e, h, m)
|
step_h(glam_vec_to_internal(id), meta, stimulus_h, material, e, h, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[spirv(compute(threads(4, 4, 4)))]
|
#[spirv(compute(threads(4, 4, 4)))]
|
||||||
pub fn $step_e(
|
pub fn $step_e(
|
||||||
#[spirv(global_invocation_id)] id: UVec3,
|
#[spirv(global_invocation_id)] id: glam::UVec3,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] meta: &SerializedSimMeta,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] stimulus_e: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] stimulus_e: &UnsizedArray<Vec3<f32>>,
|
||||||
// XXX: delete this input?
|
// XXX: delete this input?
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] _unused_stimulus_h: &UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] material: &UnsizedArray<$mat>,
|
#[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 = 4)] e: &mut UnsizedArray<Vec3<f32>>,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] h: &UnsizedArray<Vec3<f32>>,
|
||||||
// XXX: can/should this m input be deleted?
|
// XXX: can/should this m input be deleted?
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &UnsizedArray<Vec3Std>,
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 6)] _unused_m: &UnsizedArray<Vec3<f32>>,
|
||||||
) {
|
) {
|
||||||
step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h)
|
step_e(glam_vec_to_internal(id), meta, stimulus_e, material, e, h)
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
use crate::support::{Optional, Vec3Std};
|
use crate::support::Optional;
|
||||||
|
use coremem_types::vec::Vec3;
|
||||||
|
|
||||||
pub trait Material: Sized {
|
pub trait Material: Sized {
|
||||||
fn conductivity(&self) -> Vec3Std {
|
fn conductivity(&self) -> Vec3<f32> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
/// returns the new M vector for this material
|
/// returns the new M vector for this material
|
||||||
fn move_b_vec(&self, m: Vec3Std, _target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, _target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
// XXX could return either 0, or `m`. they should be the same, but one might be more
|
// XXX could return either 0, or `m`. they should be the same, but one might be more
|
||||||
// optimizable than the other (untested).
|
// optimizable than the other (untested).
|
||||||
m
|
m
|
||||||
@@ -14,18 +15,18 @@ pub trait Material: Sized {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Default, PartialEq)]
|
#[derive(Copy, Clone, Default, PartialEq)]
|
||||||
pub struct Conductor<T>(pub T);
|
pub struct Conductor<T>(pub T);
|
||||||
pub type AnisomorphicConductor = Conductor<Vec3Std>;
|
pub type AnisomorphicConductor = Conductor<Vec3<f32>>;
|
||||||
pub type IsomorphicConductor = Conductor<f32>;
|
pub type IsomorphicConductor = Conductor<f32>;
|
||||||
|
|
||||||
impl Material for AnisomorphicConductor {
|
impl Material for AnisomorphicConductor {
|
||||||
fn conductivity(&self) -> Vec3Std {
|
fn conductivity(&self) -> Vec3<f32> {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material for IsomorphicConductor {
|
impl Material for IsomorphicConductor {
|
||||||
fn conductivity(&self) -> Vec3Std {
|
fn conductivity(&self) -> Vec3<f32> {
|
||||||
Vec3Std::uniform(self.0)
|
Vec3::uniform(self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +80,8 @@ impl MBPgram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Material for MBPgram {
|
impl Material for MBPgram {
|
||||||
fn move_b_vec(&self, m: Vec3Std, target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
Vec3Std::new(
|
Vec3::new(
|
||||||
self.move_b(m.x(), target_b.x()),
|
self.move_b(m.x(), target_b.x()),
|
||||||
self.move_b(m.y(), target_b.y()),
|
self.move_b(m.y(), target_b.y()),
|
||||||
self.move_b(m.z(), target_b.z()),
|
self.move_b(m.z(), target_b.z()),
|
||||||
@@ -167,8 +168,8 @@ impl MHPgram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Material for MHPgram {
|
impl Material for MHPgram {
|
||||||
fn move_b_vec(&self, m: Vec3Std, target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
Vec3Std::new(
|
Vec3::new(
|
||||||
self.move_b(m.x(), target_b.x()),
|
self.move_b(m.x(), target_b.x()),
|
||||||
self.move_b(m.y(), target_b.y()),
|
self.move_b(m.y(), target_b.y()),
|
||||||
self.move_b(m.z(), target_b.z()),
|
self.move_b(m.z(), target_b.z()),
|
||||||
@@ -178,16 +179,16 @@ impl Material for MHPgram {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Default, PartialEq)]
|
#[derive(Copy, Clone, Default, PartialEq)]
|
||||||
pub struct FullyGenericMaterial {
|
pub struct FullyGenericMaterial {
|
||||||
pub conductivity: Vec3Std,
|
pub conductivity: Vec3<f32>,
|
||||||
pub m_b_curve: Optional<MBPgram>,
|
pub m_b_curve: Optional<MBPgram>,
|
||||||
pub m_h_curve: Optional<MHPgram>,
|
pub m_h_curve: Optional<MHPgram>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material for FullyGenericMaterial {
|
impl Material for FullyGenericMaterial {
|
||||||
fn conductivity(&self) -> Vec3Std {
|
fn conductivity(&self) -> Vec3<f32> {
|
||||||
self.conductivity
|
self.conductivity
|
||||||
}
|
}
|
||||||
fn move_b_vec(&self, m: Vec3Std, target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
if self.m_b_curve.is_some() {
|
if self.m_b_curve.is_some() {
|
||||||
self.m_b_curve.unwrap().move_b_vec(m, target_b)
|
self.m_b_curve.unwrap().move_b_vec(m, target_b)
|
||||||
} else if self.m_h_curve.is_some() {
|
} else if self.m_h_curve.is_some() {
|
||||||
@@ -210,7 +211,7 @@ impl Into<MHPgram> for Ferroxcube3R1MH {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Material for Ferroxcube3R1MH {
|
impl Material for Ferroxcube3R1MH {
|
||||||
fn move_b_vec(&self, m: Vec3Std, target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
let curve: MHPgram = (*self).into();
|
let curve: MHPgram = (*self).into();
|
||||||
curve.move_b_vec(m, target_b)
|
curve.move_b_vec(m, target_b)
|
||||||
}
|
}
|
||||||
@@ -241,10 +242,10 @@ impl<M: Default> IsoConductorOr<M> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Material + Copy> Material for IsoConductorOr<M> {
|
impl<M: Material + Copy> Material for IsoConductorOr<M> {
|
||||||
fn conductivity(&self) -> Vec3Std {
|
fn conductivity(&self) -> Vec3<f32> {
|
||||||
Vec3Std::uniform(self.value.max(0.0))
|
Vec3::uniform(self.value.max(0.0))
|
||||||
}
|
}
|
||||||
fn move_b_vec(&self, m: Vec3Std, target_b: Vec3Std) -> Vec3Std {
|
fn move_b_vec(&self, m: Vec3<f32>, target_b: Vec3<f32>) -> Vec3<f32> {
|
||||||
if self.value < 0.0 {
|
if self.value < 0.0 {
|
||||||
let mat = self.mat; //< XXX hack for ZST
|
let mat = self.mat; //< XXX hack for ZST
|
||||||
mat.move_b_vec(m, target_b)
|
mat.move_b_vec(m, target_b)
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
// use spirv_std::RuntimeArray;
|
// use spirv_std::RuntimeArray;
|
||||||
use crate::mat::Material;
|
use crate::mat::Material;
|
||||||
use crate::support::{
|
use crate::support::{
|
||||||
Array3, Array3Mut, ArrayHandle, ArrayHandleMut, Optional, UnsizedArray, Vec3Std
|
Array3, Array3Mut, ArrayHandle, ArrayHandleMut, Optional, UnsizedArray
|
||||||
};
|
};
|
||||||
|
use coremem_types::vec::Vec3;
|
||||||
use coremem_types::vecu::Vec3u;
|
use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@@ -17,21 +18,21 @@ pub struct SerializedSimMeta {
|
|||||||
/// Whatever data we received from the host in their call to step_h
|
/// Whatever data we received from the host in their call to step_h
|
||||||
pub struct SerializedStepH<'a, M> {
|
pub struct SerializedStepH<'a, M> {
|
||||||
meta: &'a SerializedSimMeta,
|
meta: &'a SerializedSimMeta,
|
||||||
stimulus_h: &'a UnsizedArray<Vec3Std>,
|
stimulus_h: &'a UnsizedArray<Vec3<f32>>,
|
||||||
material: &'a UnsizedArray<M>,
|
material: &'a UnsizedArray<M>,
|
||||||
e: &'a UnsizedArray<Vec3Std>,
|
e: &'a UnsizedArray<Vec3<f32>>,
|
||||||
h: &'a mut UnsizedArray<Vec3Std>,
|
h: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
m: &'a mut UnsizedArray<Vec3Std>,
|
m: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, M> SerializedStepH<'a, M> {
|
impl<'a, M> SerializedStepH<'a, M> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
meta: &'a SerializedSimMeta,
|
meta: &'a SerializedSimMeta,
|
||||||
stimulus_h: &'a UnsizedArray<Vec3Std>,
|
stimulus_h: &'a UnsizedArray<Vec3<f32>>,
|
||||||
material: &'a UnsizedArray<M>,
|
material: &'a UnsizedArray<M>,
|
||||||
e: &'a UnsizedArray<Vec3Std>,
|
e: &'a UnsizedArray<Vec3<f32>>,
|
||||||
h: &'a mut UnsizedArray<Vec3Std>,
|
h: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
m: &'a mut UnsizedArray<Vec3Std>,
|
m: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
meta, stimulus_h, material, e, h, m
|
meta, stimulus_h, material, e, h, m
|
||||||
@@ -72,19 +73,19 @@ impl<'a, M> SerializedStepH<'a, M> {
|
|||||||
/// Whatever data we received from the host in their call to step_e
|
/// Whatever data we received from the host in their call to step_e
|
||||||
pub struct SerializedStepE<'a, M> {
|
pub struct SerializedStepE<'a, M> {
|
||||||
meta: &'a SerializedSimMeta,
|
meta: &'a SerializedSimMeta,
|
||||||
stimulus_e: &'a UnsizedArray<Vec3Std>,
|
stimulus_e: &'a UnsizedArray<Vec3<f32>>,
|
||||||
material: &'a UnsizedArray<M>,
|
material: &'a UnsizedArray<M>,
|
||||||
e: &'a mut UnsizedArray<Vec3Std>,
|
e: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
h: &'a UnsizedArray<Vec3Std>,
|
h: &'a UnsizedArray<Vec3<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, M> SerializedStepE<'a, M> {
|
impl<'a, M> SerializedStepE<'a, M> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
meta: &'a SerializedSimMeta,
|
meta: &'a SerializedSimMeta,
|
||||||
stimulus_e: &'a UnsizedArray<Vec3Std>,
|
stimulus_e: &'a UnsizedArray<Vec3<f32>>,
|
||||||
material: &'a UnsizedArray<M>,
|
material: &'a UnsizedArray<M>,
|
||||||
e: &'a mut UnsizedArray<Vec3Std>,
|
e: &'a mut UnsizedArray<Vec3<f32>>,
|
||||||
h: &'a UnsizedArray<Vec3Std>,
|
h: &'a UnsizedArray<Vec3<f32>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
meta, stimulus_e, material, e, h
|
meta, stimulus_e, material, e, h
|
||||||
@@ -140,10 +141,10 @@ impl<'a, M> SerializedStepE<'a, M> {
|
|||||||
/// This is used in step_e when looking at the H field deltas.
|
/// This is used in step_e when looking at the H field deltas.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct VolumeSampleNeg {
|
struct VolumeSampleNeg {
|
||||||
mid: Vec3Std,
|
mid: Vec3<f32>,
|
||||||
xm1: Optional<Vec3Std>,
|
xm1: Optional<Vec3<f32>>,
|
||||||
ym1: Optional<Vec3Std>,
|
ym1: Optional<Vec3<f32>>,
|
||||||
zm1: Optional<Vec3Std>,
|
zm1: Optional<Vec3<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VolumeSampleNeg {
|
impl VolumeSampleNeg {
|
||||||
@@ -197,10 +198,10 @@ impl VolumeSampleNeg {
|
|||||||
/// This is used in step_h when looking at the E field deltas.
|
/// This is used in step_h when looking at the E field deltas.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct VolumeSamplePos {
|
struct VolumeSamplePos {
|
||||||
mid: Vec3Std,
|
mid: Vec3<f32>,
|
||||||
xp1: Optional<Vec3Std>,
|
xp1: Optional<Vec3<f32>>,
|
||||||
yp1: Optional<Vec3Std>,
|
yp1: Optional<Vec3<f32>>,
|
||||||
zp1: Optional<Vec3Std>
|
zp1: Optional<Vec3<f32>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VolumeSamplePos {
|
impl VolumeSamplePos {
|
||||||
@@ -258,8 +259,8 @@ struct FieldDeltas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FieldDeltas {
|
impl FieldDeltas {
|
||||||
fn nabla(self) -> Vec3Std {
|
fn nabla(self) -> Vec3<f32> {
|
||||||
Vec3Std::new(
|
Vec3::new(
|
||||||
self.dfz_dy - self.dfy_dz,
|
self.dfz_dy - self.dfy_dz,
|
||||||
self.dfx_dz - self.dfz_dx,
|
self.dfx_dz - self.dfz_dx,
|
||||||
self.dfy_dx - self.dfx_dy,
|
self.dfy_dx - self.dfx_dy,
|
||||||
@@ -270,12 +271,12 @@ impl FieldDeltas {
|
|||||||
pub struct StepEContext<'a, M> {
|
pub struct StepEContext<'a, M> {
|
||||||
inv_feature_size: f32,
|
inv_feature_size: f32,
|
||||||
time_step: f32,
|
time_step: f32,
|
||||||
stim_e: Vec3Std,
|
stim_e: Vec3<f32>,
|
||||||
mat: ArrayHandle<'a, M>,
|
mat: ArrayHandle<'a, M>,
|
||||||
/// Input field sampled near this location
|
/// Input field sampled near this location
|
||||||
in_h: VolumeSampleNeg,
|
in_h: VolumeSampleNeg,
|
||||||
/// Handle to the output field at one specific index.
|
/// Handle to the output field at one specific index.
|
||||||
out_e: ArrayHandleMut<'a, Vec3Std>,
|
out_e: ArrayHandleMut<'a, Vec3<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, M: Material> StepEContext<'a, M> {
|
impl<'a, M: Material> StepEContext<'a, M> {
|
||||||
@@ -291,7 +292,7 @@ impl<'a, M: Material> StepEContext<'a, M> {
|
|||||||
let sigma = self.mat.get_ref().conductivity();
|
let sigma = self.mat.get_ref().conductivity();
|
||||||
let e_prev = self.out_e.get();
|
let e_prev = self.out_e.get();
|
||||||
let delta_e = (nabla_h - e_prev.elem_mul(sigma)).elem_div(
|
let delta_e = (nabla_h - e_prev.elem_mul(sigma)).elem_div(
|
||||||
sigma*self.time_step + Vec3Std::uniform(TWICE_EPS0)
|
sigma*self.time_step + Vec3::uniform(TWICE_EPS0)
|
||||||
)*(2.0*self.time_step);
|
)*(2.0*self.time_step);
|
||||||
// println!("spirv-step_e delta_e: {:?}", delta_e);
|
// println!("spirv-step_e delta_e: {:?}", delta_e);
|
||||||
self.out_e.write(e_prev + delta_e + self.stim_e);
|
self.out_e.write(e_prev + delta_e + self.stim_e);
|
||||||
@@ -302,13 +303,13 @@ impl<'a, M: Material> StepEContext<'a, M> {
|
|||||||
pub struct StepHContext<'a, M> {
|
pub struct StepHContext<'a, M> {
|
||||||
inv_feature_size: f32,
|
inv_feature_size: f32,
|
||||||
time_step: f32,
|
time_step: f32,
|
||||||
stim_h: Vec3Std,
|
stim_h: Vec3<f32>,
|
||||||
mat: ArrayHandle<'a, M>,
|
mat: ArrayHandle<'a, M>,
|
||||||
/// Input field sampled near this location
|
/// Input field sampled near this location
|
||||||
in_e: VolumeSamplePos,
|
in_e: VolumeSamplePos,
|
||||||
/// Handle to the output field at one specific index.
|
/// Handle to the output field at one specific index.
|
||||||
out_h: ArrayHandleMut<'a, Vec3Std>,
|
out_h: ArrayHandleMut<'a, Vec3<f32>>,
|
||||||
out_m: ArrayHandleMut<'a, Vec3Std>,
|
out_m: ArrayHandleMut<'a, Vec3<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, M: Material> StepHContext<'a, M> {
|
impl<'a, M: Material> StepHContext<'a, M> {
|
||||||
|
@@ -1,11 +1,5 @@
|
|||||||
use coremem_types::vec;
|
|
||||||
use coremem_types::vecu::Vec3u;
|
use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, PartialEq)]
|
|
||||||
pub struct XYZStd<T>(T, T, T);
|
|
||||||
|
|
||||||
pub type Vec3Std = vec::Vec3<f32>;
|
|
||||||
|
|
||||||
/// This is a spirv-compatible option type.
|
/// This is a spirv-compatible option type.
|
||||||
/// The native rust Option type produces invalid spirv due to its enum nature; this custom option
|
/// The native rust Option type produces invalid spirv due to its enum nature; this custom option
|
||||||
/// type creates code which will actually compile.
|
/// type creates code which will actually compile.
|
||||||
|
Reference in New Issue
Block a user