typegpu 0.0.0-alpha.3 → 0.0.0-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ <div align="center">
2
+
3
+ ![TypeGPU (light mode)](/apps/typegpu-docs/public/typegpu-logo-light.svg#gh-light-mode-only)
4
+ ![TypeGPU (dark mode)](/apps/typegpu-docs/public/typegpu-logo-dark.svg#gh-dark-mode-only)
5
+
6
+ [Website](https://docs.swmansion.com/typegpu) — [Live Examples](https://docs.swmansion.com/typegpu/examples) — [Documentation](https://docs.swmansion.com/typegpu/guides/getting-started)
7
+
8
+ </div>
9
+
10
+ TypeScript library simplifying the WebGPU API and WGSL with zero-cost abstractions, type-safe data transfer and dependency injection.
11
+
12
+ ## Documentation
13
+
14
+ We created a set of guides and tutorials to get you up and running fast. Check out our [Official Docs](https://docs.swmansion.com/typegpu/guides/getting-started)!
15
+
16
+ ## Live Examples
17
+
18
+ To show the flexibility and simplicity of **TypeGPU**, we provide the [Live Examples](https://docs.swmansion.com/typegpu/examples) platform. It allows you to change the example
19
+ code in real-time!
20
+
21
+ ## What's next?
22
+
23
+ - [Join the Software Mansion Community Discord](https://discord.swmansion.com) to chat about TypeGPU or other Software Mansion libraries.
24
+
25
+ ## TypeGPU is created by Software Mansion
26
+
27
+ [![swm](https://logo.swmansion.com/logo?color=white&variant=desktop&width=150&tag=react-native-reanimated-github 'Software Mansion')](https://swmansion.com)
28
+
29
+ Since 2012 [Software Mansion](https://swmansion.com) is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – [Hire us](https://swmansion.com/contact/projects?utm_source=reanimated&utm_medium=readme).
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var E=Object.defineProperty,M=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var x=(t,n,e)=>n in t?E(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,ee= exports.a =(t,n)=>{for(var e in n||(n={}))D.call(n,e)&&x(t,e,n[e]);if(f)for(var e of f(n))B.call(n,e)&&x(t,e,n[e]);return t},te= exports.b =(t,n)=>M(t,k(n));var re=(t,n)=>{var e={};for(var r in t)D.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&f)for(var r of f(t))n.indexOf(r)<0&&B.call(t,r)&&(e[r]=t[r]);return e};var s=(t,n,e)=>(x(t,typeof n!="symbol"?n+"":n,e),e);var _typedbinary = require('typed-binary'); var a = _interopRequireWildcard(_typedbinary); var P = _interopRequireWildcard(_typedbinary); var $ = _interopRequireWildcard(_typedbinary);var R=class t extends Error{constructor(e,r){let i=r.map(p=>`- ${p}`);i.length>20&&(i=[...i.slice(0,11),"...",...i.slice(-10)]);super(`Resolution of the following tree failed:
2
+ ${i.join(`
3
+ `)}`);this.cause=e;this.trace=r;Object.setPrototypeOf(this,t.prototype)}appendToTrace(e){let r=[e,...this.trace];return new t(this.cause,r)}},A= exports.f =class t extends Error{constructor(e){super(`Missing value for '${e}'`);this.slot=e;Object.setPrototypeOf(this,t.prototype)}},d= exports.g =class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};function C(t,n){let e="size"in t?t.size:t.currentByteOffset,r=n-1,i=e&r;"skipBytes"in t?t.skipBytes(n-i&r):t.add(n-i&r)}var m=C;var o=class extends _typedbinary.Schema{constructor({schema:e,byteAlignment:r,code:i}){super();s(this,"size");s(this,"byteAlignment");s(this,"expressionCode");s(this,"_innerSchema");this._innerSchema=e,this.byteAlignment=r,this.expressionCode=i,this.size=this.measure(_typedbinary.MaxValue).size}resolveReferences(){throw new d}write(e,r){m(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return m(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}getUnderlyingTypeString(){if(typeof this.expressionCode=="string")return this.expressionCode;if("elementSchema"in this._innerSchema)return this._innerSchema.elementSchema.getUnderlyingTypeString();throw new Error("Unexpected type used as vertex buffer element")}getUnderlyingType(){return"elementSchema"in this._innerSchema?this._innerSchema.elementSchema.getUnderlyingType():this}resolve(e){return e.resolve(this.expressionCode)}};var ce=new o({schema:a.bool,byteAlignment:4,code:"bool"}),c= exports.s =new o({schema:a.u32,byteAlignment:4,code:"u32"}),de= exports.t =new o({schema:a.i32,byteAlignment:4,code:"i32"}),T= exports.u =new o({schema:a.f32,byteAlignment:4,code:"f32"}),ye= exports.v =new o({schema:a.tupleOf([a.u32,a.u32]),byteAlignment:8,code:"vec2u"}),ge= exports.w =new o({schema:a.tupleOf([a.i32,a.i32]),byteAlignment:8,code:"vec2i"}),fe= exports.x =new o({schema:a.tupleOf([a.f32,a.f32]),byteAlignment:8,code:"vec2f"}),g= exports.y =new o({schema:a.tupleOf([a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec3u"}),xe= exports.z =new o({schema:a.tupleOf([a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec3i"}),Te= exports.A =new o({schema:a.tupleOf([a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec3f"}),be= exports.B =new o({schema:a.tupleOf([a.u32,a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec4u"}),he= exports.C =new o({schema:a.tupleOf([a.i32,a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec4i"}),b= exports.D =new o({schema:a.tupleOf([a.f32,a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec4f"}),We= exports.E =new o({schema:a.arrayOf(a.f32,16),byteAlignment:16,code:"mat4x4f"});function h(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function Se(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||h(t)}function ve(t){return t.__brand==="WgslSlot"}function we(t){return t==="sampler"||t==="sampler_comparison"}function Ie(t){return["texture_1d","texture_2d","texture_2d_array","texture_3d","texture_cube","texture_cube_array","texture_multisampled_2d"].includes(t)}function De(t){return["texture_depth_2d","texture_depth_2d_array","texture_depth_cube","texture_depth_cube_array","texture_depth_multisampled_2d"].includes(t)}function Be(t){return["texture_storage_1d","texture_storage_2d","texture_storage_2d_array","texture_storage_3d"].includes(t)}function Re(t){return t==="texture_external"}function Ae(t){return"pointsTo"in t}var l=class{constructor(){s(this,"label")}$name(n){return this.label=n,this}resolve(n){return n.nameFor(this)}toString(){var n;return`id:${(n=this.label)!=null?n:"<unnamed>"}`}};var u={vertexIndex:Symbol("builtin_vertexIndex"),instanceIndex:Symbol("builtin_instanceIndex"),position:Symbol("builtin_position"),clipDistances:Symbol("builtin_clipDistances"),frontFacing:Symbol("builtin_frontFacing"),fragDepth:Symbol("builtin_fragDepth"),sampleIndex:Symbol("builtin_sampleIndex"),sampleMask:Symbol("builtin_sampleMask"),fragment:Symbol("builtin_fragment"),localInvocationId:Symbol("builtin_localInvocationId"),localInvocationIndex:Symbol("builtin_localInvocationIndex"),globalInvocationId:Symbol("builtin_globalInvocationId"),workgroupId:Symbol("builtin_workgroupId"),numWorkgroups:Symbol("builtin_numWorkgroups")},U={[u.vertexIndex]:{name:"vertex_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("vertex_index")},[u.instanceIndex]:{name:"instance_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("instance_index")},[u.position]:{name:"position",stage:"vertex",direction:"output",type:b,identifier:new l().$name("position")},[u.clipDistances]:{name:"clip_distances",stage:"vertex",direction:"output",type:new o({schema:P.arrayOf(c,8),byteAlignment:16,code:"array<u32, 8>"}),identifier:new l().$name("clip_distances")},[u.frontFacing]:{name:"front_facing",stage:"fragment",direction:"input",type:T,identifier:new l().$name("front_facing")},[u.fragDepth]:{name:"frag_depth",stage:"fragment",direction:"output",type:T,identifier:new l().$name("frag_depth")},[u.sampleIndex]:{name:"sample_index",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_index")},[u.sampleMask]:{name:"sample_mask",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_mask")},[u.fragment]:{name:"fragment",stage:"fragment",direction:"input",type:b,identifier:new l().$name("fragment")},[u.localInvocationId]:{name:"local_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("local_invocation_id")},[u.localInvocationIndex]:{name:"local_invocation_index",stage:"compute",direction:"input",type:c,identifier:new l().$name("local_invocation_index")},[u.globalInvocationId]:{name:"global_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("global_invocation_id")},[u.workgroupId]:{name:"workgroup_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("workgroup_id")},[u.numWorkgroups]:{name:"num_workgroups",stage:"compute",direction:"input",type:g,identifier:new l().$name("num_workgroups")}};function V(t){let n=U[t];if(!n)throw new Error("Symbol is not a member of builtin");return n}function Ee(t){return Object.getOwnPropertySymbols(t).map(e=>{let r=U[e];if(!r)throw new Error("Symbol is not a member of builtin");let i=t[e];if(!i)throw new Error("Name is not provided");return{name:i,builtin:r}})}function y(t,...n){let e=t.flatMap((r,i)=>{let p=n[i];return p===void 0?[r]:Array.isArray(p)?[r,...p]:[r,p]});return new W(e)}var W=class{constructor(n){this.segments=n;s(this,"_label")}get label(){return this._label}$name(n){return this._label=n,this}resolve(n){let e="";for(let r of this.segments)if(typeof r=="function"){let i=r(p=>n.unwrap(p));e+=n.resolve(i)}else if(h(r))e+=n.resolve(r);else if(typeof r=="symbol"){let i=V(r);n.addBuiltin(i),e+=n.resolve(i.identifier)}else e+=String(r);return e}with(n,e){return new _(this,[n,e])}toString(){var n;return`code:${(n=this._label)!=null?n:"<unnamed>"}`}},_=class t{constructor(n,e){this._innerFn=n;this._slotValuePair=e}get label(){return this._innerFn.label}with(n,e){return new t(this,[n,e])}resolve(n){return n.resolve(this._innerFn,[this._slotValuePair])}toString(){var r,i;let[n,e]=this._slotValuePair;return`code:${(r=this.label)!=null?r:"<unnamed>"}[${(i=n.label)!=null?i:"<unnamed>"}=${e}]`}};var S=class extends _typedbinary.Schema{constructor(e,r){super();this._elementType=e;this.capacity=r;s(this,"_label");s(this,"byteAlignment");s(this,"size");this.byteAlignment=Math.max(4,this._elementType.byteAlignment),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){if(r.length>this.capacity)throw new (0, _typedbinary.ValidationError)(`Tried to write too many values, ${r.length} > ${this.capacity}`);m(e,this.byteAlignment),c.write(e,r.length),m(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let p of r)this._elementType.write(e,p);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];m(e,this.byteAlignment);let i=c.read(e);m(e,this._elementType.byteAlignment);let p=e.currentByteOffset;for(let I=0;I<i;++I)r.push(this._elementType.read(e));return e.seekTo(p+this.capacity*this._elementType.size),r}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),c.measure(_typedbinary.MaxValue,r),m(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
4
+ struct ${r} {
5
+ count: u32,
6
+ values: array<${this._elementType}, ${this.capacity}>,
7
+ }`),e.resolve(r)}},Je= exports.G =(t,n)=>new S(t,n);var rt=t=>new v(t),v=class extends _typedbinary.Schema{constructor(e){super();this._properties=e;s(this,"_label");s(this,"_innerSchema");s(this,"byteAlignment");s(this,"size");this._innerSchema=_typedbinary.object.call(void 0, e),this.byteAlignment=Object.values(e).map(r=>r.byteAlignment).reduce((r,i)=>r>i?r:i),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
8
+ struct ${r} {
9
+ ${Object.entries(this._properties).map(([i,p])=>y`${i}: ${p},\n`)}
10
+ }
11
+ `),e.resolve(r)}};var ot=(t,n)=>new o({schema:$.arrayOf(t,n),byteAlignment:t.byteAlignment,code:y`array<${t}, ${n}>`});function Q(t){return{scope:"function",pointsTo:t}}function Z(t){return new w(t)}var w=class extends _typedbinary.Schema{constructor(e){super();this.innerData=e;s(this,"size");s(this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new d}write(e,r){this.innerData.write(e,r)}read(e){return this.innerData.read(e)}measure(e,r=new _typedbinary.Measurer){return this.innerData.measure(e,r)}resolve(e){return`atomic<${e.resolve(this.innerData)}>`}};exports.a = ee; exports.b = te; exports.c = re; exports.d = s; exports.e = R; exports.f = A; exports.g = d; exports.h = h; exports.i = Se; exports.j = ve; exports.k = we; exports.l = Ie; exports.m = De; exports.n = Be; exports.o = Re; exports.p = Ae; exports.q = o; exports.r = ce; exports.s = c; exports.t = de; exports.u = T; exports.v = ye; exports.w = ge; exports.x = fe; exports.y = g; exports.z = xe; exports.A = Te; exports.B = be; exports.C = he; exports.D = b; exports.E = We; exports.F = l; exports.G = Je; exports.H = rt; exports.I = ot; exports.J = Q; exports.K = Z; exports.L = u; exports.M = V; exports.N = Ee; exports.O = y;
12
+ //# sourceMappingURL=chunk-7HTWRNOH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/data/std140.ts","../src/errors.ts","../src/data/alignIO.ts","../src/data/numeric.ts","../src/data/dynamicArray.ts","../src/types.ts","../src/wgslBuiltin.ts","../src/wgslIdentifier.ts","../src/wgslCode.ts","../src/data/struct.ts","../src/data/array.ts","../src/data/pointer.ts","../src/data/atomic.ts"],"names":["MaxValue","Measurer","Schema","ResolutionError","_ResolutionError","cause","trace","entries","ancestor","newTrace","MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","SimpleWgslData","schema","byteAlignment","code","__publicField","output","value","input","measurer","ctx","TB","bool","u32","i32","f32","vec2u","vec2i","vec2f","vec3u","vec3i","vec3f","vec4u","vec4i","vec4f","mat4f","ValidationError","isResolvable","isWgsl","isSlot","isSamplerType","type","isTypedTextureType","isDepthTextureType","isStorageTextureType","isExternalTextureType","isPointer","WgslIdentifier","label","_a","builtin","builtinSymbolToObj","getBuiltinInfo","s","getUsedBuiltinsNamed","o","name","strings","params","segments","string","idx","param","WgslCodeImpl","result","eventual","BoundWgslCodeImpl","_BoundWgslCodeImpl","_innerFn","_slotValuePair","_b","DynamicArrayDataType","_elementType","capacity","values","startOffset","array","len","i","_values","identifier","dynamicArrayOf","elementType","object","struct","properties","WgslStructImpl","_properties","prop","a","b","key","field","arrayOf","size","ptr","pointsTo","atomic","data","AtomicImpl","innerData"],"mappings":"soBAIA,OAKE,YAAAA,EACA,YAAAC,EAEA,UAAAC,MAEK,eCLA,IAAMC,EAAN,MAAMC,UAAwB,KAAM,CACzC,YACkBC,EACAC,EAChB,CACA,IAAIC,EAAUD,EAAM,IAAKE,GAAa,KAAKA,CAAQ,EAAE,EAGjDD,EAAQ,OAAS,KACnBA,EAAU,CAAC,GAAGA,EAAQ,MAAM,EAAG,EAAE,EAAG,MAAO,GAAGA,EAAQ,MAAM,GAAG,CAAC,GAGlE,MAAM;AAAA,EAA8CA,EAAQ,KAAK;AAAA,CAAI,CAAC,EAAE,EAVxD,WAAAF,EACA,WAAAC,EAYhB,OAAO,eAAe,KAAMF,EAAgB,SAAS,CACvD,CAEA,cAAcI,EAA2C,CACvD,IAAMC,EAAW,CAACD,EAAU,GAAG,KAAK,KAAK,EAEzC,OAAO,IAAIJ,EAAgB,KAAK,MAAOK,CAAQ,CACjD,CACF,EAKaC,EAAN,MAAMC,UAA8B,KAAM,CAC/C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E,CAAU;AAAA,UACf,OAAO,QAAQ,KAAK,WAAW,EAAE,IAAI,CAAC,CAACW,EAAKC,CAAK,IAAM9E,IAAO6E,CAAG,KAAKC,CAAK,KAAK,CAAC;AAAA;AAAA,KAEtF,EAEMxE,EAAI,QAAQ4D,CAAU,CAC/B,CACF,EC/FA,UAAY3D,MAAQ,eASb,IAAMwE,GAAU,CACrBX,EACAY,IAEA,IAAInF,EAAe,CACjB,OAAW,UAAQuE,EAAaY,CAAI,EACpC,cAAeZ,EAAY,cAC3B,KAAMpE,UAAaoE,CAAW,KAAKY,CAAI,GACzC,CAAC,ECfI,SAASC,EACdC,EACoC,CACpC,MAAO,CACL,MAAO,WACP,SAAAA,CACF,CACF,CCTA,OAKE,YAAA1G,EAEA,UAAAC,MAEK,eAKA,SAAS0G,EACdC,EACiB,CACjB,OAAO,IAAIC,EAAWD,CAAI,CAC5B,CAKA,IAAMC,EAAN,cACU5G,CAEV,CAIE,YAA6B6G,EAAoB,CAC/C,MAAM,EADqB,eAAAA,EAH7BrF,EAAA,KAAgB,QAChBA,EAAA,KAAgB,iBAId,KAAK,KAAO,KAAK,UAAU,KAC3B,KAAK,cAAgB,KAAK,UAAU,aACtC,CAEA,mBAA0B,CACxB,MAAM,IAAIb,CACZ,CAEA,MAAMc,EAAuBC,EAAsC,CACjE,KAAK,UAAU,MAAMD,EAAQC,CAAK,CACpC,CAEA,KAAKC,EAA8C,CACjD,OAAO,KAAK,UAAU,KAAKA,CAAK,CAClC,CAEA,QACED,EACAE,EAAsB,IAAI7B,EACf,CACX,OAAO,KAAK,UAAU,QAAQ2B,EAAOE,CAAQ,CAC/C,CAEA,QAAQC,EAA4B,CAClC,MAAO,UAAUA,EAAI,QAAQ,KAAK,SAAS,CAAC,GAC9C,CACF","sourcesContent":["/*\n * Typed-binary types that adhere to the `std140` layout rules.\n */\n\nimport {\n type AnySchema,\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, Wgsl, WgslData } from '../types';\nimport alignIO from './alignIO';\n\nexport class SimpleWgslData<TSchema extends AnySchema>\n extends Schema<Unwrap<TSchema>>\n implements WgslData<Unwrap<TSchema>>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n public readonly expressionCode: Wgsl;\n\n private readonly _innerSchema: TSchema;\n\n /**\n * byteAlignment has to be a power of 2\n */\n constructor({\n schema,\n byteAlignment,\n code,\n }: {\n schema: TSchema;\n byteAlignment: number;\n code: Wgsl;\n }) {\n super();\n\n this._innerSchema = schema;\n this.byteAlignment = byteAlignment;\n this.expressionCode = code;\n this.size = this.measure(MaxValue).size;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n alignIO(output, this.byteAlignment);\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n alignIO(input, this.byteAlignment);\n return this._innerSchema.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n\n this._innerSchema.measure(value, measurer);\n\n return measurer;\n }\n\n getUnderlyingTypeString(): string {\n if (typeof this.expressionCode === 'string') {\n return this.expressionCode;\n }\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingTypeString();\n }\n throw new Error('Unexpected type used as vertex buffer element');\n }\n\n getUnderlyingType(): SimpleWgslData<AnySchema> {\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingType();\n }\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this.expressionCode);\n }\n}\n","import type { WgslResolvable, WgslSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: WgslResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: WgslResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n","import type { IMeasurer, ISerialInput, ISerialOutput } from 'typed-binary';\n\n/**\n * @param io the IO to align\n * @param baseAlignment must be power of 2\n */\nfunction alignIO(\n io: ISerialInput | ISerialOutput | IMeasurer,\n baseAlignment: number,\n) {\n const currentPos = 'size' in io ? io.size : io.currentByteOffset;\n\n const bitMask = baseAlignment - 1;\n const offset = currentPos & bitMask;\n\n if ('skipBytes' in io) {\n io.skipBytes((baseAlignment - offset) & bitMask);\n } else {\n io.add((baseAlignment - offset) & bitMask);\n }\n}\n\nexport default alignIO;\n","import * as TB from 'typed-binary';\nimport type { WgslData } from '../types';\nimport { SimpleWgslData } from './std140';\n\nexport type Bool = WgslData<boolean>;\nexport const bool: Bool = new SimpleWgslData({\n schema: TB.bool,\n byteAlignment: 4,\n code: 'bool',\n});\nexport type U32 = WgslData<number>;\nexport const u32: U32 = new SimpleWgslData({\n schema: TB.u32,\n byteAlignment: 4,\n code: 'u32',\n});\nexport type I32 = WgslData<number>;\nexport const i32: I32 = new SimpleWgslData({\n schema: TB.i32,\n byteAlignment: 4,\n code: 'i32',\n});\nexport type F32 = WgslData<number>;\nexport const f32: F32 = new SimpleWgslData({\n schema: TB.f32,\n byteAlignment: 4,\n code: 'f32',\n});\n\nexport type Vec2u = WgslData<[number, number]>;\nexport const vec2u: Vec2u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32]),\n byteAlignment: 8,\n code: 'vec2u',\n});\n\nexport type Vec2i = WgslData<[number, number]>;\nexport const vec2i: Vec2i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32]),\n byteAlignment: 8,\n code: 'vec2i',\n});\nexport type Vec2f = WgslData<[number, number]>;\nexport const vec2f: Vec2f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32]),\n byteAlignment: 8,\n code: 'vec2f',\n});\nexport type Vec3u = WgslData<[number, number, number]>;\nexport const vec3u: Vec3u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec3u',\n});\nexport type Vec3i = WgslData<[number, number, number]>;\nexport const vec3i: Vec3i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec3i',\n});\nexport type Vec3f = WgslData<[number, number, number]>;\nexport const vec3f: Vec3f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec3f',\n});\nexport type Vec4u = WgslData<[number, number, number, number]>;\nexport const vec4u: Vec4u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec4u',\n});\nexport type Vec4i = WgslData<[number, number, number, number]>;\nexport const vec4i: Vec4i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec4i',\n});\nexport type Vec4f = WgslData<[number, number, number, number]>;\nexport const vec4f: Vec4f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec4f',\n});\n\n/**\n * Array of column vectors\n */\nexport type Mat4f = WgslData<number[]>;\nexport const mat4f: Mat4f = new SimpleWgslData({\n schema: TB.arrayOf(TB.f32, 16),\n byteAlignment: 16,\n code: 'mat4x4f',\n});\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n ValidationError,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\nimport { u32 } from './numeric';\n\nclass DynamicArrayDataType<TElement extends WgslData<unknown>>\n extends Schema<Unwrap<TElement>[]>\n implements WgslData<Unwrap<TElement>[]>\n{\n private _label: string | undefined;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(\n private readonly _elementType: TElement,\n public readonly capacity: number,\n ) {\n super();\n\n this.byteAlignment = Math.max(\n 4 /* u32 base alignment */,\n this._elementType.byteAlignment,\n );\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, values: ParseUnwrapped<TElement>[]): void {\n if (values.length > this.capacity) {\n throw new ValidationError(\n `Tried to write too many values, ${values.length} > ${this.capacity}`,\n );\n }\n\n alignIO(output, this.byteAlignment); // aligning to the start\n u32.write(output, values.length);\n alignIO(output, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = output.currentByteOffset;\n for (const value of values) {\n this._elementType.write(output, value);\n }\n output.seekTo(startOffset + this.capacity * this._elementType.size);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TElement>[] {\n const array: ParseUnwrapped<TElement>[] = [];\n\n alignIO(input, this.byteAlignment); // aligning to the start\n const len = u32.read(input);\n alignIO(input, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = input.currentByteOffset;\n for (let i = 0; i < len; ++i) {\n array.push(this._elementType.read(input) as ParseUnwrapped<TElement>);\n }\n input.seekTo(startOffset + this.capacity * this._elementType.size);\n\n return array;\n }\n\n measure(\n _values: ParseUnwrapped<TElement>[] | typeof MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment); // aligning to the start\n\n // Length encoding\n u32.measure(MaxValue, measurer);\n\n // Aligning to the start of the array\n alignIO(measurer, this._elementType.byteAlignment);\n\n // Values encoding\n measurer.add(this._elementType.size * this.capacity);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n count: u32,\n values: array<${this._elementType}, ${this.capacity}>,\n }`);\n\n return ctx.resolve(identifier);\n }\n}\n\nexport const dynamicArrayOf = <TSchema extends AnyWgslData>(\n elementType: TSchema,\n capacity: number,\n) => new DynamicArrayDataType(elementType, capacity);\n\nexport default DynamicArrayDataType;\n","import type { ISchema, Parsed } from 'typed-binary';\nimport type { F32, I32, U32, Vec4f, Vec4i, Vec4u } from './data';\nimport type { Builtin } from './wgslBuiltin';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | number | WgslResolvable | symbol | boolean;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n addRenderResource(\n resource: WgslRenderResource,\n identifier: WgslIdentifier,\n ): void;\n addBuiltin(builtin: Builtin): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n get label(): string | undefined;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type WgslSamplerType = 'sampler' | 'sampler_comparison';\nexport type WgslTypedTextureType =\n | 'texture_1d'\n | 'texture_2d'\n | 'texture_2d_array'\n | 'texture_3d'\n | 'texture_cube'\n | 'texture_cube_array'\n | 'texture_multisampled_2d';\nexport type WgslDepthTextureType =\n | 'texture_depth_2d'\n | 'texture_depth_2d_array'\n | 'texture_depth_cube'\n | 'texture_depth_cube_array'\n | 'texture_depth_multisampled_2d';\nexport type WgslStorageTextureType =\n | 'texture_storage_1d'\n | 'texture_storage_2d'\n | 'texture_storage_2d_array'\n | 'texture_storage_3d';\nexport type WgslExternalTextureType = 'texture_external';\n\nexport type WgslRenderResourceType =\n | WgslSamplerType\n | WgslTypedTextureType\n | WgslDepthTextureType\n | WgslStorageTextureType\n | WgslExternalTextureType;\n\nexport interface WgslRenderResource extends WgslResolvable {\n readonly type: WgslRenderResourceType;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';\nexport type TextureUsage = 'sampled' | 'storage';\nexport type StorageTextureAccess = 'read' | 'write' | 'read_write';\n\nexport type StorageTextureParams = {\n type: WgslStorageTextureType;\n access: StorageTextureAccess;\n descriptor?: GPUTextureViewDescriptor;\n};\nexport type SampledTextureParams = {\n type: WgslTypedTextureType;\n dataType: AnyWgslPrimitive;\n descriptor?: GPUTextureViewDescriptor;\n};\n\nexport function isSamplerType(\n type: WgslRenderResourceType,\n): type is WgslSamplerType {\n return type === 'sampler' || type === 'sampler_comparison';\n}\n\nexport function isTypedTextureType(\n type: WgslRenderResourceType,\n): type is WgslTypedTextureType {\n return [\n 'texture_1d',\n 'texture_2d',\n 'texture_2d_array',\n 'texture_3d',\n 'texture_cube',\n 'texture_cube_array',\n 'texture_multisampled_2d',\n ].includes(type);\n}\n\nexport function isDepthTextureType(\n type: WgslRenderResourceType,\n): type is WgslDepthTextureType {\n return [\n 'texture_depth_2d',\n 'texture_depth_2d_array',\n 'texture_depth_cube',\n 'texture_depth_cube_array',\n 'texture_depth_multisampled_2d',\n ].includes(type);\n}\n\nexport function isStorageTextureType(\n type: WgslRenderResourceType,\n): type is WgslStorageTextureType {\n return [\n 'texture_storage_1d',\n 'texture_storage_2d',\n 'texture_storage_2d_array',\n 'texture_storage_3d',\n ].includes(type);\n}\n\nexport function isExternalTextureType(\n type: WgslRenderResourceType,\n): type is WgslExternalTextureType {\n return type === 'texture_external';\n}\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\nexport type AnyWgslPrimitive = U32 | I32 | F32;\nexport type AnyWgslTexelFormat = Vec4u | Vec4i | Vec4f;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import * as TB from 'typed-binary';\nimport type { F32, U32, Vec3u, Vec4f } from './data';\nimport { SimpleWgslData, f32, u32, vec3u, vec4f } from './data';\nimport type { WgslData } from './types';\nimport { WgslIdentifier } from './wgslIdentifier';\n\nexport type BuiltInPossibleTypes =\n | U32\n | F32\n | Vec3u\n | Vec4f\n | WgslData<TB.Unwrap<U32>[]>;\n\nexport const builtin = {\n vertexIndex: Symbol('builtin_vertexIndex'),\n instanceIndex: Symbol('builtin_instanceIndex'),\n position: Symbol('builtin_position'),\n clipDistances: Symbol('builtin_clipDistances'),\n frontFacing: Symbol('builtin_frontFacing'),\n fragDepth: Symbol('builtin_fragDepth'),\n sampleIndex: Symbol('builtin_sampleIndex'),\n sampleMask: Symbol('builtin_sampleMask'),\n fragment: Symbol('builtin_fragment'),\n localInvocationId: Symbol('builtin_localInvocationId'),\n localInvocationIndex: Symbol('builtin_localInvocationIndex'),\n globalInvocationId: Symbol('builtin_globalInvocationId'),\n workgroupId: Symbol('builtin_workgroupId'),\n numWorkgroups: Symbol('builtin_numWorkgroups'),\n} as const;\n\nexport interface Builtin {\n name: string;\n stage: 'vertex' | 'fragment' | 'compute';\n direction: 'input' | 'output';\n type: BuiltInPossibleTypes;\n identifier: WgslIdentifier;\n}\n\nconst builtinSymbolToObj: Record<symbol, Builtin> = {\n [builtin.vertexIndex]: {\n name: 'vertex_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('vertex_index'),\n },\n [builtin.instanceIndex]: {\n name: 'instance_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('instance_index'),\n },\n [builtin.position]: {\n name: 'position',\n stage: 'vertex',\n direction: 'output',\n type: vec4f,\n identifier: new WgslIdentifier().$name('position'),\n },\n [builtin.clipDistances]: {\n name: 'clip_distances',\n stage: 'vertex',\n direction: 'output',\n type: new SimpleWgslData({\n schema: TB.arrayOf(u32, 8),\n byteAlignment: 16,\n code: 'array<u32, 8>',\n }),\n identifier: new WgslIdentifier().$name('clip_distances'),\n },\n [builtin.frontFacing]: {\n name: 'front_facing',\n stage: 'fragment',\n direction: 'input',\n type: f32,\n identifier: new WgslIdentifier().$name('front_facing'),\n },\n [builtin.fragDepth]: {\n name: 'frag_depth',\n stage: 'fragment',\n direction: 'output',\n type: f32,\n identifier: new WgslIdentifier().$name('frag_depth'),\n },\n [builtin.sampleIndex]: {\n name: 'sample_index',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_index'),\n },\n [builtin.sampleMask]: {\n name: 'sample_mask',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_mask'),\n },\n [builtin.fragment]: {\n name: 'fragment',\n stage: 'fragment',\n direction: 'input',\n type: vec4f,\n identifier: new WgslIdentifier().$name('fragment'),\n },\n [builtin.localInvocationId]: {\n name: 'local_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('local_invocation_id'),\n },\n [builtin.localInvocationIndex]: {\n name: 'local_invocation_index',\n stage: 'compute',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('local_invocation_index'),\n },\n [builtin.globalInvocationId]: {\n name: 'global_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('global_invocation_id'),\n },\n [builtin.workgroupId]: {\n name: 'workgroup_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('workgroup_id'),\n },\n [builtin.numWorkgroups]: {\n name: 'num_workgroups',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('num_workgroups'),\n },\n};\n\nexport function getBuiltinInfo(s: symbol): Builtin {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n return builtin;\n}\n\nexport function getUsedBuiltinsNamed(\n o: Record<symbol, string>,\n): { name: string; builtin: Builtin }[] {\n const res = Object.getOwnPropertySymbols(o).map((s) => {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n const name = o[s];\n if (!name) {\n throw new Error('Name is not provided');\n }\n return { name: name, builtin: builtin };\n });\n return res;\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n","import {\n type Eventual,\n type InlineResolve,\n type ResolutionCtx,\n type SlotValuePair,\n type Wgsl,\n type WgslResolvable,\n type WgslSlot,\n isResolvable,\n} from './types';\nimport { getBuiltinInfo } from './wgslBuiltin';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n\n with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;\n}\n\nexport type BoundWgslCode = Omit<WgslCode, '$name'>;\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else if (typeof s === 'symbol') {\n const builtin = getBuiltinInfo(s);\n ctx.addBuiltin(builtin);\n code += ctx.resolve(builtin.identifier);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n\nclass BoundWgslCodeImpl<T> implements BoundWgslCode {\n constructor(\n private readonly _innerFn: BoundWgslCode,\n private readonly _slotValuePair: SlotValuePair<T>,\n ) {}\n\n get label() {\n return this._innerFn.label;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._innerFn, [this._slotValuePair]);\n }\n\n toString(): string {\n const [slot, value] = this._slotValuePair;\n return `code:${this.label ?? '<unnamed>'}[${slot.label ?? '<unnamed>'}=${value}]`;\n }\n}\n","import {\n type IMeasurer,\n type ISchema,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type Parsed,\n Schema,\n type UnwrapRecord,\n object,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslStruct<TProps extends Record<string, AnyWgslData>>\n extends ISchema<UnwrapRecord<TProps>>,\n WgslData<UnwrapRecord<TProps>> {\n $name(label: string): this;\n}\n\nexport const struct = <TProps extends Record<string, AnyWgslData>>(\n properties: TProps,\n): WgslStruct<TProps> => new WgslStructImpl(properties);\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslStructImpl<TProps extends Record<string, AnyWgslData>>\n extends Schema<UnwrapRecord<TProps>>\n implements WgslData<UnwrapRecord<TProps>>\n{\n private _label: string | undefined;\n private _innerSchema: ISchema<UnwrapRecord<TProps>>;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(private readonly _properties: TProps) {\n super();\n\n this._innerSchema = object(_properties);\n\n this.byteAlignment = Object.values(_properties)\n .map((prop) => prop.byteAlignment)\n .reduce((a, b) => (a > b ? a : b));\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: Parsed<UnwrapRecord<TProps>>): void {\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): Parsed<UnwrapRecord<TProps>> {\n return this._innerSchema.read(input);\n }\n\n measure(\n value: MaxValue | Parsed<UnwrapRecord<TProps>>,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n this._innerSchema.measure(value, measurer);\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n ${Object.entries(this._properties).map(([key, field]) => code`${key}: ${field},\\n`)}\n }\n `);\n\n return ctx.resolve(identifier);\n }\n}\n","import * as TB from 'typed-binary';\nimport type { AnyWgslData, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { SimpleWgslData } from './std140';\n\nexport type WgslArray<TElement extends AnyWgslData> = WgslData<\n TB.Unwrap<TElement>[]\n>;\n\nexport const arrayOf = <TElement extends AnyWgslData>(\n elementType: TElement,\n size: number,\n): WgslArray<TElement> =>\n new SimpleWgslData({\n schema: TB.arrayOf(elementType, size),\n byteAlignment: elementType.byteAlignment,\n code: code`array<${elementType}, ${size}>`,\n });\n","import type { AnyWgslData, WgslPointer } from '../types';\n\nexport function ptr<TDataType extends AnyWgslData>(\n pointsTo: TDataType,\n): WgslPointer<'function', TDataType> {\n return {\n scope: 'function',\n pointsTo,\n };\n}\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n type MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, WgslData } from '../types';\nimport type { I32, U32 } from './numeric';\n\nexport function atomic<TSchema extends U32 | I32>(\n data: TSchema,\n): Atomic<TSchema> {\n return new AtomicImpl(data);\n}\n\nexport interface Atomic<TSchema extends U32 | I32>\n extends WgslData<Unwrap<TSchema>> {}\n\nclass AtomicImpl<TSchema extends U32 | I32>\n extends Schema<Unwrap<TSchema>>\n implements Atomic<TSchema>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n constructor(private readonly innerData: TSchema) {\n super();\n this.size = this.innerData.size;\n this.byteAlignment = this.innerData.byteAlignment;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n this.innerData.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n return this.innerData.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n return this.innerData.measure(value, measurer);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return `atomic<${ctx.resolve(this.innerData)}>`;\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ var E=Object.defineProperty,M=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var x=(t,n,e)=>n in t?E(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,ee=(t,n)=>{for(var e in n||(n={}))D.call(n,e)&&x(t,e,n[e]);if(f)for(var e of f(n))B.call(n,e)&&x(t,e,n[e]);return t},te=(t,n)=>M(t,k(n));var re=(t,n)=>{var e={};for(var r in t)D.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&f)for(var r of f(t))n.indexOf(r)<0&&B.call(t,r)&&(e[r]=t[r]);return e};var s=(t,n,e)=>(x(t,typeof n!="symbol"?n+"":n,e),e);import{MaxValue as z,Measurer as F,Schema as j}from"typed-binary";var R=class t extends Error{constructor(e,r){let i=r.map(p=>`- ${p}`);i.length>20&&(i=[...i.slice(0,11),"...",...i.slice(-10)]);super(`Resolution of the following tree failed:
2
+ ${i.join(`
3
+ `)}`);this.cause=e;this.trace=r;Object.setPrototypeOf(this,t.prototype)}appendToTrace(e){let r=[e,...this.trace];return new t(this.cause,r)}},A=class t extends Error{constructor(e){super(`Missing value for '${e}'`);this.slot=e;Object.setPrototypeOf(this,t.prototype)}},d=class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};function C(t,n){let e="size"in t?t.size:t.currentByteOffset,r=n-1,i=e&r;"skipBytes"in t?t.skipBytes(n-i&r):t.add(n-i&r)}var m=C;var o=class extends j{constructor({schema:e,byteAlignment:r,code:i}){super();s(this,"size");s(this,"byteAlignment");s(this,"expressionCode");s(this,"_innerSchema");this._innerSchema=e,this.byteAlignment=r,this.expressionCode=i,this.size=this.measure(z).size}resolveReferences(){throw new d}write(e,r){m(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return m(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new F){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}getUnderlyingTypeString(){if(typeof this.expressionCode=="string")return this.expressionCode;if("elementSchema"in this._innerSchema)return this._innerSchema.elementSchema.getUnderlyingTypeString();throw new Error("Unexpected type used as vertex buffer element")}getUnderlyingType(){return"elementSchema"in this._innerSchema?this._innerSchema.elementSchema.getUnderlyingType():this}resolve(e){return e.resolve(this.expressionCode)}};import*as a from"typed-binary";var ce=new o({schema:a.bool,byteAlignment:4,code:"bool"}),c=new o({schema:a.u32,byteAlignment:4,code:"u32"}),de=new o({schema:a.i32,byteAlignment:4,code:"i32"}),T=new o({schema:a.f32,byteAlignment:4,code:"f32"}),ye=new o({schema:a.tupleOf([a.u32,a.u32]),byteAlignment:8,code:"vec2u"}),ge=new o({schema:a.tupleOf([a.i32,a.i32]),byteAlignment:8,code:"vec2i"}),fe=new o({schema:a.tupleOf([a.f32,a.f32]),byteAlignment:8,code:"vec2f"}),g=new o({schema:a.tupleOf([a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec3u"}),xe=new o({schema:a.tupleOf([a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec3i"}),Te=new o({schema:a.tupleOf([a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec3f"}),be=new o({schema:a.tupleOf([a.u32,a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec4u"}),he=new o({schema:a.tupleOf([a.i32,a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec4i"}),b=new o({schema:a.tupleOf([a.f32,a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec4f"}),We=new o({schema:a.arrayOf(a.f32,16),byteAlignment:16,code:"mat4x4f"});import{MaxValue as O,Measurer as G,Schema as L,ValidationError as N}from"typed-binary";function h(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function Se(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||h(t)}function ve(t){return t.__brand==="WgslSlot"}function we(t){return t==="sampler"||t==="sampler_comparison"}function Ie(t){return["texture_1d","texture_2d","texture_2d_array","texture_3d","texture_cube","texture_cube_array","texture_multisampled_2d"].includes(t)}function De(t){return["texture_depth_2d","texture_depth_2d_array","texture_depth_cube","texture_depth_cube_array","texture_depth_multisampled_2d"].includes(t)}function Be(t){return["texture_storage_1d","texture_storage_2d","texture_storage_2d_array","texture_storage_3d"].includes(t)}function Re(t){return t==="texture_external"}function Ae(t){return"pointsTo"in t}import*as P from"typed-binary";var l=class{constructor(){s(this,"label")}$name(n){return this.label=n,this}resolve(n){return n.nameFor(this)}toString(){var n;return`id:${(n=this.label)!=null?n:"<unnamed>"}`}};var u={vertexIndex:Symbol("builtin_vertexIndex"),instanceIndex:Symbol("builtin_instanceIndex"),position:Symbol("builtin_position"),clipDistances:Symbol("builtin_clipDistances"),frontFacing:Symbol("builtin_frontFacing"),fragDepth:Symbol("builtin_fragDepth"),sampleIndex:Symbol("builtin_sampleIndex"),sampleMask:Symbol("builtin_sampleMask"),fragment:Symbol("builtin_fragment"),localInvocationId:Symbol("builtin_localInvocationId"),localInvocationIndex:Symbol("builtin_localInvocationIndex"),globalInvocationId:Symbol("builtin_globalInvocationId"),workgroupId:Symbol("builtin_workgroupId"),numWorkgroups:Symbol("builtin_numWorkgroups")},U={[u.vertexIndex]:{name:"vertex_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("vertex_index")},[u.instanceIndex]:{name:"instance_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("instance_index")},[u.position]:{name:"position",stage:"vertex",direction:"output",type:b,identifier:new l().$name("position")},[u.clipDistances]:{name:"clip_distances",stage:"vertex",direction:"output",type:new o({schema:P.arrayOf(c,8),byteAlignment:16,code:"array<u32, 8>"}),identifier:new l().$name("clip_distances")},[u.frontFacing]:{name:"front_facing",stage:"fragment",direction:"input",type:T,identifier:new l().$name("front_facing")},[u.fragDepth]:{name:"frag_depth",stage:"fragment",direction:"output",type:T,identifier:new l().$name("frag_depth")},[u.sampleIndex]:{name:"sample_index",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_index")},[u.sampleMask]:{name:"sample_mask",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_mask")},[u.fragment]:{name:"fragment",stage:"fragment",direction:"input",type:b,identifier:new l().$name("fragment")},[u.localInvocationId]:{name:"local_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("local_invocation_id")},[u.localInvocationIndex]:{name:"local_invocation_index",stage:"compute",direction:"input",type:c,identifier:new l().$name("local_invocation_index")},[u.globalInvocationId]:{name:"global_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("global_invocation_id")},[u.workgroupId]:{name:"workgroup_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("workgroup_id")},[u.numWorkgroups]:{name:"num_workgroups",stage:"compute",direction:"input",type:g,identifier:new l().$name("num_workgroups")}};function V(t){let n=U[t];if(!n)throw new Error("Symbol is not a member of builtin");return n}function Ee(t){return Object.getOwnPropertySymbols(t).map(e=>{let r=U[e];if(!r)throw new Error("Symbol is not a member of builtin");let i=t[e];if(!i)throw new Error("Name is not provided");return{name:i,builtin:r}})}function y(t,...n){let e=t.flatMap((r,i)=>{let p=n[i];return p===void 0?[r]:Array.isArray(p)?[r,...p]:[r,p]});return new W(e)}var W=class{constructor(n){this.segments=n;s(this,"_label")}get label(){return this._label}$name(n){return this._label=n,this}resolve(n){let e="";for(let r of this.segments)if(typeof r=="function"){let i=r(p=>n.unwrap(p));e+=n.resolve(i)}else if(h(r))e+=n.resolve(r);else if(typeof r=="symbol"){let i=V(r);n.addBuiltin(i),e+=n.resolve(i.identifier)}else e+=String(r);return e}with(n,e){return new _(this,[n,e])}toString(){var n;return`code:${(n=this._label)!=null?n:"<unnamed>"}`}},_=class t{constructor(n,e){this._innerFn=n;this._slotValuePair=e}get label(){return this._innerFn.label}with(n,e){return new t(this,[n,e])}resolve(n){return n.resolve(this._innerFn,[this._slotValuePair])}toString(){var r,i;let[n,e]=this._slotValuePair;return`code:${(r=this.label)!=null?r:"<unnamed>"}[${(i=n.label)!=null?i:"<unnamed>"}=${e}]`}};var S=class extends L{constructor(e,r){super();this._elementType=e;this.capacity=r;s(this,"_label");s(this,"byteAlignment");s(this,"size");this.byteAlignment=Math.max(4,this._elementType.byteAlignment),this.size=this.measure(O).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){if(r.length>this.capacity)throw new N(`Tried to write too many values, ${r.length} > ${this.capacity}`);m(e,this.byteAlignment),c.write(e,r.length),m(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let p of r)this._elementType.write(e,p);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];m(e,this.byteAlignment);let i=c.read(e);m(e,this._elementType.byteAlignment);let p=e.currentByteOffset;for(let I=0;I<i;++I)r.push(this._elementType.read(e));return e.seekTo(p+this.capacity*this._elementType.size),r}measure(e,r=new G){return m(r,this.byteAlignment),c.measure(O,r),m(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
4
+ struct ${r} {
5
+ count: u32,
6
+ values: array<${this._elementType}, ${this.capacity}>,
7
+ }`),e.resolve(r)}},Je=(t,n)=>new S(t,n);import{MaxValue as q,Measurer as H,Schema as J,object as K}from"typed-binary";var rt=t=>new v(t),v=class extends J{constructor(e){super();this._properties=e;s(this,"_label");s(this,"_innerSchema");s(this,"byteAlignment");s(this,"size");this._innerSchema=K(e),this.byteAlignment=Object.values(e).map(r=>r.byteAlignment).reduce((r,i)=>r>i?r:i),this.size=this.measure(q).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new H){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
8
+ struct ${r} {
9
+ ${Object.entries(this._properties).map(([i,p])=>y`${i}: ${p},\n`)}
10
+ }
11
+ `),e.resolve(r)}};import*as $ from"typed-binary";var ot=(t,n)=>new o({schema:$.arrayOf(t,n),byteAlignment:t.byteAlignment,code:y`array<${t}, ${n}>`});function Q(t){return{scope:"function",pointsTo:t}}import{Measurer as X,Schema as Y}from"typed-binary";function Z(t){return new w(t)}var w=class extends Y{constructor(e){super();this.innerData=e;s(this,"size");s(this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new d}write(e,r){this.innerData.write(e,r)}read(e){return this.innerData.read(e)}measure(e,r=new X){return this.innerData.measure(e,r)}resolve(e){return`atomic<${e.resolve(this.innerData)}>`}};export{ee as a,te as b,re as c,s as d,R as e,A as f,d as g,h,Se as i,ve as j,we as k,Ie as l,De as m,Be as n,Re as o,Ae as p,o as q,ce as r,c as s,de as t,T as u,ye as v,ge as w,fe as x,g as y,xe as z,Te as A,be as B,he as C,b as D,We as E,l as F,Je as G,rt as H,ot as I,Q as J,Z as K,u as L,V as M,Ee as N,y as O};
12
+ //# sourceMappingURL=chunk-K2GYQABQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/data/std140.ts","../src/errors.ts","../src/data/alignIO.ts","../src/data/numeric.ts","../src/data/dynamicArray.ts","../src/types.ts","../src/wgslBuiltin.ts","../src/wgslIdentifier.ts","../src/wgslCode.ts","../src/data/struct.ts","../src/data/array.ts","../src/data/pointer.ts","../src/data/atomic.ts"],"sourcesContent":["/*\n * Typed-binary types that adhere to the `std140` layout rules.\n */\n\nimport {\n type AnySchema,\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, Wgsl, WgslData } from '../types';\nimport alignIO from './alignIO';\n\nexport class SimpleWgslData<TSchema extends AnySchema>\n extends Schema<Unwrap<TSchema>>\n implements WgslData<Unwrap<TSchema>>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n public readonly expressionCode: Wgsl;\n\n private readonly _innerSchema: TSchema;\n\n /**\n * byteAlignment has to be a power of 2\n */\n constructor({\n schema,\n byteAlignment,\n code,\n }: {\n schema: TSchema;\n byteAlignment: number;\n code: Wgsl;\n }) {\n super();\n\n this._innerSchema = schema;\n this.byteAlignment = byteAlignment;\n this.expressionCode = code;\n this.size = this.measure(MaxValue).size;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n alignIO(output, this.byteAlignment);\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n alignIO(input, this.byteAlignment);\n return this._innerSchema.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n\n this._innerSchema.measure(value, measurer);\n\n return measurer;\n }\n\n getUnderlyingTypeString(): string {\n if (typeof this.expressionCode === 'string') {\n return this.expressionCode;\n }\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingTypeString();\n }\n throw new Error('Unexpected type used as vertex buffer element');\n }\n\n getUnderlyingType(): SimpleWgslData<AnySchema> {\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingType();\n }\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this.expressionCode);\n }\n}\n","import type { WgslResolvable, WgslSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: WgslResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: WgslResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n","import type { IMeasurer, ISerialInput, ISerialOutput } from 'typed-binary';\n\n/**\n * @param io the IO to align\n * @param baseAlignment must be power of 2\n */\nfunction alignIO(\n io: ISerialInput | ISerialOutput | IMeasurer,\n baseAlignment: number,\n) {\n const currentPos = 'size' in io ? io.size : io.currentByteOffset;\n\n const bitMask = baseAlignment - 1;\n const offset = currentPos & bitMask;\n\n if ('skipBytes' in io) {\n io.skipBytes((baseAlignment - offset) & bitMask);\n } else {\n io.add((baseAlignment - offset) & bitMask);\n }\n}\n\nexport default alignIO;\n","import * as TB from 'typed-binary';\nimport type { WgslData } from '../types';\nimport { SimpleWgslData } from './std140';\n\nexport type Bool = WgslData<boolean>;\nexport const bool: Bool = new SimpleWgslData({\n schema: TB.bool,\n byteAlignment: 4,\n code: 'bool',\n});\nexport type U32 = WgslData<number>;\nexport const u32: U32 = new SimpleWgslData({\n schema: TB.u32,\n byteAlignment: 4,\n code: 'u32',\n});\nexport type I32 = WgslData<number>;\nexport const i32: I32 = new SimpleWgslData({\n schema: TB.i32,\n byteAlignment: 4,\n code: 'i32',\n});\nexport type F32 = WgslData<number>;\nexport const f32: F32 = new SimpleWgslData({\n schema: TB.f32,\n byteAlignment: 4,\n code: 'f32',\n});\n\nexport type Vec2u = WgslData<[number, number]>;\nexport const vec2u: Vec2u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32]),\n byteAlignment: 8,\n code: 'vec2u',\n});\n\nexport type Vec2i = WgslData<[number, number]>;\nexport const vec2i: Vec2i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32]),\n byteAlignment: 8,\n code: 'vec2i',\n});\nexport type Vec2f = WgslData<[number, number]>;\nexport const vec2f: Vec2f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32]),\n byteAlignment: 8,\n code: 'vec2f',\n});\nexport type Vec3u = WgslData<[number, number, number]>;\nexport const vec3u: Vec3u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec3u',\n});\nexport type Vec3i = WgslData<[number, number, number]>;\nexport const vec3i: Vec3i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec3i',\n});\nexport type Vec3f = WgslData<[number, number, number]>;\nexport const vec3f: Vec3f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec3f',\n});\nexport type Vec4u = WgslData<[number, number, number, number]>;\nexport const vec4u: Vec4u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec4u',\n});\nexport type Vec4i = WgslData<[number, number, number, number]>;\nexport const vec4i: Vec4i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec4i',\n});\nexport type Vec4f = WgslData<[number, number, number, number]>;\nexport const vec4f: Vec4f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec4f',\n});\n\n/**\n * Array of column vectors\n */\nexport type Mat4f = WgslData<number[]>;\nexport const mat4f: Mat4f = new SimpleWgslData({\n schema: TB.arrayOf(TB.f32, 16),\n byteAlignment: 16,\n code: 'mat4x4f',\n});\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n ValidationError,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\nimport { u32 } from './numeric';\n\nclass DynamicArrayDataType<TElement extends WgslData<unknown>>\n extends Schema<Unwrap<TElement>[]>\n implements WgslData<Unwrap<TElement>[]>\n{\n private _label: string | undefined;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(\n private readonly _elementType: TElement,\n public readonly capacity: number,\n ) {\n super();\n\n this.byteAlignment = Math.max(\n 4 /* u32 base alignment */,\n this._elementType.byteAlignment,\n );\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, values: ParseUnwrapped<TElement>[]): void {\n if (values.length > this.capacity) {\n throw new ValidationError(\n `Tried to write too many values, ${values.length} > ${this.capacity}`,\n );\n }\n\n alignIO(output, this.byteAlignment); // aligning to the start\n u32.write(output, values.length);\n alignIO(output, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = output.currentByteOffset;\n for (const value of values) {\n this._elementType.write(output, value);\n }\n output.seekTo(startOffset + this.capacity * this._elementType.size);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TElement>[] {\n const array: ParseUnwrapped<TElement>[] = [];\n\n alignIO(input, this.byteAlignment); // aligning to the start\n const len = u32.read(input);\n alignIO(input, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = input.currentByteOffset;\n for (let i = 0; i < len; ++i) {\n array.push(this._elementType.read(input) as ParseUnwrapped<TElement>);\n }\n input.seekTo(startOffset + this.capacity * this._elementType.size);\n\n return array;\n }\n\n measure(\n _values: ParseUnwrapped<TElement>[] | typeof MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment); // aligning to the start\n\n // Length encoding\n u32.measure(MaxValue, measurer);\n\n // Aligning to the start of the array\n alignIO(measurer, this._elementType.byteAlignment);\n\n // Values encoding\n measurer.add(this._elementType.size * this.capacity);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n count: u32,\n values: array<${this._elementType}, ${this.capacity}>,\n }`);\n\n return ctx.resolve(identifier);\n }\n}\n\nexport const dynamicArrayOf = <TSchema extends AnyWgslData>(\n elementType: TSchema,\n capacity: number,\n) => new DynamicArrayDataType(elementType, capacity);\n\nexport default DynamicArrayDataType;\n","import type { ISchema, Parsed } from 'typed-binary';\nimport type { F32, I32, U32, Vec4f, Vec4i, Vec4u } from './data';\nimport type { Builtin } from './wgslBuiltin';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | number | WgslResolvable | symbol | boolean;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n addRenderResource(\n resource: WgslRenderResource,\n identifier: WgslIdentifier,\n ): void;\n addBuiltin(builtin: Builtin): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n get label(): string | undefined;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type WgslSamplerType = 'sampler' | 'sampler_comparison';\nexport type WgslTypedTextureType =\n | 'texture_1d'\n | 'texture_2d'\n | 'texture_2d_array'\n | 'texture_3d'\n | 'texture_cube'\n | 'texture_cube_array'\n | 'texture_multisampled_2d';\nexport type WgslDepthTextureType =\n | 'texture_depth_2d'\n | 'texture_depth_2d_array'\n | 'texture_depth_cube'\n | 'texture_depth_cube_array'\n | 'texture_depth_multisampled_2d';\nexport type WgslStorageTextureType =\n | 'texture_storage_1d'\n | 'texture_storage_2d'\n | 'texture_storage_2d_array'\n | 'texture_storage_3d';\nexport type WgslExternalTextureType = 'texture_external';\n\nexport type WgslRenderResourceType =\n | WgslSamplerType\n | WgslTypedTextureType\n | WgslDepthTextureType\n | WgslStorageTextureType\n | WgslExternalTextureType;\n\nexport interface WgslRenderResource extends WgslResolvable {\n readonly type: WgslRenderResourceType;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';\nexport type TextureUsage = 'sampled' | 'storage';\nexport type StorageTextureAccess = 'read' | 'write' | 'read_write';\n\nexport type StorageTextureParams = {\n type: WgslStorageTextureType;\n access: StorageTextureAccess;\n descriptor?: GPUTextureViewDescriptor;\n};\nexport type SampledTextureParams = {\n type: WgslTypedTextureType;\n dataType: AnyWgslPrimitive;\n descriptor?: GPUTextureViewDescriptor;\n};\n\nexport function isSamplerType(\n type: WgslRenderResourceType,\n): type is WgslSamplerType {\n return type === 'sampler' || type === 'sampler_comparison';\n}\n\nexport function isTypedTextureType(\n type: WgslRenderResourceType,\n): type is WgslTypedTextureType {\n return [\n 'texture_1d',\n 'texture_2d',\n 'texture_2d_array',\n 'texture_3d',\n 'texture_cube',\n 'texture_cube_array',\n 'texture_multisampled_2d',\n ].includes(type);\n}\n\nexport function isDepthTextureType(\n type: WgslRenderResourceType,\n): type is WgslDepthTextureType {\n return [\n 'texture_depth_2d',\n 'texture_depth_2d_array',\n 'texture_depth_cube',\n 'texture_depth_cube_array',\n 'texture_depth_multisampled_2d',\n ].includes(type);\n}\n\nexport function isStorageTextureType(\n type: WgslRenderResourceType,\n): type is WgslStorageTextureType {\n return [\n 'texture_storage_1d',\n 'texture_storage_2d',\n 'texture_storage_2d_array',\n 'texture_storage_3d',\n ].includes(type);\n}\n\nexport function isExternalTextureType(\n type: WgslRenderResourceType,\n): type is WgslExternalTextureType {\n return type === 'texture_external';\n}\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\nexport type AnyWgslPrimitive = U32 | I32 | F32;\nexport type AnyWgslTexelFormat = Vec4u | Vec4i | Vec4f;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import * as TB from 'typed-binary';\nimport type { F32, U32, Vec3u, Vec4f } from './data';\nimport { SimpleWgslData, f32, u32, vec3u, vec4f } from './data';\nimport type { WgslData } from './types';\nimport { WgslIdentifier } from './wgslIdentifier';\n\nexport type BuiltInPossibleTypes =\n | U32\n | F32\n | Vec3u\n | Vec4f\n | WgslData<TB.Unwrap<U32>[]>;\n\nexport const builtin = {\n vertexIndex: Symbol('builtin_vertexIndex'),\n instanceIndex: Symbol('builtin_instanceIndex'),\n position: Symbol('builtin_position'),\n clipDistances: Symbol('builtin_clipDistances'),\n frontFacing: Symbol('builtin_frontFacing'),\n fragDepth: Symbol('builtin_fragDepth'),\n sampleIndex: Symbol('builtin_sampleIndex'),\n sampleMask: Symbol('builtin_sampleMask'),\n fragment: Symbol('builtin_fragment'),\n localInvocationId: Symbol('builtin_localInvocationId'),\n localInvocationIndex: Symbol('builtin_localInvocationIndex'),\n globalInvocationId: Symbol('builtin_globalInvocationId'),\n workgroupId: Symbol('builtin_workgroupId'),\n numWorkgroups: Symbol('builtin_numWorkgroups'),\n} as const;\n\nexport interface Builtin {\n name: string;\n stage: 'vertex' | 'fragment' | 'compute';\n direction: 'input' | 'output';\n type: BuiltInPossibleTypes;\n identifier: WgslIdentifier;\n}\n\nconst builtinSymbolToObj: Record<symbol, Builtin> = {\n [builtin.vertexIndex]: {\n name: 'vertex_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('vertex_index'),\n },\n [builtin.instanceIndex]: {\n name: 'instance_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('instance_index'),\n },\n [builtin.position]: {\n name: 'position',\n stage: 'vertex',\n direction: 'output',\n type: vec4f,\n identifier: new WgslIdentifier().$name('position'),\n },\n [builtin.clipDistances]: {\n name: 'clip_distances',\n stage: 'vertex',\n direction: 'output',\n type: new SimpleWgslData({\n schema: TB.arrayOf(u32, 8),\n byteAlignment: 16,\n code: 'array<u32, 8>',\n }),\n identifier: new WgslIdentifier().$name('clip_distances'),\n },\n [builtin.frontFacing]: {\n name: 'front_facing',\n stage: 'fragment',\n direction: 'input',\n type: f32,\n identifier: new WgslIdentifier().$name('front_facing'),\n },\n [builtin.fragDepth]: {\n name: 'frag_depth',\n stage: 'fragment',\n direction: 'output',\n type: f32,\n identifier: new WgslIdentifier().$name('frag_depth'),\n },\n [builtin.sampleIndex]: {\n name: 'sample_index',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_index'),\n },\n [builtin.sampleMask]: {\n name: 'sample_mask',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_mask'),\n },\n [builtin.fragment]: {\n name: 'fragment',\n stage: 'fragment',\n direction: 'input',\n type: vec4f,\n identifier: new WgslIdentifier().$name('fragment'),\n },\n [builtin.localInvocationId]: {\n name: 'local_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('local_invocation_id'),\n },\n [builtin.localInvocationIndex]: {\n name: 'local_invocation_index',\n stage: 'compute',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('local_invocation_index'),\n },\n [builtin.globalInvocationId]: {\n name: 'global_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('global_invocation_id'),\n },\n [builtin.workgroupId]: {\n name: 'workgroup_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('workgroup_id'),\n },\n [builtin.numWorkgroups]: {\n name: 'num_workgroups',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('num_workgroups'),\n },\n};\n\nexport function getBuiltinInfo(s: symbol): Builtin {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n return builtin;\n}\n\nexport function getUsedBuiltinsNamed(\n o: Record<symbol, string>,\n): { name: string; builtin: Builtin }[] {\n const res = Object.getOwnPropertySymbols(o).map((s) => {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n const name = o[s];\n if (!name) {\n throw new Error('Name is not provided');\n }\n return { name: name, builtin: builtin };\n });\n return res;\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n","import {\n type Eventual,\n type InlineResolve,\n type ResolutionCtx,\n type SlotValuePair,\n type Wgsl,\n type WgslResolvable,\n type WgslSlot,\n isResolvable,\n} from './types';\nimport { getBuiltinInfo } from './wgslBuiltin';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n\n with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;\n}\n\nexport type BoundWgslCode = Omit<WgslCode, '$name'>;\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else if (typeof s === 'symbol') {\n const builtin = getBuiltinInfo(s);\n ctx.addBuiltin(builtin);\n code += ctx.resolve(builtin.identifier);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n\nclass BoundWgslCodeImpl<T> implements BoundWgslCode {\n constructor(\n private readonly _innerFn: BoundWgslCode,\n private readonly _slotValuePair: SlotValuePair<T>,\n ) {}\n\n get label() {\n return this._innerFn.label;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._innerFn, [this._slotValuePair]);\n }\n\n toString(): string {\n const [slot, value] = this._slotValuePair;\n return `code:${this.label ?? '<unnamed>'}[${slot.label ?? '<unnamed>'}=${value}]`;\n }\n}\n","import {\n type IMeasurer,\n type ISchema,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type Parsed,\n Schema,\n type UnwrapRecord,\n object,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslStruct<TProps extends Record<string, AnyWgslData>>\n extends ISchema<UnwrapRecord<TProps>>,\n WgslData<UnwrapRecord<TProps>> {\n $name(label: string): this;\n}\n\nexport const struct = <TProps extends Record<string, AnyWgslData>>(\n properties: TProps,\n): WgslStruct<TProps> => new WgslStructImpl(properties);\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslStructImpl<TProps extends Record<string, AnyWgslData>>\n extends Schema<UnwrapRecord<TProps>>\n implements WgslData<UnwrapRecord<TProps>>\n{\n private _label: string | undefined;\n private _innerSchema: ISchema<UnwrapRecord<TProps>>;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(private readonly _properties: TProps) {\n super();\n\n this._innerSchema = object(_properties);\n\n this.byteAlignment = Object.values(_properties)\n .map((prop) => prop.byteAlignment)\n .reduce((a, b) => (a > b ? a : b));\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: Parsed<UnwrapRecord<TProps>>): void {\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): Parsed<UnwrapRecord<TProps>> {\n return this._innerSchema.read(input);\n }\n\n measure(\n value: MaxValue | Parsed<UnwrapRecord<TProps>>,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n this._innerSchema.measure(value, measurer);\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n ${Object.entries(this._properties).map(([key, field]) => code`${key}: ${field},\\n`)}\n }\n `);\n\n return ctx.resolve(identifier);\n }\n}\n","import * as TB from 'typed-binary';\nimport type { AnyWgslData, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { SimpleWgslData } from './std140';\n\nexport type WgslArray<TElement extends AnyWgslData> = WgslData<\n TB.Unwrap<TElement>[]\n>;\n\nexport const arrayOf = <TElement extends AnyWgslData>(\n elementType: TElement,\n size: number,\n): WgslArray<TElement> =>\n new SimpleWgslData({\n schema: TB.arrayOf(elementType, size),\n byteAlignment: elementType.byteAlignment,\n code: code`array<${elementType}, ${size}>`,\n });\n","import type { AnyWgslData, WgslPointer } from '../types';\n\nexport function ptr<TDataType extends AnyWgslData>(\n pointsTo: TDataType,\n): WgslPointer<'function', TDataType> {\n return {\n scope: 'function',\n pointsTo,\n };\n}\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n type MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, WgslData } from '../types';\nimport type { I32, U32 } from './numeric';\n\nexport function atomic<TSchema extends U32 | I32>(\n data: TSchema,\n): Atomic<TSchema> {\n return new AtomicImpl(data);\n}\n\nexport interface Atomic<TSchema extends U32 | I32>\n extends WgslData<Unwrap<TSchema>> {}\n\nclass AtomicImpl<TSchema extends U32 | I32>\n extends Schema<Unwrap<TSchema>>\n implements Atomic<TSchema>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n constructor(private readonly innerData: TSchema) {\n super();\n this.size = this.innerData.size;\n this.byteAlignment = this.innerData.byteAlignment;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n this.innerData.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n return this.innerData.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n return this.innerData.measure(value, measurer);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return `atomic<${ctx.resolve(this.innerData)}>`;\n }\n}\n"],"mappings":"soBAIA,OAKE,YAAAA,EACA,YAAAC,EAEA,UAAAC,MAEK,eCLA,IAAMC,EAAN,MAAMC,UAAwB,KAAM,CACzC,YACkBC,EACAC,EAChB,CACA,IAAIC,EAAUD,EAAM,IAAKE,GAAa,KAAKA,CAAQ,EAAE,EAGjDD,EAAQ,OAAS,KACnBA,EAAU,CAAC,GAAGA,EAAQ,MAAM,EAAG,EAAE,EAAG,MAAO,GAAGA,EAAQ,MAAM,GAAG,CAAC,GAGlE,MAAM;AAAA,EAA8CA,EAAQ,KAAK;AAAA,CAAI,CAAC,EAAE,EAVxD,WAAAF,EACA,WAAAC,EAYhB,OAAO,eAAe,KAAMF,EAAgB,SAAS,CACvD,CAEA,cAAcI,EAA2C,CACvD,IAAMC,EAAW,CAACD,EAAU,GAAG,KAAK,KAAK,EAEzC,OAAO,IAAIJ,EAAgB,KAAK,MAAOK,CAAQ,CACjD,CACF,EAKaC,EAAN,MAAMC,UAA8B,KAAM,CAC/C,YAA4BC,EAAyB,CACnD,MAAM,sBAAsBA,CAAI,GAAG,EADT,UAAAA,EAI1B,OAAO,eAAe,KAAMD,EAAsB,SAAS,CAC7D,CACF,EAKaE,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF,EClDA,SAASC,EACPC,EACAC,EACA,CACA,IAAMC,EAAa,SAAUF,EAAKA,EAAG,KAAOA,EAAG,kBAEzCG,EAAUF,EAAgB,EAC1BG,EAASF,EAAaC,EAExB,cAAeH,EACjBA,EAAG,UAAWC,EAAgBG,EAAUD,CAAO,EAE/CH,EAAG,IAAKC,EAAgBG,EAAUD,CAAO,CAE7C,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AgB,iBAId,KAAK,KAAO,KAAK,UAAU,KAC3B,KAAK,cAAgB,KAAK,UAAU,aACtC,CAEA,mBAA0B,CACxB,MAAM,IAAIC,CACZ,CAEA,MAAMC,EAAuBC,EAAsC,CACjE,KAAK,UAAU,MAAMD,EAAQC,CAAK,CACpC,CAEA,KAAKC,EAA8C,CACjD,OAAO,KAAK,UAAU,KAAKA,CAAK,CAClC,CAEA,QACED,EACAE,EAAsB,IAAIC,EACf,CACX,OAAO,KAAK,UAAU,QAAQH,EAAOE,CAAQ,CAC/C,CAEA,QAAQE,EAA4B,CAClC,MAAO,UAAUA,EAAI,QAAQ,KAAK,SAAS,CAAC,GAC9C,CACF","names":["MaxValue","Measurer","Schema","ResolutionError","_ResolutionError","cause","trace","entries","ancestor","newTrace","MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","SimpleWgslData","Schema","schema","byteAlignment","code","__publicField","MaxValue","RecursiveDataTypeError","output","value","alignIO_default","input","measurer","Measurer","ctx","TB","bool","SimpleWgslData","u32","i32","f32","vec2u","vec2i","vec2f","vec3u","vec3i","vec3f","vec4u","vec4i","vec4f","mat4f","MaxValue","Measurer","Schema","ValidationError","isResolvable","value","isWgsl","isSlot","isSamplerType","type","isTypedTextureType","isDepthTextureType","isStorageTextureType","isExternalTextureType","isPointer","TB","WgslIdentifier","__publicField","label","ctx","_a","builtin","builtinSymbolToObj","u32","WgslIdentifier","vec4f","SimpleWgslData","f32","vec3u","getBuiltinInfo","s","getUsedBuiltinsNamed","o","name","code","strings","params","segments","string","idx","param","WgslCodeImpl","__publicField","label","ctx","s","result","eventual","isResolvable","builtin","getBuiltinInfo","slot","value","BoundWgslCodeImpl","_a","_BoundWgslCodeImpl","_innerFn","_slotValuePair","_b","DynamicArrayDataType","Schema","_elementType","capacity","__publicField","MaxValue","label","RecursiveDataTypeError","output","values","ValidationError","alignIO_default","u32","startOffset","value","input","array","len","i","_values","measurer","Measurer","ctx","identifier","WgslIdentifier","code","dynamicArrayOf","elementType","MaxValue","Measurer","Schema","object","struct","properties","WgslStructImpl","Schema","_properties","__publicField","object","prop","a","b","MaxValue","label","RecursiveDataTypeError","output","value","input","measurer","Measurer","alignIO_default","ctx","identifier","WgslIdentifier","code","key","field","TB","arrayOf","elementType","size","SimpleWgslData","code","ptr","pointsTo","Measurer","Schema","atomic","data","AtomicImpl","Schema","innerData","__publicField","RecursiveDataTypeError","output","value","input","measurer","Measurer","ctx"]}
package/data/index.cjs CHANGED
@@ -1,10 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _chunkG3WAZR24cjs = require('../chunk-G3WAZR24.cjs');var _chunkJYXJ5NFXcjs = require('../chunk-JYXJ5NFX.cjs');var _typedbinary = require('typed-binary'); var t = _interopRequireWildcard(_typedbinary); var g = _interopRequireWildcard(_typedbinary);function x(n,o){let e="size"in n?n.size:n.currentByteOffset,r=o-1,i=e&r;"skipBytes"in n?n.skipBytes(o-i&r):n.add(o-i&r)}var p=x;var a=class extends _typedbinary.Schema{constructor({schema:e,byteAlignment:r,code:i}){super();_chunkJYXJ5NFXcjs.d.call(void 0, this,"size");_chunkJYXJ5NFXcjs.d.call(void 0, this,"byteAlignment");_chunkJYXJ5NFXcjs.d.call(void 0, this,"_innerSchema");_chunkJYXJ5NFXcjs.d.call(void 0, this,"_expressionCode");this._innerSchema=e,this.byteAlignment=r,this._expressionCode=i,this.size=this.measure(_typedbinary.MaxValue).size}resolveReferences(){throw new _chunkG3WAZR24cjs.c}write(e,r){p(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return p(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return p(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){return e.resolve(this._expressionCode)}};var F=new a({schema:t.bool,byteAlignment:4,code:"bool"}),y= exports.u32 =new a({schema:t.u32,byteAlignment:4,code:"u32"}),q= exports.i32 =new a({schema:t.i32,byteAlignment:4,code:"i32"}),G= exports.f32 =new a({schema:t.f32,byteAlignment:4,code:"f32"}),H= exports.vec2u =new a({schema:t.tupleOf([t.u32,t.u32]),byteAlignment:8,code:"vec2u"}),J= exports.vec2i =new a({schema:t.tupleOf([t.i32,t.i32]),byteAlignment:8,code:"vec2i"}),K= exports.vec2f =new a({schema:t.tupleOf([t.f32,t.f32]),byteAlignment:8,code:"vec2f"}),L= exports.vec3u =new a({schema:t.tupleOf([t.u32,t.u32,t.u32]),byteAlignment:16,code:"vec3u"}),N= exports.vec3i =new a({schema:t.tupleOf([t.i32,t.i32,t.i32]),byteAlignment:16,code:"vec3i"}),Q= exports.vec3f =new a({schema:t.tupleOf([t.f32,t.f32,t.f32]),byteAlignment:16,code:"vec3f"}),X= exports.vec4u =new a({schema:t.tupleOf([t.u32,t.u32,t.u32,t.u32]),byteAlignment:16,code:"vec4u"}),Y= exports.vec4i =new a({schema:t.tupleOf([t.i32,t.i32,t.i32,t.i32]),byteAlignment:16,code:"vec4i"}),Z= exports.vec4f =new a({schema:t.tupleOf([t.f32,t.f32,t.f32,t.f32]),byteAlignment:16,code:"vec4f"}),ee= exports.mat4f =new a({schema:t.arrayOf(t.f32,16),byteAlignment:16,code:"mat4x4f"});var d=class extends _typedbinary.Schema{constructor(e,r){super();this._elementType=e;this.capacity=r;_chunkJYXJ5NFXcjs.d.call(void 0, this,"_label");_chunkJYXJ5NFXcjs.d.call(void 0, this,"byteAlignment");_chunkJYXJ5NFXcjs.d.call(void 0, this,"size");this.byteAlignment=Math.max(4,this._elementType.byteAlignment),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new _chunkG3WAZR24cjs.c}write(e,r){if(r.length>this.capacity)throw new (0, _typedbinary.ValidationError)(`Tried to write too many values, ${r.length} > ${this.capacity}`);p(e,this.byteAlignment),y.write(e,r.length),p(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let c of r)this._elementType.write(e,c);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];p(e,this.byteAlignment);let i=y.read(e);p(e,this._elementType.byteAlignment);let c=e.currentByteOffset;for(let f=0;f<i;++f)r.push(this._elementType.read(e));return e.seekTo(c+this.capacity*this._elementType.size),r}measure(e,r=new _typedbinary.Measurer){return p(r,this.byteAlignment),y.measure(_typedbinary.MaxValue,r),p(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new (0, _chunkJYXJ5NFXcjs.j)().$name(this._label);return e.addDeclaration(_chunkJYXJ5NFXcjs.i`
2
- struct ${r} {
3
- count: u32,
4
- values: array<${this._elementType}, ${this.capacity}>,
5
- }`),e.resolve(r)}},pe= exports.dynamicArrayOf =(n,o)=>new d(n,o);var he=n=>new h(n),h=class extends _typedbinary.Schema{constructor(e){super();this._properties=e;_chunkJYXJ5NFXcjs.d.call(void 0, this,"_label");_chunkJYXJ5NFXcjs.d.call(void 0, this,"_innerSchema");_chunkJYXJ5NFXcjs.d.call(void 0, this,"byteAlignment");_chunkJYXJ5NFXcjs.d.call(void 0, this,"size");this._innerSchema=_typedbinary.object.call(void 0, e),this.byteAlignment=Object.values(e).map(r=>r.byteAlignment).reduce((r,i)=>r>i?r:i),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new _chunkG3WAZR24cjs.c}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return this._innerSchema.measure(e,r),r}resolve(e){let r=new (0, _chunkJYXJ5NFXcjs.j)().$name(this._label);return e.addDeclaration(_chunkJYXJ5NFXcjs.i`
6
- struct ${r} {
7
- ${Object.entries(this._properties).map(([i,c])=>_chunkJYXJ5NFXcjs.i`${i}: ${c},\n`)}
8
- }
9
- `),e.resolve(r)}};var xe=(n,o)=>new a({schema:g.arrayOf(n,o),byteAlignment:n.byteAlignment,code:_chunkJYXJ5NFXcjs.i`array<${n}, ${o}>`});function O(n){return{scope:"function",pointsTo:n}}function R(n){return new T(n)}var T=class extends _typedbinary.Schema{constructor(e){super();this.innerData=e;_chunkJYXJ5NFXcjs.d.call(void 0, this,"size");_chunkJYXJ5NFXcjs.d.call(void 0, this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new _chunkG3WAZR24cjs.c}write(e,r){this.innerData.write(e,r)}read(e){return this.innerData.read(e)}measure(e,r=new _typedbinary.Measurer){return this.innerData.measure(e,r)}resolve(e){return`atomic<${e.resolve(this.innerData)}>`}};exports.SimpleWgslData = a; exports.arrayOf = xe; exports.atomic = R; exports.bool = F; exports.dynamicArrayOf = pe; exports.f32 = G; exports.i32 = q; exports.mat4f = ee; exports.ptr = O; exports.struct = he; exports.u32 = y; exports.vec2f = K; exports.vec2i = J; exports.vec2u = H; exports.vec3f = Q; exports.vec3i = N; exports.vec3u = L; exports.vec4f = Z; exports.vec4i = Y; exports.vec4u = X;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7HTWRNOHcjs = require('../chunk-7HTWRNOH.cjs');exports.SimpleWgslData = _chunk7HTWRNOHcjs.q; exports.arrayOf = _chunk7HTWRNOHcjs.I; exports.atomic = _chunk7HTWRNOHcjs.K; exports.bool = _chunk7HTWRNOHcjs.r; exports.dynamicArrayOf = _chunk7HTWRNOHcjs.G; exports.f32 = _chunk7HTWRNOHcjs.u; exports.i32 = _chunk7HTWRNOHcjs.t; exports.mat4f = _chunk7HTWRNOHcjs.E; exports.ptr = _chunk7HTWRNOHcjs.J; exports.struct = _chunk7HTWRNOHcjs.H; exports.u32 = _chunk7HTWRNOHcjs.s; exports.vec2f = _chunk7HTWRNOHcjs.x; exports.vec2i = _chunk7HTWRNOHcjs.w; exports.vec2u = _chunk7HTWRNOHcjs.v; exports.vec3f = _chunk7HTWRNOHcjs.A; exports.vec3i = _chunk7HTWRNOHcjs.z; exports.vec3u = _chunk7HTWRNOHcjs.y; exports.vec4f = _chunk7HTWRNOHcjs.D; exports.vec4i = _chunk7HTWRNOHcjs.C; exports.vec4u = _chunk7HTWRNOHcjs.B;
10
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data/std140.ts","../../src/data/alignIO.ts","../../src/data/numeric.ts","../../src/data/dynamicArray.ts","../../src/data/struct.ts","../../src/data/array.ts","../../src/data/pointer.ts","../../src/data/atomic.ts"],"names":["MaxValue","Measurer","Schema","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","SimpleWgslData","schema","byteAlignment","code","__publicField","RecursiveDataTypeError","output","value","input","measurer","ctx","TB","bool","u32","i32","f32","vec2u","vec2i","vec2f","vec3u","vec3i","vec3f","vec4u","vec4i","vec4f","mat4f","ValidationError","DynamicArrayDataType","_elementType","capacity","label","values","startOffset","array","len","i","_values","identifier","WgslIdentifier","dynamicArrayOf","elementType","object","struct","properties","WgslStructImpl","_properties","prop","a","b","key","field","arrayOf","size","ptr","pointsTo","atomic","data","AtomicImpl","innerData"],"mappings":"kGAIA,OAKE,YAAAA,EACA,YAAAC,EAEA,UAAAC,MAEK,eCRP,SAASC,EACPC,EACAC,EACA,CACA,IAAMC,EAAa,SAAUF,EAAKA,EAAG,KAAOA,EAAG,kBAEzCG,EAAUF,EAAgB,EAC1BG,EAASF,EAAaC,EAExB,cAAeH,EACjBA,EAAG,UAAWC,EAAgBG,EAAUD,CAAO,EAE/CH,EAAG,IAAKC,EAAgBG,EAAUD,CAAO,CAE7C,CAEA,IAAOE,EAAQN,EDHR,IAAMO,EAAN,cACGR,CAEV,CAUE,YAAY,CACV,OAAAS,EACA,cAAAC,EACA,KAAAC,CACF,EAIG,CACD,MAAM,EAlBRC,EAAA,KAAgB,QAChBA,EAAA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,GAAU,CACrBX,EACAY,IAEA,IAAIpD,EAAe,CACjB,OAAW,UAAQwC,EAAaY,CAAI,EACpC,cAAeZ,EAAY,cAC3B,KAAMrC,UAAaqC,CAAW,KAAKY,CAAI,GACzC,CAAC,ECfI,SAASC,EACdC,EACoC,CACpC,MAAO,CACL,MAAO,WACP,SAAAA,CACF,CACF,CCTA,OAKE,YAAA/D,EAEA,UAAAC,MAEK,eAKA,SAAS+D,EACdC,EACiB,CACjB,OAAO,IAAIC,EAAWD,CAAI,CAC5B,CAKA,IAAMC,EAAN,cACUjE,CAEV,CAIE,YAA6BkE,EAAoB,CAC/C,MAAM,EADqB,eAAAA,EAH7BtD,EAAA,KAAgB,QAChBA,EAAA,KAAgB,iBAId,KAAK,KAAO,KAAK,UAAU,KAC3B,KAAK,cAAgB,KAAK,UAAU,aACtC,CAEA,mBAA0B,CACxB,MAAM,IAAIC,CACZ,CAEA,MAAMC,EAAuBC,EAAsC,CACjE,KAAK,UAAU,MAAMD,EAAQC,CAAK,CACpC,CAEA,KAAKC,EAA8C,CACjD,OAAO,KAAK,UAAU,KAAKA,CAAK,CAClC,CAEA,QACED,EACAE,EAAsB,IAAIlB,EACf,CACX,OAAO,KAAK,UAAU,QAAQgB,EAAOE,CAAQ,CAC/C,CAEA,QAAQC,EAA4B,CAClC,MAAO,UAAUA,EAAI,QAAQ,KAAK,SAAS,CAAC,GAC9C,CACF","sourcesContent":["/*\n * Typed-binary types that adhere to the `std140` layout rules.\n */\n\nimport {\n type AnySchema,\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, Wgsl, WgslData } from '../types';\nimport alignIO from './alignIO';\n\nexport class SimpleWgslData<TSchema extends AnySchema>\n extends Schema<Unwrap<TSchema>>\n implements WgslData<Unwrap<TSchema>>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n private readonly _innerSchema: TSchema;\n private readonly _expressionCode: Wgsl;\n\n /**\n * byteAlignment has to be a power of 2\n */\n constructor({\n schema,\n byteAlignment,\n code,\n }: {\n schema: TSchema;\n byteAlignment: number;\n code: Wgsl;\n }) {\n super();\n\n this._innerSchema = schema;\n this.byteAlignment = byteAlignment;\n this._expressionCode = code;\n this.size = this.measure(MaxValue).size;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n alignIO(output, this.byteAlignment);\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n alignIO(input, this.byteAlignment);\n return this._innerSchema.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n\n this._innerSchema.measure(value, measurer);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._expressionCode);\n }\n}\n","import type { IMeasurer, ISerialInput, ISerialOutput } from 'typed-binary';\n\n/**\n * @param io the IO to align\n * @param baseAlignment must be power of 2\n */\nfunction alignIO(\n io: ISerialInput | ISerialOutput | IMeasurer,\n baseAlignment: number,\n) {\n const currentPos = 'size' in io ? io.size : io.currentByteOffset;\n\n const bitMask = baseAlignment - 1;\n const offset = currentPos & bitMask;\n\n if ('skipBytes' in io) {\n io.skipBytes((baseAlignment - offset) & bitMask);\n } else {\n io.add((baseAlignment - offset) & bitMask);\n }\n}\n\nexport default alignIO;\n","import * as TB from 'typed-binary';\nimport type { WgslData } from '../types';\nimport { SimpleWgslData } from './std140';\n\nexport type Bool = WgslData<boolean>;\nexport const bool: Bool = new SimpleWgslData({\n schema: TB.bool,\n byteAlignment: 4,\n code: 'bool',\n});\nexport type U32 = WgslData<number>;\nexport const u32: U32 = new SimpleWgslData({\n schema: TB.u32,\n byteAlignment: 4,\n code: 'u32',\n});\nexport type I32 = WgslData<number>;\nexport const i32: I32 = new SimpleWgslData({\n schema: TB.i32,\n byteAlignment: 4,\n code: 'i32',\n});\nexport type F32 = WgslData<number>;\nexport const f32: F32 = new SimpleWgslData({\n schema: TB.f32,\n byteAlignment: 4,\n code: 'f32',\n});\n\nexport type Vec2u = WgslData<[number, number]>;\nexport const vec2u: Vec2u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32]),\n byteAlignment: 8,\n code: 'vec2u',\n});\n\nexport type Vec2i = WgslData<[number, number]>;\nexport const vec2i: Vec2i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32]),\n byteAlignment: 8,\n code: 'vec2i',\n});\nexport type Vec2f = WgslData<[number, number]>;\nexport const vec2f: Vec2f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32]),\n byteAlignment: 8,\n code: 'vec2f',\n});\nexport type Vec3u = WgslData<[number, number, number]>;\nexport const vec3u: Vec3u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec3u',\n});\nexport type Vec3i = WgslData<[number, number, number]>;\nexport const vec3i: Vec3i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec3i',\n});\nexport type Vec3f = WgslData<[number, number, number]>;\nexport const vec3f: Vec3f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec3f',\n});\nexport type Vec4u = WgslData<[number, number, number, number]>;\nexport const vec4u: Vec4u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec4u',\n});\nexport type Vec4i = WgslData<[number, number, number, number]>;\nexport const vec4i: Vec4i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec4i',\n});\nexport type Vec4f = WgslData<[number, number, number, number]>;\nexport const vec4f: Vec4f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec4f',\n});\n\n/**\n * Array of column vectors\n */\nexport type Mat4f = WgslData<number[]>;\nexport const mat4f: Mat4f = new SimpleWgslData({\n schema: TB.arrayOf(TB.f32, 16),\n byteAlignment: 16,\n code: 'mat4x4f',\n});\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n ValidationError,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\nimport { u32 } from './numeric';\n\nclass DynamicArrayDataType<TElement extends WgslData<unknown>>\n extends Schema<Unwrap<TElement>[]>\n implements WgslData<Unwrap<TElement>[]>\n{\n private _label: string | undefined;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(\n private readonly _elementType: TElement,\n public readonly capacity: number,\n ) {\n super();\n\n this.byteAlignment = Math.max(\n 4 /* u32 base alignment */,\n this._elementType.byteAlignment,\n );\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, values: ParseUnwrapped<TElement>[]): void {\n if (values.length > this.capacity) {\n throw new ValidationError(\n `Tried to write too many values, ${values.length} > ${this.capacity}`,\n );\n }\n\n alignIO(output, this.byteAlignment); // aligning to the start\n u32.write(output, values.length);\n alignIO(output, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = output.currentByteOffset;\n for (const value of values) {\n this._elementType.write(output, value);\n }\n output.seekTo(startOffset + this.capacity * this._elementType.size);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TElement>[] {\n const array: ParseUnwrapped<TElement>[] = [];\n\n alignIO(input, this.byteAlignment); // aligning to the start\n const len = u32.read(input);\n alignIO(input, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = input.currentByteOffset;\n for (let i = 0; i < len; ++i) {\n array.push(this._elementType.read(input) as ParseUnwrapped<TElement>);\n }\n input.seekTo(startOffset + this.capacity * this._elementType.size);\n\n return array;\n }\n\n measure(\n _values: ParseUnwrapped<TElement>[] | typeof MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment); // aligning to the start\n\n // Length encoding\n u32.measure(MaxValue, measurer);\n\n // Aligning to the start of the array\n alignIO(measurer, this._elementType.byteAlignment);\n\n // Values encoding\n measurer.add(this._elementType.size * this.capacity);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n count: u32,\n values: array<${this._elementType}, ${this.capacity}>,\n }`);\n\n return ctx.resolve(identifier);\n }\n}\n\nexport const dynamicArrayOf = <TSchema extends AnyWgslData>(\n elementType: TSchema,\n capacity: number,\n) => new DynamicArrayDataType(elementType, capacity);\n\nexport default DynamicArrayDataType;\n","import {\n type IMeasurer,\n type ISchema,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type Parsed,\n Schema,\n type UnwrapRecord,\n object,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslStruct<TProps extends Record<string, AnyWgslData>>\n extends ISchema<UnwrapRecord<TProps>>,\n WgslData<UnwrapRecord<TProps>> {\n $name(label: string): this;\n}\n\nexport const struct = <TProps extends Record<string, AnyWgslData>>(\n properties: TProps,\n): WgslStruct<TProps> => new WgslStructImpl(properties);\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslStructImpl<TProps extends Record<string, AnyWgslData>>\n extends Schema<UnwrapRecord<TProps>>\n implements WgslData<UnwrapRecord<TProps>>\n{\n private _label: string | undefined;\n private _innerSchema: ISchema<UnwrapRecord<TProps>>;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(private readonly _properties: TProps) {\n super();\n\n this._innerSchema = object(_properties);\n\n this.byteAlignment = Object.values(_properties)\n .map((prop) => prop.byteAlignment)\n .reduce((a, b) => (a > b ? a : b));\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: Parsed<UnwrapRecord<TProps>>): void {\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): Parsed<UnwrapRecord<TProps>> {\n return this._innerSchema.read(input);\n }\n\n measure(\n value: MaxValue | Parsed<UnwrapRecord<TProps>>,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n this._innerSchema.measure(value, measurer);\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n ${Object.entries(this._properties).map(([key, field]) => code`${key}: ${field},\\n`)}\n }\n `);\n\n return ctx.resolve(identifier);\n }\n}\n","import * as TB from 'typed-binary';\nimport type { AnyWgslData, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { SimpleWgslData } from './std140';\n\nexport type WgslArray<TElement extends AnyWgslData> = WgslData<\n TB.Unwrap<TElement>[]\n>;\n\nexport const arrayOf = <TElement extends AnyWgslData>(\n elementType: TElement,\n size: number,\n): WgslArray<TElement> =>\n new SimpleWgslData({\n schema: TB.arrayOf(elementType, size),\n byteAlignment: elementType.byteAlignment,\n code: code`array<${elementType}, ${size}>`,\n });\n","import type { AnyWgslData, WgslPointer } from '../types';\n\nexport function ptr<TDataType extends AnyWgslData>(\n pointsTo: TDataType,\n): WgslPointer<'function', TDataType> {\n return {\n scope: 'function',\n pointsTo,\n };\n}\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n type MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, WgslData } from '../types';\nimport type { I32, U32 } from './numeric';\n\nexport function atomic<TSchema extends U32 | I32>(\n data: TSchema,\n): Atomic<TSchema> {\n return new AtomicImpl(data);\n}\n\nexport interface Atomic<TSchema extends U32 | I32>\n extends WgslData<Unwrap<TSchema>> {}\n\nclass AtomicImpl<TSchema extends U32 | I32>\n extends Schema<Unwrap<TSchema>>\n implements Atomic<TSchema>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n constructor(private readonly innerData: TSchema) {\n super();\n this.size = this.innerData.size;\n this.byteAlignment = this.innerData.byteAlignment;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n this.innerData.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n return this.innerData.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n return this.innerData.measure(value, measurer);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return `atomic<${ctx.resolve(this.innerData)}>`;\n }\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
package/data/index.d.cts CHANGED
@@ -1,60 +1,9 @@
1
+ export { S as SimpleWgslData } from '../std140-DRitCcmc.cjs';
2
+ import { k as AnyWgslData, M as WgslData, R as ResolutionCtx, N as WgslPointer, _ as U32, $ as I32 } from '../types-ENDwr_p9.cjs';
3
+ export { a0 as Bool, a4 as F32, ao as Mat4f, aa as Vec2f, a8 as Vec2i, a6 as Vec2u, ag as Vec3f, ae as Vec3i, ac as Vec3u, am as Vec4f, ak as Vec4i, ai as Vec4u, a1 as bool, a5 as f32, a3 as i32, ap as mat4f, a2 as u32, ab as vec2f, a9 as vec2i, a7 as vec2u, ah as vec3f, af as vec3i, ad as vec3u, an as vec4f, al as vec4i, aj as vec4u } from '../types-ENDwr_p9.cjs';
1
4
  import * as TB from 'typed-binary';
2
- import { AnySchema, Schema, Unwrap, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer } from 'typed-binary';
5
+ import { Schema, Unwrap, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer, ISchema, UnwrapRecord } from 'typed-binary';
3
6
  export { Parsed, Unwrap } from 'typed-binary';
4
- import { r as WgslData, e as Wgsl, R as ResolutionCtx, A as AnyWgslData, s as WgslPointer } from '../types-DeF6xFAt.cjs';
5
- export { W as WgslStruct, s as struct } from '../struct-ER9XI7ad.cjs';
6
-
7
- declare class SimpleWgslData<TSchema extends AnySchema> extends Schema<Unwrap<TSchema>> implements WgslData<Unwrap<TSchema>> {
8
- readonly size: number;
9
- readonly byteAlignment: number;
10
- private readonly _innerSchema;
11
- private readonly _expressionCode;
12
- /**
13
- * byteAlignment has to be a power of 2
14
- */
15
- constructor({ schema, byteAlignment, code, }: {
16
- schema: TSchema;
17
- byteAlignment: number;
18
- code: Wgsl;
19
- });
20
- resolveReferences(): void;
21
- write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void;
22
- read(input: ISerialInput): ParseUnwrapped<TSchema>;
23
- measure(value: ParseUnwrapped<TSchema> | MaxValue, measurer?: IMeasurer): IMeasurer;
24
- resolve(ctx: ResolutionCtx): string;
25
- }
26
-
27
- type Bool = WgslData<boolean>;
28
- declare const bool: Bool;
29
- type U32 = WgslData<number>;
30
- declare const u32: U32;
31
- type I32 = WgslData<number>;
32
- declare const i32: I32;
33
- type F32 = WgslData<number>;
34
- declare const f32: F32;
35
- type Vec2u = WgslData<[number, number]>;
36
- declare const vec2u: Vec2u;
37
- type Vec2i = WgslData<[number, number]>;
38
- declare const vec2i: Vec2i;
39
- type Vec2f = WgslData<[number, number]>;
40
- declare const vec2f: Vec2f;
41
- type Vec3u = WgslData<[number, number, number]>;
42
- declare const vec3u: Vec3u;
43
- type Vec3i = WgslData<[number, number, number]>;
44
- declare const vec3i: Vec3i;
45
- type Vec3f = WgslData<[number, number, number]>;
46
- declare const vec3f: Vec3f;
47
- type Vec4u = WgslData<[number, number, number, number]>;
48
- declare const vec4u: Vec4u;
49
- type Vec4i = WgslData<[number, number, number, number]>;
50
- declare const vec4i: Vec4i;
51
- type Vec4f = WgslData<[number, number, number, number]>;
52
- declare const vec4f: Vec4f;
53
- /**
54
- * Array of column vectors
55
- */
56
- type Mat4f = WgslData<number[]>;
57
- declare const mat4f: Mat4f;
58
7
 
59
8
  declare class DynamicArrayDataType<TElement extends WgslData<unknown>> extends Schema<Unwrap<TElement>[]> implements WgslData<Unwrap<TElement>[]> {
60
9
  private readonly _elementType;
@@ -72,6 +21,11 @@ declare class DynamicArrayDataType<TElement extends WgslData<unknown>> extends S
72
21
  }
73
22
  declare const dynamicArrayOf: <TSchema extends AnyWgslData>(elementType: TSchema, capacity: number) => DynamicArrayDataType<TSchema>;
74
23
 
24
+ interface WgslStruct<TProps extends Record<string, AnyWgslData>> extends ISchema<UnwrapRecord<TProps>>, WgslData<UnwrapRecord<TProps>> {
25
+ $name(label: string): this;
26
+ }
27
+ declare const struct: <TProps extends Record<string, AnyWgslData>>(properties: TProps) => WgslStruct<TProps>;
28
+
75
29
  type WgslArray<TElement extends AnyWgslData> = WgslData<TB.Unwrap<TElement>[]>;
76
30
  declare const arrayOf: <TElement extends AnyWgslData>(elementType: TElement, size: number) => WgslArray<TElement>;
77
31
 
@@ -81,4 +35,4 @@ declare function atomic<TSchema extends U32 | I32>(data: TSchema): Atomic<TSchem
81
35
  interface Atomic<TSchema extends U32 | I32> extends WgslData<Unwrap<TSchema>> {
82
36
  }
83
37
 
84
- export { type Bool, type F32, type I32, type Mat4f, SimpleWgslData, type U32, type Vec2f, type Vec2i, type Vec2u, type Vec3f, type Vec3i, type Vec3u, type Vec4f, type Vec4i, type Vec4u, type WgslArray, arrayOf, atomic, bool, dynamicArrayOf, f32, i32, mat4f, ptr, u32, vec2f, vec2i, vec2u, vec3f, vec3i, vec3u, vec4f, vec4i, vec4u };
38
+ export { I32, U32, type WgslArray, type WgslStruct, arrayOf, atomic, dynamicArrayOf, ptr, struct };
package/data/index.d.ts CHANGED
@@ -1,60 +1,9 @@
1
+ export { S as SimpleWgslData } from '../std140-Cv7GDE9w.js';
2
+ import { k as AnyWgslData, M as WgslData, R as ResolutionCtx, N as WgslPointer, _ as U32, $ as I32 } from '../types-ENDwr_p9.js';
3
+ export { a0 as Bool, a4 as F32, ao as Mat4f, aa as Vec2f, a8 as Vec2i, a6 as Vec2u, ag as Vec3f, ae as Vec3i, ac as Vec3u, am as Vec4f, ak as Vec4i, ai as Vec4u, a1 as bool, a5 as f32, a3 as i32, ap as mat4f, a2 as u32, ab as vec2f, a9 as vec2i, a7 as vec2u, ah as vec3f, af as vec3i, ad as vec3u, an as vec4f, al as vec4i, aj as vec4u } from '../types-ENDwr_p9.js';
1
4
  import * as TB from 'typed-binary';
2
- import { AnySchema, Schema, Unwrap, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer } from 'typed-binary';
5
+ import { Schema, Unwrap, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer, ISchema, UnwrapRecord } from 'typed-binary';
3
6
  export { Parsed, Unwrap } from 'typed-binary';
4
- import { r as WgslData, e as Wgsl, R as ResolutionCtx, A as AnyWgslData, s as WgslPointer } from '../types-DeF6xFAt.js';
5
- export { W as WgslStruct, s as struct } from '../struct-udnQvwHG.js';
6
-
7
- declare class SimpleWgslData<TSchema extends AnySchema> extends Schema<Unwrap<TSchema>> implements WgslData<Unwrap<TSchema>> {
8
- readonly size: number;
9
- readonly byteAlignment: number;
10
- private readonly _innerSchema;
11
- private readonly _expressionCode;
12
- /**
13
- * byteAlignment has to be a power of 2
14
- */
15
- constructor({ schema, byteAlignment, code, }: {
16
- schema: TSchema;
17
- byteAlignment: number;
18
- code: Wgsl;
19
- });
20
- resolveReferences(): void;
21
- write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void;
22
- read(input: ISerialInput): ParseUnwrapped<TSchema>;
23
- measure(value: ParseUnwrapped<TSchema> | MaxValue, measurer?: IMeasurer): IMeasurer;
24
- resolve(ctx: ResolutionCtx): string;
25
- }
26
-
27
- type Bool = WgslData<boolean>;
28
- declare const bool: Bool;
29
- type U32 = WgslData<number>;
30
- declare const u32: U32;
31
- type I32 = WgslData<number>;
32
- declare const i32: I32;
33
- type F32 = WgslData<number>;
34
- declare const f32: F32;
35
- type Vec2u = WgslData<[number, number]>;
36
- declare const vec2u: Vec2u;
37
- type Vec2i = WgslData<[number, number]>;
38
- declare const vec2i: Vec2i;
39
- type Vec2f = WgslData<[number, number]>;
40
- declare const vec2f: Vec2f;
41
- type Vec3u = WgslData<[number, number, number]>;
42
- declare const vec3u: Vec3u;
43
- type Vec3i = WgslData<[number, number, number]>;
44
- declare const vec3i: Vec3i;
45
- type Vec3f = WgslData<[number, number, number]>;
46
- declare const vec3f: Vec3f;
47
- type Vec4u = WgslData<[number, number, number, number]>;
48
- declare const vec4u: Vec4u;
49
- type Vec4i = WgslData<[number, number, number, number]>;
50
- declare const vec4i: Vec4i;
51
- type Vec4f = WgslData<[number, number, number, number]>;
52
- declare const vec4f: Vec4f;
53
- /**
54
- * Array of column vectors
55
- */
56
- type Mat4f = WgslData<number[]>;
57
- declare const mat4f: Mat4f;
58
7
 
59
8
  declare class DynamicArrayDataType<TElement extends WgslData<unknown>> extends Schema<Unwrap<TElement>[]> implements WgslData<Unwrap<TElement>[]> {
60
9
  private readonly _elementType;
@@ -72,6 +21,11 @@ declare class DynamicArrayDataType<TElement extends WgslData<unknown>> extends S
72
21
  }
73
22
  declare const dynamicArrayOf: <TSchema extends AnyWgslData>(elementType: TSchema, capacity: number) => DynamicArrayDataType<TSchema>;
74
23
 
24
+ interface WgslStruct<TProps extends Record<string, AnyWgslData>> extends ISchema<UnwrapRecord<TProps>>, WgslData<UnwrapRecord<TProps>> {
25
+ $name(label: string): this;
26
+ }
27
+ declare const struct: <TProps extends Record<string, AnyWgslData>>(properties: TProps) => WgslStruct<TProps>;
28
+
75
29
  type WgslArray<TElement extends AnyWgslData> = WgslData<TB.Unwrap<TElement>[]>;
76
30
  declare const arrayOf: <TElement extends AnyWgslData>(elementType: TElement, size: number) => WgslArray<TElement>;
77
31
 
@@ -81,4 +35,4 @@ declare function atomic<TSchema extends U32 | I32>(data: TSchema): Atomic<TSchem
81
35
  interface Atomic<TSchema extends U32 | I32> extends WgslData<Unwrap<TSchema>> {
82
36
  }
83
37
 
84
- export { type Bool, type F32, type I32, type Mat4f, SimpleWgslData, type U32, type Vec2f, type Vec2i, type Vec2u, type Vec3f, type Vec3i, type Vec3u, type Vec4f, type Vec4i, type Vec4u, type WgslArray, arrayOf, atomic, bool, dynamicArrayOf, f32, i32, mat4f, ptr, u32, vec2f, vec2i, vec2u, vec3f, vec3i, vec3u, vec4f, vec4i, vec4u };
38
+ export { I32, U32, type WgslArray, type WgslStruct, arrayOf, atomic, dynamicArrayOf, ptr, struct };