nalgebra support: ShaderSize is not implemented for Matrix<f32, Const<3>...
JMLX42 opened this issue · 10 comments
Considering the following WGSL code:
struct Material {
color: vec4<f32>
}
@group(0)
@binding(0)
var<uniform> material: Material;
This is what wgsl_to_wgpu
generates:
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, encase::ShaderType)]
pub struct Material {
pub color: nalgebra::SVector<f32, 4>,
}
Which causes the following build error:
error[E0277]: the trait bound `Matrix<f32, Const<4>, Const<1>, ArrayStorage<f32, 4, 1>>: ShaderSize` is not satisfied
--> src\shaders\shader.rs:4:41
|
4 | #[derive(Debug, Copy, Clone, PartialEq, encase::ShaderType)]
| ^^^^^^^^^^^^^^^^^^ the trait `ShaderSize` is not implemented for `Matrix<f32, Const<4>, Const<1>, ArrayStorage<f32, 4, 1>>`
|
= help: the following other types implement trait `ShaderSize`:
&T
&mut T
Arc<T>
ArrayLength
AtomicI32
AtomicU32
Box<T>
Cow<'_, T>
and 47 others
= help: see issue #48214
= note: this error originates in the derive macro `encase::ShaderType` (in Nightly builds, run with -Z macro-backtrace for more info)
Which is unexpected.
Please advise.
I think this should work. Do you have the nalgebra
feature flag of encase switched on?
I'm seeing code for Vector4<T>
and vector slices in the nalgebra implementations but not SVector
. Is this just a missing implementation?
https://github.com/teoxoy/encase/blob/main/src/impls/nalgebra.rs
I'm seeing code for Vector4 and vector slices in the nalgebra implementations but not SVector. Is this just a missing implementation?
@ScanMountGoat AFAIK Vector
is an alias for SVector
:
https://nalgebra.org/docs/user_guide/vectors_and_matrices
- SVector<T, D> is a statically-sized column vector with D rows, e.g., SVector<f32, 10>.
[...]
Aliases exist for statically-sized vectors and matrices with small dimensions:
- Vector1 .. Vector6: are column vectors of dimension 1 to 6.
That's why I would expect it to work.
I'm seeing code for Vector4 and vector slices in the nalgebra implementations but not SVector. Is this just a missing implementation?
@ScanMountGoat AFAIK
Vector
is an alias forSVector
:
Looking at nalgebra
's source:
pub type SVector<T, const D: usize> = Matrix<T, Const<D>, U1, ArrayStorage<T, D, 1>>;
pub type Vector4<T> = Matrix<T, U4, U1, ArrayStorage<T, 4, 1>>;
You are using SVector<f32, 4>
and encase uses Vector4<T>
- they should point to the same definition.
Do you have a minimum reproducible example?
Do you have a minimum reproducible example?
@teoxoy here you go:
https://github.com/JMLX42/wgsl_to_wgpu/tree/bug/encase-22/example
Ah, I think I figured it out. I haven't updated encase to support nalgebra v0.32
, but you request it in Cargo.toml
.
You essentially have both versions in your project now.
The next major release (0.5
) will contain the PR. Do you need it released or could you use a git dependency for now?