Skip to content

Commit

Permalink
Merge #803
Browse files Browse the repository at this point in the history
803: Player-based GPU test framework r=cwfitzgerald a=kvark

**Connections**
Closes #786

**Description**
This change adds a GPU-based testing by re-using the Player from tracing infrastructure - #289.
It converts the player into a lib + binary, and adds an integration test into the crate that implements RON-specified testing.

Current implementation has a few requirements/gotchas that are listed in `test.rs`:
* in all the IDs, the backend is `Empty`
* all expected buffers have `MAP_READ` usage on them
* last action is `Submit`

I believe it's workable, and we can improve it down the road (e.g. with #792).

**Testing**
MUHAHAHA
`cargo test` nails it

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark authored Jul 17, 2020
2 parents 0c7f189 + eb7bdcd commit 2455a65
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 169 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ features = ["replay", "raw-window-handle"]

[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5", features = ["x11"] }

[dev-dependencies]
serde = "1"
5 changes: 3 additions & 2 deletions player/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# wgpu player

This is application that allows replaying the `wgpu` workloads recorded elsewhere.
This is application that allows replaying the `wgpu` workloads recorded elsewhere. You must use the player built from
the same revision as an application was linking to, or otherwise the data may fail to load.

Launch as:
```rust
player <trace-dir>
play <trace-dir>
```

When built with "winit" feature, it's able to replay the workloads that operate on a swapchain. It renders each frame sequentially, then waits for the user to close the window. When built without "winit", it launches in console mode and can replay any trace that doesn't use swapchains.
Expand Down
166 changes: 166 additions & 0 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*! This is a player for WebGPU traces.
!*/

use player::{gfx_select, GlobalPlay as _, IdentityPassThroughFactory};
use wgc::device::trace;

use std::{
fs,
path::{Path, PathBuf},
};

fn main() {
#[cfg(feature = "winit")]
use winit::{event_loop::EventLoop, window::WindowBuilder};

env_logger::init();

#[cfg(feature = "renderdoc")]
#[cfg_attr(feature = "winit", allow(unused))]
let mut rd = renderdoc::RenderDoc::<renderdoc::V110>::new()
.expect("Failed to connect to RenderDoc: are you running without it?");

//TODO: setting for the backend bits
//TODO: setting for the target frame, or controls

let dir = match std::env::args().nth(1) {
Some(arg) if Path::new(&arg).is_dir() => PathBuf::from(arg),
_ => panic!("Provide the dir path as the parameter"),
};

log::info!("Loading trace '{:?}'", dir);
let file = fs::File::open(dir.join(trace::FILE_NAME)).unwrap();
let mut actions: Vec<trace::Action> = ron::de::from_reader(file).unwrap();
actions.reverse(); // allows us to pop from the top
log::info!("Found {} actions", actions.len());

#[cfg(feature = "winit")]
let event_loop = {
log::info!("Creating a window");
EventLoop::new()
};
#[cfg(feature = "winit")]
let window = WindowBuilder::new()
.with_title("wgpu player")
.with_resizable(false)
.build(&event_loop)
.unwrap();

let global =
wgc::hub::Global::new("player", IdentityPassThroughFactory, wgt::BackendBit::all());
let mut command_buffer_id_manager = wgc::hub::IdentityManager::default();

#[cfg(feature = "winit")]
let surface =
global.instance_create_surface(&window, wgc::id::TypedId::zip(0, 1, wgt::Backend::Empty));

let device = match actions.pop() {
Some(trace::Action::Init { desc, backend }) => {
log::info!("Initializing the device for backend: {:?}", backend);
let adapter = global
.pick_adapter(
&wgc::instance::RequestAdapterOptions {
power_preference: wgt::PowerPreference::Default,
#[cfg(feature = "winit")]
compatible_surface: Some(surface),
#[cfg(not(feature = "winit"))]
compatible_surface: None,
},
wgc::instance::AdapterInputs::IdSet(
&[wgc::id::TypedId::zip(0, 0, backend)],
|id| id.backend(),
),
)
.expect("Unable to find an adapter for selected backend");

let info = gfx_select!(adapter => global.adapter_get_info(adapter));
log::info!("Picked '{}'", info.name);
gfx_select!(adapter => global.adapter_request_device(
adapter,
&desc,
None,
wgc::id::TypedId::zip(1, 0, wgt::Backend::Empty)
))
.expect("Failed to request device")
}
_ => panic!("Expected Action::Init"),
};
log::info!("Executing actions");
#[cfg(not(feature = "winit"))]
{
#[cfg(feature = "renderdoc")]
rd.start_frame_capture(std::ptr::null(), std::ptr::null());

while let Some(action) = actions.pop() {
gfx_select!(device => global.process(device, action, &dir, &mut command_buffer_id_manager));
}

#[cfg(feature = "renderdoc")]
rd.end_frame_capture(std::ptr::null(), std::ptr::null());
gfx_select!(device => global.device_poll(device, true));
}
#[cfg(feature = "winit")]
{
use winit::{
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::ControlFlow,
};

let mut frame_count = 0;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::MainEventsCleared => {
window.request_redraw();
}
Event::RedrawRequested(_) => loop {
match actions.pop() {
Some(trace::Action::CreateSwapChain { id, desc }) => {
log::info!("Initializing the swapchain");
assert_eq!(id.to_surface_id(), surface);
window.set_inner_size(winit::dpi::PhysicalSize::new(
desc.width,
desc.height,
));
gfx_select!(device => global.device_create_swap_chain(device, surface, &desc));
}
Some(trace::Action::PresentSwapChain(id)) => {
frame_count += 1;
log::debug!("Presenting frame {}", frame_count);
gfx_select!(device => global.swap_chain_present(id));
break;
}
Some(action) => {
gfx_select!(device => global.process(device, action, &dir, &mut command_buffer_id_manager));
}
None => break,
}
},
Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
state: ElementState::Pressed,
..
},
..
}
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
_ => {}
},
Event::LoopDestroyed => {
log::info!("Closing");
gfx_select!(device => global.device_poll(device, true));
}
_ => {}
}
});
}
}
Loading

0 comments on commit 2455a65

Please sign in to comment.