This repository was archived by the owner on Jun 18, 2021. It is now read-only.
This repository was archived by the owner on Jun 18, 2021. It is now read-only.
Uniform buffer's field value is chaotic in compute shader #36
Closed
Description
I have defined a uniform
struct named FluidUniform
, in the compute shader, , use buffer
to record the uniform value in order, then, use copy_buffer_to_buffer
copy buffer's value to staging_buffer
and print it, the value of the FluidUniform's e
field is chaotic, and some values are for other fields (such as lattice_num
).
#[repr(C)]
#[derive(Copy, Clone)]
pub struct FluidUniform {
// e: [[f32; 2]; 9],
e: [f32; 18],
lattice_size: [f32; 2],
lattice_num: [f32; 2],
weight: [f32; 9],
swap: i32,
}
// compute shader
layout(set = 0, binding = 0) uniform FluidUniform {
// vec2 e[9];
float e[18];
vec2 lattice_size;
vec2 lattice_num;
float weight[9];
int swap;
};
...
layout (set = 0, binding = 3) buffer FluidBuffer {
FluidCell fluidCells[];
};
// write e's value to buffer
for (int j = 0; j < 6; j ++) {
fluidCells[j].color[0] = e[j * 3];
fluidCells[j].color[1] = e[j * 3 + 1];
fluidCells[j].color[2] = e[j * 3 + 2];
}
Print staging_buffer
's value
encoder.copy_buffer_to_buffer(&self.fluid_buffer, 0, &self.staging_buffer, 0, fluid_buf_range);
self.app_view.device.get_queue().submit(&[encoder.finish()]);
self.staging_buffer.map_read_async(0, fluid_buf_range, |result: wgpu::BufferMapAsyncResult<&[FluidCell]>| {
println!("{:?}", result.unwrap().data);
});