From 268b87df5f875e0f020793de617dc37c547ef324 Mon Sep 17 00:00:00 2001 From: Sycrosity <72102935+Sycrosity@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:30:28 +0200 Subject: [PATCH] feat: added a render graph visualiser --- Cargo.lock | 16 ++++++++++ Cargo.toml | 3 ++ bacon.toml | 11 +++++++ src/main.rs | 17 +++++------ src/utils.rs | 84 +++++++++++++++++++++++++++------------------------- 5 files changed, 82 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5eac1d1..8c1e76a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -866,6 +866,21 @@ dependencies = [ "glam 0.24.1", ] +[[package]] +name = "bevy_mod_debugdump" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8e56ca0ed565ddc8c2507e105a63c277a5671bb5b27e3130ea8e138be18050" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_render", + "bevy_utils", + "once_cell", + "petgraph", + "pretty-type-name", +] + [[package]] name = "bevy_pbr" version = "0.11.0" @@ -2330,6 +2345,7 @@ dependencies = [ "bevy", "bevy-inspector-egui", "bevy_asset_loader", + "bevy_mod_debugdump", "bevy_rapier2d", "indexmap 2.0.0", "leafwing-input-manager", diff --git a/Cargo.toml b/Cargo.toml index d6cbd22..3fd0c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,8 @@ bevy_rapier2d = { version = "0.22.0", features = ["serde-serialize", "debug-rend bevy_asset_loader = { version = "0.17.0", features = ["2d", "standard_dynamic_assets"] } #handling inputs in a logical, extensible way with options for command combinations or aliases. leafwing-input-manager = "0.10.0" +#used for debugging the render pipeline +bevy_mod_debugdump = { version = "0.8.0", optional = true } #(ser)ialising/(de)serialising library serde = "1" @@ -51,6 +53,7 @@ default = [] dynamic_linking = ["bevy/dynamic_linking"] ci_testing = ["bevy/bevy_ci_testing"] +render_graph = ["bevy_mod_debugdump"] # long_description diff --git a/bacon.toml b/bacon.toml index c8ad3ab..e58065a 100644 --- a/bacon.toml +++ b/bacon.toml @@ -79,6 +79,15 @@ command = [ need_stdout = true allow_warnings = true +[jobs.render_graph] +command = [ + "zsh", "-c", "cargo build --features render_graph && cargo run --color always --features render_graph | dot -Tsvg -o render_graph.svg && /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome `readlink -f render_graph.svg`" + + # put launch parameters for your program behind a `--` separator +] +need_stdout = true +allow_warnings = true + [jobs.fast-compile] command = [ "cargo", "run", @@ -99,3 +108,5 @@ shift-r = "job:fast-compile" b = "job:build" f = "job:fmt" shift-f = "job:clippy-fix" +shift-b = "job:build-fast-compile" +g = "job:render_graph" diff --git a/src/main.rs b/src/main.rs index 9a90981..3e8cbfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,9 @@ use galaxy::prelude::*; fn main() { - App::new() - .insert_resource(ClearColor(Color::BLACK)) + let mut app = App::new(); + app.insert_resource(ClearColor(Color::BLACK)) .add_state::() - .insert_resource(bevy::winit::WinitSettings { - focused_mode: bevy::winit::UpdateMode::Continuous, - unfocused_mode: bevy::winit::UpdateMode::ReactiveLowPower { - max_wait: bevy::utils::Duration::from_millis(1000), - }, - ..default() - }) .add_plugins(GalaxyDefaultPlugins) .add_plugins(( GalaxyDebugPlugin, @@ -20,4 +13,10 @@ fn main() { GalaxyGamePlugin, GalaxyShaderPlugin, )); + + #[cfg(feature = "render_graph")] + bevy_mod_debugdump::print_schedule_graph(&mut app, PreUpdate); + + #[cfg(not(feature = "render_graph"))] + app.run(); } diff --git a/src/utils.rs b/src/utils.rs index 6b5a908..6f86f9b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -31,48 +31,52 @@ pub fn teardown( pub struct GalaxyDefaultPlugins; impl Plugin for GalaxyDefaultPlugins { - fn build(&self, app: &mut App) { - app.add_plugins( - DefaultPlugins - .set(WindowPlugin { - primary_window: Some(Window { - title: "Cosmic Crew: Galaxy".to_string(), - fit_canvas_to_parent: true, - ..default() - }), + fn build(&self, mut app: &mut App) { + let mut default_plugins = DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "Cosmic Crew: Galaxy".to_string(), + fit_canvas_to_parent: true, ..default() - }) - .set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), - asset_folder: { - if cfg!(all( - target_os = "macos", - not(debug_assertions), - not(features = "dynamic_linking") - )) { - "../Resources/assets".to_string() - } else { - "assets".to_string() - } - }, - }) - .set({ - use bevy::log::LogPlugin; - if cfg!(debug_assertions) { - LogPlugin { - level: bevy::log::Level::DEBUG, - filter: "debug,wgpu_core=warn,wgpu_hal=warn,naga=info,bevy=info".into(), - } + }), + ..default() + }) + .set(AssetPlugin { + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), + asset_folder: { + if cfg!(all( + target_os = "macos", + not(debug_assertions), + not(features = "dynamic_linking") + )) { + "../Resources/assets".to_string() } else { - // this code is compiled only if debug assertions are disabled (release - // mode) - LogPlugin { - level: bevy::log::Level::INFO, - filter: "info,wgpu_core=warn,wgpu_hal=warn".into(), - } + "assets".to_string() } - }) - .set(ImagePlugin::default_nearest()), - ); + }, + }) + .set({ + use bevy::log::LogPlugin; + if cfg!(debug_assertions) { + LogPlugin { + level: bevy::log::Level::DEBUG, + filter: "debug,wgpu_core=warn,wgpu_hal=warn,naga=info,bevy=info".into(), + } + } else { + // this code is compiled only if debug assertions are disabled (release + // mode) + LogPlugin { + level: bevy::log::Level::INFO, + filter: "info,wgpu_core=warn,wgpu_hal=warn".into(), + } + } + }) + .set(ImagePlugin::default_nearest()); + + if cfg!(feature = "render_graph") { + default_plugins = default_plugins.disable::(); + } + + app.add_plugins(default_plugins); } }