Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

test(shaders): a switched shader wants a twin, which is what the generator does now

esengine98f3d1f06be9
diff --git a/sdk/tests/shader-twins.test.ts b/sdk/tests/shader-twins.test.ts
index b7e18fce9..f9e2fe1e1 100644
--- a/sdk/tests/shader-twins.test.ts
+++ b/sdk/tests/shader-twins.test.ts
@@ -105,8 +105,11 @@ describe('gen-shader-twins needsTwin / sourceHash (staleness)', () => {
expect(gen.needsTwin(twin(null))).toBe(true));
it('hand-authored (non-full) twin → left alone', () =>
expect(gen.needsTwin(`${glsl}\n#pragma fragment wgsl\n@fragment fn fs_main() { }\n#pragma end\n`)).toBe(false));
- it('#pragma switch shader → never auto-generated', () =>
- expect(gen.needsTwin(`${glsl}#pragma switch FOO default(off)\n`)).toBe(false));
+ // Switched shaders were skipped once, which left a material compiling on one
+ // backend and not the other. The generator emits every combination now, so
+ // one without a twin is missing one like any other shader.
+ it('#pragma switch shader → wants a twin like any other', () =>
+ expect(gen.needsTwin(`${glsl}#pragma switch FOO default(off)\n`)).toBe(true));
it('editing only the twin body does not stale it; editing the GLSL does', () => {
const fresh = twin(gen.sourceHash(glsl));
expect(gen.needsTwin(fresh.replace('fs_main', 'fs_main_x'))).toBe(false);
diff --git a/tools/gen-shader-twins.mjs b/tools/gen-shader-twins.mjs
index f2ed4cc2d..afe299a55 100644
--- a/tools/gen-shader-twins.mjs
+++ b/tools/gen-shader-twins.mjs
@@ -33,9 +33,10 @@
* --check report what would change, write nothing (exit 1 if any)
* --force regenerate even when a twin exists (replaces generated sections)
*
- * Requires: a built engine (pnpm build:web). Shaders using `#pragma switch`
- * are skipped (permutations need per-set twins; hand-author those) — the tool
- * says so per file.
+ * Requires: a built engine (pnpm build:web). A `#pragma switch` or feature is a
+ * toggle: every combination is emitted into one body behind the same `#ifdef`
+ * the GLSL side uses. Past three toggles the file is skipped and says so —
+ * each one doubles the emitted programs.
*/
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';