File size: 554 Bytes
c36501e
552351c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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 };
}