Skip to content

Commit b6a2fc5

Browse files
authored
Improve execution of examples in CI (bevyengine#9331)
# Objective - Some examples crash in CI because of needing too many resources for the windows runner - Some examples have random results making it hard to compare screenshots ## Solution - `bloom_3d`: reduce the number of spheres - `pbr`: use simpler spheres and reuse the mesh - `tonemapping`: use simpler spheres and reuse the mesh - `shadow_biases`: reduce the number of spheres - `spotlight`: use a seeded rng, move more cubes in view while reducing the total number of cubes, and reuse meshes and materials - `external_source_external_thread`, `iter_combinations`, `parallel_query`: use a seeded rng Examples of errors encountered: ``` Caused by: In Device::create_bind_group note: label = `bloom_upsampling_bind_group` Not enough memory left ``` ``` Caused by: In Queue::write_buffer Parent device is lost ``` ``` ERROR wgpu_core::device::life: Mapping failed Device(Lost) ```
1 parent db47ea2 commit b6a2fc5

8 files changed

+70
-70
lines changed

examples/3d/bloom_3d.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ fn setup_scene(
6565
.unwrap(),
6666
);
6767

68-
for x in -10..10 {
69-
for z in -10..10 {
68+
for x in -5..5 {
69+
for z in -5..5 {
7070
let mut hasher = DefaultHasher::new();
7171
(x, z).hash(&mut hasher);
7272
let rand = (hasher.finish() - 2) % 6;

examples/3d/pbr.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ fn setup(
1717
mut materials: ResMut<Assets<StandardMaterial>>,
1818
asset_server: Res<AssetServer>,
1919
) {
20+
let sphere_mesh = meshes.add(
21+
Mesh::try_from(shape::Icosphere {
22+
radius: 0.45,
23+
..default()
24+
})
25+
.unwrap(),
26+
);
2027
// add entities to the world
2128
for y in -2..=2 {
2229
for x in -5..=5 {
2330
let x01 = (x + 5) as f32 / 10.0;
2431
let y01 = (y + 2) as f32 / 4.0;
2532
// sphere
2633
commands.spawn(PbrBundle {
27-
mesh: meshes.add(
28-
Mesh::try_from(shape::Icosphere {
29-
radius: 0.45,
30-
subdivisions: 32,
31-
})
32-
.unwrap(),
33-
),
34+
mesh: sphere_mesh.clone(),
3435
material: materials.add(StandardMaterial {
3536
base_color: Color::hex("#ffd891").unwrap(),
3637
// vary key PBR parameters on a grid of spheres to show the effect
@@ -45,13 +46,7 @@ fn setup(
4546
}
4647
// unlit sphere
4748
commands.spawn(PbrBundle {
48-
mesh: meshes.add(
49-
Mesh::try_from(shape::Icosphere {
50-
radius: 0.45,
51-
subdivisions: 32,
52-
})
53-
.unwrap(),
54-
),
49+
mesh: sphere_mesh,
5550
material: materials.add(StandardMaterial {
5651
base_color: Color::hex("#ffd891").unwrap(),
5752
// vary key PBR parameters on a grid of spheres to show the effect

examples/3d/shadow_biases.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn setup(
2626
mut meshes: ResMut<Assets<Mesh>>,
2727
mut materials: ResMut<Assets<StandardMaterial>>,
2828
) {
29-
let spawn_plane_depth = 500.0f32;
29+
let spawn_plane_depth = 300.0f32;
3030
let spawn_height = 2.0;
3131
let sphere_radius = 0.25;
3232

@@ -84,7 +84,7 @@ fn setup(
8484
CameraController::default(),
8585
));
8686

87-
for z_i32 in -spawn_plane_depth as i32..=0 {
87+
for z_i32 in (-spawn_plane_depth as i32..=0).step_by(2) {
8888
commands.spawn(PbrBundle {
8989
mesh: sphere_handle.clone(),
9090
material: white_handle.clone(),

examples/3d/spotlight.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy::{
55
pbr::NotShadowCaster,
66
prelude::*,
77
};
8-
use rand::{thread_rng, Rng};
8+
use rand::{rngs::StdRng, Rng, SeedableRng};
99

1010
fn main() {
1111
App::new()
@@ -40,18 +40,20 @@ fn setup(
4040
});
4141

4242
// cubes
43-
let mut rng = thread_rng();
44-
for _ in 0..100 {
43+
let mut rng = StdRng::seed_from_u64(19878367467713);
44+
let cube_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.5 }));
45+
let blue = materials.add(StandardMaterial {
46+
base_color: Color::BLUE,
47+
..default()
48+
});
49+
for _ in 0..40 {
4550
let x = rng.gen_range(-5.0..5.0);
46-
let y = rng.gen_range(-5.0..5.0);
51+
let y = rng.gen_range(0.0..3.0);
4752
let z = rng.gen_range(-5.0..5.0);
4853
commands.spawn((
4954
PbrBundle {
50-
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
51-
material: materials.add(StandardMaterial {
52-
base_color: Color::BLUE,
53-
..default()
54-
}),
55+
mesh: cube_mesh.clone(),
56+
material: blue.clone(),
5557
transform: Transform::from_xyz(x, y, z),
5658
..default()
5759
},
@@ -65,6 +67,24 @@ fn setup(
6567
brightness: 0.14,
6668
});
6769

70+
let sphere_mesh = meshes.add(Mesh::from(shape::UVSphere {
71+
radius: 0.05,
72+
..default()
73+
}));
74+
let sphere_mesh_direction = meshes.add(Mesh::from(shape::UVSphere {
75+
radius: 0.1,
76+
..default()
77+
}));
78+
let red_emissive = materials.add(StandardMaterial {
79+
base_color: Color::RED,
80+
emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0),
81+
..default()
82+
});
83+
let maroon_emissive = materials.add(StandardMaterial {
84+
base_color: Color::MAROON,
85+
emissive: Color::rgba_linear(0.369, 0.0, 0.0, 0.0),
86+
..default()
87+
});
6888
for x in 0..4 {
6989
for z in 0..4 {
7090
let x = x as f32 - 2.0;
@@ -86,29 +106,15 @@ fn setup(
86106
})
87107
.with_children(|builder| {
88108
builder.spawn(PbrBundle {
89-
mesh: meshes.add(Mesh::from(shape::UVSphere {
90-
radius: 0.05,
91-
..default()
92-
})),
93-
material: materials.add(StandardMaterial {
94-
base_color: Color::RED,
95-
emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0),
96-
..default()
97-
}),
109+
mesh: sphere_mesh.clone(),
110+
material: red_emissive.clone(),
98111
..default()
99112
});
100113
builder.spawn((
101114
PbrBundle {
102115
transform: Transform::from_translation(Vec3::Z * -0.1),
103-
mesh: meshes.add(Mesh::from(shape::UVSphere {
104-
radius: 0.1,
105-
..default()
106-
})),
107-
material: materials.add(StandardMaterial {
108-
base_color: Color::MAROON,
109-
emissive: Color::rgba_linear(0.369, 0.0, 0.0, 0.0),
110-
..default()
111-
}),
116+
mesh: sphere_mesh_direction.clone(),
117+
material: maroon_emissive.clone(),
112118
..default()
113119
},
114120
NotShadowCaster,

examples/3d/tonemapping.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ fn setup_basic_scene(
135135
}
136136

137137
// spheres
138+
let sphere_mesh = meshes.add(Mesh::from(shape::UVSphere {
139+
radius: 0.125,
140+
..default()
141+
}));
138142
for i in 0..6 {
139143
let j = i % 3;
140144
let s_val = if i < 3 { 0.0 } else { 0.2 };
@@ -162,11 +166,7 @@ fn setup_basic_scene(
162166
};
163167
commands.spawn((
164168
PbrBundle {
165-
mesh: meshes.add(Mesh::from(shape::UVSphere {
166-
radius: 0.125,
167-
sectors: 128,
168-
stacks: 128,
169-
})),
169+
mesh: sphere_mesh.clone(),
170170
material,
171171
transform: Transform::from_xyz(
172172
j as f32 * 0.25 + if i < 3 { -0.15 } else { 0.15 } - 0.4,

examples/async_tasks/external_source_external_thread.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use bevy::prelude::*;
44
// Using crossbeam_channel instead of std as std `Receiver` is `!Sync`
55
use crossbeam_channel::{bounded, Receiver};
6-
use rand::Rng;
6+
use rand::{rngs::StdRng, Rng, SeedableRng};
77
use std::time::{Duration, Instant};
88

99
fn main() {
@@ -25,17 +25,19 @@ fn setup(mut commands: Commands) {
2525
commands.spawn(Camera2dBundle::default());
2626

2727
let (tx, rx) = bounded::<u32>(10);
28-
std::thread::spawn(move || loop {
29-
// Everything here happens in another thread
30-
// This is where you could connect to an external data source
31-
let mut rng = rand::thread_rng();
32-
let start_time = Instant::now();
33-
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
34-
while start_time.elapsed() < duration {
35-
// Spinning for 'duration', simulating doing hard work!
36-
}
28+
std::thread::spawn(move || {
29+
let mut rng = StdRng::seed_from_u64(19878367467713);
30+
loop {
31+
// Everything here happens in another thread
32+
// This is where you could connect to an external data source
33+
let start_time = Instant::now();
34+
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
35+
while start_time.elapsed() < duration {
36+
// Spinning for 'duration', simulating doing hard work!
37+
}
3738

38-
tx.send(rng.gen_range(0..2000)).unwrap();
39+
tx.send(rng.gen_range(0..2000)).unwrap();
40+
}
3941
});
4042

4143
commands.insert_resource(StreamReceiver(rx));
@@ -59,11 +61,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
5961
commands.spawn(Text2dBundle {
6062
text: Text::from_section(event.0.to_string(), text_style.clone())
6163
.with_alignment(TextAlignment::Center),
62-
transform: Transform::from_xyz(
63-
per_frame as f32 * 100.0 + rand::thread_rng().gen_range(-40.0..40.0),
64-
300.0,
65-
0.0,
66-
),
64+
transform: Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0),
6765
..default()
6866
});
6967
}

examples/ecs/iter_combinations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Shows how to iterate over combinations of query results.
22
33
use bevy::{pbr::AmbientLight, prelude::*};
4-
use rand::{thread_rng, Rng};
4+
use rand::{rngs::StdRng, Rng, SeedableRng};
55

66
const DELTA_TIME: f32 = 0.01;
77

@@ -56,7 +56,7 @@ fn generate_bodies(
5656
let color_range = 0.5..1.0;
5757
let vel_range = -0.5..0.5;
5858

59-
let mut rng = thread_rng();
59+
let mut rng = StdRng::seed_from_u64(19878367467713);
6060
for _ in 0..NUM_BODIES {
6161
let radius: f32 = rng.gen_range(0.1..0.7);
6262
let mass_value = radius.powi(3) * 10.;

examples/ecs/parallel_query.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
33
use bevy::ecs::query::BatchingStrategy;
44
use bevy::prelude::*;
5-
use rand::random;
5+
use rand::{rngs::StdRng, Rng, SeedableRng};
66

77
#[derive(Component, Deref)]
88
struct Velocity(Vec2);
99

1010
fn spawn_system(mut commands: Commands, asset_server: Res<AssetServer>) {
1111
commands.spawn(Camera2dBundle::default());
1212
let texture = asset_server.load("branding/icon.png");
13+
let mut rng = StdRng::seed_from_u64(19878367467713);
1314
for _ in 0..128 {
1415
commands.spawn((
1516
SpriteBundle {
1617
texture: texture.clone(),
1718
transform: Transform::from_scale(Vec3::splat(0.1)),
1819
..default()
1920
},
20-
Velocity(20.0 * Vec2::new(random::<f32>() - 0.5, random::<f32>() - 0.5)),
21+
Velocity(20.0 * Vec2::new(rng.gen::<f32>() - 0.5, rng.gen::<f32>() - 0.5)),
2122
));
2223
}
2324
}

0 commit comments

Comments
 (0)