Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bevy 0.11 #4

Closed
wants to merge 8 commits into from
Closed
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
75 changes: 39 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
[package]
name = "bevy_app_compute"
version = "0.10.3"
authors = ["Kjolnyr <[email protected]>"]
edition = "2021"
description = "App compute plugin for Bevy"
repository = "https://github.com/Kjolnyr/bevy_app_compute"
homepage = "https://github.com/Kjolnyr/bevy_app_compute"
documentation = "https://docs.rs/bevy_app_compute"
license = "MIT OR Apache-2.0"
readme = "README.md"
categories = ["game-development"]


[dependencies]
bevy = "0.10.1"
parking_lot = "0.12.1"
wgpu = "0.15.1"
codespan-reporting = "0.11.1"
futures-lite = "1.13.0"
bytemuck = "1.13.1"

[dev-dependencies]
rand = "0.8.5"

[[example]]
name = "simple"

[[example]]
name = "multi_pass"

[[example]]
name = "one_shot"

[[example]]
name = "boids"
[package]
name = "bevy_app_compute"
version = "0.11.0"
authors = ["Kjolnyr <[email protected]>"]
edition = "2021"
description = "App compute plugin for Bevy"
repository = "https://github.com/Kjolnyr/bevy_app_compute"
homepage = "https://github.com/Kjolnyr/bevy_app_compute"
documentation = "https://docs.rs/bevy_app_compute"
license = "MIT OR Apache-2.0"
readme = "README.md"
categories = ["game-development"]


[dependencies]
bevy = "0.11"
parking_lot = "0.12.1"
wgpu = { version = "0.16.0", features = ["naga"] }
codespan-reporting = "0.11.1"
futures-lite = "1.13.0"
bytemuck = "1.4.0"
naga = { version = "0.12.0", features = ["wgsl-in"] }
naga_oil = "0.8.0"

[dev-dependencies]
rand = "0.8.5"
bevy = { version = "0.11", features = ["wayland"] }

[[example]]
name = "simple"

[[example]]
name = "multi_pass"

[[example]]
name = "one_shot"

[[example]]
name = "boids"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add the following line to your `Cargo.toml`

```toml
[dependencies]
bevy_app_compute = "0.10.3"
bevy_app_compute = "0.11.0"
```

## Usage
Expand Down Expand Up @@ -86,8 +86,8 @@ use bevy_app_compute::AppComputePlugin;

fn main() {
App::new()
.add_plugin(AppComputePlugin)
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
.add_plugins(AppComputePlugin)
.add_plugins(AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
}
```

Expand Down Expand Up @@ -184,4 +184,5 @@ See [examples](https://github.com/kjolnyr/bevy_app_compute/tree/main/examples)
|Bevy|bevy_app_compute|
|---|---|
|main|main|
|0.10|0.10.3|
|0.10|0.10.3|
|0.11|0.11.0|
14 changes: 8 additions & 6 deletions examples/boids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ impl ComputeWorker for BoidWorker {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(AppComputePlugin)
.add_plugin(AppComputeWorkerPlugin::<BoidWorker>::default())
.add_plugins((
LogDiagnosticsPlugin::default(),
FrameTimeDiagnosticsPlugin,
AppComputePlugin,
AppComputeWorkerPlugin::<BoidWorker>::default(),
))
.insert_resource(ClearColor(Color::DARK_GRAY))
.add_startup_system(setup)
.add_system(move_entities)
.add_systems(Startup, setup)
.add_systems(Update, move_entities)
.run()
}

Expand Down
128 changes: 65 additions & 63 deletions examples/multi_pass.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
//! Example showing how to have multiple passes

use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::ShaderRef};
use bevy_app_compute::prelude::*;

#[derive(TypeUuid)]
#[uuid = "5a4f7163-88cd-4a59-94c7-fb51abe389b8"]
struct FirstPassShader;

impl ComputeShader for FirstPassShader {
fn shader() -> ShaderRef {
"shaders/first_pass.wgsl".into()
}
}

#[derive(TypeUuid)]
#[uuid = "7ada0206-7871-404b-b197-5e2477e7073f"]
struct SecondPassShader;

impl ComputeShader for SecondPassShader {
fn shader() -> ShaderRef {
"shaders/second_pass.wgsl".into()
}
}

#[derive(Resource)]
struct SimpleComputeWorker;

impl ComputeWorker for SimpleComputeWorker {
fn build(world: &mut World) -> AppComputeWorker<Self> {
let worker = AppComputeWorkerBuilder::new(world)
.add_uniform("value", &3.)
.add_storage("input", &[1., 2., 3., 4.])
.add_staging("output", &[0f32; 4])
.add_pass::<FirstPassShader>([4, 1, 1], &["value", "input", "output"]) // add each item + `value` from `input` to `output`
.add_pass::<SecondPassShader>([4, 1, 1], &["output"]) // multiply each element of `output` by itself
.build();

// [1. + 3., 2. + 3., 3. + 3., 4. + 3.] = [4., 5., 6., 7.]
// [4. * 4., 5. * 5., 6. * 6., 7. * 7.] = [16., 25., 36., 49.]

worker
}
}

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AppComputePlugin)
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
.add_system(test)
.run();
}

fn test(compute_worker: Res<AppComputeWorker<SimpleComputeWorker>>) {
if !compute_worker.ready() {
return;
};

let result: Vec<f32> = compute_worker.read_vec("output");

println!("got {:?}", result) // [16., 25., 36., 49.]
}
//! Example showing how to have multiple passes

use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::ShaderRef};
use bevy_app_compute::prelude::*;

#[derive(TypeUuid)]
#[uuid = "5a4f7163-88cd-4a59-94c7-fb51abe389b8"]
struct FirstPassShader;

impl ComputeShader for FirstPassShader {
fn shader() -> ShaderRef {
"shaders/first_pass.wgsl".into()
}
}

#[derive(TypeUuid)]
#[uuid = "7ada0206-7871-404b-b197-5e2477e7073f"]
struct SecondPassShader;

impl ComputeShader for SecondPassShader {
fn shader() -> ShaderRef {
"shaders/second_pass.wgsl".into()
}
}

#[derive(Resource)]
struct SimpleComputeWorker;

impl ComputeWorker for SimpleComputeWorker {
fn build(world: &mut World) -> AppComputeWorker<Self> {
let worker = AppComputeWorkerBuilder::new(world)
.add_uniform("value", &3.)
.add_storage("input", &[1., 2., 3., 4.])
.add_staging("output", &[0f32; 4])
.add_pass::<FirstPassShader>([4, 1, 1], &["value", "input", "output"]) // add each item + `value` from `input` to `output`
.add_pass::<SecondPassShader>([4, 1, 1], &["output"]) // multiply each element of `output` by itself
.build();

// [1. + 3., 2. + 3., 3. + 3., 4. + 3.] = [4., 5., 6., 7.]
// [4. * 4., 5. * 5., 6. * 6., 7. * 7.] = [16., 25., 36., 49.]

worker
}
}

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((
AppComputePlugin,
AppComputeWorkerPlugin::<SimpleComputeWorker>::default(),
))
.add_systems(Update, test)
.run();
}

fn test(compute_worker: Res<AppComputeWorker<SimpleComputeWorker>>) {
if !compute_worker.ready() {
return;
};

let result: Vec<f32> = compute_worker.read_vec("output");

println!("got {:?}", result) // [16., 25., 36., 49.]
}
127 changes: 64 additions & 63 deletions examples/one_shot.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
//! Example showing how to execute compute shaders on demand

use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::ShaderRef};
use bevy_app_compute::prelude::*;

#[derive(TypeUuid)]
#[uuid = "2545ae14-a9bc-4f03-9ea4-4eb43d1075a7"]
struct SimpleShader;

impl ComputeShader for SimpleShader {
fn shader() -> ShaderRef {
"shaders/simple.wgsl".into()
}
}

#[derive(Resource)]
struct SimpleComputeWorker;

impl ComputeWorker for SimpleComputeWorker {
fn build(world: &mut World) -> AppComputeWorker<Self> {
let worker = AppComputeWorkerBuilder::new(world)
.add_uniform("uni", &5.)
.add_staging("values", &[1., 2., 3., 4.])
.add_pass::<SimpleShader>([4, 1, 1], &["uni", "values"])
.one_shot()
.build();

worker
}
}

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AppComputePlugin)
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
.add_system(on_click_compute)
.add_system(read_data)
.run();
}

fn on_click_compute(
buttons: Res<Input<MouseButton>>,
mut compute_worker: ResMut<AppComputeWorker<SimpleComputeWorker>>,
) {
if !buttons.just_pressed(MouseButton::Left) {
return;
}

compute_worker.execute();
}

fn read_data(mut compute_worker: ResMut<AppComputeWorker<SimpleComputeWorker>>) {
if !compute_worker.ready() {
return;
};

let result: Vec<f32> = compute_worker.read_vec("values");

compute_worker.write_slice("values", &result);

println!("got {:?}", result)
}
//! Example showing how to execute compute shaders on demand

use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::ShaderRef};
use bevy_app_compute::prelude::*;

#[derive(TypeUuid)]
#[uuid = "2545ae14-a9bc-4f03-9ea4-4eb43d1075a7"]
struct SimpleShader;

impl ComputeShader for SimpleShader {
fn shader() -> ShaderRef {
"shaders/simple.wgsl".into()
}
}

#[derive(Resource)]
struct SimpleComputeWorker;

impl ComputeWorker for SimpleComputeWorker {
fn build(world: &mut World) -> AppComputeWorker<Self> {
let worker = AppComputeWorkerBuilder::new(world)
.add_uniform("uni", &5.)
.add_staging("values", &[1., 2., 3., 4.])
.add_pass::<SimpleShader>([4, 1, 1], &["uni", "values"])
.one_shot()
.build();

worker
}
}

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((
AppComputePlugin,
AppComputeWorkerPlugin::<SimpleComputeWorker>::default(),
))
.add_systems(Update, (read_data, on_click_compute))
.run();
}

fn on_click_compute(
buttons: Res<Input<MouseButton>>,
mut compute_worker: ResMut<AppComputeWorker<SimpleComputeWorker>>,
) {
if !buttons.just_pressed(MouseButton::Left) {
return;
}

compute_worker.execute();
}

fn read_data(mut compute_worker: ResMut<AppComputeWorker<SimpleComputeWorker>>) {
if !compute_worker.ready() {
return;
};

let result: Vec<f32> = compute_worker.read_vec("values");

compute_worker.write_slice("values", &result);

println!("got {:?}", result)
}
8 changes: 5 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ impl ComputeWorker for SimpleComputeWorker {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AppComputePlugin)
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
.add_system(test)
.add_plugins((
AppComputePlugin,
AppComputeWorkerPlugin::<SimpleComputeWorker>::default(),
))
.add_systems(Update, test)
.run();
}

Expand Down
Loading