Fix CI problems

This commit is contained in:
Tyler Critchlow 2025-07-14 23:17:24 -04:00
parent 1b1af05b59
commit 60dd402088
3 changed files with 76 additions and 42 deletions

View File

@ -656,27 +656,35 @@ struct UiGradientVertex {
fn convert_color_to_space(color: LinearRgba, space: InterpolationColorSpace) -> [f32; 4] {
match space {
InterpolationColorSpace::OkLab => {
InterpolationColorSpace::Oklaba => {
let oklaba: Oklaba = color.into();
[oklaba.lightness, oklaba.a, oklaba.b, oklaba.alpha]
}
InterpolationColorSpace::OkLch | InterpolationColorSpace::OkLchLong => {
InterpolationColorSpace::Oklcha | InterpolationColorSpace::OklchaLong => {
let oklcha: Oklcha = color.into();
[oklcha.lightness, oklcha.chroma, oklcha.hue.to_radians(), oklcha.alpha]
[
oklcha.lightness,
oklcha.chroma,
oklcha.hue.to_radians(),
oklcha.alpha,
]
}
InterpolationColorSpace::Srgb => {
InterpolationColorSpace::Srgba => {
let srgba: Srgba = color.into();
[srgba.red, srgba.green, srgba.blue, srgba.alpha]
}
InterpolationColorSpace::LinearRgb => {
color.to_f32_array()
}
InterpolationColorSpace::Hsl | InterpolationColorSpace::HslLong => {
InterpolationColorSpace::LinearRgba => color.to_f32_array(),
InterpolationColorSpace::Hsla | InterpolationColorSpace::HslaLong => {
let hsla: Hsla = color.into();
// Normalize hue to 0..1 range for shader
[hsla.hue / 360.0, hsla.saturation, hsla.lightness, hsla.alpha]
[
hsla.hue / 360.0,
hsla.saturation,
hsla.lightness,
hsla.alpha,
]
}
InterpolationColorSpace::Hsv | InterpolationColorSpace::HsvLong => {
InterpolationColorSpace::Hsva | InterpolationColorSpace::HsvaLong => {
let hsva: Hsva = color.into();
// Normalize hue to 0..1 range for shader
[hsva.hue / 360.0, hsva.saturation, hsva.value, hsva.alpha]
@ -834,7 +842,8 @@ pub fn prepare_gradient(
continue;
}
}
let start_color = convert_color_to_space(start_stop.0, gradient.color_space);
let start_color =
convert_color_to_space(start_stop.0, gradient.color_space);
let end_color = convert_color_to_space(end_stop.0, gradient.color_space);
let mut stop_flags = flags;
if 0. < start_stop.1

View File

@ -510,6 +510,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 Gizmos](../examples/stress_tests/many_gizmos.rs) | Test rendering of many gizmos
[Many Glyphs](../examples/stress_tests/many_glyphs.rs) | Simple benchmark to test text rendering.
[Many Gradients](../examples/stress_tests/many_gradients.rs) | Stress test for gradient rendering performance
[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 Text2d](../examples/stress_tests/many_text2d.rs) | Displays many Text2d! Used for performance testing.

View File

@ -1,5 +1,5 @@
//! Stress test demonstrating gradient performance improvements.
//!
//!
//! This example creates many UI nodes with gradients to measure the performance
//! impact of pre-converting colors to the target color space on the CPU.
@ -8,7 +8,10 @@ use bevy::{
color::palettes::css::*,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
ui::{BackgroundGradient, LinearGradient, ColorStop, Gradient, RepeatedGridTrack, Display, InterpolationColorSpace},
ui::{
BackgroundGradient, ColorStop, Display, Gradient, InterpolationColorSpace, LinearGradient,
RepeatedGridTrack,
},
window::{PresentMode, WindowResolution},
};
@ -26,7 +29,7 @@ struct Args {
animate: bool,
/// use sRGB interpolation
#[argh(switch)]
#[argh(switch)]
srgb: bool,
/// use HSL interpolation
@ -37,15 +40,18 @@ struct Args {
fn main() {
let args: Args = argh::from_env();
let total_gradients = args.gradient_count;
println!("Gradient stress test with {} gradients", total_gradients);
println!("Color space: {}", if args.srgb {
"sRGB"
} else if args.hsl {
"HSL"
} else {
"OkLab (default)"
});
println!(
"Color space: {}",
if args.srgb {
"sRGB"
} else if args.hsl {
"HSL"
} else {
"OkLab (default)"
}
);
App::new()
.add_plugins((
@ -85,17 +91,20 @@ fn setup(mut commands: Commands, args: Res<Args>) {
.with_children(|parent| {
for i in 0..args.gradient_count {
let angle = (i as f32 * 10.0) % 360.0;
let mut gradient = LinearGradient::new(angle, vec![
ColorStop::new(RED, Val::Percent(0.0)),
ColorStop::new(BLUE, Val::Percent(100.0)),
ColorStop::new(GREEN, Val::Percent(20.0)),
ColorStop::new(YELLOW, Val::Percent(40.0)),
ColorStop::new(ORANGE, Val::Percent(60.0)),
ColorStop::new(LIME, Val::Percent(80.0)),
ColorStop::new(DARK_CYAN, Val::Percent(90.0)),
]);
let mut gradient = LinearGradient::new(
angle,
vec![
ColorStop::new(RED, Val::Percent(0.0)),
ColorStop::new(BLUE, Val::Percent(100.0)),
ColorStop::new(GREEN, Val::Percent(20.0)),
ColorStop::new(YELLOW, Val::Percent(40.0)),
ColorStop::new(ORANGE, Val::Percent(60.0)),
ColorStop::new(LIME, Val::Percent(80.0)),
ColorStop::new(DARK_CYAN, Val::Percent(90.0)),
],
);
gradient.color_space = if args.srgb {
InterpolationColorSpace::Srgb
} else if args.hsl {
@ -132,24 +141,39 @@ fn animate_gradients(
}
let t = time.elapsed_secs();
for (mut bg_gradient, node) in &mut gradients {
let offset = node.index as f32 * 0.01;
let hue_shift = (t + offset).sin() * 0.5 + 0.5;
if let Some(Gradient::Linear(gradient)) = bg_gradient.0.get_mut(0) {
let color1 = Color::hsl(hue_shift * 360.0, 1.0, 0.5);
let color2 = Color::hsl((hue_shift + 0.3) * 360.0 % 360.0, 1.0, 0.5);
gradient.stops = vec![
ColorStop::new(color1, Val::Percent(0.0)),
ColorStop::new(color2, Val::Percent(100.0)),
ColorStop::new(Color::hsl((hue_shift + 0.1) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(20.0)),
ColorStop::new(Color::hsl((hue_shift + 0.15) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(40.0)),
ColorStop::new(Color::hsl((hue_shift + 0.2) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(60.0)),
ColorStop::new(Color::hsl((hue_shift + 0.25) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(80.0)),
ColorStop::new(Color::hsl((hue_shift + 0.28) * 360.0 % 360.0, 1.0, 0.5), Val::Percent(90.0)),
ColorStop::new(
Color::hsl((hue_shift + 0.1) * 360.0 % 360.0, 1.0, 0.5),
Val::Percent(20.0),
),
ColorStop::new(
Color::hsl((hue_shift + 0.15) * 360.0 % 360.0, 1.0, 0.5),
Val::Percent(40.0),
),
ColorStop::new(
Color::hsl((hue_shift + 0.2) * 360.0 % 360.0, 1.0, 0.5),
Val::Percent(60.0),
),
ColorStop::new(
Color::hsl((hue_shift + 0.25) * 360.0 % 360.0, 1.0, 0.5),
Val::Percent(80.0),
),
ColorStop::new(
Color::hsl((hue_shift + 0.28) * 360.0 % 360.0, 1.0, 0.5),
Val::Percent(90.0),
),
];
}
}
}
}