@@ -362,6 +362,7 @@ typedef struct WebGPURenderer
362
362
WGPUInstance instance ;
363
363
WGPUAdapter adapter ;
364
364
WGPUDevice device ;
365
+ bool deviceError ;
365
366
WGPUQueue queue ;
366
367
367
368
WindowData * * claimedWindows ;
@@ -1150,9 +1151,11 @@ static void WebGPU_RequestDeviceCallback(WGPURequestDeviceStatus status, WGPUDev
1150
1151
WebGPURenderer * renderer = (WebGPURenderer * )userdata ;
1151
1152
if (status == WGPURequestDeviceStatus_Success ) {
1152
1153
renderer -> device = device ;
1154
+ renderer -> deviceError = false;
1153
1155
SDL_Log ("WebGPU device requested successfully" );
1154
1156
} else {
1155
1157
SDL_LogError (SDL_LOG_CATEGORY_GPU , "Failed to request WebGPU device: %s" , message );
1158
+ renderer -> deviceError = true;
1156
1159
}
1157
1160
}
1158
1161
@@ -1414,6 +1417,8 @@ static void *WebGPU_MapTransferBuffer(
1414
1417
return NULL ;
1415
1418
}
1416
1419
1420
+ // Must be called to yield control to the browser so that it can tick the device for us.
1421
+ // Without this, the mapping operation will never complete.
1417
1422
SDL_Delay (1 );
1418
1423
}
1419
1424
@@ -4458,6 +4463,7 @@ static SDL_GPUDevice *WebGPU_CreateDevice(bool debug, bool preferLowPower, SDL_P
4458
4463
SDL_zero (* renderer );
4459
4464
renderer -> debug = debug ;
4460
4465
renderer -> preferLowPower = preferLowPower ;
4466
+ renderer -> deviceError = false;
4461
4467
4462
4468
// Initialize WebGPU instance so that we can request an adapter and then device
4463
4469
renderer -> instance = wgpuCreateInstance (NULL );
@@ -4480,7 +4486,10 @@ static SDL_GPUDevice *WebGPU_CreateDevice(bool debug, bool preferLowPower, SDL_P
4480
4486
// This seems to be necessary to ensure that the device is created before continuing
4481
4487
// This should probably be tested on all browsers to ensure that it works as expected
4482
4488
// but Chrome's Dawn WebGPU implementation needs this to work
4483
- while (!renderer -> device ) {
4489
+ // See: https://eliemichel.github.io/LearnWebGPU/basic-3d-rendering/input-geometry/playing-with-buffers.html
4490
+ //
4491
+ // This will not loop infinitely as the callback will set the device or deviceError
4492
+ while (!renderer -> device && !renderer -> deviceError ) {
4484
4493
SDL_Delay (1 );
4485
4494
}
4486
4495
0 commit comments