-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebGPUHelpers.js
More file actions
38 lines (31 loc) · 1.13 KB
/
WebGPUHelpers.js
File metadata and controls
38 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export const WebGPUHelpers = {
WORKGROUP_SIZE_1D: 256,
WORKGROUP_SIZE_2D: 16,
initGPUDevice: async (enablePerformanceTimers) => {
if (!navigator.gpu) {
throw new Error("WebGPU not supported on this browser.");
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw new Error("No appropriate GPUAdapter found.");
}
const adapterInfo = adapter.info;
let device;
if (enablePerformanceTimers) {
// Device initialization with performance timers
const canTimestamp = adapter.features.has('timestamp-query');
if (!canTimestamp) {
throw new Error("Timestamps not available. Enable the right flags in your browser.");
}
device = await adapter.requestDevice({
requiredFeatures: ["timestamp-query"]
});
} else {
device = await adapter.requestDevice();
}
if (!device) {
throw new Error("Need a browser that supports WebGPU.");
}
return { adapterInfo, device };
}
}