From be66facc0bb1b7a48d65391101890e8b5b3c68f1 Mon Sep 17 00:00:00 2001 From: nanoqsh Date: Wed, 17 Jan 2024 03:24:14 +0600 Subject: [PATCH] Matrices in instance --- dunge/src/instance.rs | 10 +-- dunge/src/shader.rs | 127 ++++++++++++++++------------- dunge_macros/src/instance.rs | 6 +- dunge_shader/src/context.rs | 12 +-- dunge_shader/src/eval.rs | 76 +++++++++++++---- dunge_shader/src/instance.rs | 4 +- dunge_shader/src/lib.rs | 4 +- dunge_shader/src/matrix.rs | 58 ++++++++++++- dunge_shader/src/types.rs | 153 ++++++++++++++++++++++++++--------- 9 files changed, 325 insertions(+), 125 deletions(-) diff --git a/dunge/src/instance.rs b/dunge/src/instance.rs index 841fda6..7fa7426 100644 --- a/dunge/src/instance.rs +++ b/dunge/src/instance.rs @@ -3,7 +3,7 @@ use { context::Context, sl::{ReadInstance, Ret}, state::State, - types::{self, VectorType}, + types::{self, ValueType, VectorType}, uniform::{self, Value}, Instance, }, @@ -17,7 +17,7 @@ pub use dunge_shader::instance::Projection; /// /// The trait is sealed because the derive macro relies on no new types being used. pub trait MemberProjection: private::Sealed { - const TYPE: VectorType; + const TYPE: ValueType; type Field; fn member_projection(id: u32) -> Self::Field; } @@ -25,7 +25,7 @@ pub trait MemberProjection: private::Sealed { impl private::Sealed for Row<[f32; 2]> {} impl MemberProjection for Row<[f32; 2]> { - const TYPE: VectorType = VectorType::Vec2f; + const TYPE: ValueType = ValueType::Vector(VectorType::Vec2f); type Field = Ret>; fn member_projection(id: u32) -> Self::Field { @@ -36,7 +36,7 @@ impl MemberProjection for Row<[f32; 2]> { impl private::Sealed for Row<[f32; 3]> {} impl MemberProjection for Row<[f32; 3]> { - const TYPE: VectorType = VectorType::Vec3f; + const TYPE: ValueType = ValueType::Vector(VectorType::Vec3f); type Field = Ret>; fn member_projection(id: u32) -> Self::Field { @@ -47,7 +47,7 @@ impl MemberProjection for Row<[f32; 3]> { impl private::Sealed for Row<[f32; 4]> {} impl MemberProjection for Row<[f32; 4]> { - const TYPE: VectorType = VectorType::Vec4f; + const TYPE: ValueType = ValueType::Vector(VectorType::Vec4f); type Field = Ret>; fn member_projection(id: u32) -> Self::Field { diff --git a/dunge/src/shader.rs b/dunge/src/shader.rs index 683effa..dae2528 100644 --- a/dunge/src/shader.rs +++ b/dunge/src/shader.rs @@ -1,14 +1,14 @@ use { crate::{ bind::TypedGroup, - sl::{InputInfo, InstInfo, IntoModule, Module, Stages, VertInfo}, + sl::{InputInfo, IntoModule, Module, Stages}, state::State, - types::{MemberType, VectorType}, + types::{MemberType, ScalarType, ValueType, VectorType}, }, std::{cell::Cell, marker::PhantomData}, wgpu::{ BufferAddress, PipelineLayout, ShaderModule, VertexAttribute, VertexBufferLayout, - VertexStepMode, + VertexFormat, VertexStepMode, }, }; @@ -167,60 +167,28 @@ impl Inner { state.device().create_pipeline_layout(&desc) }; - let to_format = |vecty| match vecty { - VectorType::Vec2f => VertexFormat::Float32x2, - VectorType::Vec3f => VertexFormat::Float32x3, - VectorType::Vec4f => VertexFormat::Float32x4, - VectorType::Vec2u => VertexFormat::Uint32x2, - VectorType::Vec3u => VertexFormat::Uint32x3, - VectorType::Vec4u => VertexFormat::Uint32x4, - VectorType::Vec2i => VertexFormat::Sint32x2, - VectorType::Vec3i => VertexFormat::Sint32x3, - VectorType::Vec4i => VertexFormat::Sint32x4, + let location = Cell::default(); + let next_location = || { + let current = location.get(); + location.set(current + 1); + current }; - let next_location = { - let location = Cell::default(); - move || { - let current = location.get(); - location.set(current + 1); - current - } - }; - - let vert = |info: VertInfo| { + let make_attr = || { let mut offset = 0; - let attr = |vecty| { - let format = to_format(vecty); - let attr = VertexAttribute { - format, - offset, - shader_location: next_location(), + move |ty, attrs: &mut Vec<_>| { + let mut f = |format| { + let attr = VertexAttribute { + format, + offset, + shader_location: next_location(), + }; + + offset += format.size(); + attrs.push(attr); }; - offset += format.size(); - attr - }; - - Vertex { - array_stride: info.size as BufferAddress, - step_mode: VertexStepMode::Vertex, - attributes: info.def.into_iter().map(attr).collect(), - } - }; - - let inst = |info: InstInfo| { - let format = to_format(info.vecty); - let attr = VertexAttribute { - format, - offset: 0, - shader_location: next_location(), - }; - - Vertex { - array_stride: format.size(), - step_mode: VertexStepMode::Instance, - attributes: Box::from([attr]), + to_format(ty, &mut f); } }; @@ -235,7 +203,22 @@ impl Inner { match input { InputInfo::Vert(v) => { slots.vertex = vertex.len() as u32; - vertex.push(vert(v)); + + let vert = { + let mut attr = make_attr(); + let mut attrs = vec![]; + for vecty in v.def { + attr(ValueType::Vector(vecty), &mut attrs); + } + + Vertex { + array_stride: v.size as BufferAddress, + step_mode: VertexStepMode::Vertex, + attributes: attrs.into(), + } + }; + + vertex.push(vert); } InputInfo::Inst(i) => { if set_instance { @@ -243,7 +226,16 @@ impl Inner { set_instance = false; } - vertex.push(inst(i)); + let mut attr = make_attr(); + let mut attrs = vec![]; + attr(i.ty, &mut attrs); + let vert = Vertex { + array_stride: attrs.iter().map(|attr| attr.format.size()).sum(), + step_mode: VertexStepMode::Instance, + attributes: attrs.into(), + }; + + vertex.push(vert); } InputInfo::Index => {} } @@ -259,3 +251,30 @@ impl Inner { } } } + +fn to_format(ty: ValueType, f: &mut F) +where + F: FnMut(VertexFormat), +{ + match ty { + ValueType::Scalar(ScalarType::Float) => f(VertexFormat::Float32), + ValueType::Scalar(ScalarType::Sint) => f(VertexFormat::Sint32), + ValueType::Scalar(ScalarType::Uint) | ValueType::Scalar(ScalarType::Bool) => { + f(VertexFormat::Uint32); + } + ValueType::Vector(VectorType::Vec2f) => f(VertexFormat::Float32x2), + ValueType::Vector(VectorType::Vec3f) => f(VertexFormat::Float32x3), + ValueType::Vector(VectorType::Vec4f) => f(VertexFormat::Float32x4), + ValueType::Vector(VectorType::Vec2u) => f(VertexFormat::Uint32x2), + ValueType::Vector(VectorType::Vec3u) => f(VertexFormat::Uint32x3), + ValueType::Vector(VectorType::Vec4u) => f(VertexFormat::Uint32x4), + ValueType::Vector(VectorType::Vec2i) => f(VertexFormat::Sint32x2), + ValueType::Vector(VectorType::Vec3i) => f(VertexFormat::Sint32x3), + ValueType::Vector(VectorType::Vec4i) => f(VertexFormat::Sint32x4), + ValueType::Matrix(mat) => { + for _ in 0..mat.dims() { + to_format(ValueType::Vector(mat.vector_type()), f); + } + } + } +} diff --git a/dunge_macros/src/instance.rs b/dunge_macros/src/instance.rs index f843d7a..58be09c 100644 --- a/dunge_macros/src/instance.rs +++ b/dunge_macros/src/instance.rs @@ -80,7 +80,7 @@ pub(crate) fn derive(input: DeriveInput) -> TokenStream { quote::quote! { impl ::dunge::Instance for #name { type Projection = #projection_name; - const DEF: ::dunge::sl::Define<::dunge::types::VectorType> = ::dunge::sl::Define::new(&[ + const DEF: ::dunge::sl::Define<::dunge::types::ValueType> = ::dunge::sl::Define::new(&[ #(#instance_types),*, ]); } @@ -121,7 +121,7 @@ mod tests { let expected = quote::quote! { impl ::dunge::Instance for Transform { type Projection = TransformProjection; - const DEF: ::dunge::sl::Define<::dunge::types::VectorType> = ::dunge::sl::Define::new(&[ + const DEF: ::dunge::sl::Define<::dunge::types::ValueType> = ::dunge::sl::Define::new(&[ as ::dunge::instance::MemberProjection>::TYPE, as ::dunge::instance::MemberProjection>::TYPE, ]); @@ -163,7 +163,7 @@ mod tests { let expected = quote::quote! { impl ::dunge::Instance for Transform { type Projection = TransformProjection; - const DEF: ::dunge::sl::Define<::dunge::types::VectorType> = ::dunge::sl::Define::new(&[ + const DEF: ::dunge::sl::Define<::dunge::types::ValueType> = ::dunge::sl::Define::new(&[ as ::dunge::instance::MemberProjection>::TYPE, as ::dunge::instance::MemberProjection>::TYPE, ]); diff --git a/dunge_shader/src/context.rs b/dunge_shader/src/context.rs index ad78483..b061b17 100644 --- a/dunge_shader/src/context.rs +++ b/dunge_shader/src/context.rs @@ -5,7 +5,7 @@ use { group::{self, Group}, instance::{self, Instance}, ret::Ret, - types::{MemberType, VectorType}, + types::{MemberType, ValueType, VectorType}, vertex::{self, Vertex}, }, std::{any::TypeId, mem, ops}, @@ -51,7 +51,7 @@ pub struct VertInfo { #[doc(hidden)] #[derive(Clone, Copy)] pub struct InstInfo { - pub vecty: VectorType, + pub ty: ValueType, } pub(crate) struct GroupEntry { @@ -115,10 +115,10 @@ impl Context { id } - fn add_instance(&mut self, vec: VectorType) -> u32 { + fn add_instance(&mut self, ty: ValueType) -> u32 { countdown(&mut self.limits.insts, "too many instances in the shader"); let id = self.inputs.len() as u32; - let info = InstInfo { vecty: vec }; + let info = InstInfo { ty }; self.inputs.push(InputInfo::Inst(info)); id } @@ -230,8 +230,8 @@ where fn from_context_input(cx: &mut Context) -> Self { let mut id = None; - for vec in I::DEF { - id.get_or_insert(cx.add_instance(vec)); + for ty in I::DEF { + id.get_or_insert(cx.add_instance(ty)); } let id = id.expect("the instance must have at least one field"); diff --git a/dunge_shader/src/eval.rs b/dunge_shader/src/eval.rs index 50f62d4..02a4819 100644 --- a/dunge_shader/src/eval.rs +++ b/dunge_shader/src/eval.rs @@ -4,7 +4,7 @@ use { define::Define, module::{Module, Out, Output}, ret::Ret, - types::{self, MemberType, ScalarType, VectorType}, + types::{self, MemberType, ScalarType, ValueType, VectorType}, }, naga::{ AddressSpace, Arena, BinaryOperator, Binding, Block, BuiltIn, EntryPoint, Expression, @@ -27,9 +27,12 @@ where let mut new = def.into_iter().map(Member::from_vecty); Argument::from_type(compl.define_input(&mut new, &mut binds)) } - InputInfo::Inst(InstInfo { vecty, .. }) => Argument { - ty: compl.define_instance(*vecty), - binding: Some(binds.next(&vecty.ty())), + InputInfo::Inst(InstInfo { ty }) => Argument { + ty: compl.define_instance(*ty, &mut binds), + binding: match ty { + ValueType::Scalar(_) | ValueType::Vector(_) => Some(binds.next(&ty.ty())), + ValueType::Matrix(_) => None, + }, }, InputInfo::Index => Argument { ty: compl.define_index(), @@ -207,12 +210,27 @@ impl ReadInstance { } } -impl Eval for Ret { +impl Eval for Ret +where + T: types::Value, +{ type Out = T; fn eval(self, en: &mut Vs) -> Expr { let en = &mut en.inner; - en.argument(self.get().id) + let id = self.get().id; + match T::VALUE_TYPE { + ValueType::Scalar(_) | ValueType::Vector(_) => en.argument(id), + ValueType::Matrix(mat) => { + let ty = en.new_type(T::VALUE_TYPE.ty()); + let arg = en.argument(id); + let exprs = (0..mat.dims()) + .map(|index| en.access_index(arg, index)) + .collect(); + + en.compose(ty, exprs) + } + } } } @@ -615,6 +633,7 @@ pub struct Entry { compl: Compiler, exprs: Arena, stats: Statements, + cached_args: HashMap, } impl Entry { @@ -623,6 +642,7 @@ impl Entry { compl, exprs: Arena::default(), stats: Statements::default(), + cached_args: HashMap::default(), } } @@ -636,8 +656,10 @@ impl Entry { } fn argument(&mut self, n: u32) -> Expr { - let ex = Expression::FunctionArgument(n); - Expr(self.exprs.append(ex, Span::UNDEFINED)) + *self.cached_args.entry(n).or_insert_with(|| { + let ex = Expression::FunctionArgument(n); + Expr(self.exprs.append(ex, Span::UNDEFINED)) + }) } fn global(&mut self, var: Handle) -> Expr { @@ -792,13 +814,13 @@ struct Compiler { } impl Compiler { + const VECTOR_SIZE: u32 = mem::size_of::() as u32 * 4; + fn define_index(&mut self) -> Handle { self.types.insert(ScalarType::Uint.ty(), Span::UNDEFINED) } fn define_input(&mut self, new: &mut Members, binds: &mut Bindings) -> Handle { - const VECTOR_SIZE: u32 = mem::size_of::() as u32 * 4; - let len = new.len(); let mut members = Vec::with_capacity(len); for (idx, Member { vecty, built }) in iter::zip(0.., new) { @@ -813,7 +835,7 @@ impl Compiler { name: None, ty: self.types.insert(ty, Span::UNDEFINED), binding: Some(binding), - offset: idx * VECTOR_SIZE, + offset: idx * Self::VECTOR_SIZE, }); } @@ -821,15 +843,41 @@ impl Compiler { name: None, inner: TypeInner::Struct { members, - span: len as u32 * VECTOR_SIZE, + span: len as u32 * Self::VECTOR_SIZE, }, }; self.types.insert(ty, Span::UNDEFINED) } - fn define_instance(&mut self, vecty: VectorType) -> Handle { - self.types.insert(vecty.ty(), Span::UNDEFINED) + fn define_instance(&mut self, ty: ValueType, binds: &mut Bindings) -> Handle { + let ty = match ty { + ValueType::Scalar(_) | ValueType::Vector(_) => ty.ty(), + ValueType::Matrix(mat) => { + let len = mat.dims(); + let mut members = Vec::with_capacity(len as usize); + for idx in 0..len { + let ty = mat.vector_type().ty(); + let binding = binds.next(&ty); + members.push(StructMember { + name: None, + ty: self.types.insert(ty, Span::UNDEFINED), + binding: Some(binding), + offset: idx * Self::VECTOR_SIZE, + }); + } + + Type { + name: None, + inner: TypeInner::Struct { + members, + span: len * Self::VECTOR_SIZE, + }, + } + } + }; + + self.types.insert(ty, Span::UNDEFINED) } fn define_group(&mut self, group: u32, def: Define) { diff --git a/dunge_shader/src/instance.rs b/dunge_shader/src/instance.rs index c795d2a..973d4f8 100644 --- a/dunge_shader/src/instance.rs +++ b/dunge_shader/src/instance.rs @@ -1,9 +1,9 @@ -use crate::{define::Define, types::VectorType}; +use crate::{define::Define, types::ValueType}; /// The instance type description. pub trait Instance { type Projection: Projection + 'static; - const DEF: Define; + const DEF: Define; } pub trait Projection { diff --git a/dunge_shader/src/lib.rs b/dunge_shader/src/lib.rs index 49940b1..75105df 100644 --- a/dunge_shader/src/lib.rs +++ b/dunge_shader/src/lib.rs @@ -15,7 +15,7 @@ pub mod vertex; pub mod sl { pub use crate::{ - context::*, convert::*, define::*, eval::*, math::*, module::*, ret::*, texture::*, - vector::*, + context::*, convert::*, define::*, eval::*, math::*, matrix::*, module::*, ret::*, + texture::*, vector::*, }; } diff --git a/dunge_shader/src/matrix.rs b/dunge_shader/src/matrix.rs index 1b07834..233e13f 100644 --- a/dunge_shader/src/matrix.rs +++ b/dunge_shader/src/matrix.rs @@ -1,5 +1,6 @@ use crate::{ - eval::{Eval, Expr, Exprs, GetEntry}, + eval::{Eval, EvalTuple, Evaluated, Expr, Exprs, GetEntry}, + ret::Ret, types::{self, Matrix}, }; @@ -12,7 +13,7 @@ macro_rules! impl_eval_mat { type Out = $t; fn eval(self, en: &mut E) -> Expr { - let mut components = Vec::with_capacity(<$t>::TYPE.dims()); + let mut components = Vec::with_capacity(<$t>::TYPE.dims() as usize); self.into_matrix(|vector| { let v = vector.eval(en).get(); components.push(v); @@ -30,6 +31,59 @@ impl_eval_mat!(glam::Mat2 => types::Mat2); impl_eval_mat!(glam::Mat3 => types::Mat3); impl_eval_mat!(glam::Mat4 => types::Mat4); +type Matrix2 = Ret, types::Mat2>; + +pub const fn mat2(x: X, y: Y) -> Matrix2 +where + X: Eval>, + Y: Eval>, +{ + Ret::new(NewMat((x, y))) +} + +type Matrix3 = Ret, types::Mat3>; + +pub const fn mat3(x: X, y: Y, z: Z) -> Matrix3 +where + X: Eval>, + Y: Eval>, + Z: Eval>, +{ + Ret::new(NewMat((x, y, z))) +} + +type Matrix4 = Ret, types::Mat4>; + +pub const fn mat4(x: X, y: Y, z: Z, w: W) -> Matrix4 +where + X: Eval>, + Y: Eval>, + Z: Eval>, + W: Eval>, +{ + Ret::new(NewMat((x, y, z, w))) +} + +pub struct NewMat(A); + +impl Eval for Ret, O> +where + A: EvalTuple, + O: Matrix, + E: GetEntry, +{ + type Out = O; + + fn eval(self, en: &mut E) -> Expr { + let mut o = Evaluated::default(); + self.get().0.eval(en, &mut o); + let en = en.get_entry(); + let ty = en.new_type(O::TYPE.ty()); + let components = o.into_iter().collect(); + en.compose(ty, components) + } +} + trait IntoMatrix { type Vector; diff --git a/dunge_shader/src/types.rs b/dunge_shader/src/types.rs index 01e3abe..3c795b5 100644 --- a/dunge_shader/src/types.rs +++ b/dunge_shader/src/types.rs @@ -3,26 +3,73 @@ use { std::marker::PhantomData, }; -pub trait Scalar { - const TYPE: ScalarType; +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum ValueType { + Scalar(ScalarType), + Vector(VectorType), + Matrix(MatrixType), } -impl Scalar for f32 { - const TYPE: ScalarType = ScalarType::Float; +impl ValueType { + pub(crate) const fn ty(self) -> Type { + match self { + Self::Scalar(v) => v.ty(), + Self::Vector(v) => v.ty(), + Self::Matrix(v) => v.ty(), + } + } + + const fn into_scalar(self) -> ScalarType { + match self { + Self::Scalar(v) => v, + _ => panic!("non-scalar type"), + } + } + + const fn into_vector(self) -> VectorType { + match self { + Self::Vector(v) => v, + _ => panic!("non-vector type"), + } + } + + const fn into_matrix(self) -> MatrixType { + match self { + Self::Matrix(v) => v, + _ => panic!("non-matrix type"), + } + } } -impl Scalar for i32 { - const TYPE: ScalarType = ScalarType::Sint; +pub trait Value { + const VALUE_TYPE: ValueType; } -impl Scalar for u32 { - const TYPE: ScalarType = ScalarType::Uint; +impl Value for f32 { + const VALUE_TYPE: ValueType = ValueType::Scalar(ScalarType::Float); } -impl Scalar for bool { - const TYPE: ScalarType = ScalarType::Bool; +impl Value for i32 { + const VALUE_TYPE: ValueType = ValueType::Scalar(ScalarType::Sint); } +impl Value for u32 { + const VALUE_TYPE: ValueType = ValueType::Scalar(ScalarType::Uint); +} + +impl Value for bool { + const VALUE_TYPE: ValueType = ValueType::Scalar(ScalarType::Bool); +} + +pub trait Scalar: Value { + const TYPE: ScalarType = Self::VALUE_TYPE.into_scalar(); +} + +impl Scalar for f32 {} +impl Scalar for i32 {} +impl Scalar for u32 {} +impl Scalar for bool {} + #[derive(Clone, Copy, PartialEq, Eq)] pub enum ScalarType { Float, @@ -91,54 +138,81 @@ impl VectorType { } } -pub trait Vector { +pub trait Vector: Value { type Scalar; - const TYPE: VectorType; + const TYPE: VectorType = Self::VALUE_TYPE.into_vector(); +} + +impl Value for Vec2 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec2f); +} + +impl Value for Vec3 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec3f); +} + +impl Value for Vec4 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec4f); +} + +impl Value for Vec2 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec2u); +} + +impl Value for Vec3 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec3u); +} + +impl Value for Vec4 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec4u); +} + +impl Value for Vec2 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec2i); +} + +impl Value for Vec3 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec3i); +} + +impl Value for Vec4 { + const VALUE_TYPE: ValueType = ValueType::Vector(VectorType::Vec4i); } impl Vector for Vec2 { type Scalar = f32; - const TYPE: VectorType = VectorType::Vec2f; } impl Vector for Vec3 { type Scalar = f32; - const TYPE: VectorType = VectorType::Vec3f; } impl Vector for Vec4 { type Scalar = f32; - const TYPE: VectorType = VectorType::Vec4f; } impl Vector for Vec2 { type Scalar = u32; - const TYPE: VectorType = VectorType::Vec2u; } impl Vector for Vec3 { type Scalar = u32; - const TYPE: VectorType = VectorType::Vec3u; } impl Vector for Vec4 { type Scalar = u32; - const TYPE: VectorType = VectorType::Vec4u; } impl Vector for Vec2 { type Scalar = i32; - const TYPE: VectorType = VectorType::Vec2i; } impl Vector for Vec3 { type Scalar = i32; - const TYPE: VectorType = VectorType::Vec3i; } impl Vector for Vec4 { type Scalar = i32; - const TYPE: VectorType = VectorType::Vec4i; } const VEC2F: Type = vec(VectorSize::Bi, ScalarKind::Float); @@ -174,7 +248,7 @@ pub enum MatrixType { } impl MatrixType { - pub(crate) const fn dims(self) -> usize { + pub const fn dims(self) -> u32 { match self { Self::Mat2 => 2, Self::Mat3 => 3, @@ -189,24 +263,36 @@ impl MatrixType { Self::Mat4 => MAT4F, } } + + pub const fn vector_type(self) -> VectorType { + match self { + Self::Mat2 => VectorType::Vec2f, + Self::Mat3 => VectorType::Vec3f, + Self::Mat4 => VectorType::Vec4f, + } + } } -pub trait Matrix { - const TYPE: MatrixType; +pub trait Matrix: Value { + const TYPE: MatrixType = Self::VALUE_TYPE.into_matrix(); } -impl Matrix for Mat2 { - const TYPE: MatrixType = MatrixType::Mat2; +impl Value for Mat2 { + const VALUE_TYPE: ValueType = ValueType::Matrix(MatrixType::Mat2); } -impl Matrix for Mat3 { - const TYPE: MatrixType = MatrixType::Mat3; +impl Value for Mat3 { + const VALUE_TYPE: ValueType = ValueType::Matrix(MatrixType::Mat3); } -impl Matrix for Mat4 { - const TYPE: MatrixType = MatrixType::Mat4; +impl Value for Mat4 { + const VALUE_TYPE: ValueType = ValueType::Matrix(MatrixType::Mat4); } +impl Matrix for Mat2 {} +impl Matrix for Mat3 {} +impl Matrix for Mat4 {} + const MAT2F: Type = mat(VectorSize::Bi); const MAT3F: Type = mat(VectorSize::Tri); const MAT4F: Type = mat(VectorSize::Quad); @@ -222,13 +308,6 @@ const fn mat(size: VectorSize) -> Type { } } -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum ValueType { - Scalar(ScalarType), - Vector(VectorType), - Matrix(MatrixType), -} - pub struct Texture2d(PhantomData); const TEXTURE2DF: Type = texture(ImageDimension::D2, ScalarKind::Float);