Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Record two SwiftShader frame experiments that did not pay (Part of #74)

Nguyen Xuan An197017519ee9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35074dd7..4609a6e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Try two exact-picture speed-ups for the SwiftShader frame and keep neither (part of issue #74, which stays open; no engine change). Drawing the environment background after the opaque pass on the far plane, and fetching the post pass's extra FXAA taps only on edges, both moved `instanced-objects` inside the noise (medians 379 to 377 ms and 388 to 386 ms over three alternated pairs). Current ratios against three.js on SwiftShader: `large-mesh` 6.0, `many-materials` 5.0, `instanced-objects` 7.0, so the 3 times target is not met. `bench/runtime/PROFILE.md` records why: a shader that returns the base colour still costs about 4 times three.js, so the rest needs MSAA, the HDR target or the shadow filter to change, which change the picture.
+
- Let the path tracer stop converged pixels, draw normal and roughness maps on box-projected materials, and finish a 1080p still (part of issue #129, which stays open). `noiseThreshold` (0 to 1, default 0.03, 0 draws every sample) stops a pixel once the standard error of its mean luminance is under that share of the mean plus 0.05, checked from 16 samples on and after every 8 more; the decision reads only the pixel's own samples, so bands and thread counts still give the same bytes, and `report.averageSamples` says what was used. Shadow rays no longer interpolate the surface they hit unless it is a cutout (pixels unchanged, 1.23 to 1.36 times faster per thread on the demo room). Box-projected parts are traced with the UVs of their projection (`boxProjectedGeometry`, with `columnLengths` now exported from `src/export-box-uv.js`), so their colour, normal and metallic-roughness maps are all read (before, a box-projected colour map read one texel); `report.ignored` no longer lists them. Render jobs may set `maxSeconds` up to 600 (was 240; the deadline is `maxSeconds` plus 60 s): the 1920 by 1080, 64 sample still of `tests/fixtures/demo-room.recipe.json` took 246.4 s in the tracer (30.7 samples per pixel on average, 8 threads, 257 s per job), 6 s past the old limit. Measured, and not all good: at 24 fixed samples with the filter `brick-graph` is 0.0024 and `character` 0.0048 worse than at 64; adaptive sampling costs `spot-area` 0.0658 to 0.0900 against Cycles at the default threshold; drawing one light at the first hit was tried and dropped (twice as fast, 66 percent more error). `brick-graph` did not improve against the same tracer at 64 samples (0.1370 to 0.1373); the darker floor of `character` and `outdoor-hdri` was narrowed but not found. `bench/reference/run.mjs` takes `--noise-threshold` and records `averageSamples`. Core did not change.
- Read the textures inside glTF layer extensions and accept TEXCOORD_1 (part of issue #51). `clearcoatTexture`, `clearcoatRoughnessTexture`, `clearcoatNormalTexture`, `anisotropyTexture`, `sheenColorTexture` and `sheenRoughnessTexture` load into `material.layerMaps` and draw through shader features in `material-layer-shaders`, and `exportGlb` writes them back. Occlusion, emissive and metallic-roughness textures may read TEXCOORD_1. Against Cycles, `AnisotropyBarnLamp` goes from 0.4758 to 0.3584, `AnisotropyDiscTest` from 0.3481 to 0.2808 and `ClearCoatTest` from 0.2344 to 0.2306; `TransmissionTest` is unchanged and `SheenChair` still waits on per-map texture transforms. The core entry grows by about 345 bytes gzip.
diff --git a/bench/runtime/PROFILE.md b/bench/runtime/PROFILE.md
index 0e3dd835..973c35e9 100644
--- a/bench/runtime/PROFILE.md
+++ b/bench/runtime/PROFILE.md
@@ -107,6 +107,27 @@ So: the passes around the mesh cost 1.3 ms, three.js's whole frame is 0.6, and a
**One change tried and reverted.** Skipping the two fill-light `illuminate` calls when `fillIntensity` is 0 (the benchmark's value). SwiftShader frame, one run each: `large-mesh` 1,684 to 1,338 (this scene swings by 20 percent between runs), `many-materials` 1,219 to 1,233, `instanced-objects` 376 to 383. Inside the noise on two of three scenes, so it was not kept.
+## Two more changes tried, neither kept (2026-11-01, branch `perf/swiftshader-frame`)
+
+Method: the changed file and the unchanged file were swapped in `src/` between runs, A then B, three pairs, `--cpu-only --frames 6`, median of the three. The machine was shared with other sessions (the RTX 3060 was 78 percent busy before the first run; SwiftShader runs on the CPU, whose load was not measured), so a difference under about 5 percent is noise here.
+
+| Change (all would give identical pictures) | Scene | Before (ms, 3 runs) | After (ms, 3 runs) | Kept |
+| --- | --- | --- | --- | --- |
+| Draw the environment background after the opaque pass, on the far plane, with the depth test on, so covered pixels skip its shader | `instanced-objects` | 381, 379, 376 | 375, 377, 383 | No |
+| Post pass: fetch the four extra FXAA taps only where an edge is found (the other pixels used `center` anyway), reuse the centre sample's alpha | `instanced-objects` | 386, 388, 402 | 552 (load spike), 375, 386 | No |
+
+Both medians are inside the noise, so neither was committed and the reference images were not needed again (the engine is unchanged; the 16 baseline renders were taken first and no code differs from them).
+
+**Current numbers, SwiftShader frame in ms, 3 runs each, 67js and three.js alternated** (a loop over `--scene` and `--engine`, script not kept in the repository):
+
+| Scene | 67js | three.js | Ratio (medians) |
+| --- | --- | --- | --- |
+| `large-mesh` | 1,327, 1,336, 1,431 | 219, 221, 232 | 6.0 |
+| `many-materials` | 1,216, 1,227, 1,254 | 238, 246, 256 | 5.0 |
+| `instanced-objects` | 376, 386, 390 | 54, 55, 55 | 7.0 |
+
+**Why 3 times is not reachable without changing the picture.** Three facts measured earlier in this file set the floor. A fragment shader that returns the base colour still takes 195 ms on `instanced-objects` (frame 620 ms then), which is 3.5 to 4 times three.js's 48 to 55 ms before any lighting is paid for; that floor is the 4 sample HDR target, the 49,850 triangles, the clear and the resolve. With one sample and no HDR target the whole frame is 194 ms (5.2 times three.js with one sample). The two passes that three.js does not draw, the environment background and the post pass, cost about 45 ms each when drawn alone, but the two experiments above show that trimming them does not move the frame beyond the noise. What is left in the lit shader (shadow filter, environment lookup, three lights) is 5 to 8 percent per block (profile above), so removing one block cannot close a gap of 2.3 times. The remaining routes all change the picture or the frame format: no MSAA (about 40 percent), LDR target (about 20 percent), fewer shadow taps (visible penumbra), or a quarter-resolution sky.
+
## Left
- A SwiftShader frame is still 4.5 to 7 times three.js, not 3. What remains is the per-pixel cost of the lit shader with 4 MSAA samples and an HDR target. Ideas that change the cost without changing the picture: a cheaper path for parts that are flat colour with no maps, and sharing one shadow comparison across the 3 by 3 filter. Both need the pictures checked again.