typegpu 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/attributes-BdU8hyQq.d.cts +435 -0
  3. package/attributes-CAsvE5Z9.d.ts +435 -0
  4. package/chunk-5PJ3H5OR.js +2 -0
  5. package/chunk-5PJ3H5OR.js.map +1 -0
  6. package/chunk-7UUBX6MC.cjs +4 -0
  7. package/chunk-7UUBX6MC.cjs.map +1 -0
  8. package/chunk-AKBL6GDL.js +4 -0
  9. package/chunk-AKBL6GDL.js.map +1 -0
  10. package/chunk-URJCMUTT.cjs +2 -0
  11. package/chunk-URJCMUTT.cjs.map +1 -0
  12. package/data/index.cjs +1 -1
  13. package/data/index.cjs.map +1 -1
  14. package/data/index.d.cts +51 -4
  15. package/data/index.d.ts +51 -4
  16. package/data/index.js +1 -1
  17. package/index.cjs +17 -17
  18. package/index.cjs.map +1 -1
  19. package/index.d.cts +92 -53
  20. package/index.d.ts +92 -53
  21. package/index.js +17 -17
  22. package/index.js.map +1 -1
  23. package/package.json +2 -2
  24. package/std/index.cjs +1 -1
  25. package/std/index.cjs.map +1 -1
  26. package/std/index.d.cts +141 -33
  27. package/std/index.d.ts +141 -33
  28. package/std/index.js +1 -1
  29. package/std/index.js.map +1 -1
  30. package/{wgslTypes-VtSRoe90.d.ts → wgslTypes-Bh2dG5qv.d.cts} +213 -405
  31. package/{wgslTypes-VtSRoe90.d.cts → wgslTypes-Bh2dG5qv.d.ts} +213 -405
  32. package/attributes-B4JpvOTz.d.ts +0 -159
  33. package/attributes-DSOqT8yA.d.cts +0 -159
  34. package/chunk-3JTP2ATR.cjs +0 -2
  35. package/chunk-3JTP2ATR.cjs.map +0 -1
  36. package/chunk-3QXCKMEJ.cjs +0 -2
  37. package/chunk-3QXCKMEJ.cjs.map +0 -1
  38. package/chunk-DR55IHDD.js +0 -4
  39. package/chunk-DR55IHDD.js.map +0 -1
  40. package/chunk-KVOFUY5A.js +0 -2
  41. package/chunk-KVOFUY5A.js.map +0 -1
  42. package/chunk-QRLTUOBJ.cjs +0 -4
  43. package/chunk-QRLTUOBJ.cjs.map +0 -1
  44. package/chunk-VOFHV4Z6.js +0 -2
  45. package/chunk-VOFHV4Z6.js.map +0 -1
package/index.js CHANGED
@@ -1,26 +1,26 @@
1
- import{$ as A,a as Er,aa as W,b as Vr,c as Xe,ca as h,d as Ze,e as Z,ea as $r,f as Gr,g as ee,h as k,i as Pt,j as $,k as Ce,oa as Or,ra as kr,ta as et,ua as tt}from"./chunk-VOFHV4Z6.js";import{a as b,b as j,c as K,d as Rt,e as ue,f as P,h as Pr,i as q,j as Lr,k as Qe,l as Cr}from"./chunk-KVOFUY5A.js";import{A as S,B as Pe,C,D as E,E as qe,F as Je,G as He,I as Ye,J as _t,K as be,L as U,M as B,N as m,O as Le,P as vr,Q as Ur,R as Ar,S as Ir,T as Rr,U as Br,V as Q,W as X,X as _,Z as _r,a as R,b as L,c as p,d as Ae,da as we,e as ye,f as Ft,g as vt,h as Ut,i as ie,j as Ie,k as Re,l as Dr,m as z,n as At,o as It,p as se,q as Fr,r as Bt,s as G,t as Be,u as H,v as Y,w as pe,x as _e,y as xe,z as he}from"./chunk-DR55IHDD.js";var zn=["vec2f","vec2h","vec2i","vec2u","vec3f","vec3h","vec3i","vec3u","vec4f","vec4h","vec4i","vec4u","struct"],jn={f:{1:m,2:G,3:pe,4:S},h:{1:Le,2:Be,3:_e,4:Pe},i:{1:B,2:H,3:xe,4:C},u:{1:U,2:Y,3:he,4:E}},Wr={vec2f:G,vec2h:Be,vec2i:H,vec2u:Y,vec3f:pe,vec3h:_e,vec3i:xe,vec3u:he,vec4f:S,vec4h:Pe,vec4i:C,vec4u:E,mat2x2f:qe,mat3x3f:Je,mat4x4f:He},Mr={vec2f:m,vec2h:Le,vec2i:B,vec2u:U,vec3f:m,vec3h:Le,vec3i:B,vec3u:U,vec4f:m,vec4h:Le,vec4i:B,vec4u:U,mat2x2f:G,mat3x3f:pe,mat4x4f:S};function Ee(e,t){var o;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return P;if(K(e)||j(e)){let i=z();if(!i)throw new Error("Resolution context not found when unwrapping slot or derived");let s=i.unwrap(e);return Se(s)}let r=e;for(Cr(r)&&(r=r[b].dataType);we(r);)r=r.inner;let n="kind"in r?r.kind:r.type;if(n==="struct")return(o=r.propTypes[t])!=null?o:P;let a=t.length;if(zn.includes(n)&&a>=1&&a<=4){let i=n[4],s=jn[i][a];if(s)return s}return Q(r)?r:P}function Nr(e){if(Q(e)){if(X(e))return e.elementType;if(e.type in Mr)return Mr[e.type]}return P}function Se(e){var t,r;if(K(e)||j(e))return Se(e.value);if(typeof e=="string")return P;if(typeof e=="number")return(r=(t=Lt(String(e)))==null?void 0:t.dataType)!=null?r:P;if(typeof e=="boolean")return be;if("kind"in e){let n=e.kind;if(n in Wr)return Wr[n]}return Q(e)?e:P}function Lt(e){if(/^0x[0-9a-f]+$/i.test(e))return{value:e,dataType:Ye};if(/^0b[01]+$/i.test(e))return{value:`${Number.parseInt(e.slice(2),2)}`,dataType:Ye};if(/^-?(?:\d+\.\d*|\d*\.\d+)$/i.test(e))return{value:e,dataType:_t};if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return{value:e,dataType:_t};if(/^-?\d+$/i.test(e))return{value:e,dataType:Ye}}var M={get(e,t){if(t in e)return Reflect.get(e,t);if(t!=="~providing")return t==="toString"||t===Symbol.toStringTag||t===Symbol.toPrimitive?()=>e.toString():new Proxy({"~resolve":r=>`${r.resolve(e)}.${String(t)}`,toString:()=>{var r;return`.value(...).${String(t)}:${(r=e.label)!=null?r:"<unnamed>"}`},[b]:{dataType:Ee(e[b].dataType,String(t))}},M)}};function Ve(e){let t=e;for(;j(t)||K(t)||ue(t)||Qe(t);)t=t.value;return t}function jr(e,t){return new Ct(e,t)}var zr;zr=b;var Ct=class{constructor(t,r){this.dataType=t;this._value=r;p(this,"_label");p(this,zr);this[b]={dataType:t}}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${r} = ${n};`),r}toString(){var t;return`const:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){return se()?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`},[b]:{dataType:this.dataType}},M):this._value}};function N(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function le(e,t){for(let[r,n]of Object.entries(t))e[r]=n,N(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function Kr(e,t,r){let n=[...e.matchAll(new RegExp(":\\s*(?<arg>.*?)\\s*[,)]","g"))].map(a=>a?a[1]:void 0);r(Object.fromEntries(t.flatMap((a,o)=>{let i=n?n[o]:void 0;return _(a)&&i!==void 0?[[i,a]]:[]})))}function De(e,t,r){var o;let n=e.match(new RegExp("->(?<output>.*?){","s")),a=n?(o=n[1])==null?void 0:o.trim():void 0;_(t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function Kn(e){return new RegExp(`(?<![\\w_.])${e.replaceAll(".","\\.")}(?![\\w_])`,"g")}function de(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{var i;return q(o)||Xe(o)?n.replaceAll(Kn(a),e.resolve(o)):o!==null&&typeof o=="object"?((i=[...r.matchAll(new RegExp(`${a.replaceAll(".","\\.")}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(l=>l[1]))!=null?i:[]).reduce((l,u)=>u&&u in o?de(e,{[`${a}.${u}`]:o[u]},l):l,n):n},r)}function qr(e){return new Et(e)}var Et=class{constructor(t){this.declaration=t;p(this,"externalsToApply",[])}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)le(r,a);let n=de(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var Jr=new WeakMap;function Hr(e){return Jr.get(e)}function Yr(e,t,r){return Jr.set(e,{ast:t,externals:r}),e}function te(e,t){let r=[];return typeof t=="string"&&(Kr(t,e.argTypes,n=>r.push(n)),De(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){var s;let o={};for(let l of r)le(o,l);let i=n.names.makeUnique(this.label);if(typeof t=="string"){let l=de(n,o,t.trim());n.addDeclaration(`${a}fn ${i}${l}`)}else{let l=Hr(t);if(l!=null&&l.externals){let c=Object.fromEntries(Object.entries(l.externals).filter(([T])=>!(T in o)));le(o,c)}let u=(s=l==null?void 0:l.ast)!=null?s:n.transpileFn(String(t)),d=u.externalNames.filter(c=>!(c in o));if(d.length>0)throw new Ut(this.label,d);let f=u.argNames.map((c,T)=>({value:c,dataType:e.argTypes[T]})),{head:g,body:w}=n.fnToWgsl({args:f,returnType:e.returnType,body:u.body,externalMap:o});n.addDeclaration(`${a}fn ${i}${n.resolve(g)}${n.resolve(w)}`)}return i}}}function Qr(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(et(n))return[r,n];let a=ee(n);return a!==void 0?(t=a+1,[r,n]):[r,Or(n,{type:"@location",value:t++})]}))}function rt(e){return k(e)?ee(e)!==void 0?e:kr(0,e):Pt(Qr(e))}function Fe(e){return Pt(Qr(e))}function Xr(e){var t,r,n,a;return{argTypes:[Fe((t=e.in)!=null?t:{})],returnType:void 0,workgroupSize:[(r=e.workgroupSize[0])!=null?r:1,(n=e.workgroupSize[1])!=null?n:1,(a=e.workgroupSize[2])!=null?a:1],does(o){return qn(this,e.workgroupSize,o)}}}function qn(e,t,r){let n=te(e,r),a=e.argTypes[0];return{shell:e,get label(){return n.label},$uses(o){return n.applyExternals(o),this},$name(o){return n.label=o,N(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){return n.resolve(o,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){var o;return`computeFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}function Zr(e,t){return{argTypes:e,returnType:t,does(r){return Hn(this,r)}}}function Vt(e){return(e==null?void 0:e.resourceType)==="function"}function Jn([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function Hn(e,t){let r=te(e,t),n={shell:e,resourceType:"function",$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,this},with(i,s){return en(o,[[ue(i)?i.slot:i,s]])},"~resolve"(i){return r.resolve(i)}},a=Bt((...i)=>{if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...i)},(...i)=>{var s;return{value:new nt(o,i.map(l=>l.value)),dataType:(s=e.returnType)!=null?s:P}});Object.defineProperty(a,b,{value:{implementation:t}});let o=Object.assign(a,n);return Object.defineProperty(o,"label",{get:()=>r.label}),Object.defineProperty(o,"toString",{value:()=>{var i;return`fn:${(i=r.label)!=null?i:"<unnamed>"}`}}),o}function en(e,t){let r={resourceType:"function",shell:e.shell,"~providing":{inner:e,pairs:t},$uses(o){return e.$uses(o),this},$name(o){return e.$name(o),this},with(o,i){return en(a,[...t,[ue(o)?o.slot:o,i]])}},n=Bt((...o)=>e(...o),(...o)=>{var i;return{value:new nt(a,o.map(s=>s.value)),dataType:(i=e.shell.returnType)!=null?i:P}}),a=Object.assign(n,r);return Object.defineProperty(a,"label",{get:()=>e.label}),Object.defineProperty(a,"toString",{value(){var i;return`fn:${(i=e.label)!=null?i:"<unnamed>"}[${t.map(Jn).join(", ")}]`}}),Object.defineProperty(a,b,{value:{implementation:e[b].implementation}}),a}var nt=class{constructor(t,r){this._fn=t;this._params=r}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(r=>t.resolve(r)).join(", ")})`)}toString(){var t;return`call:${(t=this.label)!=null?t:"<unnamed>"}`}};function tn(e){var t;return{argTypes:[Fe((t=e.in)!=null?t:{})],targets:e.out,returnType:rt(e.out),does(r){return Yn(this,r)}}}function Yn(e,t){let r=te(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&De(t,n,i=>r.applyExternals(i)),{shell:e,outputType:n,get label(){return r.label},$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,N(n)&&n.$name(`${i}_Output`),N(a)&&a.$name(`${i}_Input`),this},"~resolve"(i){if(typeof t=="string")return r.resolve(i,"@fragment ");let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(n),r.resolve(i,"@fragment ")}finally{s.callStack.pop()}},toString(){var i;return`fragmentFn:${(i=this.label)!=null?i:"<unnamed>"}`}}}function rn(e){var t,r;return{attributes:[(t=e.in)!=null?t:{}],returnType:rt(e.out),argTypes:[Fe((r=e.in)!=null?r:{})],does(n){return Qn(this,n)}}}function Qn(e,t){let r=te(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&De(t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,inputType:a,get label(){return r.label},$uses(o){return r.applyExternals(o),this},$name(o){return r.label=o,N(n)&&n.$name(`${o}_Output`),N(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){if(typeof t=="string")return r.resolve(o,"@vertex ");let i=o;if(i.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return i.callStack.push(n),r.resolve(o,"@vertex ")}finally{i.callStack.pop()}},toString(){var o;return`vertexFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}var re=class{constructor(){p(this,"lastUniqueId",0)}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},ne=class{constructor(){p(this,"_usedNames",new Set)}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function nn(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function Ge(e){return typeof(e==null?void 0:e.format)=="string"}function an(e,t){var i,s;let r=[];if(k(e)){if(!Ge(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:(i=ee(e))!=null?i:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[l,u]of Object.entries(e)){if(et(u))continue;let d=t[l];if(!d)throw new Error(`An attribute by the name of '${l}' was not provided to the shader.`);let f=d._layout,g=a.get(f);g||(r.push(f),g=[],n.push({arrayStride:f.stride,stepMode:f.stepMode,attributes:g}),a.set(f,g)),o=(s=ee(u))!=null?s:o,g.push({format:d.format,offset:d.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var Xn=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function Zn(e){return Xn.includes(e.type)}function Gt(e,[t,r]){return` ${tt(r)}${t}: ${e.resolve(r)},
2
- `}function ea(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
1
+ import{a as y,b as N,c as j,d as Dt,e as oe,f as R,h as _r,i as z,j as Pr,k as qe,l as Lr}from"./chunk-5PJ3H5OR.js";import{A as x,B as Re,C as B,D as _,E as Bt,F as je,G as ze,H as Ke,J as Te,K as _t,L as E,M as S,N as I,O as l,P as Be,Q as Fr,R as Dr,S as Ur,T as Ar,U as Ir,V as Rr,W as V,X as O,Y as h,_ as Br,a as Fe,b as me,c as bt,cb as D,d as wt,db as G,e as St,ea as ce,f as ne,fa as Cr,fb as L,g as De,ga as Er,gb as c,h as Ue,ha as He,i as Sr,ia as Je,ib as Or,j as M,ja as Y,k as vt,ka as Vr,l as Ft,la as Q,lb as $r,m as ae,ma as $,n as vr,na as _e,nb as Ye,o as Ut,ob as ye,p as At,pb as Pt,q as P,qb as Gr,r as Ae,s as H,t as J,u as It,v as ie,w as Ie,x as ge,y as fe,z as Rt}from"./chunk-AKBL6GDL.js";var kn=["vec2f","vec2h","vec2i","vec2u","vec2<bool>","vec3f","vec3h","vec3i","vec3u","vec3<bool>","vec4f","vec4h","vec4i","vec4u","vec4<bool>","struct"],Wn={f:{1:l,2:P,3:ie,4:x},h:{1:Be,2:Ae,3:Ie,4:Re},i:{1:I,2:H,3:ge,4:B},u:{1:S,2:J,3:fe,4:_},b:{1:E,2:It,3:Rt,4:Bt}},kr={vec2f:P,vec2h:Ae,vec2i:H,vec2u:J,"vec2<bool>":It,vec3f:ie,vec3h:Ie,vec3i:ge,vec3u:fe,"vec3<bool>":Rt,vec4f:x,vec4h:Re,vec4i:B,vec4u:_,"vec4<bool>":Bt,mat2x2f:je,mat3x3f:ze,mat4x4f:Ke},Wr={vec2f:l,vec2h:Be,vec2i:I,vec2u:S,"vec2<bool>":E,vec3f:l,vec3h:Be,vec3i:I,vec3u:S,"vec3<bool>":E,vec4f:l,vec4h:Be,vec4i:I,vec4u:S,"vec4<bool>":E,mat2x2f:P,mat3x3f:ie,mat4x4f:x};function Pe(e,t){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return R;if(j(e)||N(e)){let o=M();if(!o)throw new Error("Resolution context not found when unwrapping slot or derived");let i=o.unwrap(e);return xe(i)}let r=e;for(Lr(r)&&(r=r[y].dataType);ce(r);)r=r.inner;let n="kind"in r?r.kind:r.type;if(n==="struct")return r.propTypes[t]??R;let a=t.length;if(kn.includes(n)&&a>=1&&a<=4){let o=n.includes("bool")?"b":n[4],i=Wn[o][a];if(i)return i}return V(r)?r:R}function Mr(e){if(V(e)){if(O(e))return e.elementType;if(e.type in Wr)return Wr[e.type]}return R}function xe(e){if(j(e)||N(e))return xe(e.value);if(typeof e=="string")return R;if(typeof e=="number")return Lt(String(e))?.dataType??R;if(typeof e=="boolean")return E;if("kind"in e){let t=e.kind;if(t in kr)return kr[t]}return V(e)?e:R}function Lt(e){if(/^0x[0-9a-f]+$/i.test(e))return{value:e,dataType:Te};if(/^0b[01]+$/i.test(e))return{value:`${Number.parseInt(e.slice(2),2)}`,dataType:Te};if(/^-?(?:\d+\.\d*|\d*\.\d+)$/i.test(e))return{value:e,dataType:_t};if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return{value:e,dataType:_t};if(/^-?\d+$/i.test(e))return{value:e,dataType:Te}}var k={get(e,t){if(t in e)return Reflect.get(e,t);if(t!=="~providing")return t==="toString"||t===Symbol.toStringTag||t===Symbol.toPrimitive?()=>e.toString():new Proxy({"~resolve":r=>`${r.resolve(e)}.${String(t)}`,toString:()=>`.value(...).${String(t)}:${e.label??"<unnamed>"}`,[y]:{dataType:Pe(e[y].dataType,String(t))}},k)}};function Le(e){let t=e;for(;N(t)||j(t)||oe(t)||qe(t);)t=t.value;return t}function Nr(e,t){return new Ct(e,t)}var Ct=class{constructor(t,r){this.dataType=t;this._value=r;this[y]={dataType:t}}_label;[y];get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${r} = ${n};`),r}toString(){return`const:${this.label??"<unnamed>"}`}get value(){return ae()?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.dataType}},k):this._value}};function W(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function K(e,t){for(let[r,n]of Object.entries(t))e[r]=n,W(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function jr(e,t,r){let n=[...e.matchAll(/:\s*(?<arg>.*?)\s*[,)]/g)].map(a=>a?a[1]:void 0);r(Object.fromEntries(t.flatMap((a,o)=>{let i=n?n[o]:void 0;return h(a)&&i!==void 0?[[i,a]]:[]})))}function he(e,t,r){let n=e.match(/->(?<output>.*?){/s),a=n?n[1]?.trim():void 0;h(t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function Mn(e){return new RegExp(`(?<![\\w\\$_.])${e.replaceAll(".","\\.").replaceAll("$","\\$")}(?![\\w\\$_])`,"g")}function se(e,t,r){return Object.entries(t).reduce((n,[a,o])=>z(o)||He(o)?n.replaceAll(Mn(a),e.resolve(o)):o!==null&&typeof o=="object"?([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.").replaceAll("$","\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`,"g"))].map(s=>s[1])??[]).reduce((s,p)=>p&&p in o?se(e,{[`${a}.${p}`]:o[p]},s):s,n):n,r)}function zr(e){return new Et(e)}var Et=class{constructor(t){this.declaration=t}externalsToApply=[];$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)K(r,a);let n=se(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var Kr=new WeakMap;function qr(e){return Kr.get(e)}function Hr(e,t,r){return Kr.set(e,{ast:t,externals:r}),e}function Jr(e){return()=>{throw new Error(`The function "${e??"<unnamed>"}" is invokable only on the GPU. If you want to use it on the CPU, mark it with the "kernel & js" directive.`)}}function Yr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function Ce(e){return typeof e?.format=="string"}function Qr(e,t){let r=[];if($(e)){if(!Ce(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:Q(e)??0}]}]}}let n=[],a=new WeakMap,o=0;for(let[i,s]of Object.entries(e)){if(Ye(s))continue;let p=t[i];if(!p)throw new Error(`An attribute by the name of '${i}' was not provided to the shader.`);let u=p._layout,d=a.get(u);d||(r.push(u),d=[],n.push({arrayStride:u.stride,stepMode:u.stepMode,attributes:d}),a.set(u,d)),o=Q(s)??o,d.push({format:p.format,offset:p.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var Nn=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","vec2<bool>","vec3<bool>","vec4<bool>","mat2x2f","mat3x3f","mat4x4f"];function jn(e){return Nn.includes(e.type)}function Vt(e,[t,r]){return` ${ye(r)}${t}: ${e.resolve(r)},
2
+ `}function zn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
- ${Object.entries(t.propTypes).map(n=>Gt(e,n)).join("")}}
5
- `),r}function ta(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
4
+ ${Object.entries(t.propTypes).map(n=>Vt(e,n)).join("")}}
5
+ `),r}function Kn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
6
6
  struct ${r} {
7
- ${Object.entries(t.propTypes).map(n=>Ge(n[1])?Gt(e,[n[0],Ce[n[1].format]]):Gt(e,n)).join("")}
7
+ ${Object.entries(t.propTypes).map(n=>Ce(n[1])?Vt(e,[n[0],_e[n[1].format]]):Vt(e,n)).join("")}
8
8
  }
9
- `),r}function ra(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function na(e,t){let r=e.resolve(Ge(t.elementType)?Ce[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function $t(e,t){if(Xe(t))return t.type==="unstruct"?ta(e,t):t.type==="disarray"?na(e,t):t.type==="loose-decorated"?e.resolve(Ge(t.inner)?Ce[t.inner.format]:t.inner):e.resolve(Ce[t.type]);if(Zn(t))return t.type;if(t.type==="struct")return ea(e,t);if(t.type==="array")return ra(e,t);if(t.type==="atomic")return`atomic<${$t(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);if(t.type==="ptr")return t.addressSpace==="storage"?`ptr<storage, ${e.resolve(t.inner)}, ${t.access==="read-write"?"read_write":t.access}>`:`ptr<${t.addressSpace}, ${e.resolve(t.inner)}>`;if(t.type==="abstractInt"||t.type==="abstractFloat")throw new Error("Abstract types have no concrete representation in WGSL");nn(t,"resolveData")}var oa=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"],ia=["&&","||","==","!=","<","<=",">",">="];function on(e,t,r){return r?ia.includes(t)?be:t==="="?r:e:t==="!"||t==="~"?be:e}function v(e,t){return q(t.value)?e.resolve(t.value):String(t.value)}function sa(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function sn(e,t){return{value:t?"true":"false",dataType:be}}function un(e,t){e.pushBlockScope();try{return`${e.indent()}{
10
- ${t.b.map(r=>me(e,r)).join(`
9
+ `),r}function qn(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Hn(e,t){let r=e.resolve(Ce(t.elementType)?_e[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Ot(e,t){if(He(t))return t.type==="unstruct"?Kn(e,t):t.type==="disarray"?Hn(e,t):t.type==="loose-decorated"?e.resolve(Ce(t.inner)?_e[t.inner.format]:t.inner):e.resolve(_e[t.type]);if(jn(t))return t.type;if(t.type==="struct")return zn(e,t);if(t.type==="array")return qn(e,t);if(t.type==="atomic")return`atomic<${Ot(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);if(t.type==="ptr")return t.addressSpace==="storage"?`ptr<storage, ${e.resolve(t.inner)}, ${t.access==="read-write"?"read_write":t.access}>`:`ptr<${t.addressSpace}, ${e.resolve(t.inner)}>`;if(t.type==="abstractInt"||t.type==="abstractFloat")throw new Error("Abstract types have no concrete representation in WGSL");Yr(t,"resolveData")}var Yn=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"],Qn=["&&","||","==","!=","<","<=",">",">="];function Xr(e,t,r){return r?Qn.includes(t)?E:t==="="?r:e:t==="!"||t==="~"?E:e}function v(e,t){return z(t.value)?e.resolve(t.value):String(t.value)}function Xn(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function Zr(e,t){return{value:t?"true":"false",dataType:E}}function en(e,t){e.pushBlockScope();try{return`${e.indent()}{
10
+ ${t.b.map(r=>ue(e,r)).join(`
11
11
  `)}
12
- ${e.dedent()}}`}finally{e.popBlockScope()}}function ua(e,t,r){return e.defineVariable(t,r)}function Ot(e,t){let r=e.getById(t);if(!r)throw new Error(`Identifier ${t} not found`);return r}function I(e,t){var r;if(typeof t=="string")return Ot(e,t);if(typeof t=="boolean")return sn(e,t);if("x"in t){let[n,a,o]=t.x,i=I(e,n),s=I(e,o),l=v(e,i),u=v(e,s),d=on(i.dataType,a,s.dataType);return{value:oa.includes(a)?`(${l} ${a} ${u})`:`${l} ${a} ${u}`,dataType:d}}if("p"in t){let[n,a]=t.p,o=I(e,a);return{value:`${v(e,o)}${n}`,dataType:o.dataType}}if("u"in t){let[n,a]=t.u,o=I(e,a),i=v(e,o),s=on(o.dataType,n);return{value:`${n}${i}`,dataType:s}}if("a"in t){let[n,a]=t.a,o=I(e,n);if(typeof o.value=="string")return{value:`${o.value}.${a}`,dataType:Ee(o.dataType,a)};let i=o.value[a];if(q(o.value))return{value:i,dataType:Ee(o.value,a)};if(typeof o.value=="object"){let s=q(i)?Se(i):P;return{value:i,dataType:s}}throw new Error(`Cannot access member ${a} of ${o.value}`)}if("i"in t){let[n,a]=t.i,o=I(e,n),i=I(e,a),s=v(e,o),l=v(e,i);return{value:`${s}[${l}]`,dataType:Nr(o.dataType)}}if("n"in t){let n=Lt(t.n);if(!n)throw new Error(`Invalid numeric literal ${t.n}`);return n}if("f"in t){let[n,a]=t.f,o=I(e,n),i=o.value;e.callStack.push(i);let l=a.map(d=>I(e,d)).map(d=>({value:v(e,d),dataType:d.dataType})),u=l.map(d=>d.value);return e.callStack.pop(),typeof i=="string"?{value:`${i}(${u.join(", ")})`,dataType:o.dataType}:_(i)?{value:`${e.resolve(i)}(${u.join(", ")})`,dataType:o.dataType}:i(...l)}if("o"in t){let n=t.o,a=e.callStack[e.callStack.length-1],o=i=>i.map(s=>{let l=I(e,s);return v(e,l)}).join(", ");if(_(a)){let s=Object.keys(a.propTypes).map(l=>{let u=n[l];if(u===void 0)throw new Error(`Missing property ${l} in object literal for struct ${a}`);return u});return{value:o(s),dataType:a}}return{value:o(Object.values(n)),dataType:P}}if("y"in t){let n=t.y.map(u=>I(e,u));if(n.length===0)throw new Error("Cannot create empty array literal.");let a=(r=n[0])==null?void 0:r.dataType,o=n.find(u=>u.dataType!==a);if(o)throw new Error(`Cannot mix types in array literal. Type ${o.dataType.type} does not match expected type ${a==null?void 0:a.type}.`);if(!Q(a))throw new Error("Cannot use non-WGSL data types in array literals.");a=a.type==="abstractInt"?U:a.type==="abstractFloat"?m:a;let s=`array<${e.resolve(a)}, ${n.length}>`,l=n.map(u=>v(e,u));return{value:`${s}( ${l.join(", ")} )`,dataType:$r(a,n.length)}}if("s"in t)throw new Error("Cannot use string literals in TGSL.");sa(t)}function me(e,t){if(typeof t=="string")return`${e.pre}${v(e,Ot(e,t))};`;if(typeof t=="boolean")return`${e.pre}${v(e,sn(e,t))};`;if("r"in t){if(_(e.callStack[e.callStack.length-1])&&t.r!==null&&typeof t.r=="object"&&"o"in t.r){let r=v(e,I(e,t.r)),n=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}return ${n}(${r});`}return t.r===null?`${e.pre}return;`:`${e.pre}return ${v(e,I(e,t.r))};`}if("q"in t){let[r,n,a]=t.q,o=v(e,I(e,r));e.indent();let i=me(e,n);e.dedent(),e.indent();let s=a?me(e,a):void 0;return e.dedent(),s?`${e.pre}if (${o})
12
+ ${e.dedent()}}`}finally{e.popBlockScope()}}function Zn(e,t,r){return e.defineVariable(t,r)}function $t(e,t){let r=e.getById(t);if(!r)throw new Error(`Identifier ${t} not found`);return r}function U(e,t){if(typeof t=="string")return $t(e,t);if(typeof t=="boolean")return Zr(e,t);if("x"in t){let[r,n,a]=t.x,o=U(e,r),i=U(e,a),s=v(e,o),p=v(e,i),u=Xr(o.dataType,n,i.dataType);return{value:Yn.includes(n)?`(${s} ${n} ${p})`:`${s} ${n} ${p}`,dataType:u}}if("p"in t){let[r,n]=t.p,a=U(e,n);return{value:`${v(e,a)}${r}`,dataType:a.dataType}}if("u"in t){let[r,n]=t.u,a=U(e,n),o=v(e,a),i=Xr(a.dataType,r);return{value:`${r}${o}`,dataType:i}}if("a"in t){let[r,n]=t.a,a=U(e,r);if(typeof a.value=="string")return{value:`${a.value}.${n}`,dataType:Pe(a.dataType,n)};if(O(a.dataType)&&n==="length")return a.dataType.elementCount===0?{value:`arrayLength(&${e.resolve(a.value)})`,dataType:S}:{value:String(a.dataType.elementCount),dataType:Te};let o=a.value[n];if(z(a.value))return{value:o,dataType:Pe(a.value,n)};if(typeof a.value=="object"){let i=z(o)?xe(o):R;return{value:o,dataType:i}}throw new Error(`Cannot access member ${n} of ${a.value}`)}if("i"in t){let[r,n]=t.i,a=U(e,r),o=U(e,n),i=v(e,a),s=v(e,o);return{value:`${i}[${s}]`,dataType:Mr(a.dataType)}}if("n"in t){let r=Lt(t.n);if(!r)throw new Error(`Invalid numeric literal ${t.n}`);return r}if("f"in t){let[r,n]=t.f,a=U(e,r),o=a.value;e.callStack.push(o);let s=n.map(u=>U(e,u)).map(u=>({value:v(e,u),dataType:u.dataType})),p=s.map(u=>u.value);return e.callStack.pop(),typeof o=="string"?{value:`${o}(${p.join(", ")})`,dataType:a.dataType}:h(o)?{value:`${e.resolve(o)}(${p.join(", ")})`,dataType:a.dataType}:o(...s)}if("o"in t){let r=t.o,n=e.callStack[e.callStack.length-1],a=o=>o.map(i=>{let s=U(e,i);return v(e,s)}).join(", ");if(h(n)){let i=Object.keys(n.propTypes).map(s=>{let p=r[s];if(p===void 0)throw new Error(`Missing property ${s} in object literal for struct ${n}`);return p});return{value:a(i),dataType:n}}return{value:a(Object.values(r)),dataType:R}}if("y"in t){let r=t.y.map(p=>U(e,p));if(r.length===0)throw new Error("Cannot create empty array literal.");let n=r[0]?.dataType,a=r.find(p=>p.dataType!==n);if(a)throw new Error(`Cannot mix types in array literal. Type ${a.dataType.type} does not match expected type ${n?.type}.`);if(!V(n))throw new Error("Cannot use non-WGSL data types in array literals.");n=n.type==="abstractInt"?S:n.type==="abstractFloat"?l:n;let i=`array<${e.resolve(n)}, ${r.length}>`,s=r.map(p=>v(e,p));return{value:`${i}( ${s.join(", ")} )`,dataType:Gr(n,r.length)}}if("s"in t)throw new Error("Cannot use string literals in TGSL.");Xn(t)}function ue(e,t){if(typeof t=="string")return`${e.pre}${v(e,$t(e,t))};`;if(typeof t=="boolean")return`${e.pre}${v(e,Zr(e,t))};`;if("r"in t){if(h(e.callStack[e.callStack.length-1])&&t.r!==null&&typeof t.r=="object"&&"o"in t.r){let r=v(e,U(e,t.r)),n=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}return ${n}(${r});`}return t.r===null?`${e.pre}return;`:`${e.pre}return ${v(e,U(e,t.r))};`}if("q"in t){let[r,n,a]=t.q,o=v(e,U(e,r));e.indent();let i=ue(e,n);e.dedent(),e.indent();let s=a?ue(e,a):void 0;return e.dedent(),s?`${e.pre}if (${o})
13
13
  ${i}
14
14
  ${e.pre}else
15
15
  ${s}`:`${e.pre}if (${o})
16
- ${i}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=n?I(e,n):void 0;if(!a||!n)throw new Error("Cannot create variable without an initial value.");ua(e,r,a.dataType);let o=v(e,Ot(e,r));if(typeof n=="object"&&"o"in n&&_(e.callStack[e.callStack.length-1])){let i=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}var ${o} = ${i}(${v(e,a)});`}return`${e.pre}var ${o} = ${v(e,a)};`}if("b"in t){e.pushBlockScope();try{return un(e,t)}finally{e.popBlockScope()}}if("j"in t){let[r,n,a,o]=t.j,i=r?me(e,r):void 0,s=i?i.slice(0,-1):"",l=n?I(e,n):void 0,u=l?v(e,l):"",d=a?me(e,a):void 0,f=d?d.slice(0,-1):"";e.indent();let g=me(e,o);return e.dedent(),`${e.pre}for (${s}; ${u}; ${f})
17
- ${g}`}if("w"in t){let[r,n]=t.w,a=v(e,I(e,r));e.indent();let o=me(e,n);return e.dedent(),`${e.pre}while (${a})
18
- ${o}`}return"k"in t?`${e.pre}continue;`:"d"in t?`${e.pre}break;`:`${e.pre}${v(e,I(e,t))};`}function kt(e,t){return un(e,t)}import{BufferReader as Jt,BufferWriter as Ht}from"typed-binary";import{getSystemEndianness as ma}from"typed-binary";import{Measurer as la}from"typed-binary";function pa(e,t){let r="size"in e?e.size:e.currentByteOffset,n=t-1,a=r&n;"skipBytes"in e?e.skipBytes(t-a&n):e.add(t-a&n)}var D=pa;var pn=new WeakMap;function at(e){let t=pn.get(e);if(t)return t;let r=new la,n={},a;for(let o in e.propTypes){let i=e.propTypes[o];if(i===void 0)throw new Error(`Property ${o} is undefined in struct`);let s=r.size;D(r,Z(e)?W(i):A(i)),a&&(a.padding=r.size-s);let l=h(i);n[o]={offset:r.size,size:l},a=n[o],r.add(l)}return a&&(a.padding=$(h(e),A(e))-r.size),pn.set(e,n),n}var ot=(()=>{try{return new Function("return true"),!0}catch(e){return!1}})(),Wt=new WeakMap,Mt={u32:"u32",vec2u:"u32",vec3u:"u32",vec4u:"u32",i32:"i32",vec2i:"i32",vec3i:"i32",vec4i:"i32",f32:"f32",vec2f:"f32",vec3f:"f32",vec4f:"f32",vec2h:"f32",vec3h:"f32",vec4h:"f32",mat2x2f:"f32",mat3x3f:"f32",mat4x4f:"f32"},Nt={u32:"setUint32",i32:"setInt32",f32:"setFloat32"};function zt(e,t,r){if(_(e)||Z(e)){let o=at(e),i=Object.entries(o).sort((l,u)=>l[1].offset-u[1].offset),s="";for(let[l,u]of i){let d=e.propTypes[l];d&&(s+=zt(d,`(${t} + ${u.offset})`,`${r}.${l}`))}return s}if(X(e)||Ze(e)){let o=e,i=$(h(o.elementType),A(o.elementType)),s="";return s+=`for (let i = 0; i < ${o.elementCount}; i++) {
19
- `,s+=zt(o.elementType,`(${t} + i * ${i})`,`${r}[i]`),s+=`}
20
- `,s}if(Ar(e)){let o=Mt[e.type],i="",s=Nt[o],l=["x","y","z","w"],u=vr(e)?2:Ur(e)?3:4;for(let d=0;d<u;d++)i+=`output.${s}((${t} + ${d*4}), ${r}.${l[d]}, littleEndian);
21
- `;return i}if(Br(e)){let o=Mt[e.type],i=Nt[o],s=Ir(e)?2:Rr(e)?3:4,l=s*s,u=$(s*4,8),d="";for(let f=0;f<l;f++){let g=Math.floor(f/s),w=f%s,c=g*u+w*4;d+=`output.${i}((${t} + ${c}), ${r}.columns[${g}].${["x","y","z","w"][w]}, littleEndian);
22
- `}return d}let n=e;for(;_r(n)||we(n);)n=n.inner;let a=Mt[n.type];return`output.${Nt[a]}(${t}, ${r}, littleEndian);
23
- `}function it(e){if(Wt.has(e))return Wt.get(e);let t=zt(e,"offset","value"),r=new Function("output","offset","value","littleEndian=true",t);return Wt.set(e,r),r}var V={bool(e,t,r){e.writeBool(r)},f32(e,t,r){e.writeFloat32(r)},f16(e,t,r){e.writeFloat16(r)},i32(e,t,r){e.writeInt32(r)},u32(e,t,r){e.writeUint32(r)},vec2f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},vec2h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},vec2i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},vec2u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},vec3f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},vec3h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z)},vec3i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},vec3u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},vec4f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},vec4h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},vec4i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},vec4u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},mat2x2f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat3x3f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat4x4f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},struct(e,t,r){let n=A(t);D(e,n);for(let[a,o]of Object.entries(t.propTypes))D(e,A(o)),ae(e,o,r[a]);D(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=A(t);D(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)D(e,n),ae(e,t.elementType,r[o]);e.seekTo(a+h(t))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){var n;(n=V[t.inner.type])==null||n.call(V,e,t,r)},decorated(e,t,r){var o,i;let n=W(t);D(e,n);let a=e.currentByteOffset;(i=V[(o=t.inner)==null?void 0:o.type])==null||i.call(V,e,t.inner,r),e.seekTo(a+h(t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){var o,i;let n=A(t);D(e,n);let a=e.currentByteOffset;for(let s=0;s<Math.min(t.elementCount,r.length);s++)D(e,n),(i=V[(o=t.elementType)==null?void 0:o.type])==null||i.call(V,e,t.elementType,r[s]);e.seekTo(a+h(t))},unstruct(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=V[o.type])==null||n.call(V,e,o,r[a])},"loose-decorated"(e,t,r){var i;let n=W(t);D(e,n);let a=e.currentByteOffset,o=V[(i=t.inner)==null?void 0:i.type];return o==null||o(e,t.inner,r),e.seekTo(a+h(t)),r}};function ae(e,t,r){let n=V[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var fe={bool(e){return e.readBool()},f32(e){return e.readFloat32()},f16(e){return e.readFloat16()},i32(e){return e.readInt32()},u32(e){return e.readUint32()},vec2f(e){return G(e.readFloat32(),e.readFloat32())},vec3f(e){return pe(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return S(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return Be(e.readFloat16(),e.readFloat16())},vec3h(e){return _e(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return Pe(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return H(e.readInt32(),e.readInt32())},vec3i(e){return xe(e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return C(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return Y(e.readUint32(),e.readUint32())},vec3u(e){return he(e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return E(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return qe(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return Je(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return He(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},struct(e,t){let r=A(t);D(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))D(e,A(o)),n[a]=O(e,o);return D(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=A(t),n=[];for(let a=0;a<t.elementCount;a++){D(e,r);let o=t.elementType,i=O(e,o);n.push(i)}return D(e,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return O(e,t.inner)},decorated(e,t){let r=W(t);D(e,r);let n=e.currentByteOffset,a=O(e,t.inner);return e.seekTo(n+h(t)),a},uint8:e=>e.readUint8(),uint8x2:e=>Y(e.readUint8(),e.readUint8()),uint8x4:e=>E(e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>H(e.readInt8(),e.readInt8()),sint8x4:e=>C(e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>G(e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>S(e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>G((e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>S((e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>Y(e.readUint16(),e.readUint16()),uint16x4:e=>E(e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>H(e.readInt16(),e.readInt16()),sint16x4:e=>C(e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>G(e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>S(e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>G(fe.snorm16(e),fe.snorm16(e)),snorm16x4:e=>S(fe.snorm16(e),fe.snorm16(e),fe.snorm16(e),fe.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>G(e.readFloat16(),e.readFloat16()),float16x4:e=>S(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>G(e.readFloat32(),e.readFloat32()),float32x3:e=>pe(e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>S(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>Y(e.readUint32(),e.readUint32()),uint32x3:e=>he(e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>E(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>H(e.readInt32(),e.readInt32()),sint32x3:e=>xe(e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>C(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32()),"unorm10-10-10-2"(e){let t=e.readUint32(),r=(t>>22)/1023,n=(t>>12&1023)/1023,a=(t>>2&1023)/1023,o=(t&3)/3;return S(r,n,a,o)},"unorm8x4-bgra"(e){let t=e.readByte()/255,r=e.readByte()/255,n=e.readByte()/255,a=e.readByte()/255;return S(n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=O(e,a);return r},disarray(e,t){let r=A(t),n=[];for(let a=0;a<t.elementCount;a++)D(e,r),n.push(O(e,t.elementType));return D(e,r),n},"loose-decorated"(e,t){D(e,W(t));let r=e.currentByteOffset,n=O(e,t.inner);return e.seekTo(r+h(t)),n}};function O(e,t){let r=fe[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}import{BufferWriter as da}from"typed-binary";function ln(e,t){var u;let r=h(e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new da(n),o=[];function i(d,f,g,w){var c;if(f!=null){if(_(d)||Z(d)){let T=at(d);for(let[F,y]of Object.entries(T)){let x=d.propTypes[F];if(!x)continue;let ce=f[F];ce!==void 0&&i(x,ce,g+y.offset,(c=y.padding)!=null?c:w)}return}if(X(d)||Ze(d)){let T=d,F=$(h(T.elementType),A(T.elementType));if(!Array.isArray(f))throw new Error("Partial value for array must be an array");let y=f;y.sort((x,ce)=>x.idx-ce.idx);for(let{idx:x,value:ce}of y)i(T.elementType,ce,g+x*F,F-h(T.elementType))}else{let T=h(d);a.seekTo(g),ae(a,d,f),o.push({start:g,end:g+T,padding:w})}}}if(i(e,t,0),o.length===0)return[];let s=[],l=o[0];for(let d=1;d<o.length;d++){let f=o[d];if(!f||!l)throw new Error("Internal error: missing segment");f.start===l.end+((u=l.padding)!=null?u:0)?(l.end=f.end,l.padding=f.padding):(s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),l=f)}if(!l)throw new Error("Internal error: missing segment");return s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),s}function ge(e){return!!(e!=null&&e.usableAsStorage)}var $e=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function st(e){return!!e.usableAsUniform}var cn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},gn;gn=b;var Oe=class{constructor(t,r){this.usage=t;this.buffer=r;p(this,"~repr");p(this,"resourceType","buffer-usage");p(this,gn);this[b]={dataType:r.dataType}}get label(){return this.buffer.label}$name(t){return this.buffer.$name(t),this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),o=cn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${t.resolve(this.buffer.dataType)};`),r}write(t){this.buffer.write(t)}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!se())throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`},[b]:{dataType:this.buffer.dataType}},M)}},Tn;Tn=b;var ke=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;p(this,"~repr");p(this,"resourceType","buffer-usage");p(this,Tn);this[b]={dataType:r}}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=cn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${t.resolve(this.dataType)};`),r}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!se())throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`},[b]:{dataType:this.dataType}},M)}},dn=new WeakMap;function jt(e){if(!ge(e))throw new Error(`Cannot pass ${e} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=dn.get(e);return t||(t=new Oe("mutable",e),dn.set(e,t)),t}var mn=new WeakMap;function Kt(e){if(!ge(e))throw new Error(`Cannot pass ${e} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=mn.get(e);return t||(t=new Oe("readonly",e),mn.set(e,t)),t}var fn=new WeakMap;function qt(e){if(!st(e))throw new Error(`Cannot pass ${e} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let t=fn.get(e);return t||(t=new Oe("uniform",e),fn.set(e,t)),t}var Yt={uniform:qt,mutable:jt,readonly:Kt};function xn(e,t,r){return Q(t)?new ut(e,t,r):new ut(e,t,r,["storage","uniform"])}function oe(e){return e.resourceType==="buffer"}function fa(e){return!!e.usableAsVertex}var yn=ma(),ut=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;p(this,"resourceType","buffer");p(this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);p(this,"_buffer",null);p(this,"_ownBuffer");p(this,"_destroyed",!1);p(this,"_hostBuffer");p(this,"_label");p(this,"initial");p(this,"usableAsUniform",!1);p(this,"usableAsStorage",!1);p(this,"usableAsVertex",!1);Lr(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}get label(){return this._label}get buffer(){var r;let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:h(this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:(r=this.label)!=null?r:"<unnamed>"}),this.initial)){let n=new Ht(this._buffer.getMappedRange());ae(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}compileWriter(){if(ot)it(this.dataType);else throw new Error("This environment does not allow eval")}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let o=r.getMappedRange();if(ot){it(this.dataType)(new DataView(o),0,t,yn==="little");return}ae(new Ht(o),this.dataType,t);return}let a=h(this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),ot?it(this.dataType)(new DataView(this._hostBuffer),0,t,yn==="little"):ae(new Ht(this._hostBuffer),this.dataType,t),n.queue.writeBuffer(r,0,this._hostBuffer,0,a)}writePartial(t){let r=this.buffer,n=this._group.device,a=ln(this.dataType,t);if(r.mapState==="mapped"){let o=r.getMappedRange(),i=new Uint8Array(o);for(let s of a)i.set(s.data,s.data.byteOffset)}else for(let o of a)n.queue.writeBuffer(r,o.data.byteOffset,o.data,0,o.data.byteLength)}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=h(this.dataType);this._group.commandEncoder.copyBufferToBuffer(t.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let t=this.buffer,r=this._group.device;if(t.mapState==="mapped"){let i=t.getMappedRange();return O(new Jt(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),s=O(new Jt(i),this.dataType);return t.unmap(),s}let n=r.createBuffer({size:h(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,h(this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,h(this.dataType));let o=O(new Jt(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(t){var r;return(r=Yt[t])==null?void 0:r.call(Yt,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,this._ownBuffer&&((t=this._buffer)==null||t.destroy()))}toString(){var t;return`buffer:${(t=this._label)!=null?t:"<unnamed>"}`}};function hn(e){return new Qt(e)}function bn(e){return new Xt(e)}function We(e){return(e==null?void 0:e.resourceType)==="sampler"}function Me(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var pt=class{constructor(t){this._membership=t;p(this,"resourceType","sampler")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},lt=class{constructor(t){this._membership=t;p(this,"resourceType","sampler-comparison")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Qt=class{constructor(t){this._props=t;p(this,"resourceType","sampler");p(this,"_label");p(this,"_filtering");p(this,"_sampler",null);this._filtering=t.minFilter==="linear"||t.magFilter==="linear"||t.mipmapFilter==="linear"}unwrap(t){var r;return this._sampler||(this._sampler=t.device.createSampler(L(R({},this._props),{label:(r=this._label)!=null?r:"<unnamed>"}))),this._sampler}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),{group:n,binding:a}=t.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Xt=class{constructor(t){this._props=t;p(this,"resourceType","sampler-comparison");p(this,"_label");p(this,"_sampler",null)}unwrap(t){var r;return this._sampler||(this._sampler=t.device.createSampler(L(R({},this._props),{label:(r=this._label)!=null?r:"<unnamed>"}))),this._sampler}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({sampler:"comparison"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var dt=class{constructor(t){this._membership=t;p(this,"resourceType","external-texture")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var wn={r8unorm:m,r8snorm:m,r8uint:U,r8sint:B,r16uint:U,r16sint:B,r16float:m,rg8unorm:m,rg8snorm:m,rg8uint:U,rg8sint:B,r32uint:U,r32sint:B,r32float:m,rg16uint:U,rg16sint:B,rg16float:m,rgba8unorm:m,"rgba8unorm-srgb":m,rgba8snorm:m,rgba8uint:U,rgba8sint:B,bgra8unorm:m,"bgra8unorm-srgb":m,rgb9e5ufloat:m,rgb10a2uint:U,rgb10a2unorm:m,rg11b10ufloat:m,rg32uint:U,rg32sint:B,rg32float:m,rgba16uint:U,rgba16sint:B,rgba16float:m,rgba32uint:U,rgba32sint:B,rgba32float:m,stencil8:m,depth16unorm:m,depth24plus:m,"depth24plus-stencil8":m,depth32float:m,"depth32float-stencil8":m,"bc1-rgba-unorm":m,"bc1-rgba-unorm-srgb":m,"bc2-rgba-unorm":m,"bc2-rgba-unorm-srgb":m,"bc3-rgba-unorm":m,"bc3-rgba-unorm-srgb":m,"bc4-r-unorm":m,"bc4-r-snorm":m,"bc5-rg-unorm":m,"bc5-rg-snorm":m,"bc6h-rgb-ufloat":m,"bc6h-rgb-float":m,"bc7-rgba-unorm":m,"bc7-rgba-unorm-srgb":m,"etc2-rgb8unorm":m,"etc2-rgb8unorm-srgb":m,"etc2-rgb8a1unorm":m,"etc2-rgb8a1unorm-srgb":m,"etc2-rgba8unorm":m,"etc2-rgba8unorm-srgb":m,"eac-r11unorm":m,"eac-r11snorm":m,"eac-rg11unorm":m,"eac-rg11snorm":m,"astc-4x4-unorm":m,"astc-4x4-unorm-srgb":m,"astc-5x4-unorm":m,"astc-5x4-unorm-srgb":m,"astc-5x5-unorm":m,"astc-5x5-unorm-srgb":m,"astc-6x5-unorm":m,"astc-6x5-unorm-srgb":m,"astc-6x6-unorm":m,"astc-6x6-unorm-srgb":m,"astc-8x5-unorm":m,"astc-8x5-unorm-srgb":m,"astc-8x6-unorm":m,"astc-8x6-unorm-srgb":m,"astc-8x8-unorm":m,"astc-8x8-unorm-srgb":m,"astc-10x5-unorm":m,"astc-10x5-unorm-srgb":m,"astc-10x6-unorm":m,"astc-10x6-unorm-srgb":m,"astc-10x8-unorm":m,"astc-10x8-unorm-srgb":m,"astc-10x10-unorm":m,"astc-10x10-unorm-srgb":m,"astc-12x10-unorm":m,"astc-12x10-unorm-srgb":m,"astc-12x12-unorm":m,"astc-12x12-unorm-srgb":m},Ne={rgba8unorm:S,rgba8snorm:S,rgba8uint:E,rgba8sint:C,rgba16uint:E,rgba16sint:C,rgba16float:S,r32uint:E,r32sint:C,r32float:S,rg32uint:E,rg32sint:C,rg32float:S,rgba32uint:E,rgba32sint:C,rgba32float:S,bgra8unorm:S},Sn={f32:"float",u32:"uint",i32:"sint"},Dn={float:m,"unfilterable-float":m,uint:U,sint:B,depth:m};function Fn(e,t){return new Zt(e,t)}function J(e){return(e==null?void 0:e.resourceType)==="texture"}function ze(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function je(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var vn={mutable:"read_write",readonly:"read",writeonly:"write"},Zt=class{constructor(t,r){this.props=t;this._branch=r;p(this,"resourceType","texture");p(this,"usableAsSampled",!1);p(this,"usableAsStorage",!1);p(this,"usableAsRender",!1);p(this,"_destroyed",!1);p(this,"_label");p(this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);p(this,"_texture",null)}get label(){return this._label}$name(t){return this._label=t,this}unwrap(){var t,r,n,a,o;if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:(t=this._label)!=null?t:"<unnamed>",format:this.props.format,size:this.props.size,usage:this._flags,dimension:(r=this.props.dimension)!=null?r:"2d",viewFormats:(n=this.props.viewFormats)!=null?n:[],mipLevelCount:(a=this.props.mipLevelCount)!=null?a:1,sampleCount:(o=this.props.sampleCount)!=null?o:1})),this._texture}$usage(...t){let r=t.includes("storage"),n=t.includes("sampled"),a=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||(this.usableAsStorage=r),this.usableAsSampled||(this.usableAsSampled=n),this.usableAsRender||(this.usableAsRender=a),this}createView(t,r){if(t==="sampled")return this._asSampled(r);let n=r;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,r){var o;if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=(o=t==null?void 0:t.format)!=null?o:this.props.format,a=Ne[n];return Ae(!!a,`Unsupported storage texture format: ${n}`),new er(t!=null?t:{},r,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){var a;if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=(a=t==null?void 0:t.format)!=null?a:this.props.format;if(!Ne[r])throw new Error(`Unsupported storage texture format: ${r}`);return new tr(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},gt={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},er=class{constructor(t,r,n){this.access=r;this._texture=n;p(this,"resourceType","texture-storage-view");p(this,"texelDataType");p(this,"dimension");p(this,"_view");p(this,"_format");var a,o,i;this.dimension=(o=(a=t==null?void 0:t.dimension)!=null?a:n.props.dimension)!=null?o:"2d",this._format=(i=t==null?void 0:t.format)!=null?i:n.props.format,this.texelDataType=Ne[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),o=`texture_storage_${gt[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${vn[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},mt=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;p(this,"resourceType","texture-storage-view");p(this,"texelDataType");this.texelDataType=Ne[this._format]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=`texture_storage_${gt[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${vn[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},tr=class{constructor(t,r){this._props=t;this._texture=r;p(this,"resourceType","texture-sampled-view");p(this,"channelDataType");p(this,"dimension");p(this,"_format");p(this,"_view");var n,a,o;this.dimension=(a=(n=t==null?void 0:t.dimension)!=null?n:r.props.dimension)!=null?a:"2d",this._format=(o=t==null?void 0:t.format)!=null?o:r.props.format,this.channelDataType=wn[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView(R({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`},this._props))),this._view}"~resolve"(t){var s;let r=t.names.makeUnique(this.label),n=((s=this._texture.props.sampleCount)!=null?s:1)>1,{group:a,binding:o}=t.allocateFixedEntry({texture:Sn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},ft=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;p(this,"resourceType","texture-sampled-view");p(this,"channelDataType");this.channelDataType=Dn[t]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=this._multisampled?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};function rr(e){return!!(e!=null&&e.usableAsSampled)}function ga(e){return!!(e!=null&&e.usableAsRender)}var Tt=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function ct(e){return new ar(e)}function yt(e){return!!e&&e.resourceType==="bind-group-layout"}function or(e){return!!e&&e.resourceType==="bind-group"}var nr=class e extends Error{constructor(t,r){super(`Bind group '${t!=null?t:"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},Un=["compute"],ve=["compute","vertex","fragment"],ar=class{constructor(t){this.entries=t;p(this,"_label");p(this,"_index");p(this,"resourceType","bind-group-layout");p(this,"bound",{});var n,a,o,i,s;let r=0;for(let[l,u]of Object.entries(t)){if(u===null){r++;continue}let d={idx:r,key:l,layout:this};if("uniform"in u&&(this.bound[l]=new ke("uniform",u.uniform,d)),"storage"in u){let f="type"in u.storage?u.storage:u.storage(0);this.bound[l]=new ke((n=u.access)!=null?n:"readonly",f,d)}"texture"in u&&(this.bound[l]=new ft(u.texture,(a=u.viewDimension)!=null?a:"2d",(o=u.multisampled)!=null?o:!1,d)),"storageTexture"in u&&(this.bound[l]=new mt(u.storageTexture,(i=u.viewDimension)!=null?i:"2d",(s=u.access)!=null?s:"writeonly",d)),"externalTexture"in u&&(this.bound[l]=new dt(d)),"sampler"in u&&(u.sampler==="comparison"?this.bound[l]=new lt(d):this.bound[l]=new pt(d)),r++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var n;return t.device.createBindGroupLayout({label:(n=this.label)!=null?n:"<unnamed>",entries:Object.values(this.entries).map((a,o)=>{var l,u,d,f;if(a===null)return null;let i=a.visibility,s={binding:o,visibility:0};if("uniform"in a)i=i!=null?i:ve,s.buffer={type:"uniform"};else if("storage"in a)i=i!=null?i:a.access==="mutable"?Un:ve,s.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)i=i!=null?i:ve,s.sampler={type:a.sampler};else if("texture"in a)i=i!=null?i:ve,s.texture={sampleType:a.texture,viewDimension:(l=a.viewDimension)!=null?l:"2d",multisampled:(u=a.multisampled)!=null?u:!1};else if("storageTexture"in a){let g=(d=a.access)!=null?d:"writeonly";i=i!=null?i:g==="readonly"?ve:Un,s.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[g],viewDimension:(f=a.viewDimension)!=null?f:"2d"}}else"externalTexture"in a&&(i=i!=null?i:ve,s.externalTexture={});return i!=null&&i.includes("compute")&&(s.visibility|=GPUShaderStage.COMPUTE),i!=null&&i.includes("vertex")&&(s.visibility|=GPUShaderStage.VERTEX),i!=null&&i.includes("fragment")&&(s.visibility|=GPUShaderStage.FRAGMENT),s}).filter(a=>a!==null)})}populate(t){return new Te(this,t)}},Te=class{constructor(t,r){this.layout=t;this.entries=r;p(this,"resourceType","bind-group");for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new nr(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],i)=>{var l;if(o===null)return null;let s=this.entries[a];if(s===void 0)throw new Error(`'${a}' is a resource required to populate bind group layout '${(l=this.layout.label)!=null?l:"<unnamed>"}'.`);if("uniform"in o){let u;if(oe(s)){if(!st(s))throw new vt(s);u={buffer:t.unwrap(s)}}else u={buffer:s};return{binding:i,resource:u}}if("storage"in o){let u;if(oe(s)){if(!ge(s))throw new $e(s);u={buffer:t.unwrap(s)}}else u={buffer:s};return{binding:i,resource:u}}if("texture"in o){let u;if(J(s)){if(!rr(s))throw new Tt(s);u=t.unwrap(s.createView("sampled"))}else je(s)?u=t.unwrap(s):u=s;return{binding:i,resource:u}}if("storageTexture"in o){let u;if(J(s)){if(!ge(s))throw new $e(s);o.access==="readonly"?u=t.unwrap(s.createView("readonly")):o.access==="mutable"?u=t.unwrap(s.createView("mutable")):u=t.unwrap(s.createView("writeonly"))}else ze(s)?u=t.unwrap(s):u=s;return{binding:i,resource:u}}if("sampler"in o)return We(s)||Me(s)?{binding:i,resource:t.unwrap(s)}:{binding:i,resource:s};if("externalTexture"in o)return{binding:i,resource:s};throw new Error(`Malformed bind group entry: ${s} (${JSON.stringify(s)})`)}).filter(a=>a!==null)})}};var In="#CATCHALL#",sr=class{constructor(){p(this,"_stack",[]);p(this,"_itemDepth",0)}get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}popItem(){this.pop("item")}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}popSlotBindings(){this.pop("slotBinding")}pushFunctionScope(t,r,n){this._stack.push({type:"functionScope",args:t,returnType:r,externalMap:n})}popFunctionScope(){this.pop("functionScope")}pushBlockScope(){this._stack.push({type:"blockScope",declarations:new Map})}popBlockScope(){this.pop("blockScope")}pop(t){let r=this._stack[this._stack.length-1];if(!r||t&&r.type!==t)throw new Error(`Internal error, expected a ${t} layer to be on top.`);this._stack.pop(),t==="item"&&this._itemDepth--}readSlot(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="item")n.usedSlots.add(t);else if((n==null?void 0:n.type)==="slotBinding"){let a=n.bindingMap.get(t);if(a!==void 0)return a}else if(!((n==null?void 0:n.type)==="functionScope"||(n==null?void 0:n.type)==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="functionScope"){let a=n.args.find(i=>i.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:q(o)?Se(o):P}:void 0}if((n==null?void 0:n.type)==="blockScope"){let a=n.declarations.get(t);if(a!==void 0)return{value:t,dataType:a}}}}defineBlockVariable(t,r){for(let n=this._stack.length-1;n>=0;--n){let a=this._stack[n];if((a==null?void 0:a.type)==="blockScope")return a.declarations.set(t,r),{value:t,dataType:r}}throw new Error("No block scope found to define a variable in.")}},xt=[""," "," "," "," "," "," "," "," "],ir=xt.length-1,ur=class{constructor(){p(this,"identLevel",0)}get pre(){var t;return(t=xt[this.identLevel])!=null?t:xt[ir].repeat(this.identLevel/ir)+xt[this.identLevel%ir]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},An;An=b;var pr=class{constructor(t){p(this,"_memoizedResolves",new WeakMap);p(this,"_memoizedDerived",new WeakMap);p(this,"_indentController",new ur);p(this,"_jitTranspiler");p(this,"_itemStateStack",new sr);p(this,"_declarations",[]);p(this,An,{itemStateStack:this._itemStateStack});p(this,"bindGroupLayoutsToPlaceholderMap",new Map);p(this,"_nextFreeLayoutPlaceholderIdx",0);p(this,"fixedBindings",[]);p(this,"callStack",[]);p(this,"names");this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){let r=this._itemStateStack.getResourceById(t);return r===void 0?null:r}defineVariable(t,r){return this._itemStateStack.defineBlockVariable(t,r)}pushBlockScope(){this._itemStateStack.pushBlockScope()}popBlockScope(){this._itemStateStack.popBlockScope()}transpileFn(t){if(!this._jitTranspiler)throw new Error("Tried to execute a tgpu.fn function without providing a JIT transpiler, or transpiling at build time.");return this._jitTranspiler.transpileFn(t)}fnToWgsl(t){this._itemStateStack.pushFunctionScope(t.args,t.returnType,t.externalMap);try{let r=kt(this,t.body),n=t.args.map(a=>`${a.value}: ${this.resolve(a.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${tt(t.returnType)} ${this.resolve(t.returnType)}`:`(${n})`,body:r}}finally{this._itemStateStack.popFunctionScope()}}addDeclaration(t){this._declarations.push(t)}allocateLayoutEntry(t){let r=this.bindGroupLayoutsToPlaceholderMap,n=r.get(t);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,r.set(t,n)),n}allocateFixedEntry(t,r){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:t,resource:r}),{group:In,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new Ft(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.popSlotBindings()}}unwrap(t){if(Rt(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(j(r))r=this.readSlot(r);else if(K(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([l,u])=>l.areEqual(this._itemStateStack.readSlot(l),u)))return i.result;At(Re.CPU);let a;try{a=t["~compute"]()}finally{It(Re.CPU)}let o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedDerived.set(t,r),a}catch(a){throw a instanceof ye?a.appendToTrace(t):new ye(a,[t])}finally{this._itemStateStack.popItem()}}_getOrInstantiate(t){var n;let r=(n=this._memoizedResolves.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([l,u])=>l.areEqual(this._itemStateStack.readSlot(l),u)))return i.result;let a;k(t)?a=$t(this,t):K(t)||j(t)?a=this.resolve(this.unwrap(t)):Pr(t)?a=t["~resolve"](this):a=this.resolveValue(t);let o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedResolves.set(t,r),a}catch(a){throw a instanceof ye?a.appendToTrace(t):new ye(a,[t])}finally{this._itemStateStack.popItem()}}resolve(t){if(Rt(t))return this.withSlots(t["~providing"].pairs,()=>this.resolve(t["~providing"].inner));if(t&&typeof t=="object"||typeof t=="function"){if(this._itemStateStack.itemDepth===0)try{At(Re.GPU);let r=Dr(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
16
+ ${i}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=n?U(e,n):void 0;if(!a||!n)throw new Error("Cannot create variable without an initial value.");Zn(e,r,a.dataType);let o=v(e,$t(e,r));if(typeof n=="object"&&"o"in n&&h(e.callStack[e.callStack.length-1])){let i=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}var ${o} = ${i}(${v(e,a)});`}return`${e.pre}var ${o} = ${v(e,a)};`}if("b"in t){e.pushBlockScope();try{return en(e,t)}finally{e.popBlockScope()}}if("j"in t){let[r,n,a,o]=t.j,i=r?ue(e,r):void 0,s=i?i.slice(0,-1):"",p=n?U(e,n):void 0,u=p?v(e,p):"",d=a?ue(e,a):void 0,m=d?d.slice(0,-1):"";e.indent();let T=ue(e,o);return e.dedent(),`${e.pre}for (${s}; ${u}; ${m})
17
+ ${T}`}if("w"in t){let[r,n]=t.w,a=v(e,U(e,r));e.indent();let o=ue(e,n);return e.dedent(),`${e.pre}while (${a})
18
+ ${o}`}return"k"in t?`${e.pre}continue;`:"d"in t?`${e.pre}break;`:`${e.pre}${v(e,U(e,t))};`}function Gt(e,t){return en(e,t)}import{BufferReader as Kt,BufferWriter as qt}from"typed-binary";import{getSystemEndianness as na}from"typed-binary";import{Measurer as ta}from"typed-binary";function ea(e,t){let r="size"in e?e.size:e.currentByteOffset,n=t-1,a=r&n;"skipBytes"in e?e.skipBytes(t-a&n):e.add(t-a&n)}var b=ea;var tn=new WeakMap;function Qe(e){let t=tn.get(e);if(t)return t;let r=new ta,n={},a;for(let o in e.propTypes){let i=e.propTypes[o];if(i===void 0)throw new Error(`Property ${o} is undefined in struct`);let s=r.size;b(r,Y(e)?G(i):D(i)),a&&(a.padding=r.size-s);let p=c(i);n[o]={offset:r.size,size:p},a=n[o],r.add(p)}return a&&(a.padding=L(c(e),D(e))-r.size),tn.set(e,n),n}var Ze=(()=>{try{return new Function("return true"),!0}catch{return!1}})(),kt=new WeakMap,Wt={u32:"u32",vec2u:"u32",vec3u:"u32",vec4u:"u32",i32:"i32",vec2i:"i32",vec3i:"i32",vec4i:"i32",f32:"f32",vec2f:"f32",vec3f:"f32",vec4f:"f32",vec2h:"f32",vec3h:"f32",vec4h:"f32",mat2x2f:"f32",mat3x3f:"f32",mat4x4f:"f32"},Mt={u32:"setUint32",i32:"setInt32",f32:"setFloat32"};function Xe(e,t,r){if(Br(e)||ce(e))return Xe(e.inner,t,r);if(h(e)||Y(e)){let a=Qe(e),o=Object.entries(a).sort((s,p)=>s[1].offset-p[1].offset),i="";for(let[s,p]of o){let u=e.propTypes[s];u&&(i+=Xe(u,`(${t} + ${p.offset})`,`${r}.${s}`))}return i}if(O(e)||Je(e)){let a=e,o=L(c(a.elementType),D(a.elementType)),i="";return i+=`for (let i = 0; i < ${a.elementCount}; i++) {
19
+ `,i+=Xe(a.elementType,`(${t} + i * ${o})`,`${r}[i]`),i+=`}
20
+ `,i}if(Ur(e)){let a=Wt[e.type],o="",i=Mt[a],s=["x","y","z","w"],p=Fr(e)?2:Dr(e)?3:4;for(let u=0;u<p;u++)o+=`output.${i}((${t} + ${u*4}), ${r}.${s[u]}, littleEndian);
21
+ `;return o}if(Rr(e)){let a=Wt[e.type],o=Mt[a],i=Ar(e)?2:Ir(e)?3:4,s=i*i,p=L(i*4,8),u="";for(let d=0;d<s;d++){let m=Math.floor(d/i),T=d%i,f=m*p+T*4;u+=`output.${o}((${t} + ${f}), ${r}.columns[${m}].${["x","y","z","w"][T]}, littleEndian);
22
+ `}return u}let n=Wt[e.type];return`output.${Mt[n]}(${t}, ${r}, littleEndian);
23
+ `}function et(e){if(kt.has(e))return kt.get(e);let t=Xe(e,"offset","value"),r=new Function("output","offset","value","littleEndian=true",t);return kt.set(e,r),r}var be={bool(){throw new Error("Booleans are not host-shareable")},f32(e,t,r){e.writeFloat32(r)},f16(e,t,r){e.writeFloat16(r)},i32(e,t,r){e.writeInt32(r)},u32(e,t,r){e.writeUint32(r)},vec2f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},vec2h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},vec2i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},vec2u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},vec3f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},vec3h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z)},vec3i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},vec3u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},vec4f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},vec4h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},vec4i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},vec4u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat3x3f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat4x4f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},struct(e,t,r){let n=D(t);b(e,n);for(let[a,o]of Object.entries(t.propTypes))b(e,D(o)),X(e,o,r[a]);b(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=D(t);b(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)b(e,n),X(e,t.elementType,r[o]);e.seekTo(a+c(t))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){be[t.inner.type]?.(e,t,r)},decorated(e,t,r){let n=G(t);b(e,n);let a=e.currentByteOffset;be[t.inner?.type]?.(e,t.inner,r),e.seekTo(a+c(t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){let n=D(t);b(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)b(e,n),be[t.elementType?.type]?.(e,t.elementType,r[o]);e.seekTo(a+c(t))},unstruct(e,t,r){for(let[n,a]of Object.entries(t.propTypes))be[a.type]?.(e,a,r[n])},"loose-decorated"(e,t,r){let n=G(t);b(e,n);let a=e.currentByteOffset,o=be[t.inner?.type];return o?.(e,t.inner,r),e.seekTo(a+c(t)),r}};function X(e,t,r){let n=be[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var pe={bool(){throw new Error("Booleans are not host-shareable")},f32(e){return e.readFloat32()},f16(e){return e.readFloat16()},i32(e){return e.readInt32()},u32(e){return e.readUint32()},vec2f(e){return P(e.readFloat32(),e.readFloat32())},vec3f(e){return ie(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return x(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return Ae(e.readFloat16(),e.readFloat16())},vec3h(e){return Ie(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return Re(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return H(e.readInt32(),e.readInt32())},vec3i(e){return ge(e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return B(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return J(e.readUint32(),e.readUint32())},vec3u(e){return fe(e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(e){return je(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return ze(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return Ke(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},struct(e,t){let r=D(t);b(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))b(e,D(o)),n[a]=C(e,o);return b(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=D(t),n=[];for(let a=0;a<t.elementCount;a++){b(e,r);let o=t.elementType,i=C(e,o);n.push(i)}return b(e,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return C(e,t.inner)},decorated(e,t){let r=G(t);b(e,r);let n=e.currentByteOffset,a=C(e,t.inner);return e.seekTo(n+c(t)),a},uint8:e=>e.readUint8(),uint8x2:e=>J(e.readUint8(),e.readUint8()),uint8x4:e=>_(e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>H(e.readInt8(),e.readInt8()),sint8x4:e=>B(e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>P(e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>x(e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>P((e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>x((e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>J(e.readUint16(),e.readUint16()),uint16x4:e=>_(e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>H(e.readInt16(),e.readInt16()),sint16x4:e=>B(e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>P(e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>x(e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>P(pe.snorm16(e),pe.snorm16(e)),snorm16x4:e=>x(pe.snorm16(e),pe.snorm16(e),pe.snorm16(e),pe.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>P(e.readFloat16(),e.readFloat16()),float16x4:e=>x(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>P(e.readFloat32(),e.readFloat32()),float32x3:e=>ie(e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>x(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>J(e.readUint32(),e.readUint32()),uint32x3:e=>fe(e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>H(e.readInt32(),e.readInt32()),sint32x3:e=>ge(e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>B(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32()),"unorm10-10-10-2"(e){let t=e.readUint32(),r=(t>>22)/1023,n=(t>>12&1023)/1023,a=(t>>2&1023)/1023,o=(t&3)/3;return x(r,n,a,o)},"unorm8x4-bgra"(e){let t=e.readByte()/255,r=e.readByte()/255,n=e.readByte()/255,a=e.readByte()/255;return x(n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=C(e,a);return r},disarray(e,t){let r=D(t),n=[];for(let a=0;a<t.elementCount;a++)b(e,r),n.push(C(e,t.elementType));return b(e,r),n},"loose-decorated"(e,t){b(e,G(t));let r=e.currentByteOffset,n=C(e,t.inner);return e.seekTo(r+c(t)),n}};function C(e,t){let r=pe[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}import{BufferWriter as ra}from"typed-binary";function rn(e,t){let r=c(e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new ra(n),o=[];function i(u,d,m,T){if(d!=null){if(h(u)||Y(u)){let f=Qe(u);for(let[g,F]of Object.entries(f)){let w=u.propTypes[g];if(!w)continue;let A=d[g];A!==void 0&&i(w,A,m+F.offset,F.padding??T)}return}if(O(u)||Je(u)){let f=u,g=L(c(f.elementType),D(f.elementType));if(!Array.isArray(d))throw new Error("Partial value for array must be an array");let F=d;F.sort((w,A)=>w.idx-A.idx);for(let{idx:w,value:A}of F)i(f.elementType,A,m+w*g,g-c(f.elementType))}else{let f=c(u);a.seekTo(m),X(a,u,d),o.push({start:m,end:m+f,padding:T})}}}if(i(e,t,0),o.length===0)return[];let s=[],p=o[0];for(let u=1;u<o.length;u++){let d=o[u];if(!d||!p)throw new Error("Internal error: missing segment");d.start===p.end+(p.padding??0)?(p.end=d.end,p.padding=d.padding):(s.push({data:new Uint8Array(n,p.start,p.end-p.start)}),p=d)}if(!p)throw new Error("Internal error: missing segment");return s.push({data:new Uint8Array(n,p.start,p.end-p.start)}),s}function le(e){return!!e?.usableAsStorage}var Ee=class e extends Error{constructor(t){super(`Resource '${t.label??"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function tt(e){return!!e.usableAsUniform}var sn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Ve=class{constructor(t,r){this.usage=t;this.buffer=r;this[y]={dataType:r.dataType}}resourceType="buffer-usage";[y];get label(){return this.buffer.label}$name(t){return this.buffer.$name(t),this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),o=sn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${t.resolve(this.buffer.dataType)};`),r}write(t){this.buffer.write(t)}toString(){return`${this.usage}:${this.label??"<unnamed>"}`}get value(){if(!ae())throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.buffer.dataType}},k)}},Oe=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;this[y]={dataType:r}}resourceType="buffer-usage";[y];get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=sn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${t.resolve(this.dataType)};`),r}toString(){return`${this.usage}:${this.label??"<unnamed>"}`}get value(){if(!ae())throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.dataType}},k)}},nn=new WeakMap;function Nt(e){if(!le(e))throw new Error(`Cannot pass ${e} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=nn.get(e);return t||(t=new Ve("mutable",e),nn.set(e,t)),t}var an=new WeakMap;function jt(e){if(!le(e))throw new Error(`Cannot pass ${e} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=an.get(e);return t||(t=new Ve("readonly",e),an.set(e,t)),t}var on=new WeakMap;function zt(e){if(!tt(e))throw new Error(`Cannot pass ${e} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let t=on.get(e);return t||(t=new Ve("uniform",e),on.set(e,t)),t}var aa={uniform:zt,mutable:Nt,readonly:jt};function pn(e,t,r){return V(t)?new rt(e,t,r):new rt(e,t,r,["storage","uniform"])}function Z(e){return e.resourceType==="buffer"}function oa(e){return!!e.usableAsVertex}var un=na(),rt=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;Pr(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}resourceType="buffer";flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC;_buffer=null;_ownBuffer;_destroyed=!1;_hostBuffer;_label;initial;usableAsUniform=!1;usableAsStorage=!1;usableAsVertex=!1;get label(){return this._label}get buffer(){let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:c(this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:this.label??"<unnamed>"}),this.initial)){let r=new qt(this._buffer.getMappedRange());X(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){for(let r of t){if(this._disallowedUsages?.includes(r))throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${r}`);this.flags|=r==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=r==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=r==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||r==="uniform",this.usableAsStorage=this.usableAsStorage||r==="storage",this.usableAsVertex=this.usableAsVertex||r==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}compileWriter(){if(Ze)et(this.dataType);else throw new Error("This environment does not allow eval")}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let o=r.getMappedRange();if(Ze){et(this.dataType)(new DataView(o),0,t,un==="little");return}X(new qt(o),this.dataType,t);return}let a=c(this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),Ze?et(this.dataType)(new DataView(this._hostBuffer),0,t,un==="little"):X(new qt(this._hostBuffer),this.dataType,t),n.queue.writeBuffer(r,0,this._hostBuffer,0,a)}writePartial(t){let r=this.buffer,n=this._group.device,a=rn(this.dataType,t);if(r.mapState==="mapped"){let o=r.getMappedRange(),i=new Uint8Array(o);for(let s of a)i.set(s.data,s.data.byteOffset)}else for(let o of a)n.queue.writeBuffer(r,o.data.byteOffset,o.data,0,o.data.byteLength)}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=c(this.dataType);this._group.commandEncoder.copyBufferToBuffer(t.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let t=this.buffer,r=this._group.device;if(t.mapState==="mapped"){let i=t.getMappedRange();return C(new Kt(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),s=C(new Kt(i),this.dataType);return t.unmap(),s}let n=r.createBuffer({size:c(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,c(this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,c(this.dataType));let o=C(new Kt(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(t){return aa[t]?.(this)}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&this._buffer?.destroy())}toString(){return`buffer:${this._label??"<unnamed>"}`}};function ln(e){return new Ht(e)}function dn(e){return new Jt(e)}function $e(e){return e?.resourceType==="sampler"}function Ge(e){return e?.resourceType==="sampler-comparison"}var nt=class{constructor(t){this._membership=t}resourceType="sampler";get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},at=class{constructor(t){this._membership=t}resourceType="sampler-comparison";get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},Ht=class{constructor(t){this._props=t;this._filtering=t.minFilter==="linear"||t.magFilter==="linear"||t.mipmapFilter==="linear"}resourceType="sampler";_label;_filtering;_sampler=null;unwrap(t){return this._sampler||(this._sampler=t.device.createSampler({...this._props,label:this._label??"<unnamed>"})),this._sampler}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),{group:n,binding:a}=t.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},Jt=class{constructor(t){this._props=t}resourceType="sampler-comparison";_label;_sampler=null;unwrap(t){return this._sampler||(this._sampler=t.device.createSampler({...this._props,label:this._label??"<unnamed>"})),this._sampler}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({sampler:"comparison"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}};var ot=class{constructor(t){this._membership=t}resourceType="external-texture";get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}};var mn={r8unorm:l,r8snorm:l,r8uint:S,r8sint:I,r16uint:S,r16sint:I,r16float:l,rg8unorm:l,rg8snorm:l,rg8uint:S,rg8sint:I,r32uint:S,r32sint:I,r32float:l,rg16uint:S,rg16sint:I,rg16float:l,rgba8unorm:l,"rgba8unorm-srgb":l,rgba8snorm:l,rgba8uint:S,rgba8sint:I,bgra8unorm:l,"bgra8unorm-srgb":l,rgb9e5ufloat:l,rgb10a2uint:S,rgb10a2unorm:l,rg11b10ufloat:l,rg32uint:S,rg32sint:I,rg32float:l,rgba16uint:S,rgba16sint:I,rgba16float:l,rgba32uint:S,rgba32sint:I,rgba32float:l,stencil8:l,depth16unorm:l,depth24plus:l,"depth24plus-stencil8":l,depth32float:l,"depth32float-stencil8":l,"bc1-rgba-unorm":l,"bc1-rgba-unorm-srgb":l,"bc2-rgba-unorm":l,"bc2-rgba-unorm-srgb":l,"bc3-rgba-unorm":l,"bc3-rgba-unorm-srgb":l,"bc4-r-unorm":l,"bc4-r-snorm":l,"bc5-rg-unorm":l,"bc5-rg-snorm":l,"bc6h-rgb-ufloat":l,"bc6h-rgb-float":l,"bc7-rgba-unorm":l,"bc7-rgba-unorm-srgb":l,"etc2-rgb8unorm":l,"etc2-rgb8unorm-srgb":l,"etc2-rgb8a1unorm":l,"etc2-rgb8a1unorm-srgb":l,"etc2-rgba8unorm":l,"etc2-rgba8unorm-srgb":l,"eac-r11unorm":l,"eac-r11snorm":l,"eac-rg11unorm":l,"eac-rg11snorm":l,"astc-4x4-unorm":l,"astc-4x4-unorm-srgb":l,"astc-5x4-unorm":l,"astc-5x4-unorm-srgb":l,"astc-5x5-unorm":l,"astc-5x5-unorm-srgb":l,"astc-6x5-unorm":l,"astc-6x5-unorm-srgb":l,"astc-6x6-unorm":l,"astc-6x6-unorm-srgb":l,"astc-8x5-unorm":l,"astc-8x5-unorm-srgb":l,"astc-8x6-unorm":l,"astc-8x6-unorm-srgb":l,"astc-8x8-unorm":l,"astc-8x8-unorm-srgb":l,"astc-10x5-unorm":l,"astc-10x5-unorm-srgb":l,"astc-10x6-unorm":l,"astc-10x6-unorm-srgb":l,"astc-10x8-unorm":l,"astc-10x8-unorm-srgb":l,"astc-10x10-unorm":l,"astc-10x10-unorm-srgb":l,"astc-12x10-unorm":l,"astc-12x10-unorm-srgb":l,"astc-12x12-unorm":l,"astc-12x12-unorm-srgb":l},ke={rgba8unorm:x,rgba8snorm:x,rgba8uint:_,rgba8sint:B,rgba16uint:_,rgba16sint:B,rgba16float:x,r32uint:_,r32sint:B,r32float:x,rg32uint:_,rg32sint:B,rg32float:x,rgba32uint:_,rgba32sint:B,rgba32float:x,bgra8unorm:x},gn={f32:"float",u32:"uint",i32:"sint"},fn={float:l,"unfilterable-float":l,uint:S,sint:I,depth:l};function Tn(e,t){return new Yt(e,t)}function q(e){return e?.resourceType==="texture"}function We(e){return e?.resourceType==="texture-storage-view"}function Me(e){return e?.resourceType==="texture-sampled-view"}var cn={mutable:"read_write",readonly:"read",writeonly:"write"},Yt=class{constructor(t,r){this.props=t;this._branch=r}resourceType="texture";usableAsSampled=!1;usableAsStorage=!1;usableAsRender=!1;_destroyed=!1;_label;_flags=GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;_texture=null;get label(){return this._label}$name(t){return this._label=t,this}unwrap(){if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:this._label??"<unnamed>",format:this.props.format,size:this.props.size,usage:this._flags,dimension:this.props.dimension??"2d",viewFormats:this.props.viewFormats??[],mipLevelCount:this.props.mipLevelCount??1,sampleCount:this.props.sampleCount??1})),this._texture}$usage(...t){let r=t.includes("storage"),n=t.includes("sampled"),a=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||=r,this.usableAsSampled||=n,this.usableAsRender||=a,this}createView(t,r){if(t==="sampled")return this._asSampled(r);let n=r;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,r){if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=t?.format??this.props.format,a=ke[n];return Fe(!!a,`Unsupported storage texture format: ${n}`),new Qt(t??{},r,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=t?.format??this.props.format;if(!ke[r])throw new Error(`Unsupported storage texture format: ${r}`);return new Xt(t,this)}destroy(){this._destroyed||(this._destroyed=!0,this._texture?.destroy())}},ut={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Qt=class{constructor(t,r,n){this.access=r;this._texture=n;this.dimension=t?.dimension??n.props.dimension??"2d",this._format=t?.format??n.props.format,this.texelDataType=ke[this._format]}resourceType="texture-storage-view";texelDataType;dimension;_view;_format;get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){return this._view||(this._view=this._texture.unwrap().createView({label:`${this.label??"<unnamed>"} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),o=`texture_storage_${ut[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${cn[this.access]}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},it=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;this.texelDataType=ke[this._format]}resourceType="texture-storage-view";texelDataType;get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=`texture_storage_${ut[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${cn[this.access]}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},Xt=class{constructor(t,r){this._props=t;this._texture=r;this.dimension=t?.dimension??r.props.dimension??"2d",this._format=t?.format??r.props.format,this.channelDataType=mn[this._format]}resourceType="texture-sampled-view";channelDataType;dimension;_format;_view;get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){return this._view||(this._view=this._texture.unwrap().createView({label:`${this.label??"<unnamed>"} - View`,...this._props})),this._view}"~resolve"(t){let r=t.names.makeUnique(this.label),n=(this._texture.props.sampleCount??1)>1,{group:a,binding:o}=t.allocateFixedEntry({texture:gn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${ut[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},st=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;this.channelDataType=fn[t]}resourceType="texture-sampled-view";channelDataType;get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=this._multisampled?"texture_multisampled_2d":`texture_${ut[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}};function Zt(e){return!!e?.usableAsSampled}function ia(e){return!!e?.usableAsRender}var pt=class e extends Error{constructor(t){super(`Resource '${t.label??"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function lt(e){return new tr(e)}function dt(e){return!!e&&e.resourceType==="bind-group-layout"}function rr(e){return!!e&&e.resourceType==="bind-group"}var er=class e extends Error{constructor(t,r){super(`Bind group '${t??"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},yn=["compute"],we=["compute","vertex","fragment"],tr=class{constructor(t){this.entries=t;let r=0;for(let[n,a]of Object.entries(t)){if(a===null){r++;continue}let o={idx:r,key:n,layout:this};if("uniform"in a&&(this.bound[n]=new Oe("uniform",a.uniform,o)),"storage"in a){let i="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Oe(a.access??"readonly",i,o)}"texture"in a&&(this.bound[n]=new st(a.texture,a.viewDimension??"2d",a.multisampled??!1,o)),"storageTexture"in a&&(this.bound[n]=new it(a.storageTexture,a.viewDimension??"2d",a.access??"writeonly",o)),"externalTexture"in a&&(this.bound[n]=new ot(o)),"sampler"in a&&(a.sampler==="comparison"?this.bound[n]=new at(o):this.bound[n]=new nt(o)),"texture"in a||"storageTexture"in a||"externalTexture"in a||"sampler"in a?this.value[n]=this.bound[n]:Object.defineProperty(this.value,n,{get:()=>this.bound[n].value}),r++}}_label;_index;resourceType="bind-group-layout";bound={};value={};$=this.value;toString(){return`bindGroupLayout:${this._label??"<unnamed>"}`}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){return t.device.createBindGroupLayout({label:this.label??"<unnamed>",entries:Object.values(this.entries).map((n,a)=>{if(n===null)return null;let o=n.visibility,i={binding:a,visibility:0};if("uniform"in n)o=o??we,i.buffer={type:"uniform"};else if("storage"in n)o=o??(n.access==="mutable"?yn:we),i.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=o??we,i.sampler={type:n.sampler};else if("texture"in n)o=o??we,i.texture={sampleType:n.texture,viewDimension:n.viewDimension??"2d",multisampled:n.multisampled??!1};else if("storageTexture"in n){let s=n.access??"writeonly";o=o??(s==="readonly"?we:yn),i.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[s],viewDimension:n.viewDimension??"2d"}}else"externalTexture"in n&&(o=o??we,i.externalTexture={});return o?.includes("compute")&&(i.visibility|=GPUShaderStage.COMPUTE),o?.includes("vertex")&&(i.visibility|=GPUShaderStage.VERTEX),o?.includes("fragment")&&(i.visibility|=GPUShaderStage.FRAGMENT),i}).filter(n=>n!==null)})}populate(t){return new de(this,t)}},de=class{constructor(t,r){this.layout=t;this.entries=r;for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new er(t.label,n)}resourceType="bind-group";unwrap(t){return t.device.createBindGroup({label:this.layout.label??"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([n,a],o)=>{if(a===null)return null;let i=this.entries[n];if(i===void 0)throw new Error(`'${n}' is a resource required to populate bind group layout '${this.layout.label??"<unnamed>"}'.`);if("uniform"in a){let s;if(Z(i)){if(!tt(i))throw new wt(i);s={buffer:t.unwrap(i)}}else s={buffer:i};return{binding:o,resource:s}}if("storage"in a){let s;if(Z(i)){if(!le(i))throw new Ee(i);s={buffer:t.unwrap(i)}}else s={buffer:i};return{binding:o,resource:s}}if("texture"in a){let s;if(q(i)){if(!Zt(i))throw new pt(i);s=t.unwrap(i.createView("sampled"))}else Me(i)?s=t.unwrap(i):s=i;return{binding:o,resource:s}}if("storageTexture"in a){let s;if(q(i)){if(!le(i))throw new Ee(i);a.access==="readonly"?s=t.unwrap(i.createView("readonly")):a.access==="mutable"?s=t.unwrap(i.createView("mutable")):s=t.unwrap(i.createView("writeonly"))}else We(i)?s=t.unwrap(i):s=i;return{binding:o,resource:s}}if("sampler"in a)return $e(i)||Ge(i)?{binding:o,resource:t.unwrap(i)}:{binding:o,resource:i};if("externalTexture"in a)return{binding:o,resource:i};throw new Error(`Malformed bind group entry: ${i} (${JSON.stringify(i)})`)}).filter(n=>n!==null)})}};var xn="#CATCHALL#",ar=class{_stack=[];_itemDepth=0;get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}popItem(){this.pop("item")}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}popSlotBindings(){this.pop("slotBinding")}pushFunctionScope(t,r,n){this._stack.push({type:"functionScope",args:t,returnType:r,externalMap:n})}popFunctionScope(){this.pop("functionScope")}pushBlockScope(){this._stack.push({type:"blockScope",declarations:new Map})}popBlockScope(){this.pop("blockScope")}pop(t){let r=this._stack[this._stack.length-1];if(!r||t&&r.type!==t)throw new Error(`Internal error, expected a ${t} layer to be on top.`);this._stack.pop(),t==="item"&&this._itemDepth--}readSlot(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(n?.type==="item")n.usedSlots.add(t);else if(n?.type==="slotBinding"){let a=n.bindingMap.get(t);if(a!==void 0)return a}else if(!(n?.type==="functionScope"||n?.type==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(n?.type==="functionScope"){let a=n.args.find(i=>i.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:z(o)?xe(o):R}:void 0}if(n?.type==="blockScope"){let a=n.declarations.get(t);if(a!==void 0)return{value:t,dataType:a}}}}defineBlockVariable(t,r){for(let n=this._stack.length-1;n>=0;--n){let a=this._stack[n];if(a?.type==="blockScope")return a.declarations.set(t,r),{value:t,dataType:r}}throw new Error("No block scope found to define a variable in.")}},mt=[""," "," "," "," "," "," "," "," "],nr=mt.length-1,or=class{identLevel=0;get pre(){return mt[this.identLevel]??mt[nr].repeat(this.identLevel/nr)+mt[this.identLevel%nr]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},ir=class{_memoizedResolves=new WeakMap;_memoizedDerived=new WeakMap;_indentController=new or;_jitTranspiler;_itemStateStack=new ar;_declarations=[];[y]={itemStateStack:this._itemStateStack};bindGroupLayoutsToPlaceholderMap=new Map;_nextFreeLayoutPlaceholderIdx=0;fixedBindings=[];callStack=[];names;constructor(t){this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){let r=this._itemStateStack.getResourceById(t);return r===void 0?null:r}defineVariable(t,r){return this._itemStateStack.defineBlockVariable(t,r)}pushBlockScope(){this._itemStateStack.pushBlockScope()}popBlockScope(){this._itemStateStack.popBlockScope()}transpileFn(t){if(!this._jitTranspiler)throw new Error("Tried to execute a tgpu.fn function without providing a JIT transpiler, or transpiling at build time.");return this._jitTranspiler.transpileFn(t)}fnToWgsl(t){this._itemStateStack.pushFunctionScope(t.args,t.returnType,t.externalMap);try{return{head:sr(this,t.args,t.returnType),body:Gt(this,t.body)}}finally{this._itemStateStack.popFunctionScope()}}addDeclaration(t){this._declarations.push(t)}allocateLayoutEntry(t){let r=this.bindGroupLayoutsToPlaceholderMap,n=r.get(t);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,r.set(t,n)),n}allocateFixedEntry(t,r){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:t,resource:r}),{group:xn,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new bt(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.popSlotBindings()}}unwrap(t){if(Dt(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(N(r))r=this.readSlot(r);else if(j(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){let r=this._memoizedDerived.get(t)??[];this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([s,p])=>s.areEqual(this._itemStateStack.readSlot(s),p)))return o.result;vt(Ue.CPU);let n;try{n=t["~compute"]()}finally{Ft(Ue.CPU)}let a=new Map;for(let o of this._itemStateStack.topItem.usedSlots)a.set(o,this._itemStateStack.readSlot(o));return r.push({slotToValueMap:a,result:n}),this._memoizedDerived.set(t,r),n}catch(n){throw n instanceof me?n.appendToTrace(t):new me(n,[t])}finally{this._itemStateStack.popItem()}}_getOrInstantiate(t){let r=this._memoizedResolves.get(t)??[];this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([s,p])=>s.areEqual(this._itemStateStack.readSlot(s),p)))return o.result;let n;$(t)?n=Ot(this,t):j(t)||N(t)?n=this.resolve(this.unwrap(t)):_r(t)?n=t["~resolve"](this):n=this.resolveValue(t);let a=new Map;for(let o of this._itemStateStack.topItem.usedSlots)a.set(o,this._itemStateStack.readSlot(o));return r.push({slotToValueMap:a,result:n}),this._memoizedResolves.set(t,r),n}catch(n){throw n instanceof me?n.appendToTrace(t):new me(n,[t])}finally{this._itemStateStack.popItem()}}resolve(t){if(Dt(t))return this.withSlots(t["~providing"].pairs,()=>this.resolve(t["~providing"].inner));if(t&&typeof t=="object"||typeof t=="function"){if(this._itemStateStack.itemDepth===0)try{vt(Ue.GPU);let r=Sr(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
24
24
 
25
- `)}${r}`}finally{It(Re.GPU)}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(q(t))return this.resolve(t);if(r&&X(r))return`array(${t.map(n=>this.resolveValue(n,r.elementType))})`;if(Array.isArray(t))return`array(${t.map(n=>this.resolveValue(n))})`;if(r&&_(r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolveValue(t[n],a))})`;throw new Error(`Value ${t} (as json: ${JSON.stringify(t)}) of schema ${r} is not resolvable to WGSL`)}};function Ue(e,t){var f;let r=new pr(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],i=new Set([...a.keys()].map(g=>g.index).filter(g=>g!==void 0)),s=Fr(i),l=r.fixedBindings.map((g,w)=>[String(w),g.layoutEntry]),u=()=>{let g=s.next().value,w=ct(Object.fromEntries(l));return o[g]=w,n=n.replaceAll(In,String(g)),[g,new Te(w,Object.fromEntries(r.fixedBindings.map((c,T)=>[String(T),c.resource])))]},d=l.length>0?u():null;for(let[g,w]of a.entries()){let c=(f=g.index)!=null?f:s.next().value;o[c]=g,n=n.replaceAll(w,String(c))}return{code:n,bindGroupLayouts:o,catchall:d}}function Rn(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};le(o,t!=null?t:{});let i={"~resolve"(l){return de(l,o,r!=null?r:"")},toString:()=>"<root>"},{code:s}=Ue(i,{names:n==="strict"?new ne:new re,jitTranspiler:a});return s}var Ke=class{constructor(t){this._make=t;p(this,"_map",new WeakMap)}getOrMake(t,...r){if(this._map.has(t))return this._map.get(t);let n=this._make(t,...r);return this._map.set(t,n),n}};function Bn(e,t,r){return new lr(new dr(e,t,r),{})}function _n(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var lr=class e{constructor(t,r){this._core=t;this._priors=r;p(this,"resourceType","compute-pipeline")}get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(t,r){var n;return new e(this._core,{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])})}dispatchWorkgroups(t,r,n){let a=this._core.unwrap(),{branch:o,label:i}=this._core,s=o.commandEncoder.beginComputePass({label:i!=null?i:"<unnamed>"});s.setPipeline(a.pipeline);let l=new Set(a.bindGroupLayouts);if(a.bindGroupLayouts.forEach((u,d)=>{var f;if(a.catchall&&d===a.catchall[0])s.setBindGroup(d,o.unwrap(a.catchall[1])),l.delete(u);else{let g=(f=this._priors.bindGroupLayoutMap)==null?void 0:f.get(u);g!==void 0&&(l.delete(u),s.setBindGroup(d,o.unwrap(g)))}}),l.size>0)throw new ie(l);s.dispatchWorkgroups(t,r,n),s.end()}$name(t){return this._core.label=t,this}},dr=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;p(this,"label");p(this,"_memo")}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let i=this.branch.device,{code:s,bindGroupLayouts:l,catchall:u}=Ue({"~resolve":d=>(d.withSlots(this._slotBindings,()=>{d.resolve(this._entryFn)}),""),toString:()=>{var d;return`computePipeline:${(d=this.label)!=null?d:"<unnamed>"}`}},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});u!==null&&((r=l[u[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`)),this._memo={pipeline:i.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:i.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:l.map(d=>this.branch.unwrap(d))}),compute:{module:i.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:s})}}),bindGroupLayouts:l,catchall:u}}return this._memo}};function gr(e,t="vertex"){return new fr(e,t)}function bt(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}var mr=Symbol("defaultAttribEntry");function ht(e,t,r,n,a){if(we(t)||Gr(t)){let o=ee(t);return o!==void 0&&(n[a!=null?a:mr]=o),ht(e,t.inner,$(r,W(t)),n)}if(_(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=$(o,A(s));let l=[i,ht(e,s,o,n,i)];return o+=h(s),l}))}if(Z(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=$(o,W(s));let l=[i,ht(e,s,o,n,i)];return o+=h(s),l}))}if("type"in t&&typeof t.type=="string"){if(Er.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=Vr[t.type];if(o)return{_layout:e,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var fr=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;p(this,"resourceType","vertex-layout");p(this,"stride");p(this,"attrib");p(this,"_customLocationMap",{});p(this,"_label");let n=t(0);this.stride=$(h(n.elementType),A(n)),this.attrib=ht(this,n.elementType,0,this._customLocationMap)}get label(){return this._label}get vertexLayout(){if(this._customLocationMap[mr]!==void 0){if(typeof this.attrib.format!="string"||typeof this.attrib.offset!="number")throw new Error("Single attribute vertex layouts must have a format and offset.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[{format:this.attrib.format,offset:this.attrib.offset,shaderLocation:this._customLocationMap[mr]}]}}if(!Object.keys(this.attrib).every(r=>this._customLocationMap[r]!==void 0))throw new Error("All attributes must have custom locations in order to unwrap a vertex layout.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[...Object.entries(this.attrib).map(([r,n])=>({format:n.format,offset:n.offset,shaderLocation:this._customLocationMap[r]}))]}}$name(t){return this._label=t,this}};function Ta(e){return typeof(e==null?void 0:e.loadOp)=="string"}function Pn(e,t){if(k(e)){if(!Ta(t))throw new Error("Expected a single color attachment, not a record.");return[t]}let r=[];for(let n of Object.keys(e)){let a=t[n];if(!a)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function ca(e){return typeof(e==null?void 0:e.format)=="string"}function Ln(e,t){if(k(e)){if(!ca(t))throw new Error("Expected a single color target configuration, not a record.");return[t]}let r=[];for(let n of Object.keys(e)){let a=t[n];if(!a)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function Cn(e){return new Tr(new cr(e),{})}function En(e){return(e==null?void 0:e.resourceType)==="render-pipeline"}var Tr=class e{constructor(t,r){this.core=t;this.priors=r;p(this,"resourceType","render-pipeline")}get label(){return this.core.label}$name(t){return this.core.label=t,this}with(t,r){var n,a;if(yt(t))return new e(this.core,L(R({},this.priors),{bindGroupLayoutMap:new Map([...(n=this.priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(bt(t))return new e(this.core,L(R({},this.priors),{vertexLayoutMap:new Map([...(a=this.priors.vertexLayoutMap)!=null?a:[],[t,r]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(t){return new e(this.core,L(R({},this.priors),{colorAttachment:t}))}withDepthStencilAttachment(t){return new e(this.core,L(R({},this.priors),{depthStencilAttachment:t}))}draw(t,r,n,a){var c;let o=this.core.unwrap(),{branch:i,fragmentFn:s}=this.core.options,u={colorAttachments:Pn(s.shell.targets,(c=this.priors.colorAttachment)!=null?c:{}).map(T=>J(T.view)?L(R({},T),{view:i.unwrap(T.view).createView()}):T)};if(this.core.label!==void 0&&(u.label=this.core.label),this.priors.depthStencilAttachment!==void 0){let T=this.priors.depthStencilAttachment;J(T.view)?u.depthStencilAttachment=L(R({},T),{view:i.unwrap(T.view).createView()}):u.depthStencilAttachment=T}let d=i.commandEncoder.beginRenderPass(u);d.setPipeline(o.pipeline);let f=new Set(o.bindGroupLayouts);o.bindGroupLayouts.forEach((T,F)=>{var y;if(o.catchall&&F===o.catchall[0])d.setBindGroup(F,i.unwrap(o.catchall[1])),f.delete(T);else{let x=(y=this.priors.bindGroupLayoutMap)==null?void 0:y.get(T);x!==void 0&&(f.delete(T),d.setBindGroup(F,i.unwrap(x)))}});let g=new Set(this.core.usedVertexLayouts);if(this.core.usedVertexLayouts.forEach((T,F)=>{var x;let y=(x=this.priors.vertexLayoutMap)==null?void 0:x.get(T);y&&(g.delete(T),d.setVertexBuffer(F,i.unwrap(y)))}),f.size>0)throw new ie(f);if(g.size>0)throw new Ie(g);d.draw(t,r,n,a),d.end(),i.flush()}},cr=class{constructor(t){this.options=t;p(this,"label");p(this,"usedVertexLayouts");p(this,"_memo");p(this,"_vertexBufferLayouts");p(this,"_targets");let r=an(t.vertexFn.shell.attributes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Ln(t.fragmentFn.shell.targets,t.targets)}unwrap(){var t,r,n,a;if(this._memo===void 0){let{branch:o,vertexFn:i,fragmentFn:s,slotBindings:l,primitiveState:u,depthStencilState:d,multisampleState:f}=this.options,{code:g,bindGroupLayouts:w,catchall:c}=Ue({"~resolve":x=>(x.withSlots(l,()=>{x.resolve(i),x.resolve(s)}),""),toString:()=>{var x;return`renderPipeline:${(x=this.label)!=null?x:"<unnamed>"}`}},{names:o.nameRegistry,jitTranspiler:o.jitTranspiler});c!==null&&((r=w[c[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let T=o.device,F=T.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:g}),y={layout:T.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:w.map(x=>o.unwrap(x))}),vertex:{module:F,buffers:this._vertexBufferLayouts},fragment:{module:F,targets:this._targets}};this.label!==void 0&&(y.label=this.label),u&&(y.primitive=u),d&&(y.depthStencil=d),f&&(y.multisample=f),this._memo={pipeline:T.createRenderPipeline(y),bindGroupLayouts:w,catchall:c}}return this._memo}};var yr=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[ue(t)?t.slot:t,r]])}withCompute(t){return new xr(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new hr({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r,multisampleState:void 0})}},xr=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Bn(this._root,this._slotBindings,this._entryFn)}},hr=class{constructor(t){this._options=t}withFragment(t,r,n){return Ae(typeof t!="string","Just type mismatch validation"),Ae(typeof r!="string","Just type mismatch validation"),new br(L(R({},this._options),{fragmentFn:t,targets:r}))}},br=class e{constructor(t){this._options=t}withPrimitive(t){return new e(L(R({},this._options),{primitiveState:t}))}withDepthStencil(t){return new e(L(R({},this._options),{depthStencilState:t}))}withMultisample(t){return new e(L(R({},this._options),{multisampleState:t}))}createPipeline(){return Cn(this._options)}},wt=class extends yr{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;p(this,"~unstable");p(this,"_disposables",[]);p(this,"_unwrappedBindGroupLayouts",new Ke(r=>r.unwrap(this)));p(this,"_unwrappedBindGroups",new Ke(r=>r.unwrap(this)));p(this,"_commandEncoder",null);this["~unstable"]=this}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=xn(this,r,n);return this._disposables.push(a),a}createUniform(r,n){return this.createBuffer(r,n).$usage("uniform").as("uniform")}createMutable(r,n){return this.createBuffer(r,n).$usage("storage").as("mutable")}createReadonly(r,n){return this.createBuffer(r,n).$usage("storage").as("readonly")}createBindGroup(r,n){return new Te(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=Fn(r,this);return this._disposables.push(n),n}unwrap(r){if(_n(r))return r.rawPipeline;if(En(r))return r.core.unwrap().pipeline;if(yt(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(or(r))return this._unwrappedBindGroups.getOrMake(r);if(oe(r))return r.buffer;if(J(r)||ze(r)||je(r))return r.unwrap();if(bt(r))return r.vertexLayout;if(We(r)){if("unwrap"in r)return r.unwrap(this);throw new Error("Cannot unwrap laid-out sampler.")}if(Me(r)){if("unwrap"in r)return r.unwrap(this);throw new Error("Cannot unwrap laid-out comparison sampler.")}throw new Error(`Unknown resource type: ${r}`)}beginRenderPass(r,n){let a=this.commandEncoder.beginRenderPass(r),o=new Map,i=new Map,s,l=()=>{if(!s)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:u,priors:d}=s,f=u.unwrap();a.setPipeline(f.pipeline);let g=new Set(f.bindGroupLayouts);f.bindGroupLayouts.forEach((c,T)=>{var F,y;if(f.catchall&&T===f.catchall[0])a.setBindGroup(T,this.unwrap(f.catchall[1])),g.delete(c);else{let x=(y=(F=d.bindGroupLayoutMap)==null?void 0:F.get(c))!=null?y:o.get(c);x!==void 0&&(g.delete(c),or(x)?a.setBindGroup(T,this.unwrap(x)):a.setBindGroup(T,x))}});let w=new Set;if(u.usedVertexLayouts.forEach((c,T)=>{var x;let F=(x=d.vertexLayoutMap)==null?void 0:x.get(c),y=F?{buffer:F,offset:void 0,size:void 0}:i.get(c);!y||!y.buffer?w.add(c):oe(y.buffer)?a.setVertexBuffer(T,this.unwrap(y.buffer),y.offset,y.size):a.setVertexBuffer(T,y.buffer,y.offset,y.size)}),g.size>0)throw new ie(g);if(w.size>0)throw new Ie(w)};n({setViewport(...u){a.setViewport(...u)},setScissorRect(...u){a.setScissorRect(...u)},setBlendConstant(...u){a.setBlendConstant(...u)},setStencilReference(...u){a.setStencilReference(...u)},beginOcclusionQuery(...u){a.beginOcclusionQuery(...u)},endOcclusionQuery(...u){a.endOcclusionQuery(...u)},executeBundles(...u){a.executeBundles(...u)},setPipeline(u){s=u},setIndexBuffer:(u,d,f,g)=>{oe(u)?a.setIndexBuffer(this.unwrap(u),d,f,g):a.setIndexBuffer(u,d,f,g)},setVertexBuffer(u,d,f,g){i.set(u,{buffer:d,offset:f,size:g})},setBindGroup(u,d){o.set(u,d)},draw(u,d,f,g){l(),a.draw(u,d,f,g)},drawIndexed(...u){l(),a.drawIndexed(...u)},drawIndirect(...u){l(),a.drawIndirect(...u)},drawIndexedIndirect(...u){l(),a.drawIndexedIndirect(...u)}}),a.end()}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Vn(e){let{adapter:t,device:r,unstable_names:n="random",unstable_jitTranspiler:a}=e!=null?e:{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let o=await navigator.gpu.requestAdapter(t);if(!o)throw new Error("Could not find a compatible GPU");return new wt(await o.requestDevice(r),n==="random"?new re:new ne,a,!0)}function Gn(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new wt(t,r==="random"?new re:new ne,n,!1)}function St(e){return new wr(e)}var wr=class{constructor(t=void 0){this.defaultValue=t;p(this,"resourceType","slot");p(this,"label");p(this,"~repr")}$name(t){return this.label=t,this}areEqual(t,r){return Object.is(t,r)}toString(){var t;return`slot:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){let t=z();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return Ve(t.unwrap(this))}};function $n(e,t){return new Sr(e,t)}var Sr=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;p(this,"resourceType","accessor");p(this,"~repr");p(this,"label");p(this,"slot");this.slot=St(r)}$name(t){return this.label=t,this.slot.$name(t),this}toString(){var t;return`accessor:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!z())throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return new Proxy({"~resolve":r=>r.resolve(this),toString:()=>{var r;return`.value:${(r=this.label)!=null?r:"<unnamed>"}`},[b]:{dataType:this.schema}},M)}"~resolve"(t){let r=t.unwrap(this.slot);return Qe(r)?t.resolve(r):Vt(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function On(e){return xa(e)}function ya([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function xa(e){return{resourceType:"derived","~compute":e,"~repr":void 0,get value(){let r=z();if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Ve(r.unwrap(this))},with(r,n){return kn(this,[[r,n]])},toString(){return"derived"}}}function kn(e,t){return{resourceType:"derived","~repr":void 0,"~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},"~providing":{inner:e,pairs:t},get value(){let n=z();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Ve(n.unwrap(this))},with(n,a){return kn(e,[...t,[n,a]])},toString(){return`derived[${t.map(ya).join(", ")}]`}}}function Wn(e,t){return new Dt("private",e,t)}function Mn(e){return new Dt("workgroup",e)}var Dt=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n;p(this,"_label")}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)};`),r}get label(){return this._label}toString(){var t;return`var:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!se())throw new Error("Cannot access tgpu.var's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`},[b]:{dataType:this._dataType}},M)}};var Nn={bindGroupLayout:ct,vertexLayout:gr,init:Vn,initFromDevice:Gn,resolve:Rn,"~unstable":{fn:Zr,fragmentFn:tn,vertexFn:rn,computeFn:Xr,vertexLayout:gr,derived:On,slot:St,accessor:$n,privateVar:Wn,workgroupVar:Mn,const:jr,declare:qr,sampler:hn,comparisonSampler:bn}},ju=Nn;Object.assign(Nn,{__assignAst:Yr});export{ie as MissingBindGroupsError,Ut as MissingLinksError,Ft as MissingSlotValueError,Ie as MissingVertexBuffersError,vt as NotUniformError,re as RandomNameRegistry,ye as ResolutionError,ne as StrictNameRegistry,ju as default,oe as isBuffer,Me as isComparisonSampler,K as isDerived,je as isSampledTextureView,We as isSampler,j as isSlot,ze as isStorageTextureView,J as isTexture,Vt as isTgpuFn,ga as isUsableAsRender,rr as isUsableAsSampled,ge as isUsableAsStorage,st as isUsableAsUniform,fa as isUsableAsVertex,Nn as tgpu,jt as unstable_asMutable,Kt as unstable_asReadonly,qt as unstable_asUniform};
25
+ `)}${r}`}finally{Ft(Ue.GPU)}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(z(t))return this.resolve(t);if(r&&O(r))return`array(${t.map(n=>this.resolveValue(n,r.elementType))})`;if(Array.isArray(t))return`array(${t.map(n=>this.resolveValue(n))})`;if(r&&h(r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolveValue(t[n],a))})`;throw new Error(`Value ${t} (as json: ${JSON.stringify(t)}) of schema ${r} is not resolvable to WGSL`)}};function Se(e,t){let r=new ir(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],i=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),s=vr(i),p=r.fixedBindings.map((m,T)=>[String(T),m.layoutEntry]),u=()=>{let m=s.next().value,T=lt(Object.fromEntries(p));return o[m]=T,n=n.replaceAll(xn,String(m)),[m,new de(T,Object.fromEntries(r.fixedBindings.map((f,g)=>[String(g),f.resource])))]},d=p.length>0?u():null;for(let[m,T]of a.entries()){let f=m.index??s.next().value;o[f]=m,n=n.replaceAll(T,String(f))}return{code:n,bindGroupLayouts:o,catchall:d}}function sr(e,t,r){let n=t.map(a=>`${a.value}: ${e.resolve(a.dataType)}`).join(", ");return r!==void 0?`(${n}) -> ${ye(r)} ${e.resolve(r)}`:`(${n})`}function ee(e,t){let r=[];return typeof t=="string"&&(jr(t,Array.isArray(e.argTypes)?e.argTypes:Object.values(e.argTypes),n=>r.push(n)),he(t,e.returnType,n=>r.push(n)),Array.isArray(e.argTypes)&&h(e.argTypes[0])&&r.push({In:e.argTypes[0]}),h(e.returnType)&&r.push({Out:e.returnType})),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){let o={};for(let s of r)K(o,s);let i=n.names.makeUnique(this.label);if(typeof t=="string"){let s="";if(a==="")s=Array.isArray(e.argTypes)?"":sr(n,Object.entries(e.argTypes).map(([u,d])=>({value:u,dataType:d})),e.returnType);else{let u=Array.isArray(e.argTypes)&&h(e.argTypes[0])?"(in: In)":"()",d=V(e.returnType)?ye(e.returnType):"",m=e.returnType!==void 0?h(e.returnType)?"-> Out":`-> ${d!==""?d:"@location(0)"} ${n.resolve(e.returnType)}`:"";s=`${u} ${m} `}let p=se(n,o,`${s}${t.trim()}`);n.addDeclaration(`${a}fn ${i}${p}`)}else{let s=qr(t);if(s?.externals){let f=Object.fromEntries(Object.entries(s.externals).filter(([g])=>!(g in o)));K(o,f)}let p=s?.ast??n.transpileFn(String(t));p.argNames.type==="destructured-object"&&K(o,Object.fromEntries(p.argNames.props.map(({prop:f,alias:g})=>[g,f]))),!Array.isArray(e.argTypes)&&p.argNames.type==="identifiers"&&p.argNames.names[0]!==void 0&&K(o,{[p.argNames.names[0]]:Object.fromEntries(Object.keys(e.argTypes).map(f=>[f,f]))});let u=p.externalNames.filter(f=>!(f in o));if(u.length>0)throw new St(this.label,u);let d=Array.isArray(e.argTypes)?p.argNames.type==="identifiers"?p.argNames.names.map((f,g)=>({value:f,dataType:e.argTypes[g]})):[]:Object.entries(e.argTypes).map(([f,g])=>({value:f,dataType:g})),{head:m,body:T}=n.fnToWgsl({args:d,returnType:e.returnType,body:p.body,externalMap:o});n.addDeclaration(`${a}fn ${i}${n.resolve(m)}${n.resolve(T)}`)}return i}}}function hn(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(Ye(n))return[r,n];let a=Q(n);return a!==void 0?(t=a+1,[r,n]):[r,Or(n,{type:"@location",value:t++})]}))}function gt(e){return $(e)?Q(e)!==void 0?e:$r(0,e):Pt(hn(e))}function ve(e){return Pt(hn(e))}function bn(e){let t={argTypes:[ve(e.in??{})],returnType:void 0,workgroupSize:[e.workgroupSize[0]??1,e.workgroupSize[1]??1,e.workgroupSize[2]??1]},r=n=>sa(t,e.workgroupSize,n);return Object.assign(Object.assign(r,t),{does:r})}function sa(e,t,r){let n=ee(e,r),a=e.argTypes[0];return{shell:e,get label(){return n.label},$uses(o){return n.applyExternals(o),this},$name(o){return n.label=o,W(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){return n.resolve(o,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){return`computeFn:${this.label??"<unnamed>"}`}}}function wn(e,t){let r={argTypes:e,returnType:t},n=a=>pa(r,a);return Object.assign(Object.assign(n,r),{does:n})}function ur(e){return e?.resourceType==="function"}function ua([e,t]){return`${e.label??"<unnamed>"}=${t}`}function pa(e,t){let r=ee(e,t),n={shell:e,resourceType:"function",$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,this},with(i,s){return Sn(o,[[oe(i)?i.slot:i,s]])},"~resolve"(i){if(typeof t=="string")return r.resolve(i);let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(e.returnType),r.resolve(i)}finally{s.callStack.pop()}}},a=Ut((...i)=>{if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...i)},(...i)=>({value:new ft(o,i.map(s=>s.value)),dataType:e.returnType??R}));Object.defineProperty(a,y,{value:{implementation:t}});let o=Object.assign(a,n);return Object.defineProperty(o,"label",{get:()=>r.label}),Object.defineProperty(o,"toString",{value:()=>`fn:${r.label??"<unnamed>"}`}),o}function Sn(e,t){let r={resourceType:"function",shell:e.shell,"~providing":{inner:e,pairs:t},$uses(o){return e.$uses(o),this},$name(o){return e.$name(o),this},with(o,i){return Sn(a,[...t,[oe(o)?o.slot:o,i]])}},n=Ut((...o)=>e(...o),(...o)=>({value:new ft(a,o.map(i=>i.value)),dataType:e.shell.returnType??R})),a=Object.assign(n,r);return Object.defineProperty(a,"label",{get:()=>e.label}),Object.defineProperty(a,"toString",{value(){return`fn:${e.label??"<unnamed>"}[${t.map(ua).join(", ")}]`}}),Object.defineProperty(a,y,{value:{implementation:e[y].implementation}}),a}var ft=class{constructor(t,r){this._fn=t;this._params=r}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(r=>t.resolve(r)).join(", ")})`)}toString(){return`call:${this.label??"<unnamed>"}`}};function vn(e){let t={argTypes:[ve(e.in??{})],targets:e.out,returnType:gt(e.out)},r=n=>la(t,n);return Object.assign(Object.assign(r,t),{does:r})}function la(e,t){let r=ee(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&he(t,n,i=>r.applyExternals(i)),{shell:e,outputType:n,get label(){return r.label},$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,W(n)&&n.$name(`${i}_Output`),W(a)&&a.$name(`${i}_Input`),this},"~resolve"(i){if(typeof t=="string")return r.resolve(i,"@fragment ");let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(n),r.resolve(i,"@fragment ")}finally{s.callStack.pop()}},toString(){return`fragmentFn:${this.label??"<unnamed>"}`}}}function Fn(e){let t={attributes:[e.in??{}],returnType:gt(e.out),argTypes:[ve(e.in??{})]},r=n=>da(t,n);return Object.assign(Object.assign(r,t),{does:r})}function da(e,t){let r=ee(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&he(t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,inputType:a,get label(){return r.label},$uses(o){return r.applyExternals(o),this},$name(o){return r.label=o,W(n)&&n.$name(`${o}_Output`),W(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){if(typeof t=="string")return r.resolve(o,"@vertex ");let i=o;if(i.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return i.callStack.push(n),r.resolve(o,"@vertex ")}finally{i.callStack.pop()}},toString(){return`vertexFn:${this.label??"<unnamed>"}`}}}var te=class{lastUniqueId=0;makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},re=class{_usedNames=new Set;makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function Dn(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};K(o,t??{});let i={"~resolve"(p){return se(p,o,r??"")},toString:()=>"<root>"},{code:s}=Se(i,{names:n==="strict"?new re:new te,jitTranspiler:a});return s}var Ne=class{constructor(t){this._make=t}_map=new WeakMap;getOrMake(t,...r){if(this._map.has(t))return this._map.get(t);let n=this._make(t,...r);return this._map.set(t,n),n}};function Un(e,t,r){return new pr(new lr(e,t,r),{})}function An(e){return e?.resourceType==="compute-pipeline"}var pr=class e{constructor(t,r){this._core=t;this._priors=r}resourceType="compute-pipeline";get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(t,r){return new e(this._core,{bindGroupLayoutMap:new Map([...this._priors.bindGroupLayoutMap??[],[t,r]])})}dispatchWorkgroups(t,r,n){let a=this._core.unwrap(),{branch:o,label:i}=this._core,s=o.commandEncoder.beginComputePass({label:i??"<unnamed>"});s.setPipeline(a.pipeline);let p=new Set(a.bindGroupLayouts);if(a.bindGroupLayouts.forEach((u,d)=>{if(a.catchall&&d===a.catchall[0])s.setBindGroup(d,o.unwrap(a.catchall[1])),p.delete(u);else{let m=this._priors.bindGroupLayoutMap?.get(u);m!==void 0&&(p.delete(u),s.setBindGroup(d,o.unwrap(m)))}}),p.size>0)throw new ne(p);s.dispatchWorkgroups(t,r,n),s.end()}$name(t){return this._core.label=t,this}},lr=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n}label;_memo;unwrap(){if(this._memo===void 0){let t=this.branch.device,{code:r,bindGroupLayouts:n,catchall:a}=Se({"~resolve":o=>(o.withSlots(this._slotBindings,()=>{o.resolve(this._entryFn)}),""),toString:()=>`computePipeline:${this.label??"<unnamed>"}`},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});a!==null&&n[a[0]]?.$name(`${this.label??"<unnamed>"} - Automatic Bind Group & Layout`),this._memo={pipeline:t.createComputePipeline({label:this.label??"<unnamed>",layout:t.createPipelineLayout({label:`${this.label??"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:n.map(o=>this.branch.unwrap(o))}),compute:{module:t.createShaderModule({label:`${this.label??"<unnamed>"} - Shader`,code:r})}}),bindGroupLayouts:n,catchall:a}}return this._memo}};function gr(e,t="vertex"){return new mr(e,t)}function ct(e){return e?.resourceType==="vertex-layout"}var dr=Symbol("defaultAttribEntry");function Tt(e,t,r,n,a){if(ce(t)||Vr(t)){let o=Q(t);return o!==void 0&&(n[a??dr]=o),Tt(e,t.inner,L(r,G(t)),n)}if(h(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=L(o,D(s));let p=[i,Tt(e,s,o,n,i)];return o+=c(s),p}))}if(Y(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=L(o,G(s));let p=[i,Tt(e,s,o,n,i)];return o+=c(s),p}))}if("type"in t&&typeof t.type=="string"){if(Cr.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=Er[t.type];if(o)return{_layout:e,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var mr=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;let n=t(0);this.stride=L(c(n.elementType),D(n)),this.attrib=Tt(this,n.elementType,0,this._customLocationMap)}resourceType="vertex-layout";stride;attrib;_customLocationMap={};_label;get label(){return this._label}get vertexLayout(){if(this._customLocationMap[dr]!==void 0){if(typeof this.attrib.format!="string"||typeof this.attrib.offset!="number")throw new Error("Single attribute vertex layouts must have a format and offset.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[{format:this.attrib.format,offset:this.attrib.offset,shaderLocation:this._customLocationMap[dr]}]}}if(!Object.keys(this.attrib).every(r=>this._customLocationMap[r]!==void 0))throw new Error("All attributes must have custom locations in order to unwrap a vertex layout.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[...Object.entries(this.attrib).map(([r,n])=>({format:n.format,offset:n.offset,shaderLocation:this._customLocationMap[r]}))]}}$name(t){return this._label=t,this}};function ma(e){return typeof e?.loadOp=="string"}function In(e,t){if($(e)){if(!ma(t))throw new Error("Expected a single color attachment, not a record.");return[t]}let r=[];for(let n of Object.keys(e)){let a=t[n];if(!a)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function ga(e){return typeof e?.format=="string"}function Rn(e,t){if($(e)){if(!ga(t))throw new Error("Expected a single color target configuration, not a record.");return[t]}let r=[];for(let n of Object.keys(e)){let a=t[n];if(!a)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function Bn(e){return new fr(new Tr(e),{})}function _n(e){return e?.resourceType==="render-pipeline"}var fr=class e{constructor(t,r){this.core=t;this.priors=r}resourceType="render-pipeline";get label(){return this.core.label}$name(t){return this.core.label=t,this}with(t,r){if(dt(t))return new e(this.core,{...this.priors,bindGroupLayoutMap:new Map([...this.priors.bindGroupLayoutMap??[],[t,r]])});if(ct(t))return new e(this.core,{...this.priors,vertexLayoutMap:new Map([...this.priors.vertexLayoutMap??[],[t,r]])});throw new Error("Unsupported value passed into .with()")}withColorAttachment(t){return new e(this.core,{...this.priors,colorAttachment:t})}withDepthStencilAttachment(t){return new e(this.core,{...this.priors,depthStencilAttachment:t})}draw(t,r,n,a){let o=this.core.unwrap(),{branch:i,fragmentFn:s}=this.core.options,u={colorAttachments:In(s.shell.targets,this.priors.colorAttachment??{}).map(g=>q(g.view)?{...g,view:i.unwrap(g.view).createView()}:g)};if(this.core.label!==void 0&&(u.label=this.core.label),this.priors.depthStencilAttachment!==void 0){let g=this.priors.depthStencilAttachment;q(g.view)?u.depthStencilAttachment={...g,view:i.unwrap(g.view).createView()}:u.depthStencilAttachment=g}let d=i.commandEncoder.beginRenderPass(u);d.setPipeline(o.pipeline);let m=new Set(o.bindGroupLayouts);o.bindGroupLayouts.forEach((g,F)=>{if(o.catchall&&F===o.catchall[0])d.setBindGroup(F,i.unwrap(o.catchall[1])),m.delete(g);else{let w=this.priors.bindGroupLayoutMap?.get(g);w!==void 0&&(m.delete(g),d.setBindGroup(F,i.unwrap(w)))}});let T=new Set(this.core.usedVertexLayouts);if(this.core.usedVertexLayouts.forEach((g,F)=>{let w=this.priors.vertexLayoutMap?.get(g);w&&(T.delete(g),d.setVertexBuffer(F,i.unwrap(w)))}),m.size>0)throw new ne(m);if(T.size>0)throw new De(T);d.draw(t,r,n,a),d.end(),i.flush()}},Tr=class{constructor(t){this.options=t;let r=Qr(t.vertexFn.shell.attributes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Rn(t.fragmentFn.shell.targets,t.targets)}label;usedVertexLayouts;_memo;_vertexBufferLayouts;_targets;unwrap(){if(this._memo===void 0){let{branch:t,vertexFn:r,fragmentFn:n,slotBindings:a,primitiveState:o,depthStencilState:i,multisampleState:s}=this.options,{code:p,bindGroupLayouts:u,catchall:d}=Se({"~resolve":g=>(g.withSlots(a,()=>{g.resolve(r),g.resolve(n)}),""),toString:()=>`renderPipeline:${this.label??"<unnamed>"}`},{names:t.nameRegistry,jitTranspiler:t.jitTranspiler});d!==null&&u[d[0]]?.$name(`${this.label??"<unnamed>"} - Automatic Bind Group & Layout`);let m=t.device,T=m.createShaderModule({label:`${this.label??"<unnamed>"} - Shader`,code:p}),f={layout:m.createPipelineLayout({label:`${this.label??"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:u.map(g=>t.unwrap(g))}),vertex:{module:T,buffers:this._vertexBufferLayouts},fragment:{module:T,targets:this._targets}};this.label!==void 0&&(f.label=this.label),o&&(f.primitive=o),i&&(f.depthStencil=i),s&&(f.multisample=s),this._memo={pipeline:m.createRenderPipeline(f),bindGroupLayouts:u,catchall:d}}return this._memo}};var cr=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[oe(t)?t.slot:t,r]])}withCompute(t){return new yr(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new xr({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r,multisampleState:void 0})}},yr=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Un(this._root,this._slotBindings,this._entryFn)}},xr=class{constructor(t){this._options=t}withFragment(t,r,n){return Fe(typeof t!="string","Just type mismatch validation"),Fe(typeof r!="string","Just type mismatch validation"),new hr({...this._options,fragmentFn:t,targets:r})}},hr=class e{constructor(t){this._options=t}withPrimitive(t){return new e({...this._options,primitiveState:t})}withDepthStencil(t){return new e({...this._options,depthStencilState:t})}withMultisample(t){return new e({...this._options,multisampleState:t})}createPipeline(){return Bn(this._options)}},yt=class extends cr{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;this["~unstable"]=this}"~unstable";_disposables=[];_unwrappedBindGroupLayouts=new Ne(r=>r.unwrap(this));_unwrappedBindGroups=new Ne(r=>r.unwrap(this));_commandEncoder=null;get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=pn(this,r,n);return this._disposables.push(a),a}createUniform(r,n){return this.createBuffer(r,n).$usage("uniform").as("uniform")}createMutable(r,n){return this.createBuffer(r,n).$usage("storage").as("mutable")}createReadonly(r,n){return this.createBuffer(r,n).$usage("storage").as("readonly")}createBindGroup(r,n){return new de(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=Tn(r,this);return this._disposables.push(n),n}unwrap(r){if(An(r))return r.rawPipeline;if(_n(r))return r.core.unwrap().pipeline;if(dt(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(rr(r))return this._unwrappedBindGroups.getOrMake(r);if(Z(r))return r.buffer;if(q(r)||We(r)||Me(r))return r.unwrap();if(ct(r))return r.vertexLayout;if($e(r)){if("unwrap"in r)return r.unwrap(this);throw new Error("Cannot unwrap laid-out sampler.")}if(Ge(r)){if("unwrap"in r)return r.unwrap(this);throw new Error("Cannot unwrap laid-out comparison sampler.")}throw new Error(`Unknown resource type: ${r}`)}beginRenderPass(r,n){let a=this.commandEncoder.beginRenderPass(r),o=new Map,i=new Map,s,p=()=>{if(!s)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:u,priors:d}=s,m=u.unwrap();a.setPipeline(m.pipeline);let T=new Set(m.bindGroupLayouts);m.bindGroupLayouts.forEach((g,F)=>{if(m.catchall&&F===m.catchall[0])a.setBindGroup(F,this.unwrap(m.catchall[1])),T.delete(g);else{let w=d.bindGroupLayoutMap?.get(g)??o.get(g);w!==void 0&&(T.delete(g),rr(w)?a.setBindGroup(F,this.unwrap(w)):a.setBindGroup(F,w))}});let f=new Set;if(u.usedVertexLayouts.forEach((g,F)=>{let w=d.vertexLayoutMap?.get(g),A=w?{buffer:w,offset:void 0,size:void 0}:i.get(g);!A||!A.buffer?f.add(g):Z(A.buffer)?a.setVertexBuffer(F,this.unwrap(A.buffer),A.offset,A.size):a.setVertexBuffer(F,A.buffer,A.offset,A.size)}),T.size>0)throw new ne(T);if(f.size>0)throw new De(f)};n({setViewport(...u){a.setViewport(...u)},setScissorRect(...u){a.setScissorRect(...u)},setBlendConstant(...u){a.setBlendConstant(...u)},setStencilReference(...u){a.setStencilReference(...u)},beginOcclusionQuery(...u){a.beginOcclusionQuery(...u)},endOcclusionQuery(...u){a.endOcclusionQuery(...u)},executeBundles(...u){a.executeBundles(...u)},setPipeline(u){s=u},setIndexBuffer:(u,d,m,T)=>{Z(u)?a.setIndexBuffer(this.unwrap(u),d,m,T):a.setIndexBuffer(u,d,m,T)},setVertexBuffer(u,d,m,T){i.set(u,{buffer:d,offset:m,size:T})},setBindGroup(u,d){o.set(u,d)},draw(u,d,m,T){p(),a.draw(u,d,m,T)},drawIndexed(...u){p(),a.drawIndexed(...u)},drawIndirect(...u){p(),a.drawIndirect(...u)},drawIndexedIndirect(...u){p(),a.drawIndexedIndirect(...u)}}),a.end()}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Pn(e){let{adapter:t,device:r,unstable_names:n="random",unstable_jitTranspiler:a}=e??{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let o=await navigator.gpu.requestAdapter(t);if(!o)throw new Error("Could not find a compatible GPU");return new yt(await o.requestDevice(r),n==="random"?new te:new re,a,!0)}function Ln(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e??{};return new yt(t,r==="random"?new te:new re,n,!1)}function xt(e){return new br(e)}var br=class{constructor(t=void 0){this.defaultValue=t}resourceType="slot";label;$name(t){return this.label=t,this}areEqual(t,r){return Object.is(t,r)}toString(){return`slot:${this.label??"<unnamed>"}`}get value(){let t=M();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return Le(t.unwrap(this))}};function Cn(e,t){return new wr(e,t)}var wr=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;this.slot=xt(r)}resourceType="accessor";label;slot;$name(t){return this.label=t,this.slot.$name(t),this}toString(){return`accessor:${this.label??"<unnamed>"}`}get value(){if(!M())throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return new Proxy({"~resolve":r=>r.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.schema}},k)}"~resolve"(t){let r=t.unwrap(this.slot);return qe(r)?t.resolve(r):ur(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function En(e){return Ta(e)}function fa([e,t]){return`${e.label??"<unnamed>"}=${t}`}function Ta(e){return{resourceType:"derived","~compute":e,[At]:void 0,get value(){let r=M();if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Le(r.unwrap(this))},with(r,n){return Vn(this,[[r,n]])},toString(){return"derived"}}}function Vn(e,t){return{resourceType:"derived",[At]:void 0,"~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},"~providing":{inner:e,pairs:t},get value(){let n=M();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Le(n.unwrap(this))},with(n,a){return Vn(e,[...t,[n,a]])},toString(){return`derived[${t.map(fa).join(", ")}]`}}}function On(e,t){return new ht("private",e,t)}function $n(e){return new ht("workgroup",e)}var ht=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n}_label;$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)};`),r}get label(){return this._label}toString(){return`var:${this.label??"<unnamed>"}`}get value(){if(!ae())throw new Error("Cannot access tgpu.var's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this._dataType}},k)}};var Gn={bindGroupLayout:lt,vertexLayout:gr,init:Pn,initFromDevice:Ln,resolve:Dn,"~unstable":{fn:wn,fragmentFn:vn,vertexFn:Fn,computeFn:bn,vertexLayout:gr,derived:En,slot:xt,accessor:Cn,privateVar:On,workgroupVar:$n,const:Nr,declare:zr,sampler:ln,comparisonSampler:dn}},Bu=Gn;Object.assign(Gn,{__assignAst:Hr,__removedJsImpl:Jr});export{ne as MissingBindGroupsError,St as MissingLinksError,bt as MissingSlotValueError,De as MissingVertexBuffersError,wt as NotUniformError,te as RandomNameRegistry,me as ResolutionError,re as StrictNameRegistry,Bu as default,Z as isBuffer,Ge as isComparisonSampler,j as isDerived,Me as isSampledTextureView,$e as isSampler,N as isSlot,We as isStorageTextureView,q as isTexture,ur as isTgpuFn,ia as isUsableAsRender,Zt as isUsableAsSampled,le as isUsableAsStorage,tt as isUsableAsUniform,oa as isUsableAsVertex,Gn as tgpu,Nt as unstable_asMutable,jt as unstable_asReadonly,zt as unstable_asUniform};
26
26
  //# sourceMappingURL=index.js.map