@@ -174,7 +174,7 @@ struct Context; // Forward declaration so that TensorPool can have a pointer to
174
174
* resources.
175
175
*/
176
176
struct TensorPool {
177
- inline TensorPool (Context *ctx) : ctx(ctx), data() {};
177
+ inline TensorPool (Context *ctx) : ctx(ctx), data(){};
178
178
Context *ctx;
179
179
std::unordered_map<WGPUBuffer, Tensor> data;
180
180
~TensorPool ();
@@ -416,7 +416,7 @@ struct KernelPool {
416
416
}
417
417
};
418
418
419
- inline void processEvents (const WGPUInstance& instance) {
419
+ inline void processEvents (const WGPUInstance & instance) {
420
420
#ifdef __EMSCRIPTEN__
421
421
emscripten_sleep (0 );
422
422
#else
@@ -680,15 +680,17 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
680
680
const WGPUDeviceDescriptor &devDescriptor = {}) {
681
681
Context context;
682
682
{
683
- #ifndef __EMSCRIPTEN__
684
- context.instance = wgpuCreateInstance (&desc);
685
- #else
683
+ #ifdef __EMSCRIPTEN__
686
684
// Emscripten does not support the instance descriptor
687
685
// and throws an assertion error if it is not nullptr.
688
686
context.instance = wgpuCreateInstance (nullptr );
687
+ #else
688
+ context.instance = wgpuCreateInstance (&desc);
689
689
#endif
690
+ // check status
690
691
check (context.instance , " Initialize WebGPU" , __FILE__, __LINE__);
691
692
}
693
+
692
694
LOG (kDefLog , kInfo , " Requesting adapter" );
693
695
{
694
696
struct AdapterData {
@@ -700,19 +702,38 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
700
702
WGPUAdapter adapter, char const *message,
701
703
void *pUserData) {
702
704
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\n A 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
703
721
check (status == WGPURequestAdapterStatus_Success,
704
722
" Request WebGPU adapter" , __FILE__, __LINE__);
705
723
adapterData.adapter = adapter;
706
724
adapterData.requestEnded = true ;
707
725
};
726
+
708
727
wgpuInstanceRequestAdapter (context.instance , &adapterOpts,
709
728
onAdapterRequestEnded, (void *)&adapterData);
729
+
710
730
while (!adapterData.requestEnded ) {
711
731
processEvents (context.instance );
712
732
}
713
733
assert (adapterData.requestEnded );
714
734
context.adapter = adapterData.adapter ;
715
735
}
736
+
716
737
LOG (kDefLog , kInfo , " Requesting device" );
717
738
{
718
739
struct DeviceData {
@@ -745,7 +766,6 @@ inline Context createContext(const WGPUInstanceDescriptor &desc = {},
745
766
},
746
767
};
747
768
#endif
748
- LOG (kDefLog , kInfo , " Requesting device" );
749
769
wgpuAdapterRequestDevice (context.adapter , &devDescriptor,
750
770
onDeviceRequestEnded, (void *)&devData);
751
771
LOG (kDefLog , kInfo , " Waiting for device request to end" );
0 commit comments