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