spirv_backend: remove UVec3Std in favor of Vec3u
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, UVec3Std};
|
pub use spirv_backend::support::{Optional, Vec3Std};
|
||||||
pub use spirv_backend::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr, Material, MBPgram, MHPgram};
|
pub use spirv_backend::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr, Material, MBPgram, MHPgram};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +55,7 @@ macro_rules! identity {
|
|||||||
// XXX: should work for any other lifetime, not just 'static
|
// XXX: should work for any other lifetime, not just 'static
|
||||||
identity!(=> &'static str);
|
identity!(=> &'static str);
|
||||||
identity!(T0, T1, => (T0, T1));
|
identity!(T0, T1, => (T0, T1));
|
||||||
|
identity!(=> Vec3u);
|
||||||
|
|
||||||
impl<L: IntoFfi> IntoFfi for Option<L>
|
impl<L: IntoFfi> IntoFfi for Option<L>
|
||||||
where L::Ffi: Default
|
where L::Ffi: Default
|
||||||
@@ -92,19 +93,6 @@ impl IntoLib for ffi::Vec3Std {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoFfi for Vec3u {
|
|
||||||
type Ffi = ffi::UVec3Std;
|
|
||||||
fn into_ffi(self) -> Self::Ffi {
|
|
||||||
Self::Ffi::new(self.x(), self.y(), self.z())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl IntoLib for ffi::UVec3Std {
|
|
||||||
type Lib = Vec3u;
|
|
||||||
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 {
|
||||||
|
@@ -17,18 +17,20 @@ 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, UVec3Std, Vec3Std};
|
pub use support::{Optional, UnsizedArray, Vec3Std};
|
||||||
|
|
||||||
use mat::{IsoConductorOr, Ferroxcube3R1MH, FullyGenericMaterial, Material};
|
use mat::{IsoConductorOr, Ferroxcube3R1MH, FullyGenericMaterial, Material};
|
||||||
|
|
||||||
|
use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
type Iso3R1 = IsoConductorOr<Ferroxcube3R1MH>;
|
type Iso3R1 = IsoConductorOr<Ferroxcube3R1MH>;
|
||||||
|
|
||||||
fn glam_vec_to_internal(v: UVec3) -> UVec3Std {
|
fn glam_vec_to_internal(v: UVec3) -> Vec3u {
|
||||||
UVec3Std::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: UVec3Std,
|
id: Vec3u,
|
||||||
meta: &SerializedSimMeta,
|
meta: &SerializedSimMeta,
|
||||||
stimulus_h: &UnsizedArray<Vec3Std>,
|
stimulus_h: &UnsizedArray<Vec3Std>,
|
||||||
material: &UnsizedArray<M>,
|
material: &UnsizedArray<M>,
|
||||||
@@ -44,7 +46,7 @@ fn step_h<M: Material>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn step_e<M: Material>(
|
fn step_e<M: Material>(
|
||||||
id: UVec3Std,
|
id: Vec3u,
|
||||||
meta: &SerializedSimMeta,
|
meta: &SerializedSimMeta,
|
||||||
stimulus_e: &UnsizedArray<Vec3Std>,
|
stimulus_e: &UnsizedArray<Vec3Std>,
|
||||||
material: &UnsizedArray<M>,
|
material: &UnsizedArray<M>,
|
||||||
|
@@ -1,12 +1,13 @@
|
|||||||
// 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, UVec3Std, Vec3Std
|
Array3, Array3Mut, ArrayHandle, ArrayHandleMut, Optional, UnsizedArray, Vec3Std
|
||||||
};
|
};
|
||||||
|
use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct SerializedSimMeta {
|
pub struct SerializedSimMeta {
|
||||||
pub dim: UVec3Std,
|
pub dim: Vec3u,
|
||||||
pub inv_feature_size: f32,
|
pub inv_feature_size: f32,
|
||||||
pub time_step: f32,
|
pub time_step: f32,
|
||||||
pub feature_size: f32,
|
pub feature_size: f32,
|
||||||
@@ -37,7 +38,7 @@ impl<'a, M> SerializedStepH<'a, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(self, idx: UVec3Std) -> StepHContext<'a, M> {
|
pub fn index(self, idx: Vec3u) -> StepHContext<'a, M> {
|
||||||
let dim = self.meta.dim;
|
let dim = self.meta.dim;
|
||||||
let stim_h_matrix = Array3::new(self.stimulus_h, dim);
|
let stim_h_matrix = Array3::new(self.stimulus_h, dim);
|
||||||
let mat_matrix = Array3::new(self.material, dim);
|
let mat_matrix = Array3::new(self.material, dim);
|
||||||
@@ -47,9 +48,9 @@ impl<'a, M> SerializedStepH<'a, M> {
|
|||||||
|
|
||||||
let in_e = VolumeSamplePos {
|
let in_e = VolumeSamplePos {
|
||||||
mid: e.get(idx).unwrap(),
|
mid: e.get(idx).unwrap(),
|
||||||
xp1: e.get(idx + UVec3Std::unit_x()),
|
xp1: e.get(idx + Vec3u::unit_x()),
|
||||||
yp1: e.get(idx + UVec3Std::unit_y()),
|
yp1: e.get(idx + Vec3u::unit_y()),
|
||||||
zp1: e.get(idx + UVec3Std::unit_z()),
|
zp1: e.get(idx + Vec3u::unit_z()),
|
||||||
};
|
};
|
||||||
let out_h = h.into_mut_handle(idx);
|
let out_h = h.into_mut_handle(idx);
|
||||||
let out_m = m.into_mut_handle(idx);
|
let out_m = m.into_mut_handle(idx);
|
||||||
@@ -90,7 +91,7 @@ impl<'a, M> SerializedStepE<'a, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(self, idx: UVec3Std) -> StepEContext<'a, M> {
|
pub fn index(self, idx: Vec3u) -> StepEContext<'a, M> {
|
||||||
let dim = self.meta.dim;
|
let dim = self.meta.dim;
|
||||||
let stim_e_matrix = Array3::new(self.stimulus_e, dim);
|
let stim_e_matrix = Array3::new(self.stimulus_e, dim);
|
||||||
let mat_matrix = Array3::new(self.material, dim);
|
let mat_matrix = Array3::new(self.material, dim);
|
||||||
@@ -100,17 +101,17 @@ impl<'a, M> SerializedStepE<'a, M> {
|
|||||||
let xm1 = if idx.x() == 0 {
|
let xm1 = if idx.x() == 0 {
|
||||||
Optional::none()
|
Optional::none()
|
||||||
} else {
|
} else {
|
||||||
h.get(idx - UVec3Std::unit_x())
|
h.get(idx - Vec3u::unit_x())
|
||||||
};
|
};
|
||||||
let ym1 = if idx.y() == 0 {
|
let ym1 = if idx.y() == 0 {
|
||||||
Optional::none()
|
Optional::none()
|
||||||
} else {
|
} else {
|
||||||
h.get(idx - UVec3Std::unit_y())
|
h.get(idx - Vec3u::unit_y())
|
||||||
};
|
};
|
||||||
let zm1 = if idx.z() == 0 {
|
let zm1 = if idx.z() == 0 {
|
||||||
Optional::none()
|
Optional::none()
|
||||||
} else {
|
} else {
|
||||||
h.get(idx - UVec3Std::unit_z())
|
h.get(idx - Vec3u::unit_z())
|
||||||
};
|
};
|
||||||
|
|
||||||
let in_h = VolumeSampleNeg {
|
let in_h = VolumeSampleNeg {
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
use coremem_types::vec;
|
use coremem_types::vec;
|
||||||
use coremem_types::vecu;
|
use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, PartialEq)]
|
#[derive(Clone, Copy, Default, PartialEq)]
|
||||||
pub struct XYZStd<T>(T, T, T);
|
pub struct XYZStd<T>(T, T, T);
|
||||||
|
|
||||||
pub type Vec3Std = vec::Vec3<f32>;
|
pub type Vec3Std = vec::Vec3<f32>;
|
||||||
pub type UVec3Std = vecu::Vec3u;
|
|
||||||
|
|
||||||
/// 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
|
||||||
@@ -184,14 +183,14 @@ impl<'a, T: Copy> ArrayHandleMut<'a, T> {
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Array3<'a, T> {
|
pub struct Array3<'a, T> {
|
||||||
data: &'a UnsizedArray<T>,
|
data: &'a UnsizedArray<T>,
|
||||||
dim: UVec3Std,
|
dim: Vec3u,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(loc: UVec3Std, dim: UVec3Std) -> usize {
|
fn index(loc: Vec3u, dim: Vec3u) -> usize {
|
||||||
((loc.z()*dim.y() + loc.y())*dim.x() + loc.x()) as usize
|
((loc.z()*dim.y() + loc.y())*dim.x() + loc.x()) as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checked_index(idx: UVec3Std, dim: UVec3Std) -> Optional<usize> {
|
fn checked_index(idx: Vec3u, dim: Vec3u) -> Optional<usize> {
|
||||||
if idx.x() < dim.x() && idx.y() < dim.y() && idx.z() < dim.z() {
|
if idx.x() < dim.x() && idx.y() < dim.y() && idx.z() < dim.z() {
|
||||||
let flat_idx = index(idx, dim);
|
let flat_idx = index(idx, dim);
|
||||||
Optional::some(flat_idx)
|
Optional::some(flat_idx)
|
||||||
@@ -201,18 +200,18 @@ fn checked_index(idx: UVec3Std, dim: UVec3Std) -> Optional<usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> Array3<'a, T> {
|
impl<'a, T> Array3<'a, T> {
|
||||||
pub fn new(data: &'a UnsizedArray<T>, dim: UVec3Std) -> Self {
|
pub fn new(data: &'a UnsizedArray<T>, dim: Vec3u) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
dim,
|
dim,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(self, idx: UVec3Std) -> Optional<usize> {
|
pub fn index(self, idx: Vec3u) -> Optional<usize> {
|
||||||
checked_index(idx, self.dim)
|
checked_index(idx, self.dim)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_handle(self, idx: UVec3Std) -> ArrayHandle<'a, T> {
|
pub fn into_handle(self, idx: Vec3u) -> ArrayHandle<'a, T> {
|
||||||
let idx = checked_index(idx, self.dim).unwrap();
|
let idx = checked_index(idx, self.dim).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
self.data.get_handle(idx)
|
self.data.get_handle(idx)
|
||||||
@@ -221,7 +220,7 @@ impl<'a, T> Array3<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Copy + Default> Array3<'a, T> {
|
impl<'a, T: Copy + Default> Array3<'a, T> {
|
||||||
pub fn get(&self, idx: UVec3Std) -> Optional<T> {
|
pub fn get(&self, idx: Vec3u) -> Optional<T> {
|
||||||
let idx = self.index(idx);
|
let idx = self.index(idx);
|
||||||
if idx.is_some() {
|
if idx.is_some() {
|
||||||
Optional::some(unsafe {
|
Optional::some(unsafe {
|
||||||
@@ -236,11 +235,11 @@ impl<'a, T: Copy + Default> Array3<'a, T> {
|
|||||||
/// 3d dynamically-sized array backed by a mutably borrowed buffer.
|
/// 3d dynamically-sized array backed by a mutably borrowed buffer.
|
||||||
pub struct Array3Mut<'a, T> {
|
pub struct Array3Mut<'a, T> {
|
||||||
data: &'a mut UnsizedArray<T>,
|
data: &'a mut UnsizedArray<T>,
|
||||||
dim: UVec3Std,
|
dim: Vec3u,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> Array3Mut<'a, T> {
|
impl<'a, T> Array3Mut<'a, T> {
|
||||||
pub fn new(data: &'a mut UnsizedArray<T>, dim: UVec3Std) -> Self {
|
pub fn new(data: &'a mut UnsizedArray<T>, dim: Vec3u) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
dim,
|
dim,
|
||||||
@@ -251,7 +250,7 @@ impl<'a, T> Array3Mut<'a, T> {
|
|||||||
// Array3::new(self.data, self.dim)
|
// Array3::new(self.data, self.dim)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn index(&self, idx: UVec3Std) -> Optional<usize> {
|
pub fn index(&self, idx: Vec3u) -> Optional<usize> {
|
||||||
if idx.x() < self.dim.x() && idx.y() < self.dim.y() && idx.z() < self.dim.z() {
|
if idx.x() < self.dim.x() && idx.y() < self.dim.y() && idx.z() < self.dim.z() {
|
||||||
let flat_idx = index(idx, self.dim);
|
let flat_idx = index(idx, self.dim);
|
||||||
Optional::some(flat_idx)
|
Optional::some(flat_idx)
|
||||||
@@ -262,7 +261,7 @@ impl<'a, T> Array3Mut<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Copy> Array3Mut<'a, T> {
|
impl<'a, T: Copy> Array3Mut<'a, T> {
|
||||||
pub fn into_mut_handle(self, idx: UVec3Std) -> ArrayHandleMut<'a, T> {
|
pub fn into_mut_handle(self, idx: Vec3u) -> ArrayHandleMut<'a, T> {
|
||||||
let idx = self.index(idx).unwrap();
|
let idx = self.index(idx).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
self.data.get_handle_mut(idx)
|
self.data.get_handle_mut(idx)
|
||||||
@@ -276,16 +275,16 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index() {
|
fn test_index() {
|
||||||
let dim = UVec3Std::new(2, 3, 7);
|
let dim = Vec3u::new(2, 3, 7);
|
||||||
assert_eq!(index(UVec3Std::new(0, 0, 0), dim), 0);
|
assert_eq!(index(Vec3u::new(0, 0, 0), dim), 0);
|
||||||
assert_eq!(index(UVec3Std::new(1, 0, 0), dim), 1);
|
assert_eq!(index(Vec3u::new(1, 0, 0), dim), 1);
|
||||||
assert_eq!(index(UVec3Std::new(0, 1, 0), dim), 2);
|
assert_eq!(index(Vec3u::new(0, 1, 0), dim), 2);
|
||||||
assert_eq!(index(UVec3Std::new(1, 1, 0), dim), 3);
|
assert_eq!(index(Vec3u::new(1, 1, 0), dim), 3);
|
||||||
assert_eq!(index(UVec3Std::new(0, 2, 0), dim), 4);
|
assert_eq!(index(Vec3u::new(0, 2, 0), dim), 4);
|
||||||
assert_eq!(index(UVec3Std::new(0, 0, 1), dim), 6);
|
assert_eq!(index(Vec3u::new(0, 0, 1), dim), 6);
|
||||||
assert_eq!(index(UVec3Std::new(1, 0, 1), dim), 7);
|
assert_eq!(index(Vec3u::new(1, 0, 1), dim), 7);
|
||||||
assert_eq!(index(UVec3Std::new(0, 1, 1), dim), 8);
|
assert_eq!(index(Vec3u::new(0, 1, 1), dim), 8);
|
||||||
assert_eq!(index(UVec3Std::new(1, 2, 1), dim), 11);
|
assert_eq!(index(Vec3u::new(1, 2, 1), dim), 11);
|
||||||
assert_eq!(index(UVec3Std::new(1, 2, 2), dim), 17);
|
assert_eq!(index(Vec3u::new(1, 2, 2), dim), 17);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user