Skip to content

Commit 5418546

Browse files
lokokungDawn LUCI CQ
authored andcommitted
[dawn][emscripten] Add device lost future getter.
- Adds a non-standardized (yet?) getter for the device lost future in order to support testing in Emscripten. Bug: 374803367 Change-Id: I659281c88709dd3d1aa566985998267c54ea3a7d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/211938 Reviewed-by: Kai Ninomiya <[email protected]> Reviewed-by: Corentin Wallez <[email protected]> Commit-Queue: Loko Kung <[email protected]>
1 parent bfb2456 commit 5418546

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/dawn/dawn.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,11 @@
15461546
{"name": "limits", "type": "supported limits", "annotation": "*"}
15471547
]
15481548
},
1549+
{
1550+
"name": "get lost future",
1551+
"returns": "future",
1552+
"tags": ["emscripten"]
1553+
},
15491554
{
15501555
"name": "has feature",
15511556
"returns": "bool",

third_party/emdawnwebgpu/webgpu.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ class EventManager : NonMovable {
566566

567567
template <typename Event, typename... ReadyArgs>
568568
void SetFutureReady(FutureID futureId, ReadyArgs&&... readyArgs) {
569+
assert(futureId != kNullFutureId);
569570
std::unique_ptr<TrackedEvent> spontaneousEvent;
570571
{
571572
std::unique_lock<std::mutex> lock(mMutex);
@@ -681,9 +682,8 @@ struct WGPUDeviceImpl final : public EventSource,
681682

682683
void Destroy();
683684
WGPUQueue GetQueue() const;
684-
WGPUFuture GetDeviceLostFuture() const;
685+
WGPUFuture GetLostFuture() const;
685686

686-
void OnDeviceLost(WGPUDeviceLostReason reason, const char* message);
687687
void OnUncapturedError(WGPUErrorType type, char const* message);
688688

689689
private:
@@ -1228,10 +1228,11 @@ void emwgpuOnRequestDeviceCompleted(double futureId,
12281228
device, message);
12291229
} else {
12301230
// If the request failed, we need to resolve the DeviceLostEvent.
1231-
device->OnDeviceLost(WGPUDeviceLostReason_FailedCreation,
1232-
"Device failed at creation.");
12331231
GetEventManager().SetFutureReady<RequestDeviceEvent>(futureId, status,
12341232
nullptr, message);
1233+
GetEventManager().SetFutureReady<DeviceLostEvent>(
1234+
device->GetLostFuture().id, WGPUDeviceLostReason_FailedCreation,
1235+
"Device failed at creation.");
12351236
}
12361237
}
12371238
void emwgpuOnWorkDoneCompleted(double futureId,
@@ -1382,28 +1383,17 @@ WGPUDeviceImpl::WGPUDeviceImpl(const EventSource* source, WGPUQueue queue)
13821383

13831384
void WGPUDeviceImpl::Destroy() {
13841385
emwgpuDeviceDestroy(this);
1385-
// TODO(374803367): Remove this when we can get the device lost future.
1386-
OnDeviceLost(WGPUDeviceLostReason_Destroyed, "Device was destroyed.");
13871386
}
13881387

13891388
WGPUQueue WGPUDeviceImpl::GetQueue() const {
13901389
auto queue = mQueue;
13911390
return ReturnToAPI(std::move(queue));
13921391
}
13931392

1394-
WGPUFuture WGPUDeviceImpl::GetDeviceLostFuture() const {
1393+
WGPUFuture WGPUDeviceImpl::GetLostFuture() const {
13951394
return WGPUFuture{mDeviceLostFutureId};
13961395
}
13971396

1398-
void WGPUDeviceImpl::OnDeviceLost(WGPUDeviceLostReason reason,
1399-
const char* message) {
1400-
if (mDeviceLostFutureId != kNullFutureId) {
1401-
GetEventManager().SetFutureReady<DeviceLostEvent>(mDeviceLostFutureId,
1402-
reason, message);
1403-
}
1404-
mDeviceLostFutureId = kNullFutureId;
1405-
}
1406-
14071397
void WGPUDeviceImpl::OnUncapturedError(WGPUErrorType type,
14081398
char const* message) {
14091399
if (mUncapturedErrorCallbackInfo.callback) {
@@ -1576,7 +1566,7 @@ WGPUFuture wgpuAdapterRequestDevice2(
15761566
// Device is also immediately associated with the DeviceLostEvent.
15771567
WGPUQueue queue = new WGPUQueueImpl(adapter);
15781568
WGPUDevice device = new WGPUDeviceImpl(adapter, descriptor, queue);
1579-
auto deviceLostFutureId = device->GetDeviceLostFuture().id;
1569+
auto deviceLostFutureId = device->GetLostFuture().id;
15801570

15811571
emwgpuAdapterRequestDevice(adapter, futureId, deviceLostFutureId, device,
15821572
queue, descriptor);
@@ -1733,6 +1723,10 @@ void wgpuDeviceDestroy(WGPUDevice device) {
17331723
device->Destroy();
17341724
}
17351725

1726+
WGPUFuture wgpuDeviceGetLostFuture(WGPUDevice device) {
1727+
return device->GetLostFuture();
1728+
}
1729+
17361730
WGPUQueue wgpuDeviceGetQueue(WGPUDevice device) {
17371731
return device->GetQueue();
17381732
}

0 commit comments

Comments
 (0)