Skip to content

Commit 1df251b

Browse files
committed
Update to bevy 0.10.0, bump version to 0.5.0
1 parent 13e6840 commit 1df251b

File tree

6 files changed

+40
-69
lines changed

6 files changed

+40
-69
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy-rust-gpu"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2021"
55

66
[features]
@@ -10,8 +10,8 @@ hot-rebuild = []
1010
bevy-pbr-rust = []
1111

1212
[dependencies]
13-
bevy = "0.9.1"
13+
bevy = "0.10.0"
1414
serde = "1.0.152"
1515
serde_json = "1.0.93"
16-
bevy_common_assets = { version = "0.4.0", features = ["json"] }
16+
bevy_common_assets = { version = "0.5.0", features = ["json"] }
1717
once_cell = "1.17.1"

src/entry_point.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Trait representation of a `rust-gpu` entry point.
22
3+
use bevy::render::render_resource::ShaderDefVal;
4+
35
/// An entry point name for use with the [`EntryPoint`] trait.
46
pub type EntryPointName = &'static str;
57

@@ -30,12 +32,12 @@ pub trait EntryPoint: 'static + Send + Sync {
3032
const PARAMETERS: EntryPointParameters;
3133

3234
/// Constructs a permutation set from the provided shader defs
33-
fn permutation(shader_defs: &Vec<String>) -> Vec<String> {
35+
fn permutation(shader_defs: &Vec<ShaderDefVal>) -> Vec<String> {
3436
let mut permutation = vec![];
3537

3638
for (defined, undefined) in Self::PARAMETERS.iter() {
3739
if let Some(mapping) = defined.iter().find_map(|(def, mapping)| {
38-
if shader_defs.contains(&def.to_string()) {
40+
if shader_defs.contains(&ShaderDefVal::Bool(def.to_string(), true)) {
3941
Some(mapping)
4042
} else {
4143
None
@@ -51,7 +53,7 @@ pub trait EntryPoint: 'static + Send + Sync {
5153
}
5254

5355
/// Build an entry point name from the provided shader defs
54-
fn build(shader_defs: &Vec<String>) -> String {
56+
fn build(shader_defs: &Vec<ShaderDefVal>) -> String {
5557
std::iter::once(Self::NAME.to_string())
5658
.chain(
5759
Self::permutation(shader_defs)

src/entry_point_export.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use std::{
99
};
1010

1111
use bevy::{
12-
prelude::{
13-
default, info, CoreStage, Deref, DerefMut, IntoSystemDescriptor, NonSendMut, Plugin,
14-
},
12+
prelude::{default, info, CoreSet, Deref, DerefMut, IntoSystemConfig, NonSendMut, Plugin},
1513
tasks::IoTaskPool,
1614
utils::HashMap,
1715
};
@@ -34,19 +32,13 @@ impl Plugin for EntryPointExportPlugin {
3432
fn build(&self, app: &mut bevy::prelude::App) {
3533
app.world.init_non_send_resource::<EntryPointExport>();
3634

37-
app.add_system_to_stage(
38-
CoreStage::Update,
39-
EntryPointExport::create_export_containers_system,
40-
)
41-
.add_system_to_stage(
42-
CoreStage::Last,
43-
EntryPointExport::receive_entry_points_system,
44-
)
45-
.add_system_to_stage(
46-
CoreStage::Last,
35+
app.add_systems((
36+
EntryPointExport::create_export_containers_system.in_base_set(CoreSet::Update),
37+
EntryPointExport::receive_entry_points_system.in_base_set(CoreSet::Last),
4738
EntryPointExport::export_entry_points_system
39+
.in_base_set(CoreSet::Last)
4840
.after(EntryPointExport::receive_entry_points_system),
49-
);
41+
));
5042
}
5143
}
5244

src/plugin.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Main Rust-GPU plugin.
22
33
use bevy::{
4-
prelude::{default, info, Plugin},
5-
render::{settings::WgpuSettings, RenderPlugin},
4+
prelude::{default, Plugin},
5+
render::settings::{WgpuLimits, WgpuSettings},
66
};
77

88
use crate::prelude::ChangedShaders;
@@ -13,31 +13,6 @@ pub struct RustGpuPlugin;
1313

1414
impl Plugin for RustGpuPlugin {
1515
fn build(&self, app: &mut bevy::prelude::App) {
16-
// Panic if added too late for `WgpuSettings` to take effect
17-
if app.is_plugin_added::<RenderPlugin>() {
18-
panic!("BevyRustGpuPlugin must be added before bevy_render::RenderPlugin");
19-
}
20-
21-
// Forcibly disable storage buffers to account for rust-gpu limitations
22-
let mut wgpu_settings = app
23-
.world
24-
.get_resource_or_insert_with::<WgpuSettings>(default);
25-
26-
let constrained_limits = match &mut wgpu_settings.constrained_limits {
27-
Some(constrained_limits) => {
28-
info!("Constrained limits exists");
29-
constrained_limits
30-
}
31-
None => {
32-
info!("Constrained limits does not exist");
33-
wgpu_settings.constrained_limits = Some(wgpu_settings.limits.clone());
34-
wgpu_settings.constrained_limits.as_mut().unwrap()
35-
}
36-
};
37-
38-
info!("Setting max storage buffers per shader stage");
39-
constrained_limits.max_storage_buffers_per_shader_stage = 0;
40-
4116
// Initialize `ChangedShaders` resource
4217
app.init_resource::<ChangedShaders>();
4318

@@ -46,3 +21,15 @@ impl Plugin for RustGpuPlugin {
4621
app.add_plugin(crate::prelude::EntryPointExportPlugin);
4722
}
4823
}
24+
25+
impl RustGpuPlugin {
26+
pub fn wgpu_settings() -> WgpuSettings {
27+
WgpuSettings {
28+
constrained_limits: Some(WgpuLimits {
29+
max_storage_buffers_per_shader_stage: 0,
30+
..default()
31+
}),
32+
..default()
33+
}
34+
}
35+
}

src/rust_gpu.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{any::TypeId, marker::PhantomData, path::PathBuf, sync::RwLock};
55
use bevy::{
66
pbr::MaterialPipelineKey,
77
prelude::{
8-
default, info, warn, CoreStage, Image, IntoSystemDescriptor, Material, MaterialPlugin,
9-
Plugin, Handle, Shader, Deref, DerefMut, Resource,
8+
default, info, warn, CoreSet, Deref, DerefMut, Handle, Image, IntoSystemConfig, Material,
9+
MaterialPlugin, Plugin, Resource, Shader,
1010
},
1111
reflect::TypeUuid,
1212
render::render_resource::{AsBindGroup, PreparedBindGroup, ShaderRef},
@@ -20,14 +20,6 @@ use crate::{
2020
systems::{reload_materials, shader_events},
2121
};
2222

23-
const SHADER_DEFS: &[&'static str] = &[
24-
"NO_STORAGE_BUFFERS_SUPPORT",
25-
#[cfg(feature = "webgl")]
26-
"NO_TEXTURE_ARRAYS_SUPPORT",
27-
#[cfg(feature = "webgl")]
28-
"SIXTEEN_BYTE_ALIGNMENT",
29-
];
30-
3123
static MATERIAL_SETTINGS: Lazy<RwLock<HashMap<TypeId, RustGpuSettings>>> = Lazy::new(default);
3224

3325
/// Configures backend support for [`RustGpu<M>`].
@@ -55,11 +47,8 @@ where
5547
M::Data: Clone + Eq + std::hash::Hash,
5648
{
5749
fn build(&self, app: &mut bevy::prelude::App) {
58-
app.add_system_to_stage(CoreStage::Last, reload_materials::<M>);
59-
app.add_system_to_stage(
60-
CoreStage::Last,
61-
shader_events::<M>.before(reload_materials::<M>),
62-
);
50+
app.add_system(reload_materials::<M>.in_base_set(CoreSet::Last));
51+
app.add_system(shader_events::<M>.before(reload_materials::<M>));
6352

6453
app.add_plugin(MaterialPlugin::<RustGpu<M>>::default());
6554

@@ -221,7 +210,7 @@ where
221210
images: &bevy::render::render_asset::RenderAssets<Image>,
222211
fallback_image: &bevy::render::texture::FallbackImage,
223212
) -> Result<
224-
bevy::render::render_resource::PreparedBindGroup<Self>,
213+
bevy::render::render_resource::PreparedBindGroup<Self::Data>,
225214
bevy::render::render_resource::AsBindGroupError,
226215
> {
227216
self.base

src/shader_meta.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ use once_cell::sync::Lazy;
66

77
use bevy::{
88
prelude::{
9-
default, info, AssetEvent, Assets, Deref, DerefMut, EventReader, Handle,
10-
IntoSystemDescriptor, Plugin, Res, ResMut, Resource, Shader,
9+
default, info, AssetEvent, Assets, CoreSet, Deref, DerefMut, EventReader, Handle,
10+
IntoSystemConfig, Plugin, Res, ResMut, Resource, Shader,
1111
},
1212
reflect::TypeUuid,
13-
utils::{HashMap, HashSet},
13+
utils::HashMap,
1414
};
1515
use bevy_common_assets::json::JsonAssetPlugin;
1616

1717
use serde::{Deserialize, Serialize};
1818

1919
use crate::{
2020
prelude::{reload_materials, RustGpuMaterial},
21-
systems::shader_events, ChangedShaders,
21+
systems::shader_events,
22+
ChangedShaders,
2223
};
2324

2425
pub(crate) static SHADER_META: Lazy<RwLock<ShaderMeta>> = Lazy::new(Default::default);
@@ -47,9 +48,9 @@ where
4748
app.add_plugin(JsonAssetPlugin::<ModuleMeta>::new(&["spv.json"]));
4849
}
4950

50-
app.add_system_to_stage(
51-
bevy::prelude::CoreStage::Last,
51+
app.add_system(
5252
module_meta_events::<M>
53+
.in_base_set(CoreSet::Last)
5354
.after(shader_events::<M>)
5455
.before(reload_materials::<M>),
5556
);

0 commit comments

Comments
 (0)