File size: 487 Bytes
d21242b
 
cb68079
 
d21242b
 
 
 
 
 
 
 
 
 
 
cb68079
 
d21242b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export async function initGPU(width, height) {
  if (!navigator.gpu) {
    console.warn("WebGPU not supported, falling back to CPU");
    return null;
  }

  const adapter = await navigator.gpu.requestAdapter();
  const device = await adapter.requestDevice();

  const size = width * height * 4;

  const buffer = device.createBuffer({
    size,
    usage:
      GPUBufferUsage.STORAGE |
      GPUBufferUsage.COPY_SRC |
      GPUBufferUsage.COPY_DST
  });

  return { device, buffer };
}