[dawn][emscripten] Various future fixes for MLDrift.
- Allows passing a descriptor to createInstance, though it will
currently be ignored.
- Introduces a null Instance for now to help ease users that
are injecting the Device. See the bug for more details.
No-Try: true
Bug: 388914937
Change-Id: I5ac816128e341436df4c50c21759ab19c5cc4dfb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/221675
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Auto-Submit: Loko Kung <lokokung@google.com>
diff --git a/third_party/emdawnwebgpu/library_webgpu.js b/third_party/emdawnwebgpu/library_webgpu.js
index 6676c42..c768a27 100644
--- a/third_party/emdawnwebgpu/library_webgpu.js
+++ b/third_party/emdawnwebgpu/library_webgpu.js
@@ -91,13 +91,12 @@
// the jsObject table simple.
bufferOnUnmaps: [],
- // Future to promise management, and temporary list allocated up-front for
- // WaitAny implementation on the promises. Note that all FutureIDs
- // (uint64_t) are passed either as a low and high value or by pointer
- // because they need to be passed back and forth between JS and C++, and JS
- // is currently unable to pass a value to a C++ function as a uint64_t.
- // This might be possible with -sWASM_BIGINT, but I was unable to get that
- // to work properly at the time of writing.
+ // Future to promise management. Note that all FutureIDs (uint64_t) are
+ // passed either as a low and high value or by pointer because they need
+ // to be passed back and forth between JS and C++, and JS is currently
+ // unable to pass a value to a C++ function as a uint64_t. This might be
+ // possible with -sWASM_BIGINT, but I was unable to get that to work
+ // properly at the time of writing.
futures: [],
futureInsert: (futureId, promise) => {
#if ASYNCIFY
diff --git a/third_party/emdawnwebgpu/webgpu.cpp b/third_party/emdawnwebgpu/webgpu.cpp
index 1c44642..ade9435 100644
--- a/third_party/emdawnwebgpu/webgpu.cpp
+++ b/third_party/emdawnwebgpu/webgpu.cpp
@@ -383,6 +383,15 @@
// order to handle Spontaneous events.
class EventManager : NonMovable {
public:
+ EventManager() {
+ // We set up a tracker for events that are registered against a null
+ // Instance because devices may have been created and injected before the
+ // Instance was created.
+ // TODO(crbug.com/388914937): Remove this once users are updated.
+ std::unique_lock<std::mutex> lock(mMutex);
+ mPerInstanceEvents.try_emplace(kNullInstanceId);
+ }
+
void RegisterInstance(InstanceID instance) {
assert(instance);
std::unique_lock<std::mutex> lock(mMutex);
@@ -1529,7 +1538,7 @@
WGPUInstance wgpuCreateInstance(
[[maybe_unused]] const WGPUInstanceDescriptor* descriptor) {
- assert(descriptor == nullptr); // descriptor not implemented yet
+ // TODO: descriptor not implemented yet.
return new WGPUInstanceImpl();
}