LordXido commited on
Commit
c379da4
·
verified ·
1 Parent(s): fd6b1be

Update gpu.js

Browse files
Files changed (1) hide show
  1. gpu.js +14 -16
gpu.js CHANGED
@@ -1,21 +1,19 @@
1
- export async function initGPU(width, height) {
 
2
  if (!navigator.gpu) {
3
- console.warn("WebGPU not supported, falling back to CPU");
4
- return null;
5
  }
6
 
7
- const adapter = await navigator.gpu.requestAdapter();
8
- const device = await adapter.requestDevice();
 
9
 
10
- const size = width * height * 4;
11
-
12
- const buffer = device.createBuffer({
13
- size,
14
- usage:
15
- GPUBufferUsage.STORAGE |
16
- GPUBufferUsage.COPY_SRC |
17
- GPUBufferUsage.COPY_DST
18
- });
19
-
20
- return { device, buffer };
21
  }
 
1
+ // gpu.js v9.2 hardened
2
+ export async function initGPU() {
3
  if (!navigator.gpu) {
4
+ console.warn("[GPU] WebGPU unavailable CPU fallback engaged");
5
+ return { mode: "cpu", device: null };
6
  }
7
 
8
+ try {
9
+ const adapter = await navigator.gpu.requestAdapter();
10
+ if (!adapter) throw new Error("No GPU adapter");
11
 
12
+ const device = await adapter.requestDevice();
13
+ console.log("[GPU] WebGPU initialized");
14
+ return { mode: "gpu", device };
15
+ } catch (e) {
16
+ console.error("[GPU] Initialization failed:", e);
17
+ return { mode: "cpu", device: null };
18
+ }
 
 
 
 
19
  }