@@ -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}
12371238void emwgpuOnWorkDoneCompleted (double futureId,
@@ -1382,28 +1383,17 @@ WGPUDeviceImpl::WGPUDeviceImpl(const EventSource* source, WGPUQueue queue)
13821383
13831384void 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
13891388WGPUQueue 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-
14071397void 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+
17361730WGPUQueue wgpuDeviceGetQueue (WGPUDevice device) {
17371731 return device->GetQueue ();
17381732}
0 commit comments