在 rust wgpu 中绑定存储缓冲区

问题描述 投票:0回答:1

我正在学习 rust wgpu。到目前为止,我可以将统一数据发送到着色器。现在我想将存储缓冲区发送到着色器。但我收到以下错误:

[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)

我正在关注本教程。它是为 javascript 编写的,我正在尝试将其转换为 Rust。我在下面分享代码

        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_pass.set_bind_group(0, &self.uniform_bind_group, &[]);
            render_pass.set_bind_group(1, &self.storage_bind_group, &[]);

着色器代码:

@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>;
rust shader vertex-shader webgpu wgpu-rs
1个回答
0
投票

如果你查看

Features::VERTEX_WRITABLE_STORAGE
的文档,它会说:

启用可写存储缓冲区和顶点着色器可见的纹理的绑定。

这是本机独有的功能。

wgpu
的文档神秘地使用“native”来表示“非网络”。因此,不支持的是您在这里请求读写绑定:

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

但是您不需要从顶点着色器写入缓冲区,因此您应该将

read_only
设置为
true

© www.soinside.com 2019 - 2024. All rights reserved.