Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use radsort for Transparent2d PhaseItem sorting #9882

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
rparrett marked this conversation as resolved.
Show resolved Hide resolved
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ guillotiere = "0.6.0"
thiserror = "1.0"
rectangle-pack = "0.4"
bitflags = "2.3"
radsort = "0.1"
20 changes: 18 additions & 2 deletions examples/stress_tests/bevymark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
rparrett marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Default, Clone)]
Expand Down Expand Up @@ -163,6 +167,7 @@ struct BirdResources {
color_rng: StdRng,
material_rng: StdRng,
velocity_rng: StdRng,
transform_rng: StdRng,
}

#[derive(Component)]
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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::<f32>()
} else {
(current_count + count) as f32 * 0.00001
};

let (transform, velocity) = bird_velocity_transform(
half_extents,
Vec3::new(bird_x, bird_y, bird_z),
Expand Down Expand Up @@ -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::<f32>()
} else {
(current_count + count) as f32 * 0.00001
};

let (transform, velocity) = bird_velocity_transform(
half_extents,
Vec3::new(bird_x, bird_y, bird_z),
Expand Down
Loading