plasma-arc / wgpu-device.js
p3nGu1nZz's picture
🌟 feat: Modularize WebGPU initialization
6af9568
raw
history blame
554 Bytes
// wgpu-device.js
export async function initializeDevice(navigator, adapter, canvas) {
const context = canvas.getContext('webgpu');
const device = await adapter?.requestDevice();
if (!device) {
alert('need a browser that supports WebGPU');
return { device: null, context: null, presentationFormat: null };
}
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
context.configure({
device,
format: presentationFormat,
});
return { device, context, presentationFormat };
}