Spaces:
Running
Running
Update gpu.js
Browse files
gpu.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
| 1 |
export async function initGPU() {
|
| 2 |
-
if (!navigator.gpu)
|
| 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 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 |
});
|
|
|
|
| 1 |
export async function initGPU() {
|
| 2 |
+
if (!navigator.gpu) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
return { mode: "cpu" };
|
| 4 |
}
|
| 5 |
+
|
| 6 |
+
const adapter = await navigator.gpu.requestAdapter();
|
| 7 |
+
const device = await adapter.requestDevice();
|
| 8 |
+
return { mode: "gpu", device };
|
| 9 |
}
|
| 10 |
|
| 11 |
export function createCompute(device, code) {
|
|
|
|
|
|
|
| 12 |
return device.createComputePipeline({
|
| 13 |
layout: "auto",
|
| 14 |
compute: {
|
| 15 |
+
module: device.createShaderModule({ code }),
|
| 16 |
entryPoint: "main"
|
| 17 |
}
|
| 18 |
});
|