Skip to content

Commit 9c6c0b4

Browse files
author
Kjolnyr
committed
Updated to bevy 0.16
1 parent 663faca commit 9c6c0b4

File tree

18 files changed

+1906
-855
lines changed

18 files changed

+1906
-855
lines changed

Cargo.lock

Lines changed: 1080 additions & 471 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
[package]
2-
name = "bevy_easy_compute"
3-
version = "0.15.0"
2+
name = "bevy_app_compute"
3+
version = "0.16.0"
44
authors = [
55
"Cornchip <[email protected]>",
66
"Kjolnyr <[email protected]>",
77
]
8-
edition = "2021"
8+
edition = "2024"
99
description = "An easy way to run compute shaders for Bevy"
10-
repository = "https://github.com/AnthonyTornetta/bevy_easy_compute"
11-
homepage = "https://github.com/AnthonyTornetta/bevy_easy_compute"
12-
documentation = "https://docs.rs/bevy_easy_compute"
10+
repository = "https://github.com/Kjolnyr/bevy_app_compute"
11+
homepage = "https://github.com/Kjolnyr/bevy_app_compute"
12+
documentation = "https://docs.rs/bevy_app_compute"
1313
license = "MIT OR Apache-2.0"
1414
readme = "README.md"
15-
categories = ["game-development"]
15+
categories = ["game-development", "bevy"]
1616

1717
[features]
1818
shader_format_spirv = ["wgpu/spirv"]
19+
shader_format_wesl = ["wesl"]
1920
webgl = []
2021

2122
[lib]
@@ -24,18 +25,22 @@ doctest = false
2425
[dependencies]
2526
parking_lot = ">=0.12.3"
2627
bytemuck = ">=1.16.1"
28+
wesl = { version = "0.1.2", optional = true }
2729

28-
# The following are only needed to support the `pipeline_cache` "hack". See:
30+
# The following are only needed to support the `pipeline_cache` "hack". See issue in bevy_easy_compute:
2931
# https://github.com/AnthonyTornetta/bevy_easy_compute/issues/7
3032
# Make sure these match bevy's versions
31-
wgpu = { version = "23.0.1", features = ["naga-ir"] }
32-
naga = { version = "23", features = ["wgsl-in"] }
33-
naga_oil = { version = "0.16", default-features = false, features = [
33+
wgpu = { version = "24.0.0", features = ["naga-ir"] }
34+
naga = { version = "24.0.0", features = ["wgsl-in"] }
35+
naga_oil = { version = "0.17.0", default-features = false, features = [
3436
"test_shader",
3537
] }
38+
futures-lite = "2.0.1"
39+
thiserror = { version = "2", default-features = false }
40+
tracing = { version = "0.1", default-features = false, features = ["std"] }
3641

3742
[dependencies.bevy]
38-
version = "0.15"
43+
version = "0.16.0"
3944
default-features = false
4045
# See https://github.com/bevyengine/bevy/blob/main/docs/cargo_features.md
4146
features = [
@@ -46,10 +51,10 @@ features = [
4651
]
4752

4853
[dev-dependencies]
49-
rand = ">=0.8.5"
54+
rand = ">=0.9.1"
5055

5156
[dev-dependencies.bevy]
52-
version = "0.15"
57+
version = "0.16.0"
5358
default-features = false
5459
features = [
5560
"animation",

README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
# Bevy Easy Compute
22

33
![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)
4-
[![Doc](https://docs.rs/bevy_easy_compute/badge.svg)](https://docs.rs/bevy_easy_compute)
5-
[![Crate](https://img.shields.io/crates/v/bevy_easy_compute.svg)](https://crates.io/crates/bevy_easy_compute)
4+
[![Doc](https://docs.rs/bevy_app_compute/badge.svg)](https://docs.rs/bevy_app_compute)
5+
[![Crate](https://img.shields.io/crates/v/bevy_app_compute.svg)](https://crates.io/crates/bevy_app_compute)
66

77
An easy way to run wgpu compute shaders within a bevy app.
88

9-
This is a fork of [Kjolnyr/bevy_app_compute](https://github.com/Kjolnyr/bevy_app_compute), which is no longer being maintained. This project's goal is to keep maintaining `bevy_app_compute` while keeping the overall architecture of it and adding improvements. Issues + PRs are welcome.
10-
119
## Getting Started
1210

1311
Add the following line to your `Cargo.toml`
1412

1513
```toml
1614
[dependencies]
17-
bevy_easy_compute = "0.15"
15+
bevy_app_compute = "0.16"
1816
```
1917

2018
## Usage
2119

2220
### Setup
2321

24-
Declare your shaders in structs implementing `ComputeShader`. The `shader()` fn should point to your shader source code.
25-
You need to derive `TypePath` as well:
22+
Declare your shaders in structs implementing `ComputeShader`. The `shader()` fn
23+
should point to your shader source code. You need to derive `TypePath` as well:
2624

2725
```rust
2826
#[derive(TypePath)]
@@ -35,7 +33,8 @@ impl ComputeShader for SimpleShader {
3533
}
3634
```
3735

38-
Next, declare a struct implementing `ComputeWorker` to declare the bindings and the logic of your worker:
36+
Next, declare a struct implementing `ComputeWorker` to declare the bindings and
37+
the logic of your worker:
3938

4039
```rust
4140
#[derive(Resource)]
@@ -78,15 +77,17 @@ fn main(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
7877
}
7978
```
8079

81-
Add the `AppComputePlugin` plugin to your app, as well as one `AppComputeWorkerPlugin` per struct implementing `ComputeWorker`:
80+
Add the `AppComputePlugin` plugin to your app, as well as one
81+
`AppComputeWorkerPlugin` per struct implementing `ComputeWorker`:
8282

8383
```rust
8484
App::new()
8585
// ... other plugins ...
86-
.add_plugins(bevy_easy_compute::AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
86+
.add_plugins(bevy_app_compute::AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
8787
```
8888

89-
Your compute worker will now run every frame, during the `PostUpdate` stage. To read/write from it, use the `AppComputeWorker<T>` resource!
89+
Your compute worker will now run every frame, during the `PostUpdate` stage. To
90+
read/write from it, use the `AppComputeWorker<T>` resource!
9091

9192
```rust
9293
fn my_system(
@@ -104,11 +105,13 @@ fn my_system(
104105
}
105106
```
106107

107-
(see [simple.rs](https://github.com/AnthonyTornetta/bevy_easy_compute/tree/main/examples/simple.rs))
108+
(see
109+
[simple.rs](https://github.com/Kjolnyr/bevy_app_compute/tree/main/examples/simple.rs))
108110

109111
### Multiple passes
110112

111-
You can have multiple passes without having to copy data back to the CPU in between:
113+
You can have multiple passes without having to copy data back to the CPU in
114+
between:
112115

113116
```rust
114117
let worker = AppComputeWorkerBuilder::new(world)
@@ -125,7 +128,8 @@ let worker = AppComputeWorkerBuilder::new(world)
125128
// the `output` buffer will contain [16.0, 25.0, 36.0, 49.0]
126129
```
127130

128-
(see [multi_pass.rs](https://github.com/AnthonyTornetta/bevy_easy_compute/tree/main/examples/multi_pass.rs))
131+
(see
132+
[multi_pass.rs](https://github.com/Kjolnyr/bevy_app_compute/tree/main/examples/multi_pass.rs))
129133

130134
### One shot computes
131135

@@ -157,17 +161,18 @@ fn on_click_compute(
157161
}
158162
```
159163

160-
It will run at the end of the current frame, and you'll be able to read the data in the next frame.
164+
It will run at the end of the current frame, and you'll be able to read the data
165+
in the next frame.
161166

162-
(see [one_shot.rs](https://github.com/AnthonyTornetta/bevy_easy_compute/tree/main/examples/one_shot.rs))
167+
(see
168+
[one_shot.rs](https://github.com/Kjolnyr/bevy_app_compute/tree/main/examples/one_shot.rs))
163169

164170
## Examples
165171

166-
See [examples](https://github.com/AnthonyTornetta/bevy_easy_compute/tree/main/examples)
172+
See [examples](https://github.com/Kjolnyr/bevy_app_compute/tree/main/examples)
167173

168174
## Bevy version mapping
169175

170-
| Bevy | bevy_easy_compute |
171-
| ---- | ----------------- |
172-
| 0.15 | 0.15 |
173-
| 0.14 | 0.14.1 |
176+
| Bevy | bevy_app_compute |
177+
| ---- | ---------------- |
178+
| 0.16 | 0.16 |

examples/boids/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
99
use bevy::prelude::*;
1010

1111
use bevy::window::PrimaryWindow;
12-
use bevy_easy_compute::prelude::*;
12+
use bevy_app_compute::prelude::*;
1313

1414
use worker::{Boid, BoidWorker};
1515

@@ -19,7 +19,7 @@ fn main() {
1919
App::new()
2020
.add_plugins(DefaultPlugins)
2121
.add_plugins(LogDiagnosticsPlugin::default())
22-
.add_plugins(FrameTimeDiagnosticsPlugin)
22+
.add_plugins(FrameTimeDiagnosticsPlugin::default())
2323
.add_plugins(AppComputePlugin)
2424
.add_plugins(AppComputeWorkerPlugin::<BoidWorker>::default())
2525
.insert_resource(ClearColor(css::BLACK.into()))
@@ -61,12 +61,12 @@ fn move_entities(
6161
worker: ResMut<AppComputeWorker<BoidWorker>>,
6262
q_window: Query<&Window, With<PrimaryWindow>>,
6363
mut q_boid: Query<(&mut Transform, &BoidEntity), With<BoidEntity>>,
64-
) {
64+
) -> Result<()> {
6565
if !worker.ready() {
66-
return;
66+
return Ok(());
6767
}
6868

69-
let window = q_window.single();
69+
let window = q_window.single()?;
7070

7171
let boids = worker.read_vec::<Boid>("boids_dst");
7272

@@ -81,4 +81,6 @@ fn move_entities(
8181
transform.translation = world_pos.extend(0.);
8282
transform.look_to(Vec3::Z, boids[boid_entity.0].vel.extend(0.));
8383
});
84+
85+
Ok(())
8486
}

examples/boids/worker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bevy::prelude::*;
22

3-
use bevy_easy_compute::prelude::*;
3+
use bevy_app_compute::prelude::*;
44
use bytemuck::{Pod, Zeroable};
55

6-
use rand::distributions::{Distribution, Uniform};
6+
use rand::distr::{Distribution, Uniform};
77

88
use crate::NUM_BOIDS;
99

@@ -50,8 +50,8 @@ impl ComputeWorker for BoidWorker {
5050
};
5151

5252
let mut initial_boids_data = Vec::with_capacity(NUM_BOIDS as usize);
53-
let mut rng = rand::thread_rng();
54-
let unif = Uniform::new_inclusive(-1., 1.);
53+
let mut rng = rand::rng();
54+
let unif = Uniform::new_inclusive(-1., 1.).unwrap();
5555

5656
for _ in 0..NUM_BOIDS {
5757
initial_boids_data.push(Boid {

examples/game_of_life/bind_groups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bevy::{
99
renderer::RenderDevice,
1010
},
1111
};
12-
use bevy_easy_compute::prelude::*;
12+
use bevy_app_compute::prelude::*;
1313

1414
use crate::worker::{
1515
GameOfLifeWorker, Settings, CELLS_IN_BUFFER, CELLS_OUT_BUFFER, SETTINGS_BUFFER,

examples/game_of_life/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
2020

2121
use bevy::prelude::*;
2222

23-
use bevy_easy_compute::prelude::*;
23+
use bevy_app_compute::prelude::*;
2424
use render::draw_plugin::DrawPlugin;
2525

2626
use crate::bind_groups::get_buffers_for_renderer;
@@ -32,7 +32,7 @@ fn main() {
3232
App::new()
3333
.add_plugins(DefaultPlugins)
3434
.add_plugins(LogDiagnosticsPlugin::default())
35-
.add_plugins(FrameTimeDiagnosticsPlugin)
35+
.add_plugins(FrameTimeDiagnosticsPlugin::default())
3636
.add_plugins(AppComputePlugin)
3737
.add_plugins(AppComputeWorkerPlugin::<GameOfLifeWorker>::default())
3838
.add_plugins(DrawPlugin)

examples/game_of_life/worker.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use bevy::prelude::*;
22

3-
use bevy_easy_compute::prelude::*;
3+
use bevy_app_compute::prelude::*;
44
use bytemuck::{Pod, Zeroable};
5-
use rand::{distributions::Uniform, Rng};
5+
use rand::{Rng, distr::Uniform};
6+
use tracing::info;
67
use wgpu::BufferUsages;
78

89
use crate::DIMENSIONS;
@@ -37,8 +38,8 @@ impl ComputeWorker for GameOfLifeWorker {
3738
};
3839

3940
let mut initial_cell_data = Vec::with_capacity(NUMBER_OF_CELLS as usize);
40-
let mut rng = rand::thread_rng();
41-
let range = Uniform::new(0.0, 1.0);
41+
let mut rng = rand::rng();
42+
let range = Uniform::new(0.0, 1.0).unwrap();
4243

4344
info!("Generating {NUMBER_OF_CELLS} random cells...");
4445
for _ in 0..NUMBER_OF_CELLS {

examples/multi_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! input for the next pass.
33
44
use bevy::{prelude::*, reflect::TypePath};
5-
use bevy_easy_compute::prelude::*;
5+
use bevy_app_compute::prelude::*;
66

77
#[derive(TypePath)]
88
struct FirstPassShader;

examples/one_shot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example showing how to execute compute shaders on-demand
22
33
use bevy::prelude::*;
4-
use bevy_easy_compute::prelude::*;
4+
use bevy_app_compute::prelude::*;
55

66
#[derive(TypePath)]
77
struct SimpleShader;

0 commit comments

Comments
 (0)