@aardworx/wombat.rendering 0.9.11 → 0.9.12
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.
- package/dist/runtime/derivedUniforms/codegen.d.ts +8 -0
- package/dist/runtime/derivedUniforms/codegen.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/codegen.js +449 -0
- package/dist/runtime/derivedUniforms/codegen.js.map +1 -0
- package/dist/runtime/derivedUniforms/dispatch.d.ts +14 -93
- package/dist/runtime/derivedUniforms/dispatch.d.ts.map +1 -1
- package/dist/runtime/derivedUniforms/dispatch.js +123 -299
- package/dist/runtime/derivedUniforms/dispatch.js.map +1 -1
- package/dist/runtime/derivedUniforms/flatten.d.ts +25 -0
- package/dist/runtime/derivedUniforms/flatten.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/flatten.js +71 -0
- package/dist/runtime/derivedUniforms/flatten.js.map +1 -0
- package/dist/runtime/derivedUniforms/index.d.ts +10 -5
- package/dist/runtime/derivedUniforms/index.d.ts.map +1 -1
- package/dist/runtime/derivedUniforms/index.js +24 -19
- package/dist/runtime/derivedUniforms/index.js.map +1 -1
- package/dist/runtime/derivedUniforms/marker.d.ts +32 -0
- package/dist/runtime/derivedUniforms/marker.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/marker.js +84 -0
- package/dist/runtime/derivedUniforms/marker.js.map +1 -0
- package/dist/runtime/derivedUniforms/recipes.d.ts +6 -41
- package/dist/runtime/derivedUniforms/recipes.d.ts.map +1 -1
- package/dist/runtime/derivedUniforms/recipes.js +53 -129
- package/dist/runtime/derivedUniforms/recipes.js.map +1 -1
- package/dist/runtime/derivedUniforms/records.d.ts +40 -0
- package/dist/runtime/derivedUniforms/records.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/records.js +151 -0
- package/dist/runtime/derivedUniforms/records.js.map +1 -0
- package/dist/runtime/derivedUniforms/registry.d.ts +33 -0
- package/dist/runtime/derivedUniforms/registry.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/registry.js +58 -0
- package/dist/runtime/derivedUniforms/registry.js.map +1 -0
- package/dist/runtime/derivedUniforms/rule.d.ts +26 -0
- package/dist/runtime/derivedUniforms/rule.d.ts.map +1 -0
- package/dist/runtime/derivedUniforms/rule.js +35 -0
- package/dist/runtime/derivedUniforms/rule.js.map +1 -0
- package/dist/runtime/derivedUniforms/sceneIntegration.d.ts +34 -33
- package/dist/runtime/derivedUniforms/sceneIntegration.d.ts.map +1 -1
- package/dist/runtime/derivedUniforms/sceneIntegration.js +80 -90
- package/dist/runtime/derivedUniforms/sceneIntegration.js.map +1 -1
- package/dist/runtime/heapScene.d.ts.map +1 -1
- package/dist/runtime/heapScene.js +72 -27
- package/dist/runtime/heapScene.js.map +1 -1
- package/dist/runtime/hybridScene.js +1 -1
- package/dist/runtime/hybridScene.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/renderTask.js +1 -1
- package/dist/runtime/renderTask.js.map +1 -1
- package/dist/runtime/runtime.js +1 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/package.json +1 -1
- package/src/runtime/derivedUniforms/codegen.ts +477 -0
- package/src/runtime/derivedUniforms/dispatch.ts +135 -341
- package/src/runtime/derivedUniforms/flatten.ts +89 -0
- package/src/runtime/derivedUniforms/index.ts +50 -34
- package/src/runtime/derivedUniforms/marker.ts +91 -0
- package/src/runtime/derivedUniforms/recipes.ts +63 -155
- package/src/runtime/derivedUniforms/records.ts +158 -0
- package/src/runtime/derivedUniforms/registry.ts +77 -0
- package/src/runtime/derivedUniforms/rule.ts +59 -0
- package/src/runtime/derivedUniforms/sceneIntegration.ts +115 -149
- package/src/runtime/heapScene.ts +73 -29
- package/src/runtime/hybridScene.ts +1 -1
- package/src/runtime/index.ts +8 -0
- package/src/runtime/renderTask.ts +1 -1
- package/src/runtime/runtime.ts +1 -1
- package/dist/runtime/derivedUniforms/slotId.d.ts +0 -15
- package/dist/runtime/derivedUniforms/slotId.d.ts.map +0 -1
- package/dist/runtime/derivedUniforms/slotId.js +0 -30
- package/dist/runtime/derivedUniforms/slotId.js.map +0 -1
- package/dist/runtime/derivedUniforms/uberKernel.wgsl.d.ts +0 -13
- package/dist/runtime/derivedUniforms/uberKernel.wgsl.d.ts.map +0 -1
- package/dist/runtime/derivedUniforms/uberKernel.wgsl.js +0 -218
- package/dist/runtime/derivedUniforms/uberKernel.wgsl.js.map +0 -1
- package/src/runtime/derivedUniforms/slotId.ts +0 -35
- package/src/runtime/derivedUniforms/uberKernel.wgsl.ts +0 -220
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
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,
|
|
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 (
|
|
4
|
+
// Caller responsibilities (heapScene.ts):
|
|
4
5
|
//
|
|
5
|
-
// 1. Construct one DerivedUniformsScene per heap scene,
|
|
6
|
-
//
|
|
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)
|
|
10
|
-
// 3.
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// 4.
|
|
14
|
-
//
|
|
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
|
-
//
|
|
18
|
-
// All
|
|
16
|
+
// scene.encode(enc); // one compute dispatch
|
|
17
|
+
// All O(changed); clean frames no-op.
|
|
19
18
|
//
|
|
20
|
-
//
|
|
21
|
-
|
|
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 {
|
|
24
|
-
export {
|
|
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
|
|
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,32 @@
|
|
|
1
|
+
import type { Expr, Type } from "@aardworx/wombat.shader/ir";
|
|
2
|
+
import { type DerivedRule } from "./rule.js";
|
|
3
|
+
/** A traced expression in a `derivedUniform` builder. */
|
|
4
|
+
export declare class DerivedExpr {
|
|
5
|
+
readonly ir: Expr;
|
|
6
|
+
constructor(ir: Expr);
|
|
7
|
+
get type(): Type;
|
|
8
|
+
/** Matrix product `this · other` (also matrix·vector / vector·matrix by operand types). */
|
|
9
|
+
mul(other: DerivedExpr): DerivedExpr;
|
|
10
|
+
add(other: DerivedExpr): DerivedExpr;
|
|
11
|
+
sub(other: DerivedExpr): DerivedExpr;
|
|
12
|
+
neg(): DerivedExpr;
|
|
13
|
+
/** Inverse (of a constituent trafo this reads its stored backward half; otherwise unsupported in codegen). */
|
|
14
|
+
inverse(): DerivedExpr;
|
|
15
|
+
transpose(): DerivedExpr;
|
|
16
|
+
/** Upper-left 3×3 (mat → mat3). */
|
|
17
|
+
upperLeft3x3(): DerivedExpr;
|
|
18
|
+
/** This mat4 applied to the origin `(0,0,0,1)`, returning the resulting position (xyz). */
|
|
19
|
+
transformOrigin(): DerivedExpr;
|
|
20
|
+
/** vecN swizzle, e.g. `.swizzle("xyz")`. */
|
|
21
|
+
swizzle(comps: string): DerivedExpr;
|
|
22
|
+
}
|
|
23
|
+
/** The `u` passed to a `derivedUniform` builder. `u.<Name>` is a mat4 trafo leaf. */
|
|
24
|
+
export type DerivedScope = {
|
|
25
|
+
readonly [name: string]: DerivedExpr;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Define a derived uniform. `derivedUniform(u => u.ViewTrafo.mul(u.ModelTrafo))` makes a
|
|
29
|
+
* rule that slots in wherever a uniform value goes — see this module's header.
|
|
30
|
+
*/
|
|
31
|
+
export declare function derivedUniform<T = unknown>(build: (u: DerivedScope) => DerivedExpr): DerivedRule<T>;
|
|
32
|
+
//# sourceMappingURL=marker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marker.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/marker.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAcrE,yDAAyD;AACzD,qBAAa,WAAW;IACV,QAAQ,CAAC,EAAE,EAAE,IAAI;gBAAR,EAAE,EAAE,IAAI;IAC7B,IAAI,IAAI,IAAI,IAAI,CAAyB;IAEzC,2FAA2F;IAC3F,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAapC,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IACpC,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IACpC,GAAG,IAAI,WAAW;IAElB,8GAA8G;IAC9G,OAAO,IAAI,WAAW;IACtB,SAAS,IAAI,WAAW;IACxB,mCAAmC;IACnC,YAAY,IAAI,WAAW;IAC3B,2FAA2F;IAC3F,eAAe,IAAI,WAAW;IAI9B,4CAA4C;IAC5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;CAIpC;AAED,qFAAqF;AACrF,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;CAAE,CAAC;AAWpE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAMnG"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
function transposed(t) {
|
|
18
|
+
return t.kind === "Matrix" ? { kind: "Matrix", element: t.element, rows: t.cols, cols: t.rows } : t;
|
|
19
|
+
}
|
|
20
|
+
function constVec4(x, y, z, w) {
|
|
21
|
+
const c = (v) => ({ kind: "Const", type: Tf32, value: { kind: "Float", value: v } });
|
|
22
|
+
return { kind: "NewVector", components: [c(x), c(y), c(z), c(w)], type: vec(4) };
|
|
23
|
+
}
|
|
24
|
+
/** A traced expression in a `derivedUniform` builder. */
|
|
25
|
+
export class DerivedExpr {
|
|
26
|
+
ir;
|
|
27
|
+
constructor(ir) {
|
|
28
|
+
this.ir = ir;
|
|
29
|
+
}
|
|
30
|
+
get type() { return this.ir.type; }
|
|
31
|
+
/** Matrix product `this · other` (also matrix·vector / vector·matrix by operand types). */
|
|
32
|
+
mul(other) {
|
|
33
|
+
const a = this.ir.type, b = other.ir.type;
|
|
34
|
+
if (a.kind === "Matrix" && b.kind === "Matrix") {
|
|
35
|
+
return new DerivedExpr({ kind: "MulMatMat", lhs: this.ir, rhs: other.ir, type: { kind: "Matrix", element: a.element, rows: a.rows, cols: b.cols } });
|
|
36
|
+
}
|
|
37
|
+
if (a.kind === "Matrix" && b.kind === "Vector") {
|
|
38
|
+
return new DerivedExpr({ kind: "MulMatVec", lhs: this.ir, rhs: other.ir, type: { kind: "Vector", element: b.element, dim: a.rows } });
|
|
39
|
+
}
|
|
40
|
+
if (a.kind === "Vector" && b.kind === "Matrix") {
|
|
41
|
+
return new DerivedExpr({ kind: "MulVecMat", lhs: this.ir, rhs: other.ir, type: { kind: "Vector", element: a.element, dim: b.cols } });
|
|
42
|
+
}
|
|
43
|
+
return new DerivedExpr({ kind: "Mul", lhs: this.ir, rhs: other.ir, type: a.kind === "Float" ? b : a });
|
|
44
|
+
}
|
|
45
|
+
add(other) { return new DerivedExpr({ kind: "Add", lhs: this.ir, rhs: other.ir, type: this.ir.type }); }
|
|
46
|
+
sub(other) { return new DerivedExpr({ kind: "Sub", lhs: this.ir, rhs: other.ir, type: this.ir.type }); }
|
|
47
|
+
neg() { return new DerivedExpr({ kind: "Neg", value: this.ir, type: this.ir.type }); }
|
|
48
|
+
/** Inverse (of a constituent trafo this reads its stored backward half; otherwise unsupported in codegen). */
|
|
49
|
+
inverse() { return new DerivedExpr({ kind: "Inverse", value: this.ir, type: this.ir.type }); }
|
|
50
|
+
transpose() { return new DerivedExpr({ kind: "Transpose", value: this.ir, type: transposed(this.ir.type) }); }
|
|
51
|
+
/** Upper-left 3×3 (mat → mat3). */
|
|
52
|
+
upperLeft3x3() { return new DerivedExpr({ kind: "ConvertMatrix", value: this.ir, type: mat(3) }); }
|
|
53
|
+
/** This mat4 applied to the origin `(0,0,0,1)`, returning the resulting position (xyz). */
|
|
54
|
+
transformOrigin() {
|
|
55
|
+
const v4 = { kind: "MulMatVec", lhs: this.ir, rhs: constVec4(0, 0, 0, 1), type: vec(4) };
|
|
56
|
+
return new DerivedExpr({ kind: "VecSwizzle", value: v4, comps: ["x", "y", "z"], type: vec(3) });
|
|
57
|
+
}
|
|
58
|
+
/** vecN swizzle, e.g. `.swizzle("xyz")`. */
|
|
59
|
+
swizzle(comps) {
|
|
60
|
+
const c = comps.split("");
|
|
61
|
+
return new DerivedExpr({ kind: "VecSwizzle", value: this.ir, comps: c, type: c.length === 1 ? Tf32 : vec(c.length) });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function makeScope() {
|
|
65
|
+
return new Proxy({}, {
|
|
66
|
+
get(_t, key) {
|
|
67
|
+
if (typeof key !== "string")
|
|
68
|
+
throw new Error("derivedUniform: leaf names must be strings");
|
|
69
|
+
return new DerivedExpr(uniformRef(key, mat(4)));
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Define a derived uniform. `derivedUniform(u => u.ViewTrafo.mul(u.ModelTrafo))` makes a
|
|
75
|
+
* rule that slots in wherever a uniform value goes — see this module's header.
|
|
76
|
+
*/
|
|
77
|
+
export function derivedUniform(build) {
|
|
78
|
+
const result = build(makeScope());
|
|
79
|
+
if (!(result instanceof DerivedExpr)) {
|
|
80
|
+
throw new Error("derivedUniform: the builder must return a derived expression, e.g. u.ViewTrafo.mul(u.ModelTrafo)");
|
|
81
|
+
}
|
|
82
|
+
return ruleFromIR(result.ir, result.ir.type);
|
|
83
|
+
}
|
|
84
|
+
//# 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,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAEhF,SAAS,UAAU,CAAC,CAAO;IACzB,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAA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C;IACD,OAAO,UAAU,CAAI,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1,42 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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":"
|
|
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
|
|
1
|
+
// §7 v2 — the standard trafo recipes, as DerivedRule constants.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
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
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
[
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recipes.js","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/recipes.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"recipes.js","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/recipes.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,gFAAgF;AAChF,wEAAwE;AACxE,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,EAAE;AACF,kFAAkF;AAClF,+EAA+E;AAC/E,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,2EAA2E;AAG3E,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,KAAK,GAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AACxE,MAAM,KAAK,GAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAExE,MAAM,IAAI,GAAG,CAAC,IAAY,EAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC7D,MAAM,GAAG,GAAG,CAAC,CAAO,EAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC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@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Tagged-handle source bindings (top 3 bits of an in_slot / out_slot word). */
|
|
2
|
+
export declare const enum SlotTag {
|
|
3
|
+
/** Constituent slot — a Trafo3d half in df32 storage. Payload = slot index. */
|
|
4
|
+
Constituent = 0,
|
|
5
|
+
/** A host uniform on the same RO — payload = its data byte offset in the main heap. Also used for the output.
|
|
6
|
+
* There is no separate "global" tag: whether a uniform is global is a per-RO fact (the sg can override it
|
|
7
|
+
* anywhere), so anything that isn't a constituent trafo resolves to this; a uniform that's the same on every
|
|
8
|
+
* RO is the same aval ⇒ the UniformPool interns it to one heap slot anyway. */
|
|
9
|
+
HostHeap = 1
|
|
10
|
+
}
|
|
11
|
+
export declare function makeHandle(tag: SlotTag, payload: number): number;
|
|
12
|
+
export declare function handleTag(h: number): SlotTag;
|
|
13
|
+
export declare function handlePayload(h: number): number;
|
|
14
|
+
/** Owner key — typically the RenderObject (or any stable object). */
|
|
15
|
+
export type RecordOwner = object;
|
|
16
|
+
export declare class RecordsBuffer {
|
|
17
|
+
private buf;
|
|
18
|
+
private owners;
|
|
19
|
+
private readonly byOwner;
|
|
20
|
+
private strideU32;
|
|
21
|
+
private count;
|
|
22
|
+
/** Bumps whenever the byte layout changes shape (stride growth) so the dispatcher recompiles. */
|
|
23
|
+
layoutVersion: number;
|
|
24
|
+
/** Bumps on every mutation (add / remove / stride growth) so the dispatcher knows to re-upload. */
|
|
25
|
+
generation: number;
|
|
26
|
+
constructor(initialCapacityRecords?: number);
|
|
27
|
+
get recordCount(): number;
|
|
28
|
+
get strideWords(): number;
|
|
29
|
+
get strideBytes(): number;
|
|
30
|
+
/** The packed record data, exactly `recordCount * strideWords` long. Upload this. */
|
|
31
|
+
get data(): Uint32Array;
|
|
32
|
+
/** Append a record. Returns its index. `inSlots` length may exceed the current stride (triggers growth). */
|
|
33
|
+
add(owner: RecordOwner, ruleId: number, outSlot: number, inSlots: readonly number[]): number;
|
|
34
|
+
/** Remove every record owned by `owner` (swap-remove against the tail). */
|
|
35
|
+
removeAllForOwner(owner: RecordOwner): void;
|
|
36
|
+
private removeAt;
|
|
37
|
+
private ensureCapacity;
|
|
38
|
+
private growStride;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/runtime/derivedUniforms/records.ts"],"names":[],"mappings":"AAcA,gFAAgF;AAChF,0BAAkB,OAAO;IACvB,+EAA+E;IAC/E,WAAW,IAAI;IACf;;;oFAGgF;IAChF,QAAQ,IAAI;CAEb;AAKD,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKhE;AACD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5C;AACD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAIjC,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,KAAK,CAAK;IAClB,iGAAiG;IACjG,aAAa,SAAK;IAClB,mGAAmG;IACnG,UAAU,SAAK;gBAEH,sBAAsB,SAAM;IAIxC,IAAI,WAAW,IAAI,MAAM,CAExB;IACD,IAAI,WAAW,IAAI,MAAM,CAExB;IACD,IAAI,WAAW,IAAI,MAAM,CAExB;IACD,qFAAqF;IACrF,IAAI,IAAI,IAAI,WAAW,CAEtB;IAED,4GAA4G;IAC5G,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAA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