diff --git a/Cargo.toml b/Cargo.toml index 655d62e12bb7e..90ec30987622d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" @@ -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" diff --git a/examples/README.md b/examples/README.md index 0a763363ff660..bc03d2382c372 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 diff --git a/examples/stress_tests/text_pipeline.rs b/examples/stress_tests/text_pipeline.rs new file mode 100644 index 0000000000000..a2782a97a9c36 --- /dev/null +++ b/examples/stress_tests/text_pipeline.rs @@ -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) { + 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::>(); + 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