Skip to content
Open
21 changes: 21 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ libloading = "0.8"
libm = { version = "0.2.6", default-features = false }
libtest-mimic = "0.8"
log = "0.4.21"
macro_rules_attribute = "0.2"
nanoserde = "0.2"
nanorand = { version = "0.8", default-features = false, features = ["wyrand"] }
noise = "0.9"
Expand Down
7 changes: 2 additions & 5 deletions deno_webgpu/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,8 @@ impl GPUDevice {
multiview: None,
};

let res = wgpu_core::command::RenderBundleEncoder::new(
&wgpu_descriptor,
self.id,
None,
);
let res =
wgpu_core::command::RenderBundleEncoder::new(&wgpu_descriptor, self.id);
let (encoder, err) = match res {
Ok(encoder) => (encoder, None),
Err(e) => (
Expand Down
1 change: 1 addition & 0 deletions player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test = false
wgpu-types = { workspace = true, features = ["serde", "std"] }

env_logger.workspace = true
hashbrown.workspace = true
log.workspace = true
raw-window-handle.workspace = true
ron.workspace = true
Expand Down
102 changes: 43 additions & 59 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ fn main() {
extern crate wgpu_core as wgc;
extern crate wgpu_types as wgt;

use player::GlobalPlay as _;
use player::Player;
use wgc::device::trace;
use wgpu_core::identity::IdentityManager;
use wgpu_core::command::PointerReferences;

use std::{
fs,
path::{Path, PathBuf},
process::exit,
sync::Arc,
};

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

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

Expand All @@ -68,17 +69,14 @@ fn main() {
.build(&event_loop)
.unwrap();

let global =
wgc::global::Global::new("player", &wgt::InstanceDescriptor::from_env_or_default());
let mut command_encoder_id_manager = IdentityManager::new();
let mut command_buffer_id_manager = IdentityManager::new();
let instance_desc = wgt::InstanceDescriptor::from_env_or_default();
let instance = wgc::instance::Instance::new("player", &instance_desc);

#[cfg(feature = "winit")]
let surface = unsafe {
global.instance_create_surface(
instance.create_surface(
window.display_handle().unwrap().into(),
window.window_handle().unwrap().into(),
Some(wgc::id::Id::zip(0, 1)),
)
}
.unwrap();
Expand All @@ -93,50 +91,43 @@ fn main() {
None => (wgt::Backends::all(), wgt::DeviceDescriptor::default()),
};

let adapter = global
.request_adapter(
&wgc::instance::RequestAdapterOptions {
#[cfg(feature = "winit")]
compatible_surface: Some(surface),
#[cfg(not(feature = "winit"))]
compatible_surface: None,
..Default::default()
},
backends,
Some(wgc::id::AdapterId::zip(0, 1)),
)
.expect("Unable to obtain an adapter");

let info = global.adapter_get_info(adapter);
let adapter = Arc::new(
instance
.request_adapter(
&wgt::RequestAdapterOptions {
#[cfg(feature = "winit")]
compatible_surface: Some(&surface),
#[cfg(not(feature = "winit"))]
compatible_surface: None,
..Default::default()
},
backends,
)
.expect("Unable to obtain an adapter"),
);

let info = adapter.get_info();
log::info!("Using '{}'", info.name);

let device = wgc::id::Id::zip(0, 1);
let queue = wgc::id::Id::zip(0, 1);
let res = global.adapter_request_device(adapter, &device_desc, Some(device), Some(queue));
if let Err(e) = res {
panic!("{e:?}");
}
let (device, queue) = adapter
.create_device_and_queue(&device_desc, instance_desc.flags)
.unwrap();

let mut player = Player::default();

log::info!("Executing actions");
#[cfg(not(feature = "winit"))]
{
unsafe { global.device_start_graphics_debugger_capture(device) };

while let Some(action) = actions.pop() {
global.process(
device,
queue,
action,
&dir,
&mut command_encoder_id_manager,
&mut command_buffer_id_manager,
);
player.process(&device, &queue, action, &dir);
}

unsafe { global.device_stop_graphics_debugger_capture(device) };
global
.device_poll(device, wgt::PollType::wait_indefinitely())
.unwrap();
let (user_closures, result) = device.poll(wgt::PollType::wait_indefinitely());
user_closures.fire();
result.unwrap();
}
#[cfg(feature = "winit")]
{
Expand Down Expand Up @@ -170,33 +161,25 @@ fn main() {
resize_config = Some(config);
target.exit();
} else {
let error =
global.surface_configure(surface, device, &config);
let error = device.configure_surface(&surface, &config);
if let Some(e) = error {
panic!("{e:?}");
}
}
}
Some(trace::Action::Present(id)) => {
Some(trace::Action::Present(_id)) => {
frame_count += 1;
log::debug!("Presenting frame {frame_count}");
global.surface_present(id).unwrap();
surface.present().unwrap();
target.exit();
}
Some(trace::Action::DiscardSurfaceTexture(id)) => {
Some(trace::Action::DiscardSurfaceTexture(_id)) => {
log::debug!("Discarding frame {frame_count}");
global.surface_texture_discard(id).unwrap();
surface.discard().unwrap();
target.exit();
}
Some(action) => {
global.process(
device,
queue,
action,
&dir,
&mut command_encoder_id_manager,
&mut command_buffer_id_manager,
);
player.process(&device, &queue, action, &dir);
}
None => {
if !done {
Expand All @@ -209,7 +192,7 @@ fn main() {
}
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = global.surface_configure(surface, device, &config);
let error = device.configure_surface(&surface, &config);
if let Some(e) = error {
panic!("{e:?}");
}
Expand All @@ -229,9 +212,10 @@ fn main() {
},
Event::LoopExiting => {
log::info!("Closing");
global
.device_poll(device, wgt::PollType::wait_indefinitely())
.unwrap();
let (user_closures, result) =
device.poll(wgt::PollType::wait_indefinitely());
user_closures.fire();
result.unwrap();
}
_ => {}
}
Expand Down
Loading
Loading