File size: 648 Bytes
6af9568
552351c
0870851
594b86d
 
0870851
594b86d
552351c
0870851
 
 
 
552351c
 
594b86d
 
 
 
552351c
6af9568
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// wgpu-device.js

export async function initializeDevice(state) {
    state.webgpu.context = state.canvas.getContext('webgpu');
    state.webgpu.device = await state.webgpu.adapter?.requestDevice();
    
    if (!state.webgpu.device) {
        alert('need a browser that supports WebGPU');
        state.webgpu.device = null;
        state.webgpu.context = null;
        state.webgpu.presentationFormat = null;
        return;
    }

    state.webgpu.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
    state.webgpu.context.configure({
        device: state.webgpu.device,
        format: state.webgpu.presentationFormat,
    });
}