1/** The GPU device, requested the same way everywhere (app and scripts). */
2export async function requestAcousticDevice(): Promise<GPUDevice> {
3 if (!navigator.gpu) {
4 throw new Error(
5 'this browser has no WebGPU. Chrome and Edge 113+, Safari 26+, and ' +
6 'Firefox 141+ on Windows have it; on Linux Firefox and Chrome may need ' +
7 'it enabled explicitly.',
8 );
9 }
10 const adapter = await navigator.gpu.requestAdapter({ powerPreference: 'high-performance' });
11 if (!adapter) throw new Error('WebGPU found no adapter on this machine.');
13 // A field of 192^3 f32 is 28 MB and there are four of them, so the default
14 // 128 MB buffer limit and 256 MB total are both too small at the top grid
15 // size. Ask for what the adapter will give.
16 const lim = adapter.limits;
17 return adapter.requestDevice({
18 requiredLimits: {
19 maxStorageBufferBindingSize: lim.maxStorageBufferBindingSize,
20 maxBufferSize: lim.maxBufferSize,
21 },
22 });
23}
25/** Largest cube side this device can hold four fields of. */
26export function maxGridSide(device: GPUDevice): number {
27 const perField = device.limits.maxStorageBufferBindingSize;
28 for (const n of [192, 160, 128, 96, 64]) {
29 if (4 * n * n * n <= perField) return n;
30 }
31 return 64;
32}