Skip to content

Commit 0bf90bb

Browse files
authored
Merge pull request #3175 from cart/merge-renderer
Merge New Renderer
2 parents 94db017 + 8009af3 commit 0bf90bb

File tree

194 files changed

+24520
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+24520
-326
lines changed

Cargo.toml

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ repository = "https://github.com/bevyengine/bevy"
1313

1414
[workspace]
1515
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
16-
members = ["crates/*", "examples/ios", "tools/ci", "errors"]
16+
members = ["crates/*", "pipelined/*", "examples/ios", "tools/ci", "errors"]
1717

1818
[features]
1919
default = [
2020
"bevy_audio",
21+
"bevy_core_pipeline",
2122
"bevy_gilrs",
22-
"bevy_gltf",
23+
"bevy_gltf2",
2324
"bevy_wgpu",
25+
"bevy_sprite2",
26+
"bevy_render2",
27+
"bevy_pbr2",
2428
"bevy_winit",
2529
"render",
2630
"png",
@@ -50,6 +54,12 @@ bevy_gltf = ["bevy_internal/bevy_gltf"]
5054
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
5155
bevy_winit = ["bevy_internal/bevy_winit"]
5256

57+
bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
58+
bevy_render2 = ["bevy_internal/bevy_render2"]
59+
bevy_sprite2 = ["bevy_internal/bevy_sprite2"]
60+
bevy_pbr2 = ["bevy_internal/bevy_pbr2"]
61+
bevy_gltf2 = ["bevy_internal/bevy_gltf2"]
62+
5363
trace_chrome = ["bevy_internal/trace_chrome"]
5464
trace_tracy = ["bevy_internal/trace_tracy"]
5565
trace = ["bevy_internal/trace"]
@@ -95,6 +105,7 @@ ron = "0.6.2"
95105
serde = { version = "1", features = ["derive"] }
96106
# Needed to poll Task examples
97107
futures-lite = "1.11.3"
108+
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }
98109

99110
[[example]]
100111
name = "hello_world"
@@ -133,23 +144,51 @@ path = "examples/2d/text2d.rs"
133144
name = "texture_atlas"
134145
path = "examples/2d/texture_atlas.rs"
135146

147+
[[example]]
148+
name = "pipelined_texture_atlas"
149+
path = "examples/2d/pipelined_texture_atlas.rs"
150+
136151
# 3D Rendering
137152
[[example]]
138153
name = "3d_scene"
139154
path = "examples/3d/3d_scene.rs"
140155

156+
[[example]]
157+
name = "3d_scene_pipelined"
158+
path = "examples/3d/3d_scene_pipelined.rs"
159+
160+
[[example]]
161+
name = "many_cubes_pipelined"
162+
path = "examples/3d/many_cubes_pipelined.rs"
163+
164+
[[example]]
165+
name = "cornell_box_pipelined"
166+
path = "examples/3d/cornell_box_pipelined.rs"
167+
141168
[[example]]
142169
name = "load_gltf"
143170
path = "examples/3d/load_gltf.rs"
144171

172+
[[example]]
173+
name = "load_gltf_pipelined"
174+
path = "examples/3d/load_gltf_pipelined.rs"
175+
145176
[[example]]
146177
name = "msaa"
147178
path = "examples/3d/msaa.rs"
148179

180+
[[example]]
181+
name = "msaa_pipelined"
182+
path = "examples/3d/msaa_pipelined.rs"
183+
149184
[[example]]
150185
name = "orthographic"
151186
path = "examples/3d/orthographic.rs"
152187

188+
[[example]]
189+
name = "orthographic_pipelined"
190+
path = "examples/3d/orthographic_pipelined.rs"
191+
153192
[[example]]
154193
name = "parenting"
155194
path = "examples/3d/parenting.rs"
@@ -158,10 +197,22 @@ path = "examples/3d/parenting.rs"
158197
name = "pbr"
159198
path = "examples/3d/pbr.rs"
160199

200+
[[example]]
201+
name = "pbr_pipelined"
202+
path = "examples/3d/pbr_pipelined.rs"
203+
161204
[[example]]
162205
name = "render_to_texture"
163206
path = "examples/3d/render_to_texture.rs"
164207

208+
[[example]]
209+
name = "shadow_biases_pipelined"
210+
path = "examples/3d/shadow_biases_pipelined.rs"
211+
212+
[[example]]
213+
name = "shadow_caster_receiver_pipelined"
214+
path = "examples/3d/shadow_caster_receiver_pipelined.rs"
215+
165216
[[example]]
166217
name = "spawner"
167218
path = "examples/3d/spawner.rs"
@@ -170,6 +221,10 @@ path = "examples/3d/spawner.rs"
170221
name = "texture"
171222
path = "examples/3d/texture.rs"
172223

224+
[[example]]
225+
name = "texture_pipelined"
226+
path = "examples/3d/texture_pipelined.rs"
227+
173228
[[example]]
174229
name = "update_gltf_scene"
175230
path = "examples/3d/update_gltf_scene.rs"
@@ -413,11 +468,23 @@ path = "examples/shader/shader_custom_material.rs"
413468
name = "shader_defs"
414469
path = "examples/shader/shader_defs.rs"
415470

471+
[[example]]
472+
name = "custom_shader_pipelined"
473+
path = "examples/shader/custom_shader_pipelined.rs"
474+
475+
[[example]]
476+
name = "shader_defs_pipelined"
477+
path = "examples/shader/shader_defs_pipelined.rs"
478+
416479
# Tools
417480
[[example]]
418481
name = "bevymark"
419482
path = "examples/tools/bevymark.rs"
420483

484+
[[example]]
485+
name = "bevymark_pipelined"
486+
path = "examples/tools/bevymark_pipelined.rs"
487+
421488
# UI (User Interface)
422489
[[example]]
423490
name = "button"
@@ -444,6 +511,10 @@ path = "examples/ui/ui.rs"
444511
name = "clear_color"
445512
path = "examples/window/clear_color.rs"
446513

514+
[[example]]
515+
name = "clear_color_pipelined"
516+
path = "examples/window/clear_color_pipelined.rs"
517+
447518
[[example]]
448519
name = "multiple_windows"
449520
path = "examples/window/multiple_windows.rs"

assets/shaders/custom_material.wgsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[block]]
2+
struct CustomMaterial {
3+
color: vec4<f32>;
4+
};
5+
[[group(1), binding(0)]]
6+
var<uniform> material: CustomMaterial;
7+
8+
[[stage(fragment)]]
9+
fn fragment() -> [[location(0)]] vec4<f32> {
10+
return material.color;
11+
}

assets/shaders/shader_defs.wgsl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#import bevy_pbr::mesh_view_bind_group
2+
#import bevy_pbr::mesh_struct
3+
4+
[[group(1), binding(0)]]
5+
var<uniform> mesh: Mesh;
6+
7+
struct Vertex {
8+
[[location(0)]] position: vec3<f32>;
9+
[[location(1)]] normal: vec3<f32>;
10+
[[location(2)]] uv: vec2<f32>;
11+
};
12+
13+
struct VertexOutput {
14+
[[builtin(position)]] clip_position: vec4<f32>;
15+
};
16+
17+
[[stage(vertex)]]
18+
fn vertex(vertex: Vertex) -> VertexOutput {
19+
let world_position = mesh.model * vec4<f32>(vertex.position, 1.0);
20+
21+
var out: VertexOutput;
22+
out.clip_position = view.view_proj * world_position;
23+
return out;
24+
}
25+
26+
[[stage(fragment)]]
27+
fn fragment() -> [[location(0)]] vec4<f32> {
28+
var color = vec4<f32>(0.0, 0.0, 1.0, 1.0);
29+
# ifdef IS_RED
30+
color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
31+
# endif
32+
return color;
33+
}

crates/bevy_app/src/app.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
2+
pub use bevy_derive::AppLabel;
23
use bevy_ecs::{
34
prelude::{FromWorld, IntoExclusiveSystem},
45
schedule::{
@@ -8,12 +9,14 @@ use bevy_ecs::{
89
system::Resource,
910
world::World,
1011
};
11-
use bevy_utils::tracing::debug;
12+
use bevy_utils::{tracing::debug, HashMap};
1213
use std::fmt::Debug;
1314

1415
#[cfg(feature = "trace")]
1516
use bevy_utils::tracing::info_span;
1617

18+
bevy_utils::define_label!(AppLabel);
19+
1720
#[allow(clippy::needless_doctest_main)]
1821
/// Containers of app logic and data
1922
///
@@ -42,6 +45,12 @@ pub struct App {
4245
pub world: World,
4346
pub runner: Box<dyn Fn(App)>,
4447
pub schedule: Schedule,
48+
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
49+
}
50+
51+
struct SubApp {
52+
app: App,
53+
runner: Box<dyn Fn(&mut World, &mut App)>,
4554
}
4655

4756
impl Default for App {
@@ -73,6 +82,7 @@ impl App {
7382
world: Default::default(),
7483
schedule: Default::default(),
7584
runner: Box::new(run_once),
85+
sub_apps: HashMap::default(),
7686
}
7787
}
7888

@@ -85,6 +95,9 @@ impl App {
8595
#[cfg(feature = "trace")]
8696
let _bevy_frame_update_guard = bevy_frame_update_span.enter();
8797
self.schedule.run(&mut self.world);
98+
for sub_app in self.sub_apps.values_mut() {
99+
(sub_app.runner)(&mut self.world, &mut sub_app.app);
100+
}
88101
}
89102

90103
/// Starts the application by calling the app's [runner function](Self::set_runner).
@@ -823,6 +836,39 @@ impl App {
823836
}
824837
self
825838
}
839+
840+
pub fn add_sub_app(
841+
&mut self,
842+
label: impl AppLabel,
843+
app: App,
844+
f: impl Fn(&mut World, &mut App) + 'static,
845+
) -> &mut Self {
846+
self.sub_apps.insert(
847+
Box::new(label),
848+
SubApp {
849+
app,
850+
runner: Box::new(f),
851+
},
852+
);
853+
self
854+
}
855+
856+
/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
857+
pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App {
858+
match self.get_sub_app(label) {
859+
Ok(app) => app,
860+
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
861+
}
862+
}
863+
864+
/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
865+
/// an [Err] containing the given label.
866+
pub fn get_sub_app(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> {
867+
self.sub_apps
868+
.get_mut((&label) as &dyn AppLabel)
869+
.map(|sub_app| &mut sub_app.app)
870+
.ok_or(label)
871+
}
826872
}
827873

828874
fn run_once(mut app: App) {

crates/bevy_app/src/ci_testing.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ fn ci_testing_exit_after(
2222
*current_frame += 1;
2323
}
2424

25-
pub(crate) fn setup_app(app_builder: &mut App) -> &mut App {
25+
pub(crate) fn setup_app(app: &mut App) -> &mut App {
2626
let filename =
2727
std::env::var("CI_TESTING_CONFIG").unwrap_or_else(|_| "ci_testing_config.ron".to_string());
2828
let config: CiTestingConfig = ron::from_str(
2929
&std::fs::read_to_string(filename).expect("error reading CI testing configuration file"),
3030
)
3131
.expect("error deserializing CI testing configuration file");
32-
app_builder
33-
.insert_resource(config)
32+
app.insert_resource(config)
3433
.add_system(ci_testing_exit_after);
3534

36-
app_builder
35+
app
3736
}

crates/bevy_asset/src/handle.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl<T: Asset> Handle<T> {
9696
}
9797
}
9898

99+
#[inline]
99100
pub fn weak(id: HandleId) -> Self {
100101
Self {
101102
id,
@@ -129,6 +130,7 @@ impl<T: Asset> Handle<T> {
129130
self.handle_type = HandleType::Strong(sender);
130131
}
131132

133+
#[inline]
132134
pub fn clone_weak(&self) -> Self {
133135
Handle::weak(self.id)
134136
}

crates/bevy_asset/src/loader.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ impl<T: Asset> LoadedAsset<T> {
4343
}
4444
}
4545

46-
pub fn with_dependency(mut self, asset_path: AssetPath) -> Self {
46+
pub fn add_dependency(&mut self, asset_path: AssetPath) {
4747
self.dependencies.push(asset_path.to_owned());
48+
}
49+
50+
pub fn with_dependency(mut self, asset_path: AssetPath) -> Self {
51+
self.add_dependency(asset_path);
4852
self
4953
}
5054

51-
pub fn with_dependencies(mut self, asset_paths: Vec<AssetPath<'static>>) -> Self {
52-
self.dependencies.extend(asset_paths);
55+
pub fn with_dependencies(mut self, mut asset_paths: Vec<AssetPath<'static>>) -> Self {
56+
for asset_path in asset_paths.drain(..) {
57+
self.add_dependency(asset_path);
58+
}
5359
self
5460
}
5561
}

crates/bevy_derive/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ mod render_resource;
99
mod render_resources;
1010
mod shader_defs;
1111

12+
use bevy_macro_utils::{derive_label, BevyManifest};
1213
use proc_macro::TokenStream;
14+
use quote::format_ident;
1315

1416
/// Derives the Bytes trait. Each field must also implements Bytes or this will fail.
1517
#[proc_macro_derive(Bytes)]
@@ -52,3 +54,11 @@ pub fn bevy_main(attr: TokenStream, item: TokenStream) -> TokenStream {
5254
pub fn derive_enum_variant_meta(input: TokenStream) -> TokenStream {
5355
enum_variant_meta::derive_enum_variant_meta(input)
5456
}
57+
58+
#[proc_macro_derive(AppLabel)]
59+
pub fn derive_app_label(input: TokenStream) -> TokenStream {
60+
let input = syn::parse_macro_input!(input as syn::DeriveInput);
61+
let mut trait_path = BevyManifest::default().get_path("bevy_app");
62+
trait_path.segments.push(format_ident!("AppLabel").into());
63+
derive_label(input, trait_path)
64+
}

0 commit comments

Comments
 (0)