Skip to content

Commit

Permalink
Text pipeline benchmark (bevyengine#7845)
Browse files Browse the repository at this point in the history
# Objective

Simple text pipeline benchmark. It's quite expensive but current examples don't capture the performance of `queue_text` as it only runs on changes to the text.
  • Loading branch information
ickshonpe authored and Shfty committed Mar 19, 2023
1 parent 41f56d3 commit 4b6f822
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,6 @@ description = "A shader that uses the various textures generated by the prepass"
category = "Shaders"
wasm = false


[[example]]
name = "shader_material_screenspace_texture"
path = "examples/shader/shader_material_screenspace_texture.rs"
Expand Down Expand Up @@ -1584,6 +1583,16 @@ description = "Various test cases for hierarchy and transform propagation perfor
category = "Stress Tests"
wasm = true

[[example]]
name = "text_pipeline"
path = "examples/stress_tests/text_pipeline.rs"

[package.metadata.example.text_pipeline]
name = "Text Pipeline"
description = "Text Pipeline benchmark"
category = "Stress Tests"
wasm = false

# Tools
[[example]]
name = "scene_viewer"
Expand Down Expand Up @@ -1726,7 +1735,6 @@ description = "Demonstrates how the AlignItems and JustifyContent properties can
category = "UI (User Interface)"
wasm = false


[[example]]
name = "transparency_ui"
path = "examples/ui/transparency_ui.rs"
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ Example | Description
[Many Foxes](../examples/stress_tests/many_foxes.rs) | Loads an animated fox model and spawns lots of them. Good for testing skinned mesh performance. Takes an unsigned integer argument for the number of foxes to spawn. Defaults to 1000
[Many Lights](../examples/stress_tests/many_lights.rs) | Simple benchmark to test rendering many point lights. Run with `WGPU_SETTINGS_PRIO=webgl2` to restrict to uniform buffers and max 256 lights
[Many Sprites](../examples/stress_tests/many_sprites.rs) | Displays many sprites in a grid arrangement! Used for performance testing. Use `--colored` to enable color tinted sprites.
[Text Pipeline](../examples/stress_tests/text_pipeline.rs) | Text Pipeline benchmark
[Transform Hierarchy](../examples/stress_tests/transform_hierarchy.rs) | Various test cases for hierarchy and transform propagation performance

## Tools
Expand Down
68 changes: 68 additions & 0 deletions examples/stress_tests/text_pipeline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Text pipeline benchmark.
//!
//! Continuously recomputes a large `Text` component with 100 sections.

use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
text::{BreakLineOn, Text2dBounds},
window::{PresentMode, WindowPlugin},
};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
..default()
}),
..default()
}))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_startup_system(spawn)
.add_system(update_text_bounds)
.run();
}

fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
let sections = (1..=50)
.flat_map(|i| {
[
TextSection {
value: "text".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: (4 + i % 10) as f32,
color: Color::BLUE,
},
},
TextSection {
value: "pipeline".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: (4 + i % 11) as f32,
color: Color::YELLOW,
},
},
]
})
.collect::<Vec<_>>();
commands.spawn(Text2dBundle {
text: Text {
sections,
alignment: TextAlignment::Center,
linebreak_behaviour: BreakLineOn::AnyCharacter,
},
..Default::default()
});
}

// changing the bounds of the text will cause a recomputation
fn update_text_bounds(time: Res<Time>, mut text_bounds_query: Query<&mut Text2dBounds>) {
let width = (1. + time.elapsed_seconds().sin()) * 600.0;
for mut text_bounds in text_bounds_query.iter_mut() {
text_bounds.size.x = width;
}
}

0 comments on commit 4b6f822

Please sign in to comment.