spirv_backend: remove UVec3Std in favor of Vec3u
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
use coremem_types::vec;
|
||||
use coremem_types::vecu;
|
||||
use coremem_types::vecu::Vec3u;
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
pub struct XYZStd<T>(T, T, T);
|
||||
|
||||
pub type Vec3Std = vec::Vec3<f32>;
|
||||
pub type UVec3Std = vecu::Vec3u;
|
||||
|
||||
/// This is a spirv-compatible option type.
|
||||
/// 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)]
|
||||
pub struct Array3<'a, 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
|
||||
}
|
||||
|
||||
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() {
|
||||
let flat_idx = index(idx, dim);
|
||||
Optional::some(flat_idx)
|
||||
@@ -201,18 +200,18 @@ fn checked_index(idx: UVec3Std, dim: UVec3Std) -> Optional<usize> {
|
||||
}
|
||||
|
||||
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 {
|
||||
data,
|
||||
dim,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index(self, idx: UVec3Std) -> Optional<usize> {
|
||||
pub fn index(self, idx: Vec3u) -> Optional<usize> {
|
||||
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();
|
||||
unsafe {
|
||||
self.data.get_handle(idx)
|
||||
@@ -221,7 +220,7 @@ impl<'a, T> 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);
|
||||
if idx.is_some() {
|
||||
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.
|
||||
pub struct Array3Mut<'a, T> {
|
||||
data: &'a mut UnsizedArray<T>,
|
||||
dim: UVec3Std,
|
||||
dim: Vec3u,
|
||||
}
|
||||
|
||||
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 {
|
||||
data,
|
||||
dim,
|
||||
@@ -251,7 +250,7 @@ impl<'a, T> Array3Mut<'a, T> {
|
||||
// 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() {
|
||||
let flat_idx = index(idx, self.dim);
|
||||
Optional::some(flat_idx)
|
||||
@@ -262,7 +261,7 @@ impl<'a, T> 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();
|
||||
unsafe {
|
||||
self.data.get_handle_mut(idx)
|
||||
@@ -276,16 +275,16 @@ mod test {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_index() {
|
||||
let dim = UVec3Std::new(2, 3, 7);
|
||||
assert_eq!(index(UVec3Std::new(0, 0, 0), dim), 0);
|
||||
assert_eq!(index(UVec3Std::new(1, 0, 0), dim), 1);
|
||||
assert_eq!(index(UVec3Std::new(0, 1, 0), dim), 2);
|
||||
assert_eq!(index(UVec3Std::new(1, 1, 0), dim), 3);
|
||||
assert_eq!(index(UVec3Std::new(0, 2, 0), dim), 4);
|
||||
assert_eq!(index(UVec3Std::new(0, 0, 1), dim), 6);
|
||||
assert_eq!(index(UVec3Std::new(1, 0, 1), dim), 7);
|
||||
assert_eq!(index(UVec3Std::new(0, 1, 1), dim), 8);
|
||||
assert_eq!(index(UVec3Std::new(1, 2, 1), dim), 11);
|
||||
assert_eq!(index(UVec3Std::new(1, 2, 2), dim), 17);
|
||||
let dim = Vec3u::new(2, 3, 7);
|
||||
assert_eq!(index(Vec3u::new(0, 0, 0), dim), 0);
|
||||
assert_eq!(index(Vec3u::new(1, 0, 0), dim), 1);
|
||||
assert_eq!(index(Vec3u::new(0, 1, 0), dim), 2);
|
||||
assert_eq!(index(Vec3u::new(1, 1, 0), dim), 3);
|
||||
assert_eq!(index(Vec3u::new(0, 2, 0), dim), 4);
|
||||
assert_eq!(index(Vec3u::new(0, 0, 1), dim), 6);
|
||||
assert_eq!(index(Vec3u::new(1, 0, 1), dim), 7);
|
||||
assert_eq!(index(Vec3u::new(0, 1, 1), dim), 8);
|
||||
assert_eq!(index(Vec3u::new(1, 2, 1), dim), 11);
|
||||
assert_eq!(index(Vec3u::new(1, 2, 2), dim), 17);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user