Skip to content

Commit

Permalink
Try compat in workers
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Feb 2, 2024
1 parent a5f1762 commit 1778687
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 26 additions & 12 deletions worker.js
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down

0 comments on commit 1778687

Please sign in to comment.