Skip to content

Commit 5cc5400

Browse files
authoredNov 23, 2023
Merge pull request #5 from EngoDev/feature/bevy-0.12
Feature/bevy 0.12
2 parents 7ee8c0a + d789a97 commit 5cc5400

11 files changed

+286
-256
lines changed
 

‎Cargo.toml

+39-36
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
[package]
2-
name = "bevy_app_compute"
3-
version = "0.10.3"
4-
authors = ["Kjolnyr <kjolnyr@protonmail.com>"]
5-
edition = "2021"
6-
description = "App compute plugin for Bevy"
7-
repository = "https://github.com/Kjolnyr/bevy_app_compute"
8-
homepage = "https://github.com/Kjolnyr/bevy_app_compute"
9-
documentation = "https://docs.rs/bevy_app_compute"
10-
license = "MIT OR Apache-2.0"
11-
readme = "README.md"
12-
categories = ["game-development"]
13-
14-
15-
[dependencies]
16-
bevy = "0.10.1"
17-
parking_lot = "0.12.1"
18-
wgpu = "0.15.1"
19-
codespan-reporting = "0.11.1"
20-
futures-lite = "1.13.0"
21-
bytemuck = "1.13.1"
22-
23-
[dev-dependencies]
24-
rand = "0.8.5"
25-
26-
[[example]]
27-
name = "simple"
28-
29-
[[example]]
30-
name = "multi_pass"
31-
32-
[[example]]
33-
name = "one_shot"
34-
35-
[[example]]
36-
name = "boids"
1+
[package]
2+
name = "bevy_app_compute"
3+
version = "0.12.0"
4+
authors = ["Kjolnyr <kjolnyr@protonmail.com>"]
5+
edition = "2021"
6+
description = "App compute plugin for Bevy"
7+
repository = "https://github.com/Kjolnyr/bevy_app_compute"
8+
homepage = "https://github.com/Kjolnyr/bevy_app_compute"
9+
documentation = "https://docs.rs/bevy_app_compute"
10+
license = "MIT OR Apache-2.0"
11+
readme = "README.md"
12+
categories = ["game-development"]
13+
14+
15+
[dependencies]
16+
bevy = "0.12"
17+
parking_lot = "0.12.1"
18+
wgpu = { version = "0.17.1", features = ["naga"] }
19+
codespan-reporting = "0.11.1"
20+
futures-lite = "1.13.0"
21+
bytemuck = "1.4.0"
22+
naga = { version = "0.13.0", features = ["wgsl-in"] }
23+
naga_oil = "0.10"
24+
25+
[dev-dependencies]
26+
rand = "0.8.5"
27+
bevy = { version = "0.12", features = ["wayland"] }
28+
29+
[[example]]
30+
name = "simple"
31+
32+
[[example]]
33+
name = "multi_pass"
34+
35+
[[example]]
36+
name = "one_shot"
37+
38+
[[example]]
39+
name = "boids"

‎README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ use bevy_app_compute::AppComputePlugin;
8686

8787
fn main() {
8888
App::new()
89-
.add_plugin(AppComputePlugin)
90-
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
89+
.add_plugins(AppComputePlugin)
90+
.add_plugins(AppComputeWorkerPlugin::<SimpleComputeWorker>::default());
9191
}
9292
```
9393

@@ -184,4 +184,5 @@ See [examples](https://github.com/kjolnyr/bevy_app_compute/tree/main/examples)
184184
|Bevy|bevy_app_compute|
185185
|---|---|
186186
|main|main|
187-
|0.10|0.10.3|
187+
|0.10|0.10.3|
188+
|0.12|0.10.5|

‎examples/boids.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ impl ComputeWorker for BoidWorker {
9696
fn main() {
9797
App::new()
9898
.add_plugins(DefaultPlugins)
99-
.add_plugin(LogDiagnosticsPlugin::default())
100-
.add_plugin(FrameTimeDiagnosticsPlugin::default())
101-
.add_plugin(AppComputePlugin)
102-
.add_plugin(AppComputeWorkerPlugin::<BoidWorker>::default())
99+
.add_plugins(LogDiagnosticsPlugin::default())
100+
.add_plugins(FrameTimeDiagnosticsPlugin::default())
101+
.add_plugins(AppComputePlugin)
102+
.add_plugins(AppComputeWorkerPlugin::<BoidWorker>::default())
103103
.insert_resource(ClearColor(Color::DARK_GRAY))
104-
.add_startup_system(setup)
105-
.add_system(move_entities)
104+
.add_systems(Startup, setup)
105+
.add_systems(Update, move_entities)
106106
.run()
107107
}
108108

@@ -159,7 +159,7 @@ fn move_entities(
159159

160160
q_boid
161161
.par_iter_mut()
162-
.for_each_mut(|(mut transform, boid_entity)| {
162+
.for_each(|(mut transform, boid_entity)| {
163163
let world_pos = Vec2::new(
164164
(window.width() / 2.) * (boids[boid_entity.0].pos.x),
165165
(window.height() / 2.) * (boids[boid_entity.0].pos.y),

‎examples/multi_pass.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl ComputeWorker for SimpleComputeWorker {
4646
fn main() {
4747
App::new()
4848
.add_plugins(DefaultPlugins)
49-
.add_plugin(AppComputePlugin)
50-
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
51-
.add_system(test)
49+
.add_plugins(AppComputePlugin)
50+
.add_plugins(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
51+
.add_systems(Update, test)
5252
.run();
5353
}
5454

‎examples/one_shot.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ impl ComputeWorker for SimpleComputeWorker {
3232
fn main() {
3333
App::new()
3434
.add_plugins(DefaultPlugins)
35-
.add_plugin(AppComputePlugin)
36-
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
37-
.add_system(on_click_compute)
38-
.add_system(read_data)
35+
.add_plugins(AppComputePlugin)
36+
.add_plugins(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
37+
.add_systems(Update, (on_click_compute, read_data))
3938
.run();
4039
}
4140

‎examples/simple.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Simple, hello world example to show the basic concept
22
3+
use bevy::render::RenderPlugin;
34
use bevy::{prelude::*, reflect::TypeUuid, render::render_resource::ShaderRef};
45
use bevy_app_compute::prelude::*;
56

@@ -31,9 +32,9 @@ impl ComputeWorker for SimpleComputeWorker {
3132
fn main() {
3233
App::new()
3334
.add_plugins(DefaultPlugins)
34-
.add_plugin(AppComputePlugin)
35-
.add_plugin(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
36-
.add_system(test)
35+
.add_plugins(AppComputePlugin)
36+
.add_plugins(AppComputeWorkerPlugin::<SimpleComputeWorker>::default())
37+
.add_systems(Update, test)
3738
.run();
3839
}
3940

‎src/lib.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ pub(crate) fn extract_shaders(
3333
shaders: Res<Assets<Shader>>,
3434
mut events: EventReader<AssetEvent<Shader>>,
3535
) {
36-
for event in events.iter() {
36+
for event in events.read() {
3737
match event {
38-
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => {
39-
if let Some(shader) = shaders.get(handle) {
40-
pipeline_cache.set_shader(handle, shader);
38+
AssetEvent::Added { id: shader_id } | AssetEvent::Modified { id: shader_id } => {
39+
if let Some(shader) = shaders.get(shader_id.clone()) {
40+
pipeline_cache.set_shader(shader_id, shader);
41+
}
42+
}
43+
AssetEvent::Removed { id: shader_id } => pipeline_cache.remove_shader(shader_id),
44+
AssetEvent::LoadedWithDependencies { id: shader_id } => {
45+
if let Some(shader) = shaders.get(shader_id.clone()) {
46+
pipeline_cache.set_shader(shader_id, shader);
4147
}
4248
}
43-
AssetEvent::Removed { handle } => pipeline_cache.remove_shader(handle),
4449
}
4550
}
4651
}

‎src/pipeline_cache.rs

+190-172
Large diffs are not rendered by default.

‎src/plugin.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use crate::{
1111
pub struct AppComputePlugin;
1212

1313
impl Plugin for AppComputePlugin {
14-
fn build(&self, app: &mut App) {
14+
fn build(&self, _app: &mut App) {}
15+
16+
fn finish(&self, app: &mut App) {
1517
let render_device = app.world.resource::<RenderDevice>().clone();
1618

1719
app.insert_resource(AppPipelineCache::new(render_device))
18-
.add_system(extract_shaders.in_base_set(CoreSet::PreUpdate))
19-
.add_system(process_pipeline_queue_system);
20+
.add_systems(PreUpdate, extract_shaders)
21+
.add_systems(Update, process_pipeline_queue_system);
2022
}
2123
}
2224

@@ -34,15 +36,16 @@ impl<W: ComputeWorker> Default for AppComputeWorkerPlugin<W> {
3436
}
3537

3638
impl<W: ComputeWorker> Plugin for AppComputeWorkerPlugin<W> {
37-
fn build(&self, app: &mut App) {
39+
fn build(&self, _app: &mut App) {}
40+
41+
fn finish(&self, app: &mut App) {
3842
let worker = W::build(&mut app.world);
3943

4044
app.insert_resource(worker)
41-
.add_system(AppComputeWorker::<W>::extract_pipelines)
45+
.add_systems(Update, AppComputeWorker::<W>::extract_pipelines)
4246
.add_systems(
43-
(AppComputeWorker::<W>::unmap_all, AppComputeWorker::<W>::run)
44-
.chain()
45-
.in_base_set(CoreSet::PostUpdate),
47+
PostUpdate,
48+
(AppComputeWorker::<W>::unmap_all, AppComputeWorker::<W>::run).chain(),
4649
);
4750
}
4851
}

‎src/worker.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bevy::{
1111
};
1212
use bytemuck::{bytes_of, cast_slice, from_bytes, AnyBitPattern, NoUninit};
1313
use wgpu::{
14-
BindGroupDescriptor, BindGroupEntry, CommandEncoder, CommandEncoderDescriptor,
14+
BindGroupEntry, CommandEncoder, CommandEncoderDescriptor,
1515
ComputePassDescriptor,
1616
};
1717

@@ -101,7 +101,7 @@ impl<W: ComputeWorker> From<&AppComputeWorkerBuilder<'_, W>> for AppComputeWorke
101101
steps: builder.steps.clone(),
102102
command_encoder,
103103
run_mode: builder.run_mode,
104-
_phantom: PhantomData::default(),
104+
_phantom: PhantomData,
105105
}
106106
}
107107
}
@@ -139,16 +139,16 @@ impl<W: ComputeWorker> AppComputeWorker<W> {
139139
};
140140

141141
let bind_group_layout = pipeline.get_bind_group_layout(0);
142-
let bind_group = self.render_device.create_bind_group(&BindGroupDescriptor {
143-
label: None,
144-
layout: &bind_group_layout,
145-
entries: &entries,
146-
});
142+
let bind_group = self.render_device.create_bind_group(
143+
None,
144+
&bind_group_layout.into(),
145+
&entries,
146+
);
147147

148148
let Some(encoder) = &mut self.command_encoder else { return Err(Error::EncoderIsNone) };
149149
{
150150
let mut cpass = encoder.begin_compute_pass(&ComputePassDescriptor { label: None });
151-
cpass.set_pipeline(&pipeline);
151+
cpass.set_pipeline(pipeline);
152152
cpass.set_bind_group(0, &bind_group, &[]);
153153
cpass.dispatch_workgroups(
154154
compute_pass.workgroups[0],
@@ -193,7 +193,7 @@ impl<W: ComputeWorker> AppComputeWorker<W> {
193193
else { return Err(Error::BufferNotFound(name.to_owned()))};
194194

195195
encoder.copy_buffer_to_buffer(
196-
&buffer,
196+
buffer,
197197
0,
198198
&staging_buffer.buffer,
199199
0,
@@ -243,8 +243,8 @@ impl<W: ComputeWorker> AppComputeWorker<W> {
243243

244244
/// Try Read data from `target` staging buffer, return a single `B: Pod`
245245
#[inline]
246-
pub fn try_read<'a, B: AnyBitPattern>(&'a self, target: &str) -> Result<B> {
247-
let result = from_bytes::<B>(&self.try_read_raw(target)?).clone();
246+
pub fn try_read<B: AnyBitPattern>(&self, target: &str) -> Result<B> {
247+
let result = *from_bytes::<B>(&self.try_read_raw(target)?);
248248
Ok(result)
249249
}
250250

@@ -402,13 +402,13 @@ impl<W: ComputeWorker> AppComputeWorker<W> {
402402
pipeline_cache: Res<AppPipelineCache>,
403403
) {
404404
for (uuid, cached_id) in &worker.cached_pipeline_ids.clone() {
405-
let Some(pipeline) = worker.pipelines.get(&uuid) else { continue; };
405+
let Some(pipeline) = worker.pipelines.get(uuid) else { continue; };
406406

407407
if pipeline.is_some() {
408408
continue;
409409
};
410410

411-
let cached_id = cached_id.clone();
411+
let cached_id = *cached_id;
412412

413413
worker.pipelines.insert(
414414
*uuid,

‎src/worker_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, W: ComputeWorker> AppComputeWorkerBuilder<'a, W> {
4343
staging_buffers: HashMap::default(),
4444
steps: vec![],
4545
run_mode: RunMode::Continuous,
46-
_phantom: PhantomData::default(),
46+
_phantom: PhantomData,
4747
}
4848
}
4949

@@ -234,7 +234,7 @@ impl<'a, W: ComputeWorker> AppComputeWorkerBuilder<'a, W> {
234234

235235
self.steps.push(Step::ComputePass(ComputePass {
236236
workgroups,
237-
vars: vars.into_iter().map(|a| String::from(*a)).collect(),
237+
vars: vars.iter().map(|a| String::from(*a)).collect(),
238238
shader_uuid: S::TYPE_UUID,
239239
}));
240240
self

0 commit comments

Comments
 (0)
Please sign in to comment.