Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions release-content/0.15/release-notes/14663_shader_storage_buffer.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
A new asset `ShaderStorageBuffer` has been added to simplify working with storage buffers in custom materials and compute shaders. Storage buffers are large, GPU-accessible memory buffers designed for storing data that can be read from or written to by shaders. Unlike smaller, more restricted uniform buffers, storage buffers allow you to store large amounts of data, making them perfect for general purpose tasks where large datasets need to be processed. Examples include managing complex data in physics simulations (like particle systems), holding the transformation data for thousands of objects in a scene, or storing procedural geometry information for dynamic terrain generation. Storage buffers are particularly useful when different stages of the rendering pipeline (such as compute shaders and rendering passes) need to share and update large amounts of data efficiently.
```rust
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
struct CustomMaterial {
#[storage(0, read_only)]
colors: Handle<ShaderStorageBuffer>,
}
fn setup(
mut buffers: ResMut<Assets<ShaderStorageBuffer>>,
mut materials: ResMut<Assets<CustomMaterial>>,
) {
// Example data for the storage buffer
let color_data: Vec<[f32; 4]> = vec![
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[1.0, 1.0, 0.0, 1.0],
[0.0, 1.0, 1.0, 1.0],
];
let colors = buffers.add(ShaderStorageBuffer::from(color_data));
// Create the custom material with the storage buffer
let custom_material = CustomMaterial { colors };
materials.add(custom_material);
}
```
By declaring `Handle<ShaderStorageBuffer>` on the material using `AsBindGroup`, this buffer can now be accessed in the shader:
```wgsl
@group(2) @binding(0) var<storage, read> colors: array<vec4<f32>, 5>;
```
A new asset `ShaderStorageBuffer` has been added to simplify working with storage buffers in custom materials and compute shaders. Storage buffers are large, GPU-accessible memory buffers designed for storing data that can be read from or written to by shaders. Unlike smaller, more restricted uniform buffers, storage buffers allow you to store large amounts of data, making them perfect for general purpose tasks where large datasets need to be processed. Examples include managing complex data in physics simulations (like particle systems), holding the transformation data for thousands of objects in a scene, or storing procedural geometry information for dynamic terrain generation. Storage buffers are particularly useful when different stages of the rendering pipeline (such as compute shaders and rendering passes) need to share and update large amounts of data efficiently.

```rust
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
struct CustomMaterial {
#[storage(0, read_only)]
colors: Handle<ShaderStorageBuffer>,
}

fn setup(
mut buffers: ResMut<Assets<ShaderStorageBuffer>>,
mut materials: ResMut<Assets<CustomMaterial>>,
) {
// Example data for the storage buffer
let color_data: Vec<[f32; 4]> = vec![
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[1.0, 1.0, 0.0, 1.0],
[0.0, 1.0, 1.0, 1.0],
];

let colors = buffers.add(ShaderStorageBuffer::from(color_data));

// Create the custom material with the storage buffer
let custom_material = CustomMaterial { colors };

materials.add(custom_material);
}
```

By declaring `Handle<ShaderStorageBuffer>` on the material using `AsBindGroup`, this buffer can now be accessed in the shader:

```wgsl
@group(2) @binding(0) var<storage, read> colors: array<vec4<f32>, 5>;
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<!-- Add state scoped events -->
<!-- https://github.com/bevyengine/bevy/pull/15085 -->

<!-- TODO -->
State scoped events will be automatically cleared when exiting a state (similar to [StateScoped entities](https://bevyengine.org/news/bevy-0-14/#state-scoped-entities)). This is useful when you want to guarantee clean state transitions.

Normally, you would configure your event via:
```rust
fn setup(app: &mut App) {
app.add_event::<MyGameEvent>();
}
```

If you want the events to be cleared when you exit a specific state, change this to:
```rust
fn setup(app: &mut App) {
app.add_state_scoped_event::<MyGameEvent>(GameState::Play);
}
```