plasma-arc / wgpu-device.js
p3nGu1nZz's picture
rename filenames
46ec188
raw
history blame
554 Bytes
// wgpu-devices.js
export async function initializeWebGPU(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 };
}