Skip to content

Commit f03855a

Browse files
committed
expect to timeout when targeting WebGL
1 parent daef69e commit f03855a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

wgpu-core/src/device/queue.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ impl Drop for Queue {
152152
self.device.raw().wait(
153153
fence.as_ref(),
154154
last_successful_submission_index,
155+
#[cfg(not(target_arch = "wasm32"))]
155156
crate::device::CLEANUP_WAIT_MS,
157+
#[cfg(target_arch = "wasm32")]
158+
0, // WebKit and Chromium don't support a non-0 timeout
156159
)
157160
};
158161
drop(fence);
@@ -161,6 +164,13 @@ impl Drop for Queue {
161164
Ok(true) => {}
162165
// Note: If we don't panic here we are in UB land (destroying resources while they are still in use by the GPU).
163166
Ok(false) => {
167+
// It's fine that we timed out on WebGL; GL objects can be deleted early as they
168+
// will be kept around by the driver if GPU work hasn't finished.
169+
// Moreover, the way we emulate read mappings on WebGL allows us to execute map_buffer earlier than on other
170+
// backends since getBufferSubData is synchronous with respect to the other previously enqueued GL commands.
171+
// TODO: Relying on this behavior breaks the clean abstraction wgpu-hal tries to maintain and
172+
// we should find ways to improve this.
173+
#[cfg(not(target_arch = "wasm32"))]
164174
panic!("We timed out while waiting on the last successful submission to complete!");
165175
}
166176
Err(e) => {

wgpu-hal/src/gles/device.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,10 @@ impl crate::Device for super::Device {
15631563
) -> Result<bool, crate::DeviceError> {
15641564
if fence.last_completed.load(Ordering::Relaxed) < wait_value {
15651565
let gl = &self.shared.context.lock();
1566+
// MAX_CLIENT_WAIT_TIMEOUT_WEBGL is:
1567+
// - 1s in Gecko https://searchfox.org/mozilla-central/rev/754074e05178e017ef6c3d8e30428ffa8f1b794d/dom/canvas/WebGLTypes.h#1386
1568+
// - 0 in WebKit https://github.com/WebKit/WebKit/blob/4ef90d4672ca50267c0971b85db403d9684508ea/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp#L110
1569+
// - 0 in Chromium https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webgl/webgl2_rendering_context_base.cc;l=112;drc=a3cb0ac4c71ec04abfeaed199e5d63230eca2551
15661570
let timeout_ns = if cfg!(any(webgl, Emscripten)) {
15671571
0
15681572
} else {

0 commit comments

Comments
 (0)