typegpu 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/{chunk-7S3IK3D4.js → chunk-6U5HPHCJ.js} +2 -2
  2. package/{chunk-7XFSK632.js → chunk-CGQB3SER.js} +2 -2
  3. package/{chunk-4W5Z7BO4.js → chunk-CRZWTZM2.js} +2 -2
  4. package/chunk-CRZWTZM2.js.map +1 -0
  5. package/{chunk-2UXPGML5.js → chunk-ECR2EGZX.js} +2 -2
  6. package/{chunk-VOVQAOVG.js → chunk-PWBIFP67.js} +2 -2
  7. package/common/index.d.ts +1 -1
  8. package/common/index.js +1 -1
  9. package/data/index.d.ts +3 -3
  10. package/data/index.js +1 -1
  11. package/index.d.ts +2 -2
  12. package/index.js +14 -14
  13. package/index.js.map +1 -1
  14. package/{matrix-DLipCOZF.d.ts → matrix-DIfOiRyz.d.ts} +1 -1
  15. package/package.json +5 -13
  16. package/std/index.d.ts +2 -2
  17. package/std/index.js +1 -1
  18. package/{tgpuConstant-BU72w5qs.d.cts → tgpuConstant-BTQFNlQH.d.ts} +9 -0
  19. package/chunk-3246CM7C.cjs +0 -2
  20. package/chunk-3246CM7C.cjs.map +0 -1
  21. package/chunk-4W5Z7BO4.js.map +0 -1
  22. package/chunk-5Y6GTBWR.cjs +0 -3
  23. package/chunk-5Y6GTBWR.cjs.map +0 -1
  24. package/chunk-PRMFGUQT.cjs +0 -2
  25. package/chunk-PRMFGUQT.cjs.map +0 -1
  26. package/chunk-TRE7NUKE.cjs +0 -10
  27. package/chunk-TRE7NUKE.cjs.map +0 -1
  28. package/chunk-ZYGTVBDH.cjs +0 -7
  29. package/chunk-ZYGTVBDH.cjs.map +0 -1
  30. package/common/index.cjs +0 -7
  31. package/common/index.cjs.map +0 -1
  32. package/common/index.d.cts +0 -24
  33. package/data/index.cjs +0 -2
  34. package/data/index.cjs.map +0 -1
  35. package/data/index.d.cts +0 -402
  36. package/index.cjs +0 -192
  37. package/index.cjs.map +0 -1
  38. package/index.d.cts +0 -369
  39. package/matrix-DHFT4O8f.d.cts +0 -122
  40. package/std/index.cjs +0 -2
  41. package/std/index.cjs.map +0 -1
  42. package/std/index.d.cts +0 -639
  43. package/tgpuConstant-BU72w5qs.d.ts +0 -5192
  44. /package/{chunk-7S3IK3D4.js.map → chunk-6U5HPHCJ.js.map} +0 -0
  45. /package/{chunk-7XFSK632.js.map → chunk-CGQB3SER.js.map} +0 -0
  46. /package/{chunk-2UXPGML5.js.map → chunk-ECR2EGZX.js.map} +0 -0
  47. /package/{chunk-VOVQAOVG.js.map → chunk-PWBIFP67.js.map} +0 -0
package/index.cjs DELETED
@@ -1,192 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30;var _chunk5Y6GTBWRcjs = require('./chunk-5Y6GTBWR.cjs');var _chunk3246CM7Ccjs = require('./chunk-3246CM7C.cjs');var _chunkZYGTVBDHcjs = require('./chunk-ZYGTVBDH.cjs');var _chunkTRE7NUKEcjs = require('./chunk-TRE7NUKE.cjs');function Hn(e){return new vr(e)}var vr= (_class =class{constructor(t){;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);this.declaration=t}__init() {this[_chunkTRE7NUKEcjs.a]=!0}__init2() {this.externalsToApply=[]}$uses(t){return this.externalsToApply.push(t),this}[_chunkTRE7NUKEcjs.f](t){let r={};for(let a of this.externalsToApply)_chunk5Y6GTBWRcjs.a.call(void 0, r,a);let n=_chunk5Y6GTBWRcjs.d.call(void 0, t,r,this.declaration);return t.addDeclaration(n),_chunkTRE7NUKEcjs.aa.call(void 0, "",_chunkTRE7NUKEcjs.q)}toString(){return`declare: ${this.declaration}`}}, _class);function Et(e){let t={argTypes:e.in&&Object.keys(e.in).length!==0?[_chunk5Y6GTBWRcjs.f.call(void 0, e.in)]:[],returnType:_chunkTRE7NUKEcjs.q,workgroupSize:[_nullishCoalesce(e.workgroupSize[0], () => (1)),_nullishCoalesce(e.workgroupSize[1], () => (1)),_nullishCoalesce(e.workgroupSize[2], () => (1))],isEntry:!0},r=(n,...a)=>qa(t,e.workgroupSize,_chunk5Y6GTBWRcjs.g.call(void 0, n,...a));return Object.assign(Object.assign(r,t),{does:r})}function qa(e,t,r){let n=_chunk5Y6GTBWRcjs.e.call(void 0, r,`@compute @workgroup_size(${t.join(", ")}) `),a=e.argTypes[0];return{shell:e,$uses(s){return n.applyExternals(s),this},[_chunkTRE7NUKEcjs.a]:!0,[_chunkTRE7NUKEcjs.c]:n,$name(s){return _chunkTRE7NUKEcjs.k.call(void 0, n,s),_chunkTRE7NUKEcjs.l.call(void 0, a)&&a.$name(`${s}_Input`),this},[_chunkTRE7NUKEcjs.f](s){return n.resolve(s,e.argTypes,e.returnType)},toString(){return`computeFn:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, n), () => ("<unnamed>"))}`}}}function U(e,t){let r={[_chunkTRE7NUKEcjs.a]:!0,argTypes:e,returnType:_nullishCoalesce(t, () => (_chunkTRE7NUKEcjs.q)),isEntry:!1};return Object.assign((a,...o)=>Qa(r,_chunk5Y6GTBWRcjs.g.call(void 0, a,...o)),r)}function Ke(e){return _chunkTRE7NUKEcjs.h.call(void 0, e)&&_optionalChain([e, 'optionalAccess', _2 => _2.resourceType])==="function"}function ja([e,t]){return`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, e), () => ("<unnamed>"))}=${t}`}function Qa(e,t){let r=_chunk5Y6GTBWRcjs.e.call(void 0, t,""),n={shell:e,resourceType:"function",$uses(s){return r.applyExternals(s),this},[_chunkTRE7NUKEcjs.c]:r,$name(s){return _chunkTRE7NUKEcjs.k.call(void 0, r,s),this},with(s,i){return Kn(o,[[_chunkTRE7NUKEcjs.pa.call(void 0, s)?s.slot:s,i]])},[_chunkTRE7NUKEcjs.f](s){return typeof t=="string"&&(_chunk5Y6GTBWRcjs.b.call(void 0, t,e.argTypes,r.applyExternals),_chunk5Y6GTBWRcjs.c.call(void 0, t,e.returnType,r.applyExternals)),r.resolve(s,e.argTypes,e.returnType)}},a=_chunkTRE7NUKEcjs.La.call(void 0, (...s)=>_chunkTRE7NUKEcjs.xa.call(void 0, ()=>{try{if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");let i=s.map((l,m)=>_chunkTRE7NUKEcjs.qc.call(void 0, e.argTypes[m],l)),u=t(...i);return _chunkTRE7NUKEcjs.qc.call(void 0, e.returnType,u)}catch(i){throw i instanceof _chunkTRE7NUKEcjs.da?i.appendToTrace(o):new (0, _chunkTRE7NUKEcjs.da)(i,[o])}}),(...s)=>_chunkTRE7NUKEcjs.aa.call(void 0, new Vt(o,s),e.returnType),"tgpuFnCall",e.argTypes),o=Object.assign(a,n);return o[_chunkTRE7NUKEcjs.a].implementation=t,Object.defineProperty(o,"toString",{value(){return`fn:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}),o}function Kn(e,t){let r={resourceType:"function",shell:e.shell,[_chunkTRE7NUKEcjs.d]:{inner:e,pairs:t},$uses(o){return e.$uses(o),this},[_chunkTRE7NUKEcjs.c]:e,$name(o){return e.$name(o),this},with(o,s){return Kn(a,[...t,[_chunkTRE7NUKEcjs.pa.call(void 0, o)?o.slot:o,s]])}},n=_chunkTRE7NUKEcjs.La.call(void 0, (...o)=>e(...o),(...o)=>_chunkTRE7NUKEcjs.aa.call(void 0, new Vt(a,o),e.shell.returnType),"tgpuFnCall",e.shell.argTypes),a=Object.assign(n,r);return a[_chunkTRE7NUKEcjs.a].implementation=e[_chunkTRE7NUKEcjs.a].implementation,Object.defineProperty(a,"toString",{value(){return`fn:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, e), () => ("<unnamed>"))}[${t.map(ja).join(", ")}]`}}),a[_chunkTRE7NUKEcjs.a].implementation=e[_chunkTRE7NUKEcjs.a].implementation,a}var Vt= (_class2 =class{__init3() {this[_chunkTRE7NUKEcjs.a]=!0}#e;#r;constructor(t,r){;_class2.prototype.__init3.call(this);this.#e=t,this.#r=r,this[_chunkTRE7NUKEcjs.c]=t,this[_chunkTRE7NUKEcjs.e]=_chunkTRE7NUKEcjs.aa.call(void 0, this,this.#e.shell.returnType)}[_chunkTRE7NUKEcjs.f](t){return t.withResetIndentLevel(()=>_chunkTRE7NUKEcjs.aa.call(void 0, _chunkTRE7NUKEcjs.Ea`${t.resolve(this.#e).value}(${this.#r})`,this.#e.shell.returnType))}toString(){return`call:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class2);function Yn(e){let t={in:e.in,out:e.out,returnType:_chunk5Y6GTBWRcjs.f.call(void 0, e.out),isEntry:!0},r=(n,...a)=>Ha(t,_chunk5Y6GTBWRcjs.g.call(void 0, n,...a));return Object.assign(Object.assign(r,t),{does:r})}function Ha(e,t){let r=_chunk5Y6GTBWRcjs.e.call(void 0, t,"@fragment "),n=e.returnType;return typeof t=="string"&&_chunk5Y6GTBWRcjs.c.call(void 0, t,n,o=>r.applyExternals(o)),{shell:e,outputType:n,$uses(o){return r.applyExternals(o),this},[_chunkTRE7NUKEcjs.a]:!0,[_chunkTRE7NUKEcjs.c]:r,$name(o){return _chunkTRE7NUKEcjs.k.call(void 0, r,o),_chunkTRE7NUKEcjs.l.call(void 0, n)&&n.$name(`${o}_Output`),this},[_chunkTRE7NUKEcjs.f](o){let s=e.in?_chunk5Y6GTBWRcjs.f.call(void 0, e.in,o.varyingLocations).$name(`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => (""))}_Input`):void 0;return s&&r.applyExternals({In:s}),r.applyExternals({Out:n}),r.resolve(o,s?[s]:[],e.returnType)},toString(){return`fragmentFn:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}}var Jn=new Set(["alias","break","case","const","const_assert","continue","continuing","default","diagnostic","discard","else","enable","false","fn","for","if","let","loop","override","requires","return","struct","switch","true","var","while","NULL","Self","abstract","active","alignas","alignof","as","asm","asm_fragment","async","attribute","auto","await","become","cast","catch","class","co_await","co_return","co_yield","coherent","column_major","common","compile","compile_fragment","concept","const_cast","consteval","constexpr","constinit","crate","debugger","decltype","delete","demote","demote_to_helper","do","dynamic_cast","enum","explicit","export","extends","extern","external","fallthrough","filter","final","finally","friend","from","fxgroup","get","goto","groupshared","highp","impl","implements","import","inline","instanceof","interface","layout","lowp","macro","macro_rules","match","mediump","meta","mod","module","move","mut","mutable","namespace","new","nil","noexcept","noinline","nointerpolation","non_coherent","noncoherent","noperspective","null","nullptr","of","operator","package","packoffset","partition","pass","patch","pixelfragment","precise","precision","premerge","priv","protected","pub","public","readonly","ref","regardless","register","reinterpret_cast","require","resource","restrict","self","set","shared","sizeof","smooth","snorm","static","static_assert","static_cast","std","subroutine","super","target","template","this","thread_local","throw","trait","try","type","typedef","typeid","typename","typeof","union","unless","unorm","unsafe","unsized","use","using","varying","virtual","volatile","wgsl","where","with","writeonly","yield"]);function Ir(e){if(e==="_"||e.startsWith("__")||/\s/.test(e))throw new Error(`Invalid identifier '${e}'. Choose an identifier without whitespaces or leading underscores.`);let t=e.split("_")[0];return!Jn.has(t)}var _t=class{makeValid(t){return Ir(t)?t:this.makeUnique(t)}},Wt= (_class3 =class extends _t{constructor(...args2) { super(...args2); _class3.prototype.__init4.call(this); }__init4() {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++}`}}, _class3),kt= (_class4 =class extends _t{constructor(...args3) { super(...args3); _class4.prototype.__init5.call(this); }__init5() {this._usedNames=new Set(Jn)}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}}, _class4);function Xn(e,t){let r=_chunk5Y6GTBWRcjs.e.call(void 0, t,"");return{[_chunkTRE7NUKEcjs.a]:!0,[_chunkTRE7NUKEcjs.c]:r,resourceType:"shellless-impl",[_chunkTRE7NUKEcjs.f](n){return r.resolve(n,e,void 0)},toString(){return`fn*:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}}var Mt= (_class5 =class{constructor() { _class5.prototype.__init6.call(this); }__init6() {this.cache=new Map}get(t,r){let n=_chunkTRE7NUKEcjs.n.call(void 0, t);if(!_optionalChain([n, 'optionalAccess', _3 => _3.ast]))return;if(!r&&n.ast.params.length>0)throw new Error(`Cannot resolve '${_chunkTRE7NUKEcjs.j.call(void 0, t)}' directly, because it expects arguments. Either call it from another function, or wrap it in a shell`);let a=(_nullishCoalesce(r, () => ([]))).map(i=>_chunkZYGTVBDHcjs.o.call(void 0, i.dataType)),o=this.cache.get(t);if(o){let i=o.find(u=>u.argTypes.every((l,m)=>l===a[m]));if(i)return i.value}else o=[],this.cache.set(t,o);let s=Xn(a,t);return o.push({argTypes:a,value:s}),s}}, _class5);var Ur=class{constructor(t){this[_chunkTRE7NUKEcjs.a]={nameRegistry:t,shelllessRepo:new Mt,memoizedResolves:new WeakMap,memoizedDerived:new WeakMap,listeners:{name:new Set}}}on(t,r){if(t==="name"){let n=this[_chunkTRE7NUKEcjs.a].listeners.name;return n.add(r),()=>n.delete(r)}throw new Error(`Unsupported event: ${t}`)}};function Zn(e,t){let r=e.nameRegistry.makeUnique(_chunkTRE7NUKEcjs.j.call(void 0, t));for(let n of e.listeners.name)n({target:t,name:r});return r}function Q(e){let{names:t="random"}=e||{};return new Ur(t==="strict"?new kt:new Wt)}function Ye(e){return typeof _optionalChain([e, 'optionalAccess', _4 => _4.format])=="string"}function ea(e,t){let r=[];if(_chunkTRE7NUKEcjs.V.call(void 0, e)){if(!Ye(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:_nullishCoalesce(_chunkTRE7NUKEcjs.U.call(void 0, e), () => (0))}]}]}}let n=[],a=new WeakMap,o=0;for(let[s,i]of Object.entries(e)){if(_chunkTRE7NUKEcjs.oc.call(void 0, i))continue;let u=t[s];if(!u)throw new Error(`An attribute by the name of '${s}' was not provided to the shader.`);let l=u._layout,m=a.get(l);m||(r.push(l),m=[],n.push({arrayStride:l.stride,stepMode:l.stepMode,attributes:m}),a.set(l,m)),o=_nullishCoalesce(_chunkTRE7NUKEcjs.U.call(void 0, i), () => (o)),m.push({format:u.format,offset:u.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var Ka=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","vec2<bool>","vec3<bool>","vec4<bool>","mat2x2f","mat3x3f","mat4x4f","texture_external"];function Ya(e){return Ka.includes(e.type)}function Fr(e,[t,r]){if(!Ir(t))throw new Error(`Property key '${t}' is a reserved WGSL word. Choose a different name.`);return` ${_chunkTRE7NUKEcjs.pc.call(void 0, r)}${t}: ${e.resolve(r).value},
2
- `}function Ja(e,t){if(t[_chunkTRE7NUKEcjs.a].isAbstruct)throw new Error("Cannot resolve abstract struct types to WGSL.");let r=e.getUniqueName(t);return e.addDeclaration(`struct ${r} {
3
- ${Object.entries(t.propTypes).map(n=>Fr(e,n)).join("")}}`),r}function Xa(e,t){let r=e.getUniqueName(t);return e.addDeclaration(`struct ${r} {
4
- ${Object.entries(t.propTypes).map(n=>Ye(n[1])?Fr(e,[n[0],_chunkTRE7NUKEcjs.nb[n[1].format]]):Fr(e,n)).join("")}
5
- }`),r}function Za(e,t){let r=e.resolve(t.elementType).value;return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function eo(e,t){let r=e.resolve(Ye(t.elementType)?_chunkTRE7NUKEcjs.nb[t.elementType.format]:t.elementType).value;return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Pr(e,t){if(_chunkTRE7NUKEcjs.Q.call(void 0, t))return t.type==="unstruct"?Xa(e,t):t.type==="disarray"?eo(e,t):t.type==="loose-decorated"?e.resolve(Ye(t.inner)?_chunkTRE7NUKEcjs.nb[t.inner.format]:t.inner).value:e.resolve(_chunkTRE7NUKEcjs.nb[t.type]).value;if(Ya(t))return t.type;if(t.type==="struct")return Ja(e,t);if(t.type==="array")return Za(e,t);if(t.type==="atomic")return`atomic<${Pr(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner).value;if(t.type==="ptr")return t.addressSpace==="storage"?`ptr<storage, ${e.resolve(t.inner).value}, ${t.access==="read-write"?"read_write":t.access}>`:`ptr<${t.addressSpace}, ${e.resolve(t.inner).value}>`;if(t.type==="abstractInt"||t.type==="abstractFloat"||t.type==="void"||t.type==="u16")throw new Error(`${t.type} has no representation in WGSL`);if(_chunkZYGTVBDHcjs.S.call(void 0, t))return`${t.type}<${t.format}, ${_chunkZYGTVBDHcjs.z[t.access]}>`;if(_chunkZYGTVBDHcjs.R.call(void 0, t))return t.type.startsWith("texture_depth")?t.type:`${t.type}<${t.sampleType.type}>`;if(_chunkZYGTVBDHcjs.x.call(void 0, t)||_chunkZYGTVBDHcjs.w.call(void 0, t))return t.type;_chunkTRE7NUKEcjs.Fa.call(void 0, t,"resolveData")}var Ge=class e{constructor(t){this.bindings=t}with(t,r){return new e([...this.bindings,[_chunkTRE7NUKEcjs.pa.call(void 0, t)?t.slot:t,r]])}pipe(t){let r=t(this);return new e([...this.bindings,...r.bindings])}};function*ta(e){let t=0;for(;;)e.has(t)||(yield t),t++}var _typedbinary = require('typed-binary');function to(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 B=to;var ra=new WeakMap;function Ot(e){let t=ra.get(e);if(t)return t;let r=new _typedbinary.Measurer,n={},a;for(let o in e.propTypes){let s=e.propTypes[o];if(s===void 0)throw new Error(`Property ${o} is undefined in struct`);let i=r.size;B(r,_chunkTRE7NUKEcjs.S.call(void 0, e)?_chunkTRE7NUKEcjs.ec.call(void 0, s):_chunkTRE7NUKEcjs.dc.call(void 0, s)),a&&(a.padding=r.size-i);let u=_chunkTRE7NUKEcjs.hc.call(void 0, s);n[o]={offset:r.size,size:u},a=n[o],r.add(u)}return a&&(a.padding=_chunkTRE7NUKEcjs.gc.call(void 0, _chunkTRE7NUKEcjs.hc.call(void 0, e),_chunkTRE7NUKEcjs.dc.call(void 0, e))-r.size),ra.set(e,n),n}var no=(()=>{try{return new Function("return true"),!0}catch (e2){return!1}})(),Dr=new WeakMap,zt={u32:"u32",vec2u:"u32",vec3u:"u32",vec4u:"u32",u16:"u16",i32:"i32",vec2i:"i32",vec3i:"i32",vec4i:"i32",f32:"f32",vec2f:"f32",vec3f:"f32",vec4f:"f32",f16:"f16",vec2h:"f16",vec3h:"f16",vec4h:"f16",mat2x2f:"f32",mat3x3f:"f32",mat4x4f:"f32"},ao={uint8:"u8",uint8x2:"u8",uint8x4:"u8",sint8:"i8",sint8x2:"i8",sint8x4:"i8",unorm8:"u8",unorm8x2:"u8",unorm8x4:"u8",snorm8:"i8",snorm8x2:"i8",snorm8x4:"i8",uint16:"u16",uint16x2:"u16",uint16x4:"u16",sint16:"i16",sint16x2:"i16",sint16x4:"i16",unorm16:"u16",unorm16x2:"u16",unorm16x4:"u16",snorm16:"i16",snorm16x2:"i16",snorm16x4:"i16",float16:"f16",float16x2:"f16",float16x4:"f16",float32:"f32",float32x2:"f32",float32x3:"f32",float32x4:"f32",uint32:"u32",uint32x2:"u32",uint32x3:"u32",uint32x4:"u32",sint32:"i32",sint32x2:"i32",sint32x3:"i32",sint32x4:"i32"},Nt={u32:"setUint32",i32:"setInt32",f32:"setFloat32",u16:"setUint16",i16:"setInt16",f16:"setFloat16",u8:"setUint8",i8:"setInt8"},oo={unorm8:e=>`Math.round(${e} * 255)`,unorm8x2:e=>`Math.round(${e} * 255)`,unorm8x4:e=>`Math.round(${e} * 255)`,snorm8:e=>`Math.round(${e} * 127)`,snorm8x2:e=>`Math.round(${e} * 127)`,snorm8x4:e=>`Math.round(${e} * 127)`,unorm16:e=>`Math.round(${e} * 65535)`,unorm16x2:e=>`Math.round(${e} * 65535)`,unorm16x4:e=>`Math.round(${e} * 65535)`,snorm16:e=>`Math.round(${e} * 32767)`,snorm16x2:e=>`Math.round(${e} * 32767)`,snorm16x4:e=>`Math.round(${e} * 32767)`},na={"unorm10-10-10-2":{writeFunction:"setUint32",generator:(e,t)=>`output.setUint32(${e}, ((${t}.x*1023&0x3FF)<<22)|((${t}.y*1023&0x3FF)<<12)|((${t}.z*1023&0x3FF)<<2)|(${t}.w*3&3), littleEndian);
6
- `},"unorm8x4-bgra":{writeFunction:"setUint8",generator:(e,t)=>{let r=["z","y","x","w"],n="";for(let a=0;a<4;a++)n+=`output.setUint8((${e} + ${a}), Math.round(${t}.${r[a]} * 255), littleEndian);
7
- `;return n}}};function qt(e,t,r,n=0){let a=["i","j","k"][n]||`i${n}`;if(_chunkTRE7NUKEcjs.F.call(void 0, e)||_chunkTRE7NUKEcjs.L.call(void 0, e))return qt(e.inner,t,r,n);if(_chunkTRE7NUKEcjs.D.call(void 0, e)||_chunkTRE7NUKEcjs.S.call(void 0, e)){let s=Ot(e),i="";for(let[u,l]of Object.entries(s)){let m=e.propTypes[u];m&&(i+=qt(m,`(${t} + ${l.offset})`,`${r}.${u}`,n))}return i}if(_chunkTRE7NUKEcjs.C.call(void 0, e)||_chunkTRE7NUKEcjs.R.call(void 0, e)){let s=_chunkTRE7NUKEcjs.gc.call(void 0, _chunkTRE7NUKEcjs.hc.call(void 0, e.elementType),_chunkTRE7NUKEcjs.dc.call(void 0, e)),i="";return i+=`for (let ${a} = 0; ${a} < ${e.elementCount}; ${a}++) {
8
- `,i+=qt(e.elementType,`(${t} + ${a} * ${s})`,`${r}[${a}]`,n+1),i+=`}
9
- `,i}if(_chunkTRE7NUKEcjs.v.call(void 0, e)){let s=zt[e.type],i="",u=Nt[s],l=["x","y","z","w"],m=_chunkTRE7NUKEcjs.s.call(void 0, e)?2:_chunkTRE7NUKEcjs.t.call(void 0, e)?3:4;for(let y=0;y<m;y++)i+=`output.${u}((${t} + ${y*4}), ${r}.${l[y]}, littleEndian);
10
- `;return i}if(_chunkTRE7NUKEcjs.z.call(void 0, e)){let s=zt[e.type],i=Nt[s],u=_chunkTRE7NUKEcjs.x.call(void 0, e)?2:_chunkTRE7NUKEcjs.y.call(void 0, e)?3:4,l=u*u,m=_chunkTRE7NUKEcjs.gc.call(void 0, u*4,8),y="";for(let f=0;f<l;f++){let T=Math.floor(f/u),w=f%u,x=T*m+w*4;y+=`output.${i}((${t} + ${x}), ${r}.columns[${T}].${["x","y","z","w"][w]}, littleEndian);
11
- `}return y}if(_chunkTRE7NUKEcjs.cc.call(void 0, e)){let s=e.type;if(s in na)return na[s].generator(t,r);let i=ao[s],u=Nt[i],l=_chunkTRE7NUKEcjs.nb[s],m=_chunkTRE7NUKEcjs.u.call(void 0, l)?4:_chunkTRE7NUKEcjs.t.call(void 0, l)?3:_chunkTRE7NUKEcjs.s.call(void 0, l)?2:1,y=i==="u8"||i==="i8"?1:i==="u16"||i==="i16"||i==="f16"?2:4,f=["x","y","z","w"],T=oo[s],w="";for(let x=0;x<m;x++){let P=m===1?r:`${r}.${f[x]}`,F=T?T(P):P;w+=`output.${u}((${t} + ${x*y}), ${F}, littleEndian);
12
- `}return w}if(!Object.hasOwn(zt,e.type))throw new Error(`Primitive ${e.type} is unsupported by compiled writer`);let o=zt[e.type];return`output.${Nt[o]}(${t}, ${r}, littleEndian);
13
- `}function Br(e){if(!no){console.warn("This environment does not allow eval - using default writer as fallback");return}if(Dr.has(e))return Dr.get(e);try{let t=qt(e,"offset","value",0),r=new Function("output","offset","value","littleEndian=true",t);return Dr.set(e,r),r}catch(t){console.warn(`Failed to compile writer for schema: ${e}
14
- Reason: ${t instanceof Error?t.message:String(t)}
15
- Falling back to default writer`)}}var Ce={bool(){throw new Error("Booleans are not host-shareable")},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)},u16(e,t,r){e.writeUint16(r)},vec2f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},vec2h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},vec2i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},vec2u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},vec3f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},vec3h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z)},vec3i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},vec3u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},vec4f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},vec4h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},vec4i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},vec4u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},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=_chunkTRE7NUKEcjs.dc.call(void 0, t);B(e,n);for(let[a,o]of Object.entries(t.propTypes))B(e,_chunkTRE7NUKEcjs.dc.call(void 0, o)),Ee(e,o,r[a]);B(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkTRE7NUKEcjs.dc.call(void 0, t);B(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)B(e,n),Ee(e,t.elementType,r[o]);e.seekTo(a+_chunkTRE7NUKEcjs.hc.call(void 0, t))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){_optionalChain([Ce, 'access', _5 => _5[t.inner.type], 'optionalCall', _6 => _6(e,t,r)])},decorated(e,t,r){let n=_chunkTRE7NUKEcjs.ec.call(void 0, t);B(e,n);let a=e.currentByteOffset;_optionalChain([Ce, 'access', _7 => _7[_optionalChain([t, 'access', _8 => _8.inner, 'optionalAccess', _9 => _9.type])], 'optionalCall', _10 => _10(e,t.inner,r)]),e.seekTo(a+_chunkTRE7NUKEcjs.hc.call(void 0, t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(Math.round(r*255))},unorm8x2(e,t,r){e.writeUint8(Math.round(r.x*255)),e.writeUint8(Math.round(r.y*255))},unorm8x4(e,t,r){e.writeUint8(Math.round(r.x*255)),e.writeUint8(Math.round(r.y*255)),e.writeUint8(Math.round(r.z*255)),e.writeUint8(Math.round(r.w*255))},snorm8(e,t,r){e.writeInt8(Math.round(r*127))},snorm8x2(e,t,r){e.writeInt8(Math.round(r.x*127)),e.writeInt8(Math.round(r.y*127))},snorm8x4(e,t,r){e.writeInt8(Math.round(r.x*127)),e.writeInt8(Math.round(r.y*127)),e.writeInt8(Math.round(r.z*127)),e.writeInt8(Math.round(r.w*127))},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeInt16(Math.round(r*32767))},snorm16x2(e,t,r){e.writeInt16(Math.round(r.x*32767)),e.writeInt16(Math.round(r.y*32767))},snorm16x4(e,t,r){e.writeInt16(Math.round(r.x*32767)),e.writeInt16(Math.round(r.y*32767)),e.writeInt16(Math.round(r.z*32767)),e.writeInt16(Math.round(r.w*32767))},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.y*1023&1023)<<12,n|=(r.z*1023&1023)<<2,n|=r.w*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){let n=_chunkTRE7NUKEcjs.dc.call(void 0, t);B(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)B(e,n),_optionalChain([Ce, 'access', _11 => _11[_optionalChain([t, 'access', _12 => _12.elementType, 'optionalAccess', _13 => _13.type])], 'optionalCall', _14 => _14(e,t.elementType,r[o])]);e.seekTo(a+_chunkTRE7NUKEcjs.hc.call(void 0, t))},unstruct(e,t,r){let n=t.propTypes;for(let[a,o]of Object.entries(n))_optionalChain([Ce, 'access', _15 => _15[o.type], 'optionalCall', _16 => _16(e,o,r[a])])},"loose-decorated"(e,t,r){let n=_chunkTRE7NUKEcjs.ec.call(void 0, t);B(e,n);let a=e.currentByteOffset,o=Ce[_optionalChain([t, 'access', _17 => _17.inner, 'optionalAccess', _18 => _18.type])];return _optionalChain([o, 'optionalCall', _19 => _19(e,t.inner,r)]),e.seekTo(a+_chunkTRE7NUKEcjs.hc.call(void 0, t)),r}};function Ee(e,t,r){let n=Ce[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var so={bool(){throw new Error("Booleans are not host-shareable")},f32(e){return e.readFloat32()},f16(e){return e.readFloat16()},i32(e){return e.readInt32()},u32(e){return e.readUint32()},u16(e){return e.readUint16()},vec2f(e){return _chunkTRE7NUKEcjs.Xa.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunkTRE7NUKEcjs.ab.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunkTRE7NUKEcjs.fb.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunkTRE7NUKEcjs.Ya.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunkTRE7NUKEcjs.bb.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunkTRE7NUKEcjs.gb.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunkTRE7NUKEcjs.Za.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunkTRE7NUKEcjs.cb.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunkTRE7NUKEcjs.hb.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunkTRE7NUKEcjs._a.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunkTRE7NUKEcjs.db.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunkTRE7NUKEcjs.ib.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(e){return _chunkZYGTVBDHcjs.j.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkZYGTVBDHcjs.k.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkZYGTVBDHcjs.l.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=_chunkTRE7NUKEcjs.dc.call(void 0, t);B(e,r);let n={},a=t.propTypes;for(let[o,s]of Object.entries(a))B(e,_chunkTRE7NUKEcjs.dc.call(void 0, s)),n[o]=O(e,s);return B(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkTRE7NUKEcjs.dc.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++){B(e,r);let o=t.elementType,s=O(e,o);n.push(s)}return B(e,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return O(e,t.inner)},decorated(e,t){let r=_chunkTRE7NUKEcjs.ec.call(void 0, t);B(e,r);let n=e.currentByteOffset,a=O(e,t.inner);return e.seekTo(n+_chunkTRE7NUKEcjs.hc.call(void 0, t)),a},uint8:e=>e.readUint8(),uint8x2:e=>_chunkTRE7NUKEcjs._a.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunkTRE7NUKEcjs.ib.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunkTRE7NUKEcjs.Za.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunkTRE7NUKEcjs.hb.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>e.readInt8()/127,snorm8x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readInt8()/127,e.readInt8()/127),snorm8x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readInt8()/127,e.readInt8()/127,e.readInt8()/127,e.readInt8()/127),uint16:e=>e.readUint16(),uint16x2:e=>_chunkTRE7NUKEcjs._a.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunkTRE7NUKEcjs.ib.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunkTRE7NUKEcjs.Za.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunkTRE7NUKEcjs.hb.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>e.readInt16()/32767,snorm16x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readInt16()/32767,e.readInt16()/32767),snorm16x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readInt16()/32767,e.readInt16()/32767,e.readInt16()/32767,e.readInt16()/32767),float16(e){return e.readFloat16()},float16x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunkTRE7NUKEcjs.ab.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunkTRE7NUKEcjs.fb.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunkTRE7NUKEcjs._a.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunkTRE7NUKEcjs.db.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunkTRE7NUKEcjs.ib.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunkTRE7NUKEcjs.Za.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunkTRE7NUKEcjs.cb.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunkTRE7NUKEcjs.hb.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 _chunkTRE7NUKEcjs.fb.call(void 0, r,n,a,o)},"unorm8x4-bgra"(e){let t=e.readByte()/255,r=e.readByte()/255,n=e.readByte()/255,a=e.readByte()/255;return _chunkTRE7NUKEcjs.fb.call(void 0, n,r,t,a)},unstruct(e,t){let r={},n=t.propTypes;for(let[a,o]of Object.entries(n))r[a]=O(e,o);return r},disarray(e,t){let r=_chunkTRE7NUKEcjs.dc.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++)B(e,r),n.push(O(e,t.elementType));return B(e,r),n},"loose-decorated"(e,t){B(e,_chunkTRE7NUKEcjs.ec.call(void 0, t));let r=e.currentByteOffset,n=O(e,t.inner);return e.seekTo(r+_chunkTRE7NUKEcjs.hc.call(void 0, t)),n}};function O(e,t){let r=so[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function aa(e,t){let r=_chunkTRE7NUKEcjs.hc.call(void 0, e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new (0, _typedbinary.BufferWriter)(n),o=[];function s(l,m,y,f){if(m!=null){if(_chunkTRE7NUKEcjs.D.call(void 0, l)||_chunkTRE7NUKEcjs.S.call(void 0, l)){let T=Ot(l);for(let[w,x]of Object.entries(T)){let P=l.propTypes[w];if(!P)continue;let F=m[w];F!==void 0&&s(P,F,y+x.offset,_nullishCoalesce(x.padding, () => (f)))}return}if(_chunkTRE7NUKEcjs.C.call(void 0, l)||_chunkTRE7NUKEcjs.R.call(void 0, l)){let T=l,w=_chunkTRE7NUKEcjs.gc.call(void 0, _chunkTRE7NUKEcjs.hc.call(void 0, T.elementType),_chunkTRE7NUKEcjs.dc.call(void 0, T.elementType));if(!Array.isArray(m))throw new Error("Partial value for array must be an array");let x=_nullishCoalesce(m, () => ([]));x.sort((P,F)=>P.idx-F.idx);for(let{idx:P,value:F}of x)s(T.elementType,F,y+P*w,w-_chunkTRE7NUKEcjs.hc.call(void 0, T.elementType))}else{let T=_chunkTRE7NUKEcjs.hc.call(void 0, l);a.seekTo(y),Ee(a,l,m),o.push({start:y,end:y+T,padding:f})}}}if(s(e,t,0),o.length===0)return[];let i=[],u=o[0];for(let l=1;l<o.length;l++){let m=o[l];if(!m||!u)throw new Error("Internal error: missing segment");m.start===u.end+(_nullishCoalesce(u.padding, () => (0)))?(u.end=m.end,u.padding=m.padding):(i.push({data:new Uint8Array(n,u.start,u.end-u.start)}),u=m)}if(!u)throw new Error("Internal error: missing segment");return i.push({data:new Uint8Array(n,u.start,u.end-u.start)}),i}function Te(e){return!!_optionalChain([e, 'optionalAccess', _20 => _20.usableAsStorage])}var Je=class e extends Error{constructor(t){super(`Resource '${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, t), () => ("<unnamed>"))}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function jt(e){return!!e.usableAsUniform}var ua={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Xe= (_class6 =class{constructor(t,r){;_class6.prototype.__init7.call(this);this.usage=t;this.buffer=r;this[_chunkTRE7NUKEcjs.a]={dataType:r.dataType},this[_chunkTRE7NUKEcjs.c]=r}__init7() {this.resourceType="buffer-usage"}$name(t){return this.buffer.$name(t),this}[_chunkTRE7NUKEcjs.f](t){let r=this.buffer.dataType,n=t.getUniqueName(this),{group:a,binding:o}=t.allocateFixedEntry(this.usage==="uniform"?{uniform:r}:{storage:r,access:this.usage},this.buffer),s=ua[this.usage];return t.addDeclaration(`@group(${a}) @binding(${o}) var<${s}> ${n}: ${t.resolve(r).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, n,r)}toString(){return`${this.usage}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get[_chunkTRE7NUKEcjs.b](){let t=this.buffer.dataType;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.usage}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}.$`},_chunkZYGTVBDHcjs.r)}get $(){let t=_chunkTRE7NUKEcjs.Ca.call(void 0, ),r=_chunkTRE7NUKEcjs.ya.call(void 0, );if(t.type==="normal")throw new (0, _chunkTRE7NUKEcjs.ka)(r?`Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation`:".$ and .value are inaccessible during normal JS execution. Try `.read()`");return t.type==="codegen"?this[_chunkTRE7NUKEcjs.b]:t.type==="simulate"?(t.buffers.has(this.buffer)||t.buffers.set(this.buffer,_chunkTRE7NUKEcjs.qc.call(void 0, this.buffer.dataType,this.buffer.initial)),t.buffers.get(this.buffer)):_chunkTRE7NUKEcjs.Fa.call(void 0, t,"bufferUsage.ts#TgpuFixedBufferImpl/$")}get value(){return this.$}set $(t){let r=_chunkTRE7NUKEcjs.Ca.call(void 0, ),n=_chunkTRE7NUKEcjs.ya.call(void 0, );if(r.type==="normal")throw new (0, _chunkTRE7NUKEcjs.ka)(n?`Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation`:".$ and .value are inaccessible during normal JS execution. Try `.write()`");if(r.type==="codegen")throw new Error("Unreachable bufferUsage.ts#TgpuFixedBufferImpl/$");if(r.type==="simulate"){r.buffers.set(this.buffer,t);return}_chunkTRE7NUKEcjs.Fa.call(void 0, r,"bufferUsage.ts#TgpuFixedBufferImpl/$")}set value(t){this.$=t}}, _class6),Ze= (_class7 =class{constructor(t,r,n){;_class7.prototype.__init8.call(this);this.usage=t;this.dataType=r;this[_chunkTRE7NUKEcjs.a]={dataType:r},this.#e=n,_chunkTRE7NUKEcjs.k.call(void 0, this,n.key)}__init8() {this.resourceType="buffer-usage"}#e;[_chunkTRE7NUKEcjs.f](t){let r=this.dataType,n=t.getUniqueName(this),a=t.allocateLayoutEntry(this.#e.layout),o=ua[this.usage];return t.addDeclaration(`@group(${a}) @binding(${this.#e.idx}) var<${o}> ${n}: ${t.resolve(r).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, n,r)}toString(){return`${this.usage}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get[_chunkTRE7NUKEcjs.b](){let t=this.dataType;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.usage}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to buffer values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead")}get value(){return this.$}}, _class7),oa=new WeakMap;function pa(e){if(!Te(e))throw new Error(`Cannot pass ${e} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=oa.get(e);return t||(t=new Xe("mutable",e),oa.set(e,t)),t}var sa=new WeakMap;function la(e){if(!Te(e))throw new Error(`Cannot pass ${e} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=sa.get(e);return t||(t=new Xe("readonly",e),sa.set(e,t)),t}var ia=new WeakMap;function ma(e){if(!jt(e))throw new Error(`Cannot pass ${e} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let t=ia.get(e);return t||(t=new Xe("uniform",e),ia.set(e,t)),t}var lo={uniform:ma,mutable:pa,readonly:la};function et(e,t,r){return _chunkTRE7NUKEcjs.B.call(void 0, t)?new Qt(e,t,r):new Qt(e,t,r,["storage","uniform"])}function le(e){return e.resourceType==="buffer"}function mo(e){return!!e.usableAsVertex}var fo=_typedbinary.getSystemEndianness.call(void 0, ),Qt= (_class8 =class{constructor(t,r,n,a){;_class8.prototype.__init9.call(this);_class8.prototype.__init10.call(this);_class8.prototype.__init11.call(this);_class8.prototype.__init12.call(this);_class8.prototype.__init13.call(this);_class8.prototype.__init14.call(this);_class8.prototype.__init15.call(this);_class8.prototype.__init16.call(this);_class8.prototype.__init17.call(this);this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;this.#e=t.device,_chunkTRE7NUKEcjs.wa.call(void 0, n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}__init9() {this[_chunkTRE7NUKEcjs.a]=!0}__init10() {this.resourceType="buffer"}__init11() {this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC}#e;__init12() {this._buffer=null}__init13() {this._destroyed=!1}__init14() {this.usableAsUniform=!1}__init15() {this.usableAsStorage=!1}__init16() {this.usableAsVertex=!1}__init17() {this.usableAsIndex=!1}get buffer(){if(this._destroyed)throw new Error("This buffer has been destroyed");return this._buffer||(this._buffer=this.#e.createBuffer({size:_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}),this.initial&&(this._writeToTarget(this._buffer.getMappedRange(),this.initial),this._buffer.unmap())),this._buffer}get destroyed(){return this._destroyed}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this._buffer&&(this._buffer.label=t),this}$usage(...t){for(let r of t){if(_optionalChain([this, 'access', _21 => _21._disallowedUsages, 'optionalAccess', _22 => _22.includes, 'call', _23 => _23(r)]))throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${r}`);this.flags|=r==="uniform"?GPUBufferUsage.UNIFORM:0,this.flags|=r==="storage"?GPUBufferUsage.STORAGE:0,this.flags|=r==="vertex"?GPUBufferUsage.VERTEX:0,this.flags|=r==="index"?GPUBufferUsage.INDEX:0,this.usableAsUniform=this.usableAsUniform||r==="uniform",this.usableAsStorage=this.usableAsStorage||r==="storage",this.usableAsVertex=this.usableAsVertex||r==="vertex",this.usableAsIndex=this.usableAsIndex||r==="index"}return this}$addFlags(t){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return t&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):t&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=t,this)}compileWriter(){Br(this.dataType)}_writeToTarget(t,r){let n=Br(this.dataType);if(n)try{n(new DataView(t),0,r,fo==="little");return}catch(a){console.error(`Error when using compiled writer for buffer ${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
16
- Using fallback writer instead.`,a)}Ee(new (0, _typedbinary.BufferWriter)(t),this.dataType,r)}write(t){let r=this.buffer;if(r.mapState==="mapped"){let a=r.getMappedRange();this._writeToTarget(a,t);return}let n=_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(n)),this._writeToTarget(this._hostBuffer,t),this.#e.queue.writeBuffer(r,0,this._hostBuffer,0,n)}writePartial(t){let r=this.buffer,n=aa(this.dataType,t);if(r.mapState==="mapped"){let a=r.getMappedRange(),o=new Uint8Array(a);for(let s of n)o.set(s.data,s.data.byteOffset)}else for(let a of n)this.#e.queue.writeBuffer(r,a.data.byteOffset,a.data,0,a.data.byteLength)}clear(){let t=this.buffer;if(t.mapState==="mapped"){new Uint8Array(t.getMappedRange()).fill(0);return}let r=this.#e.createCommandEncoder();r.clearBuffer(t),this.#e.queue.submit([r.finish()])}copyFrom(t){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType),n=this.#e.createCommandEncoder();n.copyBufferToBuffer(t.buffer,0,this.buffer,0,r),this.#e.queue.submit([n.finish()])}async read(){let t=this.buffer;if(t.mapState==="mapped"){let o=t.getMappedRange();return O(new (0, _typedbinary.BufferReader)(o),this.dataType)}if(t.usage&GPUBufferUsage.MAP_READ){await t.mapAsync(GPUMapMode.READ);let o=t.getMappedRange(),s=O(new (0, _typedbinary.BufferReader)(o),this.dataType);return t.unmap(),s}let r=this.#e.createBuffer({size:_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),n=this.#e.createCommandEncoder();n.copyBufferToBuffer(t,0,r,0,_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType)),this.#e.queue.submit([n.finish()]),await r.mapAsync(GPUMapMode.READ,0,_chunkTRE7NUKEcjs.hc.call(void 0, this.dataType));let a=O(new (0, _typedbinary.BufferReader)(r.getMappedRange()),this.dataType);return r.unmap(),r.destroy(),a}as(t){return _optionalChain([lo, 'access', _24 => _24[t], 'optionalCall', _25 => _25(this)])}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&_optionalChain([this, 'access', _26 => _26._buffer, 'optionalAccess', _27 => _27.destroy, 'call', _28 => _28()]))}toString(){return`buffer:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class8);function fa(e,t){return new Kt(_chunkZYGTVBDHcjs.u.call(void 0, ),e,t)}function da(e,t){return new Kt(_chunkZYGTVBDHcjs.v.call(void 0, ),e,t)}function tt(e){let t=e;return _optionalChain([t, 'optionalAccess', _29 => _29.resourceType])==="sampler"&&!!t[_chunkTRE7NUKEcjs.a]}function rt(e){let t=e;return _optionalChain([t, 'optionalAccess', _30 => _30.resourceType])==="sampler-comparison"&&!!t[_chunkTRE7NUKEcjs.a]}var Ht= (_class9 =class{constructor(t,r){;_class9.prototype.__init18.call(this);this.schema=t;this.#e=r,this.resourceType=t.type==="sampler_comparison"?"sampler-comparison":"sampler",_chunkTRE7NUKEcjs.k.call(void 0, this,r.key)}__init18() {this[_chunkTRE7NUKEcjs.a]={unwrap:void 0}}#e;[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),n=t.allocateLayoutEntry(this.#e.layout);return t.addDeclaration(`@group(${n}) @binding(${this.#e.idx}) var ${r}: ${t.resolve(this.schema).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,this.schema)}get[_chunkTRE7NUKEcjs.b](){let t=this.schema;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.toString()}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to sampler values is possible only as part of a compute dispatch or draw call.")}get value(){return this.$}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class9),Kt=class{constructor(t,r,n){this.schema=t;this.#t=r,this.#n=n,this.resourceType=t.type==="sampler_comparison"?"sampler-comparison":"sampler",this[_chunkTRE7NUKEcjs.a]={unwrap:()=>(this.#r||(this.#r=this.#n.device.createSampler({...this.#t,label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))})),this.#r)},this.#e=r.minFilter==="linear"||r.magFilter==="linear"||r.mipmapFilter==="linear"}#e;#r=null;#t;#n;[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),{group:n,binding:a}=t.allocateFixedEntry(this.schema.type==="sampler_comparison"?{sampler:"comparison"}:{sampler:this.#e?"filtering":"non-filtering"},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${t.resolve(this.schema).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,this.schema)}get[_chunkTRE7NUKEcjs.b](){let t=this.schema;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.toString()}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to sampler values is possible only as part of a compute dispatch or draw call.")}get value(){return this.$}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}};var Yt= (_class10 =class{constructor(t,r){;_class10.prototype.__init19.call(this);_class10.prototype.__init20.call(this);this.schema=t;this.#e=r,_chunkTRE7NUKEcjs.k.call(void 0, this,r.key)}__init19() {this.resourceType="external-texture"}__init20() {this[_chunkTRE7NUKEcjs.a]=!0}#e;[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),n=t.allocateLayoutEntry(this.#e.layout);return t.addDeclaration(`@group(${n}) @binding(${this.#e.idx}) var ${r}: ${t.resolve(this.schema).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,_chunkZYGTVBDHcjs.Q.call(void 0, ))}get[_chunkTRE7NUKEcjs.b](){let t=this.schema;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`textureExternal:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead")}get value(){return this.$}toString(){return`textureExternal:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class10);function Jt(e){return"displayWidth"in e&&"displayHeight"in e?{width:e.displayWidth,height:e.displayHeight}:{width:e.width,height:e.height}}var $r=new WeakMap;function ca(e){let t=$r.get(e);return t||(t=new Map,$r.set(e,t)),t}function ga(e){let t=$r.get(e);t&&t.clear()}function ya(e,t,r=0,n){if(t.dimension!=="2d")throw new Error("Cannot generate mipmaps for non-2D textures: only 2D textures are currently supported.");let a=_nullishCoalesce(n, () => (t.mipLevelCount-r)),o=_chunk3246CM7Ccjs.b.call(void 0, t.format,e);if(![...o.sampleTypes].some(i=>i==="float"||i==="unfilterable-float"))throw new Error(`Cannot generate mipmaps for format '${t.format}': only float and unfilterable-float formats are currently supported.`);if(!o.canRenderAttachment)throw new Error(`Cannot generate mipmaps for format '${t.format}': format does not support render attachments.`);for(let i=0;i<t.depthOrArrayLayers;i++)for(let u=r;u<r+a-1;u++){let l=u,m=u+1;go(e,t,l,m,i)}}function Ta(e,t,r,n){if(t.dimension==="3d")throw new Error("Cannot resample to 3D textures: only 2D textures are currently supported.");let a=_chunk3246CM7Ccjs.a[t.format];if(![...a.sampleTypes].some(s=>s==="float"||s==="unfilterable-float"))throw new Error(`Cannot resample to format '${t.format}': only float and unfilterable-float formats are currently supported.`);if(!a.canRenderAttachment)throw new Error(`Cannot resample to format '${t.format}': format does not support render attachments.`);return co(e,t,r,n)}function co(e,t,r,n=0){let o=[..._chunk3246CM7Ccjs.a[t.format].sampleTypes].includes("float"),s=`${o?"filterable":"unfilterable"}`,i=ca(e),u=i.get(s);if(!u){let F=e.createShaderModule({code:`
17
- struct VertexOutput {
18
- @builtin(position) pos: vec4f,
19
- @location(0) uv: vec2f,
20
- }
21
-
22
- @vertex
23
- fn vs_main(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
24
- let pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
25
- let uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
26
-
27
- var output: VertexOutput;
28
- output.pos = vec4f(pos[vertexIndex], 0, 1);
29
- output.uv = uv[vertexIndex];
30
- return output;
31
- }
32
- `}),R=e.createSampler({magFilter:o?"linear":"nearest",minFilter:o?"linear":"nearest"}),ke=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:o?"filtering":"non-filtering"}}]}),lr=e.createPipelineLayout({bindGroupLayouts:[ke]}),za=e.createShaderModule({code:`
33
- @group(0) @binding(0) var inputTexture: texture_2d<f32>;
34
- @group(0) @binding(1) var inputSampler: sampler;
35
-
36
- @fragment
37
- fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
38
- ${o?"return textureSample(inputTexture, inputSampler, uv);":`let texelCoord = vec2u(uv * vec2f(textureDimensions(inputTexture)));
39
- return textureLoad(inputTexture, texelCoord, 0);`}
40
- }
41
- `});u={vertexShader:F,fragmentShader:za,bindGroupLayout:ke,pipelineLayout:lr,sampler:R},i.set(s,u)}let l=e.createTexture({size:[...Object.values(Jt(r))],format:"rgba8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_DST}),{width:m,height:y}=Jt(r);e.queue.copyExternalImageToTexture({source:r},{texture:l},[m,y,1]);let f=e.createTexture({size:[t.width,t.height,1],format:t.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),T=e.createRenderPipeline({layout:u.pipelineLayout,vertex:{module:u.vertexShader},fragment:{module:u.fragmentShader,targets:[{format:t.format}]},primitive:{topology:"triangle-list"}}),w=e.createBindGroup({layout:u.bindGroupLayout,entries:[{binding:0,resource:l.createView()},{binding:1,resource:u.sampler}]}),x=e.createCommandEncoder(),P=x.beginRenderPass({colorAttachments:[{view:f.createView(),loadOp:"clear",storeOp:"store"}]});P.setPipeline(T),P.setBindGroup(0,w),P.draw(3),P.end(),x.copyTextureToTexture({texture:f},{texture:t,origin:{x:0,y:0,z:n}},{width:t.width,height:t.height,depthOrArrayLayers:1}),e.queue.submit([x.finish()]),l.destroy(),f.destroy()}function go(e,t,r,n,a){let s=[..._chunk3246CM7Ccjs.b.call(void 0, t.format,e).sampleTypes].includes("float"),i=`${s?"filterable":"unfilterable"}`,u=ca(e),l=u.get(i);if(!l){let P=e.createShaderModule({code:`
42
- struct VertexOutput {
43
- @builtin(position) pos: vec4f,
44
- @location(0) uv: vec2f,
45
- }
46
-
47
- @vertex
48
- fn vs_main(@builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
49
- let pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
50
- let uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
51
-
52
- var output: VertexOutput;
53
- output.pos = vec4f(pos[vertexIndex], 0, 1);
54
- output.uv = uv[vertexIndex];
55
- return output;
56
- }
57
- `}),F=e.createShaderModule({code:`
58
- @group(0) @binding(0) var inputTexture: texture_2d<f32>;
59
- @group(0) @binding(1) var inputSampler: sampler;
60
-
61
- @fragment
62
- fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
63
- return textureSample(inputTexture, inputSampler, uv);
64
- }
65
- `}),R=e.createSampler({magFilter:s?"linear":"nearest",minFilter:s?"linear":"nearest"}),ke=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:s?"float":"unfilterable-float"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:s?"filtering":"non-filtering"}}]}),lr=e.createPipelineLayout({bindGroupLayouts:[ke]});l={vertexShader:P,fragmentShader:F,bindGroupLayout:ke,pipelineLayout:lr,sampler:R},u.set(i,l)}let m=e.createRenderPipeline({layout:l.pipelineLayout,vertex:{module:l.vertexShader},fragment:{module:l.fragmentShader,targets:[{format:t.format}]},primitive:{topology:"triangle-list"}}),y=t.createView({baseMipLevel:r,dimension:"2d",mipLevelCount:1,...a!==void 0&&{baseArrayLayer:a,arrayLayerCount:1}}),f=t.createView({baseMipLevel:n,dimension:"2d",mipLevelCount:1,...a!==void 0&&{baseArrayLayer:a,arrayLayerCount:1}}),T=e.createBindGroup({layout:l.bindGroupLayout,entries:[{binding:0,resource:y},{binding:1,resource:l.sampler}]}),w=e.createCommandEncoder(),x=w.beginRenderPass({colorAttachments:[{view:f,loadOp:"clear",storeOp:"store"}]});x.setPipeline(m),x.setBindGroup(0,T),x.draw(3),x.end(),e.queue.submit([w.finish()])}function yo(e){return{dimension:_nullishCoalesce(e.dimension, () => ("2d")),sampleType:_chunk3246CM7Ccjs.a[e.format].channelType,multisampled:(_nullishCoalesce(e.sampleCount, () => (1)))!==1}}function To(e){return e==="depth24plus-stencil8"||e==="depth32float-stencil8"?["depth","stencil"]:e==="depth16unorm"||e==="depth24plus"||e==="depth32float"?["depth"]:e==="stencil8"?["stencil"]:["color"]}function ha(e,t){return new Lr(e,t)}function ee(e){return _optionalChain([e, 'optionalAccess', _31 => _31.resourceType])==="texture"&&!!e[_chunkTRE7NUKEcjs.a]}function he(e){return _optionalChain([e, 'optionalAccess', _32 => _32.resourceType])==="texture-view"&&!!e[_chunkTRE7NUKEcjs.a]}var Lr= (_class11 =class{constructor(t,r){;_class11.prototype.__init21.call(this);_class11.prototype.__init22.call(this);_class11.prototype.__init23.call(this);_class11.prototype.__init24.call(this);this.props=t;let n=t.format;this.#o=r,this.#e=_chunk3246CM7Ccjs.a[n],this.#r=t.size[0]*(_nullishCoalesce(t.size[1], () => (1)))*(_nullishCoalesce(t.size[2], () => (1)))*this.#e.texelSize,this.aspects=To(n),this[_chunkTRE7NUKEcjs.a]={unwrap:()=>{if(this.#t)throw new Error("This texture has been destroyed");return this.#a||(this.#a=r.device.createTexture({label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>")),format:t.format,size:t.size,usage:this.#n,dimension:_nullishCoalesce(t.dimension, () => ("2d")),viewFormats:_nullishCoalesce(t.viewFormats, () => ([])),mipLevelCount:_nullishCoalesce(t.mipLevelCount, () => (1)),sampleCount:_nullishCoalesce(t.sampleCount, () => (1))})),this.#a}}}__init21() {this.resourceType="texture"}__init22() {this.usableAsSampled=!1}__init23() {this.usableAsStorage=!1}__init24() {this.usableAsRender=!1}#e;#r;#t=!1;#n=GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;#a=null;#o;$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}$usage(...t){let r=t.includes("storage"),n=t.includes("sampled"),a=t.includes("render");return this.#n|=n?GPUTextureUsage.TEXTURE_BINDING:0,this.#n|=r?GPUTextureUsage.STORAGE_BINDING:0,this.#n|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||=r,this.usableAsSampled||=n,this.usableAsRender||=a,this}createView(t,r){return new Rr(_nullishCoalesce(t, () => (_chunkZYGTVBDHcjs.y.call(void 0, yo(this.props)))),this,r)}#s(t=0){let r=2**t,[n,a,o]=[Math.max(1,Math.floor((_nullishCoalesce(this.props.size[0], () => (1)))/r)),Math.max(1,Math.floor((_nullishCoalesce(this.props.size[1], () => (1)))/r)),Math.max(1,Math.floor((_nullishCoalesce(this.props.size[2], () => (1)))/r))];this.#o.device.queue.writeTexture({texture:this[_chunkTRE7NUKEcjs.a].unwrap(),mipLevel:t},new Uint8Array(n*a*o*this.#e.texelSize),{bytesPerRow:this.#e.texelSize*n,rowsPerImage:a},[n,a,o])}clear(t="all"){if(t==="all"){let r=_nullishCoalesce(this.props.mipLevelCount, () => (1));for(let n=0;n<r;n++)this.#s(n)}else this.#s(t)}generateMipmaps(t=0,r){if(this.usableAsRender===!1)throw new Error("generateMipmaps called without specifying 'render' usage. Add it via the $usage('render') method.");let n=_nullishCoalesce(r, () => ((_nullishCoalesce(this.props.mipLevelCount, () => (1)))-t));if(n<=1){console.warn(`generateMipmaps is a no-op: would generate ${n} mip levels (base: ${t}, total: ${_nullishCoalesce(this.props.mipLevelCount, () => (1))})`);return}if(t>=(_nullishCoalesce(this.props.mipLevelCount, () => (1))))throw new Error(`Base mip level ${t} is out of range. Texture has ${_nullishCoalesce(this.props.mipLevelCount, () => (1))} mip levels.`);ya(this.#o.device,this[_chunkTRE7NUKEcjs.a].unwrap(),t,n)}write(t,r=0){if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){this.#u(t,r);return}let n=_nullishCoalesce(this.props.dimension, () => ("2d"));if(!Array.isArray(t)){this.#i(t,n==="3d"?0:void 0);return}let o=_nullishCoalesce(this.props.size[2], () => (1));t.length>o&&console.warn(`Too many image sources provided. Expected ${o} layers, got ${t.length}. Extra sources will be ignored.`);for(let s=0;s<Math.min(t.length,o);s++){let i=t[s];i&&this.#i(i,s)}}#u(t,r){let n=Math.max(1,this.props.size[0]>>r),a=Math.max(1,(_nullishCoalesce(this.props.size[1], () => (1)))>>r),o=Math.max(1,(_nullishCoalesce(this.props.size[2], () => (1)))>>r),s=n*a*o*this.#e.texelSize,i=_nullishCoalesce(t.byteLength, () => (t.byteLength));if(i!==s)throw new Error(`Buffer size mismatch. Expected ${s} bytes for mip level ${r}, got ${i} bytes.`);this.#o.device.queue.writeTexture({texture:this[_chunkTRE7NUKEcjs.a].unwrap(),mipLevel:r},t,{bytesPerRow:this.#e.texelSize*n,rowsPerImage:a},[n,a,o])}#i(t,r){let n=this.props.size[0],a=_nullishCoalesce(this.props.size[1], () => (1)),{width:o,height:s}=Jt(t);if(o!==n||s!==a){Ta(this.#o.device,this[_chunkTRE7NUKEcjs.a].unwrap(),t,r);return}this.#o.device.queue.copyExternalImageToTexture({source:t},{texture:this[_chunkTRE7NUKEcjs.a].unwrap(),...r!==void 0&&{origin:{x:0,y:0,z:r}}},r!==void 0?[n,a,1]:this.props.size)}copyFrom(t){if(t.props.format!==this.props.format)throw new Error(`Texture format mismatch. Source texture has format ${t.props.format}, target texture has format ${this.props.format}`);if(t.props.size[0]!==this.props.size[0]||(_nullishCoalesce(t.props.size[1], () => (1)))!==(_nullishCoalesce(this.props.size[1], () => (1)))||(_nullishCoalesce(t.props.size[2], () => (1)))!==(_nullishCoalesce(this.props.size[2], () => (1))))throw new Error(`Texture size mismatch. Source texture has size ${t.props.size.join("x")}, target texture has size ${this.props.size.join("x")}`);let r=this.#o.device.createCommandEncoder();r.copyTextureToTexture({texture:t[_chunkTRE7NUKEcjs.a].unwrap()},{texture:this[_chunkTRE7NUKEcjs.a].unwrap()},t.props.size),this.#o.device.queue.submit([r.finish()])}get destroyed(){return this.#t}destroy(){this.#t||(this.#t=!0,_optionalChain([this, 'access', _33 => _33.#a, 'optionalAccess', _34 => _34.destroy, 'call', _35 => _35()]))}}, _class11),Rr= (_class12 =class{constructor(t,r,n){;_class12.prototype.__init25.call(this);this.schema=t;this.#e=r,this.#t=n,this[_chunkTRE7NUKEcjs.a]={unwrap:()=>{if(!this.#r){let a=this.schema,o;_chunkZYGTVBDHcjs.S.call(void 0, a)?o={label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>")),format:_nullishCoalesce(_optionalChain([this, 'access', _36 => _36.#t, 'optionalAccess', _37 => _37.format]), () => (a.format)),dimension:a.dimension}:o={label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>")),format:_nullishCoalesce(_optionalChain([this, 'access', _38 => _38.#t, 'optionalAccess', _39 => _39.format]), () => (this.#e.props.format)),dimension:a.dimension},_optionalChain([this, 'access', _40 => _40.#t, 'optionalAccess', _41 => _41.mipLevelCount])!==void 0&&(o.mipLevelCount=this.#t.mipLevelCount),_optionalChain([this, 'access', _42 => _42.#t, 'optionalAccess', _43 => _43.arrayLayerCount])!==void 0&&(o.arrayLayerCount=this.#t.arrayLayerCount),this.#r=this.#e[_chunkTRE7NUKEcjs.a].unwrap().createView(o)}return this.#r}}}__init25() {this.resourceType="texture-view"}#e;#r;#t;$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this.#r&&(this.#r.label=t),this}get[_chunkTRE7NUKEcjs.b](){let t=this.schema;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.toString()}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to texture view values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead")}get value(){return this.$}toString(){return`textureView:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),{group:n,binding:a}=t.allocateFixedEntry(_chunkZYGTVBDHcjs.S.call(void 0, this.schema)?{storageTexture:this.schema}:{texture:this.schema,sampleType:_nullishCoalesce(_optionalChain([this, 'access', _44 => _44.#t, 'optionalAccess', _45 => _45.sampleType]), () => (this.schema.bindingSampleType[0]))},this);return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${t.resolve(this.schema).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,this.schema)}}, _class12),nt= (_class13 =class{constructor(t,r){;_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);this.schema=t;this.#e=r,_chunkTRE7NUKEcjs.k.call(void 0, this,r.key)}__init26() {this[_chunkTRE7NUKEcjs.a]={unwrap:void 0}}__init27() {this.resourceType="texture-view"}#e;toString(){return`textureView:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),n=t.allocateLayoutEntry(this.#e.layout);return t.addDeclaration(`@group(${n}) @binding(${this.#e.idx}) var ${r}: ${t.resolve(this.schema).value};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,this.schema)}get[_chunkTRE7NUKEcjs.b](){let t=this.schema;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`${this.toString()}.$`},_chunkZYGTVBDHcjs.r)}get $(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead")}get value(){return this.$}}, _class13);function Gr(e){return!!_optionalChain([e, 'optionalAccess', _46 => _46.usableAsSampled])}function ho(e){return!!_optionalChain([e, 'optionalAccess', _47 => _47.usableAsRender])}var Xt=class e extends Error{constructor(t){super(`Resource '${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, t), () => ("<unnamed>"))}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function xo(e){let t={};for(let[r,n]of Object.entries(e)){if(n===null){t[r]=null;continue}if("texture"in n&&typeof n.texture=="string"){let a=n.texture;t[r]={...n,texture:_chunkZYGTVBDHcjs.y.call(void 0, {dimension:_nullishCoalesce(n.viewDimension, () => ("2d")),sampleType:a==="sint"?_chunkTRE7NUKEcjs.Ta:a==="uint"?_chunkTRE7NUKEcjs.Ra:_chunkTRE7NUKEcjs.Ua,multisampled:_nullishCoalesce(n.multisampled, () => (!1))})}}else if("storageTexture"in n&&typeof n.storageTexture=="string"){let a={readonly:"read-only",writeonly:"write-only",mutable:"read-write"};t[r]={...n,storageTexture:_chunkZYGTVBDHcjs.y.call(void 0, {access:a[_nullishCoalesce(n.access, () => ("writeonly"))],format:n.storageTexture,dimension:_nullishCoalesce(n.viewDimension, () => ("2d"))})}}else"externalTexture"in n&&Object.keys(n.externalTexture).length===0?t[r]={...n,externalTexture:{type:"texture_external",dimension:"2d"}}:t[r]=n}return t}function Zt(e){let t=xo(e);return new Er(t)}function er(e){return!!e&&e.resourceType==="bind-group-layout"}function xe(e){return!!e&&e.resourceType==="bind-group"}var Cr=class e extends Error{constructor(t,r){super(`Bind group '${_nullishCoalesce(t, () => ("<unnamed>"))}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,e.prototype)}},xa=["compute","fragment"],at=["compute","vertex","fragment"],Er= (_class14 =class{constructor(t){;_class14.prototype.__init28.call(this);_class14.prototype.__init29.call(this);_class14.prototype.__init30.call(this);_class14.prototype.__init31.call(this);_class14.prototype.__init32.call(this);this.entries=t;let r=0;for(let[n,a]of Object.entries(t)){if(a===null){r++;continue}let o={layout:this,key:n,idx:r};if("uniform"in a&&(this.bound[n]=new Ze("uniform",a.uniform,o)),"storage"in a){let s="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Ze(_nullishCoalesce(a.access, () => ("readonly")),s,o)}"texture"in a&&(this.bound[n]=new nt(a.texture,o)),"storageTexture"in a&&(this.bound[n]=new nt(a.storageTexture,o)),"externalTexture"in a&&(this.bound[n]=new Yt(a.externalTexture,o)),"sampler"in a&&(this.bound[n]=new Ht(a.sampler==="comparison"?_chunkZYGTVBDHcjs.v.call(void 0, ):_chunkZYGTVBDHcjs.u.call(void 0, ),o)),Object.defineProperty(this.value,n,{get:()=>this.bound[n].value}),r++}}__init28() {this[_chunkTRE7NUKEcjs.a]=!0}__init29() {this.resourceType="bind-group-layout"}__init30() {this.bound={}}__init31() {this.value={}}__init32() {this.$=this.value}get[_chunkTRE7NUKEcjs.b](){return this.$}toString(){return`bindGroupLayout:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get index(){return this._index}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}$idx(t){return this._index=t,this}unwrap(t){return t.device.createBindGroupLayout({label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>")),entries:Object.values(this.entries).map((n,a)=>{if(n===null)return null;let o=n.visibility,s={binding:a,visibility:0};if("uniform"in n)o=_nullishCoalesce(o, () => (at)),s.buffer={type:"uniform"};else if("storage"in n)o=_nullishCoalesce(o, () => ((n.access==="mutable"?xa:at))),s.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=_nullishCoalesce(o, () => (at)),s.sampler={type:n.sampler};else if("texture"in n){o=_nullishCoalesce(o, () => (at));let{multisampled:i,dimension:u,bindingSampleType:l}=n.texture;s.texture={sampleType:_nullishCoalesce(n.sampleType, () => (l[0])),viewDimension:u,multisampled:i}}else if("storageTexture"in n){o=_nullishCoalesce(o, () => (xa));let{dimension:i,access:u,format:l}=n.storageTexture;s.storageTexture={access:u,format:l,viewDimension:i}}else"externalTexture"in n&&(o=_nullishCoalesce(o, () => (at)),s.externalTexture={});return _optionalChain([o, 'optionalAccess', _48 => _48.includes, 'call', _49 => _49("compute")])&&(s.visibility|=GPUShaderStage.COMPUTE),_optionalChain([o, 'optionalAccess', _50 => _50.includes, 'call', _51 => _51("vertex")])&&(s.visibility|=GPUShaderStage.VERTEX),_optionalChain([o, 'optionalAccess', _52 => _52.includes, 'call', _53 => _53("fragment")])&&(s.visibility|=GPUShaderStage.FRAGMENT),s}).filter(n=>n!==null)})}}, _class14),Ve= (_class15 =class{constructor(t,r){;_class15.prototype.__init33.call(this);this.layout=t;this.entries=r;for(let n of Object.keys(t.entries))if(t.entries[n]!==null&&!(n in r))throw new Cr(_chunkTRE7NUKEcjs.j.call(void 0, t),n)}__init33() {this.resourceType="bind-group"}unwrap(t){return t.device.createBindGroup({label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this.layout), () => ("<unnamed>")),layout:t.unwrap(this.layout),entries:Object.entries(this.layout.entries).map(([n,a],o)=>{if(a===null)return null;let s=this.entries[n];if(s===void 0)throw new Error(`'${n}' is a resource required to populate bind group layout '${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this.layout), () => ("<unnamed>"))}'.`);if("uniform"in a){let i;if(le(s)){if(!jt(s))throw new (0, _chunkTRE7NUKEcjs.fa)(s);i={buffer:t.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("storage"in a){let i;if(le(s)){if(!Te(s))throw new Je(s);i={buffer:t.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("texture"in a){let i;if(ee(s)){if(!Gr(s))throw new Xt(s);i=t.unwrap(s.createView(a.texture))}else he(s)?i=t.unwrap(s):i=s;return{binding:o,resource:i}}if("storageTexture"in a){let i;if(ee(s)){if(!Te(s))throw new Je(s);i=t.unwrap(s.createView(a.storageTexture))}else he(s)?i=t.unwrap(s):i=s;return{binding:o,resource:i}}if("sampler"in a)return rt(s)||tt(s)?{binding:o,resource:t.unwrap(s)}:{binding:o,resource:s};if("externalTexture"in a)return{binding:o,resource:s};throw new Error(`Malformed bind group entry: ${_chunkTRE7NUKEcjs.lb.call(void 0, s)}`)}).filter(n=>n!==null)})}}, _class15);function we(e){return new Vr(e)}var Vr= (_class16 =class{constructor(t=void 0){;_class16.prototype.__init34.call(this);_class16.prototype.__init35.call(this);this.defaultValue=t}__init34() {this[_chunkTRE7NUKEcjs.a]=!0}__init35() {this.resourceType="slot"}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}areEqual(t,r){return Object.is(t,r)}toString(){return`slot:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get[_chunkTRE7NUKEcjs.b](){let t=_chunkTRE7NUKEcjs.Aa.call(void 0, );if(!t)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return _chunkZYGTVBDHcjs.s.call(void 0, t.unwrap(this))}get value(){return this[_chunkTRE7NUKEcjs.b]}get $(){return this.value}}, _class16);function _e(e,t){return new ot("private",e,t)}function _r(e){return new ot("workgroup",e)}function wo(e){return e instanceof ot}var ot= (_class17 =class{__init36() {this[_chunkTRE7NUKEcjs.a]={}}#e;#r;#t;constructor(t,r,n){;_class17.prototype.__init36.call(this);this.#e=t,this.#r=r,this.#t=n}[_chunkTRE7NUKEcjs.f](t){let r=t.getUniqueName(this),n=`var<${this.#e}> ${r}: ${t.resolve(this.#r).value}`;return this.#t?t.addDeclaration(`${n} = ${t.resolve(this.#t,this.#r).value};`):t.addDeclaration(`${n};`),_chunkTRE7NUKEcjs.aa.call(void 0, r,this.#r)}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}toString(){return`var:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get[_chunkTRE7NUKEcjs.b](){let t=this.#r;return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,get[_chunkTRE7NUKEcjs.e](){return _chunkTRE7NUKEcjs.aa.call(void 0, this,t)},[_chunkTRE7NUKEcjs.f]:r=>r.resolve(this),toString:()=>`var:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}.$`},_chunkZYGTVBDHcjs.r)}get $(){let t=_chunkTRE7NUKEcjs.Ca.call(void 0, ),r=_chunkTRE7NUKEcjs.ya.call(void 0, );if(t.type==="normal")throw new (0, _chunkTRE7NUKEcjs.ja)(r?`Cannot access variable '${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}'. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation`:"TypeGPU variables are inaccessible during normal JS execution. If you wanted to simulate GPU behavior, try `tgpu.simulate()`");return t.type==="codegen"?this[_chunkTRE7NUKEcjs.b]:t.type==="simulate"?(t.vars[this.#e].has(this)||t.vars[this.#e].set(this,this.#t),t.vars[this.#e].get(this)):_chunkTRE7NUKEcjs.Fa.call(void 0, t,"tgpuVariable.ts#TgpuVarImpl/$")}set $(t){let r=_chunkTRE7NUKEcjs.Ca.call(void 0, ),n=_chunkTRE7NUKEcjs.ya.call(void 0, );if(r.type==="normal")throw new (0, _chunkTRE7NUKEcjs.ja)(n?`Cannot access ${String(this)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation`:"TypeGPU variables are inaccessible during normal JS execution. If you wanted to simulate GPU behavior, try `tgpu.simulate()`");if(r.type==="codegen")throw new Error("Unreachable tgpuVariable.ts#TgpuVarImpl/$");if(r.type==="simulate"){r.vars[this.#e].set(this,t);return}_chunkTRE7NUKEcjs.Fa.call(void 0, r,"tgpuVariable.ts#TgpuVarImpl/$")}get value(){return this.$}set value(t){this.$=t}}, _class17);var wa=_e(_chunkTRE7NUKEcjs.Ra,0).$name("dataBlockIndex"),ba=_e(_chunkTRE7NUKEcjs.Ra,0).$name("dataByteIndex"),Sa=we().$name("dataBuffer"),bo=U([],_chunkTRE7NUKEcjs.Ra)`() {
66
- let i = dataByteIndex;
67
- dataByteIndex = dataByteIndex + 1u;
68
- return i;
69
- }`.$uses({dataByteIndex:ba}).$name("nextByteIndex"),d="dataBuffer[dataBlockIndex].serializedData[nextByteIndex()]",va={f32:U([_chunkTRE7NUKEcjs.Ua])`(n) => {
70
- ${d} = bitcast<u32>(n);
71
- }`,f16:U([_chunkTRE7NUKEcjs.Va])`(n) => {
72
- ${d} = pack2x16float(vec2f(f32(n), 0.0));
73
- }`,i32:U([_chunkTRE7NUKEcjs.Ta])`(n) => {
74
- ${d} = bitcast<u32>(n);
75
- }`,u32:U([_chunkTRE7NUKEcjs.Ra])`(n) => {
76
- ${d} = n;
77
- }`,bool:U([_chunkTRE7NUKEcjs.Qa])`(b) => {
78
- ${d} = u32(b);
79
- }`,vec2f:U([_chunkTRE7NUKEcjs.Xa])`(v) => {
80
- ${d} = bitcast<u32>(v.x);
81
- ${d} = bitcast<u32>(v.y);
82
- }`,vec3f:U([_chunkTRE7NUKEcjs.ab])`(v) => {
83
- ${d} = bitcast<u32>(v.x);
84
- ${d} = bitcast<u32>(v.y);
85
- ${d} = bitcast<u32>(v.z);
86
- }`,vec4f:U([_chunkTRE7NUKEcjs.fb])`(v) => {
87
- ${d} = bitcast<u32>(v.x);
88
- ${d} = bitcast<u32>(v.y);
89
- ${d} = bitcast<u32>(v.z);
90
- ${d} = bitcast<u32>(v.w);
91
- }`,vec2h:U([_chunkTRE7NUKEcjs.Ya])`(v) => {
92
- ${d} = pack2x16float(vec2f(f32(v.x), f32(v.y)));
93
- }`,vec3h:U([_chunkTRE7NUKEcjs.bb])`(v) => {
94
- ${d} = pack2x16float(vec2f(f32(v.x), f32(v.y)));
95
- ${d} = pack2x16float(vec2f(f32(v.z), 0.0));
96
- }`,vec4h:U([_chunkTRE7NUKEcjs.gb])`(v) => {
97
- ${d} = pack2x16float(vec2f(f32(v.x), f32(v.y)));
98
- ${d} = pack2x16float(vec2f(f32(v.z), f32(v.w)));
99
- }`,vec2i:U([_chunkTRE7NUKEcjs.Za])`(v) => {
100
- ${d} = bitcast<u32>(v.x);
101
- ${d} = bitcast<u32>(v.y);
102
- }`,vec3i:U([_chunkTRE7NUKEcjs.cb])`(v) => {
103
- ${d} = bitcast<u32>(v.x);
104
- ${d} = bitcast<u32>(v.y);
105
- ${d} = bitcast<u32>(v.z);
106
- }`,vec4i:U([_chunkTRE7NUKEcjs.hb])`(v) => {
107
- ${d} = bitcast<u32>(v.x);
108
- ${d} = bitcast<u32>(v.y);
109
- ${d} = bitcast<u32>(v.z);
110
- ${d} = bitcast<u32>(v.w);
111
- }`,vec2u:U([_chunkTRE7NUKEcjs._a])`(v) => {
112
- ${d} = v.x;
113
- ${d} = v.y;
114
- }`,vec3u:U([_chunkTRE7NUKEcjs.db])`(v) => {
115
- ${d} = v.x;
116
- ${d} = v.y;
117
- ${d} = v.z;
118
- }`,vec4u:U([_chunkTRE7NUKEcjs.ib])`(v) => {
119
- ${d} = v.x;
120
- ${d} = v.y;
121
- ${d} = v.z;
122
- ${d} = v.w;
123
- }`,"vec2<bool>":U([_chunkTRE7NUKEcjs.$a])`(v) => {
124
- ${d} = u32(v.x);
125
- ${d} = u32(v.y);
126
- }`,"vec3<bool>":U([_chunkTRE7NUKEcjs.eb])`(v) => {
127
- ${d} = u32(v.x);
128
- ${d} = u32(v.y);
129
- ${d} = u32(v.z);
130
- }`,"vec4<bool>":U([_chunkTRE7NUKEcjs.jb])`(v) => {
131
- ${d} = u32(v.x);
132
- ${d} = u32(v.y);
133
- ${d} = u32(v.z);
134
- ${d} = u32(v.w);
135
- }`,mat2x2f:U([_chunkZYGTVBDHcjs.j])`(m) => {
136
- ${d} = bitcast<u32>(m[0][0]);
137
- ${d} = bitcast<u32>(m[0][1]);
138
- ${d} = bitcast<u32>(m[1][0]);
139
- ${d} = bitcast<u32>(m[1][1]);
140
- }`,mat3x3f:U([_chunkZYGTVBDHcjs.k])`(m) => {
141
- ${d} = bitcast<u32>(m[0][0]);
142
- ${d} = bitcast<u32>(m[0][1]);
143
- ${d} = bitcast<u32>(m[0][2]);
144
- ${d} = 0u;
145
- ${d} = bitcast<u32>(m[1][0]);
146
- ${d} = bitcast<u32>(m[1][1]);
147
- ${d} = bitcast<u32>(m[1][2]);
148
- ${d} = 0u;
149
- ${d} = bitcast<u32>(m[2][0]);
150
- ${d} = bitcast<u32>(m[2][1]);
151
- ${d} = bitcast<u32>(m[2][2]);
152
- ${d} = 0u;
153
- }`,mat4x4f:U([_chunkZYGTVBDHcjs.l])`(m) => {
154
- ${d} = bitcast<u32>(m[0][0]);
155
- ${d} = bitcast<u32>(m[0][1]);
156
- ${d} = bitcast<u32>(m[0][2]);
157
- ${d} = bitcast<u32>(m[0][3]);
158
- ${d} = bitcast<u32>(m[1][0]);
159
- ${d} = bitcast<u32>(m[1][1]);
160
- ${d} = bitcast<u32>(m[1][2]);
161
- ${d} = bitcast<u32>(m[1][3]);
162
- ${d} = bitcast<u32>(m[2][0]);
163
- ${d} = bitcast<u32>(m[2][1]);
164
- ${d} = bitcast<u32>(m[2][2]);
165
- ${d} = bitcast<u32>(m[2][3]);
166
- ${d} = bitcast<u32>(m[3][0]);
167
- ${d} = bitcast<u32>(m[3][1]);
168
- ${d} = bitcast<u32>(m[3][2]);
169
- ${d} = bitcast<u32>(m[3][3]);
170
- }`};for(let[e,t]of Object.entries(va))t.$name(`serialize${e[0].toLocaleUpperCase()}${e.slice(1)}`).$uses({dataBlockIndex:wa,nextByteIndex:bo,dataBuffer:Sa});function Ia(e){return`(${e.map((t,r)=>`_arg_${r}`).join(", ")})`}function Ua(e,t){let r=va[e.type];if(r)return r.with(Sa,t);if(_chunkTRE7NUKEcjs.D.call(void 0, e)){let n=Object.keys(e.propTypes),a=Object.values(e.propTypes),o=Fa(a,t);return U([e])`(arg) {\n propsSerializer(${n.map(s=>`arg.${s}`).join(", ")});\n}`.$uses({propsSerializer:o}).$name(`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, e), () => ("struct"))}Serializer`)}if(_chunkTRE7NUKEcjs.C.call(void 0, e)){let n=e.elementType,a=e.elementCount,o=Ua(n,t);return U([e])`(arg) {\n${Array.from({length:a},(s,i)=>` elementSerializer(arg[${i}]);`).join(`
171
- `)}\n}`.$uses({elementSerializer:o}).$name("arraySerializer")}throw new Error(`Cannot serialize data of type ${e.type}`)}function Fa(e,t){let r={},n=U(e),a=Ia(e),o=e.map((s,i)=>(r[`serializer${i}`]=Ua(s,t),` serializer${i}(_arg_${i});`)).join(`
172
- `);return n`${a} {\n${o}\n}`.$uses(r).$name("compoundSerializer")}function Pa(e,t,r,n,a){let o=t.map(_chunkTRE7NUKEcjs.hc).reduce((u,l)=>u+l,0);if(o>a.logSizeLimit)throw new Error(`Logged data needs to fit in ${a.logSizeLimit} bytes (one of the logs requires ${o} bytes). Consider increasing the limit by passing appropriate options to tgpu.init().`);let s=Fa(t,r).$name(`log${e}serializer`),i=Ia(t);return U(t)`${i} {
173
- dataBlockIndex = atomicAdd(&indexBuffer, 1);
174
- if (dataBlockIndex >= ${a.logCountLimit}) {
175
- return;
176
- }
177
- dataBuffer[dataBlockIndex].id = ${e};
178
- dataByteIndex = 0;
179
-
180
- compoundSerializer${i};
181
- }`.$uses({indexBuffer:n,dataBuffer:r,dataBlockIndex:wa,dataByteIndex:ba,compoundSerializer:s}).$name(`log${e}`)}var Da=["log","debug","info","warn","error","clear"];var So={logCountLimit:64,logSizeLimit:252,messagePrefix:" GPU "},Ba=_chunkTRE7NUKEcjs.aa.call(void 0, "/* console.log() */",_chunkTRE7NUKEcjs.q),tr=class{get logResources(){}generateLog(){return console.warn("'console.log' is currently only supported in compute pipelines."),Ba}},rr=class{#e;#r;#t=1;#n;#a;constructor(t){this.#e={...So,...t[_chunkTRE7NUKEcjs.a].logOptions},this.#r=new Map;let r=_chunkTRE7NUKEcjs.rc.call(void 0, {id:_chunkTRE7NUKEcjs.Ra,serializedData:_chunkTRE7NUKEcjs.tc.call(void 0, _chunkTRE7NUKEcjs.Ra,Math.ceil(this.#e.logSizeLimit/4))}).$name("SerializedLogData");this.#a=t.createMutable(_chunkTRE7NUKEcjs.tc.call(void 0, r,this.#e.logCountLimit)).$name("dataBuffer"),this.#n=t.createMutable(_chunkZYGTVBDHcjs.T.call(void 0, _chunkTRE7NUKEcjs.Ra)).$name("indexBuffer")}generateLog(t,r,n){if(!Da.includes(r))return console.warn(`Unsupported log method '${r}' was used in TGSL.`),Ba;let a=_chunkZYGTVBDHcjs.p.call(void 0, n),o=this.#t++,s=a.filter(l=>l.dataType!==_chunkTRE7NUKEcjs.W),i=Pa(o,s.map(l=>l.dataType),this.#a,this.#n,this.#e),u=a.map(l=>l.dataType===_chunkTRE7NUKEcjs.W?l.value:l.dataType);return this.#r.set(o,{op:r,argTypes:u}),_chunkTRE7NUKEcjs.aa.call(void 0, _chunkTRE7NUKEcjs.Ea`${t.resolve(i).value}(${s})`,_chunkTRE7NUKEcjs.q)}get logResources(){return this.#t===1?void 0:{dataBuffer:this.#a,indexBuffer:this.#n,options:this.#e,logIdToMeta:this.#r}}};var Aa="#CATCHALL#",kr= (_class18 =class{constructor() { _class18.prototype.__init37.call(this);_class18.prototype.__init38.call(this); }__init37() {this._stack=[]}__init38() {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}get topFunctionScope(){return this._stack.findLast(t=>t.type==="functionScope")}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}popItem(){this.pop("item")}pushSlotBindings(t){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(t)})}popSlotBindings(){this.pop("slotBinding")}pushFunctionScope(t,r,n,a){let o={type:"functionScope",args:t,argAliases:r,returnType:n,externalMap:a,reportedReturnTypes:new Set};return this._stack.push(o),o}popFunctionScope(){this.pop("functionScope")}pushBlockScope(){this._stack.push({type:"blockScope",declarations:new Map})}popBlockScope(){this.pop("blockScope")}pop(t){let r=this._stack[this._stack.length-1];if(!r||t&&r.type!==t)throw new Error(`Internal error, expected a ${t} layer to be on top.`);this._stack.pop(),t==="item"&&this._itemDepth--}readSlot(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _54 => _54.type])==="item")n.usedSlots.add(t);else if(_optionalChain([n, 'optionalAccess', _55 => _55.type])==="slotBinding"){let a=n.bindingMap.get(t);if(a!==void 0)return a}else if(!(_optionalChain([n, 'optionalAccess', _56 => _56.type])==="functionScope"||_optionalChain([n, 'optionalAccess', _57 => _57.type])==="blockScope"))throw new Error("Unknown layer type.")}return t.defaultValue}getSnippetById(t){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _58 => _58.type])==="functionScope"){let a=n.args.find(s=>s.value===t);if(a!==void 0)return a;if(n.argAliases[t])return n.argAliases[t];let o=n.externalMap[t];return o!=null?_chunkZYGTVBDHcjs.q.call(void 0, o):void 0}if(_optionalChain([n, 'optionalAccess', _59 => _59.type])==="blockScope"){let a=n.declarations.get(t);if(a!==void 0)return a}}}defineBlockVariable(t,r){if(r.dataType.type==="unknown")throw Error(`Tried to define variable '${t}' of unknown type`);for(let n=this._stack.length-1;n>=0;--n){let a=this._stack[n];if(_optionalChain([a, 'optionalAccess', _60 => _60.type])==="blockScope"){a.declarations.set(t,r);return}}throw new Error("No block scope found to define a variable in.")}}, _class18),nr=[""," "," "," "," "," "," "," "," "],Wr=nr.length-1,Mr= (_class19 =class{constructor() { _class19.prototype.__init39.call(this); }__init39() {this.identLevel=0}get pre(){return _nullishCoalesce(nr[this.identLevel], () => (nr[Wr].repeat(this.identLevel/Wr)+nr[this.identLevel%Wr]))}indent(){let t=this.pre;return this.identLevel++,t}dedent(){return this.identLevel--,this.pre}withResetLevel(t){let r=this.identLevel;this.identLevel=0;try{return t()}finally{this.identLevel=r}}}, _class19),st= (_class20 =class{#e;#r;__init40() {this._indentController=new Mr}__init41() {this._itemStateStack=new kr}#t=[];__init42() {this._declarations=[]}#n=new WeakSet;#a;get varyingLocations(){return this._varyingLocations}__init43() {this[_chunkTRE7NUKEcjs.a]={itemStateStack:this._itemStateStack}}__init44() {this.bindGroupLayoutsToPlaceholderMap=new Map}__init45() {this._nextFreeLayoutPlaceholderIdx=0}__init46() {this.fixedBindings=[]}constructor(t){;_class20.prototype.__init40.call(this);_class20.prototype.__init41.call(this);_class20.prototype.__init42.call(this);_class20.prototype.__init43.call(this);_class20.prototype.__init44.call(this);_class20.prototype.__init45.call(this);_class20.prototype.__init46.call(this);this.enableExtensions=t.enableExtensions,this.#r=_nullishCoalesce(t.shaderGenerator, () => (_chunkZYGTVBDHcjs.jb)),this.#a=t.root?new rr(t.root):new tr,this.#e=t.namespace[_chunkTRE7NUKEcjs.a]}getUniqueName(t){return Zn(this.#e,t)}makeNameValid(t){return this.#e.nameRegistry.makeValid(t)}get pre(){return this._indentController.pre}get topFunctionReturnType(){let t=this._itemStateStack.topFunctionScope;return _chunkTRE7NUKEcjs.ba.call(void 0, t,"Internal error, expected function scope to be present."),t.returnType}get shelllessRepo(){return this.#e.shelllessRepo}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}withResetIndentLevel(t){return this._indentController.withResetLevel(t)}getById(t){let r=this._itemStateStack.getSnippetById(t);return r===void 0?null:r}defineVariable(t,r){this._itemStateStack.defineBlockVariable(t,r)}reportReturnType(t){let r=this._itemStateStack.topFunctionScope;_chunkTRE7NUKEcjs.ba.call(void 0, r,"Internal error, expected function scope to be present."),r.reportedReturnTypes.add(t)}pushBlockScope(){this._itemStateStack.pushBlockScope()}popBlockScope(){this._itemStateStack.popBlockScope()}generateLog(t,r){return this.#a.generateLog(this,t,r)}get logResources(){return this.#a.logResources}fnToWgsl(t){let r=this._itemStateStack.pushFunctionScope(t.args,t.argAliases,t.returnType,t.externalMap);try{this.#r.initGenerator(this);let n=this.#r.functionDefinition(t.body),a=t.returnType;if(!a){let o=[...r.reportedReturnTypes];if(o.length===0)a=_chunkTRE7NUKEcjs.q;else{let s=_chunkTRE7NUKEcjs.Ga.call(void 0, o);s&&!s.hasImplicitConversions&&(a=s.targetType)}if(!a)throw new Error(`Expected function to have a single return type, got [${o.join(", ")}]. Cast explicitly to the desired type.`);a=_chunkZYGTVBDHcjs.o.call(void 0, a)}return{head:vo(this,t.args,a),body:n,returnType:a}}finally{this._itemStateStack.popFunctionScope()}}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:Aa,binding:n}}readSlot(t){let r=this._itemStateStack.readSlot(t);if(r===void 0)throw new (0, _chunkTRE7NUKEcjs.ea)(t);return r}withSlots(t,r){this._itemStateStack.pushSlotBindings(t);try{return r()}finally{this._itemStateStack.popSlotBindings()}}withVaryingLocations(t,r){this._varyingLocations=t;try{return r()}finally{this._varyingLocations=void 0}}unwrap(t){if(_chunkTRE7NUKEcjs.oa.call(void 0, t))return this.withSlots(t[_chunkTRE7NUKEcjs.d].pairs,()=>this.unwrap(t[_chunkTRE7NUKEcjs.d].inner));let r=t;for(;;)if(_chunkTRE7NUKEcjs.ma.call(void 0, r))r=this.readSlot(r);else if(_chunkTRE7NUKEcjs.na.call(void 0, r))r=this._getOrCompute(r);else break;return r}_getOrCompute(t){let r=_nullishCoalesce(this.#e.memoizedDerived.get(t), () => ([]));this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([i,u])=>i.areEqual(this._itemStateStack.readSlot(i),u)))return o.result;this.pushMode(new _chunkTRE7NUKEcjs.qa);let n;try{n=t["~compute"]()}finally{this.popMode("normal")}let a=new Map;for(let o of this._itemStateStack.topItem.usedSlots)a.set(o,this._itemStateStack.readSlot(o));return r.push({slotToValueMap:a,result:n}),this.#e.memoizedDerived.set(t,r),n}catch(n){throw n instanceof _chunkTRE7NUKEcjs.ca?n.appendToTrace(t):new (0, _chunkTRE7NUKEcjs.ca)(n,[t])}finally{this._itemStateStack.popItem()}}_getOrInstantiate(t){let r=_nullishCoalesce(this.#e.memoizedResolves.get(t), () => ([]));this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([i,u])=>i.areEqual(this._itemStateStack.readSlot(i),u)))return o.result;let n;if(_chunkTRE7NUKEcjs.V.call(void 0, t))n=_chunkTRE7NUKEcjs.aa.call(void 0, Pr(this,t),_chunkTRE7NUKEcjs.q);else if(_chunkTRE7NUKEcjs.na.call(void 0, t)||_chunkTRE7NUKEcjs.ma.call(void 0, t))n=this.resolve(this.unwrap(t));else if(_chunkTRE7NUKEcjs.ta.call(void 0, t))n=t[_chunkTRE7NUKEcjs.f](this);else if(_chunkTRE7NUKEcjs.m.call(void 0, t)){let o=this.#e.shelllessRepo.get(t,void 0);if(!o)throw new Error(`Couldn't resolve ${t.name}. Make sure it's a function that accepts no arguments, or call it from another TypeGPU function.`);return this.withResetIndentLevel(()=>this.resolve(o))}else throw new TypeError(`Unresolvable internal value: ${_chunkTRE7NUKEcjs.lb.call(void 0, t)}`);let a=new Map;for(let o of this._itemStateStack.topItem.usedSlots)a.set(o,this._itemStateStack.readSlot(o));return r.push({slotToValueMap:a,result:n}),this.#e.memoizedResolves.set(t,r),n}catch(n){throw n instanceof _chunkTRE7NUKEcjs.ca?n.appendToTrace(t):new (0, _chunkTRE7NUKEcjs.ca)(n,[t])}finally{this._itemStateStack.popItem()}}resolve(t,r){if(Ke(t)||_chunkTRE7NUKEcjs.m.call(void 0, t)){if(this.#n.has(t)&&!this.#e.memoizedResolves.has(t))throw new Error(`Recursive function ${t} detected. Recursion is not allowed on the GPU.`);this.#n.add(t)}if(_chunkTRE7NUKEcjs.oa.call(void 0, t))return this.withSlots(t[_chunkTRE7NUKEcjs.d].pairs,()=>this.resolve(t[_chunkTRE7NUKEcjs.d].inner,r));if(_chunkTRE7NUKEcjs.h.call(void 0, t)||_chunkTRE7NUKEcjs.m.call(void 0, t)){if(this._itemStateStack.itemDepth===0)try{this.pushMode(new _chunkTRE7NUKEcjs.ra);let n=_chunkTRE7NUKEcjs.za.call(void 0, this,()=>this._getOrInstantiate(t));return _chunkTRE7NUKEcjs.aa.call(void 0, `${[...this._declarations].join(`
182
-
183
- `)}${n.value}`,_chunkTRE7NUKEcjs.q)}finally{this.popMode("codegen")}return this._getOrInstantiate(t)}if(typeof t=="number"){let n=_nullishCoalesce(r, () => (_chunkZYGTVBDHcjs.n.call(void 0, t).dataType));if(_chunkTRE7NUKEcjs.ba.call(void 0, n.type!=="unknown","Schema has to be known for resolving numbers"),n.type==="abstractInt")return _chunkTRE7NUKEcjs.aa.call(void 0, `${t}`,n);if(n.type==="u32")return _chunkTRE7NUKEcjs.aa.call(void 0, `${t}u`,n);if(n.type==="i32")return _chunkTRE7NUKEcjs.aa.call(void 0, `${t}i`,n);let a=t.toExponential(),o=n.type==="abstractFloat"&&Number.isInteger(t)?`${t}.`:`${t}`,s=a.length<o.length?a:o;return n.type==="f32"?_chunkTRE7NUKEcjs.aa.call(void 0, `${s}f`,n):n.type==="f16"?_chunkTRE7NUKEcjs.aa.call(void 0, `${s}h`,n):_chunkTRE7NUKEcjs.aa.call(void 0, s,n)}if(typeof t=="boolean")return _chunkTRE7NUKEcjs.aa.call(void 0, t?"true":"false",_chunkTRE7NUKEcjs.Qa);if(typeof t=="string")return _chunkTRE7NUKEcjs.aa.call(void 0, t,_chunkTRE7NUKEcjs.q);if(r&&_chunkTRE7NUKEcjs.C.call(void 0, r)){if(!Array.isArray(t))throw new (0, _chunkTRE7NUKEcjs.la)(`Cannot coerce ${t} into value of type '${r}'`);if(r.elementCount!==t.length)throw new (0, _chunkTRE7NUKEcjs.la)(`Cannot create value of type '${r}' from an array of length: ${t.length}`);let n=this.resolve(r.elementType);return _chunkTRE7NUKEcjs.aa.call(void 0, _chunkTRE7NUKEcjs.Ea`array<${n}, ${r.elementCount}>(${t.map(a=>_chunkTRE7NUKEcjs.aa.call(void 0, a,r.elementType))})`,r)}if(Array.isArray(t))return _chunkTRE7NUKEcjs.aa.call(void 0, _chunkTRE7NUKEcjs.Ea`array(${t.map(n=>this.resolve(n))})`,_chunkTRE7NUKEcjs.W);if(r&&_chunkTRE7NUKEcjs.D.call(void 0, r))return _chunkTRE7NUKEcjs.aa.call(void 0, _chunkTRE7NUKEcjs.Ea`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>_chunkTRE7NUKEcjs.aa.call(void 0, t[n],a))})`,r);throw new (0, _chunkTRE7NUKEcjs.la)(`Value ${t} (as json: ${_chunkTRE7NUKEcjs.lb.call(void 0, t)}) is not resolvable${r?` to type ${r.type}`:""}`)}pushMode(t){this.#t.push(t)}popMode(t){let r=this.#t.pop();t!==void 0&&_chunkTRE7NUKEcjs.ba.call(void 0, _optionalChain([r, 'optionalAccess', _61 => _61.type])===t,"Unexpected mode")}get mode(){return _nullishCoalesce(this.#t[this.#t.length-1], () => (_chunkTRE7NUKEcjs.Ba))}}, _class20);function me(e,t){let r=new st(t),a=(t.config?r.withSlots(t.config(new Ge([])).bindings,()=>r.resolve(e)):r.resolve(e)).value,o=r.bindGroupLayoutsToPlaceholderMap,s=[],i=new Set([...o.keys()].map(f=>f.index).filter(f=>f!==void 0)),u=ta(i),l=r.fixedBindings.map((f,T)=>[String(T),f.layoutEntry]),m=()=>{let f=u.next().value,T=Zt(Object.fromEntries(l));return s[f]=T,a=a.replaceAll(Aa,String(f)),[f,new Ve(T,Object.fromEntries(r.fixedBindings.map((w,x)=>[String(x),w.resource])))]},y=l.length>0?m():void 0;for(let[f,T]of o.entries()){let w=_nullishCoalesce(f.index, () => (u.next().value));s[w]=f,a=a.replaceAll(T,String(w))}return t.enableExtensions&&t.enableExtensions.length>0&&(a=`${t.enableExtensions.map(T=>`enable ${T};`).join(`
184
- `)}
185
-
186
- ${a}`),{code:a,usedBindGroupLayouts:s,catchall:y,logResources:r.logResources}}function vo(e,t,r){let n=t.map(a=>`${a.value}: ${e.resolve(a.dataType).value}`).join(", ");return r.type!=="void"?`(${n}) -> ${_chunkTRE7NUKEcjs.pc.call(void 0, r)}${e.resolve(r).value} `:`(${n}) `}function Or(e){let t=e;return _optionalChain([t, 'optionalAccess', _62 => _62.resourceType])==="compute-pipeline"&&!!t[_chunkTRE7NUKEcjs.a]}function zr(e){let t=e;return _optionalChain([t, 'optionalAccess', _63 => _63.resourceType])==="render-pipeline"&&!!t[_chunkTRE7NUKEcjs.a]}function $a(e){return zr(e)||Or(e)}function Nr(e){let{externals:t,shaderGenerator:r,template:n,names:a="random",config:o,enableExtensions:s}=e,i={};_chunk5Y6GTBWRcjs.a.call(void 0, i,_nullishCoalesce(t, () => ({})));let u={[_chunkTRE7NUKEcjs.a]:!0,[_chunkTRE7NUKEcjs.f](m){return _chunkTRE7NUKEcjs.aa.call(void 0, _chunk5Y6GTBWRcjs.d.call(void 0, m,i,_nullishCoalesce(n, () => (""))),_chunkTRE7NUKEcjs.q)},toString:()=>"<root>"},l=Object.values(t).filter($a);if(l.length>1)throw new Error(`Found ${l.length} pipelines but can only resolve one at a time.`);return me(u,{namespace:typeof a=="string"?Q({names:a}):a,enableExtensions:s,shaderGenerator:r,config:o,root:_optionalChain([l, 'access', _64 => _64[0], 'optionalAccess', _65 => _65[_chunkTRE7NUKEcjs.a], 'access', _66 => _66.branch])})}function La(e){return Nr(e).code}function Ra(e){let t=_nullishCoalesce(_chunkTRE7NUKEcjs.Aa.call(void 0, ), () => (new st({namespace:Q(),shaderGenerator:_chunkZYGTVBDHcjs.jb}))),r=[1,1,1],n=[1,1,1],a=[r[0]*n[0],r[1]*n[1],r[2]*n[2]],o=new Map,s=Array.from({length:r[0]},()=>Array.from({length:r[1]},()=>Array.from({length:r[2]},()=>new Map))),i=Array.from({length:a[0]},()=>Array.from({length:a[1]},()=>Array.from({length:a[2]},()=>new Map))),u=Array.from({length:a[0]},(l,m)=>Array.from({length:a[1]},(y,f)=>Array.from({length:a[2]},(T,w)=>{let x=Math.floor(m/n[0]),P=Math.floor(f/n[1]),F=Math.floor(w/n[2]);return new (0, _chunkTRE7NUKEcjs.sa)(o,{private:i[m][f][w],workgroup:s[x][P][F]})})));t.pushMode(u[0][0][0]);try{return{value:_chunkTRE7NUKEcjs.za.call(void 0, t,e),buffers:o,privateVars:i,workgroupVars:s}}finally{t.popMode("simulate")}}function Ga(e,t,r,n){return new qr(e,t,r,n)}function it(e){let t=e;return _optionalChain([t, 'optionalAccess', _67 => _67.resourceType])==="query-set"&&!!t[_chunkTRE7NUKEcjs.a]}var qr= (_class21 =class{constructor(t,r,n,a){;_class21.prototype.__init47.call(this);_class21.prototype.__init48.call(this);_class21.prototype.__init49.call(this);_class21.prototype.__init50.call(this);_class21.prototype.__init51.call(this);_class21.prototype.__init52.call(this);this.type=r;this.count=n;this.rawQuerySet=a;this.#e=t.device,this._ownQuerySet=!a,this._querySet=a||null}__init47() {this.resourceType="query-set"}#e;__init48() {this._querySet=null}__init49() {this._destroyed=!1}__init50() {this._available=!0}__init51() {this._readBuffer=null}__init52() {this._resolveBuffer=null}get querySet(){if(this._destroyed)throw new Error("This QuerySet has been destroyed.");return this.rawQuerySet?this.rawQuerySet:this._querySet?this._querySet:(this._querySet=this.#e.createQuerySet({type:this.type,count:this.count}),this._querySet)}get destroyed(){return this._destroyed}get available(){return this._available}get[_chunkTRE7NUKEcjs.a](){let t=this;return{get readBuffer(){return t._readBuffer||(t._readBuffer=t.#e.createBuffer({size:t.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})),t._readBuffer},get resolveBuffer(){return t._resolveBuffer||(t._resolveBuffer=t.#e.createBuffer({size:t.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),t._resolveBuffer}}}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this._querySet&&(this._querySet.label=t),this}resolve(){if(this._destroyed)throw new Error("This QuerySet has been destroyed.");if(!this._available)throw new Error("This QuerySet is busy resolving or reading.");let t=this.#e.createCommandEncoder();t.resolveQuerySet(this.querySet,0,this.count,this[_chunkTRE7NUKEcjs.a].resolveBuffer,0),this.#e.queue.submit([t.finish()])}async read(){if(!this._resolveBuffer)throw new Error("QuerySet must be resolved before reading.");this._available=!1;try{let t=this.#e.createCommandEncoder();t.copyBufferToBuffer(this[_chunkTRE7NUKEcjs.a].resolveBuffer,0,this[_chunkTRE7NUKEcjs.a].readBuffer,0,this.count*BigUint64Array.BYTES_PER_ELEMENT),this.#e.queue.submit([t.finish()]);let r=this[_chunkTRE7NUKEcjs.a].readBuffer;await r.mapAsync(GPUMapMode.READ);let n=new BigUint64Array(r.getMappedRange().slice());return r.unmap(),Array.from(n)}finally{this._available=!0}}destroy(){this._destroyed||(this._destroyed=!0,this._querySet&&this._ownQuerySet&&this._querySet.destroy(),_optionalChain([this, 'access', _68 => _68._readBuffer, 'optionalAccess', _69 => _69.destroy, 'call', _70 => _70()]),_optionalChain([this, 'access', _71 => _71._resolveBuffer, 'optionalAccess', _72 => _72.destroy, 'call', _73 => _73()]),this._readBuffer=this._resolveBuffer=null)}}, _class21);var ut= (_class22 =class{constructor(t){;_class22.prototype.__init53.call(this);this._make=t}__init53() {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}}, _class22);function Io(e){return e instanceof be}var be= (_class23 =class{constructor(t,r){;_class23.prototype.__init54.call(this);this.resourceType=t;this.buffer=r;this[_chunkTRE7NUKEcjs.c]=r,this.#e=this.buffer.as(this.resourceType)}__init54() {this[_chunkTRE7NUKEcjs.a]=!0}#e;$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this[_chunkTRE7NUKEcjs.c],t),this}write(t){this.buffer.write(t)}writePartial(t){this.buffer.writePartial(t)}read(){return this.buffer.read()}get[_chunkTRE7NUKEcjs.b](){return this.#e.$}get $(){return this.#e.$}get value(){return this.$}[_chunkTRE7NUKEcjs.f](t){return t.resolve(this.#e)}}, _class23);var b=e=>_chunk3246CM7Ccjs.c.call(void 0, _nullishCoalesce(e, () => (0))),H=e=>_chunk3246CM7Ccjs.d.call(void 0, _nullishCoalesce(e, () => (0))),We=e=>_chunk3246CM7Ccjs.e.call(void 0, _nullishCoalesce(e, () => (0))),Uo={f32:e=>b(e[0]),f16:e=>We(e[0]).x,i32:e=>H(e[0]),u32:e=>_nullishCoalesce(e[0], () => (0)),bool:e=>!!e[0],vec2f:e=>_chunkTRE7NUKEcjs.Xa.call(void 0, b(e[0]),b(e[1])),vec3f:e=>_chunkTRE7NUKEcjs.ab.call(void 0, b(e[0]),b(e[1]),b(e[2])),vec4f:e=>_chunkTRE7NUKEcjs.fb.call(void 0, b(e[0]),b(e[1]),b(e[2]),b(e[3])),vec2h(e){let t=We(e[0]);return _chunkTRE7NUKEcjs.Ya.call(void 0, t.x,t.y)},vec3h(e){let t=We(e[0]),r=We(e[1]);return _chunkTRE7NUKEcjs.bb.call(void 0, t.x,t.y,r.x)},vec4h(e){let t=We(e[0]),r=We(e[1]);return _chunkTRE7NUKEcjs.gb.call(void 0, t.x,t.y,r.x,r.y)},vec2i:e=>_chunkTRE7NUKEcjs.Za.call(void 0, H(e[0]),H(e[1])),vec3i:e=>_chunkTRE7NUKEcjs.cb.call(void 0, H(e[0]),H(e[1]),H(e[2])),vec4i:e=>_chunkTRE7NUKEcjs.hb.call(void 0, H(e[0]),H(e[1]),H(e[2]),H(e[3])),vec2u:e=>_chunkTRE7NUKEcjs._a.call(void 0, _nullishCoalesce(e[0], () => (0)),_nullishCoalesce(e[1], () => (0))),vec3u:e=>_chunkTRE7NUKEcjs.db.call(void 0, _nullishCoalesce(e[0], () => (0)),_nullishCoalesce(e[1], () => (0)),_nullishCoalesce(e[2], () => (0))),vec4u:e=>_chunkTRE7NUKEcjs.ib.call(void 0, _nullishCoalesce(e[0], () => (0)),_nullishCoalesce(e[1], () => (0)),_nullishCoalesce(e[2], () => (0)),_nullishCoalesce(e[3], () => (0))),"vec2<bool>":e=>_chunkTRE7NUKEcjs.$a.call(void 0, !!e[0],!!e[1]),"vec3<bool>":e=>_chunkTRE7NUKEcjs.eb.call(void 0, !!e[0],!!e[1],!!e[2]),"vec4<bool>":e=>_chunkTRE7NUKEcjs.jb.call(void 0, !!e[0],!!e[1],!!e[2],!!e[3]),mat2x2f:e=>_chunkZYGTVBDHcjs.j.call(void 0, b(e[0]),b(e[1]),b(e[2]),b(e[3])),mat3x3f:e=>_chunkZYGTVBDHcjs.k.call(void 0, b(e[0]),b(e[1]),b(e[2]),b(e[4]),b(e[5]),b(e[6]),b(e[8]),b(e[9]),b(e[10])),mat4x4f:e=>_chunkZYGTVBDHcjs.l.call(void 0, b(e[0]),b(e[1]),b(e[2]),b(e[3]),b(e[4]),b(e[5]),b(e[6]),b(e[7]),b(e[8]),b(e[9]),b(e[10]),b(e[11]),b(e[12]),b(e[13]),b(e[14]),b(e[15]))};function Fo(e,t){let r=Uo[t.type];if(r)return r(e);if(_chunkTRE7NUKEcjs.D.call(void 0, t)){let n=Object.keys(t.propTypes),a=Object.values(t.propTypes),o=jr(e,a);return Object.fromEntries(n.map((s,i)=>[s,o[i]]))}if(_chunkTRE7NUKEcjs.C.call(void 0, t)){let n=t.elementType,a=t.elementCount;return jr(e,Array.from({length:a},()=>n))}throw new Error(`Cannot deserialize data of type ${t.type}`)}function jr(e,t){let r=0;return t.map(n=>{if(!_chunkTRE7NUKEcjs.B.call(void 0, n))return n;let a=Math.ceil(_chunkTRE7NUKEcjs.hc.call(void 0, n)/4),o=Fo(e.subarray(r,r+a),n);return r+=a,o})}function Po(e,t){return jr(e,t).map(_chunkTRE7NUKEcjs.mb)}function pt(e){let{indexBuffer:t,dataBuffer:r,logIdToMeta:n,options:a}=e;r.read().then(o=>{o.filter(s=>s.id).forEach(({id:s,serializedData:i})=>{let{argTypes:u,op:l}=n.get(s),m=Po(new Uint32Array(i),u);m.length===0&&m.push(""),console[l](`%c${a.messagePrefix}%c ${m[0]}`,"background: #936ff5; color: white;","color: inherit; background: none",...m.slice(1))})}),t.read().then(o=>{o>a.logCountLimit&&console.warn(`Log count limit per dispatch (${a.logCountLimit}) exceeded by ${o-a.logCountLimit} calls. Consider increasing the limit by passing appropriate options to tgpu.init().`)}),r.buffer.clear(),t.buffer.clear()}function ar(e,t,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Performance callback requires the "timestamp-query" feature to be enabled on GPU device.');return e.timestampWrites?{...e,performanceCallback:t}:{...e,performanceCallback:t,hasAutoQuerySet:!0,timestampWrites:{querySet:r.createQuerySet("timestamp",2),beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}}function or(e,t,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Timestamp writes require the "timestamp-query" feature to be enabled on GPU device.');e.hasAutoQuerySet&&e.timestampWrites&&e.timestampWrites.querySet.destroy();let n={querySet:t.querySet};return t.beginningOfPassWriteIndex!==void 0&&(n.beginningOfPassWriteIndex=t.beginningOfPassWriteIndex),t.endOfPassWriteIndex!==void 0&&(n.endOfPassWriteIndex=t.endOfPassWriteIndex),{...e,hasAutoQuerySet:!1,timestampWrites:n}}function sr(e,t){if(!e.timestampWrites)return{};let{querySet:r,beginningOfPassWriteIndex:n,endOfPassWriteIndex:a}=e.timestampWrites,o={querySet:it(r)?t.unwrap(r):r};return n!==void 0&&(o.beginningOfPassWriteIndex=n),a!==void 0&&(o.endOfPassWriteIndex=a),{timestampWrites:o}}function lt({root:e,priors:t}){let r=_optionalChain([t, 'access', _74 => _74.timestampWrites, 'optionalAccess', _75 => _75.querySet]),n=t.performanceCallback;if(!r)throw new Error("Cannot dispatch workgroups with performance callback without a query set.");if(!it(r))throw new Error("Performance callback with raw GPUQuerySet is not supported. Use TgpuQuerySet instead.");let a=e.device.createCommandEncoder();a.resolveQuerySet(e.unwrap(r),0,r.count,r[_chunkTRE7NUKEcjs.a].resolveBuffer,0),e.device.queue.submit([a.finish()]),e.device.queue.onSubmittedWorkDone().then(async()=>{if(!r.available)return;let o=await r.read(),s=o[_nullishCoalesce(_optionalChain([t, 'access', _76 => _76.timestampWrites, 'optionalAccess', _77 => _77.beginningOfPassWriteIndex]), () => (0))],i=o[_nullishCoalesce(_optionalChain([t, 'access', _78 => _78.timestampWrites, 'optionalAccess', _79 => _79.endOfPassWriteIndex]), () => (1))];if(s===void 0||i===void 0)throw new Error("QuerySet did not return valid timestamps.");await n(s,i)})}function Ca(e,t,r){return new Qr(new Hr(e,t,r),{})}var Qr= (_class24 =class e{constructor(t,r){;_class24.prototype.__init55.call(this);this._core=t;this._priors=r;this[_chunkTRE7NUKEcjs.a]={get rawPipeline(){return t.unwrap().pipeline},get priors(){return r},get branch(){return t.branch}},this[_chunkTRE7NUKEcjs.c]=t}__init55() {this.resourceType="compute-pipeline"}[_chunkTRE7NUKEcjs.f](t){return t.resolve(this._core)}toString(){return`computePipeline:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get rawPipeline(){return this._core.unwrap().pipeline}with(t,r){return xe(t)?new e(this._core,{...this._priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(this._priors.bindGroupLayoutMap, () => ([])),[t.layout,t]])}):new e(this._core,{...this._priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(this._priors.bindGroupLayoutMap, () => ([])),[t,r]])})}withPerformanceCallback(t){let r=ar(this._priors,t,this._core.branch);return new e(this._core,r)}withTimestampWrites(t){let r=or(this._priors,t,this._core.branch);return new e(this._core,r)}dispatchWorkgroups(t,r,n){let a=this._core.unwrap(),{branch:o}=this._core,s={label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this._core), () => ("<unnamed>")),...sr(this._priors,o)},i=o.device.createCommandEncoder(),u=i.beginComputePass(s);u.setPipeline(a.pipeline);let l=new Set(a.usedBindGroupLayouts);if(a.usedBindGroupLayouts.forEach((m,y)=>{if(a.catchall&&y===a.catchall[0])u.setBindGroup(y,o.unwrap(a.catchall[1])),l.delete(m);else{let f=_optionalChain([this, 'access', _80 => _80._priors, 'access', _81 => _81.bindGroupLayoutMap, 'optionalAccess', _82 => _82.get, 'call', _83 => _83(m)]);f!==void 0&&(l.delete(m),u.setBindGroup(y,o.unwrap(f)))}}),l.size>0)throw new (0, _chunkTRE7NUKEcjs.ha)(l);u.dispatchWorkgroups(t,r,n),u.end(),o.device.queue.submit([i.finish()]),a.logResources&&pt(a.logResources),this._priors.performanceCallback&&lt({root:o,priors:this._priors})}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this._core,t),this}}, _class24),Hr= (_class25 =class{constructor(t,r,n){;_class25.prototype.__init56.call(this);this.branch=t;this._slotBindings=r;this._entryFn=n}__init56() {this[_chunkTRE7NUKEcjs.a]=!0}[_chunkTRE7NUKEcjs.f](t){return t.withSlots(this._slotBindings,()=>(t.resolve(this._entryFn),_chunkTRE7NUKEcjs.aa.call(void 0, "",_chunkTRE7NUKEcjs.q)))}toString(){return"computePipelineCore"}unwrap(){if(this._memo===void 0){let t=this.branch.device,r=_chunk3246CM7Ccjs.i.filter(y=>this.branch.enabledFeatures.has(_chunk3246CM7Ccjs.j[y])),n,a,o=Q({names:this.branch.nameRegistrySetting});if(_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _84 => _84.enabled])){let y=performance.mark("typegpu:resolution:start");n=me(this,{namespace:o,enableExtensions:r,shaderGenerator:this.branch.shaderGenerator,root:this.branch}),a=performance.measure("typegpu:resolution",{start:y.name})}else n=me(this,{namespace:o,enableExtensions:r,shaderGenerator:this.branch.shaderGenerator,root:this.branch});let{code:s,usedBindGroupLayouts:i,catchall:u,logResources:l}=n;u!==void 0&&_optionalChain([i, 'access', _85 => _85[u[0]], 'optionalAccess', _86 => _86.$name, 'call', _87 => _87(`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let m=t.createShaderModule({label:`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:s});this._memo={pipeline:t.createComputePipeline({label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>")),layout:t.createPipelineLayout({label:`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:i.map(y=>this.branch.unwrap(y))}),compute:{module:m}}),usedBindGroupLayouts:i,catchall:u,logResources:l},_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _88 => _88.enabled])&&(async()=>{let y=performance.mark("typegpu:compile-start");await t.queue.onSubmittedWorkDone();let f=performance.measure("typegpu:compiled",{start:y.name});_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _89 => _89.record, 'call', _90 => _90("resolution",{resolveDuration:_optionalChain([a, 'optionalAccess', _91 => _91.duration]),compileDuration:f.duration,wgslSize:s.length})])})()}return this._memo}}, _class25);function Jr(e,t="vertex"){return new Yr(e,t)}function ur(e){return _optionalChain([e, 'optionalAccess', _92 => _92.resourceType])==="vertex-layout"}var Kr=Symbol("defaultAttribEntry");function ir(e,t,r,n,a){if(_chunkTRE7NUKEcjs.L.call(void 0, t)||_chunkTRE7NUKEcjs.T.call(void 0, t)){let o=_chunkTRE7NUKEcjs.U.call(void 0, t);return o!==void 0&&(n[_nullishCoalesce(a, () => (Kr))]=o),ir(e,t.inner,_chunkTRE7NUKEcjs.gc.call(void 0, r,_chunkTRE7NUKEcjs.ec.call(void 0, t)),n)}if(_chunkTRE7NUKEcjs.D.call(void 0, t)){let o=r,s=t.propTypes;return Object.fromEntries(Object.entries(s).map(([i,u])=>{o=_chunkTRE7NUKEcjs.gc.call(void 0, o,_chunkTRE7NUKEcjs.dc.call(void 0, u));let l=[i,ir(e,u,o,n,i)];return o+=_chunkTRE7NUKEcjs.hc.call(void 0, u),l}))}if(_chunkTRE7NUKEcjs.S.call(void 0, t)){let o=r,s=t.propTypes;return Object.fromEntries(Object.entries(s).map(([i,u])=>{o=_chunkTRE7NUKEcjs.gc.call(void 0, o,_chunkTRE7NUKEcjs.ec.call(void 0, u));let l=[i,ir(e,u,o,n,i)];return o+=_chunkTRE7NUKEcjs.hc.call(void 0, u),l}))}if("type"in t&&typeof t.type=="string"){if(_chunkTRE7NUKEcjs.o.includes(t.type))return{_layout:e,format:t.type,offset:r};let o=_chunkTRE7NUKEcjs.p[t.type];if(o)return{_layout:e,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(t)}`)}var Yr= (_class26 =class{constructor(t,r){;_class26.prototype.__init57.call(this);_class26.prototype.__init58.call(this);_class26.prototype.__init59.call(this);this.schemaForCount=t;this.stepMode=r;let n=t(0);this.stride=_chunkTRE7NUKEcjs.gc.call(void 0, _chunkTRE7NUKEcjs.hc.call(void 0, n.elementType),_chunkTRE7NUKEcjs.dc.call(void 0, n)),this.attrib=ir(this,n.elementType,0,this._customLocationMap)}__init57() {this[_chunkTRE7NUKEcjs.a]=!0}__init58() {this.resourceType="vertex-layout"}__init59() {this._customLocationMap={}}get vertexLayout(){if(this._customLocationMap[Kr]!==void 0){if(typeof this.attrib.format!="string"||typeof this.attrib.offset!="number")throw new Error("Single attribute vertex layouts must have a format and offset.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[{format:this.attrib.format,offset:this.attrib.offset,shaderLocation:this._customLocationMap[Kr]}]}}if(!Object.keys(this.attrib).every(r=>this._customLocationMap[r]!==void 0))throw new Error("All attributes must have custom locations in order to unwrap a vertex layout.");return{arrayStride:this.stride,stepMode:this.stepMode,attributes:[...Object.entries(this.attrib).map(([r,n])=>({format:n.format,offset:n.offset,shaderLocation:this._customLocationMap[r]}))]}}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this,t),this}}, _class26);function Do(e){return typeof _optionalChain([e, 'optionalAccess', _93 => _93.loadOp])=="string"}function Ea(e,t){if(_chunkTRE7NUKEcjs.V.call(void 0, e)){if(!Do(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=e[n];if(_chunkTRE7NUKEcjs.oc.call(void 0, a))continue;let o=t[n];if(!o)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(o)}return r}function Bo(e){return typeof _optionalChain([e, 'optionalAccess', _94 => _94.format])=="string"}function Va(e,t){if(_chunkTRE7NUKEcjs.V.call(void 0, e)){if(_chunkTRE7NUKEcjs.M.call(void 0, e))return[];if(!Bo(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=e[n];if(_chunkTRE7NUKEcjs.oc.call(void 0, a))continue;let o=t[n];if(!o)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(o)}return r}function en(e){return new Xr(new Zr(e),{})}var Xr= (_class27 =class e{__init60() {this.resourceType="render-pipeline"}__init61() {this.hasIndexBuffer=!1}constructor(t,r){;_class27.prototype.__init60.call(this);_class27.prototype.__init61.call(this);this[_chunkTRE7NUKEcjs.a]={core:t,priors:r,branch:t.options.branch},this[_chunkTRE7NUKEcjs.c]=t}[_chunkTRE7NUKEcjs.f](t){return t.resolve(this[_chunkTRE7NUKEcjs.a].core)}toString(){return`renderPipeline:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}$name(t){return _chunkTRE7NUKEcjs.k.call(void 0, this[_chunkTRE7NUKEcjs.a].core,t),this}with(t,r){let n=this[_chunkTRE7NUKEcjs.a];if(xe(t))return new e(n.core,{...n.priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(n.priors.bindGroupLayoutMap, () => ([])),[t.layout,t]])});if(er(t))return new e(n.core,{...n.priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(n.priors.bindGroupLayoutMap, () => ([])),[t,r]])});if(ur(t))return new e(n.core,{...n.priors,vertexLayoutMap:new Map([..._nullishCoalesce(n.priors.vertexLayoutMap, () => ([])),[t,r]])});throw new Error("Unsupported value passed into .with()")}withPerformanceCallback(t){let r=this[_chunkTRE7NUKEcjs.a],n=ar(r.priors,t,r.core.options.branch);return new e(r.core,n)}withTimestampWrites(t){let r=this[_chunkTRE7NUKEcjs.a],n=or(r.priors,t,r.core.options.branch);return new e(r.core,n)}withColorAttachment(t){let r=this[_chunkTRE7NUKEcjs.a];return new e(r.core,{...r.priors,colorAttachment:t})}withDepthStencilAttachment(t){let r=this[_chunkTRE7NUKEcjs.a];return new e(r.core,{...r.priors,depthStencilAttachment:t})}withIndexBuffer(t,r,n,a){let o=this[_chunkTRE7NUKEcjs.a];if(_chunkTRE7NUKEcjs.wa.call(void 0, t)){if(typeof r!="string")throw new Error("If a GPUBuffer is passed, indexFormat must be provided.");return new e(o.core,{...o.priors,indexBuffer:{buffer:t,indexFormat:r,offsetBytes:n,sizeBytes:a}})}let s={u32:"uint32",u16:"uint16"},i=t.dataType.elementType;return new e(o.core,{...o.priors,indexBuffer:{buffer:t,indexFormat:s[i.type],offsetBytes:r!==void 0?r*_chunkTRE7NUKEcjs.hc.call(void 0, i):void 0,sizeBytes:a!==void 0?a*_chunkTRE7NUKEcjs.hc.call(void 0, i):void 0}})}setupRenderPass(t){let r=this[_chunkTRE7NUKEcjs.a],n=r.core.unwrap(),{branch:a,fragmentFn:o}=r.core.options,s=o?Ea(o.shell.out,_nullishCoalesce(r.priors.colorAttachment, () => ({}))).map(f=>ee(f.view)?{...f,view:a.unwrap(f.view).createView()}:he(f.view)?{...f,view:a.unwrap(f.view)}:f):[null],i={label:_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, r.core), () => ("<unnamed>")),colorAttachments:s,...sr(r.priors,a)};if(r.priors.depthStencilAttachment!==void 0){let f=r.priors.depthStencilAttachment;ee(f.view)?i.depthStencilAttachment={...f,view:a.unwrap(f.view).createView()}:i.depthStencilAttachment=f}let u=t.beginRenderPass(i);u.setPipeline(n.pipeline);let l=new Set(n.usedBindGroupLayouts);n.usedBindGroupLayouts.forEach((f,T)=>{if(n.catchall&&T===n.catchall[0])u.setBindGroup(T,a.unwrap(n.catchall[1])),l.delete(f);else{let w=_optionalChain([r, 'access', _95 => _95.priors, 'access', _96 => _96.bindGroupLayoutMap, 'optionalAccess', _97 => _97.get, 'call', _98 => _98(f)]);w!==void 0&&(l.delete(f),u.setBindGroup(T,a.unwrap(w)))}});let m=new Set(r.core.usedVertexLayouts);if(r.core.usedVertexLayouts.forEach((f,T)=>{let w=_optionalChain([r, 'access', _99 => _99.priors, 'access', _100 => _100.vertexLayoutMap, 'optionalAccess', _101 => _101.get, 'call', _102 => _102(f)]);w&&(m.delete(f),u.setVertexBuffer(T,a.unwrap(w)))}),l.size>0)throw new (0, _chunkTRE7NUKEcjs.ha)(l);if(m.size>0)throw new (0, _chunkTRE7NUKEcjs.ia)(m);return u}draw(t,r,n,a){let o=this[_chunkTRE7NUKEcjs.a],{branch:s}=o.core.options,{logResources:i}=o.core.unwrap(),u=s.device.createCommandEncoder(),l=this.setupRenderPass(u);l.draw(t,r,n,a),l.end(),s.device.queue.submit([u.finish()]),i&&pt(i),o.priors.performanceCallback&&lt({root:s,priors:o.priors})}drawIndexed(t,r,n,a,o){let s=this[_chunkTRE7NUKEcjs.a];if(!s.priors.indexBuffer)throw new Error("No index buffer set for this render pipeline.");let{logResources:i}=s.core.unwrap(),{branch:u}=s.core.options,{buffer:l,indexFormat:m,offsetBytes:y,sizeBytes:f}=s.priors.indexBuffer,T=u.device.createCommandEncoder(),w=this.setupRenderPass(T);_chunkTRE7NUKEcjs.wa.call(void 0, l)?w.setIndexBuffer(l,m,y,f):w.setIndexBuffer(u.unwrap(l),m,y,f),w.drawIndexed(t,r,n,a,o),w.end(),u.device.queue.submit([T.finish()]),i&&pt(i),s.priors.performanceCallback&&lt({root:u,priors:s.priors})}}, _class27),Zr= (_class28 =class{constructor(t){;_class28.prototype.__init62.call(this);this.options=t;let r=ea(_nullishCoalesce(t.vertexFn.shell.in, () => ({})),t.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=t.fragmentFn&&t.targets?Va(t.fragmentFn.shell.out,t.targets):[null]}__init62() {this[_chunkTRE7NUKEcjs.a]=!0}[_chunkTRE7NUKEcjs.f](t){let{vertexFn:r,fragmentFn:n,slotBindings:a}=this.options,o=Ao(r.shell.out,_optionalChain([n, 'optionalAccess', _103 => _103.shell, 'access', _104 => _104.in]),_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, r), () => ("<unnamed>")),_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, n), () => ("<unnamed>")));return t.withVaryingLocations(o,()=>t.withSlots(a,()=>(t.resolve(r),n&&t.resolve(n),_chunkTRE7NUKEcjs.aa.call(void 0, "",_chunkTRE7NUKEcjs.q))))}toString(){return"renderPipelineCore"}unwrap(){if(this._memo===void 0){let{branch:t,primitiveState:r,depthStencilState:n,multisampleState:a}=this.options,o=t.device,s=_chunk3246CM7Ccjs.i.filter(F=>t.enabledFeatures.has(_chunk3246CM7Ccjs.j[F])),i,u,l=Q({names:t.nameRegistrySetting});if(_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _105 => _105.enabled])){let F=performance.mark("typegpu:resolution:start");i=me(this,{namespace:l,enableExtensions:s,shaderGenerator:t.shaderGenerator,root:t}),u=performance.measure("typegpu:resolution",{start:F.name})}else i=me(this,{namespace:l,enableExtensions:s,shaderGenerator:t.shaderGenerator,root:t});let{code:m,usedBindGroupLayouts:y,catchall:f,logResources:T}=i;f!==void 0&&_optionalChain([y, 'access', _106 => _106[f[0]], 'optionalAccess', _107 => _107.$name, 'call', _108 => _108(`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let w=o.createShaderModule({label:`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:m}),x={layout:o.createPipelineLayout({label:`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:y.map(F=>t.unwrap(F))}),vertex:{module:w,buffers:this._vertexBufferLayouts}},P=_chunkTRE7NUKEcjs.j.call(void 0, this);P!==void 0&&(x.label=P),this.options.fragmentFn&&(x.fragment={module:w,targets:this._targets}),r&&(_chunkTRE7NUKEcjs.B.call(void 0, r.stripIndexFormat)?x.primitive={...r,stripIndexFormat:{u32:"uint32",u16:"uint16"}[r.stripIndexFormat.type]}:x.primitive=r),n&&(x.depthStencil=n),a&&(x.multisample=a),this._memo={pipeline:o.createRenderPipeline(x),usedBindGroupLayouts:y,catchall:f,logResources:T},_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _109 => _109.enabled])&&(async()=>{let F=performance.mark("typegpu:compile-start");await o.queue.onSubmittedWorkDone();let R=performance.measure("typegpu:compiled",{start:F.name});_optionalChain([_chunkTRE7NUKEcjs.i, 'optionalAccess', _110 => _110.record, 'call', _111 => _111("resolution",{resolveDuration:_optionalChain([u, 'optionalAccess', _112 => _112.duration]),compileDuration:R.duration,wgslSize:m.length})])})()}return this._memo}}, _class28);function Ao(e,t,r,n){let a={},o=new Set;function s(u,l){a[u]=l,o.add(l)}for(let[u,l]of Object.entries(e)){let m=_chunkTRE7NUKEcjs.U.call(void 0, l);m!==void 0&&s(u,m)}for(let[u,l]of Object.entries(_nullishCoalesce(t, () => ({})))){let m=_chunkTRE7NUKEcjs.U.call(void 0, l);m!==void 0&&(a[u]===void 0?s(u,m):a[u]!==m&&console.warn(`Mismatched location between vertexFn (${r}) output (${a[u]}) and fragmentFn (${n}) input (${m}) for the key "${u}", using the location set on vertex output.`))}let i=0;for(let u of Object.keys(_nullishCoalesce(e, () => ({}))))if(!(_chunkTRE7NUKEcjs.oc.call(void 0, e[u])||a[u]!==void 0)){for(;o.has(i);)i++;s(u,i)}return a}function $o(e){if(e.includes(0))throw new Error("Size and workgroupSize cannot contain zeroes.");return _chunkTRE7NUKEcjs.db.call(void 0, _nullishCoalesce(e[0], () => (1)),_nullishCoalesce(e[1], () => (1)),_nullishCoalesce(e[2], () => (1)))}var Lo=[_chunkTRE7NUKEcjs.db.call(void 0, 1,1,1),_chunkTRE7NUKEcjs.db.call(void 0, 256,1,1),_chunkTRE7NUKEcjs.db.call(void 0, 16,16,1),_chunkTRE7NUKEcjs.db.call(void 0, 8,8,4)],tn=class e{#e;#r;#t;#n;#a;constructor(t,r,n,a){this.#e=t,this.#r=r,this.#t=n,this.#n=a,this.#a=_chunkTRE7NUKEcjs.db.call(void 0, )}with(t){return new e(this.#e,this.#r.with(t),this.#t,this.#n)}dispatchThreads(...t){let r=$o(t),n=_chunkZYGTVBDHcjs.ja.call(void 0, _chunkTRE7NUKEcjs.ab.call(void 0, r).div(_chunkTRE7NUKEcjs.ab.call(void 0, this.#n)));_chunk3246CM7Ccjs.k.call(void 0, r,this.#a)||(this.#a=r,this.#t.write(r)),this.#r.dispatchWorkgroups(n.x,n.y,n.z)}},rn=class e{constructor(t,r){this._getRoot=t;this._slotBindings=r}with(t,r){return new e(this._getRoot,[...this._slotBindings,[_chunkTRE7NUKEcjs.pa.call(void 0, t)?t.slot:t,r]])}withCompute(t){return new nn(this._getRoot(),this._slotBindings,t)}createGuardedComputePipeline(t){let r=this._getRoot();if(t.length>=4)throw new Error("Guarded compute callback only supports up to three dimensions.");let n=Lo[t.length],a=U([_chunkTRE7NUKEcjs.Ra,_chunkTRE7NUKEcjs.Ra,_chunkTRE7NUKEcjs.Ra])(t),o=r.createUniform(_chunkTRE7NUKEcjs.db),s=Et({workgroupSize:n,in:{id:_chunkTRE7NUKEcjs.uc.globalInvocationId}})`{
187
- if (any(in.id >= sizeUniform)) {
188
- return;
189
- }
190
- wrappedCallback(in.id.x, in.id.y, in.id.z);
191
- }`.$uses({sizeUniform:o,wrappedCallback:a}),i=this.withCompute(s).createPipeline();return new tn(r,i,o,n)}withVertex(t,r){return new an({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:t,vertexAttribs:r,multisampleState:void 0})}pipe(t){let r=t(new Ge([]));return new e(this._getRoot,[...this._slotBindings,...r.bindings])}},nn=class{constructor(t,r,n){this._root=t;this._slotBindings=r;this._entryFn=n}createPipeline(){return Ca(this._root,this._slotBindings,this._entryFn)}},an=class e{constructor(t){this._options=t}withFragment(t,r,n){return _chunkTRE7NUKEcjs.ba.call(void 0, typeof t!="string","Just type mismatch validation"),_chunkTRE7NUKEcjs.ba.call(void 0, typeof r!="string","Just type mismatch validation"),new on({...this._options,fragmentFn:t,targets:r})}withPrimitive(t){return new e({...this._options,primitiveState:t})}withDepthStencil(t){return new e({...this._options,depthStencilState:t})}withMultisample(t){return new e({...this._options,multisampleState:t})}createPipeline(){return en({...this._options,fragmentFn:null,targets:null})}},on=class e{constructor(t){this._options=t}withPrimitive(t){return new e({...this._options,primitiveState:t})}withDepthStencil(t){return new e({...this._options,depthStencilState:t})}withMultisample(t){return new e({...this._options,multisampleState:t})}createPipeline(){return en(this._options)}},pr= (_class29 =class extends rn{constructor(r,n,a,o,s){super(()=>this,[]);_class29.prototype.__init63.call(this);_class29.prototype.__init64.call(this);;this.device=r;this.nameRegistrySetting=n;this._ownDevice=a;this.shaderGenerator=s;this["~unstable"]=this,this[_chunkTRE7NUKEcjs.a]={logOptions:o}}__init63() {this._unwrappedBindGroupLayouts=new ut(r=>r.unwrap(this))}__init64() {this._unwrappedBindGroups=new ut(r=>r.unwrap(this))}get enabledFeatures(){return new Set(this.device.features)}createBuffer(r,n){return et(this,r,n)}createUniform(r,n){let a=et(this,r,n).$usage("uniform");return new be("uniform",a)}createMutable(r,n){let a=et(this,r,n).$usage("storage");return new be("mutable",a)}createReadonly(r,n){let a=et(this,r,n).$usage("storage");return new be("readonly",a)}createQuerySet(r,n,a){return Ga(this,r,n,a)}createBindGroup(r,n){return new Ve(r,n)}destroy(){ga(this.device),this._ownDevice&&this.device.destroy()}createTexture(r){return ha(r,this)}createSampler(r){return fa(r,this)}createComparisonSampler(r){return da(r,this)}unwrap(r){if(Or(r))return r[_chunkTRE7NUKEcjs.a].rawPipeline;if(zr(r))return r[_chunkTRE7NUKEcjs.a].core.unwrap().pipeline;if(er(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(xe(r))return this._unwrappedBindGroups.getOrMake(r);if(le(r))return r.buffer;if(ee(r))return r[_chunkTRE7NUKEcjs.a].unwrap();if(he(r)){if(!r[_chunkTRE7NUKEcjs.a].unwrap)throw new Error("Cannot unwrap laid-out texture view as it has no underlying resource.");return r[_chunkTRE7NUKEcjs.a].unwrap()}if(ur(r))return r.vertexLayout;if(tt(r)||rt(r)){if(r[_chunkTRE7NUKEcjs.a].unwrap)return r[_chunkTRE7NUKEcjs.a].unwrap();throw new Error("Cannot unwrap laid-out sampler.")}if(it(r))return r.querySet;throw new Error(`Unknown resource type: ${r}`)}beginRenderPass(r,n){let a=this.device.createCommandEncoder(),o=a.beginRenderPass(r),s=new Map,i=new Map,u,l=()=>{if(!u)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:m,priors:y}=u[_chunkTRE7NUKEcjs.a],f=m.unwrap();o.setPipeline(f.pipeline);let T=new Set(f.usedBindGroupLayouts);f.usedBindGroupLayouts.forEach((x,P)=>{if(f.catchall&&P===f.catchall[0])o.setBindGroup(P,this.unwrap(f.catchall[1])),T.delete(x);else{let F=_nullishCoalesce(_optionalChain([y, 'access', _113 => _113.bindGroupLayoutMap, 'optionalAccess', _114 => _114.get, 'call', _115 => _115(x)]), () => (s.get(x)));F!==void 0&&(T.delete(x),xe(F)?o.setBindGroup(P,this.unwrap(F)):o.setBindGroup(P,F))}});let w=new Set;if(m.usedVertexLayouts.forEach((x,P)=>{let F=_optionalChain([y, 'access', _116 => _116.vertexLayoutMap, 'optionalAccess', _117 => _117.get, 'call', _118 => _118(x)]),R=F?{buffer:F,offset:void 0,size:void 0}:i.get(x);!R||!R.buffer?w.add(x):le(R.buffer)?o.setVertexBuffer(P,this.unwrap(R.buffer),R.offset,R.size):o.setVertexBuffer(P,R.buffer,R.offset,R.size)}),T.size>0)throw new (0, _chunkTRE7NUKEcjs.ha)(T);if(w.size>0)throw new (0, _chunkTRE7NUKEcjs.ia)(w)};n({setViewport(...m){o.setViewport(...m)},setScissorRect(...m){o.setScissorRect(...m)},setBlendConstant(...m){o.setBlendConstant(...m)},setStencilReference(...m){o.setStencilReference(...m)},beginOcclusionQuery(...m){o.beginOcclusionQuery(...m)},endOcclusionQuery(...m){o.endOcclusionQuery(...m)},executeBundles(...m){o.executeBundles(...m)},setPipeline(m){u=m},setIndexBuffer:(m,y,f,T)=>{le(m)?o.setIndexBuffer(this.unwrap(m),y,f,T):o.setIndexBuffer(m,y,f,T)},setVertexBuffer(m,y,f,T){i.set(m,{buffer:y,offset:f,size:T})},setBindGroup(m,y){s.set(m,y)},draw(m,y,f,T){l(),o.draw(m,y,f,T)},drawIndexed(...m){l(),o.drawIndexed(...m)},drawIndirect(...m){l(),o.drawIndirect(...m)},drawIndexedIndirect(...m){l(),o.drawIndexedIndirect(...m)}}),o.end(),this.device.queue.submit([a.finish()])}flush(){console.warn("flush() has been deprecated, and has no effect.")}}, _class29);async function _a(e){let{adapter:t,device:r,unstable_names:n="random",unstable_logOptions:a}=_nullishCoalesce(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");let s=[];for(let u of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _119 => _119.requiredFeatures]), () => ([]))){if(!o.features.has(u))throw new Error(`Requested feature "${u}" is not supported by the adapter.`);s.push(u)}for(let u of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _120 => _120.optionalFeatures]), () => ([])))o.features.has(u)?s.push(u):console.warn(`Optional feature "${u}" is not supported by the adapter.`);let i=await o.requestDevice({...r,requiredFeatures:s});return new pr(i,n,!0,_nullishCoalesce(a, () => ({})),_optionalChain([e, 'optionalAccess', _121 => _121.shaderGenerator]))}function Wa(e){let{device:t,unstable_names:r="random",unstable_logOptions:n}=_nullishCoalesce(e, () => ({}));return new pr(t,r,!1,_nullishCoalesce(n, () => ({})),_optionalChain([e, 'optionalAccess', _122 => _122.shaderGenerator]))}function ka(e,t){return new sn(e,t)}var sn= (_class30 =class{constructor(t,r=void 0){;_class30.prototype.__init65.call(this);_class30.prototype.__init66.call(this);this.schema=t;this.defaultValue=r;this.slot=we(r),this[_chunkTRE7NUKEcjs.c]=this.slot}__init65() {this[_chunkTRE7NUKEcjs.a]=!0}__init66() {this.resourceType="accessor"}get[_chunkTRE7NUKEcjs.b](){return new Proxy({[_chunkTRE7NUKEcjs.a]:!0,[_chunkTRE7NUKEcjs.e]:this.#e(),[_chunkTRE7NUKEcjs.f]:t=>t.resolve(this),toString:()=>`accessor:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}.$`},_chunkZYGTVBDHcjs.r)}#e(){let t=_chunkTRE7NUKEcjs.Aa.call(void 0, ),r=_chunkZYGTVBDHcjs.s.call(void 0, t.unwrap(this.slot));return Ke(r)?r[_chunkTRE7NUKEcjs.a].gpuImpl():_chunkTRE7NUKEcjs.aa.call(void 0, r,this.schema)}$name(t){return this.slot.$name(t),this}toString(){return`accessor:${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get value(){if(_chunkTRE7NUKEcjs.Da.call(void 0, ))return this[_chunkTRE7NUKEcjs.b];throw new Error("`tgpu.accessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call")}get $(){return this.value}[_chunkTRE7NUKEcjs.f](t){let r=this.#e();return _chunkTRE7NUKEcjs.aa.call(void 0, t.resolve(r.value,r.dataType).value,r.dataType)}}, _class30);function Ma(e){return Go(e)}function Ro([e,t]){return`${_nullishCoalesce(_chunkTRE7NUKEcjs.j.call(void 0, e), () => ("<unnamed>"))}=${t}`}function Go(e){if(_chunkTRE7NUKEcjs.Aa.call(void 0, ))throw new Error("Cannot create tgpu.derived objects at the resolution stage.");return{[_chunkTRE7NUKEcjs.a]:!0,resourceType:"derived","~compute":e,get[_chunkTRE7NUKEcjs.b](){let r=_chunkTRE7NUKEcjs.Aa.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return _chunkZYGTVBDHcjs.s.call(void 0, r.unwrap(this))},get value(){return this[_chunkTRE7NUKEcjs.b]},get $(){return this.value},with(r,n){return Oa(this,[[r,n]])},toString(){return"derived"}}}function Oa(e,t){return{[_chunkTRE7NUKEcjs.a]:!0,resourceType:"derived","~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},[_chunkTRE7NUKEcjs.d]:{inner:e,pairs:t},get[_chunkTRE7NUKEcjs.b](){let n=_chunkTRE7NUKEcjs.Aa.call(void 0, );if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return _chunkZYGTVBDHcjs.s.call(void 0, n.unwrap(this))},get value(){return this[_chunkTRE7NUKEcjs.b]},get $(){return this.value},with(n,a){return Oa(e,[...t,[n,a]])},toString(){return`derived[${t.map(Ro).join(", ")}]`}}}var Co={fn:U,bindGroupLayout:Zt,vertexLayout:Jr,slot:we,init:_a,initFromDevice:Wa,resolve:La,resolveWithContext:Nr,privateVar:_e,workgroupVar:_r,const:_chunkZYGTVBDHcjs.t,"~unstable":{fn:U,fragmentFn:Yn,vertexFn:_chunk5Y6GTBWRcjs.h,computeFn:Et,vertexLayout:Jr,namespace:Q,derived:Ma,slot:we,accessor:ka,privateVar:_e,workgroupVar:_r,const:_chunkZYGTVBDHcjs.t,declare:Hn,simulate:Ra}},bf= exports.default =Co;exports.MissingBindGroupsError = _chunkTRE7NUKEcjs.ha; exports.MissingLinksError = _chunkTRE7NUKEcjs.ga; exports.MissingSlotValueError = _chunkTRE7NUKEcjs.ea; exports.MissingVertexBuffersError = _chunkTRE7NUKEcjs.ia; exports.NotUniformError = _chunkTRE7NUKEcjs.fa; exports.ResolutionError = _chunkTRE7NUKEcjs.ca; exports.default = bf; exports.isBuffer = le; exports.isBufferShorthand = Io; exports.isComparisonSampler = rt; exports.isDerived = _chunkTRE7NUKEcjs.na; exports.isSampler = tt; exports.isSlot = _chunkTRE7NUKEcjs.ma; exports.isTexture = ee; exports.isTgpuFn = Ke; exports.isUsableAsRender = ho; exports.isUsableAsSampled = Gr; exports.isUsableAsStorage = Te; exports.isUsableAsUniform = jt; exports.isUsableAsVertex = mo; exports.isVariable = wo; exports.tgpu = Co;
192
- //# sourceMappingURL=index.cjs.map