#DynamicStorageBuffer and WGSL

12 messages · Page 1 of 1 (latest)

tribal tide
#

Hello, I'm trying to use a DynamicStorageBuffer with a compute shader. However, naga is giving me this not-so-helpful error: Loading of [1] can't be done

Relevant part of the shader:

struct Droplet {
    pos: vec2<f32>,
    dir: vec2<f32>,
    vel: f32,
    water: f32,
    sediment: f32,
}

@group(0) @binding(4)
var<storage, read_write> droplets: array<Droplet>;
willow eagle
#

Maybe you could try to wrap a new type Droplets around array<Droplet>.

#

And in rust you could define

#[derive(...)]
pub struct GpuDroplet {
  // ...
}

#[derive(Default, ShaderType)]
pub struct GpuDropletBuffer {
    #[size(runtime)]
    pub data: Vec<GpuDroplet>,
}

// This is a resource
pub struct Meta {
  pub droplet_buffer: StorageBuffer<GpuDropletBuffer>,
}
bitter quest
#

loading of [1] can't be done isn't the error, expression [8] is invalid is the error

#

i have no idea why you're getting that error though

#

check htat you haven't missed a semicolon or curly bracket further up, wgsl errors are often throw on the wrong line

tribal tide
#

I switched to a fixed size array and StorageBuffer, that works just fine. I also got this error running naga-cli validation, so it wasn't anything I did on the bevy side. I tried wrapping it in a struct but that didn't help either. For now, using fixed size array is fine for me.

bitter quest
#

strange...
here's what my bindings look like

@group(2) @binding(0)
var<uniform> u: Uniforms;
@group(2) @binding(1)
var<storage, read> gh: array<u32>;
tribal tide
#

could it be that read_write is not allowed on runtime-sized buffer?

willow eagle
#

Maybe. I only used read-only dynamic sized storage buffers.

bitter quest
#

i have runtime sized read_write bufferes in my compute pass so it should work

@group(0) @binding(0)
var<uniform> u: Uniforms;
@group(0) @binding(1)
var<storage, read_write> gh: array<atomic<u32>>;
@group(0) @binding(2)
var texture: texture_storage_3d<r16uint, read_write>;
@group(0) @binding(3)
var<storage, read_write> physics_data: array<u32>;
#

have you tried reading the buffer as just u32's? it could be the struct causing the problem