Skip to content

[Feature] Storage buffers #172

Description

@vmarcella

Overview

Add storage buffer support for read-write GPU memory used by compute shaders.

Current State

No response

Scope

Goals:

  • Storage buffer creation with read/write usage
  • Binding to compute and render pipelines
  • CPU readback support
  • Dynamic resizing

Non-Goals:

  • Atomic operations
  • Indirect buffers

Proposed API

pub struct StorageBuffer {
  buffer: wgpu::Buffer,
  size: u64,
}

pub struct StorageBufferBuilder {
  size: u64,
  usage: StorageBufferUsage,
  initial_data: Option<Vec<u8>>,
}

#[derive(Clone, Copy)]
pub struct StorageBufferUsage {
  pub read: bool,
  pub write: bool,
  pub cpu_readable: bool,
}

impl StorageBufferBuilder {
  pub fn new(size: u64) -> Self;
  pub fn with_usage(self, usage: StorageBufferUsage) -> Self;
  pub fn with_data<T: bytemuck::Pod>(self, data: &[T]) -> Self;
  pub fn build(self, gpu: &Gpu) -> StorageBuffer;
}

impl StorageBuffer {
  pub fn write<T: bytemuck::Pod>(&self, gpu: &Gpu, data: &[T]);
  pub fn read<T: bytemuck::Pod>(&self, gpu: &Gpu) -> Vec<T>;
  pub fn size(&self) -> u64;
  pub fn as_binding(&self) -> BindingResource;
}

Acceptance Criteria

  • Storage buffer creates with specified size
  • Data writes from CPU
  • Data reads back to CPU
  • Binds to compute pipeline
  • Example with data processing

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Read-back requires staging buffer and map_async
  • STORAGE usage flag required

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    computeAll things compute relatedenhancementNew feature or requestlambda-rsIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions