/ concept-collection / math-webgpu-sandbox
Sign in
concept-collection / math-webgpu-sandbox
math-webgpu-sandbox / scripts / test-node.ts
39 lines · 1.3 KBBlameHistoryRaw
1/**
2 * The shared correctness suite on desktop WebGPU (Dawn). Run: npm run test:node
3 *
4 * `--skip-without-gpu` exits 0 when no adapter exists (CI runners without a
5 * GPU for Node; the browser suite still covers everything on SwiftShader).
6 */
7import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts';
8import { runCases } from '../test/cases.ts';
10async function main(): Promise<void> {
11 const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
12 try {
13 console.log(await installWebGpu());
14 } catch (e) {
15 console.error(errMsg(e));
16 process.exit(skipWithoutGpu ? 0 : 1);
17 }
18 const adapter = await navigator.gpu.requestAdapter();
19 if (!adapter) {
20 console.error('no WebGPU adapter\n' + NO_ADAPTER_HINT);
21 process.exit(skipWithoutGpu ? 0 : 1);
22 }
23 const device = await adapter.requestDevice({
24 requiredLimits: {
25 maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
26 maxBufferSize: adapter.limits.maxBufferSize,
27 maxStorageBuffersPerShaderStage: adapter.limits.maxStorageBuffersPerShaderStage,
28 },
29 });
31 const failures = await runCases(device, (line) => console.log(line));
32 console.log(failures ? `\n${failures} failure(s)` : '\nall tests passed');
33 process.exit(failures ? 1 : 0);
36main().catch((e) => {
37 console.error(e);
38 process.exit(1);
39});
moveopenescclose