Spaces:
Running
Running
// wgpu-device.js | |
export async function initializeDevice(state) { | |
const context = state.canvas.getContext('webgpu'); | |
const device = await state.webgpu.adapter?.requestDevice(); | |
if (!device) { | |
alert('need a browser that supports WebGPU'); | |
state.webgpu.device = null; | |
state.webgpu.context = null; | |
state.webgpu.presentationFormat = null; | |
return; | |
} | |
const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); | |
context.configure({ | |
device, | |
format: presentationFormat, | |
}); | |
state.webgpu.device = device; | |
state.webgpu.context = context; | |
state.webgpu.presentationFormat = presentationFormat; | |
} | |