Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmark #577

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions bevy_rapier_benches3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
visual = [
"bevy/x11",
"bevy/tonemapping_luts",
"bevy/bevy_asset",
"bevy/bevy_scene",
"bevy/bevy_core_pipeline",
"bevy/bevy_pbr",
"bevy/bevy_gizmos",
"rapier3d/debug-render",
"bevy/bevy_asset",
]

[dependencies]
rapier3d = { features = ["profiler"], version = "0.22" }
bevy_rapier3d = { version = "0.27", path = "../bevy_rapier3d" }
bevy = { version = "0.14", default-features = false }
rapier3d = { features = ["profiler"], version = "0.22" }
Copy link
Member

@sebcrozet sebcrozet Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me that I’d like to revisit that profiler thing in rapier to switch so something less manual. Like switching the tracy or something. (This is unrelated to this PR though.)

bevy_rapier3d = { version = "0.27", path = "../bevy_rapier3d", default-features = false }
2 changes: 1 addition & 1 deletion bevy_rapier_benches3d/src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn pyramid_1_with_height_2() {
}

fn pyramid_2_with_height_20() {
custom_bencher(100, |app| setup_pyramids(app, 3, 20));
custom_bencher(100, |app| setup_pyramids(app, 40, 20));
}

fn main() {
Expand Down
31 changes: 31 additions & 0 deletions bevy_rapier_benches3d/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::{
app::PluginsState,
log::LogPlugin,
prelude::*,
render::{
settings::{RenderCreation, WgpuSettings},
Expand All @@ -10,6 +11,7 @@ use bevy::{
};
use bevy_rapier3d::prelude::*;

#[cfg(not(feature = "visual"))]
pub fn default_app() -> App {
let mut app = App::new();

Expand All @@ -18,6 +20,7 @@ pub fn default_app() -> App {
MinimalPlugins,
AssetPlugin::default(),
ScenePlugin,
LogPlugin::default(),
RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: None,
Expand All @@ -38,6 +41,34 @@ pub fn default_app() -> App {
app
}

#[cfg(feature = "visual")]
pub fn default_app() -> App {
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};

let mut app = App::new();
println!("visual mode!");
app.insert_resource(ClearColor(Color::srgb(
0xF9 as f32 / 255.0,
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)));
app.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<()>::default(),
RapierDebugRenderPlugin::default(),
FrameTimeDiagnosticsPlugin::default(),
LogDiagnosticsPlugin::default(),
));
app.add_systems(Startup, |mut commands: Commands| {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-30.0, 30.0, 100.0)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
..Default::default()
});
});
app
}

pub fn wait_app_start(app: &mut App) {
while app.plugins_state() != PluginsState::Ready {
bevy::tasks::tick_global_task_pools_on_main_thread();
Expand Down
5 changes: 5 additions & 0 deletions bevy_rapier_benches3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use bevy_rapier3d::plugin::RapierContext;
pub fn custom_bencher(steps: usize, setup: impl Fn(&mut App)) {
let mut app = default_app();
setup(&mut app);
#[cfg(feature = "visual")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add explaination to readme

{
app.run();
return;
}
wait_app_start(&mut app);

let mut timer_total = rapier3d::counters::Timer::new();
Expand Down
7 changes: 5 additions & 2 deletions bevy_rapier_benches3d/src/pyramids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ pub fn create_pyramid(commands: &mut Commands, offset: Vect, stack_height: usize
// Build the rigid body.
commands.spawn((
RigidBody::Dynamic,
Transform::from_translation(Vec3::new(x, y, 0.0) + offset),
Collider::cuboid(1.0, 1.0, 1.0),
SpatialBundle::from_transform(Transform::from_translation(
Vec3::new(x, y, 0.0) + offset,
)),
Collider::cuboid(rad, rad, rad),
));
}
}
Expand Down Expand Up @@ -47,6 +49,7 @@ pub fn setup_pyramids(app: &mut App, pyramid_count: usize, stack_height: usize)
/*
* Create the pyramids
*/

for pyramid_index in 0..pyramid_count {
let bottomy = rad;
create_pyramid(
Expand Down