typegpu 0.3.0-alpha.2 → 0.3.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
package/index.cjs CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkCKSBATTPcjs = require('./chunk-CKSBATTP.cjs');var V=class{constructor(){_chunkCKSBATTPcjs.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(){_chunkCKSBATTPcjs.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` ${_chunkCKSBATTPcjs.va.call(void 0, r)}${t}: ${e.resolve(r)},
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
2
  `}function Vt(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
4
  ${Object.entries(t.propTypes).map(n=>Ct(e,n)).join("")}}
5
5
  `),r}function kt(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function De(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<${De(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);ot(t,"resolveData")}var Se="Invariant failed";function Z(e,t){if(e)return;throw new Error(Se)}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
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)}},ne=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)||_chunkCKSBATTPcjs.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:_chunkCKSBATTPcjs.u}:{value:"false",dataType:_chunkCKSBATTPcjs.u}}function dt(e,t){return`${e.indent()}{
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)}},ne=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
8
  ${t.block.map(r=>ve(e,r)).join(`
9
9
  `)}
10
10
  ${e.dedent()}}`}function Ue(e,t){return e.getById(t)}function U(e,t){if(typeof t=="string")return Ue(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 ve(e,t){if(typeof t=="string")return`${e.pre}${x(e,Ue(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=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
11
  ${n}
12
12
  ${e.pre}else
13
13
  ${a}`:`${e.pre}if (${r})
14
- ${n}`}if("let"in t||"const"in t){let r=x(e,Ue(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 Be(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 q(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=_chunkCKSBATTPcjs.ma.call(void 0, t);T(e,n);for(let[a,o]of Object.entries(t.propTypes))T(e,_chunkCKSBATTPcjs.ma.call(void 0, o)),K(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=_chunkCKSBATTPcjs.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),K(e,t.elementType,r[o]);e.seekTo(a+_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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+_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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+_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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+_chunkCKSBATTPcjs.pa.call(void 0, t)),r}};function K(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 _chunkCKSBATTPcjs.z.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunkCKSBATTPcjs.C.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunkCKSBATTPcjs.F.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2i(e){return _chunkCKSBATTPcjs.A.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunkCKSBATTPcjs.D.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunkCKSBATTPcjs.G.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunkCKSBATTPcjs.B.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunkCKSBATTPcjs.E.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunkCKSBATTPcjs.H.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},mat2x2f(e){return _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.Ba.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.ma.call(void 0, t);T(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))T(e,_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.na.call(void 0, t);T(e,r);let n=e.currentByteOffset,a=_(e,t.inner);return e.seekTo(n+_chunkCKSBATTPcjs.pa.call(void 0, t)),a},uint8x2:e=>_chunkCKSBATTPcjs.B.call(void 0, e.readByte(),e.readByte()),uint8x4:e=>_chunkCKSBATTPcjs.H.call(void 0, e.readByte(),e.readByte(),e.readByte(),e.readByte()),sint8x2:e=>_chunkCKSBATTPcjs.A.call(void 0, q(e),q(e)),sint8x4:e=>_chunkCKSBATTPcjs.G.call(void 0, q(e),q(e),q(e),q(e)),unorm8x2:e=>_chunkCKSBATTPcjs.z.call(void 0, e.readByte()/255,e.readByte()/255),unorm8x4:e=>_chunkCKSBATTPcjs.F.call(void 0, e.readByte()/255,e.readByte()/255,e.readByte()/255,e.readByte()/255),snorm8x2:e=>_chunkCKSBATTPcjs.z.call(void 0, (e.readByte()-128)/127,(e.readByte()-128)/127),snorm8x4:e=>_chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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=>_chunkCKSBATTPcjs.z.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunkCKSBATTPcjs.F.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunkCKSBATTPcjs.z.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunkCKSBATTPcjs.C.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunkCKSBATTPcjs.F.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunkCKSBATTPcjs.B.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunkCKSBATTPcjs.E.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunkCKSBATTPcjs.H.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunkCKSBATTPcjs.A.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunkCKSBATTPcjs.D.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunkCKSBATTPcjs.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 _chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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,_chunkCKSBATTPcjs.na.call(void 0, t));let r=e.currentByteOffset,n=_(e,t.inner);return e.seekTo(r+_chunkCKSBATTPcjs.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 Ae(e,t,r)}function G(e){return e.resourceType==="buffer"}function Ee(e){return!!e.usableAsUniform}function Wt(e){return!!e.usableAsVertex}var Ae=class{constructor(t,r,n){this._group=t;this.dataType=r;this.initialOrBuffer=n;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","buffer");_chunkCKSBATTPcjs.c.call(void 0, this,"flags",GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC);_chunkCKSBATTPcjs.c.call(void 0, this,"_device",null);_chunkCKSBATTPcjs.c.call(void 0, this,"_buffer",null);_chunkCKSBATTPcjs.c.call(void 0, this,"_destroyed",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"_label");_chunkCKSBATTPcjs.c.call(void 0, this,"initial");_chunkCKSBATTPcjs.c.call(void 0, this,"usableAsUniform",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkCKSBATTPcjs.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:_chunkCKSBATTPcjs.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());K(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.");K(new (0, _typedbinary.BufferWriter)(o),this.dataType,t);return}let a=_chunkCKSBATTPcjs.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);K(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:_chunkCKSBATTPcjs.pa.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(t,0,n,0,_chunkCKSBATTPcjs.pa.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkCKSBATTPcjs.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 oe(e){return!!(e!=null&&e.usableAsStorage)}var ae=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;_chunkCKSBATTPcjs.c.call(void 0, this,"~repr");_chunkCKSBATTPcjs.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(!_chunkCKSBATTPcjs.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 ie=class{constructor(t){this._membership=t;_chunkCKSBATTPcjs.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}},se=class{constructor(t){this._membership=t;_chunkCKSBATTPcjs.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 ue=class{constructor(t){this._membership=t;_chunkCKSBATTPcjs.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:_chunkCKSBATTPcjs.x,r8snorm:_chunkCKSBATTPcjs.x,r8uint:_chunkCKSBATTPcjs.v,r8sint:_chunkCKSBATTPcjs.w,r16uint:_chunkCKSBATTPcjs.v,r16sint:_chunkCKSBATTPcjs.w,r16float:_chunkCKSBATTPcjs.x,rg8unorm:_chunkCKSBATTPcjs.x,rg8snorm:_chunkCKSBATTPcjs.x,rg8uint:_chunkCKSBATTPcjs.v,rg8sint:_chunkCKSBATTPcjs.w,r32uint:_chunkCKSBATTPcjs.v,r32sint:_chunkCKSBATTPcjs.w,r32float:_chunkCKSBATTPcjs.x,rg16uint:_chunkCKSBATTPcjs.v,rg16sint:_chunkCKSBATTPcjs.w,rg16float:_chunkCKSBATTPcjs.x,rgba8unorm:_chunkCKSBATTPcjs.x,"rgba8unorm-srgb":_chunkCKSBATTPcjs.x,rgba8snorm:_chunkCKSBATTPcjs.x,rgba8uint:_chunkCKSBATTPcjs.v,rgba8sint:_chunkCKSBATTPcjs.w,bgra8unorm:_chunkCKSBATTPcjs.x,"bgra8unorm-srgb":_chunkCKSBATTPcjs.x,rgb9e5ufloat:_chunkCKSBATTPcjs.x,rgb10a2uint:_chunkCKSBATTPcjs.v,rgb10a2unorm:_chunkCKSBATTPcjs.x,rg11b10ufloat:_chunkCKSBATTPcjs.x,rg32uint:_chunkCKSBATTPcjs.v,rg32sint:_chunkCKSBATTPcjs.w,rg32float:_chunkCKSBATTPcjs.x,rgba16uint:_chunkCKSBATTPcjs.v,rgba16sint:_chunkCKSBATTPcjs.w,rgba16float:_chunkCKSBATTPcjs.x,rgba32uint:_chunkCKSBATTPcjs.v,rgba32sint:_chunkCKSBATTPcjs.w,rgba32float:_chunkCKSBATTPcjs.x,stencil8:_chunkCKSBATTPcjs.x,depth16unorm:_chunkCKSBATTPcjs.x,depth24plus:_chunkCKSBATTPcjs.x,"depth24plus-stencil8":_chunkCKSBATTPcjs.x,depth32float:_chunkCKSBATTPcjs.x,"depth32float-stencil8":_chunkCKSBATTPcjs.x,"bc1-rgba-unorm":_chunkCKSBATTPcjs.x,"bc1-rgba-unorm-srgb":_chunkCKSBATTPcjs.x,"bc2-rgba-unorm":_chunkCKSBATTPcjs.x,"bc2-rgba-unorm-srgb":_chunkCKSBATTPcjs.x,"bc3-rgba-unorm":_chunkCKSBATTPcjs.x,"bc3-rgba-unorm-srgb":_chunkCKSBATTPcjs.x,"bc4-r-unorm":_chunkCKSBATTPcjs.x,"bc4-r-snorm":_chunkCKSBATTPcjs.x,"bc5-rg-unorm":_chunkCKSBATTPcjs.x,"bc5-rg-snorm":_chunkCKSBATTPcjs.x,"bc6h-rgb-ufloat":_chunkCKSBATTPcjs.x,"bc6h-rgb-float":_chunkCKSBATTPcjs.x,"bc7-rgba-unorm":_chunkCKSBATTPcjs.x,"bc7-rgba-unorm-srgb":_chunkCKSBATTPcjs.x,"etc2-rgb8unorm":_chunkCKSBATTPcjs.x,"etc2-rgb8unorm-srgb":_chunkCKSBATTPcjs.x,"etc2-rgb8a1unorm":_chunkCKSBATTPcjs.x,"etc2-rgb8a1unorm-srgb":_chunkCKSBATTPcjs.x,"etc2-rgba8unorm":_chunkCKSBATTPcjs.x,"etc2-rgba8unorm-srgb":_chunkCKSBATTPcjs.x,"eac-r11unorm":_chunkCKSBATTPcjs.x,"eac-r11snorm":_chunkCKSBATTPcjs.x,"eac-rg11unorm":_chunkCKSBATTPcjs.x,"eac-rg11snorm":_chunkCKSBATTPcjs.x,"astc-4x4-unorm":_chunkCKSBATTPcjs.x,"astc-4x4-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-5x4-unorm":_chunkCKSBATTPcjs.x,"astc-5x4-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-5x5-unorm":_chunkCKSBATTPcjs.x,"astc-5x5-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-6x5-unorm":_chunkCKSBATTPcjs.x,"astc-6x5-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-6x6-unorm":_chunkCKSBATTPcjs.x,"astc-6x6-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-8x5-unorm":_chunkCKSBATTPcjs.x,"astc-8x5-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-8x6-unorm":_chunkCKSBATTPcjs.x,"astc-8x6-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-8x8-unorm":_chunkCKSBATTPcjs.x,"astc-8x8-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-10x5-unorm":_chunkCKSBATTPcjs.x,"astc-10x5-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-10x6-unorm":_chunkCKSBATTPcjs.x,"astc-10x6-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-10x8-unorm":_chunkCKSBATTPcjs.x,"astc-10x8-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-10x10-unorm":_chunkCKSBATTPcjs.x,"astc-10x10-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-12x10-unorm":_chunkCKSBATTPcjs.x,"astc-12x10-unorm-srgb":_chunkCKSBATTPcjs.x,"astc-12x12-unorm":_chunkCKSBATTPcjs.x,"astc-12x12-unorm-srgb":_chunkCKSBATTPcjs.x},te={rgba8unorm:_chunkCKSBATTPcjs.F,rgba8snorm:_chunkCKSBATTPcjs.F,rgba8uint:_chunkCKSBATTPcjs.H,rgba8sint:_chunkCKSBATTPcjs.G,rgba16uint:_chunkCKSBATTPcjs.H,rgba16sint:_chunkCKSBATTPcjs.G,rgba16float:_chunkCKSBATTPcjs.F,r32uint:_chunkCKSBATTPcjs.H,r32sint:_chunkCKSBATTPcjs.G,r32float:_chunkCKSBATTPcjs.F,rg32uint:_chunkCKSBATTPcjs.H,rg32sint:_chunkCKSBATTPcjs.G,rg32float:_chunkCKSBATTPcjs.F,rgba32uint:_chunkCKSBATTPcjs.H,rgba32sint:_chunkCKSBATTPcjs.G,rgba32float:_chunkCKSBATTPcjs.F,bgra8unorm:_chunkCKSBATTPcjs.F},ft={f32:"float",u32:"uint",i32:"sint"},Tt={float:_chunkCKSBATTPcjs.x,"unfilterable-float":_chunkCKSBATTPcjs.x,uint:_chunkCKSBATTPcjs.v,sint:_chunkCKSBATTPcjs.w,depth:_chunkCKSBATTPcjs.x};function yt(e,t){return new Pe(e,t)}function I(e){return(e==null?void 0:e.resourceType)==="texture"}function Ge(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function Ie(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var ct={mutable:"read_write",readonly:"read",writeonly:"write"},Pe=class{constructor(t,r){this.props=t;this._branch=r;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","texture");_chunkCKSBATTPcjs.c.call(void 0, this,"usableAsSampled",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"usableAsStorage",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"usableAsRender",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"_destroyed",!1);_chunkCKSBATTPcjs.c.call(void 0, this,"_label");_chunkCKSBATTPcjs.c.call(void 0, this,"_flags",GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC);_chunkCKSBATTPcjs.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 Re(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 Le(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},de={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Re=class{constructor(t,r,n){this.access=r;this._texture=n;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkCKSBATTPcjs.c.call(void 0, this,"texelDataType");_chunkCKSBATTPcjs.c.call(void 0, this,"dimension");_chunkCKSBATTPcjs.c.call(void 0, this,"_view");_chunkCKSBATTPcjs.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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${ct[this.access]}>;`),r}},pe=class{constructor(t,r,n,a){this._format=t;this.dimension=r;this.access=n;this._membership=a;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","texture-storage-view");_chunkCKSBATTPcjs.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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${ct[this.access]}>;`),r}},Le=class{constructor(t,r){this._props=t;this._texture=r;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkCKSBATTPcjs.c.call(void 0, this,"channelDataType");_chunkCKSBATTPcjs.c.call(void 0, this,"dimension");_chunkCKSBATTPcjs.c.call(void 0, this,"_format");_chunkCKSBATTPcjs.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(_chunkCKSBATTPcjs.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_${de[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}},le=class{constructor(t,r,n,a){this.dimension=r;this._multisampled=n;this._membership=a;_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","texture-sampled-view");_chunkCKSBATTPcjs.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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}};function Ce(e){return!!(e!=null&&e.usableAsSampled)}function qt(e){return!!(e!=null&&e.usableAsRender)}var me=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 ge(e){return new ke(e)}function fe(e){return!!e&&e.resourceType==="bind-group-layout"}function bt(e){return!!e&&e.resourceType==="bind-group"}var Ve=class e extends Error{constructor(t,r){super(`Bind group '${t!=null?t:"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},xt=["compute"],J=["compute","vertex","fragment"],ke=class{constructor(t){this.entries=t;_chunkCKSBATTPcjs.c.call(void 0, this,"_label");_chunkCKSBATTPcjs.c.call(void 0, this,"_index");_chunkCKSBATTPcjs.c.call(void 0, this,"resourceType","bind-group-layout");_chunkCKSBATTPcjs.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 le(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,d)),"storageTexture"in l&&(this.bound[g]=new pe(l.storageTexture,(i=l.viewDimension)!=null?i:"2d",(p=l.access)!=null?p:"writeonly",d)),"externalTexture"in l&&(this.bound[g]=new ue(d)),"sampler"in l&&(l.sampler==="comparison"?this.bound[g]=new se(d):this.bound[g]=new ie(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 Me(this,t)}},Me=class{constructor(t,r){this.layout=t;this.entries=r;_chunkCKSBATTPcjs.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 Ve(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],i)=>{var 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(!Ee(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(!oe(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(!Ce(p))throw new me(p);l=t.unwrap(p.asSampled())}else l=p;return{binding:i,resource:l}}if("storageTexture"in o){let l;if(I(p)){if(!oe(p))throw new ae(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(){_chunkCKSBATTPcjs.c.call(void 0, this,"_stack",[]);_chunkCKSBATTPcjs.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}}}}},Te=[""," "," "," "," "," "," "," "," "],$e=Te.length-1,We=class{constructor(){_chunkCKSBATTPcjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=Te[this.identLevel])!=null?t:Te[$e].repeat(this.identLevel/$e)+Te[this.identLevel%$e]}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}},Ne=class{constructor(t){_chunkCKSBATTPcjs.c.call(void 0, this,"_memoizedResolves",new WeakMap);_chunkCKSBATTPcjs.c.call(void 0, this,"_indentController",new We);_chunkCKSBATTPcjs.c.call(void 0, this,"_jitTranspiler");_chunkCKSBATTPcjs.c.call(void 0, this,"_itemStateStack",new Oe);_chunkCKSBATTPcjs.c.call(void 0, this,"_declarations",[]);_chunkCKSBATTPcjs.c.call(void 0, this,"bindGroupLayoutsToPlaceholderMap",new Map);_chunkCKSBATTPcjs.c.call(void 0, this,"_nextFreeLayoutPlaceholderIdx",0);_chunkCKSBATTPcjs.c.call(void 0, this,"fixedBindings",[]);_chunkCKSBATTPcjs.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=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:ht,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new ne(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=_chunkCKSBATTPcjs.d.call(void 0, t)?De(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=_chunkCKSBATTPcjs.s.call(void 0, ()=>this._getOrInstantiate(t));return`${[...this._declarations].join(`
14
+ ${n}`}if("let"in t||"const"in t){let r=x(e,Ue(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 Be(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 q(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)),K(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),K(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 K(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, q(e),q(e)),sint8x4:e=>_chunkW7MD3ZVBcjs.G.call(void 0, q(e),q(e),q(e),q(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 Ae(e,t,r)}function G(e){return e.resourceType==="buffer"}function Ee(e){return!!e.usableAsUniform}function Wt(e){return!!e.usableAsVertex}var Ae=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());K(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.");K(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);K(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 oe(e){return!!(e!=null&&e.usableAsStorage)}var ae=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 ie=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}},se=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 ue=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 Pe(e,t)}function I(e){return(e==null?void 0:e.resourceType)==="texture"}function Ge(e){return(e==null?void 0:e.resourceType)==="texture-storage-view"}function Ie(e){return(e==null?void 0:e.resourceType)==="texture-sampled-view"}var ct={mutable:"read_write",readonly:"read",writeonly:"write"},Pe=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 Re(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 Le(t,this)}destroy(){var t;this._destroyed||(this._destroyed=!0,(t=this._texture)==null||t.destroy())}},de={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Re=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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${ct[this.access]}>;`),r}},pe=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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${ct[this.access]}>;`),r}},Le=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_${de[this.dimension]}`;return t.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`),r}},le=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_${de[this.dimension]}`;return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`),r}};function Ce(e){return!!(e!=null&&e.usableAsSampled)}function qt(e){return!!(e!=null&&e.usableAsRender)}var me=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 ge(e){return new ke(e)}function fe(e){return!!e&&e.resourceType==="bind-group-layout"}function bt(e){return!!e&&e.resourceType==="bind-group"}var Ve=class e extends Error{constructor(t,r){super(`Bind group '${t!=null?t:"<unnamed>"}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},xt=["compute"],J=["compute","vertex","fragment"],ke=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 le(l.texture,(a=l.viewDimension)!=null?a:"2d",(o=l.multisampled)!=null?o:!1,d)),"storageTexture"in l&&(this.bound[g]=new pe(l.storageTexture,(i=l.viewDimension)!=null?i:"2d",(p=l.access)!=null?p:"writeonly",d)),"externalTexture"in l&&(this.bound[g]=new ue(d)),"sampler"in l&&(l.sampler==="comparison"?this.bound[g]=new se(d):this.bound[g]=new ie(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 Me(this,t)}},Me=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 Ve(t.label,n)}unwrap(t){var n;return t.device.createBindGroup({label:(n=this.layout.label)!=null?n:"<unnamed>",layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([a,o],i)=>{var 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(!Ee(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(!oe(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(!Ce(p))throw new me(p);l=t.unwrap(p.asSampled())}else l=p;return{binding:i,resource:l}}if("storageTexture"in o){let l;if(I(p)){if(!oe(p))throw new ae(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}}}}},Te=[""," "," "," "," "," "," "," "," "],$e=Te.length-1,We=class{constructor(){_chunkW7MD3ZVBcjs.c.call(void 0, this,"identLevel",0)}get pre(){var t;return(t=Te[this.identLevel])!=null?t:Te[$e].repeat(this.identLevel/$e)+Te[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=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:ht,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new ne(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)?De(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(`
15
15
 
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=ge(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)||_chunkCKSBATTPcjs.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(`
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=ge(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(`
17
17
 
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 re=class{constructor(t){this._make=t;_chunkCKSBATTPcjs.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;_chunkCKSBATTPcjs.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;_chunkCKSBATTPcjs.c.call(void 0, this,"label");_chunkCKSBATTPcjs.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 Kt(e){return typeof(e==null?void 0:e.format)=="string"}function Ft(e,t){var i,p;let r=[];if(_chunkCKSBATTPcjs.r.call(void 0, e)){if(!Kt(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=_chunkCKSBATTPcjs.q.call(void 0, e))!=null?i:0}]}]}}let n=[],a=new WeakMap,o=0;for(let[g,l]of Object.entries(e)){if(_chunkCKSBATTPcjs.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=_chunkCKSBATTPcjs.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(_chunkCKSBATTPcjs.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(_chunkCKSBATTPcjs.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 qe(new Ke(e),{})}var qe=class e{constructor(t,r){this._core=t;this._priors=r;_chunkCKSBATTPcjs.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,_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.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,_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.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,_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.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)?_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.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()}},Ke=class{constructor(t){this.options=t;_chunkCKSBATTPcjs.c.call(void 0, this,"label");_chunkCKSBATTPcjs.c.call(void 0, this,"usedVertexLayouts");_chunkCKSBATTPcjs.c.call(void 0, this,"_memo");_chunkCKSBATTPcjs.c.call(void 0, this,"_vertexBufferLayouts");_chunkCKSBATTPcjs.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(_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.a.call(void 0, {},this._options),{fragmentFn:t,targets:r}))}},Xe=class e{constructor(t){this._options=t}withPrimitive(t){return new e(_chunkCKSBATTPcjs.b.call(void 0, _chunkCKSBATTPcjs.a.call(void 0, {},this._options),{primitiveState:t}))}createPipeline(){return Pt(this._options)}},ye=class extends Je{constructor(r,n,a,o){super(()=>this,[]);this.device=r;this.nameRegistry=n;this.jitTranspiler=a;this._ownDevice=o;_chunkCKSBATTPcjs.c.call(void 0, this,"_disposables",[]);_chunkCKSBATTPcjs.c.call(void 0, this,"_unwrappedBindGroupLayouts",new re(r=>r.unwrap(this)));_chunkCKSBATTPcjs.c.call(void 0, this,"_unwrappedBindGroups",new re(r=>r.unwrap(this)));_chunkCKSBATTPcjs.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}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}unwrap(r){if(Bt(r))return r.rawPipeline;if(fe(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(bt(r))return this._unwrappedBindGroups.getOrMake(r);if(G(r))return r.buffer;if(I(r)||Ge(r)||Ie(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 ye(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 ye(t,r==="random"?new V:new k,n,!1)}var Ht={Uniform:"uniform",Storage:"storage",Vertex:"vertex",bindGroupLayout:ge,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 = Ie; exports.isSampler = jt; exports.isStorageTextureView = Ge; exports.isTexture = I; exports.isUsableAsRender = qt; exports.isUsableAsSampled = Ce; exports.isUsableAsStorage = oe; exports.isUsableAsUniform = Ee; exports.isUsableAsVertex = Wt; exports.tgpu = Ht;
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 re=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 Kt(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(!Kt(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 qe(new Ke(e),{})}var qe=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(fe(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()}},Ke=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)}},ye=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 re(r=>r.unwrap(this)));_chunkW7MD3ZVBcjs.c.call(void 0, this,"_unwrappedBindGroups",new re(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}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}unwrap(r){if(Bt(r))return r.rawPipeline;if(fe(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(bt(r))return this._unwrappedBindGroups.getOrMake(r);if(G(r))return r.buffer;if(I(r)||Ge(r)||Ie(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 ye(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 ye(t,r==="random"?new V:new k,n,!1)}var Ht={Uniform:"uniform",Storage:"storage",Vertex:"vertex",bindGroupLayout:ge,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 = Ie; exports.isSampler = jt; exports.isStorageTextureView = Ge; exports.isTexture = I; exports.isUsableAsRender = qt; exports.isUsableAsSampled = Ce; exports.isUsableAsStorage = oe; exports.isUsableAsUniform = Ee; exports.isUsableAsVertex = Wt; exports.tgpu = Ht;
19
19
  //# sourceMappingURL=index.cjs.map
package/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as TgpuNamable, D as Default, F as F32, U as U32, I as I32, V as Vec4f, a as Vec4u, b as Vec4i, c as UnionToIntersection, A as AnyData, d as Infer, E as Exotic, P as Prettify, M as Mutable, O as OmitProps, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-0b50gROn.cjs';
1
+ import { T as TgpuNamable, D as Default, F as F32, U as U32, I as I32, V as Vec4f, a as Vec4u, b as Vec4i, c as UnionToIntersection, A as AnyData, d as Infer, E as Exotic, P as Prettify, M as Mutable, O as OmitProps, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-NWbtoFu5.cjs';
2
2
  import * as smol from 'tinyest';
3
3
  import { Block } from 'tinyest';
4
4
 
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as TgpuNamable, D as Default, F as F32, U as U32, I as I32, V as Vec4f, a as Vec4u, b as Vec4i, c as UnionToIntersection, A as AnyData, d as Infer, E as Exotic, P as Prettify, M as Mutable, O as OmitProps, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-0b50gROn.js';
1
+ import { T as TgpuNamable, D as Default, F as F32, U as U32, I as I32, V as Vec4f, a as Vec4u, b as Vec4i, c as UnionToIntersection, A as AnyData, d as Infer, E as Exotic, P as Prettify, M as Mutable, O as OmitProps, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-NWbtoFu5.js';
2
2
  import * as smol from 'tinyest';
3
3
  import { Block } from 'tinyest';
4
4
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{A as H,Aa as rt,B as X,Ba as nt,C as be,Ca as at,D as he,E as we,F as y,G as B,H as F,a as E,b as R,c as s,d as M,ma as P,na as Q,pa as w,q as ce,r as $,s as Qe,t as Ze,u as xe,ua as et,v as D,va as tt,w as v,x as u,z as L}from"./chunk-IQYHODCR.js";var V=class{constructor(){s(this,"lastUniqueId",0)}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},k=class{constructor(){s(this,"_usedNames",new Set)}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function 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` ${tt(r)}${t}: ${e.resolve(r)},
1
+ import{A as H,Aa as rt,B as X,Ba as nt,C as be,Ca as at,D as he,E as we,F as y,G as B,H as F,a as E,b as R,c as s,d as M,ma as P,na as Q,pa as w,q as ce,r as $,s as Qe,t as Ze,u as xe,ua as et,v as D,va as tt,w as v,x as u,z as L}from"./chunk-6N2XUXQX.js";var V=class{constructor(){s(this,"lastUniqueId",0)}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}},k=class{constructor(){s(this,"_usedNames",new Set)}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}};function 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` ${tt(r)}${t}: ${e.resolve(r)},
2
2
  `}function Vt(e,t){let r=e.names.makeUnique(t.label);return e.addDeclaration(`
3
3
  struct ${r} {
4
4
  ${Object.entries(t.propTypes).map(n=>Ct(e,n)).join("")}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typegpu",
3
3
  "private": false,
4
- "version": "0.3.0-alpha.2",
4
+ "version": "0.3.0-alpha.3",
5
5
  "description": "A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -1119,4 +1119,4 @@ type Mutable<T> = {
1119
1119
  -readonly [P in keyof T]: T[P];
1120
1120
  };
1121
1121
 
1122
- export { isLocationAttrib as $, type AnyData as A, type BaseWgslData as B, bool as C, type Default as D, type Exotic as E, type F32 as F, f32 as G, f16 as H, type I32 as I, i32 as J, u32 as K, type Location as L, type Mutable as M, isWgslData as N, type OmitProps as O, type Prettify as P, isWgslArray as Q, isWgslStruct as R, type Size as S, type TgpuNamable as T, type U32 as U, type Vec4f as V, type WgslTypeLiteral as W, isAtomic as X, isDecorated as Y, isAlignAttrib as Z, isBuiltinAttrib as _, type Vec4u as a, type PackedData as a$, isSizeAttrib as a0, type Bool as a1, type F16 as a2, type Vec2f as a3, type Vec2i as a4, type Vec2u as a5, type Vec3f as a6, type Vec3i as a7, type Vec3u as a8, type v2i as a9, unorm8x2 as aA, unorm8x4 as aB, snorm8x2 as aC, snorm8x4 as aD, uint16x2 as aE, uint16x4 as aF, sint16x2 as aG, sint16x4 as aH, unorm16x2 as aI, unorm16x4 as aJ, snorm16x2 as aK, snorm16x4 as aL, float16x2 as aM, float16x4 as aN, float32 as aO, float32x2 as aP, float32x3 as aQ, float32x4 as aR, uint32 as aS, uint32x2 as aT, uint32x3 as aU, uint32x4 as aV, sint32 as aW, sint32x2 as aX, sint32x3 as aY, sint32x4 as aZ, unorm10_10_10_2 as a_, type v2u as aa, type v3i as ab, type v3u as ac, type v4i as ad, type v4u as ae, vec2f as af, vec2i as ag, vec2u as ah, vec3f as ai, vec3i as aj, vec3u as ak, vec4f as al, vec4i as am, vec4u as an, isLooseArray as ao, isLooseStruct as ap, isLooseDecorated as aq, isData as ar, isLooseData as as, type FormatToWGSLType as at, type TgpuVertexFormatData as au, packedFormats as av, uint8x2 as aw, uint8x4 as ax, sint8x2 as ay, sint8x4 as az, type Vec4i as b, type UnionToIntersection as c, type Infer as d, type AnyWgslData as e, type Align as f, type Builtin as g, type Decorated as h, type LooseDecorated as i, type AnyLooseData as j, type LooseTypeLiteral as k, type WgslStruct as l, type ExoticRecord as m, type WgslArray as n, type LooseArray as o, type LooseStruct as p, type m2x2f as q, type m3x3f as r, type m4x4f as s, type Mat2x2f as t, type Mat3x3f as u, type v2f as v, type v3f as w, type Mat4x4f as x, type v4f as y, type Atomic as z };
1122
+ export { isBuiltinAttrib as $, type AnyData as A, type BaseWgslData as B, type Atomic as C, type Default as D, type Exotic as E, type F32 as F, bool as G, f32 as H, type I32 as I, f16 as J, i32 as K, type Location as L, type Mutable as M, u32 as N, type OmitProps as O, type Prettify as P, isWgslData as Q, isWgslArray as R, type Size as S, type TgpuNamable as T, type U32 as U, type Vec4f as V, type WgslTypeLiteral as W, isWgslStruct as X, isAtomic as Y, isDecorated as Z, isAlignAttrib as _, type Vec4u as a, type PackedData as a$, isLocationAttrib as a0, isSizeAttrib as a1, type Bool as a2, type F16 as a3, type Vec2f as a4, type Vec2i as a5, type Vec2u as a6, type Vec3f as a7, type Vec3i as a8, type v2i as a9, unorm8x2 as aA, unorm8x4 as aB, snorm8x2 as aC, snorm8x4 as aD, uint16x2 as aE, uint16x4 as aF, sint16x2 as aG, sint16x4 as aH, unorm16x2 as aI, unorm16x4 as aJ, snorm16x2 as aK, snorm16x4 as aL, float16x2 as aM, float16x4 as aN, float32 as aO, float32x2 as aP, float32x3 as aQ, float32x4 as aR, uint32 as aS, uint32x2 as aT, uint32x3 as aU, uint32x4 as aV, sint32 as aW, sint32x2 as aX, sint32x3 as aY, sint32x4 as aZ, unorm10_10_10_2 as a_, type v2u as aa, type v3i as ab, type v3u as ac, type v4i as ad, type v4u as ae, vec2f as af, vec2i as ag, vec2u as ah, vec3f as ai, vec3i as aj, vec3u as ak, vec4f as al, vec4i as am, vec4u as an, isLooseArray as ao, isLooseStruct as ap, isLooseDecorated as aq, isData as ar, isLooseData as as, type FormatToWGSLType as at, type TgpuVertexFormatData as au, packedFormats as av, uint8x2 as aw, uint8x4 as ax, sint8x2 as ay, sint8x4 as az, type Vec4i as b, type UnionToIntersection as c, type Infer as d, type AnyWgslData as e, type Align as f, type Builtin as g, type Decorated as h, type LooseDecorated as i, type AnyLooseData as j, type LooseTypeLiteral as k, type WgslArray as l, type Vec3u as m, type WgslStruct as n, type ExoticRecord as o, type LooseArray as p, type LooseStruct as q, type m2x2f as r, type m3x3f as s, type m4x4f as t, type Mat2x2f as u, type v2f as v, type Mat3x3f as w, type v3f as x, type Mat4x4f as y, type v4f as z };
@@ -1119,4 +1119,4 @@ type Mutable<T> = {
1119
1119
  -readonly [P in keyof T]: T[P];
1120
1120
  };
1121
1121
 
1122
- export { isLocationAttrib as $, type AnyData as A, type BaseWgslData as B, bool as C, type Default as D, type Exotic as E, type F32 as F, f32 as G, f16 as H, type I32 as I, i32 as J, u32 as K, type Location as L, type Mutable as M, isWgslData as N, type OmitProps as O, type Prettify as P, isWgslArray as Q, isWgslStruct as R, type Size as S, type TgpuNamable as T, type U32 as U, type Vec4f as V, type WgslTypeLiteral as W, isAtomic as X, isDecorated as Y, isAlignAttrib as Z, isBuiltinAttrib as _, type Vec4u as a, type PackedData as a$, isSizeAttrib as a0, type Bool as a1, type F16 as a2, type Vec2f as a3, type Vec2i as a4, type Vec2u as a5, type Vec3f as a6, type Vec3i as a7, type Vec3u as a8, type v2i as a9, unorm8x2 as aA, unorm8x4 as aB, snorm8x2 as aC, snorm8x4 as aD, uint16x2 as aE, uint16x4 as aF, sint16x2 as aG, sint16x4 as aH, unorm16x2 as aI, unorm16x4 as aJ, snorm16x2 as aK, snorm16x4 as aL, float16x2 as aM, float16x4 as aN, float32 as aO, float32x2 as aP, float32x3 as aQ, float32x4 as aR, uint32 as aS, uint32x2 as aT, uint32x3 as aU, uint32x4 as aV, sint32 as aW, sint32x2 as aX, sint32x3 as aY, sint32x4 as aZ, unorm10_10_10_2 as a_, type v2u as aa, type v3i as ab, type v3u as ac, type v4i as ad, type v4u as ae, vec2f as af, vec2i as ag, vec2u as ah, vec3f as ai, vec3i as aj, vec3u as ak, vec4f as al, vec4i as am, vec4u as an, isLooseArray as ao, isLooseStruct as ap, isLooseDecorated as aq, isData as ar, isLooseData as as, type FormatToWGSLType as at, type TgpuVertexFormatData as au, packedFormats as av, uint8x2 as aw, uint8x4 as ax, sint8x2 as ay, sint8x4 as az, type Vec4i as b, type UnionToIntersection as c, type Infer as d, type AnyWgslData as e, type Align as f, type Builtin as g, type Decorated as h, type LooseDecorated as i, type AnyLooseData as j, type LooseTypeLiteral as k, type WgslStruct as l, type ExoticRecord as m, type WgslArray as n, type LooseArray as o, type LooseStruct as p, type m2x2f as q, type m3x3f as r, type m4x4f as s, type Mat2x2f as t, type Mat3x3f as u, type v2f as v, type v3f as w, type Mat4x4f as x, type v4f as y, type Atomic as z };
1122
+ export { isBuiltinAttrib as $, type AnyData as A, type BaseWgslData as B, type Atomic as C, type Default as D, type Exotic as E, type F32 as F, bool as G, f32 as H, type I32 as I, f16 as J, i32 as K, type Location as L, type Mutable as M, u32 as N, type OmitProps as O, type Prettify as P, isWgslData as Q, isWgslArray as R, type Size as S, type TgpuNamable as T, type U32 as U, type Vec4f as V, type WgslTypeLiteral as W, isWgslStruct as X, isAtomic as Y, isDecorated as Z, isAlignAttrib as _, type Vec4u as a, type PackedData as a$, isLocationAttrib as a0, isSizeAttrib as a1, type Bool as a2, type F16 as a3, type Vec2f as a4, type Vec2i as a5, type Vec2u as a6, type Vec3f as a7, type Vec3i as a8, type v2i as a9, unorm8x2 as aA, unorm8x4 as aB, snorm8x2 as aC, snorm8x4 as aD, uint16x2 as aE, uint16x4 as aF, sint16x2 as aG, sint16x4 as aH, unorm16x2 as aI, unorm16x4 as aJ, snorm16x2 as aK, snorm16x4 as aL, float16x2 as aM, float16x4 as aN, float32 as aO, float32x2 as aP, float32x3 as aQ, float32x4 as aR, uint32 as aS, uint32x2 as aT, uint32x3 as aU, uint32x4 as aV, sint32 as aW, sint32x2 as aX, sint32x3 as aY, sint32x4 as aZ, unorm10_10_10_2 as a_, type v2u as aa, type v3i as ab, type v3u as ac, type v4i as ad, type v4u as ae, vec2f as af, vec2i as ag, vec2u as ah, vec3f as ai, vec3i as aj, vec3u as ak, vec4f as al, vec4i as am, vec4u as an, isLooseArray as ao, isLooseStruct as ap, isLooseDecorated as aq, isData as ar, isLooseData as as, type FormatToWGSLType as at, type TgpuVertexFormatData as au, packedFormats as av, uint8x2 as aw, uint8x4 as ax, sint8x2 as ay, sint8x4 as az, type Vec4i as b, type UnionToIntersection as c, type Infer as d, type AnyWgslData as e, type Align as f, type Builtin as g, type Decorated as h, type LooseDecorated as i, type AnyLooseData as j, type LooseTypeLiteral as k, type WgslArray as l, type Vec3u as m, type WgslStruct as n, type ExoticRecord as o, type LooseArray as p, type LooseStruct as q, type m2x2f as r, type m3x3f as s, type m4x4f as t, type Mat2x2f as u, type v2f as v, type Mat3x3f as w, type v3f as x, type Mat4x4f as y, type v4f as z };
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var Ve=Object.defineProperty,De=Object.defineProperties;var Fe=Object.getOwnPropertyDescriptors;var we=Object.getOwnPropertySymbols;var Se=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var Q=(e,r,n)=>r in e?Ve(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,lr= exports.a =(e,r)=>{for(var n in r||(r={}))Se.call(r,n)&&Q(e,n,r[n]);if(we)for(var n of we(r))Ce.call(r,n)&&Q(e,n,r[n]);return e},mr= exports.b =(e,r)=>De(e,Fe(r));var a=(e,r,n)=>(Q(e,typeof r!="symbol"?r+"":r,n),n);var _typedbinary = require('typed-binary'); var _typedbinary2 = _interopRequireDefault(_typedbinary);var X=0;function pr(e){X++;try{return e()}finally{X--}}var f=()=>X>0;var Le={type:"bool"},We=e=>f()?`u32(${e})`:typeof e=="boolean"?e?1:0:Number.isInteger(e)?((e<0||e>4294967295)&&console.warn(`u32 value ${e} overflowed`),(e&4294967295)>>>0):Math.max(0,Math.min(4294967295,Math.floor(e))),Y= exports.v =Object.assign(We,{type:"u32"}),Be=e=>{if(f())return`i32(${e})`;if(typeof e=="boolean")return e?1:0;if(Number.isInteger(e))return(e<-2147483648||e>2147483647)&&console.warn(`i32 value ${e} overflowed`),(e|0)&4294967295;let r=e<0?Math.ceil(e):Math.floor(e);return Math.max(-2147483648,Math.min(2147483647,r))},Z= exports.w =Object.assign(Be,{type:"i32"}),Ne=e=>{if(f())return`f32(${e})`;if(typeof e=="boolean")return e?1:0;let r=new Float32Array(1);return r[0]=e,r[0]},ee= exports.x =Object.assign(Ne,{type:"f32"}),Ee=e=>{if(f())return`f16(${e})`;if(typeof e=="boolean")return e?1:0;let r=new ArrayBuffer(2);return _typedbinary2.default.f16.write(new _typedbinary2.default.BufferWriter(r),e),_typedbinary2.default.f16.read(new _typedbinary2.default.BufferReader(r))},Pe= exports.y =Object.assign(Ee,{type:"f16"});var Ie=["bool","f32","f16","i32","u32","vec2f","vec2i","vec2u","vec3f","vec3i","vec3u","vec4f","vec4i","vec4u","mat2x2f","mat3x3f","mat4x4f","struct","array","atomic","decorated"];function W(e){return Ie.includes(e==null?void 0:e.type)}function B(e){return(e==null?void 0:e.type)==="array"}function N(e){return(e==null?void 0:e.type)==="struct"}function Me(e){return(e==null?void 0:e.type)==="atomic"}function E(e){return(e==null?void 0:e.type)==="@align"}function P(e){return(e==null?void 0:e.type)==="@size"}function re(e){return(e==null?void 0:e.type)==="@location"}function ne(e){return(e==null?void 0:e.type)==="@builtin"}function d(e){return(e==null?void 0:e.type)==="decorated"}var $e=e=>new te(e),te=class{constructor(r){this.propTypes=r;a(this,"_label");a(this,"type","struct");a(this,"~repr");a(this,"~exotic")}get label(){return this._label}$name(r){return this._label=r,this}};var b=(e,r)=>{let n=r-1,t=~n;return e&n?(e&t)+r:e};var ze=["uint8x2","uint8x4","sint8x2","sint8x4","unorm8x2","unorm8x4","snorm8x2","snorm8x4","uint16x2","uint16x4","sint16x2","sint16x4","unorm16x2","unorm16x4","snorm16x2","snorm16x4","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2"];var Re=["loose-struct","loose-array","loose-decorated",...ze];function K(e){return Re.includes(e==null?void 0:e.type)}function w(e){return(e==null?void 0:e.type)==="loose-array"}function z(e){return(e==null?void 0:e.type)==="loose-struct"}function c(e){return(e==null?void 0:e.type)==="loose-decorated"}function g(e){var r,n;return(n=(r=e.attribs)==null?void 0:r.find(E))==null?void 0:n.value}function ge(e){var r,n;return(n=(r=e.attribs)==null?void 0:r.find(P))==null?void 0:n.value}function hr(e){var r,n;return(n=(r=e.attribs)==null?void 0:r.find(re))==null?void 0:n.value}function Ue(e){return W(e)||K(e)}function T(e){let r={"~repr":void 0,type:e.type};return Object.assign((...t)=>{var s;let o=t;if(f())return`${r.type}(${o.join(", ")})`;if(o.length<=1)return e.makeFromScalar((s=o[0])!=null?s:0);if(o.length===e.length)return e.make(...o);throw new Error(`'${e.type}' constructor called with invalid number of arguments.`)},r)}var I=class{constructor(r,n){this.x=r;this.y=n;a(this,"length",2)}*[Symbol.iterator](){yield this.x,yield this.y}get 0(){return this.x}get 1(){return this.y}set 0(r){this.x=r}set 1(r){this.y=r}resolve(){return`${this.kind}(${this.x}, ${this.y})`}},v=class e extends I{constructor(){super(...arguments);a(this,"kind","vec2f")}make2(n,t){return new e(n,t)}make3(n,t,o){return new k(n,t,o)}make4(n,t,o,s){return new F(n,t,o,s)}},A=class e extends I{constructor(){super(...arguments);a(this,"kind","vec2i")}make2(n,t){return new e(n,t)}make3(n,t,o){return new V(n,t,o)}make4(n,t,o,s){return new S(n,t,o,s)}},h=class e extends I{constructor(){super(...arguments);a(this,"kind","vec2u")}make2(n,t){return new e(n,t)}make3(n,t,o){return new D(n,t,o)}make4(n,t,o,s){return new C(n,t,o,s)}},M=class{constructor(r,n,t){this.x=r;this.y=n;this.z=t;a(this,"length",3)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}set 0(r){this.x=r}set 1(r){this.y=r}set 2(r){this.z=r}resolve(){return`${this.kind}(${this.x}, ${this.y}, ${this.z})`}},k=class e extends M{constructor(){super(...arguments);a(this,"kind","vec3f")}make2(n,t){return new v(n,t)}make3(n,t,o){return new e(n,t,o)}make4(n,t,o,s){return new F(n,t,o,s)}},V=class e extends M{constructor(){super(...arguments);a(this,"kind","vec3i")}make2(n,t){return new A(n,t)}make3(n,t,o){return new e(n,t,o)}make4(n,t,o,s){return new S(n,t,o,s)}},D=class e extends M{constructor(){super(...arguments);a(this,"kind","vec3u")}make2(n,t){return new h(n,t)}make3(n,t,o){return new e(n,t,o)}make4(n,t,o,s){return new C(n,t,o,s)}},O=class{constructor(r,n,t,o){this.x=r;this.y=n;this.z=t;this.w=o;a(this,"length",4)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}set 0(r){this.x=r}set 1(r){this.y=r}set 2(r){this.z=r}set 3(r){this.w=r}resolve(){return`${this.kind}(${this.x}, ${this.y}, ${this.z}, ${this.w})`}},F=class e extends O{constructor(){super(...arguments);a(this,"kind","vec4f")}make2(n,t){return new v(n,t)}make3(n,t,o){return new k(n,t,o)}make4(n,t,o,s){return new e(n,t,o,s)}},S=class e extends O{constructor(){super(...arguments);a(this,"kind","vec4i")}make2(n,t){return new A(n,t)}make3(n,t,o){return new V(n,t,o)}make4(n,t,o,s){return new e(n,t,o,s)}},C=class e extends O{constructor(){super(...arguments);a(this,"kind","vec4u")}make2(n,t){return new h(n,t)}make3(n,t,o){return new D(n,t,o)}make4(n,t,o,s){return new e(n,t,o,s)}},i={get:(e,r)=>{if(typeof r=="symbol"||!Number.isNaN(Number.parseInt(r)))return Reflect.get(e,r);let n=e,t=new Array(r.length),o=0;for(let s of r){switch(s){case"x":t[o]=n.x;break;case"y":t[o]=n.y;break;case"z":t[o]=n.z;break;case"w":t[o]=n.w;break;default:return Reflect.get(n,r)}o++}return r.length===4?new Proxy(n.make4(t[0],t[1],t[2],t[3]),i):r.length===3?new Proxy(n.make3(t[0],t[1],t[2]),i):r.length===2?new Proxy(n.make2(t[0],t[1]),i):Reflect.get(e,r)}},p= exports.z =T({type:"vec2f",length:2,make:(e,r)=>new Proxy(new v(e,r),i),makeFromScalar:e=>new Proxy(new v(e,e),i)}),$= exports.A =T({type:"vec2i",length:2,make:(e,r)=>new Proxy(new A(e,r),i),makeFromScalar:e=>new Proxy(new A(e,e),i)}),R= exports.B =T({type:"vec2u",length:2,make:(e,r)=>new Proxy(new h(e,r),i),makeFromScalar:e=>new Proxy(new h(e,e),i)}),U= exports.C =T({type:"vec3f",length:3,make:(e,r,n)=>new Proxy(new k(e,r,n),i),makeFromScalar:e=>new Proxy(new k(e,e,e),i)}),oe= exports.D =T({type:"vec3i",length:3,make:(e,r,n)=>new Proxy(new V(e,r,n),i),makeFromScalar:e=>new Proxy(new V(e,e,e),i)}),ae= exports.E =T({type:"vec3u",length:3,make:(e,r,n)=>new Proxy(new D(e,r,n),i),makeFromScalar:e=>new Proxy(new D(e,e,e),i)}),x= exports.F =T({type:"vec4f",length:4,make:(e,r,n,t)=>new Proxy(new F(e,r,n,t),i),makeFromScalar:e=>new Proxy(new F(e,e,e,e),i)}),_= exports.G =T({type:"vec4i",length:4,make:(e,r,n,t)=>new Proxy(new S(e,r,n,t),i),makeFromScalar:e=>new Proxy(new S(e,e,e,e),i)}),j= exports.H =T({length:4,type:"vec4u",make:(e,r,n,t)=>new Proxy(new C(e,r,n,t),i),makeFromScalar:e=>new Proxy(new C(e,e,e,e),i)});var u=class{constructor(r){this.type=r;a(this,"~repr")}},_e={uint8x2:R,uint8x4:j,sint8x2:$,sint8x4:_,unorm8x2:p,unorm8x4:x,snorm8x2:p,snorm8x4:x,uint16x2:R,uint16x4:j,sint16x2:$,sint16x4:_,unorm16x2:p,unorm16x4:x,snorm16x2:p,snorm16x4:x,float16x2:p,float16x4:x,float32:ee,float32x2:p,float32x3:U,float32x4:x,uint32:Y,uint32x2:R,uint32x3:ae,uint32x4:j,sint32:Z,sint32x2:$,sint32x3:oe,sint32x4:_,"unorm10-10-10-2":x},ve= exports.I =Object.keys(_e),Lr= exports.J =new u("uint8x2"),Wr= exports.K =new u("uint8x4"),Br= exports.L =new u("sint8x2"),Nr= exports.M =new u("sint8x4"),Er= exports.N =new u("unorm8x2"),Pr= exports.O =new u("unorm8x4"),Ir= exports.P =new u("snorm8x2"),Mr= exports.Q =new u("snorm8x4"),Or= exports.R =new u("uint16x2"),$r= exports.S =new u("uint16x4"),Rr= exports.T =new u("sint16x2"),Ur= exports.U =new u("sint16x4"),_r= exports.V =new u("unorm16x2"),jr= exports.W =new u("unorm16x4"),Gr= exports.X =new u("snorm16x2"),Kr= exports.Y =new u("snorm16x4"),Hr= exports.Z =new u("float16x2"),Jr= exports._ =new u("float16x4"),qr= exports.$ =new u("float32"),Qr= exports.aa =new u("float32x2"),Xr= exports.ba =new u("float32x3"),Yr= exports.ca =new u("float32x4"),Zr= exports.da =new u("uint32"),en= exports.ea =new u("uint32x2"),rn= exports.fa =new u("uint32x3"),nn= exports.ga =new u("uint32x4"),tn= exports.ha =new u("sint32"),on= exports.ia =new u("sint32x2"),an= exports.ja =new u("sint32x3"),sn= exports.ka =new u("sint32x4"),un= exports.la =new u("unorm10-10-10-2");var je={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2i:8,vec2u:8,vec3f:16,vec3i:16,vec3u:16,vec4f:16,vec4i:16,vec4u:16,mat2x2f:8,mat3x3f:16,mat4x4f:16};function Ge(e){var t,o,s;let r=e==null?void 0:e.type,n=je[r];if(n!==void 0)return n;if(N(e))return Object.values(e.propTypes).map(l).reduce((y,be)=>y>be?y:be);if(B(e))return l(e.elementType);if(z(e)){let y=Object.values(e.propTypes)[0];return y&&(t=g(y))!=null?t:1}if(w(e))return(o=g(e.elementType))!=null?o:1;if(d(e)||c(e))return(s=g(e))!=null?s:l(e.inner);if(ve.includes(r))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(e)}`)}function Ke(e){var r,n;if(z(e)){let t=Object.values(e.propTypes)[0];return t?L(t):1}return w(e)?L(e.elementType):c(e)?(r=g(e))!=null?r:L(e.inner):(n=g(e))!=null?n:1}var Ae=new WeakMap,he=new WeakMap;function l(e){let r=Ae.get(e);return r===void 0&&(r=Ge(e),Ae.set(e,r)),r}function L(e){let r=he.get(e);return r===void 0&&(r=Ke(e),he.set(e,r)),r}function He(e){return l(e)}var Je={bool:4,f32:4,f16:2,i32:4,u32:4,vec2f:8,vec2i:8,vec2u:8,vec3f:12,vec3i:12,vec3u:12,vec4f:16,vec4i:16,vec4u:16,mat2x2f:16,mat3x3f:48,mat4x4f:64,uint8x2:2,uint8x4:4,sint8x2:2,sint8x4:4,unorm8x2:2,unorm8x4:4,snorm8x2:2,snorm8x4:4,uint16x2:4,uint16x4:8,sint16x2:4,sint16x4:8,unorm16x2:4,unorm16x4:8,snorm16x2:4,snorm16x4:8,float16x2:4,float16x4:8,float32:4,float32x2:8,float32x3:12,float32x4:16,uint32:4,uint32x2:8,uint32x3:12,uint32x4:16,sint32:4,sint32x2:8,sint32x3:12,sint32x4:16,"unorm10-10-10-2":4};function qe(e){let r=0;for(let n of Object.values(e.propTypes)){if(Number.isNaN(r))throw new Error("Only the last property of a struct can be unbounded");if(r=b(r,l(n)),r+=m(n),Number.isNaN(r)&&n.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return b(r,l(e))}function Qe(e){let r=0;for(let n of Object.values(e.propTypes)){let t=L(n);r=b(r,t),r+=m(n)}return r}function Xe(e){var n;let r=Je[e==null?void 0:e.type];if(r!==void 0)return r;if(N(e))return qe(e);if(z(e))return Qe(e);if(B(e)){if(e.elementCount===0)return Number.NaN;let t=l(e.elementType);return b(m(e.elementType),t)*e.elementCount}if(w(e)){let t=L(e.elementType);return b(m(e.elementType),t)*e.elementCount}if(d(e)||c(e))return(n=ge(e))!=null?n:m(e.inner);throw new Error(`Cannot determine size of data: ${e}`)}var ke=new WeakMap;function m(e){let r=ke.get(e);return r===void 0&&(r=Xe(e),ke.set(e,r)),r}function Ye(e){return m(e)}var Ze=(e,r)=>new se(e,r),se=class{constructor(r,n){this.elementType=r;this.elementCount=n;a(this,"type","array");a(this,"~repr");a(this,"~exotic");if(Number.isNaN(m(r)))throw new Error("Cannot nest runtime sized arrays.")}};var er=(e,r)=>new ue(e,r),ue=class{constructor(r,n){this.elementType=r;this.elementCount=n;a(this,"type","loose-array");a(this,"~repr")}};var rr=e=>new ie(e),ie=class{constructor(r){this.propTypes=r;a(this,"type","loose-struct");a(this,"~repr")}};function de(e){let r={"~repr":void 0,type:e.type,label:e.type};return Object.assign((...t)=>{let o=[];for(let s of t)if(typeof s=="number")o.push(s);else for(let y=0;y<s.length;++y)o.push(s[y]);for(let s=o.length;s<e.columns*e.rows;++s)o.push(0);return e.makeFromElements(...o)},r)}var ye=class{constructor(...r){a(this,"columns");a(this,"length",4);this.columns=[this.makeColumn(r[0],r[1]),this.makeColumn(r[2],r[3])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[1].x}get 3(){return this.columns[1].y}set 0(r){this.columns[0].x=r}set 1(r){this.columns[0].y=r}set 2(r){this.columns[1].x=r}set 3(r){this.columns[1].y=r}},xe=class extends ye{constructor(){super(...arguments);a(this,"kind","mat2x2f")}makeColumn(n,t){return p(n,t)}},le=class{constructor(...r){a(this,"columns");a(this,"length",12);this.columns=[this.makeColumn(r[0],r[1],r[2]),this.makeColumn(r[3],r[4],r[5]),this.makeColumn(r[6],r[7],r[8])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return 0}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return 0}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return 0}set 0(r){this.columns[0].x=r}set 1(r){this.columns[0].y=r}set 2(r){this.columns[0].z=r}set 3(r){}set 4(r){this.columns[1].x=r}set 5(r){this.columns[1].y=r}set 6(r){this.columns[1].z=r}set 7(r){}set 8(r){this.columns[2].x=r}set 9(r){this.columns[2].y=r}set 10(r){this.columns[2].z=r}set 11(r){}},me=class extends le{constructor(){super(...arguments);a(this,"kind","mat3x3f")}makeColumn(n,t,o){return U(n,t,o)}},ce=class{constructor(...r){a(this,"columns");a(this,"length",16);this.columns=[this.makeColumn(r[0],r[1],r[2],r[3]),this.makeColumn(r[4],r[5],r[6],r[7]),this.makeColumn(r[8],r[9],r[10],r[11]),this.makeColumn(r[12],r[13],r[14],r[15])]}get 0(){return this.columns[0].x}get 1(){return this.columns[0].y}get 2(){return this.columns[0].z}get 3(){return this.columns[0].w}get 4(){return this.columns[1].x}get 5(){return this.columns[1].y}get 6(){return this.columns[1].z}get 7(){return this.columns[1].w}get 8(){return this.columns[2].x}get 9(){return this.columns[2].y}get 10(){return this.columns[2].z}get 11(){return this.columns[2].w}get 12(){return this.columns[3].x}get 13(){return this.columns[3].y}get 14(){return this.columns[3].z}get 15(){return this.columns[3].w}set 0(r){this.columns[0].x=r}set 1(r){this.columns[0].y=r}set 2(r){this.columns[0].z=r}set 3(r){this.columns[0].w=r}set 4(r){this.columns[1].x=r}set 5(r){this.columns[1].y=r}set 6(r){this.columns[1].z=r}set 7(r){this.columns[1].w=r}set 8(r){this.columns[2].x=r}set 9(r){this.columns[2].y=r}set 10(r){this.columns[2].z=r}set 11(r){this.columns[2].w=r}set 12(r){this.columns[3].x=r}set 13(r){this.columns[3].y=r}set 14(r){this.columns[3].z=r}set 15(r){this.columns[3].w=r}},pe=class extends ce{constructor(){super(...arguments);a(this,"kind","mat4x4f")}makeColumn(n,t,o,s){return x(n,t,o,s)}},nr= exports.Aa =de({type:"mat2x2f",rows:2,columns:2,makeFromElements:(...e)=>new xe(...e)}),tr= exports.Ba =de({type:"mat3x3f",rows:3,columns:3,makeFromElements:(...e)=>new me(...e)}),or= exports.Ca =de({type:"mat4x4f",rows:4,columns:4,makeFromElements:(...e)=>new pe(...e)});function ar(e){return e.kind==="mat3x3f"?[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]]:Array.from({length:e.length}).map((r,n)=>e[n])}function sr(e){return new Te(e)}var Te=class{constructor(r){this.inner=r;a(this,"type","atomic");a(this,"~repr")}};function fe(e,r){return d(e)?new J(e.inner,[r,...e.attribs]):c(e)?new q(e.inner,[r,...e.attribs]):K(e)?new q(e,[r]):new J(e,[r])}function ur(e,r){return fe(r,{type:"@align",value:e})}function ir(e,r){return fe(r,{type:"@size",value:e})}function yr(e,r){return fe(r,{type:"@location",value:e})}function xr(e){return(d(e)||c(e))&&e.attribs.find(ne)!==void 0}function Pn(e){return!d(e)&&!c(e)?"":e.attribs.map(r=>`${r.type}(${r.value}) `).join("")}var H=class{constructor(r,n){this.inner=r;this.attribs=n;a(this,"~repr");var s,y;let t=(s=n.find(E))==null?void 0:s.value,o=(y=n.find(P))==null?void 0:y.value;if(t!==void 0){if(t<=0)throw new Error(`Custom data alignment must be a positive number, got: ${t}.`);if(Math.log2(t)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${t}.`);if(W(this.inner)&&t%l(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${t}, expected multiple of: ${l(this.inner)}.`)}if(o!==void 0){if(o<m(this.inner))throw new Error(`Custom data size cannot be smaller then the standard data size. Got: ${o}, expected at least: ${m(this.inner)}.`);if(o<=0)throw new Error(`Custom data size must be a positive number. Got: ${o}.`)}}},J=class extends H{constructor(){super(...arguments);a(this,"type","decorated")}},q=class extends H{constructor(){super(...arguments);a(this,"type","loose-decorated")}};exports.a = lr; exports.b = mr; exports.c = a; exports.d = W; exports.e = B; exports.f = N; exports.g = Me; exports.h = E; exports.i = P; exports.j = re; exports.k = ne; exports.l = d; exports.m = K; exports.n = w; exports.o = z; exports.p = c; exports.q = hr; exports.r = Ue; exports.s = pr; exports.t = f; exports.u = Le; exports.v = Y; exports.w = Z; exports.x = ee; exports.y = Pe; exports.z = p; exports.A = $; exports.B = R; exports.C = U; exports.D = oe; exports.E = ae; exports.F = x; exports.G = _; exports.H = j; exports.I = ve; exports.J = Lr; exports.K = Wr; exports.L = Br; exports.M = Nr; exports.N = Er; exports.O = Pr; exports.P = Ir; exports.Q = Mr; exports.R = Or; exports.S = $r; exports.T = Rr; exports.U = Ur; exports.V = _r; exports.W = jr; exports.X = Gr; exports.Y = Kr; exports.Z = Hr; exports._ = Jr; exports.$ = qr; exports.aa = Qr; exports.ba = Xr; exports.ca = Yr; exports.da = Zr; exports.ea = en; exports.fa = rn; exports.ga = nn; exports.ha = tn; exports.ia = on; exports.ja = an; exports.ka = sn; exports.la = un; exports.ma = l; exports.na = L; exports.oa = He; exports.pa = m; exports.qa = Ye; exports.ra = ur; exports.sa = ir; exports.ta = yr; exports.ua = xr; exports.va = Pn; exports.wa = $e; exports.xa = Ze; exports.ya = er; exports.za = rr; exports.Aa = nr; exports.Ba = tr; exports.Ca = or; exports.Da = ar; exports.Ea = sr;
2
- //# sourceMappingURL=chunk-CKSBATTP.cjs.map