diff --git a/crates/spirv_backend/src/support.rs b/crates/spirv_backend/src/support.rs index 4b90551..d368580 100644 --- a/crates/spirv_backend/src/support.rs +++ b/crates/spirv_backend/src/support.rs @@ -1,64 +1,12 @@ use coremem_types::vec; use coremem_types::vecu; -// pub trait Nullable { -// fn null() -> *const Self; -// fn null_mut() -> *mut Self; -// } - #[derive(Clone, Copy, Default, PartialEq)] pub struct XYZStd(T, T, T); pub type Vec3Std = vec::Vec3; pub type UVec3Std = vecu::Vec3u; -// const NULL_VEC3STD: *const Vec3Std = core::ptr::null(); -// const NULL_VEC3STD_MUT: *mut Vec3Std = core::ptr::null_mut(); -// impl Nullable for Vec3Std { -// fn null() -> *const Self { -// NULL_VEC3STD -// } -// fn null_mut() -> *mut Self { -// NULL_VEC3STD_MUT -// } -// } - - -// pub struct OptionalRef<'a, T> { -// ptr: *const T, // NULL for None -// _marker: PhantomData<&'a T>, -// } -// -// impl<'a, T> OptionalRef<'a, T> { -// fn from_ptr(ptr: *const T) -> Self { -// Self { -// ptr, -// _marker: PhantomData, -// } -// } -// -// pub fn some(data: &'a T) -> Self { -// Self::from_ptr(data as *const T) -// } -// } - -// impl<'a, T: Nullable> OptionalRef<'a, T> { -// pub fn none() -> Self { -// Self::from_ptr(T::null()) -// } -// -// pub fn is_some(&self) -> bool { -// self.ptr != T::null() -// } -// -// pub fn unwrap(self) -> &'a T { -// assert!(self.is_some()); -// unsafe { -// &*self.ptr -// } -// } -// } - /// This is a spirv-compatible option type. /// The native rust Option type produces invalid spirv due to its enum nature; this custom option /// type creates code which will actually compile. @@ -140,46 +88,6 @@ impl Optional<(T0, T1)> { } } - -// #[derive(Copy, Clone, Default, PartialEq)] -// pub struct Optional(Option); -// -// impl Optional { -// pub fn some(data: T) -> Self { -// Self(Some(data)) -// } -// -// pub fn explicit_none(_data: T) -> Self { -// Self(None) -// } -// -// pub fn is_some(self) -> bool { -// self.0.is_some() -// } -// -// pub fn unwrap(self) -> T { -// self.0.unwrap() -// } -// -// pub fn map U>(self, f: F) -> Optional { -// Optional(self.0.map(f)) -// } -// -// pub fn unwrap_or(self, default: T) -> T { -// self.0.unwrap_or(default) -// } -// -// pub fn none() -> Self { -// Self(None) -// } -// } -// -// impl Optional { -// pub fn unwrap_or_default(self) -> T { -// self.0.unwrap_or_default() -// } -// } - /// This struct allows doing things like *(ptr + offset) = value. /// Such code wouldn't ordinarily compile with the spirv target because of /// unsupported pointer math. RuntimeArray exists to overcome this, however @@ -203,7 +111,6 @@ impl UnsizedArray { // arr = in(reg) self, // index = in(reg) index, //} - //loop {} } pub unsafe fn write(&mut self, index: usize, value: T) { @@ -326,37 +233,6 @@ impl<'a, T: Copy + Default> Array3<'a, T> { } } -// impl<'a, T> Array3<'a, T> { -// pub fn get_ref(&self, idx: UVec3Std) -> OptionalRef<'a, T> { -// OptionalRef::some(unsafe { -// self.data.index(0) -// }) -// // OptionalRef::none() -// // let idx = self.index(idx); -// // if idx.is_some() { -// // OptionalRef::some(unsafe { -// // self.data.index(idx.unwrap()) -// // }) -// // } else { -// // OptionalRef::none() -// // } -// } -// } - -// impl<'a> Array3<'a, Vec3Std> { -// pub fn get(&self, idx: UVec3Std) -> Vec3Std { -// let flat_idx = self.index(idx); -// (self.data[0].0, 0.0, 0.0) -// // let idx = self.index(idx); -// // if idx.is_some() { -// // Optional::some((0.0, 0.0, self.data[idx.unwrap()].0)) -// // } else { -// // Optional::none() -// // } -// } -// } -// - /// 3d dynamically-sized array backed by a mutably borrowed buffer. pub struct Array3Mut<'a, T> { data: &'a mut UnsizedArray, @@ -392,31 +268,6 @@ impl<'a, T: Copy> Array3Mut<'a, T> { self.data.get_handle_mut(idx) } } - // fn index(&self, idx: UVec3Std) -> Optional { - // self.as_array3().index(idx) - // } - // // pub fn get(&self, idx: UVec3Std) -> Option { - // // self.get_ref(idx).cloned() - // // } - // pub fn get_ref<'b>(&'b self, idx: UVec3Std) -> OptionalRef<'b, T> { - // let idx = self.index(idx); - // if idx.is_some() { - // OptionalRef::some(&self.data[idx.unwrap()]) - // } else { - // OptionalRef::none() - // } - // } - // pub fn get_mut(&mut self, idx: UVec3Std) -> Option { - // self.get_ref_mut(idx).cloned() - // } - // pub fn get_ref_mut<'b>(&'b mut self, idx: UVec3Std) -> Option<&'b mut T> { - // self.data.get_mut(index(idx, self.dim)) - // } - - // /// Like `get_ref_mut`, but imposes fewer lifetime requirements by consuming `self`. - // pub fn into_ref_mut(self, idx: UVec3Std) -> Option<&'a mut T> { - // self.data.get_mut(index(idx, self.dim)) - // } }