Fix bunnymark test screenshot and replace rand with nanorand (#2746)

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
Steven
2022-06-10 14:44:27 -07:00
committed by GitHub
parent 629ccaf4e0
commit df1472d4a3
10 changed files with 49 additions and 24 deletions

10
Cargo.lock generated
View File

@@ -636,10 +636,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
@@ -1053,6 +1051,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "nanorand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
[[package]]
name = "ndk"
version = "0.5.0"
@@ -2061,12 +2065,12 @@ dependencies = [
"js-sys",
"log",
"naga",
"nanorand",
"noise",
"obj",
"parking_lot 0.12.0",
"png",
"pollster",
"rand",
"raw-window-handle",
"serde",
"smallvec",

View File

@@ -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]
@@ -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"] }

View File

@@ -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;
@@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 116 KiB

View File

@@ -1,4 +1,5 @@
use bytemuck::{Pod, Zeroable};
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use wgpu::util::DeviceExt;
@@ -35,6 +36,7 @@ struct Example {
bunnies: Vec<Locals>,
local_buffer: wgpu::Buffer,
extent: [u32; 2],
rng: WyRand,
}
impl framework::Example for Example {
@@ -234,6 +236,8 @@ impl framework::Example for Example {
label: None,
});
let rng = WyRand::new_seed(42);
Example {
pipeline,
global_group,
@@ -241,6 +245,7 @@ impl framework::Example for Example {
bunnies: Vec::new(),
local_buffer,
extent: [config.width, config.height],
rng,
}
}
@@ -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],
@@ -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 not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -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,
});
// 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());

View File

@@ -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;
@@ -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;
@@ -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 {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 164 KiB

View File

@@ -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(