typegpu 0.3.0-alpha.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,17 +1,15 @@
1
- import{A as S,B as F,C as u,E as I,Ea as R,F as nt,Fa as X,G as Y,H,Ha as b,I as we,J as at,K as De,L as Se,M as f,Ma as it,N as ot,Na as st,O as _,P as v,Sa as ut,Ta as pt,Ua as lt,a as L,b as E,c as s,d as G,e as Qe,f as Ze,q as be,r as W,s as J,t as O,u as et,v as re,w as ne,x as tt,y as rt,z as he}from"./chunk-U7YXBTRR.js";var V=class{constructor(){s(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++}`}},k=class{constructor(){s(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 dt(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var kt=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function Mt(e){return kt.includes(e.type)}function $t(e,[t,r]){return` ${st(r)}${t}: ${e.resolve(r)},
2
- `}function Wt(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
1
+ import{A as S,B as _,C as u,E as I,Ea as L,F as rt,Fa as X,G as Y,H,Ha as h,I as we,J as nt,K as Ue,L as De,M as y,Ma as ot,N as at,Na as it,O as v,P as B,Sa as st,Ta as ut,Ua as pt,a as R,b as G,c as s,d as E,e as Xe,f as Qe,q as be,r as W,s as J,t as O,u as Ze,v as re,w as ne,x as et,y as tt,z as he}from"./chunk-PN2EAL4B.js";var C=class{constructor(){s(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++}`}},V=class{constructor(){s(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 lt(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var $t=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"];function Mt(e){return $t.includes(e.type)}function Wt(e,[t,r]){return` ${it(r)}${t}: ${e.resolve(r)},
2
+ `}function Ot(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
- ${Object.entries(t.propTypes).map(n=>$t(e,n)).join("")}}
5
- `),r}function Ot(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Ue(e,t){if(Mt(t))return t.type;if(t.type==="struct")return Wt(e,t);if(t.type==="array")return Ot(e,t);if(t.type==="atomic")return`atomic<${Ue(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);dt(t,"resolveData")}function N(e){return(e==null?void 0:e.resourceType)==="slot"}function ae(e){return(e==null?void 0:e.resourceType)==="derived"}function*mt(e){let t=0;for(;;)e.has(t)||(yield t),t++}var D=Symbol("Unknown data type");function Fe(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"resolve"in e}function Q(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||Fe(e)||N(e)||ae(e)}function Tt(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function h(e,t){return Q(t.value)||G(t.value)?e.resolve(t.value):String(t.value)}function Nt(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function gt(e,t){return t?{value:"true",dataType:he}:{value:"false",dataType:he}}function yt(e,t){return`${e.indent()}{
6
- ${t.block.map(r=>ve(e,r)).join(`
4
+ ${Object.entries(t.propTypes).map(n=>Wt(e,n)).join("")}}
5
+ `),r}function Nt(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Se(e,t){if(Mt(t))return t.type;if(t.type==="struct")return Ot(e,t);if(t.type==="array")return Nt(e,t);if(t.type==="atomic")return`atomic<${Se(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);lt(t,"resolveData")}function N(e){return(e==null?void 0:e.resourceType)==="slot"}function ae(e){return(e==null?void 0:e.resourceType)==="derived"}function dt(e){return(e==null?void 0:e.resourceType)==="accessor"}function*mt(e){let t=0;for(;;)e.has(t)||(yield t),t++}var w=Symbol("Unknown data type");function Fe(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"resolve"in e}function Q(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||Fe(e)||N(e)||ae(e)}function Tt(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}var jt=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"];function x(e,t){return Q(t.value)||E(t.value)?e.resolve(t.value):String(t.value)}function zt(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function gt(e,t){return t?{value:"true",dataType:he}:{value:"false",dataType:he}}function ft(e,t){return`${e.indent()}{
6
+ ${t.b.map(r=>ve(e,r)).join(`
7
7
  `)}
8
- ${e.dedent()}}`}function _e(e,t){return e.getById(t)}function U(e,t){if(typeof t=="string")return _e(e,t);if(typeof t=="boolean")return gt(e,t);if("x2"in t){let[r,n,a]=t.x2,o=h(e,U(e,r)),i=h(e,U(e,a));return{value:`${o} ${n} ${i}`,dataType:D}}if("."in t){let[r,n]=t["."],a=U(e,r),o=h(e,U(e,n));if(typeof a.value=="string")return{value:`${a.value}.${o}`,dataType:D};if(Q(a.value))return o==="value"?{value:h(e,a),dataType:D}:{value:a.value[o],dataType:D};if(typeof a.value=="object")return{value:a.value[o],dataType:D};throw new Error(`Cannot access member ${o} of ${a.value}`)}if("[]"in t){let[r,n]=t["[]"],a=h(e,U(e,r)),o=h(e,U(e,n));return{value:`${a}[${o}]`,dataType:D}}if("num"in t)return{value:t.num,dataType:D};if("call"in t){let n=U(e,t.call).value,o=t.args.map(p=>U(e,p)).map(p=>h(e,p));return typeof n=="string"?{value:`${n}(${o.join(", ")})`,dataType:D}:{value:n(...o),dataType:D}}Nt(t)}function ve(e,t){if(typeof t=="string")return`${e.pre}${h(e,_e(e,t))};`;if(typeof t=="boolean")return`${e.pre}${h(e,gt(e,t))};`;if("return"in t)return t.return===null?`${e.pre}return;`:`${e.pre}return ${h(e,U(e,t.return))};`;if("if"in t){let r=h(e,U(e,t.if));e.indent();let n=ve(e,t.do);e.dedent(),e.indent();let a=t.else?ve(e,t.else):void 0;return e.dedent(),a?`${e.pre}if (${r})
9
- ${n}
8
+ ${e.dedent()}}`}function _e(e,t){return e.getById(t)}function D(e,t){if(typeof t=="string")return _e(e,t);if(typeof t=="boolean")return gt(e,t);if("x"in t){let[r,n,a]=t.x,o=x(e,D(e,r)),i=x(e,D(e,a));return{value:jt.includes(n)?`(${o} ${n} ${i})`:`${o} ${n} ${i}`,dataType:w}}if("u"in t){let[r,n]=t.u,a=x(e,D(e,n));return{value:`${r}${a}`,dataType:w}}if("a"in t){let[r,n]=t.a,a=D(e,r),o=x(e,D(e,n));if(typeof a.value=="string")return{value:`${a.value}.${o}`,dataType:w};if(Q(a.value))return o==="value"?{value:x(e,a),dataType:w}:{value:a.value[o],dataType:w};if(typeof a.value=="object")return{value:a.value[o],dataType:w};throw new Error(`Cannot access member ${o} of ${a.value}`)}if("i"in t){let[r,n]=t.i,a=x(e,D(e,r)),o=x(e,D(e,n));return{value:`${a}[${o}]`,dataType:w}}if("n"in t)return{value:t.n,dataType:w};if("f"in t){let[r,n]=t.f,o=D(e,r).value,p=n.map(l=>D(e,l)).map(l=>x(e,l));return typeof o=="string"?{value:`${o}(${p.join(", ")})`,dataType:w}:{value:o(...p),dataType:w}}zt(t)}function ve(e,t){if(typeof t=="string")return`${e.pre}${x(e,_e(e,t))};`;if(typeof t=="boolean")return`${e.pre}${x(e,gt(e,t))};`;if("r"in t)return t.r===null?`${e.pre}return;`:`${e.pre}return ${x(e,D(e,t.r))};`;if("q"in t){let[r,n,a]=t.q,o=x(e,D(e,r));e.indent();let i=ve(e,n);e.dedent(),e.indent();let p=a?ve(e,a):void 0;return e.dedent(),p?`${e.pre}if (${o})
9
+ ${i}
10
10
  ${e.pre}else
11
- ${a}`:`${e.pre}if (${r})
12
- ${n}`}if("let"in t||"const"in t){let r=h(e,_e(e,"let"in t?t.let:t.const)),n=t.eq?U(e,t.eq):void 0;if(!n)throw new Error("Cannot create variable without an initial value.");return`${e.pre}var ${r} = ${h(e,n)};`}return"block"in t?yt(e,t):`${e.pre}${h(e,U(e,t))};`}function Be(e,t){return yt(e,t)}import{BufferReader as Ae,BufferWriter as Le}from"typed-binary";function jt(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=jt;var w={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=R(t);y(e,n);for(let[a,o]of Object.entries(t.propTypes))y(e,R(o)),j(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=R(t);y(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)y(e,n),j(e,t.elementType,r[o]);e.seekTo(a+b(t))},atomic(e,t,r){var n;(n=w[t.inner.type])==null||n.call(w,e,t,r)},decorated(e,t,r){var o,i;let n=X(t);y(e,n);let a=e.currentByteOffset;(i=w[(o=t.inner)==null?void 0:o.type])==null||i.call(w,e,t.inner,r),e.seekTo(a+b(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)},"loose-array"(e,t,r){var o,i;let n=R(t);y(e,n);let a=e.currentByteOffset;for(let p=0;p<Math.min(t.elementCount,r.length);p++)y(e,n),(i=w[(o=t.elementType)==null?void 0:o.type])==null||i.call(w,e,t.elementType,r[p]);e.seekTo(a+b(t))},"loose-struct"(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=w[o.type])==null||n.call(w,e,o,r[a])},"loose-decorated"(e,t,r){var i;let n=X(t);y(e,n);let a=e.currentByteOffset,o=w[(i=t.inner)==null?void 0:i.type];return o==null||o(e,t.inner,r),e.seekTo(a+b(t)),r}};function j(e,t,r){let n=w[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var M={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 I(e.readFloat32(),e.readFloat32())},vec3f(e){return we(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return f(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return nt(e.readFloat16(),e.readFloat16())},vec3h(e){return at(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return ot(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return Y(e.readInt32(),e.readInt32())},vec3i(e){return De(e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return H(e.readUint32(),e.readUint32())},vec3u(e){return Se(e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return v(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return ut(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return pt(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return lt(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=R(t);y(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))y(e,R(o)),n[a]=B(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=R(t),n=[];for(let a=0;a<t.elementCount;a++){y(e,r);let o=t.elementType,i=B(e,o);n.push(i)}return y(e,r),n},atomic(e,t){return B(e,t.inner)},decorated(e,t){let r=X(t);y(e,r);let n=e.currentByteOffset,a=B(e,t.inner);return e.seekTo(n+b(t)),a},uint8:e=>e.readUint8(),uint8x2:e=>H(e.readUint8(),e.readUint8()),uint8x4:e=>v(e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>Y(e.readInt8(),e.readInt8()),sint8x4:e=>_(e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>I(e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>f(e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>I((e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>f((e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>H(e.readUint16(),e.readUint16()),uint16x4:e=>v(e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>Y(e.readInt16(),e.readInt16()),sint16x4:e=>_(e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>I(e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>f(e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>I(M.snorm16(e),M.snorm16(e)),snorm16x4:e=>f(M.snorm16(e),M.snorm16(e),M.snorm16(e),M.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>I(e.readFloat16(),e.readFloat16()),float16x4:e=>f(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>I(e.readFloat32(),e.readFloat32()),float32x3:e=>we(e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>f(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>H(e.readUint32(),e.readUint32()),uint32x3:e=>Se(e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>v(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>Y(e.readInt32(),e.readInt32()),sint32x3:e=>De(e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_(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 f(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 f(n,r,t,a)},"loose-struct"(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=B(e,a);return r},"loose-array"(e,t){let r=R(t),n=[];for(let a=0;a<t.elementCount;a++)y(e,r),n.push(B(e,t.elementType));return y(e,r),n},"loose-decorated"(e,t){y(e,X(t));let r=e.currentByteOffset,n=B(e,t.inner);return e.seekTo(r+b(t)),n}};function B(e,t){let r=M[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function ft(e,t,r){return G(t)?new oe(e,t,r):new oe(e,t,r,["storage","uniform"])}function z(e){return e.resourceType==="buffer"}function Re(e){return!!e.usableAsUniform}function zt(e){return!!e.usableAsVertex}var oe=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;s(this,"resourceType","buffer");s(this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);s(this,"_buffer",null);s(this,"_ownBuffer");s(this,"_destroyed",!1);s(this,"_label");s(this,"initial");s(this,"usableAsUniform",!1);s(this,"usableAsStorage",!1);s(this,"usableAsVertex",!1);Tt(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:b(this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:(r=this.label)!=null?r:"<unnamed>"}),this.initial)){let n=new Le(this._buffer.getMappedRange());j(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){return this.flags|=t,this}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let i=r.getMappedRange();j(new Le(i),this.dataType,t);return}let a=b(this.dataType);this._group.flush();let o=new ArrayBuffer(a);j(new Le(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=b(this.dataType);this._group.commandEncoder.copyBufferToBuffer(t.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let t=this.buffer,r=this._group.device;if(t.mapState==="mapped"){let i=t.getMappedRange();return B(new Ae(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),p=B(new Ae(i),this.dataType);return t.unmap(),p}let n=r.createBuffer({size:b(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,b(this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,b(this.dataType));let o=B(new Ae(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 se(e){return!!(e!=null&&e.usableAsStorage)}var ie=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};var Kt={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"};var Z=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;s(this,"~repr");s(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=Kt[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(!rt())throw new Error("Cannot access buffer's value directly in JS.");return this}};function qt(e){return(e==null?void 0:e.resourceType)==="sampler"}function Jt(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var ue=class{constructor(t){this._membership=t;s(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}},pe=class{constructor(t){this._membership=t;s(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}};var le=class{constructor(t){this._membership=t;s(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}};var ct={r8unorm:u,r8snorm:u,r8uint:S,r8sint:F,r16uint:S,r16sint:F,r16float:u,rg8unorm:u,rg8snorm:u,rg8uint:S,rg8sint:F,r32uint:S,r32sint:F,r32float:u,rg16uint:S,rg16sint:F,rg16float:u,rgba8unorm:u,"rgba8unorm-srgb":u,rgba8snorm:u,rgba8uint:S,rgba8sint:F,bgra8unorm:u,"bgra8unorm-srgb":u,rgb9e5ufloat:u,rgb10a2uint:S,rgb10a2unorm:u,rg11b10ufloat:u,rg32uint:S,rg32sint:F,rg32float:u,rgba16uint:S,rgba16sint:F,rgba16float:u,rgba32uint:S,rgba32sint:F,rgba32float:u,stencil8:u,depth16unorm:u,depth24plus:u,"depth24plus-stencil8":u,depth32float:u,"depth32float-stencil8":u,"bc1-rgba-unorm":u,"bc1-rgba-unorm-srgb":u,"bc2-rgba-unorm":u,"bc2-rgba-unorm-srgb":u,"bc3-rgba-unorm":u,"bc3-rgba-unorm-srgb":u,"bc4-r-unorm":u,"bc4-r-snorm":u,"bc5-rg-unorm":u,"bc5-rg-snorm":u,"bc6h-rgb-ufloat":u,"bc6h-rgb-float":u,"bc7-rgba-unorm":u,"bc7-rgba-unorm-srgb":u,"etc2-rgb8unorm":u,"etc2-rgb8unorm-srgb":u,"etc2-rgb8a1unorm":u,"etc2-rgb8a1unorm-srgb":u,"etc2-rgba8unorm":u,"etc2-rgba8unorm-srgb":u,"eac-r11unorm":u,"eac-r11snorm":u,"eac-rg11unorm":u,"eac-rg11snorm":u,"astc-4x4-unorm":u,"astc-4x4-unorm-srgb":u,"astc-5x4-unorm":u,"astc-5x4-unorm-srgb":u,"astc-5x5-unorm":u,"astc-5x5-unorm-srgb":u,"astc-6x5-unorm":u,"astc-6x5-unorm-srgb":u,"astc-6x6-unorm":u,"astc-6x6-unorm-srgb":u,"astc-8x5-unorm":u,"astc-8x5-unorm-srgb":u,"astc-8x6-unorm":u,"astc-8x6-unorm-srgb":u,"astc-8x8-unorm":u,"astc-8x8-unorm-srgb":u,"astc-10x5-unorm":u,"astc-10x5-unorm-srgb":u,"astc-10x6-unorm":u,"astc-10x6-unorm-srgb":u,"astc-10x8-unorm":u,"astc-10x8-unorm-srgb":u,"astc-10x10-unorm":u,"astc-10x10-unorm-srgb":u,"astc-12x10-unorm":u,"astc-12x10-unorm-srgb":u,"astc-12x12-unorm":u,"astc-12x12-unorm-srgb":u},ee={rgba8unorm:f,rgba8snorm:f,rgba8uint:v,rgba8sint:_,rgba16uint:v,rgba16sint:_,rgba16float:f,r32uint:v,r32sint:_,r32float:f,rg32uint:v,rg32sint:_,rg32float:f,rgba32uint:v,rgba32sint:_,rgba32float:f,bgra8unorm:f},xt={f32:"float",u32:"uint",i32:"sint"},bt={float:u,"unfilterable-float":u,uint:S,sint:F,depth:u};function ht(e,t){return new Pe(e,t)}function C(e){return(e==null?void 0:e.resourceType)==="texture"}function Ie(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function Ce(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var wt={mutable:"read_write",readonly:"read",writeonly:"write"},Pe=class{constructor(t,r){this.props=t;this._branch=r;s(this,"resourceType","texture");s(this,"usableAsSampled",!1);s(this,"usableAsStorage",!1);s(this,"usableAsRender",!1);s(this,"_destroyed",!1);s(this,"_label");s(this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);s(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}_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=ee[n];return J(!!a,`Unsupported storage texture format: ${n}`),new Ee(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(!ee[r])throw new Error(`Unsupported storage texture format: ${r}`);return new Ge(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Te={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Ee=class{constructor(t,r,n){this.access=r;this._texture=n;s(this,"resourceType","texture-storage-view");s(this,"texelDataType");s(this,"dimension");s(this,"_view");s(this,"_format");var a,o,i;this.dimension=(o=(a=t==null?void 0:t.dimension)!=null?a:n.props.dimension)!=null?o:"2d",this._format=(i=t==null?void 0:t.format)!=null?i:n.props.format,this.texelDataType=ee[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_${Te[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${wt[this.access]}>;`),r}},de=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;s(this,"resourceType","texture-storage-view");s(this,"texelDataType");this.texelDataType=ee[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_${Te[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${wt[this.access]}>;`),r}},Ge=class{constructor(t,r){this._props=t;this._texture=r;s(this,"resourceType","texture-sampled-view");s(this,"channelDataType");s(this,"dimension");s(this,"_format");s(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=ct[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(L({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`},this._props))),this._view}resolve(t){var p;let r=t.names.makeUnique(this.label),n=((p=this._texture.props.sampleCount)!=null?p:1)>1,{group:a,binding:o}=t.allocateFixedEntry({texture:xt[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${Te[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}},me=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;s(this,"resourceType","texture-sampled-view");s(this,"channelDataType");this.channelDataType=bt[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_${Te[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}};function Ve(e){return!!(e!=null&&e.usableAsSampled)}function Yt(e){return!!(e!=null&&e.usableAsRender)}var ge=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function ye(e){return new Me(e)}function fe(e){return!!e&&e.resourceType==="bind-group-layout"}function St(e){return!!e&&e.resourceType==="bind-group"}var ke=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)}},Dt=["compute"],K=["compute","vertex","fragment"],Me=class{constructor(t){this.entries=t;s(this,"_label");s(this,"_index");s(this,"resourceType","bind-group-layout");s(this,"bound",{});var n,a,o,i,p;let r=0;for(let[d,l]of Object.entries(t)){if(l===null){r++;continue}let m={idx:r,key:d,layout:this};if("uniform"in l&&(this.bound[d]=new Z("uniform",l.uniform,m)),"storage"in l){let g="type"in l.storage?l.storage:l.storage(0);this.bound[d]=new Z((n=l.access)!=null?n:"readonly",g,m)}"texture"in l&&(this.bound[d]=new me(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,m)),"storageTexture"in l&&(this.bound[d]=new de(l.storageTexture,(i=l.viewDimension)!=null?i:"2d",(p=l.access)!=null?p:"writeonly",m)),"externalTexture"in l&&(this.bound[d]=new le(m)),"sampler"in l&&(l.sampler==="comparison"?this.bound[d]=new pe(m):this.bound[d]=new ue(m)),r++}}get label(){return this._label}get index(){return this._index}$name(t){return this._label=t,this}$idx(t){return this._index=t,this}unwrap(t){var n;return t.device.createBindGroupLayout({label:(n=this.label)!=null?n:"<unnamed>",entries:Object.values(this.entries).map((a,o)=>{var d,l,m,g;if(a===null)return null;let i=a.visibility,p={binding:o,visibility:0};if("uniform"in a)i=i!=null?i:K,p.buffer={type:"uniform"};else if("storage"in a)i=i!=null?i:a.access==="mutable"?Dt:K,p.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)i=i!=null?i:K,p.sampler={type:a.sampler};else if("texture"in a)i=i!=null?i:K,p.texture={sampleType:a.texture,viewDimension:(d=a.viewDimension)!=null?d:"2d",multisampled:(l=a.multisampled)!=null?l:!1};else if("storageTexture"in a){let T=(m=a.access)!=null?m:"writeonly";i=i!=null?i:T==="readonly"?K:Dt,p.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[T],viewDimension:(g=a.viewDimension)!=null?g:"2d"}}else"externalTexture"in a&&(i=i!=null?i:K,p.externalTexture={});return i!=null&&i.includes("compute")&&(p.visibility|=GPUShaderStage.COMPUTE),i!=null&&i.includes("vertex")&&(p.visibility|=GPUShaderStage.VERTEX),i!=null&&i.includes("fragment")&&(p.visibility|=GPUShaderStage.FRAGMENT),p}).filter(a=>a!==null)})}populate(t){return new $(this,t)}},$=class{constructor(t,r){this.layout=t;this.entries=r;s(this,"resourceType","bind-group");for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new ke(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],i)=>{var d;if(o===null)return null;let p=this.entries[a];if(p===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(z(p)){if(!Re(p))throw new re(p);l={buffer:t.unwrap(p)}}else l={buffer:p};return{binding:i,resource:l}}if("storage"in o){let l;if(z(p)){if(!se(p))throw new re(p);l={buffer:t.unwrap(p)}}else l={buffer:p};return{binding:i,resource:l}}if("texture"in o){let l;if(C(p)){if(!Ve(p))throw new ge(p);l=t.unwrap(p.asSampled())}else l=p;return{binding:i,resource:l}}if("storageTexture"in o){let l;if(C(p)){if(!se(p))throw new ie(p);o.access==="readonly"?l=t.unwrap(p.asReadonly()):o.access==="mutable"?l=t.unwrap(p.asMutable()):l=t.unwrap(p.asReadonly())}else l=p;return{binding:i,resource:l}}if("externalTexture"in o||"sampler"in o)return{binding:i,resource:p};throw new Error(`Malformed bind group entry: ${p} (${JSON.stringify(p)})`)}).filter(a=>a!==null)})}};var Ut="#CATCHALL#",We=class{constructor(){s(this,"_stack",[]);s(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(i=>i.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:D}: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}}}}},ce=[""," "," "," "," "," "," "," "," "],$e=ce.length-1,Oe=class{constructor(){s(this,"identLevel",0)}get pre(){var t;return(t=ce[this.identLevel])!=null?t:ce[$e].repeat(this.identLevel/$e)+ce[this.identLevel%$e]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},Ne=class{constructor(t){s(this,"_memoizedResolves",new WeakMap);s(this,"_memoizedDerived",new WeakMap);s(this,"_indentController",new Oe);s(this,"_jitTranspiler");s(this,"_itemStateStack",new We);s(this,"_declarations",[]);s(this,"bindGroupLayoutsToPlaceholderMap",new Map);s(this,"_nextFreeLayoutPlaceholderIdx",0);s(this,"fixedBindings",[]);s(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:D}}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=Be(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:Ut,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new et(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){let r=t;for(;;)if(N(r))r=this.readSlot(r);else if(ae(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let a=t["~compute"](),o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedDerived.set(t,r),a}catch(a){throw a instanceof O?a.appendToTrace(t):new O(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 i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let a=G(t)?Ue(this,t):t.resolve(this),o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedResolves.set(t,r),a}catch(a){throw a instanceof O?a.appendToTrace(t):new O(a,[t])}finally{this._itemStateStack.pop()}}resolve(t){let r=this.unwrap(t);if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return String(r);if(this._itemStateStack.itemDepth===0){let n=tt(this,()=>this._getOrInstantiate(r));return`${[...this._declarations].join(`
11
+ ${p}`:`${e.pre}if (${o})
12
+ ${i}`}if("l"in t||"c"in t){let[r,n]="l"in t?t.l:t.c,a=x(e,_e(e,r)),o=n?D(e,n):void 0;if(!o)throw new Error("Cannot create variable without an initial value.");return`${e.pre}var ${a} = ${x(e,o)};`}return"b"in t?ft(e,t):`${e.pre}${x(e,D(e,t))};`}function Be(e,t){return ft(e,t)}import{BufferReader as Ae,BufferWriter as Pe}from"typed-binary";function Kt(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 g=Kt;var U={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=L(t);g(e,n);for(let[a,o]of Object.entries(t.propTypes))g(e,L(o)),j(e,o,r[a]);g(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=L(t);g(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)g(e,n),j(e,t.elementType,r[o]);e.seekTo(a+h(t))},atomic(e,t,r){var n;(n=U[t.inner.type])==null||n.call(U,e,t,r)},decorated(e,t,r){var o,i;let n=X(t);g(e,n);let a=e.currentByteOffset;(i=U[(o=t.inner)==null?void 0:o.type])==null||i.call(U,e,t.inner,r),e.seekTo(a+h(t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){var o,i;let n=L(t);g(e,n);let a=e.currentByteOffset;for(let p=0;p<Math.min(t.elementCount,r.length);p++)g(e,n),(i=U[(o=t.elementType)==null?void 0:o.type])==null||i.call(U,e,t.elementType,r[p]);e.seekTo(a+h(t))},unstruct(e,t,r){var n;for(let[a,o]of Object.entries(t.propTypes))(n=U[o.type])==null||n.call(U,e,o,r[a])},"loose-decorated"(e,t,r){var i;let n=X(t);g(e,n);let a=e.currentByteOffset,o=U[(i=t.inner)==null?void 0:i.type];return o==null||o(e,t.inner,r),e.seekTo(a+h(t)),r}};function j(e,t,r){let n=U[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var k={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 I(e.readFloat32(),e.readFloat32())},vec3f(e){return we(e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return y(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return rt(e.readFloat16(),e.readFloat16())},vec3h(e){return nt(e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return at(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return Y(e.readInt32(),e.readInt32())},vec3i(e){return Ue(e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return v(e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return H(e.readUint32(),e.readUint32())},vec3u(e){return De(e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return B(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return st(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return ut(e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return pt(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=L(t);g(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))g(e,L(o)),n[a]=A(e,o);return g(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=L(t),n=[];for(let a=0;a<t.elementCount;a++){g(e,r);let o=t.elementType,i=A(e,o);n.push(i)}return g(e,r),n},atomic(e,t){return A(e,t.inner)},decorated(e,t){let r=X(t);g(e,r);let n=e.currentByteOffset,a=A(e,t.inner);return e.seekTo(n+h(t)),a},uint8:e=>e.readUint8(),uint8x2:e=>H(e.readUint8(),e.readUint8()),uint8x4:e=>B(e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>Y(e.readInt8(),e.readInt8()),sint8x4:e=>v(e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>I(e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>y(e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>I((e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>y((e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>H(e.readUint16(),e.readUint16()),uint16x4:e=>B(e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>Y(e.readInt16(),e.readInt16()),sint16x4:e=>v(e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>I(e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>y(e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>I(k.snorm16(e),k.snorm16(e)),snorm16x4:e=>y(k.snorm16(e),k.snorm16(e),k.snorm16(e),k.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>I(e.readFloat16(),e.readFloat16()),float16x4:e=>y(e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>I(e.readFloat32(),e.readFloat32()),float32x3:e=>we(e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>y(e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>H(e.readUint32(),e.readUint32()),uint32x3:e=>De(e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>B(e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>Y(e.readInt32(),e.readInt32()),sint32x3:e=>Ue(e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>v(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 y(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 y(n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=A(e,a);return r},disarray(e,t){let r=L(t),n=[];for(let a=0;a<t.elementCount;a++)g(e,r),n.push(A(e,t.elementType));return g(e,r),n},"loose-decorated"(e,t){g(e,X(t));let r=e.currentByteOffset,n=A(e,t.inner);return e.seekTo(r+h(t)),n}};function A(e,t){let r=k[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function yt(e,t,r){return E(t)?new oe(e,t,r):new oe(e,t,r,["storage","uniform"])}function z(e){return e.resourceType==="buffer"}function Re(e){return!!e.usableAsUniform}function qt(e){return!!e.usableAsVertex}var oe=class{constructor(t,r,n,a){this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;s(this,"resourceType","buffer");s(this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);s(this,"_buffer",null);s(this,"_ownBuffer");s(this,"_destroyed",!1);s(this,"_label");s(this,"initial");s(this,"usableAsUniform",!1);s(this,"usableAsStorage",!1);s(this,"usableAsVertex",!1);Tt(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}get label(){return this._label}get buffer(){var r;let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:h(this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:(r=this.label)!=null?r:"<unnamed>"}),this.initial)){let n=new Pe(this._buffer.getMappedRange());j(n,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return this._label=t,this._buffer&&(this._buffer.label=t),this}$usage(...t){var r;for(let n of t){if((r=this._disallowedUsages)!=null&&r.includes(n))throw new Error(`Buffer of type ${this.dataType} cannot be used as ${n}`);this.flags|=n==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=n==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=n==="vertex"?GPUBufferUsage.VERTEX:0,this.usableAsUniform=this.usableAsUniform||n==="uniform",this.usableAsStorage=this.usableAsStorage||n==="storage",this.usableAsVertex=this.usableAsVertex||n==="vertex"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}write(t){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let i=r.getMappedRange();j(new Pe(i),this.dataType,t);return}let a=h(this.dataType);this._group.flush();let o=new ArrayBuffer(a);j(new Pe(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=h(this.dataType);this._group.commandEncoder.copyBufferToBuffer(t.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let t=this.buffer,r=this._group.device;if(t.mapState==="mapped"){let i=t.getMappedRange();return A(new Ae(i),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let i=t.getMappedRange(),p=A(new Ae(i),this.dataType);return t.unmap(),p}let n=r.createBuffer({size:h(this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,h(this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,h(this.dataType));let o=A(new Ae(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 se(e){return!!(e!=null&&e.usableAsStorage)}var ie=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};var Jt={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"};var Z=class{constructor(t,r,n){this.usage=t;this.dataType=r;this._membership=n;s(this,"~repr");s(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=Jt[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(!tt())throw new Error("Cannot access buffer's value directly in JS.");return this}};function Yt(e){return(e==null?void 0:e.resourceType)==="sampler"}function Ht(e){return(e==null?void 0:e.resourceType)==="sampler-comparison"}var ue=class{constructor(t){this._membership=t;s(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>"}`}},pe=class{constructor(t){this._membership=t;s(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>"}`}};var le=class{constructor(t){this._membership=t;s(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 ct={r8unorm:u,r8snorm:u,r8uint:S,r8sint:_,r16uint:S,r16sint:_,r16float:u,rg8unorm:u,rg8snorm:u,rg8uint:S,rg8sint:_,r32uint:S,r32sint:_,r32float:u,rg16uint:S,rg16sint:_,rg16float:u,rgba8unorm:u,"rgba8unorm-srgb":u,rgba8snorm:u,rgba8uint:S,rgba8sint:_,bgra8unorm:u,"bgra8unorm-srgb":u,rgb9e5ufloat:u,rgb10a2uint:S,rgb10a2unorm:u,rg11b10ufloat:u,rg32uint:S,rg32sint:_,rg32float:u,rgba16uint:S,rgba16sint:_,rgba16float:u,rgba32uint:S,rgba32sint:_,rgba32float:u,stencil8:u,depth16unorm:u,depth24plus:u,"depth24plus-stencil8":u,depth32float:u,"depth32float-stencil8":u,"bc1-rgba-unorm":u,"bc1-rgba-unorm-srgb":u,"bc2-rgba-unorm":u,"bc2-rgba-unorm-srgb":u,"bc3-rgba-unorm":u,"bc3-rgba-unorm-srgb":u,"bc4-r-unorm":u,"bc4-r-snorm":u,"bc5-rg-unorm":u,"bc5-rg-snorm":u,"bc6h-rgb-ufloat":u,"bc6h-rgb-float":u,"bc7-rgba-unorm":u,"bc7-rgba-unorm-srgb":u,"etc2-rgb8unorm":u,"etc2-rgb8unorm-srgb":u,"etc2-rgb8a1unorm":u,"etc2-rgb8a1unorm-srgb":u,"etc2-rgba8unorm":u,"etc2-rgba8unorm-srgb":u,"eac-r11unorm":u,"eac-r11snorm":u,"eac-rg11unorm":u,"eac-rg11snorm":u,"astc-4x4-unorm":u,"astc-4x4-unorm-srgb":u,"astc-5x4-unorm":u,"astc-5x4-unorm-srgb":u,"astc-5x5-unorm":u,"astc-5x5-unorm-srgb":u,"astc-6x5-unorm":u,"astc-6x5-unorm-srgb":u,"astc-6x6-unorm":u,"astc-6x6-unorm-srgb":u,"astc-8x5-unorm":u,"astc-8x5-unorm-srgb":u,"astc-8x6-unorm":u,"astc-8x6-unorm-srgb":u,"astc-8x8-unorm":u,"astc-8x8-unorm-srgb":u,"astc-10x5-unorm":u,"astc-10x5-unorm-srgb":u,"astc-10x6-unorm":u,"astc-10x6-unorm-srgb":u,"astc-10x8-unorm":u,"astc-10x8-unorm-srgb":u,"astc-10x10-unorm":u,"astc-10x10-unorm-srgb":u,"astc-12x10-unorm":u,"astc-12x10-unorm-srgb":u,"astc-12x12-unorm":u,"astc-12x12-unorm-srgb":u},ee={rgba8unorm:y,rgba8snorm:y,rgba8uint:B,rgba8sint:v,rgba16uint:B,rgba16sint:v,rgba16float:y,r32uint:B,r32sint:v,r32float:y,rg32uint:B,rg32sint:v,rg32float:y,rgba32uint:B,rgba32sint:v,rgba32float:y,bgra8unorm:y},xt={f32:"float",u32:"uint",i32:"sint"},bt={float:u,"unfilterable-float":u,uint:S,sint:_,depth:u};function ht(e,t){return new Le(e,t)}function $(e){return(e==null?void 0:e.resourceType)==="texture"}function Ie(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function Ce(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var wt={mutable:"read_write",readonly:"read",writeonly:"write"},Le=class{constructor(t,r){this.props=t;this._branch=r;s(this,"resourceType","texture");s(this,"usableAsSampled",!1);s(this,"usableAsStorage",!1);s(this,"usableAsRender",!1);s(this,"_destroyed",!1);s(this,"_label");s(this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);s(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=ee[n];return J(!!a,`Unsupported storage texture format: ${n}`),new Ge(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(!ee[r])throw new Error(`Unsupported storage texture format: ${r}`);return new Ee(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},Te={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Ge=class{constructor(t,r,n){this.access=r;this._texture=n;s(this,"resourceType","texture-storage-view");s(this,"texelDataType");s(this,"dimension");s(this,"_view");s(this,"_format");var a,o,i;this.dimension=(o=(a=t==null?void 0:t.dimension)!=null?a:n.props.dimension)!=null?o:"2d",this._format=(i=t==null?void 0:t.format)!=null?i:n.props.format,this.texelDataType=ee[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_${Te[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${wt[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},de=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;s(this,"resourceType","texture-storage-view");s(this,"texelDataType");this.texelDataType=ee[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_${Te[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${wt[this.access]}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},Ee=class{constructor(t,r){this._props=t;this._texture=r;s(this,"resourceType","texture-sampled-view");s(this,"channelDataType");s(this,"dimension");s(this,"_format");s(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=ct[this._format]}get label(){return this._texture.label}$name(t){return this._texture.$name(t),this}unwrap(){var t;return this._view||(this._view=this._texture.unwrap().createView(R({label:`${(t=this.label)!=null?t:"<unnamed>"} - View`},this._props))),this._view}resolve(t){var p;let r=t.names.makeUnique(this.label),n=((p=this._texture.props.sampleCount)!=null?p:1)>1,{group:a,binding:o}=t.allocateFixedEntry({texture:xt[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),i=n?"texture_multisampled_2d":`texture_${Te[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}toString(){var t;return`${this.resourceType}:${(t=this.label)!=null?t:"<unnamed>"}`}},me=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;s(this,"resourceType","texture-sampled-view");s(this,"channelDataType");this.channelDataType=bt[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_${Te[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 Ut(e){return!!(e!=null&&e.usableAsSampled)}var ge=class e extends Error{constructor(t){var r;super(`Resource '${(r=t.label)!=null?r:"<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function fe(e){return new ke(e)}function ye(e){return!!e&&e.resourceType==="bind-group-layout"}function St(e){return!!e&&e.resourceType==="bind-group"}var Ve=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)}},Dt=["compute"],K=["compute","vertex","fragment"],ke=class{constructor(t){this.entries=t;s(this,"_label");s(this,"_index");s(this,"resourceType","bind-group-layout");s(this,"bound",{});var n,a,o,i,p;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 Z("uniform",l.uniform,T)),"storage"in l){let f="type"in l.storage?l.storage:l.storage(0);this.bound[d]=new Z((n=l.access)!=null?n:"readonly",f,T)}"texture"in l&&(this.bound[d]=new me(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,T)),"storageTexture"in l&&(this.bound[d]=new de(l.storageTexture,(i=l.viewDimension)!=null?i:"2d",(p=l.access)!=null?p:"writeonly",T)),"externalTexture"in l&&(this.bound[d]=new le(T)),"sampler"in l&&(l.sampler==="comparison"?this.bound[d]=new pe(T):this.bound[d]=new ue(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,f;if(a===null)return null;let i=a.visibility,p={binding:o,visibility:0};if("uniform"in a)i=i!=null?i:K,p.buffer={type:"uniform"};else if("storage"in a)i=i!=null?i:a.access==="mutable"?Dt:K,p.buffer={type:a.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in a)i=i!=null?i:K,p.sampler={type:a.sampler};else if("texture"in a)i=i!=null?i:K,p.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";i=i!=null?i:m==="readonly"?K:Dt,p.storageTexture={format:a.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[m],viewDimension:(f=a.viewDimension)!=null?f:"2d"}}else"externalTexture"in a&&(i=i!=null?i:K,p.externalTexture={});return i!=null&&i.includes("compute")&&(p.visibility|=GPUShaderStage.COMPUTE),i!=null&&i.includes("vertex")&&(p.visibility|=GPUShaderStage.VERTEX),i!=null&&i.includes("fragment")&&(p.visibility|=GPUShaderStage.FRAGMENT),p}).filter(a=>a!==null)})}populate(t){return new M(this,t)}},M=class{constructor(t,r){this.layout=t;this.entries=r;s(this,"resourceType","bind-group");for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new Ve(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],i)=>{var d;if(o===null)return null;let p=this.entries[a];if(p===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(z(p)){if(!Re(p))throw new re(p);l={buffer:t.unwrap(p)}}else l={buffer:p};return{binding:i,resource:l}}if("storage"in o){let l;if(z(p)){if(!se(p))throw new re(p);l={buffer:t.unwrap(p)}}else l={buffer:p};return{binding:i,resource:l}}if("texture"in o){let l;if($(p)){if(!Ut(p))throw new ge(p);l=t.unwrap(p.createView("sampled"))}else l=p;return{binding:i,resource:l}}if("storageTexture"in o){let l;if($(p)){if(!se(p))throw new ie(p);o.access==="readonly"?l=t.unwrap(p.createView("readonly")):o.access==="mutable"?l=t.unwrap(p.createView("mutable")):l=t.unwrap(p.createView("writeonly"))}else l=p;return{binding:i,resource:l}}if("externalTexture"in o||"sampler"in o)return{binding:i,resource:p};throw new Error(`Malformed bind group entry: ${p} (${JSON.stringify(p)})`)}).filter(a=>a!==null)})}};var Ft="#CATCHALL#",Me=class{constructor(){s(this,"_stack",[]);s(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(i=>i.value===t);if(a!==void 0)return a;let o=n.externalMap[t];return o!==void 0?{value:o,dataType:w}: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}}}}},ce=[""," "," "," "," "," "," "," "," "],$e=ce.length-1,We=class{constructor(){s(this,"identLevel",0)}get pre(){var t;return(t=ce[this.identLevel])!=null?t:ce[$e].repeat(this.identLevel/$e)+ce[this.identLevel%$e]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},Oe=class{constructor(t){s(this,"_memoizedResolves",new WeakMap);s(this,"_memoizedDerived",new WeakMap);s(this,"_indentController",new We);s(this,"_jitTranspiler");s(this,"_itemStateStack",new Me);s(this,"_declarations",[]);s(this,"bindGroupLayoutsToPlaceholderMap",new Map);s(this,"_nextFreeLayoutPlaceholderIdx",0);s(this,"fixedBindings",[]);s(this,"names");this.names=t.names,this._jitTranspiler=t.jitTranspiler}get pre(){return this._indentController.pre}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}getById(t){var r;return(r=this._itemStateStack.getResourceById(t))!=null?r:{value:t,dataType:w}}transpileFn(t){if(!this._jitTranspiler)throw new Error("Tried to execute a tgpu.fn function without providing a JIT transpiler, or transpiling at build time.");return this._jitTranspiler.transpileFn(t)}fnToWgsl(t){this._itemStateStack.pushFunctionScope(t.args,t.returnType,t.externalMap);let r=Be(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:Ft,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new Ze(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.pop()}}unwrap(t){let r=t;for(;;)if(N(r))r=this.readSlot(r);else if(ae(r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){var n;let r=(n=this._memoizedDerived.get(t))!=null?n:[];this._itemStateStack.pushItem();try{for(let i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let a=t["~compute"](),o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedDerived.set(t,r),a}catch(a){throw a instanceof O?a.appendToTrace(t):new O(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 i of r)if([...i.slotToValueMap.entries()].every(([d,l])=>d.areEqual(this._itemStateStack.readSlot(d),l)))return i.result;let a=E(t)?Se(this,t):t.resolve(this),o=new Map;for(let i of this._itemStateStack.topItem.usedSlots)o.set(i,this._itemStateStack.readSlot(i));return r.push({slotToValueMap:o,result:a}),this._memoizedResolves.set(t,r),a}catch(a){throw a instanceof O?a.appendToTrace(t):new O(a,[t])}finally{this._itemStateStack.pop()}}resolve(t){let r=this.unwrap(t);if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return String(r);if(this._itemStateStack.itemDepth===0){let n=et(this,()=>this._getOrInstantiate(r));return`${[...this._declarations].join(`
13
13
 
14
- `)}${n}`}return this._getOrInstantiate(r)}resolveValue(t,r){if(Q(t))return this.resolve(t);if(Qe(r))return`array(${t.map(n=>this.resolveValue(n,r.elementType))})`;if(Ze(r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolveValue(t[n],a))})`;throw new Error(`Value ${t} of schema ${r} is not resolvable to WGSL`)}};function q(e,t){var g;let r=new Ne(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],i=new Set([...a.keys()].map(T=>T.index).filter(T=>T!==void 0)),p=mt(i),d=r.fixedBindings.map((T,c)=>[String(c),T.layoutEntry]),l=()=>{let T=p.next().value,c=ye(Object.fromEntries(d));return o[T]=c,n=n.replaceAll(Ut,String(T)),[T,new $(c,Object.fromEntries(r.fixedBindings.map((x,A)=>[String(A),x.resource])))]},m=d.length>0?l():null;for(let[T,c]of a.entries()){let x=(g=T.index)!=null?g:p.next().value;o[x]=T,n=n.replaceAll(c,String(x))}return{code:n,bindGroupLayouts:o,catchall:m}}function Ft(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function _t(e,t){for(let[r,n]of Object.entries(t))e[r]=n,Ft(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function vt(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{let i=Fe(o)||G(o)||N(o)?e.resolve(o):String(o);return n.replaceAll(new RegExp(`(?<![\\w_])${a}(?![\\w_])`,"g"),i)},r)}function Bt(e){let{input:t,extraDependencies:r,names:n,jitTranspiler:a}=e,o={};_t(o,r!=null?r:{});let i=(Array.isArray(t)?t:[t]).filter(m=>typeof m=="string"),p=(Array.isArray(t)?t:[t]).filter(m=>typeof m!="string"),d={resolve(m){let g=i.join(`
15
-
16
- `);for(let T of p)m.resolve(T);return vt(m,o,g)}};Object.defineProperty(d,"toString",{value:()=>"<root>"});let{code:l}=q(d,{names:n==="strict"?new k:new V,jitTranspiler:a});return l}var te=class{constructor(t){this._make=t;s(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 At(e,t,r){return new je(new ze(e,t,r),{})}function Lt(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var je=class e{constructor(t,r){this._core=t;this._priors=r;s(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 i;let a=this._core.unwrap(),o=this._core.branch.commandEncoder.beginComputePass({label:(i=this._core.label)!=null?i:"<unnamed>"});o.setPipeline(a.pipeline),a.bindGroupLayouts.forEach((p,d)=>{var l;if(a.catchall&&d===a.catchall[0])o.setBindGroup(d,this._core.branch.unwrap(a.catchall[1]));else{let m=(l=this._priors.bindGroupLayoutMap)==null?void 0:l.get(p);if(m===void 0)throw new ne(p.label);o.setBindGroup(d,this._core.branch.unwrap(m))}}),o.dispatchWorkgroups(t,r,n),o.end()}$name(t){return this._core.label=t,this}},ze=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;s(this,"label");s(this,"_memo")}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let i=this.branch.device,{code:p,bindGroupLayouts:d,catchall:l}=q({resolve:m=>(m.withSlots(this._slotBindings,()=>{m.resolve(this._entryFn)}),"")},{names:this.branch.nameRegistry,jitTranspiler:this.branch.jitTranspiler});l!==null&&((r=d[l[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`)),this._memo={pipeline:i.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:i.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:d.map(m=>this.branch.unwrap(m))}),compute:{module:i.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:p})}}),bindGroupLayouts:d,catchall:l}}return this._memo}};function Ht(e){return typeof(e==null?void 0:e.format)=="string"}function Rt(e,t){var i,p;let r=[];if(W(e)){if(!Ht(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:(i=be(e))!=null?i:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[d,l]of Object.entries(e)){if(it(l))continue;let m=t[d];if(!m)throw new Error(`An attribute by the name of '${d}' was not provided to the shader.`);let g=m._layout,T=a.get(g);T||(r.push(g),T=[],n.push({arrayStride:g.stride,stepMode:g.stepMode,attributes:T}),a.set(g,T)),o=(p=be(l))!=null?p:o,T.push({format:m.format,offset:m.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}function Pt(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}function Xt(e){return typeof(e==null?void 0:e.loadOp)=="string"}function Et(e,t){if(W(e)){if(!Xt(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 Qt(e){return typeof(e==null?void 0:e.format)=="string"}function Gt(e,t){if(W(e)){if(!Qt(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 It(e){return new Ke(new qe(e),{})}var Ke=class e{constructor(t,r){this._core=t;this._priors=r;s(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(fe(t))return new e(this._core,E(L({},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(Pt(t))return new e(this._core,E(L({},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,E(L({},this._priors),{colorAttachment:t}))}draw(t,r,n,a){var m,g;let o=this._core.unwrap(),{branch:i,fragmentFn:p}=this._core.options,d=Et(p.shell.returnType,(m=this._priors.colorAttachment)!=null?m:{}).map(T=>C(T.view)?E(L({},T),{view:i.unwrap(T.view).createView()}):T),l=i.commandEncoder.beginRenderPass({label:(g=this._core.label)!=null?g:"<unnamed>",colorAttachments:d});l.setPipeline(o.pipeline),o.bindGroupLayouts.forEach((T,c)=>{var x;if(o.catchall&&c===o.catchall[0])l.setBindGroup(c,i.unwrap(o.catchall[1]));else{let A=(x=this._priors.bindGroupLayoutMap)==null?void 0:x.get(T);if(A===void 0)throw new ne(T.label);l.setBindGroup(c,i.unwrap(A))}}),this._core.usedVertexLayouts.forEach((T,c)=>{var A,P;let x=(A=this._priors.vertexLayoutMap)==null?void 0:A.get(T);if(!x)throw new Error(`Missing vertex buffer for layout '${(P=T.label)!=null?P:"<unnamed>"}'. Please provide it using pipeline.with(layout, buffer).(...)`);l.setVertexBuffer(c,i.unwrap(x))}),l.draw(t,r,n,a),l.end()}},qe=class{constructor(t){this.options=t;s(this,"label");s(this,"usedVertexLayouts");s(this,"_memo");s(this,"_vertexBufferLayouts");s(this,"_targets");let r=Rt(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=Gt(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let{branch:i,vertexFn:p,fragmentFn:d,slotBindings:l,primitiveState:m}=this.options,{code:g,bindGroupLayouts:T,catchall:c}=q({resolve:P=>(P.withSlots(l,()=>{P.resolve(p),P.resolve(d)}),"")},{names:i.nameRegistry,jitTranspiler:i.jitTranspiler});c!==null&&((r=T[c[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let x=i.device,A=x.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:g});this._memo={pipeline:x.createRenderPipeline({label:(a=this.label)!=null?a:"<unnamed>",layout:x.createPipelineLayout({label:`${(o=this.label)!=null?o:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:T.map(P=>i.unwrap(P))}),vertex:{module:A,buffers:this._vertexBufferLayouts},fragment:{module:A,targets:this._targets},primitive:m!=null?m:{}}),bindGroupLayouts:T,catchall:c}}return this._memo}};var Je=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[t,r]])}withCompute(t){return new Ye(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new He({branch:this._getRoot(),primitiveState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},Ye=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return At(this._root,this._slotBindings,this._entryFn)}},He=class{constructor(t){this._options=t}withFragment(t,r,n){return J(typeof t!="string","Just type mismatch validation"),J(typeof r!="string","Just type mismatch validation"),new Xe(E(L({},this._options),{fragmentFn:t,targets:r}))}},Xe=class e{constructor(t){this._options=t}withPrimitive(t){return new e(E(L({},this._options),{primitiveState:t}))}createPipeline(){return It(this._options)}},xe=class extends Je{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;s(this,"_disposables",[]);s(this,"_unwrappedBindGroupLayouts",new te(r=>r.unwrap(this)));s(this,"_unwrappedBindGroups",new te(r=>r.unwrap(this)));s(this,"_commandEncoder",null)}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=ft(this,r,n);return this._disposables.push(a),a}createTexture(r){let n=ht(r,this);return this._disposables.push(n),n}createBindGroup(r,n){return new $(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}unwrap(r){if(Lt(r))return r.rawPipeline;if(fe(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(St(r))return this._unwrappedBindGroups.getOrMake(r);if(z(r))return r.buffer;if(C(r)||Ie(r)||Ce(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 Ct(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 xe(await o.requestDevice(r),n==="random"?new V:new k,a,!0)}function Vt(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new xe(t,r==="random"?new V:new k,n,!1)}var Zt={Uniform:"uniform",Storage:"storage",Vertex:"vertex",bindGroupLayout:ye,init:Ct,initFromDevice:Vt,resolve:Bt},pa=Zt;export{re as NotUniformError,O as ResolutionError,pa as default,z as isBuffer,Jt as isComparisonSampler,Ce as isSampledTextureView,qt as isSampler,Ie as isStorageTextureView,C as isTexture,Yt as isUsableAsRender,Ve as isUsableAsSampled,se as isUsableAsStorage,Re as isUsableAsUniform,zt as isUsableAsVertex,Zt as tgpu};
14
+ `)}${n}`}return this._getOrInstantiate(r)}resolveValue(t,r){if(Q(t))return this.resolve(t);if(Xe(r))return`array(${t.map(n=>this.resolveValue(n,r.elementType))})`;if(Qe(r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolveValue(t[n],a))})`;throw new Error(`Value ${t} of schema ${r} is not resolvable to WGSL`)}};function q(e,t){var f;let r=new Oe(t),n=r.resolve(e),a=r.bindGroupLayoutsToPlaceholderMap,o=[],i=new Set([...a.keys()].map(m=>m.index).filter(m=>m!==void 0)),p=mt(i),d=r.fixedBindings.map((m,c)=>[String(c),m.layoutEntry]),l=()=>{let m=p.next().value,c=fe(Object.fromEntries(d));return o[m]=c,n=n.replaceAll(Ft,String(m)),[m,new M(c,Object.fromEntries(r.fixedBindings.map((b,P)=>[String(P),b.resource])))]},T=d.length>0?l():null;for(let[m,c]of a.entries()){let b=(f=m.index)!=null?f:p.next().value;o[b]=m,n=n.replaceAll(c,String(b))}return{code:n,bindGroupLayouts:o,catchall:T}}function _t(e){return!!e&&(typeof e=="object"||typeof e=="function")&&"$name"in e}function vt(e,t){for(let[r,n]of Object.entries(t))e[r]=n,_t(n)&&(!("label"in n)||n.label===void 0)&&n.$name(r)}function Bt(e,t,r){return Object.entries(t).reduce((n,[a,o])=>{let i=Fe(o)||E(o)||N(o)?e.resolve(o):String(o);return n.replaceAll(new RegExp(`(?<![\\w_])${a}(?![\\w_])`,"g"),i)},r)}function At(e){let{externals:t,template:r,names:n,unstable_jitTranspiler:a}=e,o={};vt(o,t!=null?t:{});let i={resolve(d){return Bt(d,o,r!=null?r:"")},toString:()=>"<root>"},{code:p}=q(i,{names:n==="strict"?new V:new C,jitTranspiler:a});return p}var te=class{constructor(t){this._make=t;s(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 Pt(e,t,r){return new Ne(new je(e,t,r),{})}function Rt(e){return(e==null?void 0:e.resourceType)==="compute-pipeline"}var Ne=class e{constructor(t,r){this._core=t;this._priors=r;s(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 i;let a=this._core.unwrap(),o=this._core.branch.commandEncoder.beginComputePass({label:(i=this._core.label)!=null?i:"<unnamed>"});o.setPipeline(a.pipeline),a.bindGroupLayouts.forEach((p,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(p);if(T===void 0)throw new ne(p.label);o.setBindGroup(d,this._core.branch.unwrap(T))}}),o.dispatchWorkgroups(t,r,n),o.end()}$name(t){return this._core.label=t,this}},je=class{constructor(t,r,n){this.branch=t;this._slotBindings=r;this._entryFn=n;s(this,"label");s(this,"_memo")}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let i=this.branch.device,{code:p,bindGroupLayouts:d,catchall:l}=q({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:i.createComputePipeline({label:(n=this.label)!=null?n:"<unnamed>",layout:i.createPipelineLayout({label:`${(a=this.label)!=null?a:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:d.map(T=>this.branch.unwrap(T))}),compute:{module:i.createShaderModule({label:`${(o=this.label)!=null?o:"<unnamed>"} - Shader`,code:p})}}),bindGroupLayouts:d,catchall:l}}return this._memo}};function Xt(e){return typeof(e==null?void 0:e.format)=="string"}function Lt(e,t){var i,p;let r=[];if(W(e)){if(!Xt(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:(i=be(e))!=null?i:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[d,l]of Object.entries(e)){if(ot(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 f=T._layout,m=a.get(f);m||(r.push(f),m=[],n.push({arrayStride:f.stride,stepMode:f.stepMode,attributes:m}),a.set(f,m)),o=(p=be(l))!=null?p:o,m.push({format:T.format,offset:T.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}function Gt(e){return(e==null?void 0:e.resourceType)==="vertex-layout"}function Qt(e){return typeof(e==null?void 0:e.loadOp)=="string"}function Et(e,t){if(W(e)){if(!Qt(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 Zt(e){return typeof(e==null?void 0:e.format)=="string"}function It(e,t){if(W(e)){if(!Zt(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 Ct(e){return new ze(new Ke(e),{})}var ze=class e{constructor(t,r){this._core=t;this._priors=r;s(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(ye(t))return new e(this._core,G(R({},this._priors),{bindGroupLayoutMap:new Map([...(n=this._priors.bindGroupLayoutMap)!=null?n:[],[t,r]])}));if(Gt(t))return new e(this._core,G(R({},this._priors),{vertexLayoutMap:new Map([...(a=this._priors.vertexLayoutMap)!=null?a:[],[t,r]])}));throw new Error("Unsupported value passed into .with()")}withColorAttachment(t){return new e(this._core,G(R({},this._priors),{colorAttachment:t}))}draw(t,r,n,a){var T,f;let o=this._core.unwrap(),{branch:i,fragmentFn:p}=this._core.options,d=Et(p.shell.returnType,(T=this._priors.colorAttachment)!=null?T:{}).map(m=>$(m.view)?G(R({},m),{view:i.unwrap(m.view).createView()}):m),l=i.commandEncoder.beginRenderPass({label:(f=this._core.label)!=null?f:"<unnamed>",colorAttachments:d});l.setPipeline(o.pipeline),o.bindGroupLayouts.forEach((m,c)=>{var b;if(o.catchall&&c===o.catchall[0])l.setBindGroup(c,i.unwrap(o.catchall[1]));else{let P=(b=this._priors.bindGroupLayoutMap)==null?void 0:b.get(m);if(P===void 0)throw new ne(m.label);l.setBindGroup(c,i.unwrap(P))}}),this._core.usedVertexLayouts.forEach((m,c)=>{var P,F;let b=(P=this._priors.vertexLayoutMap)==null?void 0:P.get(m);if(!b)throw new Error(`Missing vertex buffer for layout '${(F=m.label)!=null?F:"<unnamed>"}'. Please provide it using pipeline.with(layout, buffer).(...)`);l.setVertexBuffer(c,i.unwrap(b))}),l.draw(t,r,n,a),l.end()}},Ke=class{constructor(t){this.options=t;s(this,"label");s(this,"usedVertexLayouts");s(this,"_memo");s(this,"_vertexBufferLayouts");s(this,"_targets");let r=Lt(t.vertexFn.shell.argTypes[0],t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=It(t.fragmentFn.shell.returnType,t.targets)}unwrap(){var t,r,n,a,o;if(this._memo===void 0){let{branch:i,vertexFn:p,fragmentFn:d,slotBindings:l,primitiveState:T}=this.options,{code:f,bindGroupLayouts:m,catchall:c}=q({resolve:F=>(F.withSlots(l,()=>{F.resolve(p),F.resolve(d)}),""),toString:()=>{var F;return`renderPipeline:${(F=this.label)!=null?F:"<unnamed>"}`}},{names:i.nameRegistry,jitTranspiler:i.jitTranspiler});c!==null&&((r=m[c[0]])==null||r.$name(`${(t=this.label)!=null?t:"<unnamed>"} - Automatic Bind Group & Layout`));let b=i.device,P=b.createShaderModule({label:`${(n=this.label)!=null?n:"<unnamed>"} - Shader`,code:f});this._memo={pipeline:b.createRenderPipeline({label:(a=this.label)!=null?a:"<unnamed>",layout:b.createPipelineLayout({label:`${(o=this.label)!=null?o:"<unnamed>"} - Pipeline Layout`,bindGroupLayouts:m.map(F=>i.unwrap(F))}),vertex:{module:P,buffers:this._vertexBufferLayouts},fragment:{module:P,targets:this._targets},primitive:T!=null?T:{}}),bindGroupLayouts:m,catchall:c}}return this._memo}};var qe=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[dt(t)?t.slot:t,r]])}withCompute(t){return new Je(this._getRoot(),this._slotBindings,t)}withVertex(t,r){return new Ye({branch:this._getRoot(),primitiveState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r})}},Je=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Pt(this._root,this._slotBindings,this._entryFn)}},Ye=class{constructor(t){this._options=t}withFragment(t,r,n){return J(typeof t!="string","Just type mismatch validation"),J(typeof r!="string","Just type mismatch validation"),new He(G(R({},this._options),{fragmentFn:t,targets:r}))}},He=class e{constructor(t){this._options=t}withPrimitive(t){return new e(G(R({},this._options),{primitiveState:t}))}createPipeline(){return Ct(this._options)}},xe=class extends qe{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;s(this,"_disposables",[]);s(this,"_unwrappedBindGroupLayouts",new te(r=>r.unwrap(this)));s(this,"_unwrappedBindGroups",new te(r=>r.unwrap(this)));s(this,"_commandEncoder",null)}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}createBuffer(r,n){let a=yt(this,r,n);return this._disposables.push(a),a}createTexture(r){let n=ht(r,this);return this._disposables.push(n),n}createBindGroup(r,n){return new M(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}unwrap(r){if(Rt(r))return r.rawPipeline;if(ye(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(St(r))return this._unwrappedBindGroups.getOrMake(r);if(z(r))return r.buffer;if($(r)||Ie(r)||Ce(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 Vt(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 xe(await o.requestDevice(r),n==="random"?new C:new V,a,!0)}function kt(e){let{device:t,unstable_names:r="random",unstable_jitTranspiler:n}=e!=null?e:{};return new xe(t,r==="random"?new C:new V,n,!1)}var er={Uniform:"uniform",Storage:"storage",Vertex:"vertex",bindGroupLayout:fe,init:Vt,initFromDevice:kt,resolve:At},da=er;export{re as NotUniformError,O as ResolutionError,da as default,z as isBuffer,Ht as isComparisonSampler,Ce as isSampledTextureView,Yt as isSampler,Ie as isStorageTextureView,se as isUsableAsStorage,Re as isUsableAsUniform,qt as isUsableAsVertex,er as tgpu};
17
15
  //# sourceMappingURL=index.js.map