From 2ad12c3c3bacdf4863ddac0d9c486f912a75f844 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 20 Sep 2023 10:52:42 -0700 Subject: [PATCH 1/6] Add random z option for bevymark --- examples/stress_tests/bevymark.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/stress_tests/bevymark.rs b/examples/stress_tests/bevymark.rs index 4e2670ecabd9d..0c200ab5382e6 100644 --- a/examples/stress_tests/bevymark.rs +++ b/examples/stress_tests/bevymark.rs @@ -60,6 +60,10 @@ struct Args { /// the number of different textures from which to randomly select the material color. 0 means no textures. #[argh(option, default = "1")] material_texture_count: usize, + + /// use a random rather than sequential z value for birds + #[argh(switch)] + random_z: bool, } #[derive(Default, Clone)] @@ -163,6 +167,7 @@ struct BirdResources { color_rng: StdRng, material_rng: StdRng, velocity_rng: StdRng, + transform_rng: StdRng, } #[derive(Component)] @@ -204,6 +209,7 @@ fn setup( color_rng: StdRng::seed_from_u64(42), material_rng: StdRng::seed_from_u64(42), velocity_rng: StdRng::seed_from_u64(42), + transform_rng: StdRng::seed_from_u64(42), }; let text_section = move |color, value: &str| { @@ -360,7 +366,12 @@ fn spawn_birds( Mode::Sprite => { let batch = (0..spawn_count) .map(|count| { - let bird_z = (current_count + count) as f32 * 0.00001; + let bird_z = if args.random_z { + bird_resources.transform_rng.gen::() + } else { + (current_count + count) as f32 * 0.00001 + }; + let (transform, velocity) = bird_velocity_transform( half_extents, Vec3::new(bird_x, bird_y, bird_z), @@ -398,7 +409,12 @@ fn spawn_birds( Mode::Mesh2d => { let batch = (0..spawn_count) .map(|count| { - let bird_z = (current_count + count) as f32 * 0.00001; + let bird_z = if args.random_z { + bird_resources.transform_rng.gen::() + } else { + (current_count + count) as f32 * 0.00001 + }; + let (transform, velocity) = bird_velocity_transform( half_extents, Vec3::new(bird_x, bird_y, bird_z), From 24168617cec81c26d9b7bd35c8997db38dff9d83 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 20 Sep 2023 10:53:05 -0700 Subject: [PATCH 2/6] Use radsort for transparent2d phase items --- crates/bevy_core_pipeline/src/core_2d/mod.rs | 2 +- crates/bevy_sprite/Cargo.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_core_pipeline/src/core_2d/mod.rs b/crates/bevy_core_pipeline/src/core_2d/mod.rs index 49f4260b203fc..4a61cccc3ba75 100644 --- a/crates/bevy_core_pipeline/src/core_2d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_2d/mod.rs @@ -106,7 +106,7 @@ impl PhaseItem for Transparent2d { #[inline] fn sort(items: &mut [Self]) { - items.sort_by_key(|item| item.sort_key()); + radsort::sort_by_key(items, |item| item.sort_key().0); } #[inline] diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 37db1b9eb2a20..f2eefe424b2cc 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -31,3 +31,4 @@ guillotiere = "0.6.0" thiserror = "1.0" rectangle-pack = "0.4" bitflags = "2.3" +radsort = "0.1" \ No newline at end of file From dc26073777c86cc93ebd3950f7dcf8913416fa6e Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 20 Sep 2023 18:14:20 -0700 Subject: [PATCH 3/6] Fix lack of newline at end of file Co-authored-by: Alice Cecile --- crates/bevy_sprite/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index f2eefe424b2cc..649dc42345036 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -31,4 +31,4 @@ guillotiere = "0.6.0" thiserror = "1.0" rectangle-pack = "0.4" bitflags = "2.3" -radsort = "0.1" \ No newline at end of file +radsort = "0.1" From 4c112d4b11936a49bf508856bf6f7befa136d2a7 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 21 Sep 2023 09:18:07 -0700 Subject: [PATCH 4/6] Make random z the default --- examples/stress_tests/bevymark.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/stress_tests/bevymark.rs b/examples/stress_tests/bevymark.rs index 0c200ab5382e6..cd8c1ad77f3c2 100644 --- a/examples/stress_tests/bevymark.rs +++ b/examples/stress_tests/bevymark.rs @@ -61,9 +61,9 @@ struct Args { #[argh(option, default = "1")] material_texture_count: usize, - /// use a random rather than sequential z value for birds + /// generate z values in increasing order rather than randomly #[argh(switch)] - random_z: bool, + ordered_z: bool, } #[derive(Default, Clone)] @@ -366,10 +366,10 @@ fn spawn_birds( Mode::Sprite => { let batch = (0..spawn_count) .map(|count| { - let bird_z = if args.random_z { - bird_resources.transform_rng.gen::() - } else { + let bird_z = if args.ordered_z { (current_count + count) as f32 * 0.00001 + } else { + bird_resources.transform_rng.gen::() }; let (transform, velocity) = bird_velocity_transform( @@ -409,10 +409,10 @@ fn spawn_birds( Mode::Mesh2d => { let batch = (0..spawn_count) .map(|count| { - let bird_z = if args.random_z { - bird_resources.transform_rng.gen::() - } else { + let bird_z = if args.ordered_z { (current_count + count) as f32 * 0.00001 + } else { + bird_resources.transform_rng.gen::() }; let (transform, velocity) = bird_velocity_transform( From 690c5023960c805d180b217891b89090409b0190 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 21 Sep 2023 09:22:21 -0700 Subject: [PATCH 5/6] Add comment Co-authored-by: Robert Swain --- crates/bevy_core_pipeline/src/core_2d/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_core_pipeline/src/core_2d/mod.rs b/crates/bevy_core_pipeline/src/core_2d/mod.rs index 4a61cccc3ba75..bc6c19818861f 100644 --- a/crates/bevy_core_pipeline/src/core_2d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_2d/mod.rs @@ -106,6 +106,7 @@ impl PhaseItem for Transparent2d { #[inline] fn sort(items: &mut [Self]) { + // radsort is a stable radix sort that performed better than .sort_by_key() or .sort_unstable_by_key() radsort::sort_by_key(items, |item| item.sort_key().0); } From 72c7d2d63e0c83456eec4e2fdf5cc76a735c4dcc Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 21 Sep 2023 09:23:34 -0700 Subject: [PATCH 6/6] More specific comment --- crates/bevy_core_pipeline/src/core_2d/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_core_pipeline/src/core_2d/mod.rs b/crates/bevy_core_pipeline/src/core_2d/mod.rs index bc6c19818861f..084205ee24752 100644 --- a/crates/bevy_core_pipeline/src/core_2d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_2d/mod.rs @@ -106,7 +106,7 @@ impl PhaseItem for Transparent2d { #[inline] fn sort(items: &mut [Self]) { - // radsort is a stable radix sort that performed better than .sort_by_key() or .sort_unstable_by_key() + // radsort is a stable radix sort that performed better than `slice::sort_by_key` or `slice::sort_unstable_by_key`. radsort::sort_by_key(items, |item| item.sort_key().0); }