typegpu 0.8.1 → 0.8.2
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/{chunk-7S3IK3D4.js → chunk-6U5HPHCJ.js} +2 -2
- package/{chunk-7XFSK632.js → chunk-CGQB3SER.js} +2 -2
- package/{chunk-4W5Z7BO4.js → chunk-CRZWTZM2.js} +2 -2
- package/chunk-CRZWTZM2.js.map +1 -0
- package/{chunk-2UXPGML5.js → chunk-ECR2EGZX.js} +2 -2
- package/{chunk-VOVQAOVG.js → chunk-PWBIFP67.js} +2 -2
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -1
- package/data/index.d.ts +3 -3
- package/data/index.js +1 -1
- package/index.d.ts +2 -2
- package/index.js +14 -14
- package/index.js.map +1 -1
- package/{matrix-DLipCOZF.d.ts → matrix-DIfOiRyz.d.ts} +1 -1
- package/package.json +5 -13
- package/std/index.d.ts +2 -2
- package/std/index.js +1 -1
- package/{tgpuConstant-BU72w5qs.d.cts → tgpuConstant-BTQFNlQH.d.ts} +9 -0
- package/chunk-3246CM7C.cjs +0 -2
- package/chunk-3246CM7C.cjs.map +0 -1
- package/chunk-4W5Z7BO4.js.map +0 -1
- package/chunk-5Y6GTBWR.cjs +0 -3
- package/chunk-5Y6GTBWR.cjs.map +0 -1
- package/chunk-PRMFGUQT.cjs +0 -2
- package/chunk-PRMFGUQT.cjs.map +0 -1
- package/chunk-TRE7NUKE.cjs +0 -10
- package/chunk-TRE7NUKE.cjs.map +0 -1
- package/chunk-ZYGTVBDH.cjs +0 -7
- package/chunk-ZYGTVBDH.cjs.map +0 -1
- package/common/index.cjs +0 -7
- package/common/index.cjs.map +0 -1
- package/common/index.d.cts +0 -24
- package/data/index.cjs +0 -2
- package/data/index.cjs.map +0 -1
- package/data/index.d.cts +0 -402
- package/index.cjs +0 -192
- package/index.cjs.map +0 -1
- package/index.d.cts +0 -369
- package/matrix-DHFT4O8f.d.cts +0 -122
- package/std/index.cjs +0 -2
- package/std/index.cjs.map +0 -1
- package/std/index.d.cts +0 -639
- package/tgpuConstant-BU72w5qs.d.ts +0 -5192
- /package/{chunk-7S3IK3D4.js.map → chunk-6U5HPHCJ.js.map} +0 -0
- /package/{chunk-7XFSK632.js.map → chunk-CGQB3SER.js.map} +0 -0
- /package/{chunk-2UXPGML5.js.map → chunk-ECR2EGZX.js.map} +0 -0
- /package/{chunk-VOVQAOVG.js.map → chunk-PWBIFP67.js.map} +0 -0
package/chunk-ZYGTVBDH.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/iwo/Projects/wigsill/packages/typegpu/dist/chunk-ZYGTVBDH.cjs","../src/data/matrix.ts","../src/tgsl/wgslGenerator.ts"],"names":["MatBase","createMatSchema","options","construct","createDualImpl","args","elements","arg","i","snip","stitch"],"mappings":"AAAA,kmCAA4kB,ICmCtjBA,EAAAA,CAAf,KAA2D,CAOlE,CAAA,CAcA,SAASC,EAAAA,CAKPC,CAAAA,CAC6E,CAC7E,IAAMC,CAAAA,CAAYC,kCAAAA,CAEhB,GAAIC,CAAAA,CAAAA,EAA6C,CAC/C,IAAMC,CAAAA,CAAqB,CAAC,CAAA,CAE5B,GAAA,CAAA,IAAWC,EAAAA,GAAOF,CAAAA,CAChB,EAAA,CAAI,OAAOE,CAAAA,EAAQ,QAAA,CACjBD,CAAAA,CAAS,IAAA,CAAKC,CAAG,CAAA,CAAA,KAEjB,GAAA,CAAA,IAAS,CAAA,CAAI,CAAA,CAAG,CAAA,CAAIA,CAAAA,CAAI,MAAA,CAAQ,EAAE,CAAA,CAChCD,CAAAA,CAAS,IAAA,CAAKC,CAAAA,CAAI,CAAC,CAAW,CAAA,CAKpC,EAAA,CACED,CAAAA,CAAS,MAAA,GAAW,CAAA,EACpBA,CAAAA,CAAS,MAAA,GAAWJ,CAAAA,CAAQ,OAAA,CAAUA,CAAAA,CAAQ,IAAA,CAE9C,MAAM,IAAI,KAAA,CACR,CAAA,CAAA,EAAIA,CAAAA,CAAQ,IAAI,CAAA,sDAAA,CAClB,CAAA,CAGF,GAAA,CAAA,IAASM,CAAAA,CAAIF,CAAAA,CAAS,MAAA,CAAQE,CAAAA,CAAIN,CAAAA,CAAQ,OAAA,CAAUA,CAAAA,CAAQ,IAAA,CAAM,EAAEM,CAAAA,CAClEF,CAAAA,CAAS,IAAA,CAAK,CAAC,CAAA,CAGjB,OAAO,IAAIJ,CAAAA,CAAQ,OAAA,CAAQ,GAAGI,CAAQ,CACxC,CAAA,CAEA,CAAA,GAAID,CAAAA,CAAAA,EACFI,kCAAAA,oBAAKC,CAAAA,EAAAA;AC4DE;AACP;AAwFOD;AAqdgC;AAiE7B","file":"/Users/iwo/Projects/wigsill/packages/typegpu/dist/chunk-ZYGTVBDH.cjs","sourcesContent":[null,"import { createDualImpl } from '../core/function/dualImpl.ts';\nimport { stitch } from '../core/resolve/stitch.ts';\nimport { $repr } from '../shared/symbols.ts';\nimport { $internal, $resolve } from '../shared/symbols.ts';\nimport type { SelfResolvable } from '../types.ts';\nimport type { AnyData } from './dataTypes.ts';\nimport { type ResolvedSnippet, snip } from './snippet.ts';\nimport { vec2f, vec3f, vec4f } from './vector.ts';\nimport type {\n m2x2f,\n m3x3f,\n m4x4f,\n mat2x2,\n Mat2x2f,\n mat3x3,\n Mat3x3f,\n mat4x4,\n Mat4x4f,\n NumberArrayView,\n v2f,\n v3f,\n v4f,\n VecKind,\n} from './wgslTypes.ts';\n\n// --------------\n// Implementation\n// --------------\n\ntype vBase = {\n kind: VecKind;\n length: number;\n [n: number]: number;\n};\n\nexport abstract class MatBase<TColumn> implements NumberArrayView {\n abstract readonly [$internal]: true;\n abstract readonly columns: readonly TColumn[];\n\n abstract readonly length: number;\n abstract [Symbol.iterator](): Iterator<number>;\n [n: number]: number;\n}\n\ninterface MatSchemaOptions<TType extends string, ColumnType> {\n type: TType;\n rows: 2 | 3 | 4;\n columns: 2 | 3 | 4;\n MatImpl: new (...args: number[]) => MatBase<ColumnType>;\n}\n\ntype MatConstructor<\n ValueType extends MatBase<ColumnType>,\n ColumnType extends vBase,\n> = (...args: (number | ColumnType)[]) => ValueType;\n\nfunction createMatSchema<\n TType extends string,\n ValueType extends MatBase<ColumnType>,\n ColumnType extends vBase,\n>(\n options: MatSchemaOptions<TType, ColumnType>,\n): { type: TType; [$repr]: ValueType } & MatConstructor<ValueType, ColumnType> {\n const construct = createDualImpl(\n // CPU implementation\n (...args: (number | ColumnType)[]): ValueType => {\n const elements: number[] = [];\n\n for (const arg of args) {\n if (typeof arg === 'number') {\n elements.push(arg);\n } else {\n for (let i = 0; i < arg.length; ++i) {\n elements.push(arg[i] as number);\n }\n }\n }\n\n if (\n elements.length !== 0 &&\n elements.length !== options.columns * options.rows\n ) {\n throw new Error(\n `'${options.type}' constructor called with invalid number of arguments.`,\n );\n }\n\n for (let i = elements.length; i < options.columns * options.rows; ++i) {\n elements.push(0);\n }\n\n return new options.MatImpl(...elements) as ValueType;\n },\n // CODEGEN implementation\n (...args) =>\n snip(stitch`${options.type}(${args})`, schema as unknown as AnyData),\n options.type,\n );\n\n const schema = Object.assign(construct, {\n type: options.type,\n identity: identityFunctions[options.columns],\n translation: options.columns === 4 ? translation4 : undefined,\n scaling: options.columns === 4 ? scaling4 : undefined,\n rotationX: options.columns === 4 ? rotationX4 : undefined,\n rotationY: options.columns === 4 ? rotationY4 : undefined,\n rotationZ: options.columns === 4 ? rotationZ4 : undefined,\n }) as unknown as {\n type: TType;\n [$repr]: ValueType;\n } & MatConstructor<ValueType, ColumnType>;\n\n return schema;\n}\n\nabstract class mat2x2Impl<TColumn extends v2f> extends MatBase<TColumn>\n implements mat2x2<TColumn>, SelfResolvable {\n public readonly [$internal] = true;\n public readonly columns: readonly [TColumn, TColumn];\n public readonly length = 4;\n public abstract readonly kind: string;\n [n: number]: number;\n\n constructor(...elements: number[]) {\n super();\n this.columns = [\n this.makeColumn(elements[0] as number, elements[1] as number),\n this.makeColumn(elements[2] as number, elements[3] as number),\n ];\n }\n\n abstract makeColumn(e0: number, e1: number): TColumn;\n\n get 0() {\n return this.columns[0].x;\n }\n\n get 1() {\n return this.columns[0].y;\n }\n\n get 2() {\n return this.columns[1].x;\n }\n\n get 3() {\n return this.columns[1].y;\n }\n\n set 0(value: number) {\n this.columns[0].x = value;\n }\n\n set 1(value: number) {\n this.columns[0].y = value;\n }\n\n set 2(value: number) {\n this.columns[1].x = value;\n }\n\n set 3(value: number) {\n this.columns[1].y = value;\n }\n\n *[Symbol.iterator]() {\n yield this[0];\n yield this[1];\n yield this[2];\n yield this[3];\n }\n\n [$resolve](): ResolvedSnippet {\n return snip(\n `${this.kind}(${\n Array.from({ length: this.length })\n .map((_, i) => this[i])\n .join(', ')\n })`,\n mat2x2f,\n );\n }\n\n toString() {\n return this[$resolve]().value;\n }\n}\n\nclass mat2x2fImpl extends mat2x2Impl<v2f> {\n public readonly kind = 'mat2x2f';\n\n makeColumn(e0: number, e1: number): v2f {\n return vec2f(e0, e1);\n }\n}\n\nabstract class mat3x3Impl<TColumn extends v3f> extends MatBase<TColumn>\n implements mat3x3<TColumn>, SelfResolvable {\n public readonly [$internal] = true;\n public readonly columns: readonly [TColumn, TColumn, TColumn];\n public readonly length = 12;\n public abstract readonly kind: string;\n [n: number]: number;\n\n constructor(...elements: number[]) {\n super();\n this.columns = [\n this.makeColumn(\n elements[0] as number,\n elements[1] as number,\n elements[2] as number,\n ),\n this.makeColumn(\n elements[3] as number,\n elements[4] as number,\n elements[5] as number,\n ),\n this.makeColumn(\n elements[6] as number,\n elements[7] as number,\n elements[8] as number,\n ),\n ];\n }\n\n abstract makeColumn(x: number, y: number, z: number): TColumn;\n\n get 0() {\n return this.columns[0].x;\n }\n\n get 1() {\n return this.columns[0].y;\n }\n\n get 2() {\n return this.columns[0].z;\n }\n\n get 3() {\n return 0;\n }\n\n get 4() {\n return this.columns[1].x;\n }\n\n get 5() {\n return this.columns[1].y;\n }\n\n get 6() {\n return this.columns[1].z;\n }\n\n get 7() {\n return 0;\n }\n\n get 8() {\n return this.columns[2].x;\n }\n\n get 9() {\n return this.columns[2].y;\n }\n\n get 10() {\n return this.columns[2].z;\n }\n\n get 11() {\n return 0;\n }\n\n set 0(value: number) {\n this.columns[0].x = value;\n }\n\n set 1(value: number) {\n this.columns[0].y = value;\n }\n\n set 2(value: number) {\n this.columns[0].z = value;\n }\n\n set 3(_: number) {}\n\n set 4(value: number) {\n this.columns[1].x = value;\n }\n\n set 5(value: number) {\n this.columns[1].y = value;\n }\n\n set 6(value: number) {\n this.columns[1].z = value;\n }\n\n set 7(_: number) {}\n\n set 8(value: number) {\n this.columns[2].x = value;\n }\n\n set 9(value: number) {\n this.columns[2].y = value;\n }\n\n set 10(value: number) {\n this.columns[2].z = value;\n }\n\n set 11(_: number) {}\n\n *[Symbol.iterator]() {\n for (let i = 0; i < 12; i++) {\n yield this[i] as number;\n }\n }\n\n [$resolve](): ResolvedSnippet {\n return snip(\n `${this.kind}(${this[0]}, ${this[1]}, ${this[2]}, ${this[4]}, ${\n this[5]\n }, ${this[6]}, ${this[8]}, ${this[9]}, ${this[10]})`,\n mat3x3f,\n );\n }\n\n toString() {\n return this[$resolve]().value;\n }\n}\n\nclass mat3x3fImpl extends mat3x3Impl<v3f> {\n public readonly kind = 'mat3x3f';\n makeColumn(x: number, y: number, z: number): v3f {\n return vec3f(x, y, z);\n }\n}\n\nabstract class mat4x4Impl<TColumn extends v4f> extends MatBase<TColumn>\n implements mat4x4<TColumn>, SelfResolvable {\n public readonly [$internal] = true;\n public readonly columns: readonly [TColumn, TColumn, TColumn, TColumn];\n public abstract readonly kind: string;\n\n constructor(...elements: number[]) {\n super();\n this.columns = [\n this.makeColumn(\n elements[0] as number,\n elements[1] as number,\n elements[2] as number,\n elements[3] as number,\n ),\n this.makeColumn(\n elements[4] as number,\n elements[5] as number,\n elements[6] as number,\n elements[7] as number,\n ),\n this.makeColumn(\n elements[8] as number,\n elements[9] as number,\n elements[10] as number,\n elements[11] as number,\n ),\n this.makeColumn(\n elements[12] as number,\n elements[13] as number,\n elements[14] as number,\n elements[15] as number,\n ),\n ];\n }\n\n abstract makeColumn(x: number, y: number, z: number, w: number): TColumn;\n\n public readonly length = 16;\n [n: number]: number;\n\n get 0() {\n return this.columns[0].x;\n }\n\n get 1() {\n return this.columns[0].y;\n }\n\n get 2() {\n return this.columns[0].z;\n }\n\n get 3() {\n return this.columns[0].w;\n }\n\n get 4() {\n return this.columns[1].x;\n }\n\n get 5() {\n return this.columns[1].y;\n }\n\n get 6() {\n return this.columns[1].z;\n }\n\n get 7() {\n return this.columns[1].w;\n }\n\n get 8() {\n return this.columns[2].x;\n }\n\n get 9() {\n return this.columns[2].y;\n }\n\n get 10() {\n return this.columns[2].z;\n }\n\n get 11() {\n return this.columns[2].w;\n }\n\n get 12() {\n return this.columns[3].x;\n }\n\n get 13() {\n return this.columns[3].y;\n }\n\n get 14() {\n return this.columns[3].z;\n }\n\n get 15() {\n return this.columns[3].w;\n }\n\n set 0(value: number) {\n this.columns[0].x = value;\n }\n\n set 1(value: number) {\n this.columns[0].y = value;\n }\n\n set 2(value: number) {\n this.columns[0].z = value;\n }\n\n set 3(value: number) {\n this.columns[0].w = value;\n }\n\n set 4(value: number) {\n this.columns[1].x = value;\n }\n\n set 5(value: number) {\n this.columns[1].y = value;\n }\n\n set 6(value: number) {\n this.columns[1].z = value;\n }\n\n set 7(value: number) {\n this.columns[1].w = value;\n }\n\n set 8(value: number) {\n this.columns[2].x = value;\n }\n\n set 9(value: number) {\n this.columns[2].y = value;\n }\n\n set 10(value: number) {\n this.columns[2].z = value;\n }\n\n set 11(value: number) {\n this.columns[2].w = value;\n }\n\n set 12(value: number) {\n this.columns[3].x = value;\n }\n\n set 13(value: number) {\n this.columns[3].y = value;\n }\n\n set 14(value: number) {\n this.columns[3].z = value;\n }\n\n set 15(value: number) {\n this.columns[3].w = value;\n }\n\n *[Symbol.iterator]() {\n for (let i = 0; i < 16; i++) {\n yield this[i] as number;\n }\n }\n\n [$resolve](): ResolvedSnippet {\n return snip(\n `${this.kind}(${\n Array.from({ length: this.length })\n .map((_, i) => this[i])\n .join(', ')\n })`,\n mat4x4f,\n );\n }\n\n toString() {\n return this[$resolve]().value;\n }\n}\n\nclass mat4x4fImpl extends mat4x4Impl<v4f> {\n public readonly kind = 'mat4x4f';\n\n makeColumn(x: number, y: number, z: number, w: number): v4f {\n return vec4f(x, y, z, w);\n }\n}\n\n// ----------\n// Matrix ops\n// ----------\n\n/**\n * Returns a 2-by-2 identity matrix.\n * @returns {m2x2f} The result matrix.\n */\nexport const identity2 = createDualImpl(\n // CPU implementation\n () => mat2x2f(1, 0, 0, 1),\n // CODEGEN implementation\n () => snip('mat2x2f(1, 0, 0, 1)', mat2x2f),\n 'identity2',\n);\n\n/**\n * Returns a 3-by-3 identity matrix.\n * @returns {m3x3f} The result matrix.\n */\nexport const identity3 = createDualImpl(\n // CPU implementation\n () => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1),\n // CODEGEN implementation\n () => snip('mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)', mat3x3f),\n 'identity3',\n);\n\n/**\n * Returns a 4-by-4 identity matrix.\n * @returns {m4x4f} The result matrix.\n */\nexport const identity4 = createDualImpl(\n // CPU implementation\n () => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),\n // CODEGEN implementation\n () =>\n snip('mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)', mat4x4f),\n 'identity4',\n);\n\nconst identityFunctions = {\n 2: identity2,\n 3: identity3,\n 4: identity4,\n};\n\n/**\n * Creates a 4-by-4 matrix which translates by the given vector v.\n * @param {v3f} vector - The vector by which to translate.\n * @returns {m4x4f} The translation matrix.\n */\nexport const translation4 = createDualImpl(\n // CPU implementation\n (vector: v3f) =>\n // deno-fmt-ignore\n mat4x4f(\n 1, 0, 0, 0,\n 0, 1, 0, 0,\n 0, 0, 1, 0,\n vector.x, vector.y, vector.z, 1,\n ),\n // CODEGEN implementation\n (v) =>\n snip(\n stitch`mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`,\n mat4x4f,\n ),\n 'translation4',\n);\n\n/**\n * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.\n * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.\n * @returns {m4x4f} The scaling matrix.\n */\nexport const scaling4 = createDualImpl(\n // CPU implementation\n (vector: v3f) =>\n // deno-fmt-ignore\n mat4x4f(\n vector.x, 0, 0, 0,\n 0, vector.y, 0, 0,\n 0, 0, vector.z, 0,\n 0, 0, 0, 1,\n ),\n // CODEGEN implementation\n (v) =>\n snip(\n stitch`mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`,\n mat4x4f,\n ),\n 'scaling4',\n);\n\n/**\n * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.\n * @param {number} angle - The angle by which to rotate (in radians).\n * @returns {m4x4f} The rotation matrix.\n */\nexport const rotationX4 = createDualImpl(\n // CPU implementation\n (a: number) =>\n // deno-fmt-ignore\n mat4x4f(\n 1, 0, 0, 0,\n 0, Math.cos(a), Math.sin(a), 0,\n 0, -Math.sin(a), Math.cos(a), 0,\n 0, 0, 0, 1,\n ),\n // CODEGEN implementation\n (a) =>\n snip(\n stitch`mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`,\n mat4x4f,\n ),\n 'rotationX4',\n);\n\n/**\n * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.\n * @param {number} angle - The angle by which to rotate (in radians).\n * @returns {m4x4f} The rotation matrix.\n */\nexport const rotationY4 = createDualImpl(\n // CPU implementation\n (a: number) =>\n // deno-fmt-ignore\n mat4x4f(\n Math.cos(a), 0, -Math.sin(a), 0,\n 0, 1, 0, 0,\n Math.sin(a), 0, Math.cos(a), 0,\n 0, 0, 0, 1,\n ),\n // CODEGEN implementation\n (a) =>\n snip(\n stitch`mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`,\n mat4x4f,\n ),\n 'rotationY4',\n);\n\n/**\n * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.\n * @param {number} angle - The angle by which to rotate (in radians).\n * @returns {m4x4f} The rotation matrix.\n */\nexport const rotationZ4 = createDualImpl(\n // CPU implementation\n (a: number) =>\n // deno-fmt-ignore\n mat4x4f(\n Math.cos(a), Math.sin(a), 0, 0,\n -Math.sin(a), Math.cos(a), 0, 0,\n 0, 0, 1, 0,\n 0, 0, 0, 1,\n ),\n // CODEGEN implementation\n (a) =>\n snip(\n stitch`mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`,\n mat4x4f,\n ),\n 'rotationZ4',\n);\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.\n * Also a constructor function for this matrix type.\n *\n * @example\n * const zero2x2 = mat2x2f(); // filled with zeros\n *\n * @example\n * const mat = mat2x2f(0, 1, 2, 3);\n * mat.columns[0] // vec2f(0, 1)\n * mat.columns[1] // vec2f(2, 3)\n *\n * @example\n * const mat = mat2x2f(\n * vec2f(0, 1), // column 0\n * vec2f(1, 2), // column 1\n * );\n *\n * @example\n * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))\n */\nexport const mat2x2f = createMatSchema<'mat2x2f', m2x2f, v2f>({\n type: 'mat2x2f',\n rows: 2,\n columns: 2,\n MatImpl: mat2x2fImpl,\n}) as Mat2x2f;\n\n/**\n * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.\n * Also a constructor function for this matrix type.\n *\n * @example\n * const zero3x3 = mat3x3f(); // filled with zeros\n *\n * @example\n * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);\n * mat.columns[0] // vec3f(0, 1, 2)\n * mat.columns[1] // vec3f(3, 4, 5)\n * mat.columns[2] // vec3f(6, 7, 8)\n *\n * @example\n * const mat = mat3x3f(\n * vec3f(0, 1, 2), // column 0\n * vec3f(2, 3, 4), // column 1\n * vec3f(5, 6, 7), // column 2\n * );\n *\n * @example\n * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros\n */\nexport const mat3x3f = createMatSchema<'mat3x3f', m3x3f, v3f>({\n type: 'mat3x3f',\n rows: 3,\n columns: 3,\n MatImpl: mat3x3fImpl,\n}) as Mat3x3f;\n\n/**\n * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.\n * Also a constructor function for this matrix type.\n *\n * @example\n * const zero4x4 = mat4x4f(); // filled with zeros\n *\n * @example\n * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);\n * mat.columns[0] // vec4f(0, 1, 2, 3)\n * mat.columns[1] // vec4f(4, 5, 6, 7)\n * mat.columns[2] // vec4f(8, 9, 10, 11)\n * mat.columns[3] // vec4f(12, 13, 14, 15)\n *\n * @example\n * const mat = mat4x4f(\n * vec4f(0, 1, 2, 3), // column 0\n * vec4f(4, 5, 6, 7), // column 1\n * vec4f(8, 9, 10, 11), // column 2\n * vec4f(12, 13, 14, 15), // column 3\n * );\n *\n * @example\n * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros\n */\nexport const mat4x4f = createMatSchema<'mat4x4f', m4x4f, v4f>({\n type: 'mat4x4f',\n rows: 4,\n columns: 4,\n MatImpl: mat4x4fImpl,\n}) as Mat4x4f;\n\nexport function matToArray(mat: m2x2f | m3x3f | m4x4f): number[] {\n if (mat.kind === 'mat3x3f') {\n return [\n mat[0],\n mat[1],\n mat[2],\n mat[4],\n mat[5],\n mat[6],\n mat[8],\n mat[9],\n mat[10],\n ] as number[];\n }\n\n return Array.from({ length: mat.length }).map((_, idx) => mat[idx] as number);\n}\n","import * as tinyest from 'tinyest';\nimport { stitch } from '../core/resolve/stitch.ts';\nimport { arrayOf } from '../data/array.ts';\nimport {\n type AnyData,\n ConsoleLog,\n InfixDispatch,\n isData,\n isLooseData,\n MatrixColumnsAccess,\n UnknownData,\n} from '../data/dataTypes.ts';\nimport { abstractInt, bool, u32 } from '../data/numeric.ts';\nimport { isSnippet, snip, type Snippet } from '../data/snippet.ts';\nimport * as wgsl from '../data/wgslTypes.ts';\nimport { invariant, ResolutionError, WgslTypeError } from '../errors.ts';\nimport { getName } from '../shared/meta.ts';\nimport { isMarkedInternal } from '../shared/symbols.ts';\nimport { safeStringify } from '../shared/stringify.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport { pow } from '../std/numeric.ts';\nimport { add, div, mul, sub } from '../std/operators.ts';\nimport type { FnArgsConversionHint } from '../types.ts';\nimport {\n convertStructValues,\n convertToCommonType,\n tryConvertSnippet,\n} from './conversion.ts';\nimport {\n coerceToSnippet,\n concretize,\n type GenerationCtx,\n getTypeForIndexAccess,\n getTypeForPropAccess,\n numericLiteralToSnippet,\n} from './generationHelpers.ts';\nimport type { ShaderGenerator } from './shaderGenerator.ts';\nimport { constant } from '../core/constant/tgpuConstant.ts';\n\nconst { NodeTypeCatalog: NODE } = tinyest;\n\nconst parenthesizedOps = [\n '==',\n '!=',\n '<',\n '<=',\n '>',\n '>=',\n '<<',\n '>>',\n '+',\n '-',\n '*',\n '/',\n '%',\n '|',\n '^',\n '&',\n '&&',\n '||',\n];\n\nconst binaryLogicalOps = ['&&', '||', '==', '!=', '<', '<=', '>', '>='];\n\nconst infixKinds = [\n 'vec2f',\n 'vec3f',\n 'vec4f',\n 'vec2h',\n 'vec3h',\n 'vec4h',\n 'vec2i',\n 'vec3i',\n 'vec4i',\n 'vec2u',\n 'vec3u',\n 'vec4u',\n 'mat2x2f',\n 'mat3x3f',\n 'mat4x4f',\n];\n\nexport const infixOperators = {\n add,\n sub,\n mul,\n div,\n} as const;\n\nexport type InfixOperator = keyof typeof infixOperators;\n\ntype Operator =\n | tinyest.BinaryOperator\n | tinyest.AssignmentOperator\n | tinyest.LogicalOperator\n | tinyest.UnaryOperator;\n\nfunction operatorToType<\n TL extends AnyData | UnknownData,\n TR extends AnyData | UnknownData,\n>(lhs: TL, op: Operator, rhs?: TR): TL | TR | wgsl.Bool {\n if (!rhs) {\n if (op === '!' || op === '~') {\n return bool;\n }\n\n return lhs;\n }\n\n if (binaryLogicalOps.includes(op)) {\n return bool;\n }\n\n if (op === '=') {\n return rhs;\n }\n\n return lhs;\n}\n\nconst opCodeToCodegen = {\n '+': add[$internal].gpuImpl,\n '-': sub[$internal].gpuImpl,\n '*': mul[$internal].gpuImpl,\n '/': div[$internal].gpuImpl,\n '**': pow[$internal].gpuImpl,\n} satisfies Partial<\n Record<tinyest.BinaryOperator, (...args: never[]) => unknown>\n>;\n\nclass WgslGenerator implements ShaderGenerator {\n #ctx: GenerationCtx | undefined = undefined;\n\n public initGenerator(ctx: GenerationCtx) {\n this.#ctx = ctx;\n }\n\n private get ctx(): GenerationCtx {\n if (!this.#ctx) {\n throw new Error(\n 'WGSL Generator has not yet been initialized. Please call initialize(ctx) before using the generator.',\n );\n }\n return this.#ctx;\n }\n\n public block(\n [_, statements]: tinyest.Block,\n ): string {\n this.ctx.pushBlockScope();\n try {\n this.ctx.indent();\n const body = statements.map((statement) => this.statement(statement))\n .join('\\n');\n this.ctx.dedent();\n return `{\n${body}\n${this.ctx.pre}}`;\n } finally {\n this.ctx.popBlockScope();\n }\n }\n\n public blockVariable(\n id: string,\n dataType: wgsl.AnyWgslData | UnknownData,\n ): Snippet {\n const snippet = snip(this.ctx.makeNameValid(id), dataType);\n this.ctx.defineVariable(id, snippet);\n return snippet;\n }\n\n public identifier(id: string): Snippet {\n if (!id) {\n throw new Error('Cannot resolve an empty identifier');\n }\n const res = this.ctx.getById(id);\n\n if (!res) {\n throw new Error(`Identifier ${id} not found`);\n }\n\n return res;\n }\n\n /**\n * A wrapper for `generateExpression` that updates `ctx.expectedType`\n * and tries to convert the result when it does not match the expected type.\n */\n public typedExpression(\n expression: tinyest.Expression,\n expectedType: AnyData,\n ) {\n const prevExpectedType = this.ctx.expectedType;\n this.ctx.expectedType = expectedType;\n\n try {\n const result = this.expression(expression);\n return tryConvertSnippet(result, expectedType);\n } finally {\n this.ctx.expectedType = prevExpectedType;\n }\n }\n\n public expression(\n expression: tinyest.Expression,\n ): Snippet {\n if (typeof expression === 'string') {\n return this.identifier(expression);\n }\n\n if (typeof expression === 'boolean') {\n return snip(expression, bool);\n }\n\n if (\n expression[0] === NODE.logicalExpr ||\n expression[0] === NODE.binaryExpr ||\n expression[0] === NODE.assignmentExpr\n ) {\n // Logical/Binary/Assignment Expression\n const [_, lhs, op, rhs] = expression;\n const lhsExpr = this.expression(lhs);\n const rhsExpr = this.expression(rhs);\n\n const codegen = opCodeToCodegen[op as keyof typeof opCodeToCodegen];\n if (codegen) {\n return codegen(lhsExpr, rhsExpr);\n }\n\n const forcedType = expression[0] === NODE.assignmentExpr\n ? lhsExpr.dataType.type === 'ptr'\n ? [lhsExpr.dataType.inner as AnyData]\n : [lhsExpr.dataType as AnyData]\n : undefined;\n\n const [convLhs, convRhs] =\n convertToCommonType([lhsExpr, rhsExpr], forcedType) ??\n [lhsExpr, rhsExpr];\n\n const lhsStr = this.ctx.resolve(convLhs.value, convLhs.dataType).value;\n const rhsStr = this.ctx.resolve(convRhs.value, convRhs.dataType).value;\n const type = operatorToType(convLhs.dataType, op, convRhs.dataType);\n\n return snip(\n parenthesizedOps.includes(op)\n ? `(${lhsStr} ${op} ${rhsStr})`\n : `${lhsStr} ${op} ${rhsStr}`,\n type,\n );\n }\n\n if (expression[0] === NODE.postUpdate) {\n // Post-Update Expression\n const [_, op, arg] = expression;\n const argExpr = this.expression(arg);\n const argStr = this.ctx.resolve(argExpr.value, argExpr.dataType).value;\n\n return snip(`${argStr}${op}`, argExpr.dataType);\n }\n\n if (expression[0] === NODE.unaryExpr) {\n // Unary Expression\n const [_, op, arg] = expression;\n const argExpr = this.expression(arg);\n const argStr = this.ctx.resolve(argExpr.value, argExpr.dataType).value;\n\n const type = operatorToType(argExpr.dataType, op);\n return snip(`${op}${argStr}`, type);\n }\n\n if (expression[0] === NODE.memberAccess) {\n // Member Access\n const [_, targetNode, property] = expression;\n const target = this.expression(targetNode);\n\n if (target.value === console) {\n return snip(\n new ConsoleLog(property),\n UnknownData,\n );\n }\n\n if (\n infixKinds.includes(target.dataType.type) &&\n property in infixOperators\n ) {\n return {\n value: new InfixDispatch(\n property,\n target,\n infixOperators[property as InfixOperator][$internal].gpuImpl,\n ),\n dataType: UnknownData,\n };\n }\n\n if (target.dataType.type === 'unknown') {\n // No idea what the type is, so we act on the snippet's value and try to guess\n\n // biome-ignore lint/suspicious/noExplicitAny: we're inspecting the value, and it could be any value\n const propValue = (target.value as any)[property];\n\n // We try to extract any type information based on the prop's value\n return coerceToSnippet(propValue);\n }\n\n if (wgsl.isPtr(target.dataType)) {\n return snip(\n `(*${this.ctx.resolve(target.value).value}).${property}`,\n getTypeForPropAccess(target.dataType.inner as AnyData, property),\n );\n }\n\n if (wgsl.isWgslArray(target.dataType) && property === 'length') {\n if (target.dataType.elementCount === 0) {\n // Dynamically-sized array\n return snip(\n `arrayLength(&${this.ctx.resolve(target.value).value})`,\n u32,\n );\n }\n\n return snip(String(target.dataType.elementCount), abstractInt);\n }\n\n if (wgsl.isMat(target.dataType) && property === 'columns') {\n return snip(new MatrixColumnsAccess(target), UnknownData);\n }\n\n if (\n wgsl.isVec(target.dataType) && wgsl.isVecInstance(target.value)\n ) {\n // We're operating on a vector that's known at resolution time\n // biome-ignore lint/suspicious/noExplicitAny: it's probably a swizzle\n return coerceToSnippet((target.value as any)[property]);\n }\n\n return snip(\n `${this.ctx.resolve(target.value).value}.${property}`,\n getTypeForPropAccess(target.dataType, property),\n );\n }\n\n if (expression[0] === NODE.indexAccess) {\n // Index Access\n const [_, targetNode, propertyNode] = expression;\n const target = this.expression(targetNode);\n const property = this.expression(propertyNode);\n const propertyStr =\n this.ctx.resolve(property.value, property.dataType).value;\n\n if (target.value instanceof MatrixColumnsAccess) {\n return snip(\n stitch`${target.value.matrix}[${propertyStr}]`,\n getTypeForIndexAccess(target.value.matrix.dataType as AnyData),\n );\n }\n const targetStr = this.ctx.resolve(target.value, target.dataType).value;\n\n if (target.dataType.type === 'unknown') {\n // No idea what the type is, so we act on the snippet's value and try to guess\n\n if (\n Array.isArray(propertyNode) && propertyNode[0] === NODE.numericLiteral\n ) {\n return coerceToSnippet(\n // biome-ignore lint/suspicious/noExplicitAny: we're inspecting the value, and it could be any value\n (target.value as any)[propertyNode[1] as number],\n );\n }\n\n throw new Error(\n `Unable to index a value of unknown type with index ${propertyStr}. If the value is an array, to address this, consider one of the following approaches: (1) declare the array using 'tgpu.const', (2) store the array in a buffer, or (3) define the array within the GPU function scope.`,\n );\n }\n\n if (wgsl.isMat(target.dataType)) {\n throw new Error(\n \"The only way of accessing matrix elements in TGSL is through the 'columns' property.\",\n );\n }\n\n if (wgsl.isPtr(target.dataType)) {\n return snip(\n `(*${targetStr})[${propertyStr}]`,\n getTypeForIndexAccess(target.dataType.inner as AnyData),\n );\n }\n\n return snip(\n `${targetStr}[${propertyStr}]`,\n isData(target.dataType)\n ? getTypeForIndexAccess(target.dataType)\n : UnknownData,\n );\n }\n\n if (expression[0] === NODE.numericLiteral) {\n // Numeric Literal\n const type = typeof expression[1] === 'string'\n ? numericLiteralToSnippet(parseNumericString(expression[1]))\n : numericLiteralToSnippet(expression[1]);\n if (!type) {\n throw new Error(`Invalid numeric literal ${expression[1]}`);\n }\n return type;\n }\n\n if (expression[0] === NODE.call) {\n // Function Call\n const [_, calleeNode, argNodes] = expression;\n const callee = this.expression(calleeNode);\n\n if (wgsl.isWgslStruct(callee.value) || wgsl.isWgslArray(callee.value)) {\n // Struct/array schema call.\n if (argNodes.length > 1) {\n throw new WgslTypeError(\n 'Array and struct schemas should always be called with at most 1 argument',\n );\n }\n\n // No arguments `Struct()`, resolve struct name and return.\n if (!argNodes[0]) {\n // the schema becomes the data type\n return snip(\n `${this.ctx.resolve(callee.value).value}()`,\n callee.value,\n );\n }\n\n const arg = this.typedExpression(\n argNodes[0],\n callee.value,\n );\n\n // Either `Struct({ x: 1, y: 2 })`, or `Struct(otherStruct)`.\n // In both cases, we just let the argument resolve everything.\n return snip(\n this.ctx.resolve(arg.value, callee.value).value,\n callee.value,\n );\n }\n\n if (callee.value === constant) {\n throw new Error(\n 'Constants cannot be defined within TypeGPU function scope. To address this, move the constant definition outside the function scope.',\n );\n }\n\n if (callee.value instanceof InfixDispatch) {\n // Infix operator dispatch.\n if (!argNodes[0]) {\n throw new WgslTypeError(\n `An infix operator '${callee.value.name}' was called without any arguments`,\n );\n }\n const rhs = this.expression(argNodes[0]);\n return callee.value.operator(callee.value.lhs, rhs);\n }\n\n if (!isMarkedInternal(callee.value)) {\n const args = argNodes.map((arg) => this.expression(arg));\n const shellless = this.ctx.shelllessRepo.get(\n callee.value as (...args: never[]) => unknown,\n args,\n );\n if (shellless) {\n return this.ctx.withResetIndentLevel(() => {\n const snippet = this.ctx.resolve(shellless);\n return snip(stitch`${snippet.value}(${args})`, snippet.dataType);\n });\n }\n\n throw new Error(\n `Function '${\n getName(callee.value) ?? String(callee.value)\n }' is not marked with the 'use gpu' directive and cannot be used in a shader`,\n );\n }\n\n // Other, including tgsl functions, std and vector/matrix schema calls.\n\n const argConversionHint =\n (callee.value[$internal] as Record<string, unknown>)\n ?.argConversionHint as FnArgsConversionHint ?? 'keep';\n try {\n let convertedArguments: Snippet[];\n\n if (Array.isArray(argConversionHint)) {\n // The hint is an array of schemas.\n convertedArguments = argNodes.map((arg, i) => {\n const argType = argConversionHint[i];\n if (!argType) {\n throw new WgslTypeError(\n `Function '${\n getName(callee.value)\n }' was called with too many arguments`,\n );\n }\n return this.typedExpression(arg, argType);\n });\n } else {\n const snippets = argNodes.map((arg) => this.expression(arg));\n\n if (argConversionHint === 'keep') {\n // The hint tells us to do nothing.\n convertedArguments = snippets;\n } else if (argConversionHint === 'unify') {\n // The hint tells us to unify the types.\n convertedArguments = convertToCommonType(snippets) ?? snippets;\n } else {\n // The hint is a function that converts the arguments.\n convertedArguments = argConversionHint(...snippets)\n .map((type, i) => [type, snippets[i] as Snippet] as const)\n .map(([type, sn]) => tryConvertSnippet(sn, type));\n }\n }\n\n if (callee.value instanceof ConsoleLog) {\n return this.ctx.generateLog(callee.value.op, convertedArguments);\n }\n\n // Assuming that `callee` is callable\n const fnRes =\n (callee.value as unknown as (...args: unknown[]) => unknown)(\n ...convertedArguments,\n );\n\n if (!isSnippet(fnRes)) {\n throw new Error(\n 'Functions running in codegen mode must return snippets',\n );\n }\n return fnRes;\n } catch (error) {\n throw new ResolutionError(error, [{\n toString: () => getName(callee.value),\n }]);\n }\n }\n\n if (expression[0] === NODE.objectExpr) {\n // Object Literal\n const obj = expression[1];\n\n const structType = this.ctx.expectedType;\n\n if (!structType || !wgsl.isWgslStruct(structType)) {\n throw new WgslTypeError(\n `No target type could be inferred for object with keys [${\n Object.keys(obj).join(', ')\n }], please wrap the object in the corresponding schema.`,\n );\n }\n\n const entries = Object.fromEntries(\n Object.entries(structType.propTypes).map(([key, value]) => {\n const val = obj[key];\n if (val === undefined) {\n throw new WgslTypeError(\n `Missing property ${key} in object literal for struct ${structType}`,\n );\n }\n const result = this.typedExpression(\n val,\n value as AnyData,\n );\n return [key, result];\n }),\n );\n\n const convertedSnippets = convertStructValues(structType, entries);\n\n return snip(\n stitch`${this.ctx.resolve(structType).value}(${convertedSnippets})`,\n structType,\n );\n }\n\n if (expression[0] === NODE.arrayExpr) {\n const [_, valueNodes] = expression;\n // Array Expression\n const arrType = this.ctx.expectedType;\n let elemType: AnyData;\n let values: Snippet[];\n\n if (wgsl.isWgslArray(arrType)) {\n elemType = arrType.elementType as AnyData;\n // The array is typed, so its elements should be as well.\n values = valueNodes.map((value) =>\n this.typedExpression(value, elemType)\n );\n // Since it's an expected type, we enforce the length\n if (values.length !== arrType.elementCount) {\n throw new WgslTypeError(\n `Cannot create value of type '${arrType}' from an array of length: ${values.length}`,\n );\n }\n } else {\n // The array is not typed, so we try to guess the types.\n const valuesSnippets = valueNodes.map((value) =>\n this.expression(value as tinyest.Expression)\n );\n\n if (valuesSnippets.length === 0) {\n throw new WgslTypeError(\n 'Cannot infer the type of an empty array literal.',\n );\n }\n\n const converted = convertToCommonType(valuesSnippets);\n if (!converted) {\n throw new WgslTypeError(\n 'The given values cannot be automatically converted to a common type. Consider wrapping the array in an appropriate schema',\n );\n }\n\n values = converted;\n elemType = concretize(values[0]?.dataType as wgsl.AnyWgslData);\n }\n\n const arrayType = `array<${\n this.ctx.resolve(elemType).value\n }, ${values.length}>`;\n\n return snip(\n stitch`${arrayType}(${values})`,\n arrayOf[$internal].jsImpl(\n elemType as wgsl.AnyWgslData,\n values.length,\n ) as wgsl.AnyWgslData,\n );\n }\n\n if (expression[0] === NODE.stringLiteral) {\n return snip(expression[1], UnknownData);\n }\n\n if (expression[0] === NODE.preUpdate) {\n throw new Error('Cannot use pre-updates in TGSL.');\n }\n\n assertExhaustive(expression);\n }\n\n public functionDefinition(\n body: tinyest.Block,\n ): string {\n return this.block(body);\n }\n\n public statement(\n statement: tinyest.Statement,\n ): string {\n if (typeof statement === 'string') {\n return `${this.ctx.pre}${\n this.ctx.resolve(this.identifier(statement).value).value\n };`;\n }\n\n if (typeof statement === 'boolean') {\n return `${this.ctx.pre}${statement ? 'true' : 'false'};`;\n }\n\n if (statement[0] === NODE.return) {\n const returnNode = statement[1];\n\n if (returnNode !== undefined) {\n const expectedReturnType = this.ctx.topFunctionReturnType;\n const returnSnippet = expectedReturnType\n ? this.typedExpression(\n returnNode,\n expectedReturnType,\n )\n : this.expression(returnNode);\n\n invariant(\n returnSnippet.dataType.type !== 'unknown',\n 'Return type should be known',\n );\n\n this.ctx.reportReturnType(returnSnippet.dataType);\n return stitch`${this.ctx.pre}return ${returnSnippet};`;\n }\n\n return `${this.ctx.pre}return;`;\n }\n\n if (statement[0] === NODE.if) {\n const [_, condNode, consNode, altNode] = statement;\n const condition = this.typedExpression(condNode, bool);\n\n const consequent = condition.value === false\n ? undefined\n : this.block(blockifySingleStatement(consNode));\n const alternate = condition.value === true || !altNode\n ? undefined\n : this.block(blockifySingleStatement(altNode));\n\n if (condition.value === true) {\n return `${this.ctx.pre}${consequent}`;\n }\n\n if (condition.value === false) {\n return alternate ? `${this.ctx.pre}${alternate}` : '';\n }\n\n if (!alternate) {\n return stitch`${this.ctx.pre}if (${condition}) ${consequent}`;\n }\n\n return stitch`\\\n${this.ctx.pre}if (${condition}) ${consequent}\n${this.ctx.pre}else ${alternate}`;\n }\n\n if (statement[0] === NODE.let || statement[0] === NODE.const) {\n const [_, rawId, rawValue] = statement;\n const eq = rawValue !== undefined ? this.expression(rawValue) : undefined;\n\n if (!eq) {\n throw new Error(\n `Cannot create variable '${rawId}' without an initial value.`,\n );\n }\n\n if (isLooseData(eq.dataType)) {\n throw new Error(\n `Cannot create variable '${rawId}' with loose data type.`,\n );\n }\n\n const snippet = this.blockVariable(\n rawId,\n concretize(eq.dataType as wgsl.AnyWgslData),\n );\n return stitch`${this.ctx.pre}var ${snippet\n .value as string} = ${eq};`;\n }\n\n if (statement[0] === NODE.block) {\n return this.block(statement);\n }\n\n if (statement[0] === NODE.for) {\n const [_, init, condition, update, body] = statement;\n\n const [initStatement, conditionExpr, updateStatement] = this.ctx\n .withResetIndentLevel(\n () => [\n init ? this.statement(init) : undefined,\n condition ? this.typedExpression(condition, bool) : undefined,\n update ? this.statement(update) : undefined,\n ],\n );\n\n const initStr = initStatement ? initStatement.slice(0, -1) : '';\n const updateStr = updateStatement ? updateStatement.slice(0, -1) : '';\n\n const bodyStr = this.block(blockifySingleStatement(body));\n return stitch`${this.ctx.pre}for (${initStr}; ${conditionExpr}; ${updateStr}) ${bodyStr}`;\n }\n\n if (statement[0] === NODE.while) {\n const [_, condition, body] = statement;\n const condSnippet = this.typedExpression(condition, bool);\n const conditionStr = this.ctx.resolve(condSnippet.value).value;\n\n const bodyStr = this.block(blockifySingleStatement(body));\n return `${this.ctx.pre}while (${conditionStr}) ${bodyStr}`;\n }\n\n if (statement[0] === NODE.continue) {\n return `${this.ctx.pre}continue;`;\n }\n\n if (statement[0] === NODE.break) {\n return `${this.ctx.pre}break;`;\n }\n\n return `${this.ctx.pre}${\n this.ctx.resolve(this.expression(statement).value).value\n };`;\n }\n}\n\nfunction assertExhaustive(value: never): never {\n throw new Error(\n `'${safeStringify(value)}' was not handled by the WGSL generator.`,\n );\n}\n\nfunction parseNumericString(str: string): number {\n // Hex literals\n if (/^0x[0-9a-f]+$/i.test(str)) {\n return Number.parseInt(str);\n }\n\n // Binary literals\n if (/^0b[01]+$/i.test(str)) {\n return Number.parseInt(str.slice(2), 2);\n }\n\n return Number.parseFloat(str);\n}\n\nfunction blockifySingleStatement(statement: tinyest.Statement): tinyest.Block {\n return typeof statement !== 'object' ||\n statement[0] !== NODE.block\n ? [NODE.block, [statement]]\n : statement;\n}\n\nconst wgslGenerator: WgslGenerator = new WgslGenerator();\nexport default wgslGenerator;\n"]}
|
package/common/index.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk5Y6GTBWRcjs = require('../chunk-5Y6GTBWR.cjs');var _chunkTRE7NUKEcjs = require('../chunk-TRE7NUKE.cjs');var o=_chunk5Y6GTBWRcjs.h.call(void 0, {in:{vertexIndex:_chunkTRE7NUKEcjs.uc.vertexIndex},out:{pos:_chunkTRE7NUKEcjs.uc.position,uv:_chunkTRE7NUKEcjs.Xa}})`{
|
|
2
|
-
const pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
|
|
3
|
-
const uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
|
|
4
|
-
|
|
5
|
-
return Out(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);
|
|
6
|
-
}`;exports.fullScreenTriangle = o;
|
|
7
|
-
//# sourceMappingURL=index.cjs.map
|
package/common/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/iwo/Projects/wigsill/packages/typegpu/dist/common/index.cjs","../../src/common/fullScreenTriangle.ts"],"names":["fullScreenTriangle","vertexFn","builtin","vec2f"],"mappings":"AAAA,kIAAyC,yDAAmD,ICoB/EA,CAAAA,CAAqBC,iCAAAA,CAChC,EAAA,CAAI,CAAE,WAAA,CAAaC,oBAAAA,CAAQ,WAAY,CAAA,CACvC,GAAA,CAAK,CAAE,GAAA,CAAKA,oBAAAA,CAAQ,QAAA,CAAU,EAAA,CAAIC,oBAAM,CAC1C,CAAC,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA;ADlBD,CAAC,CAAC,CAAC,+BAA+B","file":"/Users/iwo/Projects/wigsill/packages/typegpu/dist/common/index.cjs","sourcesContent":[null,"import { builtin } from '../builtin.ts';\nimport { vertexFn } from '../core/function/tgpuVertexFn.ts';\nimport { vec2f } from '../data/vector.ts';\n\n/**\n * A vertex function that defines a single full-screen triangle out\n * of three points.\n *\n * @example\n * ```ts\n * import { fullScreenTriangle } from 'typegpu/common';\n *\n * const pipeline = root['~unstable']\n * .withVertex(fullScreenTriangle)\n * .withFragment(yourFragmentShader)\n * .createPipeline();\n *\n * pipeline.draw(3);\n * ```\n */\nexport const fullScreenTriangle = vertexFn({\n in: { vertexIndex: builtin.vertexIndex },\n out: { pos: builtin.position, uv: vec2f },\n})`{\n const pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));\n const uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));\n\n return Out(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);\n}`;\n"]}
|
package/common/index.d.cts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { aH as TgpuVertexFn, aP as Vec2f } from '../tgpuConstant-BU72w5qs.cjs';
|
|
2
|
-
import 'tinyest';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A vertex function that defines a single full-screen triangle out
|
|
6
|
-
* of three points.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { fullScreenTriangle } from 'typegpu/common';
|
|
11
|
-
*
|
|
12
|
-
* const pipeline = root['~unstable']
|
|
13
|
-
* .withVertex(fullScreenTriangle)
|
|
14
|
-
* .withFragment(yourFragmentShader)
|
|
15
|
-
* .createPipeline();
|
|
16
|
-
*
|
|
17
|
-
* pipeline.draw(3);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
declare const fullScreenTriangle: TgpuVertexFn<{}, {
|
|
21
|
-
uv: Vec2f;
|
|
22
|
-
}>;
|
|
23
|
-
|
|
24
|
-
export { fullScreenTriangle };
|
package/data/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkPRMFGUQTcjs = require('../chunk-PRMFGUQT.cjs');var _chunkZYGTVBDHcjs = require('../chunk-ZYGTVBDH.cjs');var _chunkTRE7NUKEcjs = require('../chunk-TRE7NUKE.cjs');exports.Void = _chunkTRE7NUKEcjs.q; exports.align = _chunkTRE7NUKEcjs.jc; exports.alignmentOf = _chunkTRE7NUKEcjs.fc; exports.arrayOf = _chunkTRE7NUKEcjs.tc; exports.atomic = _chunkZYGTVBDHcjs.T; exports.bool = _chunkTRE7NUKEcjs.Qa; exports.builtin = _chunkTRE7NUKEcjs.uc; exports.comparisonSampler = _chunkZYGTVBDHcjs.v; exports.deepEqual = _chunkPRMFGUQTcjs.i; exports.disarrayOf = _chunkPRMFGUQTcjs.g; exports.f16 = _chunkTRE7NUKEcjs.Va; exports.f32 = _chunkTRE7NUKEcjs.Ua; exports.float16 = _chunkTRE7NUKEcjs.Nb; exports.float16x2 = _chunkTRE7NUKEcjs.Ob; exports.float16x4 = _chunkTRE7NUKEcjs.Pb; exports.float32 = _chunkTRE7NUKEcjs.Qb; exports.float32x2 = _chunkTRE7NUKEcjs.Rb; exports.float32x3 = _chunkTRE7NUKEcjs.Sb; exports.float32x4 = _chunkTRE7NUKEcjs.Tb; exports.formatToWGSLType = _chunkTRE7NUKEcjs.nb; exports.i32 = _chunkTRE7NUKEcjs.Ta; exports.interpolate = _chunkTRE7NUKEcjs.mc; exports.invariant = _chunkTRE7NUKEcjs.nc; exports.isAlignAttrib = _chunkTRE7NUKEcjs.G; exports.isAtomic = _chunkTRE7NUKEcjs.F; exports.isBuiltin = _chunkTRE7NUKEcjs.oc; exports.isBuiltinAttrib = _chunkTRE7NUKEcjs.K; exports.isData = _chunkTRE7NUKEcjs.V; exports.isDecorated = _chunkTRE7NUKEcjs.L; exports.isDisarray = _chunkTRE7NUKEcjs.R; exports.isInterpolateAttrib = _chunkTRE7NUKEcjs.J; exports.isLocationAttrib = _chunkTRE7NUKEcjs.I; exports.isLooseData = _chunkTRE7NUKEcjs.Q; exports.isLooseDecorated = _chunkTRE7NUKEcjs.T; exports.isPackedData = _chunkTRE7NUKEcjs.cc; exports.isPtr = _chunkTRE7NUKEcjs.E; exports.isSizeAttrib = _chunkTRE7NUKEcjs.H; exports.isUnstruct = _chunkTRE7NUKEcjs.S; exports.isWgslArray = _chunkTRE7NUKEcjs.C; exports.isWgslData = _chunkTRE7NUKEcjs.B; exports.isWgslStruct = _chunkTRE7NUKEcjs.D; exports.location = _chunkTRE7NUKEcjs.lc; exports.mat2x2f = _chunkZYGTVBDHcjs.j; exports.mat3x3f = _chunkZYGTVBDHcjs.k; exports.mat4x4f = _chunkZYGTVBDHcjs.l; exports.matToArray = _chunkZYGTVBDHcjs.m; exports.packedFormats = _chunkTRE7NUKEcjs.ob; exports.ptrFn = _chunkPRMFGUQTcjs.a; exports.ptrHandle = _chunkPRMFGUQTcjs.f; exports.ptrPrivate = _chunkPRMFGUQTcjs.b; exports.ptrStorage = _chunkPRMFGUQTcjs.d; exports.ptrUniform = _chunkPRMFGUQTcjs.e; exports.ptrWorkgroup = _chunkPRMFGUQTcjs.c; exports.sampler = _chunkZYGTVBDHcjs.u; exports.sint16 = _chunkTRE7NUKEcjs.Eb; exports.sint16x2 = _chunkTRE7NUKEcjs.Fb; exports.sint16x4 = _chunkTRE7NUKEcjs.Gb; exports.sint32 = _chunkTRE7NUKEcjs.Yb; exports.sint32x2 = _chunkTRE7NUKEcjs.Zb; exports.sint32x3 = _chunkTRE7NUKEcjs._b; exports.sint32x4 = _chunkTRE7NUKEcjs.$b; exports.sint8 = _chunkTRE7NUKEcjs.sb; exports.sint8x2 = _chunkTRE7NUKEcjs.tb; exports.sint8x4 = _chunkTRE7NUKEcjs.ub; exports.size = _chunkTRE7NUKEcjs.kc; exports.sizeOf = _chunkTRE7NUKEcjs.ic; exports.snorm16 = _chunkTRE7NUKEcjs.Kb; exports.snorm16x2 = _chunkTRE7NUKEcjs.Lb; exports.snorm16x4 = _chunkTRE7NUKEcjs.Mb; exports.snorm8 = _chunkTRE7NUKEcjs.yb; exports.snorm8x2 = _chunkTRE7NUKEcjs.zb; exports.snorm8x4 = _chunkTRE7NUKEcjs.Ab; exports.struct = _chunkTRE7NUKEcjs.rc; exports.texture1d = _chunkZYGTVBDHcjs.A; exports.texture2d = _chunkZYGTVBDHcjs.B; exports.texture2dArray = _chunkZYGTVBDHcjs.D; exports.texture3d = _chunkZYGTVBDHcjs.G; exports.textureCube = _chunkZYGTVBDHcjs.E; exports.textureCubeArray = _chunkZYGTVBDHcjs.F; exports.textureDepth2d = _chunkZYGTVBDHcjs.L; exports.textureDepth2dArray = _chunkZYGTVBDHcjs.N; exports.textureDepthCube = _chunkZYGTVBDHcjs.O; exports.textureDepthCubeArray = _chunkZYGTVBDHcjs.P; exports.textureDepthMultisampled2d = _chunkZYGTVBDHcjs.M; exports.textureExternal = _chunkZYGTVBDHcjs.Q; exports.textureMultisampled2d = _chunkZYGTVBDHcjs.C; exports.textureStorage1d = _chunkZYGTVBDHcjs.H; exports.textureStorage2d = _chunkZYGTVBDHcjs.I; exports.textureStorage2dArray = _chunkZYGTVBDHcjs.J; exports.textureStorage3d = _chunkZYGTVBDHcjs.K; exports.u16 = _chunkTRE7NUKEcjs.Sa; exports.u32 = _chunkTRE7NUKEcjs.Ra; exports.uint16 = _chunkTRE7NUKEcjs.Bb; exports.uint16x2 = _chunkTRE7NUKEcjs.Cb; exports.uint16x4 = _chunkTRE7NUKEcjs.Db; exports.uint32 = _chunkTRE7NUKEcjs.Ub; exports.uint32x2 = _chunkTRE7NUKEcjs.Vb; exports.uint32x3 = _chunkTRE7NUKEcjs.Wb; exports.uint32x4 = _chunkTRE7NUKEcjs.Xb; exports.uint8 = _chunkTRE7NUKEcjs.pb; exports.uint8x2 = _chunkTRE7NUKEcjs.qb; exports.uint8x4 = _chunkTRE7NUKEcjs.rb; exports.unorm10_10_10_2 = _chunkTRE7NUKEcjs.ac; exports.unorm16 = _chunkTRE7NUKEcjs.Hb; exports.unorm16x2 = _chunkTRE7NUKEcjs.Ib; exports.unorm16x4 = _chunkTRE7NUKEcjs.Jb; exports.unorm8 = _chunkTRE7NUKEcjs.vb; exports.unorm8x2 = _chunkTRE7NUKEcjs.wb; exports.unorm8x4 = _chunkTRE7NUKEcjs.xb; exports.unorm8x4_bgra = _chunkTRE7NUKEcjs.bc; exports.unstruct = _chunkPRMFGUQTcjs.h; exports.vec2b = _chunkTRE7NUKEcjs.$a; exports.vec2f = _chunkTRE7NUKEcjs.Xa; exports.vec2h = _chunkTRE7NUKEcjs.Ya; exports.vec2i = _chunkTRE7NUKEcjs.Za; exports.vec2u = _chunkTRE7NUKEcjs._a; exports.vec3b = _chunkTRE7NUKEcjs.eb; exports.vec3f = _chunkTRE7NUKEcjs.ab; exports.vec3h = _chunkTRE7NUKEcjs.bb; exports.vec3i = _chunkTRE7NUKEcjs.cb; exports.vec3u = _chunkTRE7NUKEcjs.db; exports.vec4b = _chunkTRE7NUKEcjs.jb; exports.vec4f = _chunkTRE7NUKEcjs.fb; exports.vec4h = _chunkTRE7NUKEcjs.gb; exports.vec4i = _chunkTRE7NUKEcjs.hb; exports.vec4u = _chunkTRE7NUKEcjs.ib;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/data/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/iwo/Projects/wigsill/packages/typegpu/dist/data/index.cjs"],"names":[],"mappings":"AAAA,kIAA0G,yDAA+N,yDAAqyB,koKAA27D","file":"/Users/iwo/Projects/wigsill/packages/typegpu/dist/data/index.cjs"}
|
package/data/index.d.cts
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { aQ as Vec2b, aP as Vec2f, aR as Vec2h, aS as Vec2i, aT as Vec2u, aU as Vec3b, aV as Vec3f, aW as Vec3h, aX as Vec3i, aY as Vec3u, aZ as Vec4b, a_ as Vec4f, a$ as Vec4h, b0 as Vec4i, b1 as Vec4u, b2 as Bool, b3 as F16, b4 as F32, b5 as I32, b6 as U16, b7 as U32, j as AnyWgslData, b8 as WgslStruct, b9 as DualFn, o as WgslArray, ba as StorableData, bb as Ptr, A as AnyData, D as Disarray, bc as BaseData, bd as Unstruct, be as Atomic } from '../tgpuConstant-BU72w5qs.cjs';
|
|
2
|
-
export { br as Align, cx as AnyAttribute, cL as AnyBuiltin, bR as AnyLooseData, bs as AnyVecInstance, bt as AnyWgslStruct, bu as Builtin, cM as BuiltinClipDistances, cN as BuiltinFragDepth, cO as BuiltinFrontFacing, cP as BuiltinGlobalInvocationId, cQ as BuiltinInstanceIndex, cR as BuiltinLocalInvocationId, cS as BuiltinLocalInvocationIndex, cT as BuiltinNumWorkgroups, cU as BuiltinPosition, cV as BuiltinSampleIndex, cW as BuiltinSampleMask, cX as BuiltinVertexIndex, cY as BuiltinWorkgroupId, bv as Decorated, c$ as FormatToWGSLType, cy as HasCustomLocation, I as Infer, cZ as InferGPU, c_ as InferPartial, bw as Interpolate, cB as IsBuiltin, bx as Location, bS as LooseDecorated, bB as Mat2x2f, bC as Mat3x3f, bD as Mat4x4f, dJ as PackedData, bE as Size, d0 as TgpuVertexFormatData, bq as Void, cu as WgslComparisonSampler, c8 as WgslExternalTexture, cv as WgslSampler, c9 as WgslStorageTexture, ca as WgslStorageTexture1d, cb as WgslStorageTexture2d, cc as WgslStorageTexture2dArray, cd as WgslStorageTexture3d, ce as WgslStorageTextureProps, cf as WgslTexture, cg as WgslTexture1d, ch as WgslTexture2d, ci as WgslTexture2dArray, cj as WgslTexture3d, ck as WgslTextureCube, cl as WgslTextureCubeArray, cm as WgslTextureDepth2d, cn as WgslTextureDepth2dArray, co as WgslTextureDepthCube, cp as WgslTextureDepthCubeArray, cq as WgslTextureDepthMultisampled2d, cr as WgslTextureMultisampled2d, cw as align, cK as builtin, cs as comparisonSampler, ds as float16, dt as float16x2, du as float16x4, dv as float32, dw as float32x2, dx as float32x3, dy as float32x4, d1 as formatToWGSLType, cz as interpolate, cA as invariant, bf as isAlignAttrib, bg as isAtomic, cC as isBuiltin, bh as isBuiltinAttrib, cF as isData, bi as isDecorated, cG as isDisarray, bj as isInterpolateAttrib, bk as isLocationAttrib, cH as isLooseData, cI as isLooseDecorated, dK as isPackedData, bl as isPtr, bm as isSizeAttrib, cJ as isUnstruct, bn as isWgslArray, bo as isWgslData, bp as isWgslStruct, cD as location, by as m2x2f, bz as m3x3f, bA as m4x4f, d2 as packedFormats, ct as sampler, di as sint16, dj as sint16x2, dk as sint16x4, dD as sint32, dE as sint32x2, dF as sint32x3, dG as sint32x4, d6 as sint8, d7 as sint8x2, d8 as sint8x4, cE as size, dp as snorm16, dq as snorm16x2, dr as snorm16x4, dc as snorm8, dd as snorm8x2, de as snorm8x4, bT as texture1d, bU as texture2d, bV as texture2dArray, bW as texture3d, bX as textureCube, bY as textureCubeArray, bZ as textureDepth2d, b_ as textureDepth2dArray, b$ as textureDepthCube, c0 as textureDepthCubeArray, c1 as textureDepthMultisampled2d, c2 as textureExternal, c3 as textureMultisampled2d, c4 as textureStorage1d, c5 as textureStorage2d, c6 as textureStorage2dArray, c7 as textureStorage3d, df as uint16, dg as uint16x2, dh as uint16x4, dz as uint32, dA as uint32x2, dB as uint32x3, dC as uint32x4, d3 as uint8, d4 as uint8x2, d5 as uint8x4, dH as unorm10_10_10_2, dl as unorm16, dm as unorm16x2, dn as unorm16x4, d9 as unorm8, da as unorm8x2, db as unorm8x4, dI as unorm8x4_bgra, bF as v2b, bG as v2f, bH as v2i, bI as v2u, bJ as v3b, bK as v3f, bL as v3i, bM as v3u, bN as v4b, bO as v4f, bP as v4i, bQ as v4u } from '../tgpuConstant-BU72w5qs.cjs';
|
|
3
|
-
export { m as mat2x2f, a as mat3x3f, b as mat4x4f, c as matToArray } from '../matrix-DHFT4O8f.cjs';
|
|
4
|
-
import 'tinyest';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Schema representing vec2f - a vector with 2 elements of type f32.
|
|
8
|
-
* Also a constructor function for this vector value.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const vector = d.vec2f(); // (0.0, 0.0)
|
|
12
|
-
* const vector = d.vec2f(1); // (1.0, 1.0)
|
|
13
|
-
* const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
|
|
17
|
-
*/
|
|
18
|
-
declare const vec2f: Vec2f;
|
|
19
|
-
/**
|
|
20
|
-
* Schema representing vec2h - a vector with 2 elements of type f16.
|
|
21
|
-
* Also a constructor function for this vector value.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const vector = d.vec2h(); // (0.0, 0.0)
|
|
25
|
-
* const vector = d.vec2h(1); // (1.0, 1.0)
|
|
26
|
-
* const vector = d.vec2h(0.5, 0.1); // (0.5, 0.1)
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* const buffer = root.createBuffer(d.vec2h, d.vec2h(0, 1)); // buffer holding a d.vec2h value, with an initial value of vec2h(0, 1);
|
|
30
|
-
*/
|
|
31
|
-
declare const vec2h: Vec2h;
|
|
32
|
-
/**
|
|
33
|
-
* Schema representing vec2i - a vector with 2 elements of type i32.
|
|
34
|
-
* Also a constructor function for this vector value.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* const vector = d.vec2i(); // (0, 0)
|
|
38
|
-
* const vector = d.vec2i(1); // (1, 1)
|
|
39
|
-
* const vector = d.vec2i(-1, 1); // (-1, 1)
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
|
|
43
|
-
*/
|
|
44
|
-
declare const vec2i: Vec2i;
|
|
45
|
-
/**
|
|
46
|
-
* Schema representing vec2u - a vector with 2 elements of type u32.
|
|
47
|
-
* Also a constructor function for this vector value.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const vector = d.vec2u(); // (0, 0)
|
|
51
|
-
* const vector = d.vec2u(1); // (1, 1)
|
|
52
|
-
* const vector = d.vec2u(1, 2); // (1, 2)
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
|
|
56
|
-
*/
|
|
57
|
-
declare const vec2u: Vec2u;
|
|
58
|
-
/**
|
|
59
|
-
* Schema representing `vec2<bool>` - a vector with 2 elements of type `bool`.
|
|
60
|
-
* Also a constructor function for this vector value.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* const vector = d.vec2b(); // (false, false)
|
|
64
|
-
* const vector = d.vec2b(true); // (true, true)
|
|
65
|
-
* const vector = d.vec2b(false, true); // (false, true)
|
|
66
|
-
*/
|
|
67
|
-
declare const vec2b: Vec2b;
|
|
68
|
-
/**
|
|
69
|
-
* Schema representing vec3f - a vector with 3 elements of type f32.
|
|
70
|
-
* Also a constructor function for this vector value.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* const vector = d.vec3f(); // (0.0, 0.0, 0.0)
|
|
74
|
-
* const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
|
|
75
|
-
* const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* const buffer = root.createBuffer(d.vec3f, d.vec3f(0, 1, 2)); // buffer holding a d.vec3f value, with an initial value of vec3f(0, 1, 2);
|
|
79
|
-
*/
|
|
80
|
-
declare const vec3f: Vec3f;
|
|
81
|
-
/**
|
|
82
|
-
* Schema representing vec3h - a vector with 3 elements of type f16.
|
|
83
|
-
* Also a constructor function for this vector value.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* const vector = d.vec3h(); // (0.0, 0.0, 0.0)
|
|
87
|
-
* const vector = d.vec3h(1); // (1.0, 1.0, 1.0)
|
|
88
|
-
* const vector = d.vec3h(1, 2, 3.5); // (1.0, 2.0, 3.5)
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* const buffer = root.createBuffer(d.vec3h, d.vec3h(0, 1, 2)); // buffer holding a d.vec3h value, with an initial value of vec3h(0, 1, 2);
|
|
92
|
-
*/
|
|
93
|
-
declare const vec3h: Vec3h;
|
|
94
|
-
/**
|
|
95
|
-
* Schema representing vec3i - a vector with 3 elements of type i32.
|
|
96
|
-
* Also a constructor function for this vector value.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* const vector = d.vec3i(); // (0, 0, 0)
|
|
100
|
-
* const vector = d.vec3i(1); // (1, 1, 1)
|
|
101
|
-
* const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* const buffer = root.createBuffer(d.vec3i, d.vec3i(0, 1, 2)); // buffer holding a d.vec3i value, with an initial value of vec3i(0, 1, 2);
|
|
105
|
-
*/
|
|
106
|
-
declare const vec3i: Vec3i;
|
|
107
|
-
/**
|
|
108
|
-
* Schema representing vec3u - a vector with 3 elements of type u32.
|
|
109
|
-
* Also a constructor function for this vector value.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* const vector = d.vec3u(); // (0, 0, 0)
|
|
113
|
-
* const vector = d.vec3u(1); // (1, 1, 1)
|
|
114
|
-
* const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* const buffer = root.createBuffer(d.vec3u, d.vec3u(0, 1, 2)); // buffer holding a d.vec3u value, with an initial value of vec3u(0, 1, 2);
|
|
118
|
-
*/
|
|
119
|
-
declare const vec3u: Vec3u;
|
|
120
|
-
/**
|
|
121
|
-
* Schema representing `vec3<bool>` - a vector with 3 elements of type `bool`.
|
|
122
|
-
* Also a constructor function for this vector value.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* const vector = d.vec3b(); // (false, false, false)
|
|
126
|
-
* const vector = d.vec3b(true); // (true, true, true)
|
|
127
|
-
* const vector = d.vec3b(false, true, false); // (false, true, false)
|
|
128
|
-
*/
|
|
129
|
-
declare const vec3b: Vec3b;
|
|
130
|
-
/**
|
|
131
|
-
* Schema representing vec4f - a vector with 4 elements of type f32.
|
|
132
|
-
* Also a constructor function for this vector value.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
|
|
136
|
-
* const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
|
|
137
|
-
* const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* const buffer = root.createBuffer(d.vec4f, d.vec4f(0, 1, 2, 3)); // buffer holding a d.vec4f value, with an initial value of vec4f(0, 1, 2, 3);
|
|
141
|
-
*/
|
|
142
|
-
declare const vec4f: Vec4f;
|
|
143
|
-
/**
|
|
144
|
-
* Schema representing vec4h - a vector with 4 elements of type f16.
|
|
145
|
-
* Also a constructor function for this vector value.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* const vector = d.vec4h(); // (0.0, 0.0, 0.0, 0.0)
|
|
149
|
-
* const vector = d.vec4h(1); // (1.0, 1.0, 1.0, 1.0)
|
|
150
|
-
* const vector = d.vec4h(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* const buffer = root.createBuffer(d.vec4h, d.vec4h(0, 1, 2, 3)); // buffer holding a d.vec4h value, with an initial value of vec4h(0, 1, 2, 3);
|
|
154
|
-
*/
|
|
155
|
-
declare const vec4h: Vec4h;
|
|
156
|
-
/**
|
|
157
|
-
* Schema representing vec4i - a vector with 4 elements of type i32.
|
|
158
|
-
* Also a constructor function for this vector value.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const vector = d.vec4i(); // (0, 0, 0, 0)
|
|
162
|
-
* const vector = d.vec4i(1); // (1, 1, 1, 1)
|
|
163
|
-
* const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* const buffer = root.createBuffer(d.vec4i, d.vec4i(0, 1, 2, 3)); // buffer holding a d.vec4i value, with an initial value of vec4i(0, 1, 2, 3);
|
|
167
|
-
*/
|
|
168
|
-
declare const vec4i: Vec4i;
|
|
169
|
-
/**
|
|
170
|
-
* Schema representing vec4u - a vector with 4 elements of type u32.
|
|
171
|
-
* Also a constructor function for this vector value.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* const vector = d.vec4u(); // (0, 0, 0, 0)
|
|
175
|
-
* const vector = d.vec4u(1); // (1, 1, 1, 1)
|
|
176
|
-
* const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* const buffer = root.createBuffer(d.vec4u, d.vec4u(0, 1, 2, 3)); // buffer holding a d.vec4u value, with an initial value of vec4u(0, 1, 2, 3);
|
|
180
|
-
*/
|
|
181
|
-
declare const vec4u: Vec4u;
|
|
182
|
-
/**
|
|
183
|
-
* Schema representing `vec4<bool>` - a vector with 4 elements of type `bool`.
|
|
184
|
-
* Also a constructor function for this vector value.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* const vector = d.vec4b(); // (false, false, false, false)
|
|
188
|
-
* const vector = d.vec4b(true); // (true, true, true, true)
|
|
189
|
-
* const vector = d.vec4b(false, true, false, true); // (false, true, false, true)
|
|
190
|
-
*/
|
|
191
|
-
declare const vec4b: Vec4b;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* A schema that represents a boolean value. (equivalent to `bool` in WGSL)
|
|
195
|
-
*
|
|
196
|
-
* Can also be called to cast a value to a bool in accordance with WGSL casting rules.
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* const value = bool(); // false
|
|
200
|
-
* @example
|
|
201
|
-
* const value = bool(0); // false
|
|
202
|
-
* @example
|
|
203
|
-
* const value = bool(-0); // false
|
|
204
|
-
* @example
|
|
205
|
-
* const value = bool(21.37); // true
|
|
206
|
-
*/
|
|
207
|
-
declare const bool: Bool;
|
|
208
|
-
/**
|
|
209
|
-
* A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
|
|
210
|
-
*
|
|
211
|
-
* Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* const value = u32(); // 0
|
|
215
|
-
* @example
|
|
216
|
-
* const value = u32(7); // 7
|
|
217
|
-
* @example
|
|
218
|
-
* const value = u32(3.14); // 3
|
|
219
|
-
* @example
|
|
220
|
-
* const value = u32(-1); // 4294967295
|
|
221
|
-
* @example
|
|
222
|
-
* const value = u32(-3.1); // 0
|
|
223
|
-
*/
|
|
224
|
-
declare const u32: U32;
|
|
225
|
-
declare const u16: U16;
|
|
226
|
-
/**
|
|
227
|
-
* A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
|
|
228
|
-
*
|
|
229
|
-
* Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* const value = i32(); // 0
|
|
233
|
-
* @example
|
|
234
|
-
* const value = i32(3.14); // 3
|
|
235
|
-
* @example
|
|
236
|
-
* const value = i32(-3.9); // -3
|
|
237
|
-
* @example
|
|
238
|
-
* const value = i32(10000000000) // 1410065408
|
|
239
|
-
*/
|
|
240
|
-
declare const i32: I32;
|
|
241
|
-
/**
|
|
242
|
-
* A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
|
|
243
|
-
*
|
|
244
|
-
* Can also be called to cast a value to an f32.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* const value = f32(); // 0
|
|
248
|
-
* @example
|
|
249
|
-
* const value = f32(1.23); // 1.23
|
|
250
|
-
* @example
|
|
251
|
-
* const value = f32(true); // 1
|
|
252
|
-
*/
|
|
253
|
-
declare const f32: F32;
|
|
254
|
-
/**
|
|
255
|
-
* A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
|
|
256
|
-
*
|
|
257
|
-
* Can also be called to cast a value to an f16.
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* const value = f16(); // 0
|
|
261
|
-
* @example
|
|
262
|
-
* const value = f32(1.23); // 1.23
|
|
263
|
-
* @example
|
|
264
|
-
* const value = f16(true); // 1
|
|
265
|
-
* @example
|
|
266
|
-
* const value = f16(21877.5); // 21872
|
|
267
|
-
*/
|
|
268
|
-
declare const f16: F16;
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Creates a struct schema that can be used to construct GPU buffers.
|
|
272
|
-
* Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).
|
|
273
|
-
* The order of members matches the passed in properties object.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
|
|
277
|
-
*
|
|
278
|
-
* @param props Record with `string` keys and `TgpuData` values,
|
|
279
|
-
* each entry describing one struct member.
|
|
280
|
-
*/
|
|
281
|
-
declare function struct<TProps extends Record<string, AnyWgslData>>(props: TProps): WgslStruct<TProps>;
|
|
282
|
-
|
|
283
|
-
interface WgslArrayConstructor {
|
|
284
|
-
<TElement extends AnyWgslData>(elementType: TElement): (elementCount: number) => WgslArray<TElement>;
|
|
285
|
-
<TElement extends AnyWgslData>(elementType: TElement, elementCount: number): WgslArray<TElement>;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Creates an array schema that can be used to construct gpu buffers.
|
|
289
|
-
* Describes arrays with fixed-size length, storing elements of the same type.
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* const LENGTH = 3;
|
|
293
|
-
* const array = d.arrayOf(d.u32, LENGTH);
|
|
294
|
-
*
|
|
295
|
-
* If `elementCount` is not specified, a partially applied function is returned.
|
|
296
|
-
* @example
|
|
297
|
-
* const array = d.arrayOf(d.vec3f);
|
|
298
|
-
* // ^? (n: number) => WgslArray<d.Vec3f>
|
|
299
|
-
*
|
|
300
|
-
* @param elementType The type of elements in the array.
|
|
301
|
-
* @param elementCount The number of elements in the array.
|
|
302
|
-
*/
|
|
303
|
-
declare const arrayOf: DualFn<WgslArrayConstructor>;
|
|
304
|
-
|
|
305
|
-
declare function ptrFn<T extends StorableData>(inner: T): Ptr<'function', T, 'read-write'>;
|
|
306
|
-
declare function ptrPrivate<T extends StorableData>(inner: T): Ptr<'private', T, 'read-write'>;
|
|
307
|
-
declare function ptrWorkgroup<T extends StorableData>(inner: T): Ptr<'workgroup', T, 'read-write'>;
|
|
308
|
-
declare function ptrStorage<T extends StorableData, TAccess extends 'read' | 'read-write' = 'read'>(inner: T, access?: TAccess): Ptr<'storage', T, TAccess>;
|
|
309
|
-
declare function ptrUniform<T extends StorableData>(inner: T): Ptr<'uniform', T, 'read'>;
|
|
310
|
-
declare function ptrHandle<T extends StorableData>(inner: T): Ptr<'handle', T, 'read'>;
|
|
311
|
-
|
|
312
|
-
interface DisarrayConstructor {
|
|
313
|
-
<TElement extends AnyData>(elementType: TElement): (elementCount: number) => Disarray<TElement>;
|
|
314
|
-
<TElement extends AnyData>(elementType: TElement, elementCount: number): Disarray<TElement>;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Creates an array schema that can be used to construct vertex buffers.
|
|
318
|
-
* Describes arrays with fixed-size length, storing elements of the same type.
|
|
319
|
-
*
|
|
320
|
-
* Elements in the schema are not aligned in respect to their `byteAlignment`,
|
|
321
|
-
* unless they are explicitly decorated with the custom align attribute
|
|
322
|
-
* via `d.align` function.
|
|
323
|
-
*
|
|
324
|
-
* @example
|
|
325
|
-
* const disarray = d.disarrayOf(d.vec3f, 3); // packed array of vec3f
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* const disarray = d.disarrayOf(d.align(16, d.vec3f), 3);
|
|
329
|
-
*
|
|
330
|
-
* If `elementCount` is not specified, a partially applied function is returned.
|
|
331
|
-
* @example
|
|
332
|
-
* const disarray = d.disarrayOf(d.vec3f);
|
|
333
|
-
* // ^? (n: number) => Disarray<d.Vec3f>
|
|
334
|
-
*
|
|
335
|
-
* @param elementType The type of elements in the array.
|
|
336
|
-
* @param elementCount The number of elements in the array.
|
|
337
|
-
*/
|
|
338
|
-
declare const disarrayOf: DualFn<DisarrayConstructor>;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Creates a loose struct schema that can be used to construct vertex buffers.
|
|
342
|
-
* Describes structs with members of both loose and non-loose types.
|
|
343
|
-
*
|
|
344
|
-
* The order of members matches the passed in properties object.
|
|
345
|
-
* Members are not aligned in respect to their `byteAlignment`,
|
|
346
|
-
* unless they are explicitly decorated with the custom align attribute
|
|
347
|
-
* via `d.align` function.
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* const CircleStruct = d.unstruct({ radius: d.f32, pos: d.vec3f }); // packed struct with no padding
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* const CircleStruct = d.unstruct({ radius: d.f32, pos: d.align(16, d.vec3f) });
|
|
354
|
-
*
|
|
355
|
-
* @param properties Record with `string` keys and `TgpuData` or `TgpuLooseData` values,
|
|
356
|
-
* each entry describing one struct member.
|
|
357
|
-
*/
|
|
358
|
-
declare function unstruct<TProps extends Record<string, BaseData>>(properties: TProps): Unstruct<TProps>;
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Marks a concrete integer scalar type schema (u32 or i32) as a WGSL atomic.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* const atomicU32 = d.atomic(d.u32);
|
|
365
|
-
* const atomicI32 = d.atomic(d.i32);
|
|
366
|
-
*
|
|
367
|
-
* @param data Underlying type schema.
|
|
368
|
-
*/
|
|
369
|
-
declare function atomic<TSchema extends U32 | I32>(data: TSchema): Atomic<TSchema>;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Returns the size (in bytes) of data represented by the `schema`.
|
|
373
|
-
*/
|
|
374
|
-
declare function PUBLIC_sizeOf(schema: AnyData): number;
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Returns the alignment (in bytes) of data represented by the `schema`.
|
|
378
|
-
*/
|
|
379
|
-
declare function PUBLIC_alignmentOf(schema: AnyData): number;
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Performs a deep comparison of two TypeGPU data schemas.
|
|
383
|
-
*
|
|
384
|
-
* @param a The first data schema to compare.
|
|
385
|
-
* @param b The second data schema to compare.
|
|
386
|
-
* @returns `true` if the schemas are deeply equal, `false` otherwise.
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```ts
|
|
390
|
-
* import { vec3f, struct, deepEqual } from 'typegpu/data';
|
|
391
|
-
*
|
|
392
|
-
* const schema1 = struct({ a: vec3f });
|
|
393
|
-
* const schema2 = struct({ a: vec3f });
|
|
394
|
-
* const schema3 = struct({ b: vec3f });
|
|
395
|
-
*
|
|
396
|
-
* console.log(deepEqual(schema1, schema2)); // true
|
|
397
|
-
* console.log(deepEqual(schema1, schema3)); // false
|
|
398
|
-
* ```
|
|
399
|
-
*/
|
|
400
|
-
declare function deepEqual(a: AnyData, b: AnyData): boolean;
|
|
401
|
-
|
|
402
|
-
export { AnyData, AnyWgslData, Atomic, BaseData, BaseData as BaseWgslData, Bool, Disarray, F16, F32, I32, Ptr, StorableData, U16, U32, Unstruct, Vec2b, Vec2f, Vec2h, Vec2i, Vec2u, Vec3b, Vec3f, Vec3h, Vec3i, Vec3u, Vec4b, Vec4f, Vec4h, Vec4i, Vec4u, WgslArray, WgslStruct, PUBLIC_alignmentOf as alignmentOf, arrayOf, atomic, bool, deepEqual, disarrayOf, f16, f32, i32, ptrFn, ptrHandle, ptrPrivate, ptrStorage, ptrUniform, ptrWorkgroup, PUBLIC_sizeOf as sizeOf, struct, u16, u32, unstruct, vec2b, vec2f, vec2h, vec2i, vec2u, vec3b, vec3f, vec3h, vec3i, vec3u, vec4b, vec4f, vec4h, vec4i, vec4u };
|