typegpu 0.5.3 → 0.5.5

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-DSOqT8yA.d.cts → attributes-BcDZsQCE.d.cts} +1 -1
  3. package/{attributes-B4JpvOTz.d.ts → attributes-DsIdcdq4.d.ts} +1 -1
  4. package/chunk-A6AAWPBU.cjs +2 -0
  5. package/chunk-A6AAWPBU.cjs.map +1 -0
  6. package/chunk-HZAXWB4J.js +2 -0
  7. package/chunk-HZAXWB4J.js.map +1 -0
  8. package/chunk-T5Y2EQPZ.js +4 -0
  9. package/chunk-T5Y2EQPZ.js.map +1 -0
  10. package/chunk-VUYQ2ZIK.cjs +4 -0
  11. package/chunk-VUYQ2ZIK.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 +50 -4
  15. package/data/index.d.ts +50 -4
  16. package/data/index.js +1 -1
  17. package/{wgslTypes-VtSRoe90.d.ts → dataTypes-ts2Ccted.d.cts} +608 -506
  18. package/{wgslTypes-VtSRoe90.d.cts → dataTypes-ts2Ccted.d.ts} +608 -506
  19. package/index.cjs +19 -19
  20. package/index.cjs.map +1 -1
  21. package/index.d.cts +110 -443
  22. package/index.d.ts +110 -443
  23. package/index.js +19 -19
  24. package/index.js.map +1 -1
  25. package/package.json +2 -2
  26. package/sampler-CPNwYXSH.d.ts +369 -0
  27. package/sampler-DeX4AnIZ.d.cts +369 -0
  28. package/std/index.cjs +1 -1
  29. package/std/index.cjs.map +1 -1
  30. package/std/index.d.cts +190 -47
  31. package/std/index.d.ts +190 -47
  32. package/std/index.js +1 -1
  33. package/std/index.js.map +1 -1
  34. package/chunk-DVZNNZFQ.js +0 -2
  35. package/chunk-DVZNNZFQ.js.map +0 -1
  36. package/chunk-FM3TKZFZ.cjs +0 -2
  37. package/chunk-FM3TKZFZ.cjs.map +0 -1
  38. package/chunk-M4VUFFPZ.cjs +0 -4
  39. package/chunk-M4VUFFPZ.cjs.map +0 -1
  40. package/chunk-RMXVIINO.js +0 -2
  41. package/chunk-RMXVIINO.js.map +0 -1
  42. package/chunk-UHU5Z2IS.js +0 -4
  43. package/chunk-UHU5Z2IS.js.map +0 -1
  44. package/chunk-UPPJES6W.cjs +0 -2
  45. package/chunk-UPPJES6W.cjs.map +0 -1
package/index.js CHANGED
@@ -1,26 +1,26 @@
1
- import{$ as D,a as Rr,aa as V,b as Br,c as qe,ca as c,d as Je,e as J,ea as Pr,f as _r,g as H,h as E,i as It,j as L,k as Re,oa as Lr,ra as Cr,ta as He,ua as Ye}from"./chunk-DVZNNZFQ.js";import{a as y,b as O,c as W,d as Ft,e as ne,f as R,h as Ur,i as M,j as Ar,k as Ke,l as Ir}from"./chunk-RMXVIINO.js";import{A as _,B as Me,C as Ne,D as ze,F as je,G as At,H as ge,I as v,J as A,K as p,L as Ie,M as hr,N as br,O as wr,P as Sr,Q as vr,R as Dr,S as K,T as q,U as I,W as Fr,a as Se,aa as Te,b as de,c as bt,d as wt,e as St,f as te,g as ve,h as De,i as yr,j as k,k as vt,l as Dt,m as re,n as xr,o as Ut,p as P,q as Fe,r as z,s as j,t as ae,u as Ue,v as me,w as fe,x,y as Ae,z as B}from"./chunk-UHU5Z2IS.js";var Cn=["vec2f","vec2h","vec2i","vec2u","vec3f","vec3h","vec3i","vec3u","vec4f","vec4h","vec4i","vec4u","struct"],En={f:{1:p,2:P,3:ae,4:x},h:{1:Ie,2:Fe,3:Ue,4:Ae},i:{1:A,2:z,3:me,4:B},u:{1:v,2:j,3:fe,4:_}},Er={vec2f:P,vec2h:Fe,vec2i:z,vec2u:j,vec3f:ae,vec3h:Ue,vec3i:me,vec3u:fe,vec4f:x,vec4h:Ae,vec4i:B,vec4u:_,mat2x2f:Me,mat3x3f:Ne,mat4x4f:ze},Vr={vec2f:p,vec2h:Ie,vec2i:A,vec2u:v,vec3f:p,vec3h:Ie,vec3i:A,vec3u:v,vec4f:p,vec4h:Ie,vec4i:A,vec4u:v,mat2x2f:P,mat3x3f:ae,mat4x4f:x};function Be(e,t){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return R;if(W(e)||O(e)){let o=k();if(!o)throw new Error("Resolution context not found when unwrapping slot or derived");let i=o.unwrap(e);return ce(i)}let r=e;for(Ir(r)&&(r=r[y].dataType);Te(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(Cn.includes(n)&&a>=1&&a<=4){let o=n[4],i=En[o][a];if(i)return i}return K(r)?r:R}function Gr(e){if(K(e)){if(q(e))return e.elementType;if(e.type in Vr)return Vr[e.type]}return R}function ce(e){if(W(e)||O(e))return ce(e.value);if(typeof e=="string")return R;if(typeof e=="number")return Rt(String(e))?.dataType??R;if(typeof e=="boolean")return ge;if("kind"in e){let t=e.kind;if(t in Er)return Er[t]}return K(e)?e:R}function Rt(e){if(/^0x[0-9a-f]+$/i.test(e))return{value:e,dataType:je};if(/^0b[01]+$/i.test(e))return{value:`${Number.parseInt(e.slice(2),2)}`,dataType:je};if(/^-?(?:\d+\.\d*|\d*\.\d+)$/i.test(e))return{value:e,dataType:At};if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return{value:e,dataType:At};if(/^-?\d+$/i.test(e))return{value:e,dataType:je}}var G={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:Be(e[y].dataType,String(t))}},G)}};function _e(e){let t=e;for(;O(t)||W(t)||ne(t)||Ke(t);)t=t.value;return t}function $r(e,t){return new Bt(e,t)}var Bt=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 re()?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.dataType}},G):this._value}};function $(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function oe(e,t){for(let[r,n]of Object.entries(t))e[r]=n,$(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function kr(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 I(a)&&i!==void 0?[[i,a]]:[]})))}function ye(e,t,r){let n=e.match(/->(?<output>.*?){/s),a=n?n[1]?.trim():void 0;I(t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function Vn(e){return new RegExp(`(?<![\\w_.])${e.replaceAll(".","\\.")}(?![\\w_])`,"g")}function ie(e,t,r){return Object.entries(t).reduce((n,[a,o])=>M(o)||qe(o)?n.replaceAll(Vn(a),e.resolve(o)):o!==null&&typeof o=="object"?([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.")}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(s=>s[1])??[]).reduce((s,l)=>l&&l in o?ie(e,{[`${a}.${l}`]:o[l]},s):s,n):n,r)}function Or(e){return new _t(e)}var _t=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)oe(r,a);let n=ie(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var Wr=new WeakMap;function Mr(e){return Wr.get(e)}function Nr(e,t,r){return Wr.set(e,{ast:t,externals:r}),e}function Y(e,t){let r=[];return typeof t=="string"&&(kr(t,e.argTypes,n=>r.push(n)),ye(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){let o={};for(let s of r)oe(o,s);let i=n.names.makeUnique(this.label);if(typeof t=="string"){let s=ie(n,o,t.trim());n.addDeclaration(`${a}fn ${i}${s}`)}else{let s=Mr(t);if(s?.externals){let T=Object.fromEntries(Object.entries(s.externals).filter(([f])=>!(f in o)));oe(o,T)}let l=s?.ast??n.transpileFn(String(t)),u=l.externalNames.filter(T=>!(T in o));if(u.length>0)throw new St(this.label,u);let d=l.argNames.map((T,f)=>({value:T,dataType:e.argTypes[f]})),{head:m,body:g}=n.fnToWgsl({args:d,returnType:e.returnType,body:l.body,externalMap:o});n.addDeclaration(`${a}fn ${i}${n.resolve(m)}${n.resolve(g)}`)}return i}}}function zr(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(He(n))return[r,n];let a=H(n);return a!==void 0?(t=a+1,[r,n]):[r,Lr(n,{type:"@location",value:t++})]}))}function Qe(e){return E(e)?H(e)!==void 0?e:Cr(0,e):It(zr(e))}function xe(e){return It(zr(e))}function jr(e){return{argTypes:[xe(e.in??{})],returnType:void 0,workgroupSize:[e.workgroupSize[0]??1,e.workgroupSize[1]??1,e.workgroupSize[2]??1],does(t){return Gn(this,e.workgroupSize,t)}}}function Gn(e,t,r){let n=Y(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,$(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){return n.resolve(o,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){return`computeFn:${this.label??"<unnamed>"}`}}}function Kr(e,t){return{argTypes:e,returnType:t,does(r){return kn(this,r)}}}function Pt(e){return e?.resourceType==="function"}function $n([e,t]){return`${e.label??"<unnamed>"}=${t}`}function kn(e,t){let r=Y(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 qr(o,[[ne(i)?i.slot:i,s]])},"~resolve"(i){return r.resolve(i)}},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 Xe(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 qr(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 qr(a,[...t,[ne(o)?o.slot:o,i]])}},n=Ut((...o)=>e(...o),(...o)=>({value:new Xe(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($n).join(", ")}]`}}),Object.defineProperty(a,y,{value:{implementation:e[y].implementation}}),a}var Xe=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 Jr(e){return{argTypes:[xe(e.in??{})],targets:e.out,returnType:Qe(e.out),does(t){return On(this,t)}}}function On(e,t){let r=Y(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&ye(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.$name(`${i}_Output`),$(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 Hr(e){return{attributes:[e.in??{}],returnType:Qe(e.out),argTypes:[xe(e.in??{})],does(t){return Wn(this,t)}}}function Wn(e,t){let r=Y(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&ye(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.$name(`${o}_Output`),$(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 Q=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++}`}},X=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 Yr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function Pe(e){return typeof e?.format=="string"}function Qr(e,t){let r=[];if(E(e)){if(!Pe(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:H(e)??0}]}]}}let n=[],a=new WeakMap,o=0;for(let[i,s]of Object.entries(e)){if(He(s))continue;let l=t[i];if(!l)throw new Error(`An attribute by the name of '${i}' was not provided to the shader.`);let u=l._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=H(s)??o,d.push({format:l.format,offset:l.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var Mn=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function Nn(e){return Mn.includes(e.type)}function Lt(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(`
1
+ import{Z as F,_ as W,a as _r,aa as V,b as Lr,ba as c,c as ce,d as Qe,da as Vr,e as Y,f as Cr,g as Q,ga as Er,h as _,i as Ce,ia as Xe,ja as xe,ka as Ct,la as kr}from"./chunk-HZAXWB4J.js";import{$ as b,A as Pt,B as x,C as _e,D as R,E as P,F as _t,G as qe,H as He,I as Je,K as Te,L as Lt,M as O,N as v,O as B,P as l,Q as Le,T as Ar,U as Ur,V as Ir,W as Br,X as Rr,Y as Ye,Z as C,_ as G,a as Ue,b as me,ba as Pr,c as vt,d as Dt,e as Ft,f as ae,g as Ie,h as Be,ha as ye,i as Dr,j,k as At,l as Ut,m as oe,n as y,o as Fr,p as It,q as Bt,r as L,s as Re,t as H,u as J,v as Rt,w as se,x as Pe,y as ge,z as fe}from"./chunk-T5Y2EQPZ.js";function E(e){return e?.resourceType==="slot"}function k(e){return e?.resourceType==="derived"}function Ve(e){return e?.["~providing"]!==void 0}function ie(e){return e?.resourceType==="accessor"}var A={type:"unknown"};function Vt(e){return typeof e?.["~resolve"]=="function"}function z(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||Vt(e)||C(e)||E(e)||k(e)||Ve(e)}function $r(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function Ze(e){return e?.resourceType==="buffer-usage"}function Or(e){return!!e&&typeof e=="object"&&!!e?.[y]?.dataType}function Gr(e){return!!e?.[y]}var Mn=["vec2f","vec2h","vec2i","vec2u","vec2<bool>","vec3f","vec3h","vec3i","vec3u","vec3<bool>","vec4f","vec4h","vec4i","vec4u","vec4<bool>","struct"],Nn={f:{1:l,2:L,3:se,4:x},h:{1:Le,2:Re,3:Pe,4:_e},i:{1:B,2:H,3:ge,4:R},u:{1:v,2:J,3:fe,4:P},b:{1:O,2:Rt,3:Pt,4:_t}},Wr={vec2f:L,vec2h:Re,vec2i:H,vec2u:J,"vec2<bool>":Rt,vec3f:se,vec3h:Pe,vec3i:ge,vec3u:fe,"vec3<bool>":Pt,vec4f:x,vec4h:_e,vec4i:R,vec4u:P,"vec4<bool>":_t,mat2x2f:qe,mat3x3f:He,mat4x4f:Je},Mr={vec2f:l,vec2h:Le,vec2i:B,vec2u:v,"vec2<bool>":O,vec3f:l,vec3h:Le,vec3i:B,vec3u:v,"vec3<bool>":O,vec4f:l,vec4h:Le,vec4i:B,vec4u:v,"vec4<bool>":O,mat2x2f:L,mat3x3f:se,mat4x4f:x};function be(e,t){if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return A;if(k(e)||E(e)){let o=j();if(!o)throw new Error("Resolution context not found when unwrapping slot or derived");let s=o.unwrap(e);return he(s)}let r=e;for(Or(r)&&(r=r[y].dataType);ye(r);)r=r.inner;let n="kind"in r?r.kind:r.type;if(n==="struct")return r.propTypes[t]??A;let a=t.length;if(Mn.includes(n)&&a>=1&&a<=4){let o=n.includes("bool")?"b":n[4],s=Nn[o][a];if(s)return s}return C(r)?r:A}function Nr(e){if(C(e)){if(G(e))return e.elementType;if(e.type in Mr)return Mr[e.type]}return A}function he(e){if(k(e)||E(e))return he(e.value);if(typeof e=="string")return A;if(typeof e=="number")return Et(String(e))?.dataType??A;if(typeof e=="boolean")return O;if("kind"in e){let t=e.kind;if(t in Wr)return Wr[t]}return C(e)?e:A}function Et(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:Lt};if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return{value:e,dataType:Lt};if(/^-?\d+$/i.test(e))return{value:e,dataType:Te}}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:()=>`.value(...).${String(t)}:${e.label??"<unnamed>"}`,[y]:{dataType:be(e[y].dataType,String(t))}},M)}};function Ee(e){let t=e;for(;E(t)||k(t)||ie(t)||Ze(t);)t=t.value;return t}function jr(e,t){return new kt(e,t)}var kt=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 oe()?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${this.label??"<unnamed>"}`,[y]:{dataType:this.dataType}},M):this._value}};function N(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,N(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function zr(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 s=n?n[o]:void 0;return b(a)&&s!==void 0?[[s,a]]:[]})))}function we(e,t,r){let n=e.match(/->\s(?<output>[\w\d_]+)\s{/),a=n?n[1]?.trim():void 0;b(t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function jn(e){return new RegExp(`(?<![\\w\\$_.])${e.replaceAll(".","\\.").replaceAll("$","\\$")}(?![\\w\\$_])`,"g")}function ue(e,t,r){return Object.entries(t).reduce((n,[a,o])=>z(o)||ce(o)?n.replaceAll(jn(a),e.resolve(o)):o!==null&&typeof o=="object"?([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.").replaceAll("$","\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`,"g"))].map(i=>i[1])??[]).reduce((i,p)=>p&&p in o?ue(e,{[`${a}.${p}`]:o[p]},i):i,n):n,r)}function Kr(e){return new $t(e)}var $t=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=ue(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var qr=new WeakMap;function Hr(e){return qr.get(e)}function Jr(e,t,r){return qr.set(e,{ast:t,externals:r}),e}function Yr(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 Qr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function ke(e){return typeof e?.format=="string"}function Xr(e,t){let r=[];if(_(e)){if(!ke(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[s,i]of Object.entries(e)){if(Xe(i))continue;let p=t[s];if(!p)throw new Error(`An attribute by the name of '${s}' 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(i)??o,d.push({format:p.format,offset:p.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var zn=["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 Kn(e){return zn.includes(e.type)}function Ot(e,[t,r]){return` ${xe(r)}${t}: ${e.resolve(r)},
2
+ `}function qn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
- ${Object.entries(t.propTypes).map(n=>Lt(e,n)).join("")}}
5
- `),r}function jn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
4
+ ${Object.entries(t.propTypes).map(n=>Ot(e,n)).join("")}}
5
+ `),r}function Hn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
6
6
  struct ${r} {
7
- ${Object.entries(t.propTypes).map(n=>Pe(n[1])?Lt(e,[n[0],Re[n[1].format]]):Lt(e,n)).join("")}
7
+ ${Object.entries(t.propTypes).map(n=>ke(n[1])?Ot(e,[n[0],Ce[n[1].format]]):Ot(e,n)).join("")}
8
8
  }
9
- `),r}function Kn(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function qn(e,t){let r=e.resolve(Pe(t.elementType)?Re[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Ct(e,t){if(qe(t))return t.type==="unstruct"?jn(e,t):t.type==="disarray"?qn(e,t):t.type==="loose-decorated"?e.resolve(Pe(t.inner)?Re[t.inner.format]:t.inner):e.resolve(Re[t.type]);if(Nn(t))return t.type;if(t.type==="struct")return zn(e,t);if(t.type==="array")return Kn(e,t);if(t.type==="atomic")return`atomic<${Ct(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 Hn=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"],Yn=["&&","||","==","!=","<","<=",">",">="];function Xr(e,t,r){return r?Yn.includes(t)?ge:t==="="?r:e:t==="!"||t==="~"?ge:e}function w(e,t){return M(t.value)?e.resolve(t.value):String(t.value)}function Qn(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function Zr(e,t){return{value:t?"true":"false",dataType:ge}}function en(e,t){e.pushBlockScope();try{return`${e.indent()}{
10
- ${t.b.map(r=>se(e,r)).join(`
9
+ `),r}function Jn(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Yn(e,t){let r=e.resolve(ke(t.elementType)?Ce[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Gt(e,t){if(ce(t))return t.type==="unstruct"?Hn(e,t):t.type==="disarray"?Yn(e,t):t.type==="loose-decorated"?e.resolve(ke(t.inner)?Ce[t.inner.format]:t.inner):e.resolve(Ce[t.type]);if(Kn(t))return t.type;if(t.type==="struct")return qn(e,t);if(t.type==="array")return Jn(e,t);if(t.type==="atomic")return`atomic<${Gt(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");if(t.type==="void")throw new Error("Void has no representation in WGSL");Qr(t,"resolveData")}var Xn=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"],Zn=["&&","||","==","!=","<","<=",">",">="];function Zr(e,t,r){return r?Zn.includes(t)?O:t==="="?r:e:t==="!"||t==="~"?O:e}function h(e,t){return z(t.value)?e.resolve(t.value):String(t.value)}function ea(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function en(e,t){return{value:t?"true":"false",dataType:O}}function tn(e,t){e.pushBlockScope();try{return`${e.indent()}{
10
+ ${t.b.map(r=>pe(e,r)).join(`
11
11
  `)}
12
- ${e.dedent()}}`}finally{e.popBlockScope()}}function Xn(e,t,r){return e.defineVariable(t,r)}function Et(e,t){let r=e.getById(t);if(!r)throw new Error(`Identifier ${t} not found`);return r}function F(e,t){if(typeof t=="string")return Et(e,t);if(typeof t=="boolean")return Zr(e,t);if("x"in t){let[r,n,a]=t.x,o=F(e,r),i=F(e,a),s=w(e,o),l=w(e,i),u=Xr(o.dataType,n,i.dataType);return{value:Hn.includes(n)?`(${s} ${n} ${l})`:`${s} ${n} ${l}`,dataType:u}}if("p"in t){let[r,n]=t.p,a=F(e,n);return{value:`${w(e,a)}${r}`,dataType:a.dataType}}if("u"in t){let[r,n]=t.u,a=F(e,n),o=w(e,a),i=Xr(a.dataType,r);return{value:`${r}${o}`,dataType:i}}if("a"in t){let[r,n]=t.a,a=F(e,r);if(typeof a.value=="string")return{value:`${a.value}.${n}`,dataType:Be(a.dataType,n)};let o=a.value[n];if(M(a.value))return{value:o,dataType:Be(a.value,n)};if(typeof a.value=="object"){let i=M(o)?ce(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=F(e,r),o=F(e,n),i=w(e,a),s=w(e,o);return{value:`${i}[${s}]`,dataType:Gr(a.dataType)}}if("n"in t){let r=Rt(t.n);if(!r)throw new Error(`Invalid numeric literal ${t.n}`);return r}if("f"in t){let[r,n]=t.f,a=F(e,r),o=a.value;e.callStack.push(o);let s=n.map(u=>F(e,u)).map(u=>({value:w(e,u),dataType:u.dataType})),l=s.map(u=>u.value);return e.callStack.pop(),typeof o=="string"?{value:`${o}(${l.join(", ")})`,dataType:a.dataType}:I(o)?{value:`${e.resolve(o)}(${l.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=F(e,i);return w(e,s)}).join(", ");if(I(n)){let i=Object.keys(n.propTypes).map(s=>{let l=r[s];if(l===void 0)throw new Error(`Missing property ${s} in object literal for struct ${n}`);return l});return{value:a(i),dataType:n}}return{value:a(Object.values(r)),dataType:R}}if("y"in t){let r=t.y.map(l=>F(e,l));if(r.length===0)throw new Error("Cannot create empty array literal.");let n=r[0]?.dataType,a=r.find(l=>l.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(!K(n))throw new Error("Cannot use non-WGSL data types in array literals.");n=n.type==="abstractInt"?v:n.type==="abstractFloat"?p:n;let i=`array<${e.resolve(n)}, ${r.length}>`,s=r.map(l=>w(e,l));return{value:`${i}( ${s.join(", ")} )`,dataType:Pr(n,r.length)}}if("s"in t)throw new Error("Cannot use string literals in TGSL.");Qn(t)}function se(e,t){if(typeof t=="string")return`${e.pre}${w(e,Et(e,t))};`;if(typeof t=="boolean")return`${e.pre}${w(e,Zr(e,t))};`;if("r"in t){if(I(e.callStack[e.callStack.length-1])&&t.r!==null&&typeof t.r=="object"&&"o"in t.r){let r=w(e,F(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 ${w(e,F(e,t.r))};`}if("q"in t){let[r,n,a]=t.q,o=w(e,F(e,r));e.indent();let i=se(e,n);e.dedent(),e.indent();let s=a?se(e,a):void 0;return e.dedent(),s?`${e.pre}if (${o})
13
- ${i}
12
+ ${e.dedent()}}`}finally{e.popBlockScope()}}function ta(e,t,r){return e.defineVariable(t,r)}function Wt(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 Wt(e,t);if(typeof t=="boolean")return en(e,t);if("x"in t){let[r,n,a]=t.x,o=U(e,r),s=U(e,a),i=h(e,o),p=h(e,s),u=Zr(o.dataType,n,s.dataType);return{value:Xn.includes(n)?`(${i} ${n} ${p})`:`${i} ${n} ${p}`,dataType:u}}if("p"in t){let[r,n]=t.p,a=U(e,n);return{value:`${h(e,a)}${r}`,dataType:a.dataType}}if("u"in t){let[r,n]=t.u,a=U(e,n),o=h(e,a),s=Zr(a.dataType,r);return{value:`${r}${o}`,dataType:s}}if("a"in t){let[r,n]=t.a,a=U(e,r);if(typeof a.value=="string")return{value:`${a.value}.${n}`,dataType:_(a.dataType)?be(a.dataType,n):A};if(G(a.dataType)&&n==="length")return a.dataType.elementCount===0?{value:`arrayLength(&${e.resolve(a.value)})`,dataType:v}:{value:String(a.dataType.elementCount),dataType:Te};let o=a.value[n];if(a.dataType.type!=="unknown")return Ye(a.dataType)&&n==="columns"?{value:a.value,dataType:a.dataType}:{value:o,dataType:be(a.dataType,n)};if(z(a.value))return{value:o,dataType:be(a.value,n)};if(typeof a.value=="object"){let s=z(o)?he(o):A;return{value:o,dataType:s}}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),s=h(e,a),i=h(e,o);return{value:`${s}[${i}]`,dataType:_(a.dataType)?Nr(a.dataType):A}}if("n"in t){let r=Et(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 i=n.map(d=>U(e,d)).map(d=>({value:h(e,d),dataType:d.dataType})),p=i.map(d=>d.value);if(e.callStack.pop(),typeof o=="string")return{value:`${o}(${p.join(", ")})`,dataType:a.dataType};if(b(o))return{value:`${e.resolve(o)}(${p.join(", ")})`,dataType:a.dataType};if(!Gr(o))throw new Error(`Function ${String(o)} has not been created using TypeGPU APIs. Did you mean to wrap the function with tgpu.fn(args, return)(...) ?`);let u=o(...i);return{value:h(e,u),dataType:u.dataType}}if("o"in t){let r=t.o,n=e.callStack[e.callStack.length-1],a=o=>o.map(s=>{let i=U(e,s);return h(e,i)}).join(", ");if(b(n)){let s=Object.keys(n.propTypes).map(i=>{let p=r[i];if(p===void 0)throw new Error(`Missing property ${i} in object literal for struct ${n}`);return p});return{value:a(s),dataType:n}}return{value:a(Object.values(r)),dataType:A}}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(!C(n))throw new Error("Cannot use non-WGSL data types in array literals.");n=n.type==="abstractInt"?v:n.type==="abstractFloat"?l:n;let s=`array<${e.resolve(n)}, ${r.length}>`,i=r.map(p=>h(e,p));return{value:`${s}( ${i.join(", ")} )`,dataType:kr(n,r.length)}}if("s"in t)throw new Error("Cannot use string literals in TGSL.");ea(t)}function pe(e,t){if(typeof t=="string")return`${e.pre}${h(e,Wt(e,t))};`;if(typeof t=="boolean")return`${e.pre}${h(e,en(e,t))};`;if("r"in t){if(b(e.callStack[e.callStack.length-1])&&t.r!==null&&typeof t.r=="object"&&"o"in t.r){let r=h(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 ${h(e,U(e,t.r))};`}if("q"in t){let[r,n,a]=t.q,o=h(e,U(e,r));e.indent();let s=pe(e,n);e.dedent(),e.indent();let i=a?pe(e,a):void 0;return e.dedent(),i?`${e.pre}if (${o})
13
+ ${s}
14
14
  ${e.pre}else
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?F(e,n):void 0;if(!a||!n)throw new Error("Cannot create variable without an initial value.");Xn(e,r,a.dataType);let o=w(e,Et(e,r));if(typeof n=="object"&&"o"in n&&I(e.callStack[e.callStack.length-1])){let i=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}var ${o} = ${i}(${w(e,a)});`}return`${e.pre}var ${o} = ${w(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?se(e,r):void 0,s=i?i.slice(0,-1):"",l=n?F(e,n):void 0,u=l?w(e,l):"",d=a?se(e,a):void 0,m=d?d.slice(0,-1):"";e.indent();let g=se(e,o);return e.dedent(),`${e.pre}for (${s}; ${u}; ${m})
17
- ${g}`}if("w"in t){let[r,n]=t.w,a=w(e,F(e,r));e.indent();let o=se(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}${w(e,F(e,t))};`}function Vt(e,t){return en(e,t)}import{BufferReader as Nt,BufferWriter as zt}from"typed-binary";import{getSystemEndianness as ra}from"typed-binary";import{Measurer as ea}from"typed-binary";function Zn(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 h=Zn;var tn=new WeakMap;function Ze(e){let t=tn.get(e);if(t)return t;let r=new ea,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;h(r,J(e)?V(i):D(i)),a&&(a.padding=r.size-s);let l=c(i);n[o]={offset:r.size,size:l},a=n[o],r.add(l)}return a&&(a.padding=L(c(e),D(e))-r.size),tn.set(e,n),n}var tt=(()=>{try{return new Function("return true"),!0}catch{return!1}})(),Gt=new WeakMap,$t={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"},kt={u32:"setUint32",i32:"setInt32",f32:"setFloat32"};function et(e,t,r){if(Fr(e)||Te(e))return et(e.inner,t,r);if(I(e)||J(e)){let a=Ze(e),o=Object.entries(a).sort((s,l)=>s[1].offset-l[1].offset),i="";for(let[s,l]of o){let u=e.propTypes[s];u&&(i+=et(u,`(${t} + ${l.offset})`,`${r}.${s}`))}return i}if(q(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+=et(a.elementType,`(${t} + i * ${o})`,`${r}[i]`),i+=`}
20
- `,i}if(wr(e)){let a=$t[e.type],o="",i=kt[a],s=["x","y","z","w"],l=hr(e)?2:br(e)?3:4;for(let u=0;u<l;u++)o+=`output.${i}((${t} + ${u*4}), ${r}.${s[u]}, littleEndian);
21
- `;return o}if(Dr(e)){let a=$t[e.type],o=kt[a],i=Sr(e)?2:vr(e)?3:4,s=i*i,l=L(i*4,8),u="";for(let d=0;d<s;d++){let m=Math.floor(d/i),g=d%i,T=m*l+g*4;u+=`output.${o}((${t} + ${T}), ${r}.columns[${m}].${["x","y","z","w"][g]}, littleEndian);
22
- `}return u}let n=$t[e.type];return`output.${kt[n]}(${t}, ${r}, littleEndian);
23
- `}function rt(e){if(Gt.has(e))return Gt.get(e);let t=et(e,"offset","value"),r=new Function("output","offset","value","littleEndian=true",t);return Gt.set(e,r),r}var he={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=D(t);h(e,n);for(let[a,o]of Object.entries(t.propTypes))h(e,D(o)),Z(e,o,r[a]);h(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=D(t);h(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)h(e,n),Z(e,t.elementType,r[o]);e.seekTo(a+c(t))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){he[t.inner.type]?.(e,t,r)},decorated(e,t,r){let n=V(t);h(e,n);let a=e.currentByteOffset;he[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);h(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)h(e,n),he[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))he[a.type]?.(e,a,r[n])},"loose-decorated"(e,t,r){let n=V(t);h(e,n);let a=e.currentByteOffset,o=he[t.inner?.type];return o?.(e,t.inner,r),e.seekTo(a+c(t)),r}};function Z(e,t,r){let n=he[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var ue={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 P(e.readFloat32(),e.readFloat32())},vec3f(e){return ae(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return x(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return Fe(e.readFloat16(),e.readFloat16())},vec3h(e){return Ue(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return Ae(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return z(e.readInt32(),e.readInt32())},vec3i(e){return me(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())},mat2x2f(e){return Me(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return Ne(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return ze(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);h(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))h(e,D(o)),n[a]=C(e,o);return h(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++){h(e,r);let o=t.elementType,i=C(e,o);n.push(i)}return h(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=V(t);h(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=>z(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=>z(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(ue.snorm16(e),ue.snorm16(e)),snorm16x4:e=>x(ue.snorm16(e),ue.snorm16(e),ue.snorm16(e),ue.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=>ae(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=>z(e.readInt32(),e.readInt32()),sint32x3:e=>me(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++)h(e,r),n.push(C(e,t.elementType));return h(e,r),n},"loose-decorated"(e,t){h(e,V(t));let r=e.currentByteOffset,n=C(e,t.inner);return e.seekTo(r+c(t)),n}};function C(e,t){let r=ue[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}import{BufferWriter as ta}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 ta(n),o=[];function i(u,d,m,g){if(d!=null){if(I(u)||J(u)){let T=Ze(u);for(let[f,S]of Object.entries(T)){let b=u.propTypes[f];if(!b)continue;let U=d[f];U!==void 0&&i(b,U,m+S.offset,S.padding??g)}return}if(q(u)||Je(u)){let T=u,f=L(c(T.elementType),D(T.elementType));if(!Array.isArray(d))throw new Error("Partial value for array must be an array");let S=d;S.sort((b,U)=>b.idx-U.idx);for(let{idx:b,value:U}of S)i(T.elementType,U,m+b*f,f-c(T.elementType))}else{let T=c(u);a.seekTo(m),Z(a,u,d),o.push({start:m,end:m+T,padding:g})}}}if(i(e,t,0),o.length===0)return[];let s=[],l=o[0];for(let u=1;u<o.length;u++){let d=o[u];if(!d||!l)throw new Error("Internal error: missing segment");d.start===l.end+(l.padding??0)?(l.end=d.end,l.padding=d.padding):(s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),l=d)}if(!l)throw new Error("Internal error: missing segment");return s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),s}function pe(e){return!!e?.usableAsStorage}var Le=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 nt(e){return!!e.usableAsUniform}var sn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Ce=class{constructor(t,r){this.usage=t;this.buffer=r;this[y]={dataType:r.dataType}}"~repr";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(!re())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}},G)}},Ee=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;this[y]={dataType:r}}"~repr";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(!re())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}},G)}},nn=new WeakMap;function Ot(e){if(!pe(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 Ce("mutable",e),nn.set(e,t)),t}var an=new WeakMap;function Wt(e){if(!pe(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 Ce("readonly",e),an.set(e,t)),t}var on=new WeakMap;function Mt(e){if(!nt(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 Ce("uniform",e),on.set(e,t)),t}var na={uniform:Mt,mutable:Ot,readonly:Wt};function pn(e,t,r){return K(t)?new at(e,t,r):new at(e,t,r,["storage","uniform"])}function ee(e){return e.resourceType==="buffer"}function aa(e){return!!e.usableAsVertex}var un=ra(),at=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;Ar(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 zt(this._buffer.getMappedRange());Z(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(tt)rt(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(tt){rt(this.dataType)(new DataView(o),0,t,un==="little");return}Z(new zt(o),this.dataType,t);return}let a=c(this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),tt?rt(this.dataType)(new DataView(this._hostBuffer),0,t,un==="little"):Z(new zt(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 Nt(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),s=C(new Nt(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 Nt(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(t){return na[t]?.(this)}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&this._buffer?.destroy())}toString(){return`buffer:${this._label??"<unnamed>"}`}};function ln(e){return new jt(e)}function dn(e){return new Kt(e)}function Ve(e){return e?.resourceType==="sampler"}function Ge(e){return e?.resourceType==="sampler-comparison"}var ot=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>"}`}},it=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>"}`}},jt=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>"}`}},Kt=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 st=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:p,r8snorm:p,r8uint:v,r8sint:A,r16uint:v,r16sint:A,r16float:p,rg8unorm:p,rg8snorm:p,rg8uint:v,rg8sint:A,r32uint:v,r32sint:A,r32float:p,rg16uint:v,rg16sint:A,rg16float:p,rgba8unorm:p,"rgba8unorm-srgb":p,rgba8snorm:p,rgba8uint:v,rgba8sint:A,bgra8unorm:p,"bgra8unorm-srgb":p,rgb9e5ufloat:p,rgb10a2uint:v,rgb10a2unorm:p,rg11b10ufloat:p,rg32uint:v,rg32sint:A,rg32float:p,rgba16uint:v,rgba16sint:A,rgba16float:p,rgba32uint:v,rgba32sint:A,rgba32float:p,stencil8:p,depth16unorm:p,depth24plus:p,"depth24plus-stencil8":p,depth32float:p,"depth32float-stencil8":p,"bc1-rgba-unorm":p,"bc1-rgba-unorm-srgb":p,"bc2-rgba-unorm":p,"bc2-rgba-unorm-srgb":p,"bc3-rgba-unorm":p,"bc3-rgba-unorm-srgb":p,"bc4-r-unorm":p,"bc4-r-snorm":p,"bc5-rg-unorm":p,"bc5-rg-snorm":p,"bc6h-rgb-ufloat":p,"bc6h-rgb-float":p,"bc7-rgba-unorm":p,"bc7-rgba-unorm-srgb":p,"etc2-rgb8unorm":p,"etc2-rgb8unorm-srgb":p,"etc2-rgb8a1unorm":p,"etc2-rgb8a1unorm-srgb":p,"etc2-rgba8unorm":p,"etc2-rgba8unorm-srgb":p,"eac-r11unorm":p,"eac-r11snorm":p,"eac-rg11unorm":p,"eac-rg11snorm":p,"astc-4x4-unorm":p,"astc-4x4-unorm-srgb":p,"astc-5x4-unorm":p,"astc-5x4-unorm-srgb":p,"astc-5x5-unorm":p,"astc-5x5-unorm-srgb":p,"astc-6x5-unorm":p,"astc-6x5-unorm-srgb":p,"astc-6x6-unorm":p,"astc-6x6-unorm-srgb":p,"astc-8x5-unorm":p,"astc-8x5-unorm-srgb":p,"astc-8x6-unorm":p,"astc-8x6-unorm-srgb":p,"astc-8x8-unorm":p,"astc-8x8-unorm-srgb":p,"astc-10x5-unorm":p,"astc-10x5-unorm-srgb":p,"astc-10x6-unorm":p,"astc-10x6-unorm-srgb":p,"astc-10x8-unorm":p,"astc-10x8-unorm-srgb":p,"astc-10x10-unorm":p,"astc-10x10-unorm-srgb":p,"astc-12x10-unorm":p,"astc-12x10-unorm-srgb":p,"astc-12x12-unorm":p,"astc-12x12-unorm-srgb":p},$e={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},fn={f32:"float",u32:"uint",i32:"sint"},gn={float:p,"unfilterable-float":p,uint:v,sint:A,depth:p};function Tn(e,t){return new qt(e,t)}function N(e){return e?.resourceType==="texture"}function ke(e){return e?.resourceType==="texture-storage-view"}function Oe(e){return e?.resourceType==="texture-sampled-view"}var cn={mutable:"read_write",readonly:"read",writeonly:"write"},qt=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=$e[n];return Se(!!a,`Unsupported storage texture format: ${n}`),new Jt(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(!$e[r])throw new Error(`Unsupported storage texture format: ${r}`);return new Ht(t,this)}destroy(){this._destroyed||(this._destroyed=!0,this._texture?.destroy())}},lt={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Jt=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=$e[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_${lt[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>"}`}},ut=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;this.texelDataType=$e[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_${lt[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>"}`}},Ht=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:fn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${lt[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},pt=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;this.channelDataType=gn[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_${lt[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 Yt(e){return!!e?.usableAsSampled}function oa(e){return!!e?.usableAsRender}var dt=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 mt(e){return new Xt(e)}function ft(e){return!!e&&e.resourceType==="bind-group-layout"}function Zt(e){return!!e&&e.resourceType==="bind-group"}var Qt=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"],be=["compute","vertex","fragment"],Xt=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 Ee("uniform",a.uniform,o)),"storage"in a){let i="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Ee(a.access??"readonly",i,o)}"texture"in a&&(this.bound[n]=new pt(a.texture,a.viewDimension??"2d",a.multisampled??!1,o)),"storageTexture"in a&&(this.bound[n]=new ut(a.storageTexture,a.viewDimension??"2d",a.access??"writeonly",o)),"externalTexture"in a&&(this.bound[n]=new st(o)),"sampler"in a&&(a.sampler==="comparison"?this.bound[n]=new it(o):this.bound[n]=new ot(o)),r++}}_label;_index;resourceType="bind-group-layout";bound={};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??be,i.buffer={type:"uniform"};else if("storage"in n)o=o??(n.access==="mutable"?yn:be),i.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=o??be,i.sampler={type:n.sampler};else if("texture"in n)o=o??be,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"?be: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??be,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 le(this,t)}},le=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 Qt(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(ee(i)){if(!nt(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(ee(i)){if(!pe(i))throw new Le(i);s={buffer:t.unwrap(i)}}else s={buffer:i};return{binding:o,resource:s}}if("texture"in a){let s;if(N(i)){if(!Yt(i))throw new dt(i);s=t.unwrap(i.createView("sampled"))}else Oe(i)?s=t.unwrap(i):s=i;return{binding:o,resource:s}}if("storageTexture"in a){let s;if(N(i)){if(!pe(i))throw new Le(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 ke(i)?s=t.unwrap(i):s=i;return{binding:o,resource:s}}if("sampler"in a)return Ve(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#",tr=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:M(o)?ce(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.")}},gt=[""," "," "," "," "," "," "," "," "],er=gt.length-1,rr=class{identLevel=0;get pre(){return gt[this.identLevel]??gt[er].repeat(this.identLevel/er)+gt[this.identLevel%er]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},nr=class{_memoizedResolves=new WeakMap;_memoizedDerived=new WeakMap;_indentController=new rr;_jitTranspiler;_itemStateStack=new tr;_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{let r=Vt(this,t.body),n=t.args.map(a=>`${a.value}: ${this.resolve(a.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${Ye(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: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(Ft(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(O(r))r=this.readSlot(r);else if(W(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,l])=>s.areEqual(this._itemStateStack.readSlot(s),l)))return o.result;vt(De.CPU);let n;try{n=t["~compute"]()}finally{Dt(De.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 de?n.appendToTrace(t):new de(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,l])=>s.areEqual(this._itemStateStack.readSlot(s),l)))return o.result;let n;E(t)?n=Ct(this,t):W(t)||O(t)?n=this.resolve(this.unwrap(t)):Ur(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 de?n.appendToTrace(t):new de(n,[t])}finally{this._itemStateStack.popItem()}}resolve(t){if(Ft(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(De.GPU);let r=yr(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
15
+ ${i}`:`${e.pre}if (${o})
16
+ ${s}`}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.");if(ce(a.dataType))throw new Error("Cannot create variable with loose data type.");ta(e,r,a.dataType);let o=h(e,Wt(e,r));if(typeof n=="object"&&"o"in n&&b(e.callStack[e.callStack.length-1])){let s=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}var ${o} = ${s}(${h(e,a)});`}return`${e.pre}var ${o} = ${h(e,a)};`}if("b"in t){e.pushBlockScope();try{return tn(e,t)}finally{e.popBlockScope()}}if("j"in t){let[r,n,a,o]=t.j,s=r?pe(e,r):void 0,i=s?s.slice(0,-1):"",p=n?U(e,n):void 0,u=p?h(e,p):"",d=a?pe(e,a):void 0,m=d?d.slice(0,-1):"";e.indent();let T=pe(e,o);return e.dedent(),`${e.pre}for (${i}; ${u}; ${m})
17
+ ${T}`}if("w"in t){let[r,n]=t.w,a=h(e,U(e,r));e.indent();let o=pe(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}${h(e,U(e,t))};`}function rn(e,t){return tn(e,t)}import{BufferReader as Ht,BufferWriter as Jt}from"typed-binary";import{getSystemEndianness as oa}from"typed-binary";import{Measurer as na}from"typed-binary";function ra(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 w=ra;var nn=new WeakMap;function et(e){let t=nn.get(e);if(t)return t;let r=new na,n={},a;for(let o in e.propTypes){let s=e.propTypes[o];if(s===void 0)throw new Error(`Property ${o} is undefined in struct`);let i=r.size;w(r,Y(e)?W(s):F(s)),a&&(a.padding=r.size-i);let p=c(s);n[o]={offset:r.size,size:p},a=n[o],r.add(p)}return a&&(a.padding=V(c(e),F(e))-r.size),nn.set(e,n),n}var rt=(()=>{try{return new Function("return true"),!0}catch{return!1}})(),Mt=new WeakMap,Nt={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"},jt={u32:"setUint32",i32:"setInt32",f32:"setFloat32"};function tt(e,t,r){if(Pr(e)||ye(e))return tt(e.inner,t,r);if(b(e)||Y(e)){let a=et(e),o=Object.entries(a).sort((i,p)=>i[1].offset-p[1].offset),s="";for(let[i,p]of o){let u=e.propTypes[i];u&&(s+=tt(u,`(${t} + ${p.offset})`,`${r}.${i}`))}return s}if(G(e)||Qe(e)){let a=e,o=V(c(a.elementType),F(a.elementType)),s="";return s+=`for (let i = 0; i < ${a.elementCount}; i++) {
19
+ `,s+=tt(a.elementType,`(${t} + i * ${o})`,`${r}[i]`),s+=`}
20
+ `,s}if(Ir(e)){let a=Nt[e.type],o="",s=jt[a],i=["x","y","z","w"],p=Ar(e)?2:Ur(e)?3:4;for(let u=0;u<p;u++)o+=`output.${s}((${t} + ${u*4}), ${r}.${i[u]}, littleEndian);
21
+ `;return o}if(Ye(e)){let a=Nt[e.type],o=jt[a],s=Br(e)?2:Rr(e)?3:4,i=s*s,p=V(s*4,8),u="";for(let d=0;d<i;d++){let m=Math.floor(d/s),T=d%s,f=m*p+T*4;u+=`output.${o}((${t} + ${f}), ${r}.columns[${m}].${["x","y","z","w"][T]}, littleEndian);
22
+ `}return u}let n=Nt[e.type];return`output.${jt[n]}(${t}, ${r}, littleEndian);
23
+ `}function nt(e){if(Mt.has(e))return Mt.get(e);let t=tt(e,"offset","value"),r=new Function("output","offset","value","littleEndian=true",t);return Mt.set(e,r),r}var Se={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=F(t);w(e,n);for(let[a,o]of Object.entries(t.propTypes))w(e,F(o)),X(e,o,r[a]);w(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=F(t);w(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)w(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){Se[t.inner.type]?.(e,t,r)},decorated(e,t,r){let n=W(t);w(e,n);let a=e.currentByteOffset;Se[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=F(t);w(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)w(e,n),Se[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))Se[a.type]?.(e,a,r[n])},"loose-decorated"(e,t,r){let n=W(t);w(e,n);let a=e.currentByteOffset,o=Se[t.inner?.type];return o?.(e,t.inner,r),e.seekTo(a+c(t)),r}};function X(e,t,r){let n=Se[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var le={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 L(e.readFloat32(),e.readFloat32())},vec3f(e){return se(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return x(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return Re(e.readFloat16(),e.readFloat16())},vec3h(e){return Pe(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _e(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 R(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 P(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 qe(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return He(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return Je(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=F(t);w(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))w(e,F(o)),n[a]=$(e,o);return w(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=F(t),n=[];for(let a=0;a<t.elementCount;a++){w(e,r);let o=t.elementType,s=$(e,o);n.push(s)}return w(e,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return $(e,t.inner)},decorated(e,t){let r=W(t);w(e,r);let n=e.currentByteOffset,a=$(e,t.inner);return e.seekTo(n+c(t)),a},uint8:e=>e.readUint8(),uint8x2:e=>J(e.readUint8(),e.readUint8()),uint8x4:e=>P(e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>H(e.readInt8(),e.readInt8()),sint8x4:e=>R(e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>L(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=>L((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=>P(e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>H(e.readInt16(),e.readInt16()),sint16x4:e=>R(e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>L(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=>L(le.snorm16(e),le.snorm16(e)),snorm16x4:e=>x(le.snorm16(e),le.snorm16(e),le.snorm16(e),le.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>L(e.readFloat16(),e.readFloat16()),float16x4:e=>x(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>L(e.readFloat32(),e.readFloat32()),float32x3:e=>se(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=>P(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=>R(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]=$(e,a);return r},disarray(e,t){let r=F(t),n=[];for(let a=0;a<t.elementCount;a++)w(e,r),n.push($(e,t.elementType));return w(e,r),n},"loose-decorated"(e,t){w(e,W(t));let r=e.currentByteOffset,n=$(e,t.inner);return e.seekTo(r+c(t)),n}};function $(e,t){let r=le[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}import{BufferWriter as aa}from"typed-binary";function an(e,t){let r=c(e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new aa(n),o=[];function s(u,d,m,T){if(d!=null){if(b(u)||Y(u)){let f=et(u);for(let[g,D]of Object.entries(f)){let S=u.propTypes[g];if(!S)continue;let I=d[g];I!==void 0&&s(S,I,m+D.offset,D.padding??T)}return}if(G(u)||Qe(u)){let f=u,g=V(c(f.elementType),F(f.elementType));if(!Array.isArray(d))throw new Error("Partial value for array must be an array");let D=d;D.sort((S,I)=>S.idx-I.idx);for(let{idx:S,value:I}of D)s(f.elementType,I,m+S*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(s(e,t,0),o.length===0)return[];let i=[],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):(i.push({data:new Uint8Array(n,p.start,p.end-p.start)}),p=d)}if(!p)throw new Error("Internal error: missing segment");return i.push({data:new Uint8Array(n,p.start,p.end-p.start)}),i}function de(e){return!!e?.usableAsStorage}var $e=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 at(e){return!!e.usableAsUniform}var pn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Oe=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=pn[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(!oe())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}},M)}},Ge=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=pn[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(!oe())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}},M)}},on=new WeakMap;function zt(e){if(!de(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=on.get(e);return t||(t=new Oe("mutable",e),on.set(e,t)),t}var sn=new WeakMap;function Kt(e){if(!de(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=sn.get(e);return t||(t=new Oe("readonly",e),sn.set(e,t)),t}var un=new WeakMap;function qt(e){if(!at(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=un.get(e);return t||(t=new Oe("uniform",e),un.set(e,t)),t}var sa={uniform:qt,mutable:zt,readonly:Kt};function dn(e,t,r){return C(t)?new ot(e,t,r):new ot(e,t,r,["storage","uniform"])}function Z(e){return e.resourceType==="buffer"}function ia(e){return!!e.usableAsVertex}var ln=oa(),ot=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;$r(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 Jt(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(rt)nt(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(rt){nt(this.dataType)(new DataView(o),0,t,ln==="little");return}X(new Jt(o),this.dataType,t);return}let a=c(this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),rt?nt(this.dataType)(new DataView(this._hostBuffer),0,t,ln==="little"):X(new Jt(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=an(this.dataType,t);if(r.mapState==="mapped"){let o=r.getMappedRange(),s=new Uint8Array(o);for(let i of a)s.set(i.data,i.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 s=t.getMappedRange();return $(new Ht(s),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let s=t.getMappedRange(),i=$(new Ht(s),this.dataType);return t.unmap(),i}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=$(new Ht(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(t){return sa[t]?.(this)}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&this._buffer?.destroy())}toString(){return`buffer:${this._label??"<unnamed>"}`}};function mn(e){return new Yt(e)}function gn(e){return new Qt(e)}function We(e){return e?.resourceType==="sampler"}function Me(e){return e?.resourceType==="sampler-comparison"}var st=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>"}`}},it=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>"}`}},Yt=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>"}`}},Qt=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 ut=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 fn={r8unorm:l,r8snorm:l,r8uint:v,r8sint:B,r16uint:v,r16sint:B,r16float:l,rg8unorm:l,rg8snorm:l,rg8uint:v,rg8sint:B,r32uint:v,r32sint:B,r32float:l,rg16uint:v,rg16sint:B,rg16float:l,rgba8unorm:l,"rgba8unorm-srgb":l,rgba8snorm:l,rgba8uint:v,rgba8sint:B,bgra8unorm:l,"bgra8unorm-srgb":l,rgb9e5ufloat:l,rgb10a2uint:v,rgb10a2unorm:l,rg11b10ufloat:l,rg32uint:v,rg32sint:B,rg32float:l,rgba16uint:v,rgba16sint:B,rgba16float:l,rgba32uint:v,rgba32sint:B,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},Ne={rgba8unorm:x,rgba8snorm:x,rgba8uint:P,rgba8sint:R,rgba16uint:P,rgba16sint:R,rgba16float:x,r32uint:P,r32sint:R,r32float:x,rg32uint:P,rg32sint:R,rg32float:x,rgba32uint:P,rgba32sint:R,rgba32float:x,bgra8unorm:x},Tn={f32:"float",u32:"uint",i32:"sint"},yn={float:l,"unfilterable-float":l,uint:v,sint:B,depth:l};function cn(e,t){return new Xt(e,t)}function q(e){return e?.resourceType==="texture"}function je(e){return e?.resourceType==="texture-storage-view"}function ze(e){return e?.resourceType==="texture-sampled-view"}var xn={mutable:"read_write",readonly:"read",writeonly:"write"},Xt=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=Ne[n];return Ue(!!a,`Unsupported storage texture format: ${n}`),new Zt(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(!Ne[r])throw new Error(`Unsupported storage texture format: ${r}`);return new er(t,this)}destroy(){this._destroyed||(this._destroyed=!0,this._texture?.destroy())}},dt={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Zt=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=Ne[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_${dt[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${xn[this.access]}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},pt=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;this.texelDataType=Ne[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_${dt[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${xn[this.access]}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},er=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=fn[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:Tn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${dt[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${s}<${t.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${this.label??"<unnamed>"}`}},lt=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;this.channelDataType=yn[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_${dt[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 tr(e){return!!e?.usableAsSampled}function ua(e){return!!e?.usableAsRender}var mt=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 gt(e){return new nr(e)}function ft(e){return!!e&&e.resourceType==="bind-group-layout"}function ar(e){return!!e&&e.resourceType==="bind-group"}var rr=class e extends Error{constructor(t,r){super(`Bind group '${t??"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},bn=["compute"],ve=["compute","vertex","fragment"],nr=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 Ge("uniform",a.uniform,o)),"storage"in a){let s="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Ge(a.access??"readonly",s,o)}"texture"in a&&(this.bound[n]=new lt(a.texture,a.viewDimension??"2d",a.multisampled??!1,o)),"storageTexture"in a&&(this.bound[n]=new pt(a.storageTexture,a.viewDimension??"2d",a.access??"writeonly",o)),"externalTexture"in a&&(this.bound[n]=new ut(o)),"sampler"in a&&(a.sampler==="comparison"?this.bound[n]=new it(o):this.bound[n]=new st(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,s={binding:a,visibility:0};if("uniform"in n)o=o??ve,s.buffer={type:"uniform"};else if("storage"in n)o=o??(n.access==="mutable"?bn:ve),s.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=o??ve,s.sampler={type:n.sampler};else if("texture"in n)o=o??ve,s.texture={sampleType:n.texture,viewDimension:n.viewDimension??"2d",multisampled:n.multisampled??!1};else if("storageTexture"in n){let i=n.access??"writeonly";o=o??(i==="readonly"?ve:bn),s.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[i],viewDimension:n.viewDimension??"2d"}}else"externalTexture"in n&&(o=o??ve,s.externalTexture={});return o?.includes("compute")&&(s.visibility|=GPUShaderStage.COMPUTE),o?.includes("vertex")&&(s.visibility|=GPUShaderStage.VERTEX),o?.includes("fragment")&&(s.visibility|=GPUShaderStage.FRAGMENT),s}).filter(n=>n!==null)})}},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 rr(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 s=this.entries[n];if(s===void 0)throw new Error(`'${n}' is a resource required to populate bind group layout '${this.layout.label??"<unnamed>"}'.`);if("uniform"in a){let i;if(Z(s)){if(!at(s))throw new Dt(s);i={buffer:t.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("storage"in a){let i;if(Z(s)){if(!de(s))throw new $e(s);i={buffer:t.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("texture"in a){let i;if(q(s)){if(!tr(s))throw new mt(s);i=t.unwrap(s.createView("sampled"))}else ze(s)?i=t.unwrap(s):i=s;return{binding:o,resource:i}}if("storageTexture"in a){let i;if(q(s)){if(!de(s))throw new $e(s);a.access==="readonly"?i=t.unwrap(s.createView("readonly")):a.access==="mutable"?i=t.unwrap(s.createView("mutable")):i=t.unwrap(s.createView("writeonly"))}else je(s)?i=t.unwrap(s):i=s;return{binding:o,resource:i}}if("sampler"in a)return We(s)||Me(s)?{binding:o,resource:t.unwrap(s)}:{binding:o,resource:s};if("externalTexture"in a)return{binding:o,resource:s};throw new Error(`Malformed bind group entry: ${s} (${JSON.stringify(s)})`)}).filter(n=>n!==null)})}};var hn="#CATCHALL#",sr=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}getSnippetById(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(s=>s.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:z(o)?he(o):A}: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.")}},Tt=[""," "," "," "," "," "," "," "," "],or=Tt.length-1,ir=class{identLevel=0;get pre(){return Tt[this.identLevel]??Tt[or].repeat(this.identLevel/or)+Tt[this.identLevel%or]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},ur=class{_memoizedResolves=new WeakMap;_memoizedDerived=new WeakMap;_indentController=new ir;_jitTranspiler;_itemStateStack=new sr;_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.getSnippetById(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:pr(this,t.args,t.returnType),body:rn(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:hn,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new vt(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.popSlotBindings()}}unwrap(t){if(Ve(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(E(r))r=this.readSlot(r);else if(k(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(([i,p])=>i.areEqual(this._itemStateStack.readSlot(i),p)))return o.result;At(Be.CPU);let n;try{n=t["~compute"]()}finally{Ut(Be.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(([i,p])=>i.areEqual(this._itemStateStack.readSlot(i),p)))return o.result;let n;_(t)?n=Gt(this,t):k(t)||E(t)?n=this.resolve(this.unwrap(t)):Vt(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(Ve(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(Be.GPU);let r=Dr(this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
24
24
 
25
- `)}${r}`}finally{Dt(De.GPU)}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(M(t))return this.resolve(t);if(r&&q(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&&I(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 we(e,t){let r=new nr(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],i=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),s=xr(i),l=r.fixedBindings.map((m,g)=>[String(g),m.layoutEntry]),u=()=>{let m=s.next().value,g=mt(Object.fromEntries(l));return o[m]=g,n=n.replaceAll(xn,String(m)),[m,new le(g,Object.fromEntries(r.fixedBindings.map((T,f)=>[String(f),T.resource])))]},d=l.length>0?u():null;for(let[m,g]of a.entries()){let T=m.index??s.next().value;o[T]=m,n=n.replaceAll(g,String(T))}return{code:n,bindGroupLayouts:o,catchall:d}}function hn(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};oe(o,t??{});let i={"~resolve"(l){return ie(l,o,r??"")},toString:()=>"<root>"},{code:s}=we(i,{names:n==="strict"?new X:new Q,jitTranspiler:a});return s}var We=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 bn(e,t,r){return new ar(new or(e,t,r),{})}function wn(e){return e?.resourceType==="compute-pipeline"}var ar=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 l=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])),l.delete(u);else{let m=this._priors.bindGroupLayoutMap?.get(u);m!==void 0&&(l.delete(u),s.setBindGroup(d,o.unwrap(m)))}}),l.size>0)throw new te(l);s.dispatchWorkgroups(t,r,n),s.end()}$name(t){return this._core.label=t,this}},or=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}=we({"~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 ur(e,t="vertex"){return new sr(e,t)}function ct(e){return e?.resourceType==="vertex-layout"}var ir=Symbol("defaultAttribEntry");function Tt(e,t,r,n,a){if(Te(t)||_r(t)){let o=H(t);return o!==void 0&&(n[a??ir]=o),Tt(e,t.inner,L(r,V(t)),n)}if(I(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=L(o,D(s));let l=[i,Tt(e,s,o,n,i)];return o+=c(s),l}))}if(J(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([i,s])=>{o=L(o,V(s));let l=[i,Tt(e,s,o,n,i)];return o+=c(s),l}))}if("type"in t&&typeof t.type=="string"){if(Rr.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=Br[t.type];if(o)return{_layout:e,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var sr=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[ir]!==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[ir]}]}}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 ia(e){return typeof e?.loadOp=="string"}function Sn(e,t){if(E(e)){if(!ia(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 sa(e){return typeof e?.format=="string"}function vn(e,t){if(E(e)){if(!sa(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 Dn(e){return new pr(new lr(e),{})}function Fn(e){return e?.resourceType==="render-pipeline"}var pr=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(ft(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:Sn(s.shell.targets,this.priors.colorAttachment??{}).map(f=>N(f.view)?{...f,view:i.unwrap(f.view).createView()}:f)};if(this.core.label!==void 0&&(u.label=this.core.label),this.priors.depthStencilAttachment!==void 0){let f=this.priors.depthStencilAttachment;N(f.view)?u.depthStencilAttachment={...f,view:i.unwrap(f.view).createView()}:u.depthStencilAttachment=f}let d=i.commandEncoder.beginRenderPass(u);d.setPipeline(o.pipeline);let m=new Set(o.bindGroupLayouts);o.bindGroupLayouts.forEach((f,S)=>{if(o.catchall&&S===o.catchall[0])d.setBindGroup(S,i.unwrap(o.catchall[1])),m.delete(f);else{let b=this.priors.bindGroupLayoutMap?.get(f);b!==void 0&&(m.delete(f),d.setBindGroup(S,i.unwrap(b)))}});let g=new Set(this.core.usedVertexLayouts);if(this.core.usedVertexLayouts.forEach((f,S)=>{let b=this.priors.vertexLayoutMap?.get(f);b&&(g.delete(f),d.setVertexBuffer(S,i.unwrap(b)))}),m.size>0)throw new te(m);if(g.size>0)throw new ve(g);d.draw(t,r,n,a),d.end(),i.flush()}},lr=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=vn(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:l,bindGroupLayouts:u,catchall:d}=we({"~resolve":f=>(f.withSlots(a,()=>{f.resolve(r),f.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,g=m.createShaderModule({label:`${this.label??"<unnamed>"} - Shader`,code:l}),T={layout:m.createPipelineLayout({label:`${this.label??"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:u.map(f=>t.unwrap(f))}),vertex:{module:g,buffers:this._vertexBufferLayouts},fragment:{module:g,targets:this._targets}};this.label!==void 0&&(T.label=this.label),o&&(T.primitive=o),i&&(T.depthStencil=i),s&&(T.multisample=s),this._memo={pipeline:m.createRenderPipeline(T),bindGroupLayouts:u,catchall:d}}return this._memo}};var dr=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[ne(t)?t.slot:t,r]])}withCompute(t){return new mr(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new fr({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r,multisampleState:void 0})}},mr=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return bn(this._root,this._slotBindings,this._entryFn)}},fr=class{constructor(t){this._options=t}withFragment(t,r,n){return Se(typeof t!="string","Just type mismatch validation"),Se(typeof r!="string","Just type mismatch validation"),new gr({...this._options,fragmentFn:t,targets:r})}},gr=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 Dn(this._options)}},yt=class extends dr{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 We(r=>r.unwrap(this));_unwrappedBindGroups=new We(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 le(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(wn(r))return r.rawPipeline;if(Fn(r))return r.core.unwrap().pipeline;if(ft(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(Zt(r))return this._unwrappedBindGroups.getOrMake(r);if(ee(r))return r.buffer;if(N(r)||ke(r)||Oe(r))return r.unwrap();if(ct(r))return r.vertexLayout;if(Ve(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,l=()=>{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 g=new Set(m.bindGroupLayouts);m.bindGroupLayouts.forEach((f,S)=>{if(m.catchall&&S===m.catchall[0])a.setBindGroup(S,this.unwrap(m.catchall[1])),g.delete(f);else{let b=d.bindGroupLayoutMap?.get(f)??o.get(f);b!==void 0&&(g.delete(f),Zt(b)?a.setBindGroup(S,this.unwrap(b)):a.setBindGroup(S,b))}});let T=new Set;if(u.usedVertexLayouts.forEach((f,S)=>{let b=d.vertexLayoutMap?.get(f),U=b?{buffer:b,offset:void 0,size:void 0}:i.get(f);!U||!U.buffer?T.add(f):ee(U.buffer)?a.setVertexBuffer(S,this.unwrap(U.buffer),U.offset,U.size):a.setVertexBuffer(S,U.buffer,U.offset,U.size)}),g.size>0)throw new te(g);if(T.size>0)throw new ve(T)};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,g)=>{ee(u)?a.setIndexBuffer(this.unwrap(u),d,m,g):a.setIndexBuffer(u,d,m,g)},setVertexBuffer(u,d,m,g){i.set(u,{buffer:d,offset:m,size:g})},setBindGroup(u,d){o.set(u,d)},draw(u,d,m,g){l(),a.draw(u,d,m,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 Un(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 Q:new X,a,!0)}function An(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e??{};return new yt(t,r==="random"?new Q:new X,n,!1)}function xt(e){return new Tr(e)}var Tr=class{constructor(t=void 0){this.defaultValue=t}resourceType="slot";label;"~repr"=void 0;$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=k();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return _e(t.unwrap(this))}};function In(e,t){return new cr(e,t)}var cr=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;this.slot=xt(r)}resourceType="accessor";"~repr"=void 0;label;slot;$name(t){return this.label=t,this.slot.$name(t),this}toString(){return`accessor:${this.label??"<unnamed>"}`}get value(){if(!k())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}},G)}"~resolve"(t){let r=t.unwrap(this.slot);return Ke(r)?t.resolve(r):Pt(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function Rn(e){return pa(e)}function ua([e,t]){return`${e.label??"<unnamed>"}=${t}`}function pa(e){return{resourceType:"derived","~compute":e,"~repr":void 0,get value(){let r=k();if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return _e(r.unwrap(this))},with(r,n){return Bn(this,[[r,n]])},toString(){return"derived"}}}function Bn(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=k();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return _e(n.unwrap(this))},with(n,a){return Bn(e,[...t,[n,a]])},toString(){return`derived[${t.map(ua).join(", ")}]`}}}function _n(e,t){return new ht("private",e,t)}function Pn(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(!re())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}},G)}};var Ln={bindGroupLayout:mt,vertexLayout:ur,init:Un,initFromDevice:An,resolve:hn,"~unstable":{fn:Kr,fragmentFn:Jr,vertexFn:Hr,computeFn:jr,vertexLayout:ur,derived:Rn,slot:xt,accessor:In,privateVar:_n,workgroupVar:Pn,const:$r,declare:Or,sampler:ln,comparisonSampler:dn}},xu=Ln;Object.assign(Ln,{__assignAst:Nr});export{te as MissingBindGroupsError,St as MissingLinksError,bt as MissingSlotValueError,ve as MissingVertexBuffersError,wt as NotUniformError,Q as RandomNameRegistry,de as ResolutionError,X as StrictNameRegistry,xu as default,ee as isBuffer,Ge as isComparisonSampler,W as isDerived,Oe as isSampledTextureView,Ve as isSampler,O as isSlot,ke as isStorageTextureView,N as isTexture,Pt as isTgpuFn,oa as isUsableAsRender,Yt as isUsableAsSampled,pe as isUsableAsStorage,nt as isUsableAsUniform,aa as isUsableAsVertex,Ln as tgpu,Ot as unstable_asMutable,Wt as unstable_asReadonly,Mt as unstable_asUniform};
25
+ `)}${r}`}finally{Ut(Be.GPU)}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(z(t))return this.resolve(t);if(r&&G(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&&b(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 Fe(e,t){let r=new ur(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],s=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),i=Fr(s),p=r.fixedBindings.map((m,T)=>[String(T),m.layoutEntry]),u=()=>{let m=i.next().value,T=gt(Object.fromEntries(p));return o[m]=T,n=n.replaceAll(hn,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??i.next().value;o[f]=m,n=n.replaceAll(T,String(f))}return{code:n,bindGroupLayouts:o,catchall:d}}function pr(e,t,r){let n=t.map(a=>`${a.value}: ${e.resolve(a.dataType)}`).join(", ");return r!==void 0?`(${n}) -> ${xe(r)} ${e.resolve(r)}`:`(${n})`}function ee(e,t){let r=[];return typeof t=="string"&&(e.isEntry?(Array.isArray(e.argTypes)&&b(e.argTypes[0])&&r.push({In:e.argTypes[0]}),b(e.returnType)&&r.push({Out:e.returnType})):Array.isArray(e.argTypes)&&(zr(t,Array.isArray(e.argTypes)?e.argTypes:Object.values(e.argTypes),n=>r.push(n)),we(t,e.returnType,n=>r.push(n)))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){let o={};for(let i of r)K(o,i);let s=n.names.makeUnique(this.label);if(typeof t=="string"){let i="";if(!e.isEntry)i=Array.isArray(e.argTypes)?"":pr(n,Object.entries(e.argTypes).map(([u,d])=>({value:u,dataType:d})),e.returnType);else{let u=Array.isArray(e.argTypes)&&b(e.argTypes[0])?"(in: In)":"()",d=C(e.returnType)?xe(e.returnType):"",m=e.returnType!==void 0?b(e.returnType)?"-> Out":`-> ${d!==""?d:"@location(0)"} ${n.resolve(e.returnType)}`:"";i=`${u} ${m} `}let p=ue(n,o,`${i}${t.trim()}`);n.addDeclaration(`${a}fn ${s}${p}`)}else{let i=Hr(t);if(i?.externals){let f=Object.fromEntries(Object.entries(i.externals).filter(([g])=>!(g in o)));K(o,f)}let p=i?.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 Ft(this.label,u);let d=Array.isArray(e.argTypes)?p.argNames.type==="identifiers"?e.argTypes.map((f,g)=>({value:(p.argNames.type==="identifiers"?p.argNames.names[g]:void 0)??`arg_${g}`,dataType:f})):[]: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 ${s}${n.resolve(m)}${n.resolve(T)}`)}return s}}}function wn(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(Xe(n))return[r,n];let a=Q(n);return a!==void 0?(t=a+1,[r,n]):[r,Vr(n,{type:"@location",value:t++})]}))}function yt(e){return _(e)?Q(e)!==void 0?e:Er(0,e):Ct(wn(e))}function Ae(e){return Ct(wn(e))}function te(e,...t){return pa(e)?la(e,...t):e}function pa(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)&&e.raw.every(t=>typeof t=="string")}function la(e,...t){return e.slice(1).reduce((r,n,a)=>`${r}${t[a]}${n}`,e[0])}function Sn(e){let t={argTypes:e.in&&Object.keys(e.in).length!==0?[Ae(e.in)]:[],returnType:void 0,workgroupSize:[e.workgroupSize[0]??1,e.workgroupSize[1]??1,e.workgroupSize[2]??1],isEntry:!0},r=(n,...a)=>da(t,e.workgroupSize,te(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function da(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,N(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){return n.resolve(o,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){return`computeFn:${this.label??"<unnamed>"}`}}}function vn(e,t){let r={argTypes:e,returnType:t,isEntry:!1},n=(a,...o)=>ga(r,te(a,...o));return Object.assign(Object.assign(n,r),{does:n})}function lr(e){return e?.resourceType==="function"}function ma([e,t]){return`${e.label??"<unnamed>"}=${t}`}function ga(e,t){let r=ee(e,t),n={shell:e,resourceType:"function",$uses(s){return r.applyExternals(s),this},$name(s){return r.label=s,this},with(s,i){return Dn(o,[[ie(s)?s.slot:s,i]])},"~resolve"(s){if(typeof t=="string")return r.resolve(s);let i=s;if(i.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return i.callStack.push(e.returnType),r.resolve(s)}finally{i.callStack.pop()}}},a=It((...s)=>{if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...s)},(...s)=>({value:new ct(o,s.map(i=>i.value)),dataType:e.returnType??A}));a[y].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 Dn(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,s){return Dn(a,[...t,[ie(o)?o.slot:o,s]])}},n=It((...o)=>e(...o),(...o)=>({value:new ct(a,o.map(s=>s.value)),dataType:e.shell.returnType??A})),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(ma).join(", ")}]`}}),a[y].implementation=e[y].implementation,a}var ct=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 Fn(e){let t={argTypes:e.in&&Object.keys(e.in).length!==0?[Ae(e.in)]:[],targets:e.out,returnType:Object.keys(e.out).length!==0?yt(e.out):void 0,isEntry:!0},r=(n,...a)=>fa(t,te(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function fa(e,t){let r=ee(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&we(t,n,s=>r.applyExternals(s)),{shell:e,outputType:n,get label(){return r.label},$uses(s){return r.applyExternals(s),this},$name(s){return r.label=s,N(n)&&n.$name(`${s}_Output`),N(a)&&a.$name(`${s}_Input`),this},"~resolve"(s){if(typeof t=="string")return r.resolve(s,"@fragment ");let i=s;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(s,"@fragment ")}finally{i.callStack.pop()}},toString(){return`fragmentFn:${this.label??"<unnamed>"}`}}}function An(e){let t={attributes:[e.in??{}],returnType:Object.keys(e.out).length!==0?yt(e.out):void 0,argTypes:e.in&&Object.keys(e.in).length!==0?[Ae(e.in)]:[],isEntry:!0},r=(n,...a)=>Ta(t,te(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function Ta(e,t){let r=ee(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&we(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 s=o;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(o,"@vertex ")}finally{s.callStack.pop()}},toString(){return`vertexFn:${this.label??"<unnamed>"}`}}}var re=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++}`}},ne=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 Un(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};K(o,t??{});let s={"~resolve"(p){return ue(p,o,r??"")},toString:()=>"<root>"},{code:i}=Fe(s,{names:n==="strict"?new ne:new re,jitTranspiler:a});return i}var Ke=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 In(e,t,r){return new dr(new mr(e,t,r),{})}function Bn(e){return e?.resourceType==="compute-pipeline"}var dr=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:s}=this._core,i=o.commandEncoder.beginComputePass({label:s??"<unnamed>"});i.setPipeline(a.pipeline);let p=new Set(a.bindGroupLayouts);if(a.bindGroupLayouts.forEach((u,d)=>{if(a.catchall&&d===a.catchall[0])i.setBindGroup(d,o.unwrap(a.catchall[1])),p.delete(u);else{let m=this._priors.bindGroupLayoutMap?.get(u);m!==void 0&&(p.delete(u),i.setBindGroup(d,o.unwrap(m)))}}),p.size>0)throw new ae(p);i.dispatchWorkgroups(t,r,n),i.end()}$name(t){return this._core.label=t,this}},mr=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}=Fe({"~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 Tr(e,t="vertex"){return new fr(e,t)}function bt(e){return e?.resourceType==="vertex-layout"}var gr=Symbol("defaultAttribEntry");function xt(e,t,r,n,a){if(ye(t)||Cr(t)){let o=Q(t);return o!==void 0&&(n[a??gr]=o),xt(e,t.inner,V(r,W(t)),n)}if(b(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([s,i])=>{o=V(o,F(i));let p=[s,xt(e,i,o,n,s)];return o+=c(i),p}))}if(Y(t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([s,i])=>{o=V(o,W(i));let p=[s,xt(e,i,o,n,s)];return o+=c(i),p}))}if("type"in t&&typeof t.type=="string"){if(_r.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=Lr[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;let n=t(0);this.stride=V(c(n.elementType),F(n)),this.attrib=xt(this,n.elementType,0,this._customLocationMap)}resourceType="vertex-layout";stride;attrib;_customLocationMap={};_label;get label(){return this._label}get vertexLayout(){if(this._customLocationMap[gr]!==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[gr]}]}}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 ya(e){return typeof e?.loadOp=="string"}function Rn(e,t){if(_(e)){if(!ya(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?.format=="string"}function Pn(e,t){if(_(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 _n(e){return new yr(new cr(e),{})}function Ln(e){return e?.resourceType==="render-pipeline"}var yr=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(ft(t))return new e(this.core,{...this.priors,bindGroupLayoutMap:new Map([...this.priors.bindGroupLayoutMap??[],[t,r]])});if(bt(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:s,fragmentFn:i}=this.core.options,u={colorAttachments:Rn(i.shell.targets,this.priors.colorAttachment??{}).map(g=>q(g.view)?{...g,view:s.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:s.unwrap(g.view).createView()}:u.depthStencilAttachment=g}let d=s.commandEncoder.beginRenderPass(u);d.setPipeline(o.pipeline);let m=new Set(o.bindGroupLayouts);o.bindGroupLayouts.forEach((g,D)=>{if(o.catchall&&D===o.catchall[0])d.setBindGroup(D,s.unwrap(o.catchall[1])),m.delete(g);else{let S=this.priors.bindGroupLayoutMap?.get(g);S!==void 0&&(m.delete(g),d.setBindGroup(D,s.unwrap(S)))}});let T=new Set(this.core.usedVertexLayouts);if(this.core.usedVertexLayouts.forEach((g,D)=>{let S=this.priors.vertexLayoutMap?.get(g);S&&(T.delete(g),d.setVertexBuffer(D,s.unwrap(S)))}),m.size>0)throw new ae(m);if(T.size>0)throw new Ie(T);d.draw(t,r,n,a),d.end(),s.flush()}},cr=class{constructor(t){this.options=t;let r=Xr(t.vertexFn.shell.attributes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Pn(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:s,multisampleState:i}=this.options,{code:p,bindGroupLayouts:u,catchall:d}=Fe({"~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),s&&(f.depthStencil=s),i&&(f.multisample=i),this._memo={pipeline:m.createRenderPipeline(f),bindGroupLayouts:u,catchall:d}}return this._memo}};var xr=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[ie(t)?t.slot:t,r]])}withCompute(t){return new br(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})}},br=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return In(this._root,this._slotBindings,this._entryFn)}},hr=class{constructor(t){this._options=t}withFragment(t,r,n){return Ue(typeof t!="string","Just type mismatch validation"),Ue(typeof r!="string","Just type mismatch validation"),new wr({...this._options,fragmentFn:t,targets:r})}},wr=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 _n(this._options)}},ht=class extends xr{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 Ke(r=>r.unwrap(this));_unwrappedBindGroups=new Ke(r=>r.unwrap(this));_commandEncoder=null;get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=dn(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=cn(r,this);return this._disposables.push(n),n}unwrap(r){if(Bn(r))return r.rawPipeline;if(Ln(r))return r.core.unwrap().pipeline;if(ft(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(ar(r))return this._unwrappedBindGroups.getOrMake(r);if(Z(r))return r.buffer;if(q(r)||je(r)||ze(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,s=new Map,i,p=()=>{if(!i)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:u,priors:d}=i,m=u.unwrap();a.setPipeline(m.pipeline);let T=new Set(m.bindGroupLayouts);m.bindGroupLayouts.forEach((g,D)=>{if(m.catchall&&D===m.catchall[0])a.setBindGroup(D,this.unwrap(m.catchall[1])),T.delete(g);else{let S=d.bindGroupLayoutMap?.get(g)??o.get(g);S!==void 0&&(T.delete(g),ar(S)?a.setBindGroup(D,this.unwrap(S)):a.setBindGroup(D,S))}});let f=new Set;if(u.usedVertexLayouts.forEach((g,D)=>{let S=d.vertexLayoutMap?.get(g),I=S?{buffer:S,offset:void 0,size:void 0}:s.get(g);!I||!I.buffer?f.add(g):Z(I.buffer)?a.setVertexBuffer(D,this.unwrap(I.buffer),I.offset,I.size):a.setVertexBuffer(D,I.buffer,I.offset,I.size)}),T.size>0)throw new ae(T);if(f.size>0)throw new Ie(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){i=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){s.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 Cn(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 ht(await o.requestDevice(r),n==="random"?new re:new ne,a,!0)}function Vn(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e??{};return new ht(t,r==="random"?new re:new ne,n,!1)}function wt(e){return new Sr(e)}var Sr=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=j();if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return Ee(t.unwrap(this))}};function En(e,t){return new vr(e,t)}var vr=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;this.slot=wt(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(!j())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}},M)}"~resolve"(t){let r=t.unwrap(this.slot);return Ze(r)?t.resolve(r):lr(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function kn(e){return ba(e)}function xa([e,t]){return`${e.label??"<unnamed>"}=${t}`}function ba(e){return{resourceType:"derived","~compute":e,[Bt]:void 0,get value(){let r=j();if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Ee(r.unwrap(this))},with(r,n){return $n(this,[[r,n]])},toString(){return"derived"}}}function $n(e,t){return{resourceType:"derived",[Bt]:void 0,"~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},"~providing":{inner:e,pairs:t},get value(){let n=j();if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Ee(n.unwrap(this))},with(n,a){return $n(e,[...t,[n,a]])},toString(){return`derived[${t.map(xa).join(", ")}]`}}}function On(e,t){return new St("private",e,t)}function Gn(e){return new St("workgroup",e)}var St=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(!oe())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}},M)}};var Wn={bindGroupLayout:gt,vertexLayout:Tr,init:Cn,initFromDevice:Vn,resolve:Un,"~unstable":{fn:vn,fragmentFn:Fn,vertexFn:An,computeFn:Sn,vertexLayout:Tr,derived:kn,slot:wt,accessor:En,privateVar:On,workgroupVar:Gn,const:jr,declare:Kr,sampler:mn,comparisonSampler:gn}},Mu=Wn;Object.assign(Wn,{__assignAst:Jr,__removedJsImpl:Yr});export{ae as MissingBindGroupsError,Ft as MissingLinksError,vt as MissingSlotValueError,Ie as MissingVertexBuffersError,Dt as NotUniformError,re as RandomNameRegistry,me as ResolutionError,ne as StrictNameRegistry,Mu as default,Z as isBuffer,Me as isComparisonSampler,k as isDerived,ze as isSampledTextureView,We as isSampler,E as isSlot,je as isStorageTextureView,q as isTexture,lr as isTgpuFn,ua as isUsableAsRender,tr as isUsableAsSampled,de as isUsableAsStorage,at as isUsableAsUniform,ia as isUsableAsVertex,Wn as tgpu,zt as unstable_asMutable,Kt as unstable_asReadonly,qt as unstable_asUniform};
26
26
  //# sourceMappingURL=index.js.map