Skip to content

Commit

Permalink
Merge pull request #3175 from cart/merge-renderer
Browse files Browse the repository at this point in the history
Merge New Renderer
  • Loading branch information
cart authored Nov 24, 2021
2 parents 94db017 + 8009af3 commit 0bf90bb
Show file tree
Hide file tree
Showing 194 changed files with 24,520 additions and 326 deletions.
75 changes: 73 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ repository = "https://github.com/bevyengine/bevy"

[workspace]
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
members = ["crates/*", "examples/ios", "tools/ci", "errors"]
members = ["crates/*", "pipelined/*", "examples/ios", "tools/ci", "errors"]

[features]
default = [
"bevy_audio",
"bevy_core_pipeline",
"bevy_gilrs",
"bevy_gltf",
"bevy_gltf2",
"bevy_wgpu",
"bevy_sprite2",
"bevy_render2",
"bevy_pbr2",
"bevy_winit",
"render",
"png",
Expand Down Expand Up @@ -50,6 +54,12 @@ bevy_gltf = ["bevy_internal/bevy_gltf"]
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
bevy_winit = ["bevy_internal/bevy_winit"]

bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
bevy_render2 = ["bevy_internal/bevy_render2"]
bevy_sprite2 = ["bevy_internal/bevy_sprite2"]
bevy_pbr2 = ["bevy_internal/bevy_pbr2"]
bevy_gltf2 = ["bevy_internal/bevy_gltf2"]

trace_chrome = ["bevy_internal/trace_chrome"]
trace_tracy = ["bevy_internal/trace_tracy"]
trace = ["bevy_internal/trace"]
Expand Down Expand Up @@ -95,6 +105,7 @@ ron = "0.6.2"
serde = { version = "1", features = ["derive"] }
# Needed to poll Task examples
futures-lite = "1.11.3"
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }

[[example]]
name = "hello_world"
Expand Down Expand Up @@ -133,23 +144,51 @@ path = "examples/2d/text2d.rs"
name = "texture_atlas"
path = "examples/2d/texture_atlas.rs"

[[example]]
name = "pipelined_texture_atlas"
path = "examples/2d/pipelined_texture_atlas.rs"

# 3D Rendering
[[example]]
name = "3d_scene"
path = "examples/3d/3d_scene.rs"

[[example]]
name = "3d_scene_pipelined"
path = "examples/3d/3d_scene_pipelined.rs"

[[example]]
name = "many_cubes_pipelined"
path = "examples/3d/many_cubes_pipelined.rs"

[[example]]
name = "cornell_box_pipelined"
path = "examples/3d/cornell_box_pipelined.rs"

[[example]]
name = "load_gltf"
path = "examples/3d/load_gltf.rs"

[[example]]
name = "load_gltf_pipelined"
path = "examples/3d/load_gltf_pipelined.rs"

[[example]]
name = "msaa"
path = "examples/3d/msaa.rs"

[[example]]
name = "msaa_pipelined"
path = "examples/3d/msaa_pipelined.rs"

[[example]]
name = "orthographic"
path = "examples/3d/orthographic.rs"

[[example]]
name = "orthographic_pipelined"
path = "examples/3d/orthographic_pipelined.rs"

[[example]]
name = "parenting"
path = "examples/3d/parenting.rs"
Expand All @@ -158,10 +197,22 @@ path = "examples/3d/parenting.rs"
name = "pbr"
path = "examples/3d/pbr.rs"

[[example]]
name = "pbr_pipelined"
path = "examples/3d/pbr_pipelined.rs"

[[example]]
name = "render_to_texture"
path = "examples/3d/render_to_texture.rs"

[[example]]
name = "shadow_biases_pipelined"
path = "examples/3d/shadow_biases_pipelined.rs"

[[example]]
name = "shadow_caster_receiver_pipelined"
path = "examples/3d/shadow_caster_receiver_pipelined.rs"

[[example]]
name = "spawner"
path = "examples/3d/spawner.rs"
Expand All @@ -170,6 +221,10 @@ path = "examples/3d/spawner.rs"
name = "texture"
path = "examples/3d/texture.rs"

[[example]]
name = "texture_pipelined"
path = "examples/3d/texture_pipelined.rs"

[[example]]
name = "update_gltf_scene"
path = "examples/3d/update_gltf_scene.rs"
Expand Down Expand Up @@ -413,11 +468,23 @@ path = "examples/shader/shader_custom_material.rs"
name = "shader_defs"
path = "examples/shader/shader_defs.rs"

[[example]]
name = "custom_shader_pipelined"
path = "examples/shader/custom_shader_pipelined.rs"

[[example]]
name = "shader_defs_pipelined"
path = "examples/shader/shader_defs_pipelined.rs"

# Tools
[[example]]
name = "bevymark"
path = "examples/tools/bevymark.rs"

[[example]]
name = "bevymark_pipelined"
path = "examples/tools/bevymark_pipelined.rs"

# UI (User Interface)
[[example]]
name = "button"
Expand All @@ -444,6 +511,10 @@ path = "examples/ui/ui.rs"
name = "clear_color"
path = "examples/window/clear_color.rs"

[[example]]
name = "clear_color_pipelined"
path = "examples/window/clear_color_pipelined.rs"

[[example]]
name = "multiple_windows"
path = "examples/window/multiple_windows.rs"
Expand Down
11 changes: 11 additions & 0 deletions assets/shaders/custom_material.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[block]]
struct CustomMaterial {
color: vec4<f32>;
};
[[group(1), binding(0)]]
var<uniform> material: CustomMaterial;

[[stage(fragment)]]
fn fragment() -> [[location(0)]] vec4<f32> {
return material.color;
}
33 changes: 33 additions & 0 deletions assets/shaders/shader_defs.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#import bevy_pbr::mesh_view_bind_group
#import bevy_pbr::mesh_struct

[[group(1), binding(0)]]
var<uniform> mesh: Mesh;

struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
};

[[stage(vertex)]]
fn vertex(vertex: Vertex) -> VertexOutput {
let world_position = mesh.model * vec4<f32>(vertex.position, 1.0);

var out: VertexOutput;
out.clip_position = view.view_proj * world_position;
return out;
}

[[stage(fragment)]]
fn fragment() -> [[location(0)]] vec4<f32> {
var color = vec4<f32>(0.0, 0.0, 1.0, 1.0);
# ifdef IS_RED
color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
# endif
return color;
}
48 changes: 47 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
prelude::{FromWorld, IntoExclusiveSystem},
schedule::{
Expand All @@ -8,12 +9,14 @@ use bevy_ecs::{
system::Resource,
world::World,
};
use bevy_utils::tracing::debug;
use bevy_utils::{tracing::debug, HashMap};
use std::fmt::Debug;

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

bevy_utils::define_label!(AppLabel);

#[allow(clippy::needless_doctest_main)]
/// Containers of app logic and data
///
Expand Down Expand Up @@ -42,6 +45,12 @@ pub struct App {
pub world: World,
pub runner: Box<dyn Fn(App)>,
pub schedule: Schedule,
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
}

struct SubApp {
app: App,
runner: Box<dyn Fn(&mut World, &mut App)>,
}

impl Default for App {
Expand Down Expand Up @@ -73,6 +82,7 @@ impl App {
world: Default::default(),
schedule: Default::default(),
runner: Box::new(run_once),
sub_apps: HashMap::default(),
}
}

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

/// Starts the application by calling the app's [runner function](Self::set_runner).
Expand Down Expand Up @@ -823,6 +836,39 @@ impl App {
}
self
}

pub fn add_sub_app(
&mut self,
label: impl AppLabel,
app: App,
f: impl Fn(&mut World, &mut App) + 'static,
) -> &mut Self {
self.sub_apps.insert(
Box::new(label),
SubApp {
app,
runner: Box::new(f),
},
);
self
}

/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App {
match self.get_sub_app(label) {
Ok(app) => app,
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
}
}

/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
/// an [Err] containing the given label.
pub fn get_sub_app(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> {
self.sub_apps
.get_mut((&label) as &dyn AppLabel)
.map(|sub_app| &mut sub_app.app)
.ok_or(label)
}
}

fn run_once(mut app: App) {
Expand Down
7 changes: 3 additions & 4 deletions crates/bevy_app/src/ci_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ fn ci_testing_exit_after(
*current_frame += 1;
}

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

app_builder
app
}
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<T: Asset> Handle<T> {
}
}

#[inline]
pub fn weak(id: HandleId) -> Self {
Self {
id,
Expand Down Expand Up @@ -129,6 +130,7 @@ impl<T: Asset> Handle<T> {
self.handle_type = HandleType::Strong(sender);
}

#[inline]
pub fn clone_weak(&self) -> Self {
Handle::weak(self.id)
}
Expand Down
12 changes: 9 additions & 3 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ impl<T: Asset> LoadedAsset<T> {
}
}

pub fn with_dependency(mut self, asset_path: AssetPath) -> Self {
pub fn add_dependency(&mut self, asset_path: AssetPath) {
self.dependencies.push(asset_path.to_owned());
}

pub fn with_dependency(mut self, asset_path: AssetPath) -> Self {
self.add_dependency(asset_path);
self
}

pub fn with_dependencies(mut self, asset_paths: Vec<AssetPath<'static>>) -> Self {
self.dependencies.extend(asset_paths);
pub fn with_dependencies(mut self, mut asset_paths: Vec<AssetPath<'static>>) -> Self {
for asset_path in asset_paths.drain(..) {
self.add_dependency(asset_path);
}
self
}
}
Expand Down
10 changes: 10 additions & 0 deletions crates/bevy_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ mod render_resource;
mod render_resources;
mod shader_defs;

use bevy_macro_utils::{derive_label, BevyManifest};
use proc_macro::TokenStream;
use quote::format_ident;

/// Derives the Bytes trait. Each field must also implements Bytes or this will fail.
#[proc_macro_derive(Bytes)]
Expand Down Expand Up @@ -52,3 +54,11 @@ pub fn bevy_main(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn derive_enum_variant_meta(input: TokenStream) -> TokenStream {
enum_variant_meta::derive_enum_variant_meta(input)
}

#[proc_macro_derive(AppLabel)]
pub fn derive_app_label(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input as syn::DeriveInput);
let mut trait_path = BevyManifest::default().get_path("bevy_app");
trait_path.segments.push(format_ident!("AppLabel").into());
derive_label(input, trait_path)
}
Loading

0 comments on commit 0bf90bb

Please sign in to comment.