Skip to content

Commit

Permalink
Merge #1050
Browse files Browse the repository at this point in the history
1050: player: use the wgpu-cores's gfx-select macro r=kvark a=kvark

**Connections**
Looks like I broke the player in #1034, surprised we didn't notice, and that `cargo test` still passed. The problem was having the `Empty` backend for the device.

**Description**
Fixes the `device` backend in the player, switches the backend set to be `PRIMARY`, and re-uses the `wgc::gfx-select`.

**Testing**
Replaying a trace from #1049

Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
bors[bot] and kvark authored Nov 26, 2020
2 parents 75b4697 + 55851ad commit 8cc7bbd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

13 changes: 8 additions & 5 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/*! This is a player for WebGPU traces.
!*/

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

use std::{
fs,
Expand Down Expand Up @@ -55,8 +55,11 @@ fn main() {
.build(&event_loop)
.unwrap();

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

#[cfg(feature = "winit")]
Expand Down Expand Up @@ -84,7 +87,7 @@ fn main() {

let info = gfx_select!(adapter => global.adapter_get_info(adapter)).unwrap();
log::info!("Picked '{}'", info.name);
let id = wgc::id::TypedId::zip(1, 0, wgt::Backend::Empty);
let id = wgc::id::TypedId::zip(1, 0, backend);
let (_, error) = gfx_select!(adapter => global.adapter_request_device(
adapter,
&desc,
Expand Down
17 changes: 0 additions & 17 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ use wgc::device::trace;

use std::{borrow::Cow, fmt::Debug, fs, marker::PhantomData, path::Path};

#[macro_export]
macro_rules! gfx_select {
($id:expr => $global:ident.$method:ident( $($param:expr),+ )) => {
match $id.backend() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
wgt::Backend::Vulkan => $global.$method::<wgc::backend::Vulkan>( $($param),+ ),
#[cfg(any(target_os = "ios", target_os = "macos"))]
wgt::Backend::Metal => $global.$method::<wgc::backend::Metal>( $($param),+ ),
#[cfg(windows)]
wgt::Backend::Dx12 => $global.$method::<wgc::backend::Dx12>( $($param),+ ),
#[cfg(windows)]
wgt::Backend::Dx11 => $global.$method::<wgc::backend::Dx11>( $($param),+ ),
_ => unreachable!()
}
};
}

#[derive(Debug)]
pub struct IdentityPassThrough<I>(PhantomData<I>);

Expand Down
16 changes: 8 additions & 8 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* - no swapchain use
!*/

use player::{gfx_select, GlobalPlay, IdentityPassThroughFactory};
use player::{GlobalPlay, IdentityPassThroughFactory};
use std::{
fs::{read_to_string, File},
io::{Read, Seek, SeekFrom},
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Test<'_> {
) {
let backend = adapter.backend();
let device = wgc::id::TypedId::zip(test_num, 0, backend);
let (_, error) = gfx_select!(adapter => global.adapter_request_device(
let (_, error) = wgc::gfx_select!(adapter => global.adapter_request_device(
adapter,
&wgt::DeviceDescriptor {
label: None,
Expand All @@ -105,12 +105,12 @@ impl Test<'_> {
let mut command_buffer_id_manager = wgc::hub::IdentityManager::default();
println!("\t\t\tRunning...");
for action in self.actions {
gfx_select!(device => global.process(device, action, dir, &mut command_buffer_id_manager));
wgc::gfx_select!(device => global.process(device, action, dir, &mut command_buffer_id_manager));
}
println!("\t\t\tMapping...");
for expect in &self.expectations {
let buffer = wgc::id::TypedId::zip(expect.buffer.index, expect.buffer.epoch, backend);
gfx_select!(device => global.buffer_map_async(
wgc::gfx_select!(device => global.buffer_map_async(
buffer,
expect.offset .. expect.offset+expect.data.len() as wgt::BufferAddress,
wgc::resource::BufferMapOperation {
Expand All @@ -123,13 +123,13 @@ impl Test<'_> {
}

println!("\t\t\tWaiting...");
gfx_select!(device => global.device_poll(device, true)).unwrap();
wgc::gfx_select!(device => global.device_poll(device, true)).unwrap();

for expect in self.expectations {
println!("\t\t\tChecking {}", expect.name);
let buffer = wgc::id::TypedId::zip(expect.buffer.index, expect.buffer.epoch, backend);
let ptr =
gfx_select!(device => global.buffer_get_mapped_range(buffer, expect.offset, None))
wgc::gfx_select!(device => global.buffer_get_mapped_range(buffer, expect.offset, None))
.unwrap();
let contents = unsafe { slice::from_raw_parts(ptr, expect.data.len()) };
let expected_data = match expect.data {
Expand All @@ -147,7 +147,7 @@ impl Test<'_> {
assert_eq!(&expected_data[..], contents);
}

gfx_select!(device => global.clear_backend(()));
wgc::gfx_select!(device => global.clear_backend(()));
}
}

Expand Down Expand Up @@ -192,7 +192,7 @@ impl Corpus {

println!("\tBackend {:?}", backend);
let supported_features =
gfx_select!(adapter => global.adapter_features(adapter)).unwrap();
wgc::gfx_select!(adapter => global.adapter_features(adapter)).unwrap();
let mut test_num = 0;
for test_path in &corpus.tests {
println!("\t\tTest '{:?}'", test_path);
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ macro_rules! gfx_select {
wgt::Backend::Dx11 => $global.$method::<$crate::backend::Dx11>( $($param),* ),
#[cfg(all(unix, not(target_os = "ios")))]
wgt::Backend::Gl => $global.$method::<$crate::backend::Gl>( $($param),+ ),
_ => unreachable!()
other => panic!("Unexpected backend {:?}", other),
}
};
}
Expand Down

0 comments on commit 8cc7bbd

Please sign in to comment.