LordXido commited on
Commit
da2b37f
·
verified ·
1 Parent(s): d278682

Update gpu.js

Browse files
Files changed (1) hide show
  1. gpu.js +13 -14
gpu.js CHANGED
@@ -1,26 +1,25 @@
1
- export async function initGPU(canvas) {
2
- if (!navigator.gpu) {
3
- return { mode: "cpu" };
4
- }
5
-
6
- const adapter = await navigator.gpu.requestAdapter();
7
- if (!adapter) return { mode: "cpu" };
8
 
9
- const device = await adapter.requestDevice();
 
 
10
 
11
- return { mode: "gpu", device };
 
 
 
 
12
  }
13
 
14
- export async function createCompute(device, wgslSource) {
15
- const module = device.createShaderModule({ code: wgslSource });
16
 
17
- const pipeline = device.createComputePipeline({
18
  layout: "auto",
19
  compute: {
20
  module,
21
  entryPoint: "main"
22
  }
23
  });
24
-
25
- return pipeline;
26
  }
 
1
+ export async function initGPU() {
2
+ if (!navigator.gpu) return { mode: "cpu" };
 
 
 
 
 
3
 
4
+ try {
5
+ const adapter = await navigator.gpu.requestAdapter();
6
+ if (!adapter) return { mode: "cpu" };
7
 
8
+ const device = await adapter.requestDevice();
9
+ return { mode: "gpu", device };
10
+ } catch {
11
+ return { mode: "cpu" };
12
+ }
13
  }
14
 
15
+ export async function createCompute(device, code) {
16
+ const module = device.createShaderModule({ code });
17
 
18
+ return device.createComputePipeline({
19
  layout: "auto",
20
  compute: {
21
  module,
22
  entryPoint: "main"
23
  }
24
  });
 
 
25
  }