Skip to main content

storage_buffer_init

Function storage_buffer_init 

Source
pub fn storage_buffer_init(device: &Device, label: &str, data: &[u8]) -> Buffer
Expand description

Create a GPU storage buffer initialised with data.

The returned buffer has usages STORAGE | COPY_DST | COPY_SRC:

  • STORAGE — bindable as a shader storage buffer.
  • COPY_DST — allows queue.write_buffer updates.
  • COPY_SRC — allows copying to a staging_buffer for CPU readback.

§Parameters

  • device — the logical wgpu device.
  • label — debug label visible in GPU capture tools (pass "" to omit).
  • data — raw bytes to upload; length determines the buffer size.

§Panics

Panics if data is empty (zero-size buffers are forbidden by the WebGPU spec and wgpu validation).