getting modified buffer from compute shader

60 Views Asked by At

so i am trying to write some compute shaders but this is my first interaction with anything gpu. So the problem i am having is that i am not getting the results back from the shader. here is my code in bevy 0.12: https://codeshare.io/64pAvO

i am getting the buffer in the impl node { fn run } function like this

let storage_buffer = &world.resource::<RayTracerBuffer>().buffer;

but im quite certain this just gets a reference to the buffer on the cpu and not the gpu

this is my super simple shader code:

@group(0) @binding(0) var<storage, read_write> buffer: array<u32>;

@compute @workgroup_size(8, 8, 1)
fn init(@builtin(global_invocation_id) global_id: vec3<u32>) {

}

@compute @workgroup_size(8,8,1)
fn update(@builtin(global_invocation_id) global_id: vec3<u32>){
    let index = global_id.x;
    buffer[index] = 1u;
}

everything runs without erros but i just get 0's back instead of the expected 1's so im pretty sure im just getting the wrong version of the storage_buffer but im clueless on how to get the right one

any help is super appreciated :)

0

There are 0 best solutions below