#Equivalent of `RWStructuredBuffer`

12 messages · Page 1 of 1 (latest)

merry kayak
#

I am trying to recreate the following compute shader in Bevy, I need to send a list of structs to the gpu with read and write access which in the example is done with RWStructuredBuffer but I can't find how to do this with Bevy in WGSL, can someone please point me in the right direction?

https://github.com/SebLague/Slime-Simulation/blob/main/Assets/Scripts/Slime/SlimeSim.compute

GitHub

Contribute to SebLague/Slime-Simulation development by creating an account on GitHub.

elfin panther
#

var<storage, read_write> my_buffer; in WGSL

#
BindGroupLayoutEntry {
                binding: 0,
                visibility: ShaderStages::COMPUTE,
                ty: BindingType::Buffer {
                    ty: BufferBindingType::Storage { read_only: false },
                    has_dynamic_offset: false,
                    min_binding_size: None,
                },
                count: None,
            },
#

and something like this for the BindGroupLayoutEntry

merry kayak
#

When creating the BindGroupDescriptor how would I define it?

BindGroupEntry {
    binding: 1,
    resource: // what goes here?
},
merry kayak
#

This is my system queue_bind_group that I mostly copied from the game of life example.

fn queue_bind_group(
    mut commands: Commands,
    pipeline: Res<SlimeSimulationPipeline>,
    gpu_images: Res<RenderAssets<Image>>,
    game_of_life_image: Res<SlimeSimulationImage>,
    render_device: Res<RenderDevice>,
) {
    let view = &gpu_images[&game_of_life_image.0];
    let bind_group = render_device.create_bind_group(&BindGroupDescriptor {
        label: None,
        layout: &pipeline.texture_bind_group_layout,
        entries: &[
            BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&view.texture_view),
            },
            BindGroupEntry {
                binding: 1,
                resource: // what goes here
            },
        ],
    });
    commands.insert_resource(SlimeSimulationImageBindGroup(bind_group));
}
#

What changes would I have to make to add this buffer in?

elfin panther
#
let mut bvh_buffer: StorageBuffer<RaytracingBVH> = StorageBuffer::from((*bvh).clone());
        bvh_buffer.write_buffer(&render_device, &render_queue);
BindGroupEntry {
            binding: 0,
            resource: bvh_buffer.binding().unwrap(),
      },
#

in this case what I want to put in the storage buffer has type RaytracingBVH

#

which for reference looks like this:

#[derive(Debug, ShaderType, Clone)]
pub struct RaytracingBVH {
    #[size(runtime)]
    nodes: Vec<CustomBVHNode>,
}
#

and CustomBVHNode derives ShaderType, and it has a struct inside it that derives ShaderType

#

Try to stick to types from glam like Mat4 or Vec4 or Vec2or basic number types like u32 or f32 and structs that consist of those types