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
9 changes: 7 additions & 2 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 rand::{prelude::StdRng, Rng, SeedableRng};
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: StdRng,
}

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

let rng = rand::rngs::StdRng::seed_from_u64(64);

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.gen::<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.gen::<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
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 @@ -488,6 +488,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