Skip to content

Commit 24caba0

Browse files
committed
Breadcrumb error message in event of adapter request failure for emscripten web build - a likely issue is webgpu and vulkan not being enabled in chrome by default in linux
1 parent ef94dd8 commit 24caba0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

gpu.h

+26-6
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct Context; // Forward declaration so that TensorPool can have a pointer to
174174
* resources.
175175
*/
176176
struct TensorPool {
177-
inline TensorPool(Context *ctx) : ctx(ctx), data() {};
177+
inline TensorPool(Context *ctx) : ctx(ctx), data(){};
178178
Context *ctx;
179179
std::unordered_map<WGPUBuffer, Tensor> data;
180180
~TensorPool();
@@ -416,7 +416,7 @@ struct KernelPool {
416416
}
417417
};
418418

419-
inline void processEvents(const WGPUInstance& instance) {
419+
inline void processEvents(const WGPUInstance &instance) {
420420
#ifdef __EMSCRIPTEN__
421421
emscripten_sleep(0);
422422
#else
@@ -680,15 +680,17 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
680680
const WGPUDeviceDescriptor &devDescriptor = {}) {
681681
Context context;
682682
{
683-
#ifndef __EMSCRIPTEN__
684-
context.instance = wgpuCreateInstance(&desc);
685-
#else
683+
#ifdef __EMSCRIPTEN__
686684
// Emscripten does not support the instance descriptor
687685
// and throws an assertion error if it is not nullptr.
688686
context.instance = wgpuCreateInstance(nullptr);
687+
#else
688+
context.instance = wgpuCreateInstance(&desc);
689689
#endif
690+
// check status
690691
check(context.instance, "Initialize WebGPU", __FILE__, __LINE__);
691692
}
693+
692694
LOG(kDefLog, kInfo, "Requesting adapter");
693695
{
694696
struct AdapterData {
@@ -700,19 +702,38 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
700702
WGPUAdapter adapter, char const *message,
701703
void *pUserData) {
702704
AdapterData &adapterData = *reinterpret_cast<AdapterData *>(pUserData);
705+
LOG(kDefLog, kInfo, "WGPURequestAdapterStatus_Success: %d",
706+
WGPURequestAdapterStatus_Success);
707+
LOG(kDefLog, kInfo, "WGPURequestAdapterStatus_Unavailable: %d",
708+
WGPURequestAdapterStatus_Unavailable);
709+
LOG(kDefLog, kInfo, "Status: %d", status);
710+
#ifdef __EMSCRIPTEN__
711+
if (status != WGPURequestAdapterStatus_Success) {
712+
LOG(kDefLog, kError, "Could not get WebGPU adapter: %s", message);
713+
LOG(kDefLog, kError,
714+
"\n\nA common reason is that the browser does not have WebGPU "
715+
"enabled, particularly on Linux.\n"
716+
"- Open `chrome://flags/` in the browser and make sure "
717+
"\"WebGPU Support\" is enabled.\n"
718+
"- Chrome is launched with vulkan enabled. From the command line launch chrome as `google-chrome --enable-features=Vulkan`\n");
719+
}
720+
#endif
703721
check(status == WGPURequestAdapterStatus_Success,
704722
"Request WebGPU adapter", __FILE__, __LINE__);
705723
adapterData.adapter = adapter;
706724
adapterData.requestEnded = true;
707725
};
726+
708727
wgpuInstanceRequestAdapter(context.instance, &adapterOpts,
709728
onAdapterRequestEnded, (void *)&adapterData);
729+
710730
while (!adapterData.requestEnded) {
711731
processEvents(context.instance);
712732
}
713733
assert(adapterData.requestEnded);
714734
context.adapter = adapterData.adapter;
715735
}
736+
716737
LOG(kDefLog, kInfo, "Requesting device");
717738
{
718739
struct DeviceData {
@@ -745,7 +766,6 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
745766
},
746767
};
747768
#endif
748-
LOG(kDefLog, kInfo, "Requesting device");
749769
wgpuAdapterRequestDevice(context.adapter, &devDescriptor,
750770
onDeviceRequestEnded, (void *)&devData);
751771
LOG(kDefLog, kInfo, "Waiting for device request to end");

0 commit comments

Comments
 (0)