mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Text pipeline benchmark (#7845)
# 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.
This commit is contained in:
parent
30b29deaa9
commit
465fff2b01
3 changed files with 79 additions and 2 deletions
12
Cargo.toml
12
Cargo.toml
|
@ -1420,7 +1420,6 @@ description = "A shader that uses the various textures generated by the prepass"
|
||||||
category = "Shaders"
|
category = "Shaders"
|
||||||
wasm = false
|
wasm = false
|
||||||
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "shader_material_screenspace_texture"
|
name = "shader_material_screenspace_texture"
|
||||||
path = "examples/shader/shader_material_screenspace_texture.rs"
|
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"
|
category = "Stress Tests"
|
||||||
wasm = true
|
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
|
# Tools
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "scene_viewer"
|
name = "scene_viewer"
|
||||||
|
@ -1726,7 +1735,6 @@ description = "Demonstrates how the AlignItems and JustifyContent properties can
|
||||||
category = "UI (User Interface)"
|
category = "UI (User Interface)"
|
||||||
wasm = false
|
wasm = false
|
||||||
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "transparency_ui"
|
name = "transparency_ui"
|
||||||
path = "examples/ui/transparency_ui.rs"
|
path = "examples/ui/transparency_ui.rs"
|
||||||
|
|
|
@ -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 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 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.
|
[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
|
[Transform Hierarchy](../examples/stress_tests/transform_hierarchy.rs) | Various test cases for hierarchy and transform propagation performance
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
68
examples/stress_tests/text_pipeline.rs
Normal file
68
examples/stress_tests/text_pipeline.rs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue