typegpu 0.4.0 → 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,4 +1,4 @@
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 ur(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 pr(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 lr(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 dr(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 mr=new WeakMap;function gr(e){return mr.get(e)}function fr(e,t,r){return mr.set(e,{ast:t,externals:r}),e}function H(e,t){let r=[];return typeof t=="string"&&(lr(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=gr(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 Tr(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, Tr(e))}function me(e){return _chunkY2M5GYROcjs.y.call(void 0, Tr(e))}function yr(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 cr(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 xr(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 xr(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 xr(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 br(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 hr(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 wr(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}function De(e){return typeof(e==null?void 0:e.format)=="string"}function Sr(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)},
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
2
  `}function fn(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
4
  ${Object.entries(t.propTypes).map(n=>dt(e,n)).join("")}}
@@ -6,14 +6,14 @@ ${Object.entries(t.propTypes).map(n=>dt(e,n)).join("")}}
6
6
  struct ${r} {
7
7
  ${Object.entries(t.propTypes).map(n=>De(n[1])?dt(e,[n[0],_chunkY2M5GYROcjs.A[n[1].format]]):dt(e,n)).join("")}
8
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)}>`;wr(t,"resolveData")}function*Dr(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 Fr(e,t){return t?{value:"true",dataType:_chunkY2M5GYROcjs.t}:{value:"false",dataType:_chunkY2M5GYROcjs.t}}function Ur(e,t){return`${e.indent()}{
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
10
  ${t.b.map(r=>ft(e,r)).join(`
11
11
  `)}
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 Fr(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,Fr(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})
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
13
  ${s}
14
14
  ${e.pre}else
15
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?Ur(e,t):`${e.pre}${S(e,v(e,t))};`}function Tt(e,t){return Ur(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 vr=new WeakMap;function Ar(e){let t=vr.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),vr.set(e,n),n}function Rr(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=Ar(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 Pr={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=Pr[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=Pr[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>"}`}},$)}},Ir=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=Ir.get(e);return t||(t=new Fe("mutable",e),Ir.set(e,t)),t}var Br=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=Br.get(e);return t||(t=new Fe("readonly",e),Br.set(e,t)),t}var _r=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=_r.get(e);return t||(t=new Fe("uniform",e),_r.set(e,t)),t}var wt={uniform:xt,mutable:yt,readonly:ct};function Lr(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);ur(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=Rr(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 Cr(e){return new St(e)}function Er(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 Vr={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},Gr={f32:"float",u32:"uint",i32:"sint"},Or={float:_chunkY2M5GYROcjs.w,"unfilterable-float":_chunkY2M5GYROcjs.w,uint:_chunkY2M5GYROcjs.u,sint:_chunkY2M5GYROcjs.v,depth:_chunkY2M5GYROcjs.w};function $r(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 kr={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}, ${kr[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}, ${kr[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=Vr[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:Gr[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=Or[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 Wr(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)}},Mr=["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"?Mr: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:Mr,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 Nr="#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:Nr,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(`
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(`
17
17
 
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=Dr(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(Nr,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 jr(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 zr(e,t,r){return new Vt(new Gt(e,t,r),{})}function Kr(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 qr(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 kt(new Mt(e),{})}var kt=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()}},Mt=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=Sr(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 Wt=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 Nt(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new jt({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},Nt=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return zr(this._root,this._slotBindings,this._entryFn)}},jt=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 zt(_chunkLF344PKGcjs.b.call(void 0, _chunkLF344PKGcjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},zt=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 Wt{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=Lr(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=$r(r,this);return this._disposables.push(n),n}unwrap(r){if(Kr(r))return r.rawPipeline;if(Ke(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(Wr(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 Kt(e)}var Kt=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 qt(e,t)}var qt=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,init:Xr,initFromDevice:Qr,resolve:jr,"~unstable":{fn:cr,fragmentFn:br,vertexFn:hr,computeFn:yr,vertexLayout:qr,derived:en,slot:Xe,accessor:Zr,privateVar:rn,workgroupVar:nn,const:pr,declare:dr,sampler:Cr,comparisonSampler:Er}},Ci= exports.default =an;Object.assign(an,{__assignAst:fr});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;
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;
19
19
  //# sourceMappingURL=index.cjs.map