rustrust-wasmwebgpuwgpu-rs

How to time profile/see when tasks are complete in wgpu (targeting web)?


Basically title. There are support for timestamp queries, but that requires specific device feature support (my laptop for example does not support it when targeting web). There is also the function Queue::onSubmittedWorkDone(callback) that throws an unreachable code error when I use any callback on wasm. Finally, device.poll(Maintain::wait) is explicitly a no-op on web according to the docs (for me, it never returns true when I try it). Is there any way to see whats in the Queue or check if it is empty? In the WebGPU api spec, onSubmittedWorkDone is an async function that returns a Promise. If that were the case, we could simply await until completion. I included an example with my attempt at using Queue::onSubmittedWorkDone(callback) in case it is user error (likely).

let mut encoder = driver.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
self.calculate_summary(&mut encoder);
self.color_map(&mut encoder); 
driver.queue.on_submitted_work_done(Self::done);
driver.queue.submit(Some(encoder.finish()));

fn done(){
\\\Ive tried just print statements, incrementing dummy variables, and even empty functions, but it doesn't work
}

Solution

  • I had a similar situation for a complex render chain and came up with the solution of reading a 1-byte buffer. I can then block awaiting the result, and so then I know the queue is empty again.