Skip to content

Commit ab8fd9e

Browse files
committed
[web] fix device lost handler
1 parent 94661a4 commit ab8fd9e

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,16 @@ if (onnxruntime_USE_WEBGPU)
752752
#
753753
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/safari_polyfill.patch &&
754754

755+
# The dawn_device_lost_keepalive.patch contains the following changes:
756+
#
757+
# - (private) Fix premature ABORT when device.lost fires in callUserCallback
758+
# The device.lost handler was wrapped in callUserCallback without runtimeKeepalivePush/Pop,
759+
# causing maybeExit() to trigger _exit(0) and set ABORT=true when runtimeKeepaliveCounter
760+
# was 0. This silently dropped all subsequent WebGPU callbacks (e.g. requestAdapter),
761+
# breaking session re-creation after device destruction.
762+
#
763+
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn_device_lost_keepalive.patch &&
764+
755765
# The dawn_dxc_output_dir.patch contains the following changes:
756766
#
757767
# - (private) Fix DXC output directory for RelWithDebInfo and MinSizeRel configs
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/third_party/emdawnwebgpu/pkg/webgpu/src/library_webgpu.js b/third_party/emdawnwebgpu/pkg/webgpu/src/library_webgpu.js
2+
--- a/third_party/emdawnwebgpu/pkg/webgpu/src/library_webgpu.js
3+
+++ b/third_party/emdawnwebgpu/pkg/webgpu/src/library_webgpu.js
4+
@@ -876,9 +876,11 @@
5+
#if ASSERTIONS
6+
assert(deviceLostFutureId);
7+
#endif
8+
- // Don't keepalive here, because this isn't guaranteed to ever happen.
9+
+ // Keep the runtime alive until device.lost resolves, to prevent
10+
+ // maybeExit() from triggering premature ABORT during callUserCallback.
11+
+ {{{ runtimeKeepalivePush() }}}
12+
WebGPU.Internals.futureInsert(deviceLostFutureId, device.lost.then((info) => {
13+
// If the runtime has exited, avoid calling callUserCallback as it
14+
// will print an error (e.g. if the device got freed during shutdown).
15+
@@ -891,6 +893,7 @@
16+
{{{ gpu.passAsPointer('messagePtr') }}});
17+
stackRestore(sp);
18+
});
19+
+ {{{ runtimeKeepalivePop() }}}
20+
}));
21+
22+
// Set up uncaptured error handlers.

0 commit comments

Comments
 (0)