diff --git a/index.js b/index.js index ec4c8da..7aec971 100644 --- a/index.js +++ b/index.js @@ -444,10 +444,10 @@ async function checkWorkers(workerType) { ])); return; } - const {rAF, gpu, adapter, device, context, offscreen: offscreenSupported, twoD } = await worker.getMessage('checkWebGPU', {canvas: offscreenCanvas}, [offscreenCanvas]); + const {rAF, gpu, adapter, device, compat, context, offscreen: offscreenSupported, twoD } = await worker.getMessage('checkWebGPU', {canvas: offscreenCanvas}, [offscreenCanvas]); addSupportsRow('webgpu API', gpu, 'exists', 'n/a'); if (gpu) { - addSupportsRow('requestAdapter', adapter); + addSupportsRow(`requestAdapter${compat ? '(compat)' : ''}`, adapter); if (adapter) { addSupportsRow('requestDevice', device); if (context) { diff --git a/worker.js b/worker.js index d1d6577..a605f04 100644 --- a/worker.js +++ b/worker.js @@ -1,20 +1,34 @@ +async function createWebGPUDevice(adapterDesc, results) { + const adapter = await navigator.gpu.requestAdapter(adapterDesc); + if (adapter) { + results.adapter = true; + const device = await adapter.requestDevice(); + if (device) { + results.device = true; + const {canvas} = data; + if (canvas) { + results.context = !!canvas.getContext('webgpu'); + } + } + } +} + async function checkWebGPU(id, data) { const results = {} if (navigator.gpu) { results.gpu = true; + } + + try { + createWebGPUDevice({}, results); + } catch (e) { + results.error = (e.message || e).toString(); + } + + if (!results.adapter) { try { - const adapter = await navigator.gpu.requestAdapter(); - if (adapter) { - results.adapter = true; - const device = await adapter.requestDevice(); - if (device) { - results.device = true; - const {canvas} = data; - if (canvas) { - results.context = !!canvas.getContext('webgpu'); - } - } - } + createWebGPUDevice({compatibilityMode: true}, results); + results.compat = true; } catch (e) { results.error = (e.message || e).toString(); }