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