1

I have this structure

#[repr(C)]
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
struct ProjUniform {
    view_proj: [[f32; 3]; 3],
}

impl ProjUniform {
    fn new() -> Self {
        Self {
            view_proj: [[0.0, 0.0, 0.0],
            [1.0, 1.0, 0.5],
            [0.0, 0.0, 1.0],
            ]
        }
    }
}

I pass to gpu like this:

    let proj_uniform = ProjUniform::new();
    let proj_buffer = device.create_buffer_init(
        &wgpu::util::BufferInitDescriptor {
            label: Some("Proj Buffer"),
            contents: bytemuck::cast_slice(&[proj_uniform]),
            usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST
        });

Now I've debugged this, and I don't get the correct mat3 structure in the shader. it is off and twisted. How do I debug this thing?

This is shader code:

[[block]]
struct ProjectUniform {
  view_proj: mat3x3<f32>;
};

[[group(1), binding(0)]]
var<uniform> project: ProjectUniform;
eguneys
  • 6,028
  • 7
  • 31
  • 63
  • I am not exactly sure, but this could be an alignment issue. You could try making your `view_proj` a homogenous matrix (e.g. `[[f32; 4]; 4]`) to make sure the data is 16 byte aligned. The reason is wgpu is using std140/std430 packing. – frankenapps Oct 26 '21 at 09:42
  • Yes it works with 4x4 matrix – eguneys Oct 26 '21 at 15:32

0 Answers0