0

I'm learning rust wgpu. Till now, I am able to send uniform data to shader. Now I want to send storage buffer to shader. But I'm getting following error:

[ERROR wgpu::backend::wgpu_core] Handling wgpu errors as fatal by default
thread 'main' panicked at C:\Users\..\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-22.1.0\src\backend\wgpu_core.rs:3411:5:
wgpu error: Validation Error

Caused by:
  In Device::create_bind_group_layout, label = 'storage_bind_group_layout'
    Binding 0 entry is invalid
      Features Features(VERTEX_WRITABLE_STORAGE) are required but not enabled on the device


note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\game_of_life_desktop.exe` (exit code: 101)

I'm following this tutorial. It is written for javascript, I'm trying to convert it for rust. I'm sharing code below

        let storage_buffer = device.create_buffer_init(
            &wgpu::util::BufferInitDescriptor {
                // basic initialization
                usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
            }
        );

        let storage_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
            entries: &[
                wgpu::BindGroupLayoutEntry {
                    binding: 0, // I have tried to use 0/1 for bind as well, not working
                    visibility: wgpu::ShaderStages::VERTEX,
                    ty: wgpu::BindingType::Buffer {
                        ty: wgpu::BufferBindingType::Storage { read_only: false },
                        has_dynamic_offset: false,
                        min_binding_size: None,
                    },
                    count: None,
                }
            ],
        });
  
        let storage_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
            layout: &storage_bind_group_layout,
            entries: &[
                wgpu::BindGroupEntry {
                    binding: 1, // I have tried to use 0/1 for bind as well, not working
                    resource: storage_buffer.as_entire_binding(),
                }
            ],
        });

Render code:

            render_pass.set_bind_group(0, &self.uniform_bind_group, &[]);
            render_pass.set_bind_group(1, &self.storage_bind_group, &[]);

Shader code:

@group(0) @binding(0) var<uniform> grid: vec4<f32>; [4.0,4.0, 4.0, 4.0]
@group(0) @binding(1) var<storage> cellState: array<u32>;
1

1 Answer 1

1

If you look at the documentation of Features::VERTEX_WRITABLE_STORAGE it says:

Enables bindings of writable storage buffers and textures visible to vertex shaders.

and

This is a native only feature.

wgpu’s documentation cryptically uses “native” to mean “not web”. So, the thing that is not supported is you asking for a read-write binding here:

ty: wgpu::BufferBindingType::Storage { read_only: false },

But you don’t need to write to the buffer from the vertex shader, so you should set read_only to true.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.