LordXido commited on
Commit
d21242b
·
verified ·
1 Parent(s): 6a56a28

Create gpu.js

Browse files
Files changed (1) hide show
  1. gpu.js +20 -0
gpu.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export async function initGPU(width, height) {
2
+ if (!navigator.gpu) {
3
+ throw new Error("WebGPU not supported");
4
+ }
5
+
6
+ const adapter = await navigator.gpu.requestAdapter();
7
+ const device = await adapter.requestDevice();
8
+
9
+ const size = width * height * 4;
10
+
11
+ const buffer = device.createBuffer({
12
+ size,
13
+ usage:
14
+ GPUBufferUsage.STORAGE |
15
+ GPUBufferUsage.COPY_DST |
16
+ GPUBufferUsage.COPY_SRC
17
+ });
18
+
19
+ return { device, buffer };
20
+ }