typegpu 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
package/index.cjs CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkOHFPIYFYcjs = require('./chunk-OHFPIYFY.cjs');var _chunk47YH5LQ7cjs = require('./chunk-47YH5LQ7.cjs');function Wt(e,t){return new Ne(e,t)}var Ne=class{constructor(t,r){this.dataType=t;this._value=r;_chunk47YH5LQ7cjs.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 _chunk47YH5LQ7cjs.l.call(void 0, )?this:this._value}};function Mt(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function Q(e){return(e==null?void 0:e.resourceType)==="slot"}function Z(e){return(e==null?void 0:e.resourceType)==="derived"}function de(e){return(e==null?void 0:e.resourceType)==="accessor"}var S=Symbol("Unknown data type");function je(e){return typeof(e==null?void 0:e["~resolve"])=="function"}function z(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||je(e)||_chunkOHFPIYFYcjs.a.call(void 0, e)||Q(e)||Z(e)}function Nt(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function K(e,t){for(let[r,n]of Object.entries(t))e[r]=n,Mt(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function jt(e,t,r){let n=[...e.matchAll(new RegExp(":\\s*(?<arg>.*?)\\s*[,)]","g"))].map(a=>{var o;return(o=a.groups)==null?void 0:o.arg});r(Object.fromEntries(t.flatMap((a,o)=>{let s=n?n[o]:void 0;return _chunkOHFPIYFYcjs.c.call(void 0, a)&&s!==void 0?[[s,a]]:[]})))}function ee(e,t,r){var a,o,s;let n=(s=(o=(a=e.match(new RegExp("->(?<output>.*?){","s")))==null?void 0:a.groups)==null?void 0:o.output)==null?void 0:s.trim();_chunkOHFPIYFYcjs.c.call(void 0, t)&&n&&!/\s/g.test(n)&&r({[n]:t})}function Gr(e){return new RegExp(`(?<![\\w_.])${e}(?![\\w_])`,"g")}function q(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{var s;return z(o)?n.replaceAll(Gr(a),e.resolve(o)):o!==null&&typeof o=="object"?((s=[...r.matchAll(new RegExp(`${a}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(d=>{var p;return(p=d==null?void 0:d.groups)==null?void 0:p.prop}))!=null?s:[]).reduce((d,p)=>p&&p in o?q(e,{[`${a}.${p}`]:o[p]},d):d,n):n},r)}function zt(e){return new ze(e)}var ze=class{constructor(t){this.declaration=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"externalsToApply",[])}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)K(r,a);let n=q(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var Kt=new WeakMap;function qt(e){return Kt.get(e)}function Jt(e,t,r){return Kt.set(e,{ast:t,externals:r}),e}function W(e,t){let r=[];return typeof t=="string"&&(jt(t,e.argTypes,n=>r.push(n)),ee(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){var u;let o={};for(let d of r)K(o,d);let s=n.names.makeUnique(this.label);if(typeof t=="string"){let d=q(n,o,t.trim());n.addDeclaration(`${a}fn ${s}${d}`)}else{let d=qt(t);if(d!=null&&d.externals){let f=Object.fromEntries(Object.entries(d.externals).filter(([h])=>!(h in o)));K(o,f)}let p=(u=d==null?void 0:d.ast)!=null?u:n.transpileFn(String(t)),T=p.externalNames.filter(f=>!(f in o));if(T.length>0)throw new (0, _chunk47YH5LQ7cjs.h)(this.label,T);let g=p.argNames.map((f,h)=>({value:f,dataType:e.argTypes[h]})),{head:m,body:c}=n.fnToWgsl({args:g,returnType:e.returnType,body:p.body,externalMap:o});n.addDeclaration(`${a}fn ${s}${n.resolve(m)}${n.resolve(c)}`)}return s}}}function Yt(e,t){var n,a,o;let{workgroupSize:r}=t;return{argTypes:[],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 Or(this,r,s)}}}function Or(e,t,r){let n=W(e,r);return{shell:e,get label(){return n.label},$uses(a){return n.applyExternals(a),this},$name(a){return n.label=a,this},"~resolve"(a){return n.resolve(a,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){var a;return`computeFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}function Ht(e,t){return{argTypes:e,returnType:t,does(r){return kr(this,r)}}}function Ke(e){return(e==null?void 0:e.resourceType)==="function"}function kr(e,t){let r=W(e,t),o=Object.assign((...s)=>{if(_chunk47YH5LQ7cjs.l.call(void 0, ))return new be(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 Xt(o,de(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 Xt(e,t,r){let n={resourceType:"function",shell:e.shell,$uses(s){return e.$uses(s),this},$name(s){return e.$name(s),this},with(s,u){return Xt(o,de(s)?s.slot:s,u)},"~resolve"(s){return s.withSlots([[t,r]],()=>s.resolve(e))}},o=Object.assign((...s)=>_chunk47YH5LQ7cjs.l.call(void 0, )?new be(o,s):e(...s),n);return Object.defineProperty(o,"label",{get:()=>e.label}),Object.defineProperty(o,"toString",{value(){var s,u;return`fn:${(s=e.label)!=null?s:"<unnamed>"}[${(u=t.label)!=null?u:"<unnamed>"}=${r}]`}}),o}var be=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 $r(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(_chunkOHFPIYFYcjs.Fa.call(void 0, n))return[r,n];let a=_chunkOHFPIYFYcjs.x.call(void 0, n);return a!==void 0?(t=a+1,[r,n]):[r,_chunkOHFPIYFYcjs.Aa.call(void 0, n,{type:"@location",value:t++})]}))}function he(e){return _chunkOHFPIYFYcjs.y.call(void 0, e)?_chunkOHFPIYFYcjs.Da.call(void 0, 0,e):_chunkOHFPIYFYcjs.p.call(void 0, $r(e))}function Qt(e,t){return{argTypes:[e],returnType:t,does(r){return Wr(this,r)}}}function Wr(e,t){let r=W(e,t),n=he(e.returnType);return typeof t=="string"&&ee(t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,get label(){return r.label},$uses(o){return r.applyExternals(o),this},$name(o){return r.label=o,_chunkOHFPIYFYcjs.c.call(void 0, n)&&n.$name(`${o}_Output`),this},"~resolve"(o){return r.resolve(o,"@fragment ")},toString(){var o;return`fragmentFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}function Zt(e,t){return{argTypes:[e],returnType:t,does(r){return Mr(this,r)}}}function Mr(e,t){let r=W(e,t),n=he(e.returnType);return typeof t=="string"&&ee(t,n,a=>r.applyExternals(a)),{shell:e,outputType:n,get label(){return r.label},$uses(a){return r.applyExternals(a),this},$name(a){return r.label=a,_chunkOHFPIYFYcjs.c.call(void 0, n)&&n.$name(`${a}_Output`),this},"~resolve"(a){return r.resolve(a,"@vertex ")},toString(){var a;return`vertexFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}var M=class{constructor(){_chunk47YH5LQ7cjs.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++}`}},N= exports.StrictNameRegistry =class{constructor(){_chunk47YH5LQ7cjs.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 er(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var Nr=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function jr(e){return Nr.includes(e.type)}function zr(e,[t,r]){return` ${_chunkOHFPIYFYcjs.Ga.call(void 0, r)}${t}: ${e.resolve(r)},
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkOHFPIYFYcjs = require('./chunk-OHFPIYFY.cjs');var _chunk47YH5LQ7cjs = require('./chunk-47YH5LQ7.cjs');function Wt(e,t){return new Ne(e,t)}var Ne=class{constructor(t,r){this.dataType=t;this._value=r;_chunk47YH5LQ7cjs.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 _chunk47YH5LQ7cjs.l.call(void 0, )?this:this._value}};function Mt(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function Q(e){return(e==null?void 0:e.resourceType)==="slot"}function Z(e){return(e==null?void 0:e.resourceType)==="derived"}function de(e){return(e==null?void 0:e.resourceType)==="accessor"}var S=Symbol("Unknown data type");function je(e){return typeof(e==null?void 0:e["~resolve"])=="function"}function z(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||je(e)||_chunkOHFPIYFYcjs.a.call(void 0, e)||Q(e)||Z(e)}function Nt(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function K(e,t){for(let[r,n]of Object.entries(t))e[r]=n,Mt(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function jt(e,t,r){let n=[...e.matchAll(new RegExp(":\\s*(?<arg>.*?)\\s*[,)]","g"))].map(a=>{var o;return(o=a.groups)==null?void 0:o.arg});r(Object.fromEntries(t.flatMap((a,o)=>{let s=n?n[o]:void 0;return _chunkOHFPIYFYcjs.c.call(void 0, a)&&s!==void 0?[[s,a]]:[]})))}function ee(e,t,r){var a,o,s;let n=(s=(o=(a=e.match(new RegExp("->(?<output>.*?){","s")))==null?void 0:a.groups)==null?void 0:o.output)==null?void 0:s.trim();_chunkOHFPIYFYcjs.c.call(void 0, t)&&n&&!/\s/g.test(n)&&r({[n]:t})}function Gr(e){return new RegExp(`(?<![\\w_.])${e}(?![\\w_])`,"g")}function q(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{var s;return z(o)?n.replaceAll(Gr(a),e.resolve(o)):o!==null&&typeof o=="object"?((s=[...r.matchAll(new RegExp(`${a}\\.(?<prop>.*?)(?![\\w_])`,"g"))].map(d=>d[1]))!=null?s:[]).reduce((d,l)=>l&&l in o?q(e,{[`${a}.${l}`]:o[l]},d):d,n):n},r)}function zt(e){return new ze(e)}var ze=class{constructor(t){this.declaration=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"externalsToApply",[])}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)K(r,a);let n=q(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}};var Kt=new WeakMap;function qt(e){return Kt.get(e)}function Jt(e,t,r){return Kt.set(e,{ast:t,externals:r}),e}function W(e,t){let r=[];return typeof t=="string"&&(jt(t,e.argTypes,n=>r.push(n)),ee(t,e.returnType,n=>r.push(n))),{label:void 0,applyExternals(n){r.push(n)},resolve(n,a=""){var u;let o={};for(let d of r)K(o,d);let s=n.names.makeUnique(this.label);if(typeof t=="string"){let d=q(n,o,t.trim());n.addDeclaration(`${a}fn ${s}${d}`)}else{let d=qt(t);if(d!=null&&d.externals){let f=Object.fromEntries(Object.entries(d.externals).filter(([h])=>!(h in o)));K(o,f)}let l=(u=d==null?void 0:d.ast)!=null?u:n.transpileFn(String(t)),T=l.externalNames.filter(f=>!(f in o));if(T.length>0)throw new (0, _chunk47YH5LQ7cjs.h)(this.label,T);let g=l.argNames.map((f,h)=>({value:f,dataType:e.argTypes[h]})),{head:m,body:c}=n.fnToWgsl({args:g,returnType:e.returnType,body:l.body,externalMap:o});n.addDeclaration(`${a}fn ${s}${n.resolve(m)}${n.resolve(c)}`)}return s}}}function Yt(e,t){var n,a,o;let{workgroupSize:r}=t;return{argTypes:[],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 Or(this,r,s)}}}function Or(e,t,r){let n=W(e,r);return{shell:e,get label(){return n.label},$uses(a){return n.applyExternals(a),this},$name(a){return n.label=a,this},"~resolve"(a){return n.resolve(a,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){var a;return`computeFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}function Ht(e,t){return{argTypes:e,returnType:t,does(r){return kr(this,r)}}}function Ke(e){return(e==null?void 0:e.resourceType)==="function"}function kr(e,t){let r=W(e,t),o=Object.assign((...s)=>{if(_chunk47YH5LQ7cjs.l.call(void 0, ))return new be(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 Xt(o,de(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 Xt(e,t,r){let n={resourceType:"function",shell:e.shell,$uses(s){return e.$uses(s),this},$name(s){return e.$name(s),this},with(s,u){return Xt(o,de(s)?s.slot:s,u)},"~resolve"(s){return s.withSlots([[t,r]],()=>s.resolve(e))}},o=Object.assign((...s)=>_chunk47YH5LQ7cjs.l.call(void 0, )?new be(o,s):e(...s),n);return Object.defineProperty(o,"label",{get:()=>e.label}),Object.defineProperty(o,"toString",{value(){var s,u;return`fn:${(s=e.label)!=null?s:"<unnamed>"}[${(u=t.label)!=null?u:"<unnamed>"}=${r}]`}}),o}var be=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 $r(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(_chunkOHFPIYFYcjs.Fa.call(void 0, n))return[r,n];let a=_chunkOHFPIYFYcjs.x.call(void 0, n);return a!==void 0?(t=a+1,[r,n]):[r,_chunkOHFPIYFYcjs.Aa.call(void 0, n,{type:"@location",value:t++})]}))}function he(e){return _chunkOHFPIYFYcjs.y.call(void 0, e)?_chunkOHFPIYFYcjs.Da.call(void 0, 0,e):_chunkOHFPIYFYcjs.p.call(void 0, $r(e))}function Qt(e,t){return{argTypes:[e],returnType:t,does(r){return Wr(this,r)}}}function Wr(e,t){let r=W(e,t),n=he(e.returnType);return typeof t=="string"&&ee(t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,get label(){return r.label},$uses(o){return r.applyExternals(o),this},$name(o){return r.label=o,_chunkOHFPIYFYcjs.c.call(void 0, n)&&n.$name(`${o}_Output`),this},"~resolve"(o){return r.resolve(o,"@fragment ")},toString(){var o;return`fragmentFn:${(o=this.label)!=null?o:"<unnamed>"}`}}}function Zt(e,t){return{argTypes:[e],returnType:t,does(r){return Mr(this,r)}}}function Mr(e,t){let r=W(e,t),n=he(e.returnType);return typeof t=="string"&&ee(t,n,a=>r.applyExternals(a)),{shell:e,outputType:n,get label(){return r.label},$uses(a){return r.applyExternals(a),this},$name(a){return r.label=a,_chunkOHFPIYFYcjs.c.call(void 0, n)&&n.$name(`${a}_Output`),this},"~resolve"(a){return r.resolve(a,"@vertex ")},toString(){var a;return`vertexFn:${(a=this.label)!=null?a:"<unnamed>"}`}}}var M=class{constructor(){_chunk47YH5LQ7cjs.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++}`}},N= exports.StrictNameRegistry =class{constructor(){_chunk47YH5LQ7cjs.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 er(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var Nr=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function jr(e){return Nr.includes(e.type)}function zr(e,[t,r]){return` ${_chunkOHFPIYFYcjs.Ga.call(void 0, r)}${t}: ${e.resolve(r)},
2
2
  `}function Kr(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
4
  ${Object.entries(t.propTypes).map(n=>zr(e,n)).join("")}}
5
5
  `),r}function qr(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function qe(e,t){if(jr(t))return t.type;if(t.type==="struct")return Kr(e,t);if(t.type==="array")return qr(e,t);if(t.type==="atomic")return`atomic<${qe(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);er(t,"resolveData")}function*tr(e){let t=0;for(;;)e.has(t)||(yield t),t++}var Jr=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function w(e,t){return z(t.value)||_chunkOHFPIYFYcjs.a.call(void 0, t.value)?e.resolve(t.value):String(t.value)}function Yr(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function rr(e,t){return t?{value:"true",dataType:_chunkOHFPIYFYcjs.k}:{value:"false",dataType:_chunkOHFPIYFYcjs.k}}function nr(e,t){return`${e.indent()}{
6
6
  ${t.b.map(r=>Ye(e,r)).join(`
7
7
  `)}
8
- ${e.dedent()}}`}function Je(e,t){return e.getById(t)}function F(e,t){if(typeof t=="string")return Je(e,t);if(typeof t=="boolean")return rr(e,t);if("x"in t){let[r,n,a]=t.x,o=w(e,F(e,r)),s=w(e,F(e,a));return{value:Jr.includes(n)?`(${o} ${n} ${s})`:`${o} ${n} ${s}`,dataType:S}}if("u"in t){let[r,n]=t.u,a=w(e,F(e,n));return{value:`${r}${a}`,dataType:S}}if("a"in t){let[r,n]=t.a,a=F(e,r),o=w(e,F(e,n));if(typeof a.value=="string")return{value:`${a.value}.${o}`,dataType:S};if(z(a.value))return o==="value"?{value:w(e,a),dataType:S}:{value:a.value[o],dataType:S};if(typeof a.value=="object")return{value:a.value[o],dataType:S};throw new Error(`Cannot access member ${o} of ${a.value}`)}if("i"in t){let[r,n]=t.i,a=w(e,F(e,r)),o=w(e,F(e,n));return{value:`${a}[${o}]`,dataType:S}}if("n"in t)return{value:t.n,dataType:S};if("f"in t){let[r,n]=t.f,o=F(e,r).value,u=n.map(p=>F(e,p)).map(p=>w(e,p));return typeof o=="string"?{value:`${o}(${u.join(", ")})`,dataType:S}:{value:o(...u),dataType:S}}Yr(t)}function Ye(e,t){if(typeof t=="string")return`${e.pre}${w(e,Je(e,t))};`;if(typeof t=="boolean")return`${e.pre}${w(e,rr(e,t))};`;if("r"in t)return t.r===null?`${e.pre}return;`:`${e.pre}return ${w(e,F(e,t.r))};`;if("q"in t){let[r,n,a]=t.q,o=w(e,F(e,r));e.indent();let s=Ye(e,n);e.dedent(),e.indent();let u=a?Ye(e,a):void 0;return e.dedent(),u?`${e.pre}if (${o})
8
+ ${e.dedent()}}`}function Je(e,t){return e.getById(t)}function F(e,t){if(typeof t=="string")return Je(e,t);if(typeof t=="boolean")return rr(e,t);if("x"in t){let[r,n,a]=t.x,o=w(e,F(e,r)),s=w(e,F(e,a));return{value:Jr.includes(n)?`(${o} ${n} ${s})`:`${o} ${n} ${s}`,dataType:S}}if("u"in t){let[r,n]=t.u,a=w(e,F(e,n));return{value:`${r}${a}`,dataType:S}}if("a"in t){let[r,n]=t.a,a=F(e,r),o=w(e,F(e,n));if(typeof a.value=="string")return{value:`${a.value}.${o}`,dataType:S};if(z(a.value))return o==="value"?{value:w(e,a),dataType:S}:{value:a.value[o],dataType:S};if(typeof a.value=="object")return{value:a.value[o],dataType:S};throw new Error(`Cannot access member ${o} of ${a.value}`)}if("i"in t){let[r,n]=t.i,a=w(e,F(e,r)),o=w(e,F(e,n));return{value:`${a}[${o}]`,dataType:S}}if("n"in t)return{value:t.n,dataType:S};if("f"in t){let[r,n]=t.f,o=F(e,r).value,u=n.map(l=>F(e,l)).map(l=>w(e,l));return typeof o=="string"?{value:`${o}(${u.join(", ")})`,dataType:S}:{value:o(...u),dataType:S}}Yr(t)}function Ye(e,t){if(typeof t=="string")return`${e.pre}${w(e,Je(e,t))};`;if(typeof t=="boolean")return`${e.pre}${w(e,rr(e,t))};`;if("r"in t)return t.r===null?`${e.pre}return;`:`${e.pre}return ${w(e,F(e,t.r))};`;if("q"in t){let[r,n,a]=t.q,o=w(e,F(e,r));e.indent();let s=Ye(e,n);e.dedent(),e.indent();let u=a?Ye(e,a):void 0;return e.dedent(),u?`${e.pre}if (${o})
9
9
  ${s}
10
10
  ${e.pre}else
11
11
  ${u}`:`${e.pre}if (${o})
12
- ${s}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=w(e,Je(e,r)),o=n?F(e,n):void 0;if(!o)throw new Error("Cannot create variable without an initial value.");return`${e.pre}var ${a} = ${w(e,o)};`}return"b"in t?nr(e,t):`${e.pre}${w(e,F(e,t))};`}function He(e,t){return nr(e,t)}var _typedbinary = require('typed-binary');function Hr(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 y=Hr;var D={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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);for(let[a,o]of Object.entries(t.propTypes))y(e,_chunkOHFPIYFYcjs.na.call(void 0, o)),te(e,o,r[a]);y(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)y(e,n),te(e,t.elementType,r[o]);e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t))},atomic(e,t,r){var n;(n=D[t.inner.type])==null||n.call(D,e,t,r)},decorated(e,t,r){var o,s;let n=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,n);let a=e.currentByteOffset;(s=D[(o=t.inner)==null?void 0:o.type])==null||s.call(D,e,t.inner,r),e.seekTo(a+_chunkOHFPIYFYcjs.qa.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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);let a=e.currentByteOffset;for(let u=0;u<Math.min(t.elementCount,r.length);u++)y(e,n),(s=D[(o=t.elementType)==null?void 0:o.type])==null||s.call(D,e,t.elementType,r[u]);e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t))},unstruct(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=D[o.type])==null||n.call(D,e,o,r[a])},"loose-decorated"(e,t,r){var s;let n=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,n);let a=e.currentByteOffset,o=D[(s=t.inner)==null?void 0:s.type];return o==null||o(e,t.inner,r),e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t)),r}};function te(e,t,r){let n=D[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var J={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 _chunk47YH5LQ7cjs.m.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunk47YH5LQ7cjs.q.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunk47YH5LQ7cjs.u.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunk47YH5LQ7cjs.n.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunk47YH5LQ7cjs.r.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunk47YH5LQ7cjs.v.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunk47YH5LQ7cjs.o.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunk47YH5LQ7cjs.s.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunk47YH5LQ7cjs.w.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunk47YH5LQ7cjs.p.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunk47YH5LQ7cjs.t.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunk47YH5LQ7cjs.x.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return _chunkOHFPIYFYcjs.va.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkOHFPIYFYcjs.wa.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkOHFPIYFYcjs.xa.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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))y(e,_chunkOHFPIYFYcjs.na.call(void 0, o)),n[a]=L(e,o);return y(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkOHFPIYFYcjs.na.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++){y(e,r);let o=t.elementType,s=L(e,o);n.push(s)}return y(e,r),n},atomic(e,t){return L(e,t.inner)},decorated(e,t){let r=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,r);let n=e.currentByteOffset,a=L(e,t.inner);return e.seekTo(n+_chunkOHFPIYFYcjs.qa.call(void 0, t)),a},uint8:e=>e.readUint8(),uint8x2:e=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunk47YH5LQ7cjs.w.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>_chunk47YH5LQ7cjs.u.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=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunk47YH5LQ7cjs.w.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, J.snorm16(e),J.snorm16(e)),snorm16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, J.snorm16(e),J.snorm16(e),J.snorm16(e),J.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunk47YH5LQ7cjs.q.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunk47YH5LQ7cjs.t.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunk47YH5LQ7cjs.s.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunk47YH5LQ7cjs.w.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 _chunk47YH5LQ7cjs.u.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 _chunk47YH5LQ7cjs.u.call(void 0, n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=L(e,a);return r},disarray(e,t){let r=_chunkOHFPIYFYcjs.na.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++)y(e,r),n.push(L(e,t.elementType));return y(e,r),n},"loose-decorated"(e,t){y(e,_chunkOHFPIYFYcjs.oa.call(void 0, t));let r=e.currentByteOffset,n=L(e,t.inner);return e.seekTo(r+_chunkOHFPIYFYcjs.qa.call(void 0, t)),n}};function L(e,t){let r=J[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function ar(e,t,r){return _chunkOHFPIYFYcjs.a.call(void 0, t)?new we(e,t,r):new we(e,t,r,["storage","uniform"])}function re(e){return e.resourceType==="buffer"}function me(e){return!!e.usableAsUniform}function Xr(e){return!!e.usableAsVertex}var we=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","buffer");_chunk47YH5LQ7cjs.c.call(void 0, this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);_chunk47YH5LQ7cjs.c.call(void 0, this,"_buffer",null);_chunk47YH5LQ7cjs.c.call(void 0, this,"_ownBuffer");_chunk47YH5LQ7cjs.c.call(void 0, this,"_destroyed",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"initial");_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsUniform",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsStorage",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsVertex",!1);Nt(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:_chunkOHFPIYFYcjs.qa.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());te(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let s=r.getMappedRange();te(new (0, _typedbinary.BufferWriter)(s),this.dataType,t);return}let a=_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType);this._group.flush();let o=new ArrayBuffer(a);te(new (0, _typedbinary.BufferWriter)(o),this.dataType,t),n.queue.writeBuffer(r,0,o,0,a)}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunkOHFPIYFYcjs.qa.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 L(new (0, _typedbinary.BufferReader)(s),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let s=t.getMappedRange(),u=L(new (0, _typedbinary.BufferReader)(s),this.dataType);return t.unmap(),u}let n=r.createBuffer({size:_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType));let o=L(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}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 Y(e){return!!(e!=null&&e.usableAsStorage)}var Se=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 ur(e){return(e==null?void 0:e.resourceType)==="buffer-usage"}var pr={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Te=class{constructor(t,r){this.usage=t;this.buffer=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"~repr");_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","buffer-usage")}get label(){return this.buffer.label}$name(t){this.buffer.$name(t)}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding: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}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this}},ge=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"~repr");_chunk47YH5LQ7cjs.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(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this}},or=new WeakMap;function Qr(e){if(!Y(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=or.get(e);return t||(t=new Te("mutable",e),or.set(e,t)),t}var sr=new WeakMap;function Zr(e){if(!Y(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=sr.get(e);return t||(t=new Te("readonly",e),sr.set(e,t)),t}var ir=new WeakMap;function en(e){if(!me(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=ir.get(e);return t||(t=new Te("uniform",e),ir.set(e,t)),t}function lr(e){return new Ze(e)}function dr(e){return new et(e)}function tn(e){return(e==null?void 0:e.resourceType)==="sampler"}function rn(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var De=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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>"}`}},Fe=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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>"}`}},Ze=class{constructor(t){this._props=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","sampler");_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.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>"}`}},et=class{constructor(t){this._props=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","sampler-comparison");_chunk47YH5LQ7cjs.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 Ue=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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 mr={r8unorm:_chunkOHFPIYFYcjs.n,r8snorm:_chunkOHFPIYFYcjs.n,r8uint:_chunkOHFPIYFYcjs.l,r8sint:_chunkOHFPIYFYcjs.m,r16uint:_chunkOHFPIYFYcjs.l,r16sint:_chunkOHFPIYFYcjs.m,r16float:_chunkOHFPIYFYcjs.n,rg8unorm:_chunkOHFPIYFYcjs.n,rg8snorm:_chunkOHFPIYFYcjs.n,rg8uint:_chunkOHFPIYFYcjs.l,rg8sint:_chunkOHFPIYFYcjs.m,r32uint:_chunkOHFPIYFYcjs.l,r32sint:_chunkOHFPIYFYcjs.m,r32float:_chunkOHFPIYFYcjs.n,rg16uint:_chunkOHFPIYFYcjs.l,rg16sint:_chunkOHFPIYFYcjs.m,rg16float:_chunkOHFPIYFYcjs.n,rgba8unorm:_chunkOHFPIYFYcjs.n,"rgba8unorm-srgb":_chunkOHFPIYFYcjs.n,rgba8snorm:_chunkOHFPIYFYcjs.n,rgba8uint:_chunkOHFPIYFYcjs.l,rgba8sint:_chunkOHFPIYFYcjs.m,bgra8unorm:_chunkOHFPIYFYcjs.n,"bgra8unorm-srgb":_chunkOHFPIYFYcjs.n,rgb9e5ufloat:_chunkOHFPIYFYcjs.n,rgb10a2uint:_chunkOHFPIYFYcjs.l,rgb10a2unorm:_chunkOHFPIYFYcjs.n,rg11b10ufloat:_chunkOHFPIYFYcjs.n,rg32uint:_chunkOHFPIYFYcjs.l,rg32sint:_chunkOHFPIYFYcjs.m,rg32float:_chunkOHFPIYFYcjs.n,rgba16uint:_chunkOHFPIYFYcjs.l,rgba16sint:_chunkOHFPIYFYcjs.m,rgba16float:_chunkOHFPIYFYcjs.n,rgba32uint:_chunkOHFPIYFYcjs.l,rgba32sint:_chunkOHFPIYFYcjs.m,rgba32float:_chunkOHFPIYFYcjs.n,stencil8:_chunkOHFPIYFYcjs.n,depth16unorm:_chunkOHFPIYFYcjs.n,depth24plus:_chunkOHFPIYFYcjs.n,"depth24plus-stencil8":_chunkOHFPIYFYcjs.n,depth32float:_chunkOHFPIYFYcjs.n,"depth32float-stencil8":_chunkOHFPIYFYcjs.n,"bc1-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc1-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc2-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc2-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc3-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc3-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc4-r-unorm":_chunkOHFPIYFYcjs.n,"bc4-r-snorm":_chunkOHFPIYFYcjs.n,"bc5-rg-unorm":_chunkOHFPIYFYcjs.n,"bc5-rg-snorm":_chunkOHFPIYFYcjs.n,"bc6h-rgb-ufloat":_chunkOHFPIYFYcjs.n,"bc6h-rgb-float":_chunkOHFPIYFYcjs.n,"bc7-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc7-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgb8unorm":_chunkOHFPIYFYcjs.n,"etc2-rgb8unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgb8a1unorm":_chunkOHFPIYFYcjs.n,"etc2-rgb8a1unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgba8unorm":_chunkOHFPIYFYcjs.n,"etc2-rgba8unorm-srgb":_chunkOHFPIYFYcjs.n,"eac-r11unorm":_chunkOHFPIYFYcjs.n,"eac-r11snorm":_chunkOHFPIYFYcjs.n,"eac-rg11unorm":_chunkOHFPIYFYcjs.n,"eac-rg11snorm":_chunkOHFPIYFYcjs.n,"astc-4x4-unorm":_chunkOHFPIYFYcjs.n,"astc-4x4-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-5x4-unorm":_chunkOHFPIYFYcjs.n,"astc-5x4-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-5x5-unorm":_chunkOHFPIYFYcjs.n,"astc-5x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-6x5-unorm":_chunkOHFPIYFYcjs.n,"astc-6x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-6x6-unorm":_chunkOHFPIYFYcjs.n,"astc-6x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x5-unorm":_chunkOHFPIYFYcjs.n,"astc-8x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x6-unorm":_chunkOHFPIYFYcjs.n,"astc-8x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x8-unorm":_chunkOHFPIYFYcjs.n,"astc-8x8-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x5-unorm":_chunkOHFPIYFYcjs.n,"astc-10x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x6-unorm":_chunkOHFPIYFYcjs.n,"astc-10x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x8-unorm":_chunkOHFPIYFYcjs.n,"astc-10x8-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x10-unorm":_chunkOHFPIYFYcjs.n,"astc-10x10-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-12x10-unorm":_chunkOHFPIYFYcjs.n,"astc-12x10-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-12x12-unorm":_chunkOHFPIYFYcjs.n,"astc-12x12-unorm-srgb":_chunkOHFPIYFYcjs.n},fe={rgba8unorm:_chunk47YH5LQ7cjs.u,rgba8snorm:_chunk47YH5LQ7cjs.u,rgba8uint:_chunk47YH5LQ7cjs.x,rgba8sint:_chunk47YH5LQ7cjs.w,rgba16uint:_chunk47YH5LQ7cjs.x,rgba16sint:_chunk47YH5LQ7cjs.w,rgba16float:_chunk47YH5LQ7cjs.u,r32uint:_chunk47YH5LQ7cjs.x,r32sint:_chunk47YH5LQ7cjs.w,r32float:_chunk47YH5LQ7cjs.u,rg32uint:_chunk47YH5LQ7cjs.x,rg32sint:_chunk47YH5LQ7cjs.w,rg32float:_chunk47YH5LQ7cjs.u,rgba32uint:_chunk47YH5LQ7cjs.x,rgba32sint:_chunk47YH5LQ7cjs.w,rgba32float:_chunk47YH5LQ7cjs.u,bgra8unorm:_chunk47YH5LQ7cjs.u},Tr={f32:"float",u32:"uint",i32:"sint"},gr={float:_chunkOHFPIYFYcjs.n,"unfilterable-float":_chunkOHFPIYFYcjs.n,uint:_chunkOHFPIYFYcjs.l,sint:_chunkOHFPIYFYcjs.m,depth:_chunkOHFPIYFYcjs.n};function fr(e,t){return new tt(e,t)}function j(e){return(e==null?void 0:e.resourceType)==="texture"}function at(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function ot(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var yr={mutable:"read_write",readonly:"read",writeonly:"write"},tt=class{constructor(t,r){this.props=t;this._branch=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture");_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsSampled",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsStorage",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsRender",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_destroyed",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);_chunk47YH5LQ7cjs.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=fe[n];return _chunk47YH5LQ7cjs.d.call(void 0, !!a,`Unsupported storage texture format: ${n}`),new rt(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(!fe[r])throw new Error(`Unsupported storage texture format: ${r}`);return new nt(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Re={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},rt=class{constructor(t,r,n){this.access=r;this._texture=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"texelDataType");_chunk47YH5LQ7cjs.c.call(void 0, this,"dimension");_chunk47YH5LQ7cjs.c.call(void 0, this,"_view");_chunk47YH5LQ7cjs.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=fe[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_${Re[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${yr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},ve=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"texelDataType");this.texelDataType=fe[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_${Re[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${yr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},nt=class{constructor(t,r){this._props=t;this._texture=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"channelDataType");_chunk47YH5LQ7cjs.c.call(void 0, this,"dimension");_chunk47YH5LQ7cjs.c.call(void 0, this,"_format");_chunk47YH5LQ7cjs.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=mr[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(_chunk47YH5LQ7cjs.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:Tr[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${Re[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>"}`}},Ae=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"channelDataType");this.channelDataType=gr[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_${Re[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 st(e){return!!(e!=null&&e.usableAsSampled)}function nn(e){return!!(e!=null&&e.usableAsRender)}var _e=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 Ie(e){return new ut(e)}function Ee(e){return!!e&&e.resourceType==="bind-group-layout"}function xr(e){return!!e&&e.resourceType==="bind-group"}var it=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)}},cr=["compute"],ne=["compute","vertex","fragment"],ut=class{constructor(t){this.entries=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"_index");_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","bind-group-layout");_chunk47YH5LQ7cjs.c.call(void 0, this,"bound",{});var n,a,o,s,u;let r=0;for(let[d,p]of Object.entries(t)){if(p===null){r++;continue}let T={idx:r,key:d,layout:this};if("uniform"in p&&(this.bound[d]=new ge("uniform",p.uniform,T)),"storage"in p){let g="type"in p.storage?p.storage:p.storage(0);this.bound[d]=new ge((n=p.access)!=null?n:"readonly",g,T)}"texture"in p&&(this.bound[d]=new Ae(p.texture,(a=p.viewDimension)!=null?a:"2d",(o=p.multisampled)!=null?o:!1,T)),"storageTexture"in p&&(this.bound[d]=new ve(p.storageTexture,(s=p.viewDimension)!=null?s:"2d",(u=p.access)!=null?u:"writeonly",T)),"externalTexture"in p&&(this.bound[d]=new Ue(T)),"sampler"in p&&(p.sampler==="comparison"?this.bound[d]=new Fe(T):this.bound[d]=new De(T)),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 d,p,T,g;if(a===null)return null;let s=a.visibility,u={binding:o,visibility:0};if("uniform"in a)s=s!=null?s:ne,u.buffer={type:"uniform"};else if("storage"in a)s=s!=null?s:a.access==="mutable"?cr:ne,u.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)s=s!=null?s:ne,u.sampler={type:a.sampler};else if("texture"in a)s=s!=null?s:ne,u.texture={sampleType:a.texture,viewDimension:(d=a.viewDimension)!=null?d:"2d",multisampled:(p=a.multisampled)!=null?p:!1};else if("storageTexture"in a){let m=(T=a.access)!=null?T:"writeonly";s=s!=null?s:m==="readonly"?ne:cr,u.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[m],viewDimension:(g=a.viewDimension)!=null?g:"2d"}}else"externalTexture"in a&&(s=s!=null?s:ne,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 H(this,t)}},H=class{constructor(t,r){this.layout=t;this.entries=r;_chunk47YH5LQ7cjs.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 it(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 d;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 '${(d=this.layout.label)!=null?d:"<unnamed>"}'.`);if("uniform"in o){let p;if(re(u)){if(!me(u))throw new (0, _chunk47YH5LQ7cjs.g)(u);p={buffer:t.unwrap(u)}}else p={buffer:u};return{binding:s,resource:p}}if("storage"in o){let p;if(re(u)){if(!Y(u))throw new (0, _chunk47YH5LQ7cjs.g)(u);p={buffer:t.unwrap(u)}}else p={buffer:u};return{binding:s,resource:p}}if("texture"in o){let p;if(j(u)){if(!st(u))throw new _e(u);p=t.unwrap(u.createView("sampled"))}else p=u;return{binding:s,resource:p}}if("storageTexture"in o){let p;if(j(u)){if(!Y(u))throw new Se(u);o.access==="readonly"?p=t.unwrap(u.createView("readonly")):o.access==="mutable"?p=t.unwrap(u.createView("mutable")):p=t.unwrap(u.createView("writeonly"))}else p=u;return{binding:s,resource:p}}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 br="#CATCHALL#",lt=class{constructor(){_chunk47YH5LQ7cjs.c.call(void 0, this,"_stack",[]);_chunk47YH5LQ7cjs.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:S}: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}}}}},Le=[""," "," "," "," "," "," "," "," "],pt=Le.length-1,dt=class{constructor(){_chunk47YH5LQ7cjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=Le[this.identLevel])!=null?t:Le[pt].repeat(this.identLevel/pt)+Le[this.identLevel%pt]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},mt=class{constructor(t){_chunk47YH5LQ7cjs.c.call(void 0, this,"_memoizedResolves",new WeakMap);_chunk47YH5LQ7cjs.c.call(void 0, this,"_memoizedDerived",new WeakMap);_chunk47YH5LQ7cjs.c.call(void 0, this,"_indentController",new dt);_chunk47YH5LQ7cjs.c.call(void 0, this,"_jitTranspiler");_chunk47YH5LQ7cjs.c.call(void 0, this,"_itemStateStack",new lt);_chunk47YH5LQ7cjs.c.call(void 0, this,"_declarations",[]);_chunk47YH5LQ7cjs.c.call(void 0, this,"bindGroupLayoutsToPlaceholderMap",new Map);_chunk47YH5LQ7cjs.c.call(void 0, this,"_nextFreeLayoutPlaceholderIdx",0);_chunk47YH5LQ7cjs.c.call(void 0, this,"fixedBindings",[]);_chunk47YH5LQ7cjs.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:S}}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=He(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}) -> ${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:br,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new (0, _chunk47YH5LQ7cjs.f)(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){let r=t;for(;;)if(Q(r))r=this.readSlot(r);else if(Z(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let s of r)if([...s.slotToValueMap.entries()].every(([d,p])=>d.areEqual(this._itemStateStack.readSlot(d),p)))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 _chunk47YH5LQ7cjs.e?a.appendToTrace(t):new (0, _chunk47YH5LQ7cjs.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(([d,p])=>d.areEqual(this._itemStateStack.readSlot(d),p)))return s.result;let a;_chunkOHFPIYFYcjs.a.call(void 0, t)?a=qe(this,t):Z(t)||Q(t)?a=this.resolve(t):je(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 _chunk47YH5LQ7cjs.e?a.appendToTrace(t):new (0, _chunk47YH5LQ7cjs.e)(a,[t])}finally{this._itemStateStack.pop()}}resolve(t){let r=this.unwrap(t);if(r&&typeof r=="object"||typeof r=="function"){if(this._itemStateStack.itemDepth===0){let n=_chunk47YH5LQ7cjs.j.call(void 0, this,()=>this._getOrInstantiate(r));return`${[...this._declarations].join(`
12
+ ${s}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=w(e,Je(e,r)),o=n?F(e,n):void 0;if(!o)throw new Error("Cannot create variable without an initial value.");return`${e.pre}var ${a} = ${w(e,o)};`}return"b"in t?nr(e,t):`${e.pre}${w(e,F(e,t))};`}function He(e,t){return nr(e,t)}var _typedbinary = require('typed-binary');function Hr(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 y=Hr;var D={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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);for(let[a,o]of Object.entries(t.propTypes))y(e,_chunkOHFPIYFYcjs.na.call(void 0, o)),te(e,o,r[a]);y(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)y(e,n),te(e,t.elementType,r[o]);e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t))},atomic(e,t,r){var n;(n=D[t.inner.type])==null||n.call(D,e,t,r)},decorated(e,t,r){var o,s;let n=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,n);let a=e.currentByteOffset;(s=D[(o=t.inner)==null?void 0:o.type])==null||s.call(D,e,t.inner,r),e.seekTo(a+_chunkOHFPIYFYcjs.qa.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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,n);let a=e.currentByteOffset;for(let u=0;u<Math.min(t.elementCount,r.length);u++)y(e,n),(s=D[(o=t.elementType)==null?void 0:o.type])==null||s.call(D,e,t.elementType,r[u]);e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t))},unstruct(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=D[o.type])==null||n.call(D,e,o,r[a])},"loose-decorated"(e,t,r){var s;let n=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,n);let a=e.currentByteOffset,o=D[(s=t.inner)==null?void 0:s.type];return o==null||o(e,t.inner,r),e.seekTo(a+_chunkOHFPIYFYcjs.qa.call(void 0, t)),r}};function te(e,t,r){let n=D[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var J={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 _chunk47YH5LQ7cjs.m.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunk47YH5LQ7cjs.q.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunk47YH5LQ7cjs.u.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunk47YH5LQ7cjs.n.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunk47YH5LQ7cjs.r.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunk47YH5LQ7cjs.v.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunk47YH5LQ7cjs.o.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunk47YH5LQ7cjs.s.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunk47YH5LQ7cjs.w.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunk47YH5LQ7cjs.p.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunk47YH5LQ7cjs.t.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunk47YH5LQ7cjs.x.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return _chunkOHFPIYFYcjs.va.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkOHFPIYFYcjs.wa.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkOHFPIYFYcjs.xa.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=_chunkOHFPIYFYcjs.na.call(void 0, t);y(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))y(e,_chunkOHFPIYFYcjs.na.call(void 0, o)),n[a]=L(e,o);return y(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkOHFPIYFYcjs.na.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++){y(e,r);let o=t.elementType,s=L(e,o);n.push(s)}return y(e,r),n},atomic(e,t){return L(e,t.inner)},decorated(e,t){let r=_chunkOHFPIYFYcjs.oa.call(void 0, t);y(e,r);let n=e.currentByteOffset,a=L(e,t.inner);return e.seekTo(n+_chunkOHFPIYFYcjs.qa.call(void 0, t)),a},uint8:e=>e.readUint8(),uint8x2:e=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunk47YH5LQ7cjs.w.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>_chunk47YH5LQ7cjs.u.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=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunk47YH5LQ7cjs.w.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, J.snorm16(e),J.snorm16(e)),snorm16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, J.snorm16(e),J.snorm16(e),J.snorm16(e),J.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunk47YH5LQ7cjs.m.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunk47YH5LQ7cjs.q.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunk47YH5LQ7cjs.u.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunk47YH5LQ7cjs.p.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunk47YH5LQ7cjs.t.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunk47YH5LQ7cjs.x.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunk47YH5LQ7cjs.o.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunk47YH5LQ7cjs.s.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunk47YH5LQ7cjs.w.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 _chunk47YH5LQ7cjs.u.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 _chunk47YH5LQ7cjs.u.call(void 0, n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=L(e,a);return r},disarray(e,t){let r=_chunkOHFPIYFYcjs.na.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++)y(e,r),n.push(L(e,t.elementType));return y(e,r),n},"loose-decorated"(e,t){y(e,_chunkOHFPIYFYcjs.oa.call(void 0, t));let r=e.currentByteOffset,n=L(e,t.inner);return e.seekTo(r+_chunkOHFPIYFYcjs.qa.call(void 0, t)),n}};function L(e,t){let r=J[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function ar(e,t,r){return _chunkOHFPIYFYcjs.a.call(void 0, t)?new we(e,t,r):new we(e,t,r,["storage","uniform"])}function re(e){return e.resourceType==="buffer"}function me(e){return!!e.usableAsUniform}function Xr(e){return!!e.usableAsVertex}var we=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","buffer");_chunk47YH5LQ7cjs.c.call(void 0, this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);_chunk47YH5LQ7cjs.c.call(void 0, this,"_buffer",null);_chunk47YH5LQ7cjs.c.call(void 0, this,"_ownBuffer");_chunk47YH5LQ7cjs.c.call(void 0, this,"_destroyed",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"initial");_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsUniform",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsStorage",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsVertex",!1);Nt(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:_chunkOHFPIYFYcjs.qa.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());te(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let s=r.getMappedRange();te(new (0, _typedbinary.BufferWriter)(s),this.dataType,t);return}let a=_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType);this._group.flush();let o=new ArrayBuffer(a);te(new (0, _typedbinary.BufferWriter)(o),this.dataType,t),n.queue.writeBuffer(r,0,o,0,a)}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunkOHFPIYFYcjs.qa.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 L(new (0, _typedbinary.BufferReader)(s),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let s=t.getMappedRange(),u=L(new (0, _typedbinary.BufferReader)(s),this.dataType);return t.unmap(),u}let n=r.createBuffer({size:_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkOHFPIYFYcjs.qa.call(void 0, this.dataType));let o=L(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}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 Y(e){return!!(e!=null&&e.usableAsStorage)}var Se=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 ur(e){return(e==null?void 0:e.resourceType)==="buffer-usage"}var pr={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Te=class{constructor(t,r){this.usage=t;this.buffer=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"~repr");_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","buffer-usage")}get label(){return this.buffer.label}$name(t){this.buffer.$name(t)}"~resolve"(t){let r=t.names.makeUnique(this.label),{group:n,binding: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}toString(){var t;return`${this.usage}:${(t=this.label)!=null?t:"<unnamed>"}`}get value(){if(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this}},ge=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"~repr");_chunk47YH5LQ7cjs.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(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this}},or=new WeakMap;function Qr(e){if(!Y(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=or.get(e);return t||(t=new Te("mutable",e),or.set(e,t)),t}var sr=new WeakMap;function Zr(e){if(!Y(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=sr.get(e);return t||(t=new Te("readonly",e),sr.set(e,t)),t}var ir=new WeakMap;function en(e){if(!me(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=ir.get(e);return t||(t=new Te("uniform",e),ir.set(e,t)),t}function lr(e){return new Ze(e)}function dr(e){return new et(e)}function tn(e){return(e==null?void 0:e.resourceType)==="sampler"}function rn(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var De=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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>"}`}},Fe=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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>"}`}},Ze=class{constructor(t){this._props=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","sampler");_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.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>"}`}},et=class{constructor(t){this._props=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","sampler-comparison");_chunk47YH5LQ7cjs.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 Ue=class{constructor(t){this._membership=t;_chunk47YH5LQ7cjs.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 mr={r8unorm:_chunkOHFPIYFYcjs.n,r8snorm:_chunkOHFPIYFYcjs.n,r8uint:_chunkOHFPIYFYcjs.l,r8sint:_chunkOHFPIYFYcjs.m,r16uint:_chunkOHFPIYFYcjs.l,r16sint:_chunkOHFPIYFYcjs.m,r16float:_chunkOHFPIYFYcjs.n,rg8unorm:_chunkOHFPIYFYcjs.n,rg8snorm:_chunkOHFPIYFYcjs.n,rg8uint:_chunkOHFPIYFYcjs.l,rg8sint:_chunkOHFPIYFYcjs.m,r32uint:_chunkOHFPIYFYcjs.l,r32sint:_chunkOHFPIYFYcjs.m,r32float:_chunkOHFPIYFYcjs.n,rg16uint:_chunkOHFPIYFYcjs.l,rg16sint:_chunkOHFPIYFYcjs.m,rg16float:_chunkOHFPIYFYcjs.n,rgba8unorm:_chunkOHFPIYFYcjs.n,"rgba8unorm-srgb":_chunkOHFPIYFYcjs.n,rgba8snorm:_chunkOHFPIYFYcjs.n,rgba8uint:_chunkOHFPIYFYcjs.l,rgba8sint:_chunkOHFPIYFYcjs.m,bgra8unorm:_chunkOHFPIYFYcjs.n,"bgra8unorm-srgb":_chunkOHFPIYFYcjs.n,rgb9e5ufloat:_chunkOHFPIYFYcjs.n,rgb10a2uint:_chunkOHFPIYFYcjs.l,rgb10a2unorm:_chunkOHFPIYFYcjs.n,rg11b10ufloat:_chunkOHFPIYFYcjs.n,rg32uint:_chunkOHFPIYFYcjs.l,rg32sint:_chunkOHFPIYFYcjs.m,rg32float:_chunkOHFPIYFYcjs.n,rgba16uint:_chunkOHFPIYFYcjs.l,rgba16sint:_chunkOHFPIYFYcjs.m,rgba16float:_chunkOHFPIYFYcjs.n,rgba32uint:_chunkOHFPIYFYcjs.l,rgba32sint:_chunkOHFPIYFYcjs.m,rgba32float:_chunkOHFPIYFYcjs.n,stencil8:_chunkOHFPIYFYcjs.n,depth16unorm:_chunkOHFPIYFYcjs.n,depth24plus:_chunkOHFPIYFYcjs.n,"depth24plus-stencil8":_chunkOHFPIYFYcjs.n,depth32float:_chunkOHFPIYFYcjs.n,"depth32float-stencil8":_chunkOHFPIYFYcjs.n,"bc1-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc1-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc2-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc2-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc3-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc3-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"bc4-r-unorm":_chunkOHFPIYFYcjs.n,"bc4-r-snorm":_chunkOHFPIYFYcjs.n,"bc5-rg-unorm":_chunkOHFPIYFYcjs.n,"bc5-rg-snorm":_chunkOHFPIYFYcjs.n,"bc6h-rgb-ufloat":_chunkOHFPIYFYcjs.n,"bc6h-rgb-float":_chunkOHFPIYFYcjs.n,"bc7-rgba-unorm":_chunkOHFPIYFYcjs.n,"bc7-rgba-unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgb8unorm":_chunkOHFPIYFYcjs.n,"etc2-rgb8unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgb8a1unorm":_chunkOHFPIYFYcjs.n,"etc2-rgb8a1unorm-srgb":_chunkOHFPIYFYcjs.n,"etc2-rgba8unorm":_chunkOHFPIYFYcjs.n,"etc2-rgba8unorm-srgb":_chunkOHFPIYFYcjs.n,"eac-r11unorm":_chunkOHFPIYFYcjs.n,"eac-r11snorm":_chunkOHFPIYFYcjs.n,"eac-rg11unorm":_chunkOHFPIYFYcjs.n,"eac-rg11snorm":_chunkOHFPIYFYcjs.n,"astc-4x4-unorm":_chunkOHFPIYFYcjs.n,"astc-4x4-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-5x4-unorm":_chunkOHFPIYFYcjs.n,"astc-5x4-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-5x5-unorm":_chunkOHFPIYFYcjs.n,"astc-5x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-6x5-unorm":_chunkOHFPIYFYcjs.n,"astc-6x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-6x6-unorm":_chunkOHFPIYFYcjs.n,"astc-6x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x5-unorm":_chunkOHFPIYFYcjs.n,"astc-8x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x6-unorm":_chunkOHFPIYFYcjs.n,"astc-8x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-8x8-unorm":_chunkOHFPIYFYcjs.n,"astc-8x8-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x5-unorm":_chunkOHFPIYFYcjs.n,"astc-10x5-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x6-unorm":_chunkOHFPIYFYcjs.n,"astc-10x6-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x8-unorm":_chunkOHFPIYFYcjs.n,"astc-10x8-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-10x10-unorm":_chunkOHFPIYFYcjs.n,"astc-10x10-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-12x10-unorm":_chunkOHFPIYFYcjs.n,"astc-12x10-unorm-srgb":_chunkOHFPIYFYcjs.n,"astc-12x12-unorm":_chunkOHFPIYFYcjs.n,"astc-12x12-unorm-srgb":_chunkOHFPIYFYcjs.n},fe={rgba8unorm:_chunk47YH5LQ7cjs.u,rgba8snorm:_chunk47YH5LQ7cjs.u,rgba8uint:_chunk47YH5LQ7cjs.x,rgba8sint:_chunk47YH5LQ7cjs.w,rgba16uint:_chunk47YH5LQ7cjs.x,rgba16sint:_chunk47YH5LQ7cjs.w,rgba16float:_chunk47YH5LQ7cjs.u,r32uint:_chunk47YH5LQ7cjs.x,r32sint:_chunk47YH5LQ7cjs.w,r32float:_chunk47YH5LQ7cjs.u,rg32uint:_chunk47YH5LQ7cjs.x,rg32sint:_chunk47YH5LQ7cjs.w,rg32float:_chunk47YH5LQ7cjs.u,rgba32uint:_chunk47YH5LQ7cjs.x,rgba32sint:_chunk47YH5LQ7cjs.w,rgba32float:_chunk47YH5LQ7cjs.u,bgra8unorm:_chunk47YH5LQ7cjs.u},Tr={f32:"float",u32:"uint",i32:"sint"},gr={float:_chunkOHFPIYFYcjs.n,"unfilterable-float":_chunkOHFPIYFYcjs.n,uint:_chunkOHFPIYFYcjs.l,sint:_chunkOHFPIYFYcjs.m,depth:_chunkOHFPIYFYcjs.n};function fr(e,t){return new tt(e,t)}function j(e){return(e==null?void 0:e.resourceType)==="texture"}function at(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function ot(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var yr={mutable:"read_write",readonly:"read",writeonly:"write"},tt=class{constructor(t,r){this.props=t;this._branch=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture");_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsSampled",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsStorage",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"usableAsRender",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_destroyed",!1);_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);_chunk47YH5LQ7cjs.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=fe[n];return _chunk47YH5LQ7cjs.d.call(void 0, !!a,`Unsupported storage texture format: ${n}`),new rt(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(!fe[r])throw new Error(`Unsupported storage texture format: ${r}`);return new nt(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Re={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},rt=class{constructor(t,r,n){this.access=r;this._texture=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"texelDataType");_chunk47YH5LQ7cjs.c.call(void 0, this,"dimension");_chunk47YH5LQ7cjs.c.call(void 0, this,"_view");_chunk47YH5LQ7cjs.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=fe[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_${Re[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${yr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},ve=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"texelDataType");this.texelDataType=fe[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_${Re[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${yr[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},nt=class{constructor(t,r){this._props=t;this._texture=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"channelDataType");_chunk47YH5LQ7cjs.c.call(void 0, this,"dimension");_chunk47YH5LQ7cjs.c.call(void 0, this,"_format");_chunk47YH5LQ7cjs.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=mr[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(_chunk47YH5LQ7cjs.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:Tr[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${Re[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>"}`}},Ae=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunk47YH5LQ7cjs.c.call(void 0, this,"channelDataType");this.channelDataType=gr[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_${Re[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 st(e){return!!(e!=null&&e.usableAsSampled)}function nn(e){return!!(e!=null&&e.usableAsRender)}var _e=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 Ie(e){return new ut(e)}function Ee(e){return!!e&&e.resourceType==="bind-group-layout"}function xr(e){return!!e&&e.resourceType==="bind-group"}var it=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)}},cr=["compute"],ne=["compute","vertex","fragment"],ut=class{constructor(t){this.entries=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");_chunk47YH5LQ7cjs.c.call(void 0, this,"_index");_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","bind-group-layout");_chunk47YH5LQ7cjs.c.call(void 0, this,"bound",{});var n,a,o,s,u;let r=0;for(let[d,l]of Object.entries(t)){if(l===null){r++;continue}let T={idx:r,key:d,layout:this};if("uniform"in l&&(this.bound[d]=new ge("uniform",l.uniform,T)),"storage"in l){let g="type"in l.storage?l.storage:l.storage(0);this.bound[d]=new ge((n=l.access)!=null?n:"readonly",g,T)}"texture"in l&&(this.bound[d]=new Ae(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,T)),"storageTexture"in l&&(this.bound[d]=new ve(l.storageTexture,(s=l.viewDimension)!=null?s:"2d",(u=l.access)!=null?u:"writeonly",T)),"externalTexture"in l&&(this.bound[d]=new Ue(T)),"sampler"in l&&(l.sampler==="comparison"?this.bound[d]=new Fe(T):this.bound[d]=new De(T)),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 d,l,T,g;if(a===null)return null;let s=a.visibility,u={binding:o,visibility:0};if("uniform"in a)s=s!=null?s:ne,u.buffer={type:"uniform"};else if("storage"in a)s=s!=null?s:a.access==="mutable"?cr:ne,u.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)s=s!=null?s:ne,u.sampler={type:a.sampler};else if("texture"in a)s=s!=null?s:ne,u.texture={sampleType:a.texture,viewDimension:(d=a.viewDimension)!=null?d:"2d",multisampled:(l=a.multisampled)!=null?l:!1};else if("storageTexture"in a){let m=(T=a.access)!=null?T:"writeonly";s=s!=null?s:m==="readonly"?ne:cr,u.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[m],viewDimension:(g=a.viewDimension)!=null?g:"2d"}}else"externalTexture"in a&&(s=s!=null?s:ne,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 H(this,t)}},H=class{constructor(t,r){this.layout=t;this.entries=r;_chunk47YH5LQ7cjs.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 it(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 d;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 '${(d=this.layout.label)!=null?d:"<unnamed>"}'.`);if("uniform"in o){let l;if(re(u)){if(!me(u))throw new (0, _chunk47YH5LQ7cjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:s,resource:l}}if("storage"in o){let l;if(re(u)){if(!Y(u))throw new (0, _chunk47YH5LQ7cjs.g)(u);l={buffer:t.unwrap(u)}}else l={buffer:u};return{binding:s,resource:l}}if("texture"in o){let l;if(j(u)){if(!st(u))throw new _e(u);l=t.unwrap(u.createView("sampled"))}else l=u;return{binding:s,resource:l}}if("storageTexture"in o){let l;if(j(u)){if(!Y(u))throw new Se(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 br="#CATCHALL#",lt=class{constructor(){_chunk47YH5LQ7cjs.c.call(void 0, this,"_stack",[]);_chunk47YH5LQ7cjs.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:S}: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}}}}},Le=[""," "," "," "," "," "," "," "," "],pt=Le.length-1,dt=class{constructor(){_chunk47YH5LQ7cjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=Le[this.identLevel])!=null?t:Le[pt].repeat(this.identLevel/pt)+Le[this.identLevel%pt]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},mt=class{constructor(t){_chunk47YH5LQ7cjs.c.call(void 0, this,"_memoizedResolves",new WeakMap);_chunk47YH5LQ7cjs.c.call(void 0, this,"_memoizedDerived",new WeakMap);_chunk47YH5LQ7cjs.c.call(void 0, this,"_indentController",new dt);_chunk47YH5LQ7cjs.c.call(void 0, this,"_jitTranspiler");_chunk47YH5LQ7cjs.c.call(void 0, this,"_itemStateStack",new lt);_chunk47YH5LQ7cjs.c.call(void 0, this,"_declarations",[]);_chunk47YH5LQ7cjs.c.call(void 0, this,"bindGroupLayoutsToPlaceholderMap",new Map);_chunk47YH5LQ7cjs.c.call(void 0, this,"_nextFreeLayoutPlaceholderIdx",0);_chunk47YH5LQ7cjs.c.call(void 0, this,"fixedBindings",[]);_chunk47YH5LQ7cjs.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:S}}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=He(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}) -> ${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:br,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new (0, _chunk47YH5LQ7cjs.f)(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){let r=t;for(;;)if(Q(r))r=this.readSlot(r);else if(Z(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let s of r)if([...s.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),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 _chunk47YH5LQ7cjs.e?a.appendToTrace(t):new (0, _chunk47YH5LQ7cjs.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(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return s.result;let a;_chunkOHFPIYFYcjs.a.call(void 0, t)?a=qe(this,t):Z(t)||Q(t)?a=this.resolve(t):je(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 _chunk47YH5LQ7cjs.e?a.appendToTrace(t):new (0, _chunk47YH5LQ7cjs.e)(a,[t])}finally{this._itemStateStack.pop()}}resolve(t){let r=this.unwrap(t);if(r&&typeof r=="object"||typeof r=="function"){if(this._itemStateStack.itemDepth===0){let n=_chunk47YH5LQ7cjs.j.call(void 0, this,()=>this._getOrInstantiate(r));return`${[...this._declarations].join(`
13
13
 
14
- `)}${n}`}return this._getOrInstantiate(r)}return String(r)}resolveValue(t,r){if(z(t))return this.resolve(t);if(r&&_chunkOHFPIYFYcjs.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&&_chunkOHFPIYFYcjs.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 ae(e,t){var g;let r=new mt(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],s=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),u=tr(s),d=r.fixedBindings.map((m,c)=>[String(c),m.layoutEntry]),p=()=>{let m=u.next().value,c=Ie(Object.fromEntries(d));return o[m]=c,n=n.replaceAll(br,String(m)),[m,new H(c,Object.fromEntries(r.fixedBindings.map((f,h)=>[String(h),f.resource])))]},T=d.length>0?p():null;for(let[m,c]of a.entries()){let f=(g=m.index)!=null?g:u.next().value;o[f]=m,n=n.replaceAll(c,String(f))}return{code:n,bindGroupLayouts:o,catchall:T}}function hr(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};K(o,t!=null?t:{});let s={"~resolve"(d){return q(d,o,r!=null?r:"")},toString:()=>"<root>"},{code:u}=ae(s,{names:n==="strict"?new N:new M,jitTranspiler:a});return u}var ye=class{constructor(t){this._make=t;_chunk47YH5LQ7cjs.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 wr(e,t,r){return new Tt(new gt(e,t,r),{})}function Sr(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var Tt=class e{constructor(t,r){this._core=t;this._priors=r;_chunk47YH5LQ7cjs.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){var s;let a=this._core.unwrap(),o=this._core.branch.commandEncoder.beginComputePass({label:(s=this._core.label)!=null?s:"<unnamed>"});o.setPipeline(a.pipeline),a.bindGroupLayouts.forEach((u,d)=>{var p;if(a.catchall&&d===a.catchall[0])o.setBindGroup(d,this._core.branch.unwrap(a.catchall[1]));else{let T=(p=this._priors.bindGroupLayoutMap)==null?void 0:p.get(u);if(T===void 0)throw new (0, _chunk47YH5LQ7cjs.i)(u.label);o.setBindGroup(d,this._core.branch.unwrap(T))}}),o.dispatchWorkgroups(t,r,n),o.end()}$name(t){return this._core.label=t,this}},gt=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.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:d,catchall:p}=ae({"~resolve":T=>(T.withSlots(this._slotBindings,()=>{T.resolve(this._entryFn)}),""),toString:()=>{var T;return`computePipeline:${(T=this.label)!=null?T:"<unnamed>"}`}},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});p!==null&&((r=d[p[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:d.map(T=>this.branch.unwrap(T))}),compute:{module:s.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:u})}}),bindGroupLayouts:d,catchall:p}}return this._memo}};function an(e){return typeof(e==null?void 0:e.format)=="string"}function Dr(e,t){var s,u;let r=[];if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!an(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=_chunkOHFPIYFYcjs.x.call(void 0, e))!=null?s:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[d,p]of Object.entries(e)){if(_chunkOHFPIYFYcjs.Fa.call(void 0, p))continue;let T=t[d];if(!T)throw new Error(`An attribute by the name of '${d}' was not provided to the shader.`);let g=T._layout,m=a.get(g);m||(r.push(g),m=[],n.push({arrayStride:g.stride,stepMode:g.stepMode,attributes:m}),a.set(g,m)),o=(u=_chunkOHFPIYFYcjs.x.call(void 0, p))!=null?u:o,m.push({format:T.format,offset:T.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}function Fr(e,t="vertex"){return new ft(e,t)}function Ur(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}function Be(e,t,r){if(_chunkOHFPIYFYcjs.j.call(void 0, t)||_chunkOHFPIYFYcjs.w.call(void 0, t))return Be(e,t.inner,_chunkOHFPIYFYcjs.q.call(void 0, r,_chunkOHFPIYFYcjs.oa.call(void 0, t)));if(_chunkOHFPIYFYcjs.c.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([a,o])=>{n=_chunkOHFPIYFYcjs.q.call(void 0, n,_chunkOHFPIYFYcjs.na.call(void 0, o));let s=[a,Be(e,o,n)];return n+=_chunkOHFPIYFYcjs.qa.call(void 0, o),s}))}if(_chunkOHFPIYFYcjs.v.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([a,o])=>{n=_chunkOHFPIYFYcjs.q.call(void 0, n,_chunkOHFPIYFYcjs.oa.call(void 0, o));let s=[a,Be(e,o,n)];return n+=_chunkOHFPIYFYcjs.qa.call(void 0, o),s}))}if("type"in t&&typeof t.type=="string"){if(_chunkOHFPIYFYcjs.r.includes(t.type))return{_layout:e,format:t.type,offset:r};let n=_chunkOHFPIYFYcjs.s[t.type];if(n)return{_layout:e,format:n,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var ft=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","vertex-layout");_chunk47YH5LQ7cjs.c.call(void 0, this,"stride");_chunk47YH5LQ7cjs.c.call(void 0, this,"attrib");_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");let n=t(0);this.stride=_chunkOHFPIYFYcjs.q.call(void 0, _chunkOHFPIYFYcjs.qa.call(void 0, n.elementType),_chunkOHFPIYFYcjs.na.call(void 0, n)),this.attrib=Be(this,n.elementType,0)}get label(){return this._label}$name(t){return this._label=t,this}};function on(e){return typeof(e==null?void 0:e.loadOp)=="string"}function vr(e,t){if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!on(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 sn(e){return typeof(e==null?void 0:e.format)=="string"}function Ar(e,t){if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!sn(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 Rr(e){return new yt(new ct(e),{})}var yt=class e{constructor(t,r){this._core=t;this._priors=r;_chunk47YH5LQ7cjs.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(Ee(t))return new e(this._core,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(Ur(t))return new e(this._core,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.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,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._priors),{colorAttachment:t}))}draw(t,r,n,a){var T,g;let o=this._core.unwrap(),{branch:s,fragmentFn:u}=this._core.options,d=vr(u.shell.returnType,(T=this._priors.colorAttachment)!=null?T:{}).map(m=>j(m.view)?_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},m),{view:s.unwrap(m.view).createView()}):m),p=s.commandEncoder.beginRenderPass({label:(g=this._core.label)!=null?g:"<unnamed>",colorAttachments:d});p.setPipeline(o.pipeline),o.bindGroupLayouts.forEach((m,c)=>{var f;if(o.catchall&&c===o.catchall[0])p.setBindGroup(c,s.unwrap(o.catchall[1]));else{let h=(f=this._priors.bindGroupLayoutMap)==null?void 0:f.get(m);if(h===void 0)throw new (0, _chunk47YH5LQ7cjs.i)(m.label);p.setBindGroup(c,s.unwrap(h))}}),this._core.usedVertexLayouts.forEach((m,c)=>{var h,A;let f=(h=this._priors.vertexLayoutMap)==null?void 0:h.get(m);if(!f)throw new Error(`Missing vertex buffer for layout '${(A=m.label)!=null?A:"<unnamed>"}'. Please provide it using pipeline.with(layout, buffer).(...)`);p.setVertexBuffer(c,s.unwrap(f))}),p.draw(t,r,n,a),p.end()}},ct=class{constructor(t){this.options=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.c.call(void 0, this,"usedVertexLayouts");_chunk47YH5LQ7cjs.c.call(void 0, this,"_memo");_chunk47YH5LQ7cjs.c.call(void 0, this,"_vertexBufferLayouts");_chunk47YH5LQ7cjs.c.call(void 0, this,"_targets");let r=Dr(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Ar(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,r,n,a;if(this._memo===void 0){let{branch:o,vertexFn:s,fragmentFn:u,slotBindings:d,primitiveState:p}=this.options,{code:T,bindGroupLayouts:g,catchall:m}=ae({"~resolve":A=>(A.withSlots(d,()=>{A.resolve(s),A.resolve(u)}),""),toString:()=>{var A;return`renderPipeline:${(A=this.label)!=null?A:"<unnamed>"}`}},{names:o.nameRegistry,jitTranspiler:o.jitTranspiler});m!==null&&((r=g[m[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let c=o.device,f=c.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:T}),h={layout:c.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:g.map(A=>o.unwrap(A))}),vertex:{module:f,buffers:this._vertexBufferLayouts},fragment:{module:f,targets:this._targets}};this.label!==void 0&&(h.label=this.label),p&&(h.primitive=p),this._memo={pipeline:c.createRenderPipeline(h),bindGroupLayouts:g,catchall:m}}return this._memo}};var xt=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[de(t)?t.slot:t,r]])}withCompute(t){return new bt(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new ht({branch:this._getRoot(),primitiveState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},bt=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return wr(this._root,this._slotBindings,this._entryFn)}},ht=class{constructor(t){this._options=t}withFragment(t,r,n){return _chunk47YH5LQ7cjs.d.call(void 0, typeof t!="string","Just type mismatch validation"),_chunk47YH5LQ7cjs.d.call(void 0, typeof r!="string","Just type mismatch validation"),new wt(_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},wt=class e{constructor(t){this._options=t}withPrimitive(t){return new e(_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._options),{primitiveState:t}))}createPipeline(){return Rr(this._options)}},Pe=class extends xt{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;_chunk47YH5LQ7cjs.c.call(void 0, this,"~unstable");_chunk47YH5LQ7cjs.c.call(void 0, this,"_disposables",[]);_chunk47YH5LQ7cjs.c.call(void 0, this,"_unwrappedBindGroupLayouts",new ye(r=>r.unwrap(this)));_chunk47YH5LQ7cjs.c.call(void 0, this,"_unwrappedBindGroups",new ye(r=>r.unwrap(this)));_chunk47YH5LQ7cjs.c.call(void 0, this,"_commandEncoder",null);this["~unstable"]={nameRegistry:this.nameRegistry,commandEncoder:this.commandEncoder,createTexture:this.createTexture.bind(this),with:this.with.bind(this),withCompute:this.withCompute.bind(this),withVertex:this.withVertex.bind(this),flush:this.flush.bind(this)}}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=ar(this,r,n);return this._disposables.push(a),a}createBindGroup(r,n){return new H(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=fr(r,this);return this._disposables.push(n),n}unwrap(r){if(Sr(r))return r.rawPipeline;if(Ee(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(xr(r))return this._unwrappedBindGroups.getOrMake(r);if(re(r))return r.buffer;if(j(r)||at(r)||ot(r))return r.unwrap();throw new Error(`Unknown resource type: ${r}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function _r(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 Pe(await o.requestDevice(r),n==="random"?new M:new N,a,!0)}function Ir(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new Pe(t,r==="random"?new M:new N,n,!1)}function Ve(e){return new St(e)}var St=class{constructor(t=void 0){this.defaultValue=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","slot");_chunk47YH5LQ7cjs.c.call(void 0, this,"label")}$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=_chunk47YH5LQ7cjs.k.call(void 0, );if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return t.unwrap(this)}};function Er(e,t){return new Dt(e,t)}var Dt=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","accessor");_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.c.call(void 0, this,"slot");this.slot=Ve(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(!_chunk47YH5LQ7cjs.k.call(void 0, ))throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return this}"~resolve"(t){let r=t.unwrap(this.slot);return ur(r)?t.resolve(r):Ke(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function Lr(e){return un(e)}function un(e){return{resourceType:"derived","~compute":e,get value(){let r=_chunk47YH5LQ7cjs.k.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return r.unwrap(this)},with(r,n){return Br(e,this,[r,n])},toString(){return"derived"}}}function Br(e,t,r){return{resourceType:"derived","~compute"(){let a=_chunk47YH5LQ7cjs.k.call(void 0, );if(!a)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return a.withSlots([r],()=>a.unwrap(t))},get value(){let a=_chunk47YH5LQ7cjs.k.call(void 0, );if(!a)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return a.unwrap(this)},with(a,o){return Br(e,this,[a,o])},toString(){var s;let[a,o]=r;return`derived[${(s=a.label)!=null?s:"<unnamed>"}=${o}]`}}}function Pr(e,t){return new Ce("private",e,t)}function Vr(e){return new Ce("workgroup",e)}var Ce=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n;_chunk47YH5LQ7cjs.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(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access tgpu.var's value directly in JS.");return this}};var Cr={bindGroupLayout:Ie,init:_r,initFromDevice:Ir,resolve:hr,"~unstable":{fn:Ht,fragmentFn:Qt,vertexFn:Zt,computeFn:Yt,vertexLayout:Fr,derived:Lr,slot:Ve,accessor:Er,privateVar:Pr,workgroupVar:Vr,const:Wt,declare:zt,sampler:lr,comparisonSampler:dr}},Es= exports.default =Cr;Object.assign(Cr,{__assignAst:Jt});exports.MissingBindGroupError = _chunk47YH5LQ7cjs.i; exports.MissingLinksError = _chunk47YH5LQ7cjs.h; exports.MissingSlotValueError = _chunk47YH5LQ7cjs.f; exports.NotUniformError = _chunk47YH5LQ7cjs.g; exports.RandomNameRegistry = M; exports.ResolutionError = _chunk47YH5LQ7cjs.e; exports.StrictNameRegistry = N; exports.default = Es; exports.isBuffer = re; exports.isComparisonSampler = rn; exports.isDerived = Z; exports.isSampledTextureView = ot; exports.isSampler = tn; exports.isSlot = Q; exports.isStorageTextureView = at; exports.isTexture = j; exports.isTgpuFn = Ke; exports.isUsableAsRender = nn; exports.isUsableAsSampled = st; exports.isUsableAsStorage = Y; exports.isUsableAsUniform = me; exports.isUsableAsVertex = Xr; exports.tgpu = Cr; exports.unstable_asMutable = Qr; exports.unstable_asReadonly = Zr; exports.unstable_asUniform = en;
14
+ `)}${n}`}return this._getOrInstantiate(r)}return String(r)}resolveValue(t,r){if(z(t))return this.resolve(t);if(r&&_chunkOHFPIYFYcjs.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&&_chunkOHFPIYFYcjs.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 ae(e,t){var g;let r=new mt(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],s=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),u=tr(s),d=r.fixedBindings.map((m,c)=>[String(c),m.layoutEntry]),l=()=>{let m=u.next().value,c=Ie(Object.fromEntries(d));return o[m]=c,n=n.replaceAll(br,String(m)),[m,new H(c,Object.fromEntries(r.fixedBindings.map((f,h)=>[String(h),f.resource])))]},T=d.length>0?l():null;for(let[m,c]of a.entries()){let f=(g=m.index)!=null?g:u.next().value;o[f]=m,n=n.replaceAll(c,String(f))}return{code:n,bindGroupLayouts:o,catchall:T}}function hr(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};K(o,t!=null?t:{});let s={"~resolve"(d){return q(d,o,r!=null?r:"")},toString:()=>"<root>"},{code:u}=ae(s,{names:n==="strict"?new N:new M,jitTranspiler:a});return u}var ye=class{constructor(t){this._make=t;_chunk47YH5LQ7cjs.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 wr(e,t,r){return new Tt(new gt(e,t,r),{})}function Sr(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var Tt=class e{constructor(t,r){this._core=t;this._priors=r;_chunk47YH5LQ7cjs.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){var s;let a=this._core.unwrap(),o=this._core.branch.commandEncoder.beginComputePass({label:(s=this._core.label)!=null?s:"<unnamed>"});o.setPipeline(a.pipeline),a.bindGroupLayouts.forEach((u,d)=>{var l;if(a.catchall&&d===a.catchall[0])o.setBindGroup(d,this._core.branch.unwrap(a.catchall[1]));else{let T=(l=this._priors.bindGroupLayoutMap)==null?void 0:l.get(u);if(T===void 0)throw new (0, _chunk47YH5LQ7cjs.i)(u.label);o.setBindGroup(d,this._core.branch.unwrap(T))}}),o.dispatchWorkgroups(t,r,n),o.end()}$name(t){return this._core.label=t,this}},gt=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.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:d,catchall:l}=ae({"~resolve":T=>(T.withSlots(this._slotBindings,()=>{T.resolve(this._entryFn)}),""),toString:()=>{var T;return`computePipeline:${(T=this.label)!=null?T:"<unnamed>"}`}},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});l!==null&&((r=d[l[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`)),this._memo={pipeline:s.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:s.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:d.map(T=>this.branch.unwrap(T))}),compute:{module:s.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:u})}}),bindGroupLayouts:d,catchall:l}}return this._memo}};function an(e){return typeof(e==null?void 0:e.format)=="string"}function Dr(e,t){var s,u;let r=[];if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!an(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=_chunkOHFPIYFYcjs.x.call(void 0, e))!=null?s:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[d,l]of Object.entries(e)){if(_chunkOHFPIYFYcjs.Fa.call(void 0, l))continue;let T=t[d];if(!T)throw new Error(`An attribute by the name of '${d}' was not provided to the shader.`);let g=T._layout,m=a.get(g);m||(r.push(g),m=[],n.push({arrayStride:g.stride,stepMode:g.stepMode,attributes:m}),a.set(g,m)),o=(u=_chunkOHFPIYFYcjs.x.call(void 0, l))!=null?u:o,m.push({format:T.format,offset:T.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}function Fr(e,t="vertex"){return new ft(e,t)}function Ur(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}function Be(e,t,r){if(_chunkOHFPIYFYcjs.j.call(void 0, t)||_chunkOHFPIYFYcjs.w.call(void 0, t))return Be(e,t.inner,_chunkOHFPIYFYcjs.q.call(void 0, r,_chunkOHFPIYFYcjs.oa.call(void 0, t)));if(_chunkOHFPIYFYcjs.c.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([a,o])=>{n=_chunkOHFPIYFYcjs.q.call(void 0, n,_chunkOHFPIYFYcjs.na.call(void 0, o));let s=[a,Be(e,o,n)];return n+=_chunkOHFPIYFYcjs.qa.call(void 0, o),s}))}if(_chunkOHFPIYFYcjs.v.call(void 0, t)){let n=r;return Object.fromEntries(Object.entries(t.propTypes).map(([a,o])=>{n=_chunkOHFPIYFYcjs.q.call(void 0, n,_chunkOHFPIYFYcjs.oa.call(void 0, o));let s=[a,Be(e,o,n)];return n+=_chunkOHFPIYFYcjs.qa.call(void 0, o),s}))}if("type"in t&&typeof t.type=="string"){if(_chunkOHFPIYFYcjs.r.includes(t.type))return{_layout:e,format:t.type,offset:r};let n=_chunkOHFPIYFYcjs.s[t.type];if(n)return{_layout:e,format:n,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var ft=class{constructor(t,r){this.schemaForCount=t;this.stepMode=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","vertex-layout");_chunk47YH5LQ7cjs.c.call(void 0, this,"stride");_chunk47YH5LQ7cjs.c.call(void 0, this,"attrib");_chunk47YH5LQ7cjs.c.call(void 0, this,"_label");let n=t(0);this.stride=_chunkOHFPIYFYcjs.q.call(void 0, _chunkOHFPIYFYcjs.qa.call(void 0, n.elementType),_chunkOHFPIYFYcjs.na.call(void 0, n)),this.attrib=Be(this,n.elementType,0)}get label(){return this._label}$name(t){return this._label=t,this}};function on(e){return typeof(e==null?void 0:e.loadOp)=="string"}function vr(e,t){if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!on(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 sn(e){return typeof(e==null?void 0:e.format)=="string"}function Ar(e,t){if(_chunkOHFPIYFYcjs.y.call(void 0, e)){if(!sn(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 Rr(e){return new yt(new ct(e),{})}var yt=class e{constructor(t,r){this._core=t;this._priors=r;_chunk47YH5LQ7cjs.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(Ee(t))return new e(this._core,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(Ur(t))return new e(this._core,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.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,_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._priors),{colorAttachment:t}))}draw(t,r,n,a){var T,g;let o=this._core.unwrap(),{branch:s,fragmentFn:u}=this._core.options,d=vr(u.shell.returnType,(T=this._priors.colorAttachment)!=null?T:{}).map(m=>j(m.view)?_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},m),{view:s.unwrap(m.view).createView()}):m),l=s.commandEncoder.beginRenderPass({label:(g=this._core.label)!=null?g:"<unnamed>",colorAttachments:d});l.setPipeline(o.pipeline),o.bindGroupLayouts.forEach((m,c)=>{var f;if(o.catchall&&c===o.catchall[0])l.setBindGroup(c,s.unwrap(o.catchall[1]));else{let h=(f=this._priors.bindGroupLayoutMap)==null?void 0:f.get(m);if(h===void 0)throw new (0, _chunk47YH5LQ7cjs.i)(m.label);l.setBindGroup(c,s.unwrap(h))}}),this._core.usedVertexLayouts.forEach((m,c)=>{var h,A;let f=(h=this._priors.vertexLayoutMap)==null?void 0:h.get(m);if(!f)throw new Error(`Missing vertex buffer for layout '${(A=m.label)!=null?A:"<unnamed>"}'. Please provide it using pipeline.with(layout, buffer).(...)`);l.setVertexBuffer(c,s.unwrap(f))}),l.draw(t,r,n,a),l.end()}},ct=class{constructor(t){this.options=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.c.call(void 0, this,"usedVertexLayouts");_chunk47YH5LQ7cjs.c.call(void 0, this,"_memo");_chunk47YH5LQ7cjs.c.call(void 0, this,"_vertexBufferLayouts");_chunk47YH5LQ7cjs.c.call(void 0, this,"_targets");let r=Dr(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Ar(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,r,n,a;if(this._memo===void 0){let{branch:o,vertexFn:s,fragmentFn:u,slotBindings:d,primitiveState:l}=this.options,{code:T,bindGroupLayouts:g,catchall:m}=ae({"~resolve":A=>(A.withSlots(d,()=>{A.resolve(s),A.resolve(u)}),""),toString:()=>{var A;return`renderPipeline:${(A=this.label)!=null?A:"<unnamed>"}`}},{names:o.nameRegistry,jitTranspiler:o.jitTranspiler});m!==null&&((r=g[m[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let c=o.device,f=c.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:T}),h={layout:c.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:g.map(A=>o.unwrap(A))}),vertex:{module:f,buffers:this._vertexBufferLayouts},fragment:{module:f,targets:this._targets}};this.label!==void 0&&(h.label=this.label),l&&(h.primitive=l),this._memo={pipeline:c.createRenderPipeline(h),bindGroupLayouts:g,catchall:m}}return this._memo}};var xt=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[de(t)?t.slot:t,r]])}withCompute(t){return new bt(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new ht({branch:this._getRoot(),primitiveState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},bt=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return wr(this._root,this._slotBindings,this._entryFn)}},ht=class{constructor(t){this._options=t}withFragment(t,r,n){return _chunk47YH5LQ7cjs.d.call(void 0, typeof t!="string","Just type mismatch validation"),_chunk47YH5LQ7cjs.d.call(void 0, typeof r!="string","Just type mismatch validation"),new wt(_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},wt=class e{constructor(t){this._options=t}withPrimitive(t){return new e(_chunk47YH5LQ7cjs.b.call(void 0, _chunk47YH5LQ7cjs.a.call(void 0, {},this._options),{primitiveState:t}))}createPipeline(){return Rr(this._options)}},Pe=class extends xt{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;_chunk47YH5LQ7cjs.c.call(void 0, this,"~unstable");_chunk47YH5LQ7cjs.c.call(void 0, this,"_disposables",[]);_chunk47YH5LQ7cjs.c.call(void 0, this,"_unwrappedBindGroupLayouts",new ye(r=>r.unwrap(this)));_chunk47YH5LQ7cjs.c.call(void 0, this,"_unwrappedBindGroups",new ye(r=>r.unwrap(this)));_chunk47YH5LQ7cjs.c.call(void 0, this,"_commandEncoder",null);this["~unstable"]={nameRegistry:this.nameRegistry,commandEncoder:this.commandEncoder,createTexture:this.createTexture.bind(this),with:this.with.bind(this),withCompute:this.withCompute.bind(this),withVertex:this.withVertex.bind(this),flush:this.flush.bind(this)}}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=ar(this,r,n);return this._disposables.push(a),a}createBindGroup(r,n){return new H(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=fr(r,this);return this._disposables.push(n),n}unwrap(r){if(Sr(r))return r.rawPipeline;if(Ee(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(xr(r))return this._unwrappedBindGroups.getOrMake(r);if(re(r))return r.buffer;if(j(r)||at(r)||ot(r))return r.unwrap();throw new Error(`Unknown resource type: ${r}`)}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}};async function _r(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 Pe(await o.requestDevice(r),n==="random"?new M:new N,a,!0)}function Ir(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new Pe(t,r==="random"?new M:new N,n,!1)}function Ve(e){return new St(e)}var St=class{constructor(t=void 0){this.defaultValue=t;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","slot");_chunk47YH5LQ7cjs.c.call(void 0, this,"label")}$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=_chunk47YH5LQ7cjs.k.call(void 0, );if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return t.unwrap(this)}};function Er(e,t){return new Dt(e,t)}var Dt=class{constructor(t,r=void 0){this.schema=t;this.defaultValue=r;_chunk47YH5LQ7cjs.c.call(void 0, this,"resourceType","accessor");_chunk47YH5LQ7cjs.c.call(void 0, this,"label");_chunk47YH5LQ7cjs.c.call(void 0, this,"slot");this.slot=Ve(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(!_chunk47YH5LQ7cjs.k.call(void 0, ))throw new Error("Cannot access tgpu.accessor's value outside of resolution.");return this}"~resolve"(t){let r=t.unwrap(this.slot);return ur(r)?t.resolve(r):Ke(r)?`${t.resolve(r)}()`:t.resolveValue(r,this.schema)}};function Lr(e){return un(e)}function un(e){return{resourceType:"derived","~compute":e,get value(){let r=_chunk47YH5LQ7cjs.k.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return r.unwrap(this)},with(r,n){return Br(e,this,[r,n])},toString(){return"derived"}}}function Br(e,t,r){return{resourceType:"derived","~compute"(){let a=_chunk47YH5LQ7cjs.k.call(void 0, );if(!a)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return a.withSlots([r],()=>a.unwrap(t))},get value(){let a=_chunk47YH5LQ7cjs.k.call(void 0, );if(!a)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return a.unwrap(this)},with(a,o){return Br(e,this,[a,o])},toString(){var s;let[a,o]=r;return`derived[${(s=a.label)!=null?s:"<unnamed>"}=${o}]`}}}function Pr(e,t){return new Ce("private",e,t)}function Vr(e){return new Ce("workgroup",e)}var Ce=class{constructor(t,r,n){this.scope=t;this._dataType=r;this._initialValue=n;_chunk47YH5LQ7cjs.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(!_chunk47YH5LQ7cjs.l.call(void 0, ))throw new Error("Cannot access tgpu.var's value directly in JS.");return this}};var Cr={bindGroupLayout:Ie,init:_r,initFromDevice:Ir,resolve:hr,"~unstable":{fn:Ht,fragmentFn:Qt,vertexFn:Zt,computeFn:Yt,vertexLayout:Fr,derived:Lr,slot:Ve,accessor:Er,privateVar:Pr,workgroupVar:Vr,const:Wt,declare:zt,sampler:lr,comparisonSampler:dr}},Es= exports.default =Cr;Object.assign(Cr,{__assignAst:Jt});exports.MissingBindGroupError = _chunk47YH5LQ7cjs.i; exports.MissingLinksError = _chunk47YH5LQ7cjs.h; exports.MissingSlotValueError = _chunk47YH5LQ7cjs.f; exports.NotUniformError = _chunk47YH5LQ7cjs.g; exports.RandomNameRegistry = M; exports.ResolutionError = _chunk47YH5LQ7cjs.e; exports.StrictNameRegistry = N; exports.default = Es; exports.isBuffer = re; exports.isComparisonSampler = rn; exports.isDerived = Z; exports.isSampledTextureView = ot; exports.isSampler = tn; exports.isSlot = Q; exports.isStorageTextureView = at; exports.isTexture = j; exports.isTgpuFn = Ke; exports.isUsableAsRender = nn; exports.isUsableAsSampled = st; exports.isUsableAsStorage = Y; exports.isUsableAsUniform = me; exports.isUsableAsVertex = Xr; exports.tgpu = Cr; exports.unstable_asMutable = Qr; exports.unstable_asReadonly = Zr; exports.unstable_asUniform = en;
15
15
  //# sourceMappingURL=index.cjs.map