typegpu 0.3.0-alpha.4 → 0.3.0-alpha.6

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