test_basic_canvas.worker.js (788B)
1 self.addEventListener("message", async function (event) { 2 try { 3 const offscreen = event.data.offscreen; 4 const context = offscreen.getContext("webgpu"); 5 6 const swapChainFormat = navigator.gpu.getPreferredCanvasFormat(); 7 const adapter = await navigator.gpu.requestAdapter(); 8 const device = await adapter.requestDevice(); 9 10 context.configure({ 11 device, 12 format: swapChainFormat, 13 size: { width: 100, height: 100, depth: 1 }, 14 }); 15 16 const texture = context.getCurrentTexture(); 17 18 self.postMessage([ 19 { 20 value: texture !== undefined, 21 message: "texture !== undefined", 22 }, 23 ]); 24 } catch (e) { 25 self.postMessage([ 26 { 27 value: false, 28 message: "Unhandled exception " + e, 29 }, 30 ]); 31 } 32 });