3D engine that AI agents drive
Merge origin/main into feat/625-webgpu-backend
Nguyen Xuan An71950809664b
diff --cc bench/native-tracer/compare.shindex 00000000,debf71ad..2bc60e9emode 000000,100644..100644--- a/bench/native-tracer/compare.sh+++ b/bench/native-tracer/compare.sh@@@ -1,0 -1,14 +1,14 @@@+ #!/usr/bin/env bash+ # Alternates the native tracer and the browser WGSL kernel three times at 1920 by 1080 and 64 samples, each trace as its own+ # gpu-lock job, then scores FLIP between each pair. It needs bench/webgpu-tracer from issue #625 (pull request #629).+ # bash bench/native-tracer/compare.sh <output directory>+ set -u+ # GPU_LOCK, when set, prefixes each trace, for example a queue that serialises jobs on a shared card.+ OUT="${1:?output directory}"+ for RUN in 1 2 3; do+ ${GPU_LOCK:-} node bench/native-tracer/run.mjs "$OUT" --label "run$RUN" 2>&1 | cut -c1-1500- ${GPU_LOCK:-} node bench/webgpu-tracer/run.mjs "$OUT" webgpu --label "run$RUN" 2>&1 | cut -c1-1500++ ${GPU_LOCK:-} node bench/webgpu-tracer/run.mjs "$OUT" megakernel --label "run$RUN" 2>&1 | cut -c1-1500+ done+ for RUN in 1 2 3; do- echo "flip run$RUN native vs webgpu: $(uv run --no-project --python 3.12 --with flip-evaluator --with pillow --with numpy python -I bench/webgpu-tracer/flip.py "$OUT/webgpu-run$RUN.png" "$OUT/native-run$RUN.png")"++ echo "flip run$RUN native vs WebGPU megakernel: $(uv run --no-project --python 3.12 --with flip-evaluator --with pillow --with numpy python -I bench/webgpu-tracer/flip.py "$OUT/megakernel-run$RUN.png" "$OUT/native-run$RUN.png")"+ donediff --cc bench/webgpu-tracer/compare.shindex d2c1f41a,be0bf9dc..23464ff9--- a/bench/webgpu-tracer/compare.sh+++ b/bench/webgpu-tracer/compare.sh@@@ -3,11 -3,11 +3,11 @@@# The first pair runs in fresh Chrome profiles (cold shader caches), the later pairs reuse them (warm).# bash bench/webgpu-tracer/compare.sh <output directory>set -u- GPU_LOCK="${GPU_LOCK:-gpu-lock.sh}" # path of the machine GPU lock script+ # GPU_LOCK, when set, prefixes each trace, for example a queue that serialises jobs on a shared card.OUT="${1:?output directory}"-rm -rf "$OUT/profile-webgl" "$OUT/profile-webgpu"+rm -rf "$OUT/profile-webgl" "$OUT/profile-wavefront" "$OUT/profile-megakernel"for RUN in 1 2 3; do- for VARIANT in webgpu webgl; do+ for VARIANT in wavefront megakernel webgl; do- bash "$GPU_LOCK" node bench/webgpu-tracer/run.mjs "$OUT" "$VARIANT" --label "run$RUN" 2>&1 | cut -c1-1500+ ${GPU_LOCK:-} node bench/webgpu-tracer/run.mjs "$OUT" "$VARIANT" --label "run$RUN" 2>&1 | cut -c1-1500donedonediff --cc bench/webgpu-tracer/run.mjsindex 390a0bb9,4d5df8b3..54eddf67--- a/bench/webgpu-tracer/run.mjs+++ b/bench/webgpu-tracer/run.mjs@@@ -1,6 -1,6 +1,6 @@@// One timed trace of the demo room with one backend, in a headless Chrome whose profile persists per backend (so the first- // run in a fresh profile is the cold compile and later runs are warm). Run it through the GPU lock script (gpu-lock.sh).+ // run in a fresh profile is the cold compile and later runs are warm). On a shared card, run it through a GPU job queue.-// node bench/webgpu-tracer/run.mjs <output directory> <webgl|webgpu> [--samples 64] [--width 1920] [--height 1080] [--label run1]+// node bench/webgpu-tracer/run.mjs <output directory> <webgl|wavefront|megakernel> [--samples 64] [--width 1920] [--height 1080] [--label run1] [--sort on|off]// Writes <variant>-<label>.png and <variant>-<label>.json; the profile lives in <output directory>/profile-<variant>.import { mkdir, readFile, writeFile } from 'node:fs/promises';import { constants, setPriority } from 'node:os';diff --cc src/path-tracer.jsindex c08a7367,2b119cc9..2abe8e3d--- a/src/path-tracer.js+++ b/src/path-tracer.js@@@ -106,7 -107,12 +110,12 @@@ export function normalizePathTracerOpti};result.denoise = result.denoiser !== 'none';if (!VIEW_TRANSFORM_NAMES.includes(result.viewTransform)) throw new RangeError(`Path tracer viewTransform must be one of ${VIEW_TRANSFORM_NAMES.join(', ')}.`);- if (result.backend !== 'cpu' && result.backend !== 'gpu') throw new TypeError('Path tracer backend must be "cpu" or "gpu".');+ if (!PATH_TRACER_BACKENDS.includes(result.backend)) throw new TypeError('Path tracer backend must be "cpu", "gpu" or "webgpu".');+ if (!SAMPLING_PATTERNS.includes(result.samplingPattern)) throw new RangeError(`Path tracer samplingPattern must be one of ${SAMPLING_PATTERNS.join(', ')}.`);+ if (!LIGHT_SELECTIONS.includes(result.lightSelection)) throw new RangeError(`Path tracer lightSelection must be one of ${LIGHT_SELECTIONS.join(', ')}.`);- if (result.backend === 'cpu' && (result.samplingPattern !== 'random' || result.lightSelection !== 'uniform')) {- throw new RangeError('Path tracer samplingPattern "blue-noise-first" and lightSelection "importance" need backend "gpu"; the CPU reference draws random samples and picks lights uniformly.');++ if (result.backend !== 'gpu' && (result.samplingPattern !== 'random' || result.lightSelection !== 'uniform')) {++ throw new RangeError('Path tracer samplingPattern "blue-noise-first" and lightSelection "importance" need backend "gpu"; the CPU reference and the WebGPU tracer draw random samples and pick lights uniformly.');+ }if (result.width * result.height > MAX_TRACE_PIXELS) throw new RangeError(`A path trace takes at most ${MAX_TRACE_PIXELS} pixels.`);if (result.width * result.height * result.samples * (result.bounces + 1) > MAX_TRACE_RAY_WORK) throw new RangeError('This path trace would need too much ray work: lower the size, samples or bounces.');return result;