typegpu 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,15 +1,19 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkRFXJKOYGcjs = require('./chunk-RFXJKOYG.cjs');var _chunkVRYGOFCWcjs = require('./chunk-VRYGOFCW.cjs');function j(e){return(e==null?void 0:e.resourceType)==="slot"}function z(e){return(e==null?void 0:e.resourceType)==="derived"}function ye(e){return(e==null?void 0:e["~providing"])!==void 0}function Y(e){return(e==null?void 0:e.resourceType)==="accessor"}var w=Symbol("Unknown data type");function Ze(e){return typeof(e==null?void 0:e["~resolve"])=="function"}function X(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||Ze(e)||_chunkRFXJKOYGcjs.a.call(void 0, e)||j(e)||z(e)||ye(e)}function Yt(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function ve(e){return(e==null?void 0:e.resourceType)==="buffer-usage"}var G={get(e,t){if(t in e)return Reflect.get(e,t);if(t!=="~providing")return new Proxy({"~resolve":r=>`${r.resolve(e)}.${String(t)}`,toString:()=>{var r;return`.value(...).${String(t)}:${(r=e.label)!=null?r:"<unnamed>"}`}},G)}};function ce(e){let t=e;for(;j(t)||z(t)||Y(t)||ve(t);)t=t.value;return t}function Xt(e,t){return new et(e,t)}var et=class{constructor(t,r){this.dataType=t;this._value=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${r} = ${n};`),r}toString(){var t;return`const:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){return _chunkVRYGOFCWcjs.m.call(void 0, )?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},G):this._value}};function O(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function Q(e,t){for(let[r,n]of Object.entries(t))e[r]=n,O(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function Qt(e,t,r){let n=[...e.matchAll(new RegExp(":\\s*(?<arg>.*?)\\s*[,)]","g"))].map(o=>o?o[1]:void 0);r(Object.fromEntries(t.flatMap((o,a)=>{let i=n?n[a]:void 0;return _chunkRFXJKOYGcjs.c.call(void 0, o)&&i!==void 0?[[i,o]]:[]})))}function oe(e,t,r){var a;let n=e.match(new RegExp("->(?<output>.*?){","s")),o=n?(a=n[1])==null?void 0:a.trim():void 0;_chunkRFXJKOYGcjs.c.call(void 0, t)&&o&&!/\s/g.test(o)&&r({[o]:t})}function zr(e){return new RegExp(`(?<![\\w_.])${e.replaceAll(".","\\.")}(?![\\w_])`,"g")}function Z(e,t,r){return Object.entries(t).reduce((n,[o,a])=>{var i;return X(a)?n.replaceAll(zr(o),e.resolve(a)):a!==null&&typeof a=="object"?((i=[...r.matchAll(new RegExp(`${o.replaceAll(".","\\.")}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(d=>d[1]))!=null?i:[]).reduce((d,l)=>l&&l in a?Z(e,{[`${o}.${l}`]:a[l]},d):d,n):n},r)}function Zt(e){return new tt(e)}var tt=class{constructor(t){this.declaration=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"externalsToApply",[])}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let o of this.externalsToApply)Q(r,o);let n=Z(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var er=new WeakMap;function tr(e){return er.get(e)}function rr(e,t,r){return er.set(e,{ast:t,externals:r}),e}function K(e,t){let r=[];return typeof t=="string"&&(Qt(t,e.argTypes,n=>r.push(n)),oe(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,o=""){var u;let a={};for(let d of r)Q(a,d);let i=n.names.makeUnique(this.label);if(typeof t=="string"){let d=Z(n,a,t.trim());n.addDeclaration(`${o}fn ${i}${d}`)}else{let d=tr(t);if(d!=null&&d.externals){let h=Object.fromEntries(Object.entries(d.externals).filter(([f])=>!(f in a)));Q(a,h)}let l=(u=d==null?void 0:d.ast)!=null?u:n.transpileFn(String(t)),m=l.externalNames.filter(h=>!(h in a));if(m.length>0)throw new (0, _chunkVRYGOFCWcjs.h)(this.label,m);let T=l.argNames.map((h,f)=>({value:h,dataType:e.argTypes[f]})),{head:g,body:v}=n.fnToWgsl({args:T,returnType:e.returnType,body:l.body,externalMap:a});n.addDeclaration(`${o}fn ${i}${n.resolve(g)}${n.resolve(v)}`)}return i}}}function nr(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(_chunkRFXJKOYGcjs.Ha.call(void 0, n))return[r,n];let o=_chunkRFXJKOYGcjs.y.call(void 0, n);return o!==void 0?(t=o+1,[r,n]):[r,_chunkRFXJKOYGcjs.Ca.call(void 0, n,{type:"@location",value:t++})]}))}function Ue(e){return _chunkRFXJKOYGcjs.z.call(void 0, e)?_chunkRFXJKOYGcjs.Fa.call(void 0, 0,e):_chunkRFXJKOYGcjs.q.call(void 0, nr(e))}function Ae(e){return _chunkRFXJKOYGcjs.q.call(void 0, nr(e))}function or(e,t){var n,o,a;let{workgroupSize:r}=t;return{argTypes:[Ae(e)],returnType:void 0,workgroupSize:[(n=r[0])!=null?n:1,(o=r[1])!=null?o:1,(a=r[2])!=null?a:1],does(i){return Kr(this,r,i)}}}function Kr(e,t,r){let n=K(e,r),o=e.argTypes[0];return{shell:e,get label(){return n.label},$uses(a){return n.applyExternals(a),this},$name(a){return n.label=a,O(o)&&o.$name(`${a}_Input`),this},"~resolve"(a){return n.resolve(a,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){var a;return`computeFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}function ar(e,t){return{argTypes:e,returnType:t,does(r){return Jr(this,r)}}}function rt(e){return(e==null?void 0:e.resourceType)==="function"}function qr([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function Jr(e,t){let r=K(e,t),a=Object.assign((...i)=>{if(_chunkVRYGOFCWcjs.m.call(void 0, ))return new Ie(a,i);if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...i)},{shell:e,resourceType:"function",$uses(i){return r.applyExternals(i),this},$name(i){return r.label=i,this},with(i,u){return ir(a,[[Y(i)?i.slot:i,u]])},"~resolve"(i){return r.resolve(i)}});return Object.defineProperty(a,"label",{get:()=>r.label}),Object.defineProperty(a,"toString",{value:()=>{var i;return`fn:${(i=r.label)!=null?i:"<unnamed>"}`}}),a}function ir(e,t){let r={resourceType:"function",shell:e.shell,"~providing":{inner:e,pairs:t},$uses(a){return e.$uses(a),this},$name(a){return e.$name(a),this},with(a,i){return ir(o,[...t,[Y(a)?a.slot:a,i]])}},o=Object.assign((...a)=>_chunkVRYGOFCWcjs.m.call(void 0, )?new Ie(o,a):e(...a),r);return Object.defineProperty(o,"label",{get:()=>e.label}),Object.defineProperty(o,"toString",{value(){var i;return`fn:${(i=e.label)!=null?i:"<unnamed>"}[${t.map(qr).join(", ")}]`}}),o}var Ie=class{constructor(t,r){this._fn=t;this._params=r}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(r=>t.resolve(r)).join(", ")})`)}toString(){var t;return`call:${(t=this.label)!=null?t:"<unnamed>"}`}};function sr(e,t){return{argTypes:[e],returnType:t,does(r){return Hr(this,r)}}}function Hr(e,t){let r=K(e,t),n=Ue(e.returnType);return typeof t=="string"&&oe(t,n,a=>r.applyExternals(a)),{shell:e,outputType:n,get label(){return r.label},$uses(a){return r.applyExternals(a),this},$name(a){return r.label=a,O(n)&&n.$name(`${a}_Output`),this},"~resolve"(a){return r.resolve(a,"@fragment ")},toString(){var a;return`fragmentFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}function ur(e,t){return{attributes:[e],returnType:Ue(t),argTypes:[Ae(e)],does(r){return Yr(this,r)}}}function Yr(e,t){let r=K(e,t),n=e.returnType,o=e.argTypes[0];return typeof t=="string"&&oe(t,n,a=>r.applyExternals(a)),{shell:e,outputType:n,inputType:o,get label(){return r.label},$uses(a){return r.applyExternals(a),this},$name(a){return r.label=a,O(n)&&n.$name(`${a}_Output`),O(o)&&o.$name(`${a}_Input`),this},"~resolve"(a){if(typeof t=="string")return r.resolve(a,"@vertex ");let i=a;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(a,"@vertex ")}finally{i.callStack.pop()}},toString(){var a;return`vertexFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}var q=class{constructor(){_chunkVRYGOFCWcjs.c.call(void 0, this,"lastUniqueId",0)}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},J= exports.StrictNameRegistry =class{constructor(){_chunkVRYGOFCWcjs.c.call(void 0, this,"_usedNames",new Set)}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function pr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var Xr=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function Qr(e){return Xr.includes(e.type)}function Zr(e,[t,r]){return` ${_chunkRFXJKOYGcjs.Ia.call(void 0, r)}${t}: ${e.resolve(r)},
2
- `}function en(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkY2M5GYROcjs = require('./chunk-Y2M5GYRO.cjs');var _chunkLF344PKGcjs = require('./chunk-LF344PKG.cjs');function q(e){return(e==null?void 0:e.resourceType)==="slot"}function J(e){return(e==null?void 0:e.resourceType)==="derived"}function we(e){return(e==null?void 0:e["~providing"])!==void 0}function ee(e){return(e==null?void 0:e.resourceType)==="accessor"}var U=Symbol("Unknown data type");function it(e){return typeof(e==null?void 0:e["~resolve"])=="function"}function te(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||it(e)||_chunkY2M5GYROcjs.a.call(void 0, e)||q(e)||J(e)||we(e)}function pr(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function Pe(e){return(e==null?void 0:e.resourceType)==="buffer-usage"}var $={get(e,t){if(t in e)return Reflect.get(e,t);if(t!=="~providing")return new Proxy({"~resolve":r=>`${r.resolve(e)}.${String(t)}`,toString:()=>{var r;return`.value(...).${String(t)}:${(r=e.label)!=null?r:"<unnamed>"}`}},$)}};function Se(e){let t=e;for(;q(t)||J(t)||ee(t)||Pe(t);)t=t.value;return t}function lr(e,t){return new ut(e,t)}var ut=class{constructor(t,r){this.dataType=t;this._value=r;_chunkLF344PKGcjs.c.call(void 0, this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${r} = ${n};`),r}toString(){var t;return`const:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){return _chunkLF344PKGcjs.m.call(void 0, )?new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},$):this._value}};function k(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function re(e,t){for(let[r,n]of Object.entries(t))e[r]=n,k(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function dr(e,t,r){let n=[...e.matchAll(new RegExp(":\\s*(?<arg>.*?)\\s*[,)]","g"))].map(a=>a?a[1]:void 0);r(Object.fromEntries(t.flatMap((a,o)=>{let s=n?n[o]:void 0;return _chunkY2M5GYROcjs.c.call(void 0, a)&&s!==void 0?[[s,a]]:[]})))}function de(e,t,r){var o;let n=e.match(new RegExp("->(?<output>.*?){","s")),a=n?(o=n[1])==null?void 0:o.trim():void 0;_chunkY2M5GYROcjs.c.call(void 0, t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function on(e){return new RegExp(`(?<![\\w_.])${e.replaceAll(".","\\.")}(?![\\w_])`,"g")}function ne(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{var s;return te(o)||_chunkY2M5GYROcjs.n.call(void 0, o)?n.replaceAll(on(a),e.resolve(o)):o!==null&&typeof o=="object"?((s=[...r.matchAll(new RegExp(`${a.replaceAll(".","\\.")}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(p=>p[1]))!=null?s:[]).reduce((p,l)=>l&&l in o?ne(e,{[`${a}.${l}`]:o[l]},p):p,n):n},r)}function mr(e){return new pt(e)}var pt=class{constructor(t){this.declaration=t;_chunkLF344PKGcjs.c.call(void 0, this,"externalsToApply",[])}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)re(r,a);let n=ne(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var gr=new WeakMap;function fr(e){return gr.get(e)}function Tr(e,t,r){return gr.set(e,{ast:t,externals:r}),e}function H(e,t){let r=[];return typeof t=="string"&&(dr(t,e.argTypes,n=>r.push(n)),de(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){var u;let o={};for(let p of r)re(o,p);let s=n.names.makeUnique(this.label);if(typeof t=="string"){let p=ne(n,o,t.trim());n.addDeclaration(`${a}fn ${s}${p}`)}else{let p=fr(t);if(p!=null&&p.externals){let x=Object.fromEntries(Object.entries(p.externals).filter(([T])=>!(T in o)));re(o,x)}let l=(u=p==null?void 0:p.ast)!=null?u:n.transpileFn(String(t)),m=l.externalNames.filter(x=>!(x in o));if(m.length>0)throw new (0, _chunkLF344PKGcjs.h)(this.label,m);let f=l.argNames.map((x,T)=>({value:x,dataType:e.argTypes[T]})),{head:g,body:D}=n.fnToWgsl({args:f,returnType:e.returnType,body:l.body,externalMap:o});n.addDeclaration(`${a}fn ${s}${n.resolve(g)}${n.resolve(D)}`)}return s}}}function yr(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(_chunkY2M5GYROcjs.Ea.call(void 0, n))return[r,n];let a=_chunkY2M5GYROcjs.r.call(void 0, n);return a!==void 0?(t=a+1,[r,n]):[r,_chunkY2M5GYROcjs.za.call(void 0, n,{type:"@location",value:t++})]}))}function Le(e){return _chunkY2M5GYROcjs.s.call(void 0, e)?_chunkY2M5GYROcjs.r.call(void 0, e)!==void 0?e:_chunkY2M5GYROcjs.Ca.call(void 0, 0,e):_chunkY2M5GYROcjs.y.call(void 0, yr(e))}function me(e){return _chunkY2M5GYROcjs.y.call(void 0, yr(e))}function cr(e,t){var n,a,o;let{workgroupSize:r}=t;return{argTypes:[me(e)],returnType:void 0,workgroupSize:[(n=r[0])!=null?n:1,(a=r[1])!=null?a:1,(o=r[2])!=null?o:1],does(s){return sn(this,r,s)}}}function sn(e,t,r){let n=H(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,k(a)&&a.$name(`${o}_Input`),this},"~resolve"(o){return n.resolve(o,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){var o;return`computeFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}function xr(e,t){return{argTypes:e,returnType:t,does(r){return pn(this,r)}}}function lt(e){return(e==null?void 0:e.resourceType)==="function"}function un([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function pn(e,t){let r=H(e,t),o=Object.assign((...s)=>{if(_chunkLF344PKGcjs.m.call(void 0, ))return new Ce(o,s);if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...s)},{shell:e,resourceType:"function",$uses(s){return r.applyExternals(s),this},$name(s){return r.label=s,this},with(s,u){return br(o,[[ee(s)?s.slot:s,u]])},"~resolve"(s){return r.resolve(s)}});return Object.defineProperty(o,"label",{get:()=>r.label}),Object.defineProperty(o,"toString",{value:()=>{var s;return`fn:${(s=r.label)!=null?s:"<unnamed>"}`}}),o}function br(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 br(a,[...t,[ee(o)?o.slot:o,s]])}},a=Object.assign((...o)=>_chunkLF344PKGcjs.m.call(void 0, )?new Ce(a,o):e(...o),r);return Object.defineProperty(a,"label",{get:()=>e.label}),Object.defineProperty(a,"toString",{value(){var s;return`fn:${(s=e.label)!=null?s:"<unnamed>"}[${t.map(un).join(", ")}]`}}),a}var Ce=class{constructor(t,r){this._fn=t;this._params=r}get label(){return this._fn.label}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(r=>t.resolve(r)).join(", ")})`)}toString(){var t;return`call:${(t=this.label)!=null?t:"<unnamed>"}`}};function hr(e,t){return{argTypes:[me(e)],targets:t,returnType:Le(t),does(r){return ln(this,r)}}}function ln(e,t){let r=H(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&de(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,k(n)&&n.$name(`${s}_Output`),k(a)&&a.$name(`${s}_Input`),this},"~resolve"(s){if(typeof t=="string")return r.resolve(s,"@fragment ");let u=s;if(u.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return u.callStack.push(n),r.resolve(s,"@fragment ")}finally{u.callStack.pop()}},toString(){var s;return`fragmentFn:${(s=this.label)!=null?s:"<unnamed>"}`}}}function wr(e,t){return{attributes:[e],returnType:Le(t),argTypes:[me(e)],does(r){return dn(this,r)}}}function dn(e,t){let r=H(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&de(t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,inputType:a,get label(){return r.label},$uses(o){return r.applyExternals(o),this},$name(o){return r.label=o,k(n)&&n.$name(`${o}_Output`),k(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(){var o;return`vertexFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}var Y=class{constructor(){_chunkLF344PKGcjs.c.call(void 0, this,"lastUniqueId",0)}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},X= exports.StrictNameRegistry =class{constructor(){_chunkLF344PKGcjs.c.call(void 0, this,"_usedNames",new Set)}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function Sr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function De(e){return typeof(e==null?void 0:e.format)=="string"}function Dr(e,t){var s,u;let r=[];if(_chunkY2M5GYROcjs.s.call(void 0, e)){if(!De(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:(s=_chunkY2M5GYROcjs.r.call(void 0, e))!=null?s:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[p,l]of Object.entries(e)){if(_chunkY2M5GYROcjs.Ea.call(void 0, l))continue;let m=t[p];if(!m)throw new Error(`An attribute by the name of '${p}' was not provided to the shader.`);let f=m._layout,g=a.get(f);g||(r.push(f),g=[],n.push({arrayStride:f.stride,stepMode:f.stepMode,attributes:g}),a.set(f,g)),o=(u=_chunkY2M5GYROcjs.r.call(void 0, l))!=null?u:o,g.push({format:m.format,offset:m.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 gn(e){return mn.includes(e.type)}function dt(e,[t,r]){return` ${_chunkY2M5GYROcjs.Fa.call(void 0, r)}${t}: ${e.resolve(r)},
2
+ `}function fn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
- ${Object.entries(t.propTypes).map(n=>Zr(e,n)).join("")}}
5
- `),r}function tn(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function nt(e,t){if(Qr(t))return t.type;if(t.type==="struct")return en(e,t);if(t.type==="array")return tn(e,t);if(t.type==="atomic")return`atomic<${nt(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);if(t.type==="ptrFn")return`ptr<function, ${e.resolve(t.inner)}>`;pr(t,"resolveData")}function*lr(e){let t=0;for(;;)e.has(t)||(yield t),t++}var rn=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function b(e,t){return X(t.value)||_chunkRFXJKOYGcjs.a.call(void 0, t.value)?e.resolve(t.value):String(t.value)}function nn(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function dr(e,t){return t?{value:"true",dataType:_chunkRFXJKOYGcjs.l}:{value:"false",dataType:_chunkRFXJKOYGcjs.l}}function mr(e,t){return`${e.indent()}{
6
- ${t.b.map(r=>at(e,r)).join(`
4
+ ${Object.entries(t.propTypes).map(n=>dt(e,n)).join("")}}
5
+ `),r}function Tn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
6
+ struct ${r} {
7
+ ${Object.entries(t.propTypes).map(n=>De(n[1])?dt(e,[n[0],_chunkY2M5GYROcjs.A[n[1].format]]):dt(e,n)).join("")}
8
+ }
9
+ `),r}function yn(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function cn(e,t){let r=e.resolve(De(t.elementType)?_chunkY2M5GYROcjs.A[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function mt(e,t){if(_chunkY2M5GYROcjs.n.call(void 0, t))return t.type==="unstruct"?Tn(e,t):t.type==="disarray"?cn(e,t):t.type==="loose-decorated"?e.resolve(De(t.inner)?_chunkY2M5GYROcjs.A[t.inner.format]:t.inner):e.resolve(_chunkY2M5GYROcjs.A[t.type]);if(gn(t))return t.type;if(t.type==="struct")return fn(e,t);if(t.type==="array")return yn(e,t);if(t.type==="atomic")return`atomic<${mt(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);if(t.type==="ptrFn")return`ptr<function, ${e.resolve(t.inner)}>`;Sr(t,"resolveData")}function*Fr(e){let t=0;for(;;)e.has(t)||(yield t),t++}var xn=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function S(e,t){return te(t.value)||_chunkY2M5GYROcjs.a.call(void 0, t.value)?e.resolve(t.value):String(t.value)}function bn(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function Ur(e,t){return t?{value:"true",dataType:_chunkY2M5GYROcjs.t}:{value:"false",dataType:_chunkY2M5GYROcjs.t}}function vr(e,t){return`${e.indent()}{
10
+ ${t.b.map(r=>ft(e,r)).join(`
7
11
  `)}
8
- ${e.dedent()}}`}function ot(e,t){return e.getById(t)}function S(e,t){if(typeof t=="string")return ot(e,t);if(typeof t=="boolean")return dr(e,t);if("x"in t){let[r,n,o]=t.x,a=b(e,S(e,r)),i=b(e,S(e,o));return{value:rn.includes(n)?`(${a} ${n} ${i})`:`${a} ${n} ${i}`,dataType:w}}if("u"in t){let[r,n]=t.u,o=b(e,S(e,n));return{value:`${r}${o}`,dataType:w}}if("a"in t){let[r,n]=t.a,o=S(e,r),a=b(e,S(e,n));if(typeof o.value=="string")return{value:`${o.value}.${a}`,dataType:w};if(X(o.value))return{value:o.value[a],dataType:w};if(typeof o.value=="object")return{value:o.value[a],dataType:w};throw new Error(`Cannot access member ${a} of ${o.value}`)}if("i"in t){let[r,n]=t.i,o=b(e,S(e,r)),a=b(e,S(e,n));return{value:`${o}[${a}]`,dataType:w}}if("n"in t)return{value:t.n,dataType:w};if("f"in t){let[r,n]=t.f,a=S(e,r).value;e.callStack.push(a);let u=n.map(l=>S(e,l)).map(l=>b(e,l));return e.callStack.pop(),typeof a=="string"?{value:`${a}(${u.join(", ")})`,dataType:w}:_chunkRFXJKOYGcjs.c.call(void 0, a)?{value:`${e.resolve(a)}(${u.join(", ")})`,dataType:w}:{value:a(...u),dataType:w}}if("o"in t){let r=t.o,n=e.callStack[e.callStack.length-1],o=a=>a.map(i=>{let u=S(e,i);return b(e,u)}).join(", ");if(_chunkRFXJKOYGcjs.c.call(void 0, n)){let i=Object.keys(n.propTypes).map(u=>{let d=r[u];if(d===void 0)throw new Error(`Missing property ${u} in object literal for struct ${n}`);return d});return{value:o(i),dataType:n}}return{value:o(Object.values(r)),dataType:w}}nn(t)}function at(e,t){if(typeof t=="string")return`${e.pre}${b(e,ot(e,t))};`;if(typeof t=="boolean")return`${e.pre}${b(e,dr(e,t))};`;if("r"in t){if(_chunkRFXJKOYGcjs.c.call(void 0, e.callStack[e.callStack.length-1])&&t.r!==null){let r=b(e,S(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 ${b(e,S(e,t.r))};`}if("q"in t){let[r,n,o]=t.q,a=b(e,S(e,r));e.indent();let i=at(e,n);e.dedent(),e.indent();let u=o?at(e,o):void 0;return e.dedent(),u?`${e.pre}if (${a})
9
- ${i}
12
+ ${e.dedent()}}`}function gt(e,t){return e.getById(t)}function v(e,t){if(typeof t=="string")return gt(e,t);if(typeof t=="boolean")return Ur(e,t);if("x"in t){let[r,n,a]=t.x,o=S(e,v(e,r)),s=S(e,v(e,a));return{value:xn.includes(n)?`(${o} ${n} ${s})`:`${o} ${n} ${s}`,dataType:U}}if("u"in t){let[r,n]=t.u,a=S(e,v(e,n));return{value:`${r}${a}`,dataType:U}}if("a"in t){let[r,n]=t.a,a=v(e,r),o=S(e,v(e,n));if(typeof a.value=="string")return{value:`${a.value}.${o}`,dataType:U};if(te(a.value))return{value:a.value[o],dataType:U};if(typeof a.value=="object")return{value:a.value[o],dataType:U};throw new Error(`Cannot access member ${o} of ${a.value}`)}if("i"in t){let[r,n]=t.i,a=S(e,v(e,r)),o=S(e,v(e,n));return{value:`${a}[${o}]`,dataType:U}}if("n"in t)return{value:t.n,dataType:U};if("f"in t){let[r,n]=t.f,o=v(e,r).value;e.callStack.push(o);let u=n.map(l=>v(e,l)).map(l=>S(e,l));return e.callStack.pop(),typeof o=="string"?{value:`${o}(${u.join(", ")})`,dataType:U}:_chunkY2M5GYROcjs.c.call(void 0, o)?{value:`${e.resolve(o)}(${u.join(", ")})`,dataType:U}:{value:o(...u),dataType:U}}if("o"in t){let r=t.o,n=e.callStack[e.callStack.length-1],a=o=>o.map(s=>{let u=v(e,s);return S(e,u)}).join(", ");if(_chunkY2M5GYROcjs.c.call(void 0, n)){let s=Object.keys(n.propTypes).map(u=>{let p=r[u];if(p===void 0)throw new Error(`Missing property ${u} in object literal for struct ${n}`);return p});return{value:a(s),dataType:n}}return{value:a(Object.values(r)),dataType:U}}bn(t)}function ft(e,t){if(typeof t=="string")return`${e.pre}${S(e,gt(e,t))};`;if(typeof t=="boolean")return`${e.pre}${S(e,Ur(e,t))};`;if("r"in t){if(_chunkY2M5GYROcjs.c.call(void 0, e.callStack[e.callStack.length-1])&&t.r!==null&&typeof t.r=="object"&&"o"in t.r){let r=S(e,v(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 ${S(e,v(e,t.r))};`}if("q"in t){let[r,n,a]=t.q,o=S(e,v(e,r));e.indent();let s=ft(e,n);e.dedent(),e.indent();let u=a?ft(e,a):void 0;return e.dedent(),u?`${e.pre}if (${o})
13
+ ${s}
10
14
  ${e.pre}else
11
- ${u}`:`${e.pre}if (${a})
12
- ${i}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,o=b(e,ot(e,r)),a=n?S(e,n):void 0;if(!a)throw new Error("Cannot create variable without an initial value.");return`${e.pre}var ${o} = ${b(e,a)};`}return"b"in t?mr(e,t):`${e.pre}${b(e,S(e,t))};`}function it(e,t){return mr(e,t)}var _typedbinary = require('typed-binary');function on(e,t){let r="size"in e?e.size:e.currentByteOffset,n=t-1,o=r&n;"skipBytes"in e?e.skipBytes(t-o&n):e.add(t-o&n)}var y=on;var F={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=_chunkRFXJKOYGcjs.oa.call(void 0, t);y(e,n);for(let[o,a]of Object.entries(t.propTypes))y(e,_chunkRFXJKOYGcjs.oa.call(void 0, a)),ae(e,a,r[o]);y(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkRFXJKOYGcjs.oa.call(void 0, t);y(e,n);let o=e.currentByteOffset;for(let a=0;a<Math.min(t.elementCount,r.length);a++)y(e,n),ae(e,t.elementType,r[a]);e.seekTo(o+_chunkRFXJKOYGcjs.ra.call(void 0, t))},ptrFn(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){var n;(n=F[t.inner.type])==null||n.call(F,e,t,r)},decorated(e,t,r){var a,i;let n=_chunkRFXJKOYGcjs.pa.call(void 0, t);y(e,n);let o=e.currentByteOffset;(i=F[(a=t.inner)==null?void 0:a.type])==null||i.call(F,e,t.inner,r),e.seekTo(o+_chunkRFXJKOYGcjs.ra.call(void 0, t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){var a,i;let n=_chunkRFXJKOYGcjs.oa.call(void 0, t);y(e,n);let o=e.currentByteOffset;for(let u=0;u<Math.min(t.elementCount,r.length);u++)y(e,n),(i=F[(a=t.elementType)==null?void 0:a.type])==null||i.call(F,e,t.elementType,r[u]);e.seekTo(o+_chunkRFXJKOYGcjs.ra.call(void 0, t))},unstruct(e,t,r){var n;for(let[o,a]of Object.entries(t.propTypes))(n=F[a.type])==null||n.call(F,e,a,r[o])},"loose-decorated"(e,t,r){var i;let n=_chunkRFXJKOYGcjs.pa.call(void 0, t);y(e,n);let o=e.currentByteOffset,a=F[(i=t.inner)==null?void 0:i.type];return a==null||a(e,t.inner,r),e.seekTo(o+_chunkRFXJKOYGcjs.ra.call(void 0, t)),r}};function ae(e,t,r){let n=F[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var ee={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 _chunkVRYGOFCWcjs.n.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunkVRYGOFCWcjs.r.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunkVRYGOFCWcjs.v.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunkVRYGOFCWcjs.o.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunkVRYGOFCWcjs.s.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunkVRYGOFCWcjs.w.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunkVRYGOFCWcjs.p.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunkVRYGOFCWcjs.t.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunkVRYGOFCWcjs.x.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunkVRYGOFCWcjs.q.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunkVRYGOFCWcjs.u.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunkVRYGOFCWcjs.y.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return _chunkRFXJKOYGcjs.xa.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkRFXJKOYGcjs.ya.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkRFXJKOYGcjs.za.call(void 0, 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=_chunkRFXJKOYGcjs.oa.call(void 0, t);y(e,r);let n={};for(let[o,a]of Object.entries(t.propTypes))y(e,_chunkRFXJKOYGcjs.oa.call(void 0, a)),n[o]=E(e,a);return y(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkRFXJKOYGcjs.oa.call(void 0, t),n=[];for(let o=0;o<t.elementCount;o++){y(e,r);let a=t.elementType,i=E(e,a);n.push(i)}return y(e,r),n},ptrFn(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return E(e,t.inner)},decorated(e,t){let r=_chunkRFXJKOYGcjs.pa.call(void 0, t);y(e,r);let n=e.currentByteOffset,o=E(e,t.inner);return e.seekTo(n+_chunkRFXJKOYGcjs.ra.call(void 0, t)),o},uint8:e=>e.readUint8(),uint8x2:e=>_chunkVRYGOFCWcjs.q.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunkVRYGOFCWcjs.y.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunkVRYGOFCWcjs.p.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunkVRYGOFCWcjs.x.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>_chunkVRYGOFCWcjs.q.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunkVRYGOFCWcjs.y.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunkVRYGOFCWcjs.p.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunkVRYGOFCWcjs.x.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, ee.snorm16(e),ee.snorm16(e)),snorm16x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, ee.snorm16(e),ee.snorm16(e),ee.snorm16(e),ee.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunkVRYGOFCWcjs.n.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunkVRYGOFCWcjs.r.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunkVRYGOFCWcjs.v.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunkVRYGOFCWcjs.q.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunkVRYGOFCWcjs.u.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunkVRYGOFCWcjs.y.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunkVRYGOFCWcjs.p.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunkVRYGOFCWcjs.t.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunkVRYGOFCWcjs.x.call(void 0, 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,o=(t>>2&1023)/1023,a=(t&3)/3;return _chunkVRYGOFCWcjs.v.call(void 0, r,n,o,a)},"unorm8x4-bgra"(e){let t=e.readByte()/255,r=e.readByte()/255,n=e.readByte()/255,o=e.readByte()/255;return _chunkVRYGOFCWcjs.v.call(void 0, n,r,t,o)},unstruct(e,t){let r={};for(let[n,o]of Object.entries(t.propTypes))r[n]=E(e,o);return r},disarray(e,t){let r=_chunkRFXJKOYGcjs.oa.call(void 0, t),n=[];for(let o=0;o<t.elementCount;o++)y(e,r),n.push(E(e,t.elementType));return y(e,r),n},"loose-decorated"(e,t){y(e,_chunkRFXJKOYGcjs.pa.call(void 0, t));let r=e.currentByteOffset,n=E(e,t.inner);return e.seekTo(r+_chunkRFXJKOYGcjs.ra.call(void 0, t)),n}};function E(e,t){let r=ee[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function gr(e,t,r){return _chunkRFXJKOYGcjs.a.call(void 0, t)?new Re(e,t,r):new Re(e,t,r,["storage","uniform"])}function ie(e){return e.resourceType==="buffer"}function xe(e){return!!e.usableAsUniform}function an(e){return!!e.usableAsVertex}var Re=class{constructor(t,r,n,o){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=o;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","buffer");_chunkVRYGOFCWcjs.c.call(void 0, this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);_chunkVRYGOFCWcjs.c.call(void 0, this,"_buffer",null);_chunkVRYGOFCWcjs.c.call(void 0, this,"_ownBuffer");_chunkVRYGOFCWcjs.c.call(void 0, this,"_destroyed",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"_label");_chunkVRYGOFCWcjs.c.call(void 0, this,"initial");_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsUniform",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsVertex",!1);Yt(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}get label(){return this._label}get buffer(){var r;let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:_chunkRFXJKOYGcjs.ra.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:(r=this.label)!=null?r:"<unnamed>"}),this.initial)){let n=new (0, _typedbinary.BufferWriter)(this._buffer.getMappedRange());ae(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let i=r.getMappedRange();ae(new (0, _typedbinary.BufferWriter)(i),this.dataType,t);return}let o=_chunkRFXJKOYGcjs.ra.call(void 0, this.dataType);this._group.flush();let a=new ArrayBuffer(o);ae(new (0, _typedbinary.BufferWriter)(a),this.dataType,t),n.queue.writeBuffer(r,0,a,0,o)}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunkRFXJKOYGcjs.ra.call(void 0, 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 E(new (0, _typedbinary.BufferReader)(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),u=E(new (0, _typedbinary.BufferReader)(i),this.dataType);return t.unmap(),u}let n=r.createBuffer({size:_chunkRFXJKOYGcjs.ra.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),o=r.createCommandEncoder();o.copyBufferToBuffer(t,0,n,0,_chunkRFXJKOYGcjs.ra.call(void 0, this.dataType)),r.queue.submit([o.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkRFXJKOYGcjs.ra.call(void 0, this.dataType));let a=E(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),a}destroy(){var t;this._destroyed||(this._destroyed=!0,this._ownBuffer&&((t=this._buffer)==null||t.destroy()))}toString(){var t;return`buffer:${(t=this._label)!=null?t:"<unnamed>"}`}};function te(e){return!!(e!=null&&e.usableAsStorage)}var _e=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};var cr={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},he=class{constructor(t,r){this.usage=t;this.buffer=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"~repr");_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","buffer-usage")}get label(){return this.buffer.label}$name(t){this.buffer.$name(t)}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:o}=t.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),a=cr[this.usage];return t.addDeclaration(`@group(${n}) @binding(${o}) var<${a}> ${r}: ${t.resolve(this.buffer.dataType)};`),r}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkVRYGOFCWcjs.m.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},G)}},be=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;_chunkVRYGOFCWcjs.c.call(void 0, this,"~repr");_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","buffer-usage")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),o=cr[this.usage];return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${o}> ${r}: ${t.resolve(this.dataType)};`),r}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkVRYGOFCWcjs.m.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},G)}},Tr=new WeakMap;function sn(e){if(!te(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=Tr.get(e);return t||(t=new he("mutable",e),Tr.set(e,t)),t}var fr=new WeakMap;function un(e){if(!te(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=fr.get(e);return t||(t=new he("readonly",e),fr.set(e,t)),t}var yr=new WeakMap;function pn(e){if(!xe(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=yr.get(e);return t||(t=new he("uniform",e),yr.set(e,t)),t}function xr(e){return new pt(e)}function hr(e){return new lt(e)}function ln(e){return(e==null?void 0:e.resourceType)==="sampler"}function dn(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var Pe=class{constructor(t){this._membership=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","sampler")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Le=class{constructor(t){this._membership=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","sampler-comparison")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},pt=class{constructor(t){this._props=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","sampler");_chunkVRYGOFCWcjs.c.call(void 0, this,"_label");_chunkVRYGOFCWcjs.c.call(void 0, this,"_filtering");this._filtering=t.minFilter==="linear"||t.magFilter==="linear"||t.mipmapFilter==="linear"}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),{group:n,binding:o}=t.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return t.addDeclaration(`@group(${n}) @binding(${o}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},lt=class{constructor(t){this._props=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","sampler-comparison");_chunkVRYGOFCWcjs.c.call(void 0, this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:o}=t.allocateFixedEntry({sampler:"comparison"},this);return t.addDeclaration(`@group(${n}) @binding(${o}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var Be=class{constructor(t){this._membership=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","external-texture")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var br={r8unorm:_chunkRFXJKOYGcjs.o,r8snorm:_chunkRFXJKOYGcjs.o,r8uint:_chunkRFXJKOYGcjs.m,r8sint:_chunkRFXJKOYGcjs.n,r16uint:_chunkRFXJKOYGcjs.m,r16sint:_chunkRFXJKOYGcjs.n,r16float:_chunkRFXJKOYGcjs.o,rg8unorm:_chunkRFXJKOYGcjs.o,rg8snorm:_chunkRFXJKOYGcjs.o,rg8uint:_chunkRFXJKOYGcjs.m,rg8sint:_chunkRFXJKOYGcjs.n,r32uint:_chunkRFXJKOYGcjs.m,r32sint:_chunkRFXJKOYGcjs.n,r32float:_chunkRFXJKOYGcjs.o,rg16uint:_chunkRFXJKOYGcjs.m,rg16sint:_chunkRFXJKOYGcjs.n,rg16float:_chunkRFXJKOYGcjs.o,rgba8unorm:_chunkRFXJKOYGcjs.o,"rgba8unorm-srgb":_chunkRFXJKOYGcjs.o,rgba8snorm:_chunkRFXJKOYGcjs.o,rgba8uint:_chunkRFXJKOYGcjs.m,rgba8sint:_chunkRFXJKOYGcjs.n,bgra8unorm:_chunkRFXJKOYGcjs.o,"bgra8unorm-srgb":_chunkRFXJKOYGcjs.o,rgb9e5ufloat:_chunkRFXJKOYGcjs.o,rgb10a2uint:_chunkRFXJKOYGcjs.m,rgb10a2unorm:_chunkRFXJKOYGcjs.o,rg11b10ufloat:_chunkRFXJKOYGcjs.o,rg32uint:_chunkRFXJKOYGcjs.m,rg32sint:_chunkRFXJKOYGcjs.n,rg32float:_chunkRFXJKOYGcjs.o,rgba16uint:_chunkRFXJKOYGcjs.m,rgba16sint:_chunkRFXJKOYGcjs.n,rgba16float:_chunkRFXJKOYGcjs.o,rgba32uint:_chunkRFXJKOYGcjs.m,rgba32sint:_chunkRFXJKOYGcjs.n,rgba32float:_chunkRFXJKOYGcjs.o,stencil8:_chunkRFXJKOYGcjs.o,depth16unorm:_chunkRFXJKOYGcjs.o,depth24plus:_chunkRFXJKOYGcjs.o,"depth24plus-stencil8":_chunkRFXJKOYGcjs.o,depth32float:_chunkRFXJKOYGcjs.o,"depth32float-stencil8":_chunkRFXJKOYGcjs.o,"bc1-rgba-unorm":_chunkRFXJKOYGcjs.o,"bc1-rgba-unorm-srgb":_chunkRFXJKOYGcjs.o,"bc2-rgba-unorm":_chunkRFXJKOYGcjs.o,"bc2-rgba-unorm-srgb":_chunkRFXJKOYGcjs.o,"bc3-rgba-unorm":_chunkRFXJKOYGcjs.o,"bc3-rgba-unorm-srgb":_chunkRFXJKOYGcjs.o,"bc4-r-unorm":_chunkRFXJKOYGcjs.o,"bc4-r-snorm":_chunkRFXJKOYGcjs.o,"bc5-rg-unorm":_chunkRFXJKOYGcjs.o,"bc5-rg-snorm":_chunkRFXJKOYGcjs.o,"bc6h-rgb-ufloat":_chunkRFXJKOYGcjs.o,"bc6h-rgb-float":_chunkRFXJKOYGcjs.o,"bc7-rgba-unorm":_chunkRFXJKOYGcjs.o,"bc7-rgba-unorm-srgb":_chunkRFXJKOYGcjs.o,"etc2-rgb8unorm":_chunkRFXJKOYGcjs.o,"etc2-rgb8unorm-srgb":_chunkRFXJKOYGcjs.o,"etc2-rgb8a1unorm":_chunkRFXJKOYGcjs.o,"etc2-rgb8a1unorm-srgb":_chunkRFXJKOYGcjs.o,"etc2-rgba8unorm":_chunkRFXJKOYGcjs.o,"etc2-rgba8unorm-srgb":_chunkRFXJKOYGcjs.o,"eac-r11unorm":_chunkRFXJKOYGcjs.o,"eac-r11snorm":_chunkRFXJKOYGcjs.o,"eac-rg11unorm":_chunkRFXJKOYGcjs.o,"eac-rg11snorm":_chunkRFXJKOYGcjs.o,"astc-4x4-unorm":_chunkRFXJKOYGcjs.o,"astc-4x4-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-5x4-unorm":_chunkRFXJKOYGcjs.o,"astc-5x4-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-5x5-unorm":_chunkRFXJKOYGcjs.o,"astc-5x5-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-6x5-unorm":_chunkRFXJKOYGcjs.o,"astc-6x5-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-6x6-unorm":_chunkRFXJKOYGcjs.o,"astc-6x6-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-8x5-unorm":_chunkRFXJKOYGcjs.o,"astc-8x5-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-8x6-unorm":_chunkRFXJKOYGcjs.o,"astc-8x6-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-8x8-unorm":_chunkRFXJKOYGcjs.o,"astc-8x8-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-10x5-unorm":_chunkRFXJKOYGcjs.o,"astc-10x5-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-10x6-unorm":_chunkRFXJKOYGcjs.o,"astc-10x6-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-10x8-unorm":_chunkRFXJKOYGcjs.o,"astc-10x8-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-10x10-unorm":_chunkRFXJKOYGcjs.o,"astc-10x10-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-12x10-unorm":_chunkRFXJKOYGcjs.o,"astc-12x10-unorm-srgb":_chunkRFXJKOYGcjs.o,"astc-12x12-unorm":_chunkRFXJKOYGcjs.o,"astc-12x12-unorm-srgb":_chunkRFXJKOYGcjs.o},we={rgba8unorm:_chunkVRYGOFCWcjs.v,rgba8snorm:_chunkVRYGOFCWcjs.v,rgba8uint:_chunkVRYGOFCWcjs.y,rgba8sint:_chunkVRYGOFCWcjs.x,rgba16uint:_chunkVRYGOFCWcjs.y,rgba16sint:_chunkVRYGOFCWcjs.x,rgba16float:_chunkVRYGOFCWcjs.v,r32uint:_chunkVRYGOFCWcjs.y,r32sint:_chunkVRYGOFCWcjs.x,r32float:_chunkVRYGOFCWcjs.v,rg32uint:_chunkVRYGOFCWcjs.y,rg32sint:_chunkVRYGOFCWcjs.x,rg32float:_chunkVRYGOFCWcjs.v,rgba32uint:_chunkVRYGOFCWcjs.y,rgba32sint:_chunkVRYGOFCWcjs.x,rgba32float:_chunkVRYGOFCWcjs.v,bgra8unorm:_chunkVRYGOFCWcjs.v},wr={f32:"float",u32:"uint",i32:"sint"},Sr={float:_chunkRFXJKOYGcjs.o,"unfilterable-float":_chunkRFXJKOYGcjs.o,uint:_chunkRFXJKOYGcjs.m,sint:_chunkRFXJKOYGcjs.n,depth:_chunkRFXJKOYGcjs.o};function Dr(e,t){return new dt(e,t)}function k(e){return(e==null?void 0:e.resourceType)==="texture"}function Tt(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function ft(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var Fr={mutable:"read_write",readonly:"read",writeonly:"write"},dt=class{constructor(t,r){this.props=t;this._branch=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","texture");_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsSampled",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"usableAsRender",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"_destroyed",!1);_chunkVRYGOFCWcjs.c.call(void 0, this,"_label");_chunkVRYGOFCWcjs.c.call(void 0, this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);_chunkVRYGOFCWcjs.c.call(void 0, this,"_texture",null)}get label(){return this._label}$name(t){return this._label=t,this}unwrap(){var t,r,n,o,a;if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:(t=this._label)!=null?t:"<unnamed>",format:this.props.format,size:this.props.size,usage:this._flags,dimension:(r=this.props.dimension)!=null?r:"2d",viewFormats:(n=this.props.viewFormats)!=null?n:[],mipLevelCount:(o=this.props.mipLevelCount)!=null?o:1,sampleCount:(a=this.props.sampleCount)!=null?a:1})),this._texture}$usage(...t){let r=t.includes("storage"),n=t.includes("sampled"),o=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=o?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||(this.usableAsStorage=r),this.usableAsSampled||(this.usableAsSampled=n),this.usableAsRender||(this.usableAsRender=o),this}createView(t,r){if(t==="sampled")return this._asSampled(r);let n=r;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,r){var a;if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=(a=t==null?void 0:t.format)!=null?a:this.props.format,o=we[n];return _chunkVRYGOFCWcjs.d.call(void 0, !!o,`Unsupported storage texture format: ${n}`),new mt(t!=null?t:{},r,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){var o;if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=(o=t==null?void 0:t.format)!=null?o:this.props.format;if(!we[r])throw new Error(`Unsupported storage texture format: ${r}`);return new gt(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Ve={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},mt=class{constructor(t,r,n){this.access=r;this._texture=n;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkVRYGOFCWcjs.c.call(void 0, this,"texelDataType");_chunkVRYGOFCWcjs.c.call(void 0, this,"dimension");_chunkVRYGOFCWcjs.c.call(void 0, this,"_view");_chunkVRYGOFCWcjs.c.call(void 0, this,"_format");var o,a,i;this.dimension=(a=(o=t==null?void 0:t.dimension)!=null?o:n.props.dimension)!=null?a:"2d",this._format=(i=t==null?void 0:t.format)!=null?i:n.props.format,this.texelDataType=we[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:o}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),a=`texture_storage_${Ve[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${o}) var ${r}: ${a}<${this._format}, ${Fr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Ee=class{constructor(t,r,n,o){this._format=t;this.dimension=r;this.access=n;this._membership=o;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkVRYGOFCWcjs.c.call(void 0, this,"texelDataType");this.texelDataType=we[this._format]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),o=`texture_storage_${Ve[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${o}<${this._format}, ${Fr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},gt=class{constructor(t,r){this._props=t;this._texture=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkVRYGOFCWcjs.c.call(void 0, this,"channelDataType");_chunkVRYGOFCWcjs.c.call(void 0, this,"dimension");_chunkVRYGOFCWcjs.c.call(void 0, this,"_format");_chunkVRYGOFCWcjs.c.call(void 0, this,"_view");var n,o,a;this.dimension=(o=(n=t==null?void 0:t.dimension)!=null?n:r.props.dimension)!=null?o:"2d",this._format=(a=t==null?void 0:t.format)!=null?a:r.props.format,this.channelDataType=br[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView(_chunkVRYGOFCWcjs.a.call(void 0, {label:`${(t=this.label)!=null?t:"<unnamed>"} - View`},this._props))),this._view}"~resolve"(t){var u;let r=t.names.makeUnique(this.label),n=((u=this._texture.props.sampleCount)!=null?u:1)>1,{group:o,binding:a}=t.allocateFixedEntry({texture:wr[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${Ve[this.dimension]}`;return t.addDeclaration(`@group(${o}) @binding(${a}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Ce=class{constructor(t,r,n,o){this.dimension=r;this._multisampled=n;this._membership=o;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkVRYGOFCWcjs.c.call(void 0, this,"channelDataType");this.channelDataType=Sr[t]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),o=this._multisampled?"texture_multisampled_2d":`texture_${Ve[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${o}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};function yt(e){return!!(e!=null&&e.usableAsSampled)}function mn(e){return!!(e!=null&&e.usableAsRender)}var Ge=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function Oe(e){return new xt(e)}function ke(e){return!!e&&e.resourceType==="bind-group-layout"}function Ur(e){return!!e&&e.resourceType==="bind-group"}var ct=class e extends Error{constructor(t,r){super(`Bind group '${t!=null?t:"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},vr=["compute"],se=["compute","vertex","fragment"],xt=class{constructor(t){this.entries=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"_label");_chunkVRYGOFCWcjs.c.call(void 0, this,"_index");_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","bind-group-layout");_chunkVRYGOFCWcjs.c.call(void 0, this,"bound",{});var n,o,a,i,u;let r=0;for(let[d,l]of Object.entries(t)){if(l===null){r++;continue}let m={idx:r,key:d,layout:this};if("uniform"in l&&(this.bound[d]=new be("uniform",l.uniform,m)),"storage"in l){let T="type"in l.storage?l.storage:l.storage(0);this.bound[d]=new be((n=l.access)!=null?n:"readonly",T,m)}"texture"in l&&(this.bound[d]=new Ce(l.texture,(o=l.viewDimension)!=null?o:"2d",(a=l.multisampled)!=null?a:!1,m)),"storageTexture"in l&&(this.bound[d]=new Ee(l.storageTexture,(i=l.viewDimension)!=null?i:"2d",(u=l.access)!=null?u:"writeonly",m)),"externalTexture"in l&&(this.bound[d]=new Be(m)),"sampler"in l&&(l.sampler==="comparison"?this.bound[d]=new Le(m):this.bound[d]=new Pe(m)),r++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var n;return t.device.createBindGroupLayout({label:(n=this.label)!=null?n:"<unnamed>",entries:Object.values(this.entries).map((o,a)=>{var d,l,m,T;if(o===null)return null;let i=o.visibility,u={binding:a,visibility:0};if("uniform"in o)i=i!=null?i:se,u.buffer={type:"uniform"};else if("storage"in o)i=i!=null?i:o.access==="mutable"?vr:se,u.buffer={type:o.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in o)i=i!=null?i:se,u.sampler={type:o.sampler};else if("texture"in o)i=i!=null?i:se,u.texture={sampleType:o.texture,viewDimension:(d=o.viewDimension)!=null?d:"2d",multisampled:(l=o.multisampled)!=null?l:!1};else if("storageTexture"in o){let g=(m=o.access)!=null?m:"writeonly";i=i!=null?i:g==="readonly"?se:vr,u.storageTexture={format:o.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[g],viewDimension:(T=o.viewDimension)!=null?T:"2d"}}else"externalTexture"in o&&(i=i!=null?i:se,u.externalTexture={});return i!=null&&i.includes("compute")&&(u.visibility|=GPUShaderStage.COMPUTE),i!=null&&i.includes("vertex")&&(u.visibility|=GPUShaderStage.VERTEX),i!=null&&i.includes("fragment")&&(u.visibility|=GPUShaderStage.FRAGMENT),u}).filter(o=>o!==null)})}populate(t){return new re(this,t)}},re=class{constructor(t,r){this.layout=t;this.entries=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","bind-group");for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new ct(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([o,a],i)=>{var d;if(a===null)return null;let u=this.entries[o];if(u===void 0)throw new Error(`'${o}' is a resource required to populate bind group layout '${(d=this.layout.label)!=null?d:"<unnamed>"}'.`);if("uniform"in a){let l;if(ie(u)){if(!xe(u))throw new (0, _chunkVRYGOFCWcjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:i,resource:l}}if("storage"in a){let l;if(ie(u)){if(!te(u))throw new (0, _chunkVRYGOFCWcjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:i,resource:l}}if("texture"in a){let l;if(k(u)){if(!yt(u))throw new Ge(u);l=t.unwrap(u.createView("sampled"))}else l=u;return{binding:i,resource:l}}if("storageTexture"in a){let l;if(k(u)){if(!te(u))throw new _e(u);a.access==="readonly"?l=t.unwrap(u.createView("readonly")):a.access==="mutable"?l=t.unwrap(u.createView("mutable")):l=t.unwrap(u.createView("writeonly"))}else l=u;return{binding:i,resource:l}}if("externalTexture"in a||"sampler"in a)return{binding:i,resource:u};throw new Error(`Malformed bind group entry: ${u} (${JSON.stringify(u)})`)}).filter(o=>o!==null)})}};var Ar="#CATCHALL#",bt=class{constructor(){_chunkVRYGOFCWcjs.c.call(void 0, this,"_stack",[]);_chunkVRYGOFCWcjs.c.call(void 0, this,"_itemDepth",0)}get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}pushFunctionScope(t,r,n){this._stack.push({type:"functionScope",args:t,returnType:r,externalMap:n})}pop(){let t=this._stack.pop();(t==null?void 0:t.type)==="item"&&this._itemDepth--}readSlot(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="item")n.usedSlots.add(t);else if((n==null?void 0:n.type)==="slotBinding"){let o=n.bindingMap.get(t);if(o!==void 0)return o}else if(!((n==null?void 0:n.type)==="functionScope"||(n==null?void 0:n.type)==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="functionScope"){let o=n.args.find(i=>i.value===t);if(o!==void 0)return o;let a=n.externalMap[t];return a!==void 0?{value:a,dataType:w}:void 0}if((n==null?void 0:n.type)==="blockScope"){let o=n.declarations.get(t);if(o!==void 0)return{value:t,dataType:o}}}}},$e=[""," "," "," "," "," "," "," "," "],ht=$e.length-1,wt=class{constructor(){_chunkVRYGOFCWcjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=$e[this.identLevel])!=null?t:$e[ht].repeat(this.identLevel/ht)+$e[this.identLevel%ht]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},St=class{constructor(t){_chunkVRYGOFCWcjs.c.call(void 0, this,"_memoizedResolves",new WeakMap);_chunkVRYGOFCWcjs.c.call(void 0, this,"_memoizedDerived",new WeakMap);_chunkVRYGOFCWcjs.c.call(void 0, this,"_indentController",new wt);_chunkVRYGOFCWcjs.c.call(void 0, this,"_jitTranspiler");_chunkVRYGOFCWcjs.c.call(void 0, this,"_itemStateStack",new bt);_chunkVRYGOFCWcjs.c.call(void 0, this,"_declarations",[]);_chunkVRYGOFCWcjs.c.call(void 0, this,"bindGroupLayoutsToPlaceholderMap",new Map);_chunkVRYGOFCWcjs.c.call(void 0, this,"_nextFreeLayoutPlaceholderIdx",0);_chunkVRYGOFCWcjs.c.call(void 0, this,"fixedBindings",[]);_chunkVRYGOFCWcjs.c.call(void 0, this,"callStack",[]);_chunkVRYGOFCWcjs.c.call(void 0, this,"names");this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){var r;return(r=this._itemStateStack.getResourceById(t))!=null?r:{value:t,dataType:w}}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);let r=it(this,t.body);this._itemStateStack.pop();let n=t.args.map(o=>`${o.value}: ${this.resolve(o.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${this.resolve(t.returnType)}`:`(${n})`,body:r}}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:Ar,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new (0, _chunkVRYGOFCWcjs.f)(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){if(ye(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(j(r))r=this.readSlot(r);else if(z(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let o=t["~compute"](),a=new Map;for(let i of this._itemStateStack.topItem.usedSlots)a.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:a,result:o}),this._memoizedDerived.set(t,r),o}catch(o){throw o instanceof _chunkVRYGOFCWcjs.e?o.appendToTrace(t):new (0, _chunkVRYGOFCWcjs.e)(o,[t])}finally{this._itemStateStack.pop()}}_getOrInstantiate(t){var n;let r=(n=this._memoizedResolves.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let o;_chunkRFXJKOYGcjs.a.call(void 0, t)?o=nt(this,t):z(t)||j(t)?o=this.resolve(this.unwrap(t)):Ze(t)?o=t["~resolve"](this):o=this.resolveValue(t);let a=new Map;for(let i of this._itemStateStack.topItem.usedSlots)a.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:a,result:o}),this._memoizedResolves.set(t,r),o}catch(o){throw o instanceof _chunkVRYGOFCWcjs.e?o.appendToTrace(t):new (0, _chunkVRYGOFCWcjs.e)(o,[t])}finally{this._itemStateStack.pop()}}resolve(t){if(ye(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){let r=_chunkVRYGOFCWcjs.k.call(void 0, this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
15
+ ${u}`:`${e.pre}if (${o})
16
+ ${s}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=S(e,gt(e,r)),o=n?v(e,n):void 0;if(!o||!n)throw new Error("Cannot create variable without an initial value.");if(typeof n=="object"&&"o"in n&&_chunkY2M5GYROcjs.c.call(void 0, e.callStack[e.callStack.length-1])){let s=e.resolve(e.callStack[e.callStack.length-1]);return`${e.pre}var ${a} = ${s}(${S(e,o)});`}return`${e.pre}var ${a} = ${S(e,o)};`}return"b"in t?vr(e,t):`${e.pre}${S(e,v(e,t))};`}function Tt(e,t){return vr(e,t)}var _typedbinary = require('typed-binary');function hn(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 c=hn;var R={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=_chunkY2M5GYROcjs.pa.call(void 0, t);c(e,n);for(let[a,o]of Object.entries(t.propTypes))c(e,_chunkY2M5GYROcjs.pa.call(void 0, o)),Q(e,o,r[a]);c(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkY2M5GYROcjs.pa.call(void 0, t);c(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)c(e,n),Q(e,t.elementType,r[o]);e.seekTo(a+_chunkY2M5GYROcjs.sa.call(void 0, t))},ptrFn(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){var n;(n=R[t.inner.type])==null||n.call(R,e,t,r)},decorated(e,t,r){var o,s;let n=_chunkY2M5GYROcjs.qa.call(void 0, t);c(e,n);let a=e.currentByteOffset;(s=R[(o=t.inner)==null?void 0:o.type])==null||s.call(R,e,t.inner,r),e.seekTo(a+_chunkY2M5GYROcjs.sa.call(void 0, t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){var o,s;let n=_chunkY2M5GYROcjs.pa.call(void 0, t);c(e,n);let a=e.currentByteOffset;for(let u=0;u<Math.min(t.elementCount,r.length);u++)c(e,n),(s=R[(o=t.elementType)==null?void 0:o.type])==null||s.call(R,e,t.elementType,r[u]);e.seekTo(a+_chunkY2M5GYROcjs.sa.call(void 0, t))},unstruct(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=R[o.type])==null||n.call(R,e,o,r[a])},"loose-decorated"(e,t,r){var s;let n=_chunkY2M5GYROcjs.qa.call(void 0, t);c(e,n);let a=e.currentByteOffset,o=R[(s=t.inner)==null?void 0:s.type];return o==null||o(e,t.inner,r),e.seekTo(a+_chunkY2M5GYROcjs.sa.call(void 0, t)),r}};function Q(e,t,r){let n=R[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var ae={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 _chunkLF344PKGcjs.n.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunkLF344PKGcjs.r.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunkLF344PKGcjs.v.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunkLF344PKGcjs.o.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunkLF344PKGcjs.s.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunkLF344PKGcjs.w.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunkLF344PKGcjs.p.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunkLF344PKGcjs.t.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunkLF344PKGcjs.x.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunkLF344PKGcjs.q.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunkLF344PKGcjs.u.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunkLF344PKGcjs.y.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return _chunkLF344PKGcjs.z.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkLF344PKGcjs.A.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkLF344PKGcjs.B.call(void 0, 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=_chunkY2M5GYROcjs.pa.call(void 0, t);c(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))c(e,_chunkY2M5GYROcjs.pa.call(void 0, o)),n[a]=V(e,o);return c(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkY2M5GYROcjs.pa.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++){c(e,r);let o=t.elementType,s=V(e,o);n.push(s)}return c(e,r),n},ptrFn(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return V(e,t.inner)},decorated(e,t){let r=_chunkY2M5GYROcjs.qa.call(void 0, t);c(e,r);let n=e.currentByteOffset,a=V(e,t.inner);return e.seekTo(n+_chunkY2M5GYROcjs.sa.call(void 0, t)),a},uint8:e=>e.readUint8(),uint8x2:e=>_chunkLF344PKGcjs.q.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunkLF344PKGcjs.y.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunkLF344PKGcjs.p.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunkLF344PKGcjs.x.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunkLF344PKGcjs.n.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunkLF344PKGcjs.v.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>_chunkLF344PKGcjs.n.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>_chunkLF344PKGcjs.v.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>_chunkLF344PKGcjs.q.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunkLF344PKGcjs.y.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunkLF344PKGcjs.p.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunkLF344PKGcjs.x.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunkLF344PKGcjs.n.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunkLF344PKGcjs.v.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>_chunkLF344PKGcjs.n.call(void 0, ae.snorm16(e),ae.snorm16(e)),snorm16x4:e=>_chunkLF344PKGcjs.v.call(void 0, ae.snorm16(e),ae.snorm16(e),ae.snorm16(e),ae.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>_chunkLF344PKGcjs.n.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunkLF344PKGcjs.v.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunkLF344PKGcjs.n.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunkLF344PKGcjs.r.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunkLF344PKGcjs.v.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunkLF344PKGcjs.q.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunkLF344PKGcjs.u.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunkLF344PKGcjs.y.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunkLF344PKGcjs.p.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunkLF344PKGcjs.t.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunkLF344PKGcjs.x.call(void 0, 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 _chunkLF344PKGcjs.v.call(void 0, 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 _chunkLF344PKGcjs.v.call(void 0, n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=V(e,a);return r},disarray(e,t){let r=_chunkY2M5GYROcjs.pa.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++)c(e,r),n.push(V(e,t.elementType));return c(e,r),n},"loose-decorated"(e,t){c(e,_chunkY2M5GYROcjs.qa.call(void 0, t));let r=e.currentByteOffset,n=V(e,t.inner);return e.seekTo(r+_chunkY2M5GYROcjs.sa.call(void 0, t)),n}};function V(e,t){let r=ae[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}var Ar=new WeakMap;function Rr(e){let t=Ar.get(e);if(t)return t;let r=new _typedbinary.Measurer,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 u=r.size;c(r,_chunkY2M5GYROcjs.p.call(void 0, e)?_chunkY2M5GYROcjs.qa.call(void 0, s):_chunkY2M5GYROcjs.pa.call(void 0, s)),a&&(a.padding=r.size-u);let p=_chunkY2M5GYROcjs.sa.call(void 0, s);n[o]={offset:r.size,size:p},a=n[o],r.add(p)}return a&&(a.padding=_chunkY2M5GYROcjs.z.call(void 0, _chunkY2M5GYROcjs.sa.call(void 0, e),_chunkY2M5GYROcjs.pa.call(void 0, e))-r.size),Ar.set(e,n),n}function Ir(e,t){var l;let r=_chunkY2M5GYROcjs.sa.call(void 0, e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new (0, _typedbinary.BufferWriter)(n),o=[];function s(m,f,g,D){var x;if(f!=null)if(_chunkY2M5GYROcjs.c.call(void 0, m)||_chunkY2M5GYROcjs.p.call(void 0, m)){let T=Rr(m);for(let[F,b]of Object.entries(T)){let B=m.propTypes[F];if(!B)continue;let ie=f[F];ie!==void 0&&s(B,ie,g+b.offset,(x=b.padding)!=null?x:D)}}else if(_chunkY2M5GYROcjs.b.call(void 0, m)||_chunkY2M5GYROcjs.o.call(void 0, m)){let T=m,F=_chunkY2M5GYROcjs.z.call(void 0, _chunkY2M5GYROcjs.sa.call(void 0, T.elementType),_chunkY2M5GYROcjs.pa.call(void 0, T.elementType));if(!Array.isArray(f))throw new Error("Partial value for array must be an array");let b=f;b.sort((B,ie)=>B.idx-ie.idx);for(let{idx:B,value:ie}of b)s(T.elementType,ie,g+B*F,F-_chunkY2M5GYROcjs.sa.call(void 0, T.elementType))}else{let T=_chunkY2M5GYROcjs.sa.call(void 0, m);a.seekTo(g),Q(a,m,f),o.push({start:g,end:g+T,padding:D})}}if(s(e,t,0),o.length===0)return[];let u=[],p=o[0];for(let m=1;m<o.length;m++){let f=o[m];if(!f||!p)throw new Error("Internal error: missing segment");f.start===p.end+((l=p.padding)!=null?l:0)?(p.end=f.end,p.padding=f.padding):(u.push({data:new Uint8Array(n,p.start,p.end-p.start)}),p=f)}if(!p)throw new Error("Internal error: missing segment");return u.push({data:new Uint8Array(n,p.start,p.end-p.start)}),u}function oe(e){return!!(e!=null&&e.usableAsStorage)}var Ee=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function Ve(e){return!!e.usableAsUniform}var Lr={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Fe=class{constructor(t,r){this.usage=t;this.buffer=r;_chunkLF344PKGcjs.c.call(void 0, this,"~repr");_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","buffer-usage")}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=Lr[this.usage];return t.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${t.resolve(this.buffer.dataType)};`),r}write(t){this.buffer.write(t)}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkLF344PKGcjs.m.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},$)}},Ue=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;_chunkLF344PKGcjs.c.call(void 0, this,"~repr");_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","buffer-usage")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=Lr[this.usage];return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${t.resolve(this.dataType)};`),r}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkLF344PKGcjs.m.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},$)}},Br=new WeakMap;function yt(e){if(!oe(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=Br.get(e);return t||(t=new Fe("mutable",e),Br.set(e,t)),t}var _r=new WeakMap;function ct(e){if(!oe(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=_r.get(e);return t||(t=new Fe("readonly",e),_r.set(e,t)),t}var Pr=new WeakMap;function xt(e){if(!Ve(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=Pr.get(e);return t||(t=new Fe("uniform",e),Pr.set(e,t)),t}var wt={uniform:xt,mutable:yt,readonly:ct};function Cr(e,t,r){return _chunkY2M5GYROcjs.a.call(void 0, t)?new Ge(e,t,r):new Ge(e,t,r,["storage","uniform"])}function ge(e){return e.resourceType==="buffer"}function Dn(e){return!!e.usableAsVertex}var Ge=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","buffer");_chunkLF344PKGcjs.c.call(void 0, this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);_chunkLF344PKGcjs.c.call(void 0, this,"_buffer",null);_chunkLF344PKGcjs.c.call(void 0, this,"_ownBuffer");_chunkLF344PKGcjs.c.call(void 0, this,"_destroyed",!1);_chunkLF344PKGcjs.c.call(void 0, this,"_label");_chunkLF344PKGcjs.c.call(void 0, this,"initial");_chunkLF344PKGcjs.c.call(void 0, this,"usableAsUniform",!1);_chunkLF344PKGcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkLF344PKGcjs.c.call(void 0, this,"usableAsVertex",!1);pr(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}get label(){return this._label}get buffer(){var r;let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:_chunkY2M5GYROcjs.sa.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:(r=this.label)!=null?r:"<unnamed>"}),this.initial)){let n=new (0, _typedbinary.BufferWriter)(this._buffer.getMappedRange());Q(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let s=r.getMappedRange();Q(new (0, _typedbinary.BufferWriter)(s),this.dataType,t);return}let a=_chunkY2M5GYROcjs.sa.call(void 0, this.dataType);this._group.flush();let o=new ArrayBuffer(a);Q(new (0, _typedbinary.BufferWriter)(o),this.dataType,t),n.queue.writeBuffer(r,0,o,0,a)}writePartial(t){let r=this.buffer,n=this._group.device,a=Ir(this.dataType,t);if(r.mapState==="mapped"){let o=r.getMappedRange(),s=new Uint8Array(o);for(let u of a)s.set(u.data,u.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=_chunkY2M5GYROcjs.sa.call(void 0, 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 V(new (0, _typedbinary.BufferReader)(s),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let s=t.getMappedRange(),u=V(new (0, _typedbinary.BufferReader)(s),this.dataType);return t.unmap(),u}let n=r.createBuffer({size:_chunkY2M5GYROcjs.sa.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,_chunkY2M5GYROcjs.sa.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkY2M5GYROcjs.sa.call(void 0, this.dataType));let o=V(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(t){var r;return(r=wt[t])==null?void 0:r.call(wt,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,this._ownBuffer&&((t=this._buffer)==null||t.destroy()))}toString(){var t;return`buffer:${(t=this._label)!=null?t:"<unnamed>"}`}};function Er(e){return new St(e)}function Vr(e){return new Dt(e)}function Fn(e){return(e==null?void 0:e.resourceType)==="sampler"}function Un(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var Oe=class{constructor(t){this._membership=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","sampler")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},$e=class{constructor(t){this._membership=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","sampler-comparison")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},St=class{constructor(t){this._props=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","sampler");_chunkLF344PKGcjs.c.call(void 0, this,"_label");_chunkLF344PKGcjs.c.call(void 0, this,"_filtering");this._filtering=t.minFilter==="linear"||t.magFilter==="linear"||t.mipmapFilter==="linear"}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label),{group:n,binding:a}=t.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Dt=class{constructor(t){this._props=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","sampler-comparison");_chunkLF344PKGcjs.c.call(void 0, this,"_label")}get label(){return this._label}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({sampler:"comparison"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var ke=class{constructor(t){this._membership=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","external-texture")}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout);return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};var Gr={r8unorm:_chunkY2M5GYROcjs.w,r8snorm:_chunkY2M5GYROcjs.w,r8uint:_chunkY2M5GYROcjs.u,r8sint:_chunkY2M5GYROcjs.v,r16uint:_chunkY2M5GYROcjs.u,r16sint:_chunkY2M5GYROcjs.v,r16float:_chunkY2M5GYROcjs.w,rg8unorm:_chunkY2M5GYROcjs.w,rg8snorm:_chunkY2M5GYROcjs.w,rg8uint:_chunkY2M5GYROcjs.u,rg8sint:_chunkY2M5GYROcjs.v,r32uint:_chunkY2M5GYROcjs.u,r32sint:_chunkY2M5GYROcjs.v,r32float:_chunkY2M5GYROcjs.w,rg16uint:_chunkY2M5GYROcjs.u,rg16sint:_chunkY2M5GYROcjs.v,rg16float:_chunkY2M5GYROcjs.w,rgba8unorm:_chunkY2M5GYROcjs.w,"rgba8unorm-srgb":_chunkY2M5GYROcjs.w,rgba8snorm:_chunkY2M5GYROcjs.w,rgba8uint:_chunkY2M5GYROcjs.u,rgba8sint:_chunkY2M5GYROcjs.v,bgra8unorm:_chunkY2M5GYROcjs.w,"bgra8unorm-srgb":_chunkY2M5GYROcjs.w,rgb9e5ufloat:_chunkY2M5GYROcjs.w,rgb10a2uint:_chunkY2M5GYROcjs.u,rgb10a2unorm:_chunkY2M5GYROcjs.w,rg11b10ufloat:_chunkY2M5GYROcjs.w,rg32uint:_chunkY2M5GYROcjs.u,rg32sint:_chunkY2M5GYROcjs.v,rg32float:_chunkY2M5GYROcjs.w,rgba16uint:_chunkY2M5GYROcjs.u,rgba16sint:_chunkY2M5GYROcjs.v,rgba16float:_chunkY2M5GYROcjs.w,rgba32uint:_chunkY2M5GYROcjs.u,rgba32sint:_chunkY2M5GYROcjs.v,rgba32float:_chunkY2M5GYROcjs.w,stencil8:_chunkY2M5GYROcjs.w,depth16unorm:_chunkY2M5GYROcjs.w,depth24plus:_chunkY2M5GYROcjs.w,"depth24plus-stencil8":_chunkY2M5GYROcjs.w,depth32float:_chunkY2M5GYROcjs.w,"depth32float-stencil8":_chunkY2M5GYROcjs.w,"bc1-rgba-unorm":_chunkY2M5GYROcjs.w,"bc1-rgba-unorm-srgb":_chunkY2M5GYROcjs.w,"bc2-rgba-unorm":_chunkY2M5GYROcjs.w,"bc2-rgba-unorm-srgb":_chunkY2M5GYROcjs.w,"bc3-rgba-unorm":_chunkY2M5GYROcjs.w,"bc3-rgba-unorm-srgb":_chunkY2M5GYROcjs.w,"bc4-r-unorm":_chunkY2M5GYROcjs.w,"bc4-r-snorm":_chunkY2M5GYROcjs.w,"bc5-rg-unorm":_chunkY2M5GYROcjs.w,"bc5-rg-snorm":_chunkY2M5GYROcjs.w,"bc6h-rgb-ufloat":_chunkY2M5GYROcjs.w,"bc6h-rgb-float":_chunkY2M5GYROcjs.w,"bc7-rgba-unorm":_chunkY2M5GYROcjs.w,"bc7-rgba-unorm-srgb":_chunkY2M5GYROcjs.w,"etc2-rgb8unorm":_chunkY2M5GYROcjs.w,"etc2-rgb8unorm-srgb":_chunkY2M5GYROcjs.w,"etc2-rgb8a1unorm":_chunkY2M5GYROcjs.w,"etc2-rgb8a1unorm-srgb":_chunkY2M5GYROcjs.w,"etc2-rgba8unorm":_chunkY2M5GYROcjs.w,"etc2-rgba8unorm-srgb":_chunkY2M5GYROcjs.w,"eac-r11unorm":_chunkY2M5GYROcjs.w,"eac-r11snorm":_chunkY2M5GYROcjs.w,"eac-rg11unorm":_chunkY2M5GYROcjs.w,"eac-rg11snorm":_chunkY2M5GYROcjs.w,"astc-4x4-unorm":_chunkY2M5GYROcjs.w,"astc-4x4-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-5x4-unorm":_chunkY2M5GYROcjs.w,"astc-5x4-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-5x5-unorm":_chunkY2M5GYROcjs.w,"astc-5x5-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-6x5-unorm":_chunkY2M5GYROcjs.w,"astc-6x5-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-6x6-unorm":_chunkY2M5GYROcjs.w,"astc-6x6-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-8x5-unorm":_chunkY2M5GYROcjs.w,"astc-8x5-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-8x6-unorm":_chunkY2M5GYROcjs.w,"astc-8x6-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-8x8-unorm":_chunkY2M5GYROcjs.w,"astc-8x8-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-10x5-unorm":_chunkY2M5GYROcjs.w,"astc-10x5-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-10x6-unorm":_chunkY2M5GYROcjs.w,"astc-10x6-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-10x8-unorm":_chunkY2M5GYROcjs.w,"astc-10x8-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-10x10-unorm":_chunkY2M5GYROcjs.w,"astc-10x10-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-12x10-unorm":_chunkY2M5GYROcjs.w,"astc-12x10-unorm-srgb":_chunkY2M5GYROcjs.w,"astc-12x12-unorm":_chunkY2M5GYROcjs.w,"astc-12x12-unorm-srgb":_chunkY2M5GYROcjs.w},ve={rgba8unorm:_chunkLF344PKGcjs.v,rgba8snorm:_chunkLF344PKGcjs.v,rgba8uint:_chunkLF344PKGcjs.y,rgba8sint:_chunkLF344PKGcjs.x,rgba16uint:_chunkLF344PKGcjs.y,rgba16sint:_chunkLF344PKGcjs.x,rgba16float:_chunkLF344PKGcjs.v,r32uint:_chunkLF344PKGcjs.y,r32sint:_chunkLF344PKGcjs.x,r32float:_chunkLF344PKGcjs.v,rg32uint:_chunkLF344PKGcjs.y,rg32sint:_chunkLF344PKGcjs.x,rg32float:_chunkLF344PKGcjs.v,rgba32uint:_chunkLF344PKGcjs.y,rgba32sint:_chunkLF344PKGcjs.x,rgba32float:_chunkLF344PKGcjs.v,bgra8unorm:_chunkLF344PKGcjs.v},Or={f32:"float",u32:"uint",i32:"sint"},$r={float:_chunkY2M5GYROcjs.w,"unfilterable-float":_chunkY2M5GYROcjs.w,uint:_chunkY2M5GYROcjs.u,sint:_chunkY2M5GYROcjs.v,depth:_chunkY2M5GYROcjs.w};function kr(e,t){return new Ft(e,t)}function W(e){return(e==null?void 0:e.resourceType)==="texture"}function At(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function Rt(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var Mr={mutable:"read_write",readonly:"read",writeonly:"write"},Ft=class{constructor(t,r){this.props=t;this._branch=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","texture");_chunkLF344PKGcjs.c.call(void 0, this,"usableAsSampled",!1);_chunkLF344PKGcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkLF344PKGcjs.c.call(void 0, this,"usableAsRender",!1);_chunkLF344PKGcjs.c.call(void 0, this,"_destroyed",!1);_chunkLF344PKGcjs.c.call(void 0, this,"_label");_chunkLF344PKGcjs.c.call(void 0, this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);_chunkLF344PKGcjs.c.call(void 0, this,"_texture",null)}get label(){return this._label}$name(t){return this._label=t,this}unwrap(){var t,r,n,a,o;if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:(t=this._label)!=null?t:"<unnamed>",format:this.props.format,size:this.props.size,usage:this._flags,dimension:(r=this.props.dimension)!=null?r:"2d",viewFormats:(n=this.props.viewFormats)!=null?n:[],mipLevelCount:(a=this.props.mipLevelCount)!=null?a:1,sampleCount:(o=this.props.sampleCount)!=null?o:1})),this._texture}$usage(...t){let r=t.includes("storage"),n=t.includes("sampled"),a=t.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||(this.usableAsStorage=r),this.usableAsSampled||(this.usableAsSampled=n),this.usableAsRender||(this.usableAsRender=a),this}createView(t,r){if(t==="sampled")return this._asSampled(r);let n=r;switch(t){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(t,r){var o;if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=(o=t==null?void 0:t.format)!=null?o:this.props.format,a=ve[n];return _chunkLF344PKGcjs.d.call(void 0, !!a,`Unsupported storage texture format: ${n}`),new Ut(t!=null?t:{},r,this)}_asReadonly(t){return this._asStorage(t,"readonly")}_asWriteonly(t){return this._asStorage(t,"writeonly")}_asMutable(t){return this._asStorage(t,"mutable")}_asSampled(t){var a;if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=(a=t==null?void 0:t.format)!=null?a:this.props.format;if(!ve[r])throw new Error(`Unsupported storage texture format: ${r}`);return new vt(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Ne={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Ut=class{constructor(t,r,n){this.access=r;this._texture=n;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkLF344PKGcjs.c.call(void 0, this,"texelDataType");_chunkLF344PKGcjs.c.call(void 0, this,"dimension");_chunkLF344PKGcjs.c.call(void 0, this,"_view");_chunkLF344PKGcjs.c.call(void 0, this,"_format");var a,o,s;this.dimension=(o=(a=t==null?void 0:t.dimension)!=null?a:n.props.dimension)!=null?o:"2d",this._format=(s=t==null?void 0:t.format)!=null?s:n.props.format,this.texelDataType=ve[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`,format:this._format,dimension:this.dimension})),this._view}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding:a}=t.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),o=`texture_storage_${Ne[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${Mr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Me=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkLF344PKGcjs.c.call(void 0, this,"texelDataType");this.texelDataType=ve[this._format]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=`texture_storage_${Ne[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${Mr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},vt=class{constructor(t,r){this._props=t;this._texture=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkLF344PKGcjs.c.call(void 0, this,"channelDataType");_chunkLF344PKGcjs.c.call(void 0, this,"dimension");_chunkLF344PKGcjs.c.call(void 0, this,"_format");_chunkLF344PKGcjs.c.call(void 0, this,"_view");var n,a,o;this.dimension=(a=(n=t==null?void 0:t.dimension)!=null?n:r.props.dimension)!=null?a:"2d",this._format=(o=t==null?void 0:t.format)!=null?o:r.props.format,this.channelDataType=Gr[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView(_chunkLF344PKGcjs.a.call(void 0, {label:`${(t=this.label)!=null?t:"<unnamed>"} - View`},this._props))),this._view}"~resolve"(t){var u;let r=t.names.makeUnique(this.label),n=((u=this._texture.props.sampleCount)!=null?u:1)>1,{group:a,binding:o}=t.allocateFixedEntry({texture:Or[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${Ne[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${s}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},We=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkLF344PKGcjs.c.call(void 0, this,"channelDataType");this.channelDataType=$r[t]}get label(){return this._membership.key}"~resolve"(t){let r=t.names.makeUnique(this.label),n=t.allocateLayoutEntry(this._membership.layout),a=this._multisampled?"texture_multisampled_2d":`texture_${Ne[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}};function It(e){return!!(e!=null&&e.usableAsSampled)}function vn(e){return!!(e!=null&&e.usableAsRender)}var je=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function ze(e){return new _t(e)}function Ke(e){return!!e&&e.resourceType==="bind-group-layout"}function Nr(e){return!!e&&e.resourceType==="bind-group"}var Bt=class e extends Error{constructor(t,r){super(`Bind group '${t!=null?t:"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},Wr=["compute"],fe=["compute","vertex","fragment"],_t=class{constructor(t){this.entries=t;_chunkLF344PKGcjs.c.call(void 0, this,"_label");_chunkLF344PKGcjs.c.call(void 0, this,"_index");_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","bind-group-layout");_chunkLF344PKGcjs.c.call(void 0, this,"bound",{});var n,a,o,s,u;let r=0;for(let[p,l]of Object.entries(t)){if(l===null){r++;continue}let m={idx:r,key:p,layout:this};if("uniform"in l&&(this.bound[p]=new Ue("uniform",l.uniform,m)),"storage"in l){let f="type"in l.storage?l.storage:l.storage(0);this.bound[p]=new Ue((n=l.access)!=null?n:"readonly",f,m)}"texture"in l&&(this.bound[p]=new We(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,m)),"storageTexture"in l&&(this.bound[p]=new Me(l.storageTexture,(s=l.viewDimension)!=null?s:"2d",(u=l.access)!=null?u:"writeonly",m)),"externalTexture"in l&&(this.bound[p]=new ke(m)),"sampler"in l&&(l.sampler==="comparison"?this.bound[p]=new $e(m):this.bound[p]=new Oe(m)),r++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var n;return t.device.createBindGroupLayout({label:(n=this.label)!=null?n:"<unnamed>",entries:Object.values(this.entries).map((a,o)=>{var p,l,m,f;if(a===null)return null;let s=a.visibility,u={binding:o,visibility:0};if("uniform"in a)s=s!=null?s:fe,u.buffer={type:"uniform"};else if("storage"in a)s=s!=null?s:a.access==="mutable"?Wr:fe,u.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)s=s!=null?s:fe,u.sampler={type:a.sampler};else if("texture"in a)s=s!=null?s:fe,u.texture={sampleType:a.texture,viewDimension:(p=a.viewDimension)!=null?p:"2d",multisampled:(l=a.multisampled)!=null?l:!1};else if("storageTexture"in a){let g=(m=a.access)!=null?m:"writeonly";s=s!=null?s:g==="readonly"?fe:Wr,u.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[g],viewDimension:(f=a.viewDimension)!=null?f:"2d"}}else"externalTexture"in a&&(s=s!=null?s:fe,u.externalTexture={});return s!=null&&s.includes("compute")&&(u.visibility|=GPUShaderStage.COMPUTE),s!=null&&s.includes("vertex")&&(u.visibility|=GPUShaderStage.VERTEX),s!=null&&s.includes("fragment")&&(u.visibility|=GPUShaderStage.FRAGMENT),u}).filter(a=>a!==null)})}populate(t){return new se(this,t)}},se=class{constructor(t,r){this.layout=t;this.entries=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","bind-group");for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new Bt(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],s)=>{var p;if(o===null)return null;let u=this.entries[a];if(u===void 0)throw new Error(`'${a}' is a resource required to populate bind group layout '${(p=this.layout.label)!=null?p:"<unnamed>"}'.`);if("uniform"in o){let l;if(ge(u)){if(!Ve(u))throw new (0, _chunkLF344PKGcjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:s,resource:l}}if("storage"in o){let l;if(ge(u)){if(!oe(u))throw new (0, _chunkLF344PKGcjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:s,resource:l}}if("texture"in o){let l;if(W(u)){if(!It(u))throw new je(u);l=t.unwrap(u.createView("sampled"))}else l=u;return{binding:s,resource:l}}if("storageTexture"in o){let l;if(W(u)){if(!oe(u))throw new Ee(u);o.access==="readonly"?l=t.unwrap(u.createView("readonly")):o.access==="mutable"?l=t.unwrap(u.createView("mutable")):l=t.unwrap(u.createView("writeonly"))}else l=u;return{binding:s,resource:l}}if("externalTexture"in o||"sampler"in o)return{binding:s,resource:u};throw new Error(`Malformed bind group entry: ${u} (${JSON.stringify(u)})`)}).filter(a=>a!==null)})}};var jr="#CATCHALL#",Lt=class{constructor(){_chunkLF344PKGcjs.c.call(void 0, this,"_stack",[]);_chunkLF344PKGcjs.c.call(void 0, this,"_itemDepth",0)}get itemDepth(){return this._itemDepth}get topItem(){let t=this._stack[this._stack.length-1];if(!t||t.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return t}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}pushFunctionScope(t,r,n){this._stack.push({type:"functionScope",args:t,returnType:r,externalMap:n})}pop(){let t=this._stack.pop();(t==null?void 0:t.type)==="item"&&this._itemDepth--}readSlot(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="item")n.usedSlots.add(t);else if((n==null?void 0:n.type)==="slotBinding"){let a=n.bindingMap.get(t);if(a!==void 0)return a}else if(!((n==null?void 0:n.type)==="functionScope"||(n==null?void 0:n.type)==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getResourceById(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if((n==null?void 0:n.type)==="functionScope"){let a=n.args.find(s=>s.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:U}:void 0}if((n==null?void 0:n.type)==="blockScope"){let a=n.declarations.get(t);if(a!==void 0)return{value:t,dataType:a}}}}},qe=[""," "," "," "," "," "," "," "," "],Pt=qe.length-1,Ct=class{constructor(){_chunkLF344PKGcjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=qe[this.identLevel])!=null?t:qe[Pt].repeat(this.identLevel/Pt)+qe[this.identLevel%Pt]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},Et=class{constructor(t){_chunkLF344PKGcjs.c.call(void 0, this,"_memoizedResolves",new WeakMap);_chunkLF344PKGcjs.c.call(void 0, this,"_memoizedDerived",new WeakMap);_chunkLF344PKGcjs.c.call(void 0, this,"_indentController",new Ct);_chunkLF344PKGcjs.c.call(void 0, this,"_jitTranspiler");_chunkLF344PKGcjs.c.call(void 0, this,"_itemStateStack",new Lt);_chunkLF344PKGcjs.c.call(void 0, this,"_declarations",[]);_chunkLF344PKGcjs.c.call(void 0, this,"bindGroupLayoutsToPlaceholderMap",new Map);_chunkLF344PKGcjs.c.call(void 0, this,"_nextFreeLayoutPlaceholderIdx",0);_chunkLF344PKGcjs.c.call(void 0, this,"fixedBindings",[]);_chunkLF344PKGcjs.c.call(void 0, this,"callStack",[]);_chunkLF344PKGcjs.c.call(void 0, this,"names");this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){var r;return(r=this._itemStateStack.getResourceById(t))!=null?r:{value:t,dataType:U}}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);let r=Tt(this,t.body);this._itemStateStack.pop();let n=t.args.map(a=>`${a.value}: ${this.resolve(a.dataType)}`).join(", ");return{head:t.returnType!==void 0?`(${n}) -> ${_chunkY2M5GYROcjs.Fa.call(void 0, t.returnType)} ${this.resolve(t.returnType)}`:`(${n})`,body:r}}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:jr,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new (0, _chunkLF344PKGcjs.f)(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){if(we(t))return this.withSlots(t["~providing"].pairs,()=>this.unwrap(t["~providing"].inner));let r=t;for(;;)if(q(r))r=this.readSlot(r);else if(J(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let s of r)if([...s.slotToValueMap.entries()].every(([p,l])=>p.areEqual(this._itemStateStack.readSlot(p),l)))return s.result;let a=t["~compute"](),o=new Map;for(let s of this._itemStateStack.topItem.usedSlots)o.set(s,this._itemStateStack.readSlot(s));return r.push({slotToValueMap:o,result:a}),this._memoizedDerived.set(t,r),a}catch(a){throw a instanceof _chunkLF344PKGcjs.e?a.appendToTrace(t):new (0, _chunkLF344PKGcjs.e)(a,[t])}finally{this._itemStateStack.pop()}}_getOrInstantiate(t){var n;let r=(n=this._memoizedResolves.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let s of r)if([...s.slotToValueMap.entries()].every(([p,l])=>p.areEqual(this._itemStateStack.readSlot(p),l)))return s.result;let a;_chunkY2M5GYROcjs.a.call(void 0, t)||_chunkY2M5GYROcjs.n.call(void 0, t)?a=mt(this,t):J(t)||q(t)?a=this.resolve(this.unwrap(t)):it(t)?a=t["~resolve"](this):a=this.resolveValue(t);let o=new Map;for(let s of this._itemStateStack.topItem.usedSlots)o.set(s,this._itemStateStack.readSlot(s));return r.push({slotToValueMap:o,result:a}),this._memoizedResolves.set(t,r),a}catch(a){throw a instanceof _chunkLF344PKGcjs.e?a.appendToTrace(t):new (0, _chunkLF344PKGcjs.e)(a,[t])}finally{this._itemStateStack.pop()}}resolve(t){if(we(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){let r=_chunkLF344PKGcjs.k.call(void 0, this,()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
13
17
 
14
- `)}${r}`}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(X(t))return this.resolve(t);if(r&&_chunkRFXJKOYGcjs.b.call(void 0, 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&&_chunkRFXJKOYGcjs.c.call(void 0, r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,o])=>this.resolveValue(t[n],o))})`;throw new Error(`Value ${t} (as json: ${JSON.stringify(t)}) of schema ${r} is not resolvable to WGSL`)}};function ue(e,t){var T;let r=new St(t),n=r.resolve(e),o=r.bindGroupLayoutsToPlaceholderMap,a=[],i=new Set([...o.keys()].map(g=>g.index).filter(g=>g!==void 0)),u=lr(i),d=r.fixedBindings.map((g,v)=>[String(v),g.layoutEntry]),l=()=>{let g=u.next().value,v=Oe(Object.fromEntries(d));return a[g]=v,n=n.replaceAll(Ar,String(g)),[g,new re(v,Object.fromEntries(r.fixedBindings.map((h,f)=>[String(f),h.resource])))]},m=d.length>0?l():null;for(let[g,v]of o.entries()){let h=(T=g.index)!=null?T:u.next().value;a[h]=g,n=n.replaceAll(v,String(h))}return{code:n,bindGroupLayouts:a,catchall:m}}function Ir(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:o}=e,a={};Q(a,t!=null?t:{});let i={"~resolve"(d){return Z(d,a,r!=null?r:"")},toString:()=>"<root>"},{code:u}=ue(i,{names:n==="strict"?new J:new q,jitTranspiler:o});return u}var Se=class{constructor(t){this._make=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"_map",new WeakMap)}getOrMake(t,...r){if(this._map.has(t))return this._map.get(t);let n=this._make(t,...r);return this._map.set(t,n),n}};function Rr(e,t,r){return new Dt(new Ft(e,t,r),{})}function _r(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var Dt=class e{constructor(t,r){this._core=t;this._priors=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","compute-pipeline")}get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(t,r){var n;return new e(this._core,{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])})}dispatchWorkgroups(t,r,n){let o=this._core.unwrap(),{branch:a,label:i}=this._core,u=a.commandEncoder.beginComputePass({label:i!=null?i:"<unnamed>"});u.setPipeline(o.pipeline);let d=new Set(o.bindGroupLayouts);if(o.bindGroupLayouts.forEach((l,m)=>{var T;if(o.catchall&&m===o.catchall[0])u.setBindGroup(m,a.unwrap(o.catchall[1])),d.delete(l);else{let g=(T=this._priors.bindGroupLayoutMap)==null?void 0:T.get(l);g!==void 0&&(d.delete(l),u.setBindGroup(m,a.unwrap(g)))}}),d.size>0)throw new (0, _chunkVRYGOFCWcjs.i)(d);u.dispatchWorkgroups(t,r,n),u.end()}$name(t){return this._core.label=t,this}},Ft=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;_chunkVRYGOFCWcjs.c.call(void 0, this,"label");_chunkVRYGOFCWcjs.c.call(void 0, this,"_memo")}unwrap(){var t,r,n,o,a;if(this._memo===void 0){let i=this.branch.device,{code:u,bindGroupLayouts:d,catchall:l}=ue({"~resolve":m=>(m.withSlots(this._slotBindings,()=>{m.resolve(this._entryFn)}),""),toString:()=>{var m;return`computePipeline:${(m=this.label)!=null?m:"<unnamed>"}`}},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});l!==null&&((r=d[l[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`)),this._memo={pipeline:i.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:i.createPipelineLayout({label:`${(o=this.label)!=null?o:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:d.map(m=>this.branch.unwrap(m))}),compute:{module:i.createShaderModule({label:`${(a=this.label)!=null?a:"<unnamed>"} - Shader`,code:u})}}),bindGroupLayouts:d,catchall:l}}return this._memo}};function gn(e){return typeof(e==null?void 0:e.format)=="string"}function Pr(e,t){var i,u;let r=[];if(_chunkRFXJKOYGcjs.z.call(void 0, e)){if(!gn(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:(i=_chunkRFXJKOYGcjs.y.call(void 0, e))!=null?i:0}]}]}}let n=[],o=new WeakMap,a=0;for(let[d,l]of Object.entries(e)){if(_chunkRFXJKOYGcjs.Ha.call(void 0, l))continue;let m=t[d];if(!m)throw new Error(`An attribute by the name of '${d}' was not provided to the shader.`);let T=m._layout,g=o.get(T);g||(r.push(T),g=[],n.push({arrayStride:T.stride,stepMode:T.stepMode,attributes:g}),o.set(T,g)),a=(u=_chunkRFXJKOYGcjs.y.call(void 0, l))!=null?u:a,g.push({format:m.format,offset:m.offset,shaderLocation:a++})}return{usedVertexLayouts:r,bufferDefinitions:n}}function Lr(e,t="vertex"){return new vt(e,t)}function Br(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}function We(e,t,r){if(_chunkRFXJKOYGcjs.k.call(void 0, t)||_chunkRFXJKOYGcjs.x.call(void 0, t))return We(e,t.inner,_chunkRFXJKOYGcjs.r.call(void 0, r,_chunkRFXJKOYGcjs.pa.call(void 0, t)));if(_chunkRFXJKOYGcjs.c.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([o,a])=>{n=_chunkRFXJKOYGcjs.r.call(void 0, n,_chunkRFXJKOYGcjs.oa.call(void 0, a));let i=[o,We(e,a,n)];return n+=_chunkRFXJKOYGcjs.ra.call(void 0, a),i}))}if(_chunkRFXJKOYGcjs.w.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([o,a])=>{n=_chunkRFXJKOYGcjs.r.call(void 0, n,_chunkRFXJKOYGcjs.pa.call(void 0, a));let i=[o,We(e,a,n)];return n+=_chunkRFXJKOYGcjs.ra.call(void 0, a),i}))}if("type"in t&&typeof t.type=="string"){if(_chunkRFXJKOYGcjs.s.includes(t.type))return{_layout:e,format:t.type,offset:r};let n=_chunkRFXJKOYGcjs.t[t.type];if(n)return{_layout:e,format:n,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var vt=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","vertex-layout");_chunkVRYGOFCWcjs.c.call(void 0, this,"stride");_chunkVRYGOFCWcjs.c.call(void 0, this,"attrib");_chunkVRYGOFCWcjs.c.call(void 0, this,"_label");let n=t(0);this.stride=_chunkRFXJKOYGcjs.r.call(void 0, _chunkRFXJKOYGcjs.ra.call(void 0, n.elementType),_chunkRFXJKOYGcjs.oa.call(void 0, n)),this.attrib=We(this,n.elementType,0)}get label(){return this._label}$name(t){return this._label=t,this}};function Tn(e){return typeof(e==null?void 0:e.loadOp)=="string"}function Er(e,t){if(_chunkRFXJKOYGcjs.z.call(void 0, e)){if(!Tn(t))throw new Error("Expected a single color attachment, not a record.");return[t]}let r=[];for(let n of Object.keys(e)){let o=t[n];if(!o)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(o)}return r}function fn(e){return typeof(e==null?void 0:e.format)=="string"}function Cr(e,t){if(_chunkRFXJKOYGcjs.z.call(void 0, e)){if(!fn(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 o=t[n];if(!o)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(o)}return r}function Vr(e){return new Ut(new At(e),{})}var Ut=class e{constructor(t,r){this._core=t;this._priors=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","render-pipeline")}get label(){return this._core.label}$name(t){return this._core.label=t,this}with(t,r){var n,o;if(ke(t))return new e(this._core,_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(Br(t))return new e(this._core,_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._priors),{vertexLayoutMap:new Map([...(o=this._priors.vertexLayoutMap)!=null?o:[],[t,r]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(t){return new e(this._core,_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._priors),{colorAttachment:t}))}withDepthStencilAttachment(t){return new e(this._core,_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._priors),{depthStencilAttachment:t}))}draw(t,r,n,o){var h;let a=this._core.unwrap(),{branch:i,fragmentFn:u}=this._core.options,l={colorAttachments:Er(u.shell.returnType,(h=this._priors.colorAttachment)!=null?h:{}).map(f=>k(f.view)?_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},f),{view:i.unwrap(f.view).createView()}):f)};if(this._core.label!==void 0&&(l.label=this._core.label),this._priors.depthStencilAttachment!==void 0){let f=this._priors.depthStencilAttachment;k(f.view)?l.depthStencilAttachment=_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},f),{view:i.unwrap(f.view).createView()}):l.depthStencilAttachment=f}let m=i.commandEncoder.beginRenderPass(l);m.setPipeline(a.pipeline);let T=new Set(a.bindGroupLayouts);a.bindGroupLayouts.forEach((f,C)=>{var D;if(a.catchall&&C===a.catchall[0])m.setBindGroup(C,i.unwrap(a.catchall[1])),T.delete(f);else{let pe=(D=this._priors.bindGroupLayoutMap)==null?void 0:D.get(f);pe!==void 0&&(T.delete(f),m.setBindGroup(C,i.unwrap(pe)))}});let g=new Set(this._core.usedVertexLayouts);if(this._core.usedVertexLayouts.forEach((f,C)=>{var pe;let D=(pe=this._priors.vertexLayoutMap)==null?void 0:pe.get(f);D&&(g.delete(f),m.setVertexBuffer(C,i.unwrap(D)))}),T.size>0)throw new (0, _chunkVRYGOFCWcjs.i)(T);if(g.size>0)throw new (0, _chunkVRYGOFCWcjs.j)(g);m.draw(t,r,n,o),m.end()}},At=class{constructor(t){this.options=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"label");_chunkVRYGOFCWcjs.c.call(void 0, this,"usedVertexLayouts");_chunkVRYGOFCWcjs.c.call(void 0, this,"_memo");_chunkVRYGOFCWcjs.c.call(void 0, this,"_vertexBufferLayouts");_chunkVRYGOFCWcjs.c.call(void 0, this,"_targets");let r=Pr(t.vertexFn.shell.attributes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Cr(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,r,n,o;if(this._memo===void 0){let{branch:a,vertexFn:i,fragmentFn:u,slotBindings:d,primitiveState:l,depthStencilState:m}=this.options,{code:T,bindGroupLayouts:g,catchall:v}=ue({"~resolve":D=>(D.withSlots(d,()=>{D.resolve(i),D.resolve(u)}),""),toString:()=>{var D;return`renderPipeline:${(D=this.label)!=null?D:"<unnamed>"}`}},{names:a.nameRegistry,jitTranspiler:a.jitTranspiler});v!==null&&((r=g[v[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let h=a.device,f=h.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:T}),C={layout:h.createPipelineLayout({label:`${(o=this.label)!=null?o:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:g.map(D=>a.unwrap(D))}),vertex:{module:f,buffers:this._vertexBufferLayouts},fragment:{module:f,targets:this._targets}};this.label!==void 0&&(C.label=this.label),l&&(C.primitive=l),m&&(C.depthStencil=m),this._memo={pipeline:h.createRenderPipeline(C),bindGroupLayouts:g,catchall:v}}return this._memo}};var It=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[Y(t)?t.slot:t,r]])}withCompute(t){return new Rt(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new _t({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},Rt=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Rr(this._root,this._slotBindings,this._entryFn)}},_t=class{constructor(t){this._options=t}withFragment(t,r,n){return _chunkVRYGOFCWcjs.d.call(void 0, typeof t!="string","Just type mismatch validation"),_chunkVRYGOFCWcjs.d.call(void 0, typeof r!="string","Just type mismatch validation"),new Pt(_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},Pt=class e{constructor(t){this._options=t}withPrimitive(t){return new e(_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._options),{primitiveState:t}))}withDepthStencil(t){return new e(_chunkVRYGOFCWcjs.b.call(void 0, _chunkVRYGOFCWcjs.a.call(void 0, {},this._options),{depthStencilState:t}))}createPipeline(){return Vr(this._options)}},Me=class extends It{constructor(r,n,o,a){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=o;this._ownDevice=a;_chunkVRYGOFCWcjs.c.call(void 0, this,"~unstable");_chunkVRYGOFCWcjs.c.call(void 0, this,"_disposables",[]);_chunkVRYGOFCWcjs.c.call(void 0, this,"_unwrappedBindGroupLayouts",new Se(r=>r.unwrap(this)));_chunkVRYGOFCWcjs.c.call(void 0, this,"_unwrappedBindGroups",new Se(r=>r.unwrap(this)));_chunkVRYGOFCWcjs.c.call(void 0, this,"_commandEncoder",null);this["~unstable"]={nameRegistry:this.nameRegistry,commandEncoder:this.commandEncoder,createTexture:this.createTexture.bind(this),with:this.with.bind(this),withCompute:this.withCompute.bind(this),withVertex:this.withVertex.bind(this),flush:this.flush.bind(this)}}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let o=gr(this,r,n);return this._disposables.push(o),o}createBindGroup(r,n){return new re(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=Dr(r,this);return this._disposables.push(n),n}unwrap(r){if(_r(r))return r.rawPipeline;if(ke(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(Ur(r))return this._unwrappedBindGroups.getOrMake(r);if(ie(r))return r.buffer;if(k(r)||Tt(r)||ft(r))return r.unwrap();throw new Error(`Unknown resource type: ${r}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Gr(e){let{adapter:t,device:r,unstable_names:n="random",unstable_jitTranspiler:o}=e!=null?e:{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let a=await navigator.gpu.requestAdapter(t);if(!a)throw new Error("Could not find a compatible GPU");return new Me(await a.requestDevice(r),n==="random"?new q:new J,o,!0)}function Or(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new Me(t,r==="random"?new q:new J,n,!1)}function Ne(e){return new Lt(e)}var Lt=class{constructor(t=void 0){this.defaultValue=t;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","slot");_chunkVRYGOFCWcjs.c.call(void 0, this,"label");_chunkVRYGOFCWcjs.c.call(void 0, this,"~repr")}$name(t){return this.label=t,this}areEqual(t,r){return Object.is(t,r)}toString(){var t;return`slot:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){let t=_chunkVRYGOFCWcjs.l.call(void 0, );if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return ce(t.unwrap(this))}};function kr(e,t){return new Bt(e,t)}var Bt=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;_chunkVRYGOFCWcjs.c.call(void 0, this,"resourceType","accessor");_chunkVRYGOFCWcjs.c.call(void 0, this,"~repr");_chunkVRYGOFCWcjs.c.call(void 0, this,"label");_chunkVRYGOFCWcjs.c.call(void 0, this,"slot");this.slot=Ne(r)}$name(t){return this.label=t,this.slot.$name(t),this}toString(){var t;return`accessor:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkVRYGOFCWcjs.l.call(void 0, ))throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return new Proxy({"~resolve":r=>r.resolve(this),toString:()=>{var r;return`.value:${(r=this.label)!=null?r:"<unnamed>"}`}},G)}"~resolve"(t){let r=t.unwrap(this.slot);return ve(r)?t.resolve(r):rt(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function $r(e){return cn(e)}function yn([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function cn(e){return{resourceType:"derived","~compute":e,"~repr":void 0,get value(){let r=_chunkVRYGOFCWcjs.l.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return ce(r.unwrap(this))},with(r,n){return Wr(this,[[r,n]])},toString(){return"derived"}}}function Wr(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=_chunkVRYGOFCWcjs.l.call(void 0, );if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return ce(n.unwrap(this))},with(n,o){return Wr(e,[...t,[n,o]])},toString(){return`derived[${t.map(yn).join(", ")}]`}}}function Mr(e,t){return new je("private",e,t)}function Nr(e){return new je("workgroup",e)}var je=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n;_chunkVRYGOFCWcjs.c.call(void 0, this,"_label")}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)};`),r}get label(){return this._label}toString(){var t;return`var:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkVRYGOFCWcjs.m.call(void 0, ))throw new Error("Cannot access tgpu.var's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},G)}};var jr={bindGroupLayout:Oe,init:Gr,initFromDevice:Or,resolve:Ir,"~unstable":{fn:ar,fragmentFn:sr,vertexFn:ur,computeFn:or,vertexLayout:Lr,derived:$r,slot:Ne,accessor:kr,privateVar:Mr,workgroupVar:Nr,const:Xt,declare:Zt,sampler:xr,comparisonSampler:hr}},Xi= exports.default =jr;Object.assign(jr,{__assignAst:rr});exports.MissingBindGroupsError = _chunkVRYGOFCWcjs.i; exports.MissingLinksError = _chunkVRYGOFCWcjs.h; exports.MissingSlotValueError = _chunkVRYGOFCWcjs.f; exports.MissingVertexBuffersError = _chunkVRYGOFCWcjs.j; exports.NotUniformError = _chunkVRYGOFCWcjs.g; exports.RandomNameRegistry = q; exports.ResolutionError = _chunkVRYGOFCWcjs.e; exports.StrictNameRegistry = J; exports.default = Xi; exports.isBuffer = ie; exports.isComparisonSampler = dn; exports.isDerived = z; exports.isSampledTextureView = ft; exports.isSampler = ln; exports.isSlot = j; exports.isStorageTextureView = Tt; exports.isTexture = k; exports.isTgpuFn = rt; exports.isUsableAsRender = mn; exports.isUsableAsSampled = yt; exports.isUsableAsStorage = te; exports.isUsableAsUniform = xe; exports.isUsableAsVertex = an; exports.tgpu = jr; exports.unstable_asMutable = sn; exports.unstable_asReadonly = un; exports.unstable_asUniform = pn;
18
+ `)}${r}`}return this._getOrInstantiate(t)}return String(t)}resolveValue(t,r){if(te(t))return this.resolve(t);if(r&&_chunkY2M5GYROcjs.b.call(void 0, 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&&_chunkY2M5GYROcjs.c.call(void 0, 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 Te(e,t){var f;let r=new Et(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],s=new Set([...a.keys()].map(g=>g.index).filter(g=>g!==void 0)),u=Fr(s),p=r.fixedBindings.map((g,D)=>[String(D),g.layoutEntry]),l=()=>{let g=u.next().value,D=ze(Object.fromEntries(p));return o[g]=D,n=n.replaceAll(jr,String(g)),[g,new se(D,Object.fromEntries(r.fixedBindings.map((x,T)=>[String(T),x.resource])))]},m=p.length>0?l():null;for(let[g,D]of a.entries()){let x=(f=g.index)!=null?f:u.next().value;o[x]=g,n=n.replaceAll(D,String(x))}return{code:n,bindGroupLayouts:o,catchall:m}}function zr(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};re(o,t!=null?t:{});let s={"~resolve"(p){return ne(p,o,r!=null?r:"")},toString:()=>"<root>"},{code:u}=Te(s,{names:n==="strict"?new X:new Y,jitTranspiler:a});return u}var Ae=class{constructor(t){this._make=t;_chunkLF344PKGcjs.c.call(void 0, this,"_map",new WeakMap)}getOrMake(t,...r){if(this._map.has(t))return this._map.get(t);let n=this._make(t,...r);return this._map.set(t,n),n}};function Kr(e,t,r){return new Vt(new Gt(e,t,r),{})}function qr(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var Vt=class e{constructor(t,r){this._core=t;this._priors=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","compute-pipeline")}get label(){return this._core.label}get rawPipeline(){return this._core.unwrap().pipeline}with(t,r){var n;return new e(this._core,{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])})}dispatchWorkgroups(t,r,n){let a=this._core.unwrap(),{branch:o,label:s}=this._core,u=o.commandEncoder.beginComputePass({label:s!=null?s:"<unnamed>"});u.setPipeline(a.pipeline);let p=new Set(a.bindGroupLayouts);if(a.bindGroupLayouts.forEach((l,m)=>{var f;if(a.catchall&&m===a.catchall[0])u.setBindGroup(m,o.unwrap(a.catchall[1])),p.delete(l);else{let g=(f=this._priors.bindGroupLayoutMap)==null?void 0:f.get(l);g!==void 0&&(p.delete(l),u.setBindGroup(m,o.unwrap(g)))}}),p.size>0)throw new (0, _chunkLF344PKGcjs.i)(p);u.dispatchWorkgroups(t,r,n),u.end()}$name(t){return this._core.label=t,this}},Gt=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;_chunkLF344PKGcjs.c.call(void 0, this,"label");_chunkLF344PKGcjs.c.call(void 0, this,"_memo")}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let s=this.branch.device,{code:u,bindGroupLayouts:p,catchall:l}=Te({"~resolve":m=>(m.withSlots(this._slotBindings,()=>{m.resolve(this._entryFn)}),""),toString:()=>{var m;return`computePipeline:${(m=this.label)!=null?m:"<unnamed>"}`}},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});l!==null&&((r=p[l[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`)),this._memo={pipeline:s.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:s.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:p.map(m=>this.branch.unwrap(m))}),compute:{module:s.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:u})}}),bindGroupLayouts:p,catchall:l}}return this._memo}};function kt(e,t="vertex"){return new $t(e,t)}function He(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}var Ot=Symbol("defaultAttribEntry");function Je(e,t,r,n,a){if(_chunkY2M5GYROcjs.k.call(void 0, t)||_chunkY2M5GYROcjs.q.call(void 0, t)){let o=_chunkY2M5GYROcjs.r.call(void 0, t);return o!==void 0&&(n[a!=null?a:Ot]=o),Je(e,t.inner,_chunkY2M5GYROcjs.z.call(void 0, r,_chunkY2M5GYROcjs.qa.call(void 0, t)),n)}if(_chunkY2M5GYROcjs.c.call(void 0, t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([s,u])=>{o=_chunkY2M5GYROcjs.z.call(void 0, o,_chunkY2M5GYROcjs.pa.call(void 0, u));let p=[s,Je(e,u,o,n,s)];return o+=_chunkY2M5GYROcjs.sa.call(void 0, u),p}))}if(_chunkY2M5GYROcjs.p.call(void 0, t)){let o=r;return Object.fromEntries(Object.entries(t.propTypes).map(([s,u])=>{o=_chunkY2M5GYROcjs.z.call(void 0, o,_chunkY2M5GYROcjs.qa.call(void 0, u));let p=[s,Je(e,u,o,n,s)];return o+=_chunkY2M5GYROcjs.sa.call(void 0, u),p}))}if("type"in t&&typeof t.type=="string"){if(_chunkY2M5GYROcjs.l.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=_chunkY2M5GYROcjs.m[t.type];if(o)return{_layout:e,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var $t=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","vertex-layout");_chunkLF344PKGcjs.c.call(void 0, this,"stride");_chunkLF344PKGcjs.c.call(void 0, this,"attrib");_chunkLF344PKGcjs.c.call(void 0, this,"_customLocationMap",{});_chunkLF344PKGcjs.c.call(void 0, this,"_label");let n=t(0);this.stride=_chunkY2M5GYROcjs.z.call(void 0, _chunkY2M5GYROcjs.sa.call(void 0, n.elementType),_chunkY2M5GYROcjs.pa.call(void 0, n)),this.attrib=Je(this,n.elementType,0,this._customLocationMap)}get label(){return this._label}get vertexLayout(){if(this._customLocationMap[Ot]!==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[Ot]}]}}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 An(e){return typeof(e==null?void 0:e.loadOp)=="string"}function Jr(e,t){if(_chunkY2M5GYROcjs.s.call(void 0, e)){if(!An(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 Rn(e){return typeof(e==null?void 0:e.format)=="string"}function Hr(e,t){if(_chunkY2M5GYROcjs.s.call(void 0, e)){if(!Rn(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 Yr(e){return new Mt(new Wt(e),{})}var Mt=class e{constructor(t,r){this._core=t;this._priors=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","render-pipeline")}get label(){return this._core.label}$name(t){return this._core.label=t,this}with(t,r){var n,a;if(Ke(t))return new e(this._core,_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(He(t))return new e(this._core,_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._priors),{vertexLayoutMap:new Map([...(a=this._priors.vertexLayoutMap)!=null?a:[],[t,r]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(t){return new e(this._core,_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._priors),{colorAttachment:t}))}withDepthStencilAttachment(t){return new e(this._core,_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._priors),{depthStencilAttachment:t}))}draw(t,r,n,a){var x;let o=this._core.unwrap(),{branch:s,fragmentFn:u}=this._core.options,l={colorAttachments:Jr(u.shell.targets,(x=this._priors.colorAttachment)!=null?x:{}).map(T=>W(T.view)?_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},T),{view:s.unwrap(T.view).createView()}):T)};if(this._core.label!==void 0&&(l.label=this._core.label),this._priors.depthStencilAttachment!==void 0){let T=this._priors.depthStencilAttachment;W(T.view)?l.depthStencilAttachment=_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},T),{view:s.unwrap(T.view).createView()}):l.depthStencilAttachment=T}let m=s.commandEncoder.beginRenderPass(l);m.setPipeline(o.pipeline);let f=new Set(o.bindGroupLayouts);o.bindGroupLayouts.forEach((T,F)=>{var b;if(o.catchall&&F===o.catchall[0])m.setBindGroup(F,s.unwrap(o.catchall[1])),f.delete(T);else{let B=(b=this._priors.bindGroupLayoutMap)==null?void 0:b.get(T);B!==void 0&&(f.delete(T),m.setBindGroup(F,s.unwrap(B)))}});let g=new Set(this._core.usedVertexLayouts);if(this._core.usedVertexLayouts.forEach((T,F)=>{var B;let b=(B=this._priors.vertexLayoutMap)==null?void 0:B.get(T);b&&(g.delete(T),m.setVertexBuffer(F,s.unwrap(b)))}),f.size>0)throw new (0, _chunkLF344PKGcjs.i)(f);if(g.size>0)throw new (0, _chunkLF344PKGcjs.j)(g);m.draw(t,r,n,a),m.end()}},Wt=class{constructor(t){this.options=t;_chunkLF344PKGcjs.c.call(void 0, this,"label");_chunkLF344PKGcjs.c.call(void 0, this,"usedVertexLayouts");_chunkLF344PKGcjs.c.call(void 0, this,"_memo");_chunkLF344PKGcjs.c.call(void 0, this,"_vertexBufferLayouts");_chunkLF344PKGcjs.c.call(void 0, this,"_targets");let r=Dr(t.vertexFn.shell.attributes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Hr(t.fragmentFn.shell.targets,t.targets)}unwrap(){var t,r,n,a;if(this._memo===void 0){let{branch:o,vertexFn:s,fragmentFn:u,slotBindings:p,primitiveState:l,depthStencilState:m}=this.options,{code:f,bindGroupLayouts:g,catchall:D}=Te({"~resolve":b=>(b.withSlots(p,()=>{b.resolve(s),b.resolve(u)}),""),toString:()=>{var b;return`renderPipeline:${(b=this.label)!=null?b:"<unnamed>"}`}},{names:o.nameRegistry,jitTranspiler:o.jitTranspiler});D!==null&&((r=g[D[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let x=o.device,T=x.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:f}),F={layout:x.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:g.map(b=>o.unwrap(b))}),vertex:{module:T,buffers:this._vertexBufferLayouts},fragment:{module:T,targets:this._targets}};this.label!==void 0&&(F.label=this.label),l&&(F.primitive=l),m&&(F.depthStencil=m),this._memo={pipeline:x.createRenderPipeline(F),bindGroupLayouts:g,catchall:D}}return this._memo}};var Nt=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[ee(t)?t.slot:t,r]])}withCompute(t){return new jt(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new zt({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},jt=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Kr(this._root,this._slotBindings,this._entryFn)}},zt=class{constructor(t){this._options=t}withFragment(t,r,n){return _chunkLF344PKGcjs.d.call(void 0, typeof t!="string","Just type mismatch validation"),_chunkLF344PKGcjs.d.call(void 0, typeof r!="string","Just type mismatch validation"),new Kt(_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},Kt=class e{constructor(t){this._options=t}withPrimitive(t){return new e(_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._options),{primitiveState:t}))}withDepthStencil(t){return new e(_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._options),{depthStencilState:t}))}createPipeline(){return Yr(this._options)}},Ye=class extends Nt{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;_chunkLF344PKGcjs.c.call(void 0, this,"~unstable");_chunkLF344PKGcjs.c.call(void 0, this,"_disposables",[]);_chunkLF344PKGcjs.c.call(void 0, this,"_unwrappedBindGroupLayouts",new Ae(r=>r.unwrap(this)));_chunkLF344PKGcjs.c.call(void 0, this,"_unwrappedBindGroups",new Ae(r=>r.unwrap(this)));_chunkLF344PKGcjs.c.call(void 0, this,"_commandEncoder",null);this["~unstable"]={nameRegistry:this.nameRegistry,commandEncoder:this.commandEncoder,createUniform:this.createUniform.bind(this),createMutable:this.createMutable.bind(this),createReadonly:this.createReadonly.bind(this),createTexture:this.createTexture.bind(this),with:this.with.bind(this),withCompute:this.withCompute.bind(this),withVertex:this.withVertex.bind(this),flush:this.flush.bind(this)}}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=Cr(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 se(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=kr(r,this);return this._disposables.push(n),n}unwrap(r){if(qr(r))return r.rawPipeline;if(Ke(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(Nr(r))return this._unwrappedBindGroups.getOrMake(r);if(ge(r))return r.buffer;if(W(r)||At(r)||Rt(r))return r.unwrap();if(He(r))return r.vertexLayout;throw new Error(`Unknown resource type: ${r}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function Xr(e){let{adapter:t,device:r,unstable_names:n="random",unstable_jitTranspiler:a}=e!=null?e:{};if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let o=await navigator.gpu.requestAdapter(t);if(!o)throw new Error("Could not find a compatible GPU");return new Ye(await o.requestDevice(r),n==="random"?new Y:new X,a,!0)}function Qr(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new Ye(t,r==="random"?new Y:new X,n,!1)}function Xe(e){return new qt(e)}var qt=class{constructor(t=void 0){this.defaultValue=t;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","slot");_chunkLF344PKGcjs.c.call(void 0, this,"label");_chunkLF344PKGcjs.c.call(void 0, this,"~repr")}$name(t){return this.label=t,this}areEqual(t,r){return Object.is(t,r)}toString(){var t;return`slot:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){let t=_chunkLF344PKGcjs.l.call(void 0, );if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return Se(t.unwrap(this))}};function Zr(e,t){return new Jt(e,t)}var Jt=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;_chunkLF344PKGcjs.c.call(void 0, this,"resourceType","accessor");_chunkLF344PKGcjs.c.call(void 0, this,"~repr");_chunkLF344PKGcjs.c.call(void 0, this,"label");_chunkLF344PKGcjs.c.call(void 0, this,"slot");this.slot=Xe(r)}$name(t){return this.label=t,this.slot.$name(t),this}toString(){var t;return`accessor:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkLF344PKGcjs.l.call(void 0, ))throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return new Proxy({"~resolve":r=>r.resolve(this),toString:()=>{var r;return`.value:${(r=this.label)!=null?r:"<unnamed>"}`}},$)}"~resolve"(t){let r=t.unwrap(this.slot);return Pe(r)?t.resolve(r):lt(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function en(e){return Bn(e)}function In([e,t]){var r;return`${(r=e.label)!=null?r:"<unnamed>"}=${t}`}function Bn(e){return{resourceType:"derived","~compute":e,"~repr":void 0,get value(){let r=_chunkLF344PKGcjs.l.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Se(r.unwrap(this))},with(r,n){return tn(this,[[r,n]])},toString(){return"derived"}}}function tn(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=_chunkLF344PKGcjs.l.call(void 0, );if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return Se(n.unwrap(this))},with(n,a){return tn(e,[...t,[n,a]])},toString(){return`derived[${t.map(In).join(", ")}]`}}}function rn(e,t){return new Qe("private",e,t)}function nn(e){return new Qe("workgroup",e)}var Qe=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n;_chunkLF344PKGcjs.c.call(void 0, this,"_label")}$name(t){return this._label=t,this}"~resolve"(t){let r=t.names.makeUnique(this._label);return this._initialValue?t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)} = ${t.resolveValue(this._initialValue,this._dataType)};`):t.addDeclaration(`var<${this.scope}> ${r}: ${t.resolve(this._dataType)};`),r}get label(){return this._label}toString(){var t;return`var:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunkLF344PKGcjs.m.call(void 0, ))throw new Error("Cannot access tgpu.var's value directly in JS.");return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>{var t;return`.value:${(t=this.label)!=null?t:"<unnamed>"}`}},$)}};var an={bindGroupLayout:ze,vertexLayout:kt,init:Xr,initFromDevice:Qr,resolve:zr,"~unstable":{fn:xr,fragmentFn:hr,vertexFn:wr,computeFn:cr,vertexLayout:kt,derived:en,slot:Xe,accessor:Zr,privateVar:rn,workgroupVar:nn,const:lr,declare:mr,sampler:Er,comparisonSampler:Vr}},Ci= exports.default =an;Object.assign(an,{__assignAst:Tr});exports.MissingBindGroupsError = _chunkLF344PKGcjs.i; exports.MissingLinksError = _chunkLF344PKGcjs.h; exports.MissingSlotValueError = _chunkLF344PKGcjs.f; exports.MissingVertexBuffersError = _chunkLF344PKGcjs.j; exports.NotUniformError = _chunkLF344PKGcjs.g; exports.RandomNameRegistry = Y; exports.ResolutionError = _chunkLF344PKGcjs.e; exports.StrictNameRegistry = X; exports.default = Ci; exports.isBuffer = ge; exports.isComparisonSampler = Un; exports.isDerived = J; exports.isSampledTextureView = Rt; exports.isSampler = Fn; exports.isSlot = q; exports.isStorageTextureView = At; exports.isTexture = W; exports.isTgpuFn = lt; exports.isUsableAsRender = vn; exports.isUsableAsSampled = It; exports.isUsableAsStorage = oe; exports.isUsableAsUniform = Ve; exports.isUsableAsVertex = Dn; exports.tgpu = an; exports.unstable_asMutable = yt; exports.unstable_asReadonly = ct; exports.unstable_asUniform = xt;
15
19
  //# sourceMappingURL=index.cjs.map