ScanMountGoat / wgsl_to_wgpu

Generate typesafe Rust bindings from WGSL shaders to wgpu
MIT License
42 stars 12 forks source link

nalgebra: `ShaderSize` is not implemented for `Matrix<f32, Const<3>...` #27

Closed JMLX42 closed 1 year ago

JMLX42 commented 1 year ago

I just hit a size issue caused by:

struct Material {
    color: vec4<f32>
}

@group(0)
@binding(0)
var<uniform> material: Material;
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 1, Vulkan)>`
    In a draw command, indexed:false indirect:false
      note: render pipeline = `Render Pipeline`
    Buffer is bound with size 12 where the shader expects 16 in group[0] compact index 0

But when I try to enable derive_encase in the WriteOptions, I get the following error for a:

error[E0277]: the trait bound `Matrix<f32, Const<3>, Const<1>, ArrayStorage<f32, 3, 1>>: ShaderSize` is not satisfied
  --> src\shaders\shader.rs:11:5
   |
11 |     encase::ShaderType
   |     ^^^^^^^^^^^^^^^^^^ the trait `ShaderSize` is not implemented for `Matrix<f32, Const<3>, Const<1>, ArrayStorage<f32, 3, 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)

Please advise.

JMLX42 commented 1 year ago

I created the following issue on encase: https://github.com/teoxoy/encase/issues/22

ScanMountGoat commented 1 year ago

It looks like this is probably an issue with encase. We may need to change the code we generate for nalgebra, but it could just be an oversight by encase. I'll wait and see how the maintainers of encase respond.

JMLX42 commented 1 year ago

Fixed by https://github.com/teoxoy/encase/pull/23