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

Fix bunnymark test screenshot and replace rand with nanorand #2746

Merged
merged 13 commits into from
Jun 10, 2022
10 changes: 7 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ log = "0.4"
noise = { version = "0.7", default-features = false }
obj = "0.10"
png = "0.17"
rand = "0.7.2"
nanorand = { version = "0.7", default-features = false, features = ["wyrand"] }
winit = "0.26"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down Expand Up @@ -295,4 +295,3 @@ console_error_panic_hook = "0.1.6"
console_log = "0.1.2"
# We need the Location feature in the framework examples
web-sys = { version = "0.3.53", features = ["Location"] }
rand = { version = "0.7", features = ["wasm-bindgen"] }
17 changes: 7 additions & 10 deletions wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Flocking boids example with gpu compute update pass
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts

use rand::{
distributions::{Distribution, Uniform},
SeedableRng,
};
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use wgpu::util::DeviceExt;

Expand Down Expand Up @@ -183,13 +180,13 @@ impl framework::Example for Example {
// buffer for all particles data of type [(posx,posy,velx,vely),...]

let mut initial_particle_data = vec![0.0f32; (4 * NUM_PARTICLES) as usize];
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
let unif = Uniform::new_inclusive(-1.0, 1.0);
let mut rng = WyRand::new_seed(42);
let mut unif = || rng.generate::<f32>() * 2f32 - 1f32; // Generate a num (-1, 1)
for particle_instance_chunk in initial_particle_data.chunks_mut(4) {
particle_instance_chunk[0] = unif.sample(&mut rng); // posx
particle_instance_chunk[1] = unif.sample(&mut rng); // posy
particle_instance_chunk[2] = unif.sample(&mut rng) * 0.1; // velx
particle_instance_chunk[3] = unif.sample(&mut rng) * 0.1; // vely
particle_instance_chunk[0] = unif(); // posx
particle_instance_chunk[1] = unif(); // posy
particle_instance_chunk[2] = unif() * 0.1; // velx
particle_instance_chunk[3] = unif() * 0.1; // vely
}

// creates two buffers of particle data each of size NUM_PARTICLES
Expand Down
Binary file modified wgpu/examples/boids/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bytemuck::{Pod, Zeroable};
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use wgpu::util::DeviceExt;

Expand Down Expand Up @@ -35,6 +36,7 @@ struct Example {
bunnies: Vec<Locals>,
local_buffer: wgpu::Buffer,
extent: [u32; 2],
rng: WyRand,
}

impl framework::Example for Example {
Expand Down Expand Up @@ -234,13 +236,16 @@ impl framework::Example for Example {
label: None,
});

let rng = WyRand::new_seed(42);

Example {
pipeline,
global_group,
local_group,
bunnies: Vec::new(),
local_buffer,
extent: [config.width, config.height],
rng,
}
}

Expand All @@ -256,14 +261,14 @@ impl framework::Example for Example {
} = event
{
let spawn_count = 64 + self.bunnies.len() / 2;
let color = rand::random::<u32>();
let color = self.rng.generate::<u32>();
println!(
"Spawning {} bunnies, total at {}",
spawn_count,
self.bunnies.len() + spawn_count
);
for _ in 0..spawn_count {
let speed = rand::random::<f32>() * MAX_VELOCITY - (MAX_VELOCITY * 0.5);
let speed = self.rng.generate::<f32>() * MAX_VELOCITY - (MAX_VELOCITY * 0.5);
self.bunnies.push(Locals {
position: [0.0, 0.5 * (self.extent[1] as f32)],
velocity: [speed, 0.0],
Expand Down Expand Up @@ -360,7 +365,7 @@ fn bunnymark() {
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: framework::test_common::TestParameters::default(),
tolerance: 1,
max_outliers: 50,
tolerance: 10,
max_outliers: 53, // Bounded by WARP
});
}
Binary file modified wgpu/examples/bunnymark/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,27 @@ pub fn test<E: Example>(mut params: FrameworkRefTest) {

example.render(&dst_view, &ctx.device, &ctx.queue, &spawner);

// Handle specific case for bunnymark
#[allow(deprecated)]
if params.image_path == "/examples/bunnymark/screenshot.png" {
// Press spacebar to spawn bunnies
example.update(winit::event::WindowEvent::KeyboardInput {
input: winit::event::KeyboardInput {
scancode: 0,
state: winit::event::ElementState::Pressed,
virtual_keycode: Some(winit::event::VirtualKeyCode::Space),
modifiers: winit::event::ModifiersState::empty(),
},
device_id: unsafe { winit::event::DeviceId::dummy() },
is_synthetic: false,
stevenhuyn marked this conversation as resolved.
Show resolved Hide resolved
});

// Step 3 extra frames
for _ in 0..3 {
example.render(&dst_view, &ctx.device, &ctx.queue, &spawner);
}
}

let mut cmd_buf = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
Expand Down
7 changes: 3 additions & 4 deletions wgpu/examples/water/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod point_gen;

use bytemuck::{Pod, Zeroable};
use glam::Vec3;
use rand::SeedableRng;
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, f32::consts, iter, mem};
use wgpu::util::DeviceExt;

Expand Down Expand Up @@ -285,13 +285,12 @@ impl framework::Example for Example {
let terrain_noise = noise::OpenSimplex::new();

// Random colouration
let mut terrain_random = rand::rngs::StdRng::seed_from_u64(42);
let mut terrain_random = WyRand::new_seed(42);

// Generate terrain. The closure determines what each hexagon will look like.
let terrain =
point_gen::HexTerrainMesh::generate(SIZE, |point| -> point_gen::TerrainVertex {
use noise::NoiseFn;
use rand::Rng;
let noise = terrain_noise.get([point[0] as f64 / 5.0, point[1] as f64 / 5.0]) + 0.1;

let y = noise as f32 * 22.0;
Expand All @@ -314,7 +313,7 @@ impl framework::Example for Example {
const SNOW: [u8; 4] = [175, 224, 237, 255];

// Random colouration.
let random = terrain_random.gen::<f32>() * 0.2 + 0.9;
let random = terrain_random.generate::<f32>() * 0.2 + 0.9;

// Choose colour.
let colour = if y <= 0.0 {
Expand Down
Binary file modified wgpu/examples/water/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion wgpu/tests/common/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn compare_image_output(
.unwrap();

if outliers > max_outliers {
// Because the deta is mismatched, lets output the difference to a file.
// Because the data is mismatched, lets output the difference to a file.
let old_path = Path::new(&path);
let actual_path = Path::new(&path).with_file_name(
OsString::from_str(
Expand Down