@aardworx/wombat.rendering 0.9.11 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/runtime/derivedUniforms/codegen.d.ts +8 -0
  2. package/dist/runtime/derivedUniforms/codegen.d.ts.map +1 -0
  3. package/dist/runtime/derivedUniforms/codegen.js +449 -0
  4. package/dist/runtime/derivedUniforms/codegen.js.map +1 -0
  5. package/dist/runtime/derivedUniforms/dispatch.d.ts +14 -93
  6. package/dist/runtime/derivedUniforms/dispatch.d.ts.map +1 -1
  7. package/dist/runtime/derivedUniforms/dispatch.js +123 -299
  8. package/dist/runtime/derivedUniforms/dispatch.js.map +1 -1
  9. package/dist/runtime/derivedUniforms/flatten.d.ts +25 -0
  10. package/dist/runtime/derivedUniforms/flatten.d.ts.map +1 -0
  11. package/dist/runtime/derivedUniforms/flatten.js +71 -0
  12. package/dist/runtime/derivedUniforms/flatten.js.map +1 -0
  13. package/dist/runtime/derivedUniforms/index.d.ts +10 -5
  14. package/dist/runtime/derivedUniforms/index.d.ts.map +1 -1
  15. package/dist/runtime/derivedUniforms/index.js +24 -19
  16. package/dist/runtime/derivedUniforms/index.js.map +1 -1
  17. package/dist/runtime/derivedUniforms/marker.d.ts +76 -0
  18. package/dist/runtime/derivedUniforms/marker.d.ts.map +1 -0
  19. package/dist/runtime/derivedUniforms/marker.js +156 -0
  20. package/dist/runtime/derivedUniforms/marker.js.map +1 -0
  21. package/dist/runtime/derivedUniforms/recipes.d.ts +6 -41
  22. package/dist/runtime/derivedUniforms/recipes.d.ts.map +1 -1
  23. package/dist/runtime/derivedUniforms/recipes.js +53 -129
  24. package/dist/runtime/derivedUniforms/recipes.js.map +1 -1
  25. package/dist/runtime/derivedUniforms/records.d.ts +40 -0
  26. package/dist/runtime/derivedUniforms/records.d.ts.map +1 -0
  27. package/dist/runtime/derivedUniforms/records.js +151 -0
  28. package/dist/runtime/derivedUniforms/records.js.map +1 -0
  29. package/dist/runtime/derivedUniforms/registry.d.ts +33 -0
  30. package/dist/runtime/derivedUniforms/registry.d.ts.map +1 -0
  31. package/dist/runtime/derivedUniforms/registry.js +58 -0
  32. package/dist/runtime/derivedUniforms/registry.js.map +1 -0
  33. package/dist/runtime/derivedUniforms/rule.d.ts +26 -0
  34. package/dist/runtime/derivedUniforms/rule.d.ts.map +1 -0
  35. package/dist/runtime/derivedUniforms/rule.js +35 -0
  36. package/dist/runtime/derivedUniforms/rule.js.map +1 -0
  37. package/dist/runtime/derivedUniforms/sceneIntegration.d.ts +34 -33
  38. package/dist/runtime/derivedUniforms/sceneIntegration.d.ts.map +1 -1
  39. package/dist/runtime/derivedUniforms/sceneIntegration.js +80 -90
  40. package/dist/runtime/derivedUniforms/sceneIntegration.js.map +1 -1
  41. package/dist/runtime/heapScene.d.ts.map +1 -1
  42. package/dist/runtime/heapScene.js +78 -26
  43. package/dist/runtime/heapScene.js.map +1 -1
  44. package/dist/runtime/hybridScene.js +1 -1
  45. package/dist/runtime/hybridScene.js.map +1 -1
  46. package/dist/runtime/index.d.ts +1 -0
  47. package/dist/runtime/index.d.ts.map +1 -1
  48. package/dist/runtime/index.js +2 -0
  49. package/dist/runtime/index.js.map +1 -1
  50. package/dist/runtime/renderTask.js +1 -1
  51. package/dist/runtime/renderTask.js.map +1 -1
  52. package/dist/runtime/runtime.js +1 -1
  53. package/dist/runtime/runtime.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/runtime/derivedUniforms/codegen.ts +477 -0
  56. package/src/runtime/derivedUniforms/dispatch.ts +135 -341
  57. package/src/runtime/derivedUniforms/flatten.ts +89 -0
  58. package/src/runtime/derivedUniforms/index.ts +50 -34
  59. package/src/runtime/derivedUniforms/marker.ts +169 -0
  60. package/src/runtime/derivedUniforms/recipes.ts +63 -155
  61. package/src/runtime/derivedUniforms/records.ts +158 -0
  62. package/src/runtime/derivedUniforms/registry.ts +77 -0
  63. package/src/runtime/derivedUniforms/rule.ts +59 -0
  64. package/src/runtime/derivedUniforms/sceneIntegration.ts +115 -149
  65. package/src/runtime/heapScene.ts +77 -28
  66. package/src/runtime/hybridScene.ts +1 -1
  67. package/src/runtime/index.ts +8 -0
  68. package/src/runtime/renderTask.ts +1 -1
  69. package/src/runtime/runtime.ts +1 -1
  70. package/dist/runtime/derivedUniforms/slotId.d.ts +0 -15
  71. package/dist/runtime/derivedUniforms/slotId.d.ts.map +0 -1
  72. package/dist/runtime/derivedUniforms/slotId.js +0 -30
  73. package/dist/runtime/derivedUniforms/slotId.js.map +0 -1
  74. package/dist/runtime/derivedUniforms/uberKernel.wgsl.d.ts +0 -13
  75. package/dist/runtime/derivedUniforms/uberKernel.wgsl.d.ts.map +0 -1
  76. package/dist/runtime/derivedUniforms/uberKernel.wgsl.js +0 -218
  77. package/dist/runtime/derivedUniforms/uberKernel.wgsl.js.map +0 -1
  78. package/src/runtime/derivedUniforms/slotId.ts +0 -35
  79. package/src/runtime/derivedUniforms/uberKernel.wgsl.ts +0 -220
@@ -1,6 +1,11 @@
1
- export { RecipeId, ALL_RECIPES, DERIVED_UNIFORM_NAMES, recipeIdByName, recipeName, recipeInputs, recipeInputCount, recipeOutput, type ConstituentRef, type RecipeOutput, } from "./recipes.js";
2
- export { ConstituentSlots, DF32_MAT4_BYTES, type SlotIndex, type PairedSlots, type DerivationRecord, type SubscribeFn, } from "./slots.js";
3
- export { DerivedUniformsDispatcher, DerivedUniformsPipeline, RecordsBuffer, uploadConstituentsRange, type DerivedUniformsResources, } from "./dispatch.js";
4
- export { DerivedUniformsScene, registerRoDerivations, deregisterRoDerivations, isDerivedUniformName, type RoTrafoInputs, type RoDerivedRequest, type RoRegistration, } from "./sceneIntegration.js";
5
- export { DERIVED_UBER_KERNEL_WGSL, } from "./uberKernel.wgsl.js";
1
+ export { type DerivedRule, type IRFragment, ruleFromIR, uniformRef, sameType, hashIR, isDerivedRule, } from "./rule.js";
2
+ export { derivedUniform, DerivedExpr, type DerivedScope, } from "./marker.js";
3
+ export { type RuleInput, flatten, inputsOf, } from "./flatten.js";
4
+ export { DerivedUniformRegistry, type RuleEntry, } from "./registry.js";
5
+ export { RecordsBuffer, SlotTag, makeHandle, handleTag, handlePayload, type RecordOwner, } from "./records.js";
6
+ export { buildUberKernel, type UberKernel, } from "./codegen.js";
7
+ export { DerivedUniformsDispatcher, uploadConstituentsRange, type DerivedUniformsResources, } from "./dispatch.js";
8
+ export { ConstituentSlots, DF32_MAT4_BYTES, type SlotIndex, type PairedSlots, type SubscribeFn, } from "./slots.js";
9
+ export { DerivedUniformsScene, type DerivedUniformsSceneOptions, registerRoDerivations, deregisterRoDerivations, type RoDerivedRequest, type RoRegistration, } from "./sceneIntegration.js";
10
+ export { STANDARD_DERIVED_RULES, STANDARD_TRAFO_LEAVES, isStandardDerivedName, } from "./recipes.js";
6
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/index.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,QAAQ,EACR,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EACxE,KAAK,cAAc,EAAE,KAAK,YAAY,GACvC,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAAE,eAAe,EACjC,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,GAC1E,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,yBAAyB,EAAE,uBAAuB,EAClD,aAAa,EAAE,uBAAuB,EACtC,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,wBAAwB,GACzB,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/index.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,KAAK,WAAW,EAAE,KAAK,UAAU,EACjC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,GACxD,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,cAAc,EAAE,WAAW,EAAE,KAAK,YAAY,GAC/C,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,KAAK,SAAS,EACd,OAAO,EAAE,QAAQ,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,EAAE,KAAK,SAAS,GACvC,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EAAE,OAAO,EACtB,UAAU,EAAE,SAAS,EAAE,aAAa,EACpC,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,eAAe,EAAE,KAAK,UAAU,GACjC,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,yBAAyB,EAAE,uBAAuB,EAClD,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,gBAAgB,EAAE,eAAe,EACjC,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,GACnD,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,oBAAoB,EAAE,KAAK,2BAA2B,EACtD,qBAAqB,EAAE,uBAAuB,EAC9C,KAAK,gBAAgB,EAAE,KAAK,cAAc,GAC3C,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EAAE,qBAAqB,EAAE,qBAAqB,GACrE,MAAM,cAAc,CAAC"}
@@ -1,26 +1,31 @@
1
- // §7 derived-uniforms module — public surface.
1
+ // §7 derived-uniforms module — public surface (v2: content-keyed rule registry,
2
+ // chain flattening, codegen-emitted uber-kernel, one dispatch).
2
3
  //
3
- // Caller responsibilities (typically heapScene.ts):
4
+ // Caller responsibilities (heapScene.ts):
4
5
  //
5
- // 1. Construct one DerivedUniformsScene per heap scene, one
6
- // DerivedUniformsBucket per render bucket. The scene owns the
7
- // shared constituents storage buffer + dirty bitmask + pipeline.
6
+ // 1. Construct one DerivedUniformsScene per heap scene (owns the rule registry,
7
+ // the records buffer, the constituents heap + GPU buffer, the dispatcher).
8
8
  // 2. In the parent scene-object's `inputChanged(t, o)` router, call
9
- // `scene.routeInputChanged(o)`. Returns true iff o matched.
10
- // 3. In each RO's add path: `registerRoDerivations(scene, bucket, req)`
11
- // allocates constituent slots and pushes records into the bucket's
12
- // records buffer. In remove path: `deregisterRoDerivations(...)`.
13
- // 4. In the per-frame compute prep, inside the parent sceneObj's
14
- // `evaluateAlways(token, ...)` scope:
15
- // const dirty = scene.constituents.pullDirty(token);
9
+ // `scene.routeInputChanged(o)` returns true iff `o` is a tracked trafo aval.
10
+ // 3. Per RO add: `registerRoDerivations(scene, owner, req)` — flattens + registers
11
+ // each rule, resolves its input leaves to constituent / host slots, pushes one
12
+ // record per derived uniform. Per RO remove: `deregisterRoDerivations(scene, reg)`.
13
+ // 4. Per frame, inside the scene's `evaluateAlways(token, …)` scope:
14
+ // const dirty = scene.pullDirty(token); // re-subscribes on changed trafo avals
16
15
  // scene.uploadDirty(dirty);
17
- // for each bucket: bucket.dispatcher.encode(enc);
18
- // All steps are O(changed); on clean frames they no-op.
16
+ // scene.encode(enc); // one compute dispatch
17
+ // All O(changed); clean frames no-op.
19
18
  //
20
- // Identifying which uniform names are §7-owned: DERIVED_UNIFORM_NAMES.
21
- export { RecipeId, ALL_RECIPES, DERIVED_UNIFORM_NAMES, recipeIdByName, recipeName, recipeInputs, recipeInputCount, recipeOutput, } from "./recipes.js";
19
+ // The standard trafo recipes (ModelViewProjTrafo etc.) live in ./recipes as
20
+ // `DerivedRule` constants `STANDARD_DERIVED_RULES` / `isStandardDerivedName`.
21
+ export { ruleFromIR, uniformRef, sameType, hashIR, isDerivedRule, } from "./rule.js";
22
+ export { derivedUniform, DerivedExpr, } from "./marker.js";
23
+ export { flatten, inputsOf, } from "./flatten.js";
24
+ export { DerivedUniformRegistry, } from "./registry.js";
25
+ export { RecordsBuffer, SlotTag, makeHandle, handleTag, handlePayload, } from "./records.js";
26
+ export { buildUberKernel, } from "./codegen.js";
27
+ export { DerivedUniformsDispatcher, uploadConstituentsRange, } from "./dispatch.js";
22
28
  export { ConstituentSlots, DF32_MAT4_BYTES, } from "./slots.js";
23
- export { DerivedUniformsDispatcher, DerivedUniformsPipeline, RecordsBuffer, uploadConstituentsRange, } from "./dispatch.js";
24
- export { DerivedUniformsScene, registerRoDerivations, deregisterRoDerivations, isDerivedUniformName, } from "./sceneIntegration.js";
25
- export { DERIVED_UBER_KERNEL_WGSL, } from "./uberKernel.wgsl.js";
29
+ export { DerivedUniformsScene, registerRoDerivations, deregisterRoDerivations, } from "./sceneIntegration.js";
30
+ export { STANDARD_DERIVED_RULES, STANDARD_TRAFO_LEAVES, isStandardDerivedName, } from "./recipes.js";
26
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,oDAAoD;AACpD,EAAE;AACF,8DAA8D;AAC9D,mEAAmE;AACnE,sEAAsE;AACtE,sEAAsE;AACtE,iEAAiE;AACjE,0EAA0E;AAC1E,wEAAwE;AACxE,uEAAuE;AACvE,mEAAmE;AACnE,2CAA2C;AAC3C,4DAA4D;AAC5D,mCAAmC;AACnC,yDAAyD;AACzD,6DAA6D;AAC7D,EAAE;AACF,uEAAuE;AAEvE,OAAO,EACL,QAAQ,EACR,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,GAEzE,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAAE,eAAe,GAElC,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,yBAAyB,EAAE,uBAAuB,EAClD,aAAa,EAAE,uBAAuB,GAEvC,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GAIrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,wBAAwB,GACzB,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gEAAgE;AAChE,EAAE;AACF,0CAA0C;AAC1C,EAAE;AACF,kFAAkF;AAClF,gFAAgF;AAChF,sEAAsE;AACtE,oFAAoF;AACpF,qFAAqF;AACrF,oFAAoF;AACpF,yFAAyF;AACzF,uEAAuE;AACvE,yFAAyF;AACzF,mCAAmC;AACnC,0EAA0E;AAC1E,2CAA2C;AAC3C,EAAE;AACF,4EAA4E;AAC5E,gFAAgF;AAEhF,OAAO,EAEL,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,GACxD,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,cAAc,EAAE,WAAW,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EAEL,OAAO,EAAE,QAAQ,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,GACvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EAAE,OAAO,EACtB,UAAU,EAAE,SAAS,EAAE,aAAa,GAErC,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,yBAAyB,EAAE,uBAAuB,GAEnD,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,gBAAgB,EAAE,eAAe,GAElC,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAAE,uBAAuB,GAE/C,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EAAE,qBAAqB,EAAE,qBAAqB,GACrE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,76 @@
1
+ import type { Expr, Type } from "@aardworx/wombat.shader/ir";
2
+ import { type DerivedRule } from "./rule.js";
3
+ /** Leaf type names accepted by `DerivedExpr.as(...)`. */
4
+ export type LeafTypeName = "f32" | "u32" | "i32" | "vec2" | "vec3" | "vec4" | "mat3" | "mat4";
5
+ /** A traced expression in a `derivedUniform` builder. */
6
+ export declare class DerivedExpr {
7
+ readonly ir: Expr;
8
+ constructor(ir: Expr);
9
+ get type(): Type;
10
+ /** Matrix product `this · other` (also matrix·vector / vector·matrix by operand types). */
11
+ mul(other: DerivedExpr): DerivedExpr;
12
+ add(other: DerivedExpr): DerivedExpr;
13
+ sub(other: DerivedExpr): DerivedExpr;
14
+ neg(): DerivedExpr;
15
+ /** Inverse (of a constituent trafo this reads its stored backward half; otherwise unsupported in codegen). */
16
+ inverse(): DerivedExpr;
17
+ transpose(): DerivedExpr;
18
+ /** Upper-left 3×3 (mat → mat3). */
19
+ upperLeft3x3(): DerivedExpr;
20
+ /** This mat4 applied to the origin `(0,0,0,1)`, returning the resulting position (xyz). */
21
+ transformOrigin(): DerivedExpr;
22
+ /** This mat4 applied to the direction `(x,y,z,0)` (no translation), returning the result (xyz). */
23
+ transformDir(x: number, y: number, z: number): DerivedExpr;
24
+ /** vecN swizzle, e.g. `.swizzle("xyz")`. Single component ⇒ scalar. */
25
+ swizzle(comps: string): DerivedExpr;
26
+ get x(): DerivedExpr;
27
+ get y(): DerivedExpr;
28
+ get z(): DerivedExpr;
29
+ get w(): DerivedExpr;
30
+ /**
31
+ * Re-type a leaf — `u.<Name>` defaults to a mat4 trafo leaf; `.as("vec4")` (etc.) gives the
32
+ * leaf its real type so you can read *any* uniform: `u.Tint.as("vec4").swizzle("xyz")`.
33
+ * Only valid directly on a `u.<Name>` leaf.
34
+ */
35
+ as(typeName: LeafTypeName): DerivedExpr;
36
+ /** Escape hatch: an arbitrary builtin call `name(this, ...others)` producing `resultType`. */
37
+ call(name: string, resultType: Type, ...others: DerivedExpr[]): DerivedExpr;
38
+ private u1;
39
+ private bin;
40
+ sin(): DerivedExpr;
41
+ cos(): DerivedExpr;
42
+ tan(): DerivedExpr;
43
+ abs(): DerivedExpr;
44
+ floor(): DerivedExpr;
45
+ ceil(): DerivedExpr;
46
+ fract(): DerivedExpr;
47
+ sqrt(): DerivedExpr;
48
+ exp(): DerivedExpr;
49
+ log(): DerivedExpr;
50
+ exp2(): DerivedExpr;
51
+ log2(): DerivedExpr;
52
+ sign(): DerivedExpr;
53
+ normalize(): DerivedExpr;
54
+ min(o: DerivedExpr): DerivedExpr;
55
+ max(o: DerivedExpr): DerivedExpr;
56
+ pow(o: DerivedExpr): DerivedExpr;
57
+ atan2(o: DerivedExpr): DerivedExpr;
58
+ step(edge: DerivedExpr): DerivedExpr;
59
+ clamp(lo: DerivedExpr, hi: DerivedExpr): DerivedExpr;
60
+ mix(o: DerivedExpr, t: DerivedExpr): DerivedExpr;
61
+ dot(o: DerivedExpr): DerivedExpr;
62
+ cross(o: DerivedExpr): DerivedExpr;
63
+ length(): DerivedExpr;
64
+ distance(o: DerivedExpr): DerivedExpr;
65
+ reflect(n: DerivedExpr): DerivedExpr;
66
+ }
67
+ /** The `u` passed to a `derivedUniform` builder. `u.<Name>` is a mat4 trafo leaf. */
68
+ export type DerivedScope = {
69
+ readonly [name: string]: DerivedExpr;
70
+ };
71
+ /**
72
+ * Define a derived uniform. `derivedUniform(u => u.ViewTrafo.mul(u.ModelTrafo))` makes a
73
+ * rule that slots in wherever a uniform value goes — see this module's header.
74
+ */
75
+ export declare function derivedUniform<T = unknown>(build: (u: DerivedScope) => DerivedExpr): DerivedRule<T>;
76
+ //# sourceMappingURL=marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/marker.ts"],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AK,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAMnG"}
@@ -0,0 +1,156 @@
1
+ // §7 v2 — `derivedUniform((u) => …)` author-facing marker.
2
+ //
3
+ // A uniform binding is either a *value* (an `aval` / constant) or a *rule*
4
+ // (`derivedUniform((u) => u.ViewTrafo.mul(u.ModelTrafo))`). A rule reads other
5
+ // uniforms — `u.<Name>` is a leaf, and is resolved per RenderObject at registration
6
+ // time (a `Trafo3d` aval ⇒ a df32 constituent slot; anything else ⇒ a host uniform).
7
+ //
8
+ // This builds the rule's IR by tracing: `u.<Name>` is a mat4 leaf (the trafo case —
9
+ // the vast majority of derived uniforms), and the `DerivedExpr` methods compose them
10
+ // (the result type follows from the ops, so `.upperLeft3x3()` yields a mat3 rule, etc.).
11
+ // For non-mat4-leaf rules use `ruleFromIR` with hand-built IR, or — once it lands — the
12
+ // build-time `derivedUniform(...)` vite marker, which reads leaf types from the program.
13
+ import { ruleFromIR, uniformRef } from "./rule.js";
14
+ const Tf32 = { kind: "Float", width: 32 };
15
+ const mat = (n) => ({ kind: "Matrix", element: Tf32, rows: n, cols: n });
16
+ const vec = (n) => ({ kind: "Vector", element: Tf32, dim: n });
17
+ const Tu32 = { kind: "Int", signed: false, width: 32 };
18
+ const Ti32 = { kind: "Int", signed: true, width: 32 };
19
+ const LEAF_TYPES = {
20
+ f32: Tf32, u32: Tu32, i32: Ti32,
21
+ vec2: vec(2), vec3: vec(3), vec4: vec(4), mat3: mat(3), mat4: mat(4),
22
+ };
23
+ function transposed(t) {
24
+ return t.kind === "Matrix" ? { kind: "Matrix", element: t.element, rows: t.cols, cols: t.rows } : t;
25
+ }
26
+ function constVec4(x, y, z, w) {
27
+ const c = (v) => ({ kind: "Const", type: Tf32, value: { kind: "Float", value: v } });
28
+ return { kind: "NewVector", components: [c(x), c(y), c(z), c(w)], type: vec(4) };
29
+ }
30
+ function elemOf(t) {
31
+ return t.kind === "Vector" || t.kind === "Matrix" ? t.element : t;
32
+ }
33
+ /** A `CallIntrinsic` node — `op` is a minimal stub (this IR is only ever printed by the
34
+ * derived-uniform codegen, never run through the shader compiler). */
35
+ function intrinsicExpr(name, type, args) {
36
+ return {
37
+ kind: "CallIntrinsic",
38
+ op: { name, returnTypeOf: () => type, pure: true, emit: { glsl: name, wgsl: name } },
39
+ args,
40
+ type,
41
+ };
42
+ }
43
+ /** A traced expression in a `derivedUniform` builder. */
44
+ export class DerivedExpr {
45
+ ir;
46
+ constructor(ir) {
47
+ this.ir = ir;
48
+ }
49
+ get type() { return this.ir.type; }
50
+ /** Matrix product `this · other` (also matrix·vector / vector·matrix by operand types). */
51
+ mul(other) {
52
+ const a = this.ir.type, b = other.ir.type;
53
+ if (a.kind === "Matrix" && b.kind === "Matrix") {
54
+ return new DerivedExpr({ kind: "MulMatMat", lhs: this.ir, rhs: other.ir, type: { kind: "Matrix", element: a.element, rows: a.rows, cols: b.cols } });
55
+ }
56
+ if (a.kind === "Matrix" && b.kind === "Vector") {
57
+ return new DerivedExpr({ kind: "MulMatVec", lhs: this.ir, rhs: other.ir, type: { kind: "Vector", element: b.element, dim: a.rows } });
58
+ }
59
+ if (a.kind === "Vector" && b.kind === "Matrix") {
60
+ return new DerivedExpr({ kind: "MulVecMat", lhs: this.ir, rhs: other.ir, type: { kind: "Vector", element: a.element, dim: b.cols } });
61
+ }
62
+ return new DerivedExpr({ kind: "Mul", lhs: this.ir, rhs: other.ir, type: a.kind === "Float" ? b : a });
63
+ }
64
+ add(other) { return new DerivedExpr({ kind: "Add", lhs: this.ir, rhs: other.ir, type: this.ir.type }); }
65
+ sub(other) { return new DerivedExpr({ kind: "Sub", lhs: this.ir, rhs: other.ir, type: this.ir.type }); }
66
+ neg() { return new DerivedExpr({ kind: "Neg", value: this.ir, type: this.ir.type }); }
67
+ /** Inverse (of a constituent trafo this reads its stored backward half; otherwise unsupported in codegen). */
68
+ inverse() { return new DerivedExpr({ kind: "Inverse", value: this.ir, type: this.ir.type }); }
69
+ transpose() { return new DerivedExpr({ kind: "Transpose", value: this.ir, type: transposed(this.ir.type) }); }
70
+ /** Upper-left 3×3 (mat → mat3). */
71
+ upperLeft3x3() { return new DerivedExpr({ kind: "ConvertMatrix", value: this.ir, type: mat(3) }); }
72
+ /** This mat4 applied to the origin `(0,0,0,1)`, returning the resulting position (xyz). */
73
+ transformOrigin() {
74
+ const v4 = { kind: "MulMatVec", lhs: this.ir, rhs: constVec4(0, 0, 0, 1), type: vec(4) };
75
+ return new DerivedExpr({ kind: "VecSwizzle", value: v4, comps: ["x", "y", "z"], type: vec(3) });
76
+ }
77
+ /** This mat4 applied to the direction `(x,y,z,0)` (no translation), returning the result (xyz). */
78
+ transformDir(x, y, z) {
79
+ const v4 = { kind: "MulMatVec", lhs: this.ir, rhs: constVec4(x, y, z, 0), type: vec(4) };
80
+ return new DerivedExpr({ kind: "VecSwizzle", value: v4, comps: ["x", "y", "z"], type: vec(3) });
81
+ }
82
+ /** vecN swizzle, e.g. `.swizzle("xyz")`. Single component ⇒ scalar. */
83
+ swizzle(comps) {
84
+ const c = comps.split("");
85
+ return new DerivedExpr({ kind: "VecSwizzle", value: this.ir, comps: c, type: c.length === 1 ? Tf32 : vec(c.length) });
86
+ }
87
+ get x() { return this.swizzle("x"); }
88
+ get y() { return this.swizzle("y"); }
89
+ get z() { return this.swizzle("z"); }
90
+ get w() { return this.swizzle("w"); }
91
+ /**
92
+ * Re-type a leaf — `u.<Name>` defaults to a mat4 trafo leaf; `.as("vec4")` (etc.) gives the
93
+ * leaf its real type so you can read *any* uniform: `u.Tint.as("vec4").swizzle("xyz")`.
94
+ * Only valid directly on a `u.<Name>` leaf.
95
+ */
96
+ as(typeName) {
97
+ if (this.ir.kind !== "ReadInput" || this.ir.scope !== "Uniform") {
98
+ throw new Error("DerivedExpr.as(...): only valid on a `u.<Name>` uniform leaf");
99
+ }
100
+ return new DerivedExpr({ kind: "ReadInput", scope: "Uniform", name: this.ir.name, type: LEAF_TYPES[typeName] });
101
+ }
102
+ // ── Intrinsics — every WGSL builtin (name passed straight through). ──
103
+ /** Escape hatch: an arbitrary builtin call `name(this, ...others)` producing `resultType`. */
104
+ call(name, resultType, ...others) {
105
+ return new DerivedExpr(intrinsicExpr(name, resultType, [this.ir, ...others.map((o) => o.ir)]));
106
+ }
107
+ u1(name) { return new DerivedExpr(intrinsicExpr(name, this.ir.type, [this.ir])); }
108
+ bin(name, o) { return new DerivedExpr(intrinsicExpr(name, this.ir.type, [this.ir, o.ir])); }
109
+ sin() { return this.u1("sin"); }
110
+ cos() { return this.u1("cos"); }
111
+ tan() { return this.u1("tan"); }
112
+ abs() { return this.u1("abs"); }
113
+ floor() { return this.u1("floor"); }
114
+ ceil() { return this.u1("ceil"); }
115
+ fract() { return this.u1("fract"); }
116
+ sqrt() { return this.u1("sqrt"); }
117
+ exp() { return this.u1("exp"); }
118
+ log() { return this.u1("log"); }
119
+ exp2() { return this.u1("exp2"); }
120
+ log2() { return this.u1("log2"); }
121
+ sign() { return this.u1("sign"); }
122
+ normalize() { return this.u1("normalize"); }
123
+ min(o) { return this.bin("min", o); }
124
+ max(o) { return this.bin("max", o); }
125
+ pow(o) { return this.bin("pow", o); }
126
+ atan2(o) { return this.bin("atan2", o); }
127
+ step(edge) { return new DerivedExpr(intrinsicExpr("step", this.ir.type, [edge.ir, this.ir])); }
128
+ clamp(lo, hi) { return new DerivedExpr(intrinsicExpr("clamp", this.ir.type, [this.ir, lo.ir, hi.ir])); }
129
+ mix(o, t) { return new DerivedExpr(intrinsicExpr("mix", this.ir.type, [this.ir, o.ir, t.ir])); }
130
+ dot(o) { return new DerivedExpr(intrinsicExpr("dot", elemOf(this.ir.type), [this.ir, o.ir])); }
131
+ cross(o) { return new DerivedExpr(intrinsicExpr("cross", this.ir.type, [this.ir, o.ir])); }
132
+ length() { return new DerivedExpr(intrinsicExpr("length", elemOf(this.ir.type), [this.ir])); }
133
+ distance(o) { return new DerivedExpr(intrinsicExpr("distance", elemOf(this.ir.type), [this.ir, o.ir])); }
134
+ reflect(n) { return new DerivedExpr(intrinsicExpr("reflect", this.ir.type, [this.ir, n.ir])); }
135
+ }
136
+ function makeScope() {
137
+ return new Proxy({}, {
138
+ get(_t, key) {
139
+ if (typeof key !== "string")
140
+ throw new Error("derivedUniform: leaf names must be strings");
141
+ return new DerivedExpr(uniformRef(key, mat(4)));
142
+ },
143
+ });
144
+ }
145
+ /**
146
+ * Define a derived uniform. `derivedUniform(u => u.ViewTrafo.mul(u.ModelTrafo))` makes a
147
+ * rule that slots in wherever a uniform value goes — see this module's header.
148
+ */
149
+ export function derivedUniform(build) {
150
+ const result = build(makeScope());
151
+ if (!(result instanceof DerivedExpr)) {
152
+ throw new Error("derivedUniform: the builder must return a derived expression, e.g. u.ViewTrafo.mul(u.ModelTrafo)");
153
+ }
154
+ return ruleFromIR(result.ir, result.ir.type);
155
+ }
156
+ //# sourceMappingURL=marker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marker.js","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/marker.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,oFAAoF;AACpF,qFAAqF;AACrF,EAAE;AACF,oFAAoF;AACpF,qFAAqF;AACrF,yFAAyF;AACzF,wFAAwF;AACxF,yFAAyF;AAGzF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAC;AAErE,MAAM,IAAI,GAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAChD,MAAM,GAAG,GAAG,CAAC,CAAQ,EAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AACtF,MAAM,GAAG,GAAG,CAAC,CAAY,EAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IA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CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAc,KAAuC;IACjF,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;IACtH,CAAC;IACD,OAAO,UAAU,CAAI,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC"}
@@ -1,42 +1,7 @@
1
- /** Recipe IDs. Numeric values are stable — the kernel switches on them. */
2
- export declare const enum RecipeId {
3
- /** Model.fwd f32 mat4. */
4
- ModelTrafo = 0,
5
- /** Model.bwd f32 mat4. */
6
- ModelTrafoInv = 1,
7
- /** (Model.bwd)ᵀ upper-3×3 → f32 mat3. */
8
- NormalMatrix = 2,
9
- /** View.fwd · Model.fwd → f32 mat4. */
10
- ModelViewTrafo = 3,
11
- /** Model.bwd · View.bwd → f32 mat4. */
12
- ModelViewTrafoInv = 4,
13
- /** Proj.fwd · View.fwd · Model.fwd → f32 mat4. */
14
- ModelViewProjTrafo = 5,
15
- /** Model.bwd · View.bwd · Proj.bwd → f32 mat4. */
16
- ModelViewProjTrafoInv = 6,
17
- /** View.fwd → f32 mat4. */
18
- ViewTrafo = 7,
19
- /** View.bwd → f32 mat4. */
20
- ViewTrafoInv = 8,
21
- /** Proj.fwd · View.fwd → f32 mat4. */
22
- ViewProjTrafo = 9,
23
- /** View.bwd · Proj.bwd → f32 mat4. */
24
- ViewProjTrafoInv = 10,
25
- /** Proj.fwd → f32 mat4. */
26
- ProjTrafo = 11,
27
- /** Proj.bwd → f32 mat4. */
28
- ProjTrafoInv = 12
29
- }
30
- export declare function recipeInputCount(id: RecipeId): 1 | 2 | 3;
31
- /** Output shape — drives drawHeader byte allocation. */
32
- export type RecipeOutput = "mat4" | "mat3";
33
- export declare function recipeOutput(id: RecipeId): RecipeOutput;
34
- /** Which side (forward/backward) of which Trafo3d each input slot draws from. */
35
- export type ConstituentRef = "Model.fwd" | "Model.bwd" | "View.fwd" | "View.bwd" | "Proj.fwd" | "Proj.bwd";
36
- export declare function recipeInputs(id: RecipeId): readonly ConstituentRef[];
37
- /** All recipe IDs in switch order. */
38
- export declare const ALL_RECIPES: readonly RecipeId[];
39
- export declare const DERIVED_UNIFORM_NAMES: ReadonlySet<string>;
40
- export declare function recipeIdByName(name: string): RecipeId | undefined;
41
- export declare function recipeName(id: RecipeId): string;
1
+ import { type DerivedRule } from "./rule.js";
2
+ /** Standard derived rules, keyed by the drawHeader uniform name each produces. */
3
+ export declare const STANDARD_DERIVED_RULES: ReadonlyMap<string, DerivedRule>;
4
+ /** Leaf name → the RO uniform (`spec.inputs[…]`) that supplies its `aval<Trafo3d>`. */
5
+ export declare const STANDARD_TRAFO_LEAVES: ReadonlyMap<string, string>;
6
+ export declare function isStandardDerivedName(name: string): boolean;
42
7
  //# sourceMappingURL=recipes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recipes.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/recipes.ts"],"names":[],"mappings":"AAcA,2EAA2E;AAC3E,0BAAkB,QAAQ;IACxB,4BAA4B;IAC5B,UAAU,IAAe;IACzB,4BAA4B;IAC5B,aAAa,IAAY;IACzB,yCAAyC;IACzC,YAAY,IAAa;IAEzB,uCAAuC;IACvC,cAAc,IAAW;IACzB,uCAAuC;IACvC,iBAAiB,IAAQ;IACzB,kDAAkD;IAClD,kBAAkB,IAAO;IACzB,kDAAkD;IAClD,qBAAqB,IAAI;IAEzB,2BAA2B;IAC3B,SAAS,IAAgB;IACzB,2BAA2B;IAC3B,YAAY,IAAa;IACzB,sCAAsC;IACtC,aAAa,IAAY;IACzB,sCAAsC;IACtC,gBAAgB,KAAU;IAC1B,2BAA2B;IAC3B,SAAS,KAAiB;IAC1B,2BAA2B;IAC3B,YAAY,KAAc;CAC3B;AAmBD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAExD;AAED,wDAAwD;AACxD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAkB3C,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,YAAY,CAEvD;AAED,iFAAiF;AACjF,MAAM,MAAM,cAAc,GACtB,WAAW,GAAG,WAAW,GACzB,UAAU,GAAI,UAAU,GACxB,UAAU,GAAI,UAAU,CAAC;AAoB7B,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,cAAc,EAAE,CAEpE;AAmBD,sCAAsC;AACtC,eAAO,MAAM,WAAW,EAAE,SAAS,QAAQ,EAO1C,CAAC;AAMF,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CACZ,CAAC;AAE3C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAEjE;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAE/C"}
1
+ {"version":3,"file":"recipes.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/recipes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAmBrE,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAmBlE,CAAC;AAEH,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAI5D,CAAC;AAEH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -1,134 +1,58 @@
1
- // §7 derived-uniform recipe table leaf-only flavour.
1
+ // §7 v2 the standard trafo recipes, as DerivedRule constants.
2
2
  //
3
- // Every recipe is a self-contained leaf: reads constituents directly,
4
- // computes inline (one or two df32 muls + collapse), writes the final
5
- // f32 mat4/mat3 to the main heap drawHeader. No intermediates, no
6
- // layering, no dependents graph.
3
+ // These replace the hardcoded RecipeId table. Each rule reads BASE-trafo leaves
4
+ // (`Model` / `View` / `Proj` the raw `aval<Trafo3d>`s the RO binds as
5
+ // `ModelTrafo` / `ViewTrafo` / `ProjTrafo` uniforms) and produces the derived
6
+ // uniform the shader reads (`ModelViewProjTrafo`, `NormalMatrix`, …). A leaf
7
+ // wrapped in `Inverse(...)` selects that trafo's stored backward half (free).
7
8
  //
8
- // Two consumers of the same df32 product (e.g. ModelViewTrafo and
9
- // ModelViewProjTrafo for the same RO) recompute Model·View twice
10
- // trivial vs the encode-time savings of one flat dispatch.
9
+ // `Inverse`-of-a-product (e.g. `ModelViewProjTrafoInv`) is written as the product
10
+ // of the inverted factors in reverse order — `(P·V·M)⁻¹ = M⁻¹·V⁻¹·P⁻¹` so it
11
+ // stays a constituent matmul chain the codegen recognizes.
11
12
  //
12
- // All df32 math runs through the verified primitives in
13
- // uberKernel.wgsl.ts; the final consumer-facing values are f32.
14
- /** Recipe IDs. Numeric values are stable — the kernel switches on them. */
15
- export var RecipeId;
16
- (function (RecipeId) {
17
- /** Model.fwd f32 mat4. */
18
- RecipeId[RecipeId["ModelTrafo"] = 0] = "ModelTrafo";
19
- /** Model.bwd f32 mat4. */
20
- RecipeId[RecipeId["ModelTrafoInv"] = 1] = "ModelTrafoInv";
21
- /** (Model.bwd)ᵀ upper-3×3 f32 mat3. */
22
- RecipeId[RecipeId["NormalMatrix"] = 2] = "NormalMatrix";
23
- /** View.fwd · Model.fwd f32 mat4. */
24
- RecipeId[RecipeId["ModelViewTrafo"] = 3] = "ModelViewTrafo";
25
- /** Model.bwd · View.bwd f32 mat4. */
26
- RecipeId[RecipeId["ModelViewTrafoInv"] = 4] = "ModelViewTrafoInv";
27
- /** Proj.fwd · View.fwd · Model.fwd → f32 mat4. */
28
- RecipeId[RecipeId["ModelViewProjTrafo"] = 5] = "ModelViewProjTrafo";
29
- /** Model.bwd · View.bwd · Proj.bwd f32 mat4. */
30
- RecipeId[RecipeId["ModelViewProjTrafoInv"] = 6] = "ModelViewProjTrafoInv";
31
- /** View.fwd f32 mat4. */
32
- RecipeId[RecipeId["ViewTrafo"] = 7] = "ViewTrafo";
33
- /** View.bwd → f32 mat4. */
34
- RecipeId[RecipeId["ViewTrafoInv"] = 8] = "ViewTrafoInv";
35
- /** Proj.fwd · View.fwd → f32 mat4. */
36
- RecipeId[RecipeId["ViewProjTrafo"] = 9] = "ViewProjTrafo";
37
- /** View.bwd · Proj.bwd → f32 mat4. */
38
- RecipeId[RecipeId["ViewProjTrafoInv"] = 10] = "ViewProjTrafoInv";
39
- /** Proj.fwd → f32 mat4. */
40
- RecipeId[RecipeId["ProjTrafo"] = 11] = "ProjTrafo";
41
- /** Proj.bwd f32 mat4. */
42
- RecipeId[RecipeId["ProjTrafoInv"] = 12] = "ProjTrafoInv";
43
- })(RecipeId || (RecipeId = {}));
44
- /** Number of constituent inputs each recipe consumes (1, 2, or 3). */
45
- const INPUT_COUNT = {
46
- [RecipeId.ModelTrafo]: 1,
47
- [RecipeId.ModelTrafoInv]: 1,
48
- [RecipeId.NormalMatrix]: 1,
49
- [RecipeId.ModelViewTrafo]: 2,
50
- [RecipeId.ModelViewTrafoInv]: 2,
51
- [RecipeId.ModelViewProjTrafo]: 3,
52
- [RecipeId.ModelViewProjTrafoInv]: 3,
53
- [RecipeId.ViewTrafo]: 1,
54
- [RecipeId.ViewTrafoInv]: 1,
55
- [RecipeId.ViewProjTrafo]: 2,
56
- [RecipeId.ViewProjTrafoInv]: 2,
57
- [RecipeId.ProjTrafo]: 1,
58
- [RecipeId.ProjTrafoInv]: 1,
59
- };
60
- export function recipeInputCount(id) {
61
- return INPUT_COUNT[id];
62
- }
63
- const OUTPUT = {
64
- [RecipeId.ModelTrafo]: "mat4",
65
- [RecipeId.ModelTrafoInv]: "mat4",
66
- [RecipeId.NormalMatrix]: "mat3",
67
- [RecipeId.ModelViewTrafo]: "mat4",
68
- [RecipeId.ModelViewTrafoInv]: "mat4",
69
- [RecipeId.ModelViewProjTrafo]: "mat4",
70
- [RecipeId.ModelViewProjTrafoInv]: "mat4",
71
- [RecipeId.ViewTrafo]: "mat4",
72
- [RecipeId.ViewTrafoInv]: "mat4",
73
- [RecipeId.ViewProjTrafo]: "mat4",
74
- [RecipeId.ViewProjTrafoInv]: "mat4",
75
- [RecipeId.ProjTrafo]: "mat4",
76
- [RecipeId.ProjTrafoInv]: "mat4",
77
- };
78
- export function recipeOutput(id) {
79
- return OUTPUT[id];
80
- }
81
- const INPUTS = {
82
- [RecipeId.ModelTrafo]: ["Model.fwd"],
83
- [RecipeId.ModelTrafoInv]: ["Model.bwd"],
84
- [RecipeId.NormalMatrix]: ["Model.bwd"],
85
- // df_mul args are ordered (outer, inner) so the math product
86
- // matches Aardvark's `View.mul(Model).forward = View.fwd · Model.fwd`.
87
- [RecipeId.ModelViewTrafo]: ["View.fwd", "Model.fwd"],
88
- [RecipeId.ModelViewTrafoInv]: ["Model.bwd", "View.bwd"],
89
- [RecipeId.ModelViewProjTrafo]: ["Proj.fwd", "View.fwd", "Model.fwd"],
90
- [RecipeId.ModelViewProjTrafoInv]: ["Model.bwd", "View.bwd", "Proj.bwd"],
91
- [RecipeId.ViewTrafo]: ["View.fwd"],
92
- [RecipeId.ViewTrafoInv]: ["View.bwd"],
93
- [RecipeId.ViewProjTrafo]: ["Proj.fwd", "View.fwd"],
94
- [RecipeId.ViewProjTrafoInv]: ["View.bwd", "Proj.bwd"],
95
- [RecipeId.ProjTrafo]: ["Proj.fwd"],
96
- [RecipeId.ProjTrafoInv]: ["Proj.bwd"],
97
- };
98
- export function recipeInputs(id) {
99
- return INPUTS[id];
100
- }
101
- /** Public uniform name (one per recipe). */
102
- const NAME = {
103
- [RecipeId.ModelTrafo]: "ModelTrafo",
104
- [RecipeId.ModelTrafoInv]: "ModelTrafoInv",
105
- [RecipeId.NormalMatrix]: "NormalMatrix",
106
- [RecipeId.ModelViewTrafo]: "ModelViewTrafo",
107
- [RecipeId.ModelViewTrafoInv]: "ModelViewTrafoInv",
108
- [RecipeId.ModelViewProjTrafo]: "ModelViewProjTrafo",
109
- [RecipeId.ModelViewProjTrafoInv]: "ModelViewProjTrafoInv",
110
- [RecipeId.ViewTrafo]: "ViewTrafo",
111
- [RecipeId.ViewTrafoInv]: "ViewTrafoInv",
112
- [RecipeId.ViewProjTrafo]: "ViewProjTrafo",
113
- [RecipeId.ViewProjTrafoInv]: "ViewProjTrafoInv",
114
- [RecipeId.ProjTrafo]: "ProjTrafo",
115
- [RecipeId.ProjTrafoInv]: "ProjTrafoInv",
116
- };
117
- /** All recipe IDs in switch order. */
118
- export const ALL_RECIPES = [
119
- RecipeId.ModelTrafo, RecipeId.ModelTrafoInv, RecipeId.NormalMatrix,
120
- RecipeId.ModelViewTrafo, RecipeId.ModelViewTrafoInv,
121
- RecipeId.ModelViewProjTrafo, RecipeId.ModelViewProjTrafoInv,
122
- RecipeId.ViewTrafo, RecipeId.ViewTrafoInv,
123
- RecipeId.ViewProjTrafo, RecipeId.ViewProjTrafoInv,
124
- RecipeId.ProjTrafo, RecipeId.ProjTrafoInv,
125
- ];
126
- const BY_NAME = new Map(ALL_RECIPES.map(id => [NAME[id], id]));
127
- export const DERIVED_UNIFORM_NAMES = new Set(ALL_RECIPES.map(id => NAME[id]));
128
- export function recipeIdByName(name) {
129
- return BY_NAME.get(name);
130
- }
131
- export function recipeName(id) {
132
- return NAME[id];
13
+ // `NormalMatrix` is `(Model⁻¹)ᵀ` truncated to its upper-3×3 declared as a mat3
14
+ // output; the codegen's normal-matrix arm does the transpose + truncation.
15
+ import { ruleFromIR, uniformRef } from "./rule.js";
16
+ const Tf32 = { kind: "Float", width: 32 };
17
+ const Tmat4 = { kind: "Matrix", element: Tf32, rows: 4, cols: 4 };
18
+ const Tmat3 = { kind: "Matrix", element: Tf32, rows: 3, cols: 3 };
19
+ const mat4 = (name) => uniformRef(name, Tmat4);
20
+ const inv = (v) => ({ kind: "Inverse", value: v, type: Tmat4 });
21
+ const mul = (lhs, rhs) => ({ kind: "MulMatMat", lhs, rhs, type: Tmat4 });
22
+ /** Left-fold `A·B·C·…` (multiplication order). */
23
+ const chain = (...fs) => fs.reduce((acc, f) => mul(acc, f));
24
+ /** mat4 mat3 truncation (upper-left 3×3). */
25
+ const upper3 = (v) => ({ kind: "ConvertMatrix", value: v, type: Tmat3 });
26
+ const transpose = (v) => ({ kind: "Transpose", value: v, type: Tmat4 });
27
+ const Model = mat4("Model");
28
+ const View = mat4("View");
29
+ const Proj = mat4("Proj");
30
+ /** Standard derived rules, keyed by the drawHeader uniform name each produces. */
31
+ export const STANDARD_DERIVED_RULES = new Map([
32
+ // Trafo passthroughs (collapse the df32 fwd/bwd half to an f32 mat4).
33
+ ["ModelTrafo", ruleFromIR(Model)],
34
+ ["ModelTrafoInv", ruleFromIR(inv(Model))],
35
+ ["ViewTrafo", ruleFromIR(View)],
36
+ ["ViewTrafoInv", ruleFromIR(inv(View))],
37
+ ["ProjTrafo", ruleFromIR(Proj)],
38
+ ["ProjTrafoInv", ruleFromIR(inv(Proj))],
39
+ // Composites. `mul(a,b)` matrix product `a · b`.
40
+ ["ModelViewTrafo", ruleFromIR(chain(View, Model))],
41
+ ["ModelViewTrafoInv", ruleFromIR(chain(inv(Model), inv(View)))],
42
+ ["ModelViewProjTrafo", ruleFromIR(chain(Proj, View, Model))],
43
+ ["ModelViewProjTrafoInv", ruleFromIR(chain(inv(Model), inv(View), inv(Proj)))],
44
+ ["ViewProjTrafo", ruleFromIR(chain(Proj, View))],
45
+ ["ViewProjTrafoInv", ruleFromIR(chain(inv(View), inv(Proj)))],
46
+ // NormalMatrix = (Model⁻¹)ᵀ, upper-3×3.
47
+ ["NormalMatrix", ruleFromIR(upper3(transpose(inv(Model))), Tmat3)],
48
+ ]);
49
+ /** Leaf name → the RO uniform (`spec.inputs[]`) that supplies its `aval<Trafo3d>`. */
50
+ export const STANDARD_TRAFO_LEAVES = new Map([
51
+ ["Model", "ModelTrafo"],
52
+ ["View", "ViewTrafo"],
53
+ ["Proj", "ProjTrafo"],
54
+ ]);
55
+ export function isStandardDerivedName(name) {
56
+ return STANDARD_DERIVED_RULES.has(name);
133
57
  }
134
58
  //# sourceMappingURL=recipes.js.map