typegpu 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1,20 +1,20 @@
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 _class31; var _class32;var _chunk3K53YJSUcjs = require('./chunk-3K53YJSU.cjs');var _chunkBF35NEOXcjs = require('./chunk-BF35NEOX.cjs');function nn(t){if(typeof _optionalChain([t, 'optionalAccess', _2 => _2[_chunkBF35NEOXcjs.c]])=="function")return t[_chunkBF35NEOXcjs.c].bind(t)}var k={get(t,e){if(e in t)return Reflect.get(t,e);if(e!==_chunkBF35NEOXcjs.e)return e==="toString"||e===Symbol.toStringTag||e===Symbol.toPrimitive?()=>t.toString():new Proxy({"~resolve":r=>`${r.resolve(t)}.${String(e)}`,toString:()=>`.value(...).${String(e)}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, t), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:_chunk3K53YJSUcjs.ja.call(void 0, t[_chunkBF35NEOXcjs.b],String(e))},k)}};function Pe(t,e){let r=e,n;for(;n=nn(r);)r=n(t);return r}function an(t,e){return new Nt(t,e)}var Nt= (_class =class{constructor(e,r){;_class.prototype.__init.call(this);this.dataType=e;this.#e=r}__init() {this[_chunkBF35NEOXcjs.a]={}}#e;$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.resolveValue(this.#e,this.dataType),a=e.resolve(this.dataType);return e.addDeclaration(`const ${r}: ${a} = ${n};`),r}toString(){return`const:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](){return new Proxy({"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:this.dataType},k)}get value(){return _chunkBF35NEOXcjs.la.call(void 0, )?this[_chunkBF35NEOXcjs.c]():this.#e}get $(){return this.value}}, _class);function Y(t,e){for(let[r,n]of Object.entries(e))t[r]=n,_chunkBF35NEOXcjs.l.call(void 0, n)&&_chunkBF35NEOXcjs.j.call(void 0, n)===void 0&&n.$name(r)}function on(t,e,r){let n=[...t.matchAll(/:\s*(?<arg>.*?)\s*[,)]/g)].map(a=>a?a[1]:void 0);r(Object.fromEntries(e.flatMap((a,o)=>{let s=n?n[o]:void 0;return _chunkBF35NEOXcjs.P.call(void 0, a)&&s!==void 0?[[s,a]]:[]})))}function et(t,e,r){let n=t.match(/->\s(?<output>[\w\d_]+)\s{/),a=n?_optionalChain([n, 'access', _3 => _3[1], 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]):void 0;_chunkBF35NEOXcjs.P.call(void 0, e)&&a&&!/\s/g.test(a)&&r({[a]:e})}function na(t){return new RegExp(`(?<![\\w\\$_.])${t.replaceAll(".","\\.").replaceAll("$","\\$")}(?![\\w\\$_])`,"g")}function ie(t,e,r){return Object.entries(e).reduce((n,[a,o])=>_chunkBF35NEOXcjs.ba.call(void 0, o)||_chunk3K53YJSUcjs.d.call(void 0, o)?n.replaceAll(na(a),t.resolve(o)):o!==null&&typeof o=="object"?(_nullishCoalesce([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.").replaceAll("$","\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`,"g"))].map(i=>i[1]), () => ([]))).reduce((i,u)=>u&&u in o?ie(t,{[`${a}.${u}`]:o[u]},i):i,n):n,r)}function sn(t){return new zt(t)}var zt= (_class2 =class{constructor(e){;_class2.prototype.__init2.call(this);this.declaration=e}__init2() {this.externalsToApply=[]}$uses(e){return this.externalsToApply.push(e),this}"~resolve"(e){let r={};for(let a of this.externalsToApply)Y(r,a);let n=ie(e,r,this.declaration);return e.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}}, _class2);var _tinyest = require('tinyest');function ln(t){let{strippedCode:e,argRange:r}=aa(t),n=new tt(e);n.consume("(");let a=[];for(;!n.isAt(")");){let s=[];for(;n.isAt("@");)n.parseUntil(un,pn),n.consume(")"),s.push(n.lastParsed);n.parseUntil(sa);let i=n.lastParsed,u;n.isAt(":")&&(n.consume(":"),n.parseUntil(ia,pa),u=n.lastParsed),a.push({identifier:i,attributes:s,type:u}),n.isAt(",")&&n.consume(",")}n.consume(")");let o;if(n.isAt("->")){n.consume("->");let s=[];for(;n.isAt("@");)n.parseUntil(un,pn),n.consume(")"),s.push(n.lastParsed);o={type:n.str.slice(n.pos),attributes:s}}return{args:a,ret:o,range:{begin:r[0],end:r[1]}}}function aa(t){let e=new tt(t),r="",n;for(;!e.isFinished();){if(e.isAt(oa)){e.advanceBy(1);continue}if(e.isAt("//")){e.consume("//"),e.parseUntil(mn),e.advanceBy(1);continue}if(e.isAt("/*")){e.parseUntil(ua,la),e.consume("*/");continue}if(e.isAt("{"))return{strippedCode:r,argRange:[n,e.pos]};e.isAt("(")&&n===void 0&&(n=e.pos),n!==void 0&&(r+=e.str[e.pos]),e.advanceBy(1)}throw new Error("Invalid wgsl code!")}var tt=class{constructor(e){this.str=e;this.#t=0}#e;#t;get pos(){return this.#t}get lastParsed(){if(this.#e===void 0)throw new Error("Parse was not called yet!");return this.str.slice(this.#e,this.pos)}isFinished(){return this.#t>=this.str.length}isAt(e){if(typeof e=="string"){for(let r=0;r<e.length;r++)if(this.str[this.#t+r]!==e[r])return!1;return!0}for(let r of e)if(this.isAt(r))return!0;return!1}parseUntil(e,r){this.#e=this.#t;let n=0;for(;this.#t<this.str.length;){if(r&&this.isAt(r[0])&&(n+=1),r&&this.isAt(r[1])&&(n-=1),n===0&&this.isAt(e))return this.#t;this.#t+=1}throw new Error("Reached the end of the string without finding a match!")}advanceBy(e){this.#t+=e}consume(e){if(!this.isAt(e))throw new Error(`Expected '${e}' at position ${this.#t}, but found '${this.str.slice(this.#t,this.#t+e.length)}'`);this.advanceBy(e.length)}},mn=new Set([`
2
- `,"\v","\f","\r","\x85","\u2028","\u2029"]),oa=new Set([...mn," "," ","\u200E","\u200F"]),un=new Set([")"]),sa=new Set([":",",",")"]),ia=new Set([",",")"]),ua=new Set(["*/"]),pn=["(",")"],pa=["<",">"],la=["/*","*/"];function J(t,e=""){let r=[],n={applyExternals(o){r.push(o)},resolve(o,s,i){let u={};for(let f of r)Y(u,f);let l=o.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this));if(typeof t=="string"){let f=ie(o,u,t),g="",c="";if(e!==""){let y=_chunkBF35NEOXcjs.P.call(void 0, s[0])?`(in: ${o.resolve(s[0])})`:"()",x=_chunkBF35NEOXcjs.N.call(void 0, i)?_chunk3K53YJSUcjs.ra.call(void 0, i):"",I=i!==_chunkBF35NEOXcjs.D?_chunkBF35NEOXcjs.P.call(void 0, i)?`-> ${o.resolve(i)}`:`-> ${x!==""?x:"@location(0)"} ${o.resolve(i)}`:"";g=`${y} ${I} `,c=f}else{let y=ln(f);if(y.args.length!==s.length)throw new Error(`WGSL implementation has ${y.args.length} arguments, while the shell has ${s.length} arguments.`);let x=y.args.map((w,S)=>`${w.identifier}: ${fn(o,`parameter ${w.identifier}`,w.type,s[S])}`).join(", "),I=i===_chunkBF35NEOXcjs.D?"":`-> ${fn(o,"return type",_optionalChain([y, 'access', _6 => _6.ret, 'optionalAccess', _7 => _7.type]),i)}`;g=`(${x}) ${I}`,c=f.slice(y.range.end)}o.addDeclaration(`${e}fn ${l}${g}${c}`)}else{let f=_chunkBF35NEOXcjs.m.call(void 0, t);if(_optionalChain([f, 'optionalAccess', _8 => _8.externals])){let w=Object.fromEntries(Object.entries(f.externals).filter(([S])=>!(S in u)));Y(u,w)}let g=_optionalChain([f, 'optionalAccess', _9 => _9.ast]);if(!g)throw new Error("Missing metadata for tgpu.fn function body (either missing 'kernel' directive, or misconfigured `unplugin-typegpu`)");let c=g.externalNames.filter(w=>!(w in u));if(c.length>0)throw new (0, _chunkBF35NEOXcjs.s)(_chunkBF35NEOXcjs.j.call(void 0, this),c);let y=g.params[1];y&&y.type==="i"&&e!==""&&Y(u,{[y.name]:_chunkBF35NEOXcjs.na.call(void 0, i)});let{head:x,body:I}=o.fnToWgsl({args:s.map((w,S)=>_chunkBF35NEOXcjs.pa.call(void 0, _optionalChain([g, 'access', _10 => _10.params, 'access', _11 => _11[S], 'optionalAccess', _12 => _12.type])===_tinyest.FuncParameterType.identifier?g.params[S].name:`_arg_${S}`,w)),argAliases:Object.fromEntries(g.params.flatMap((w,S)=>w.type===_tinyest.FuncParameterType.destructuredObject?w.props.map(({name:Fr,alias:ra})=>[ra,_chunkBF35NEOXcjs.pa.call(void 0, `_arg_${S}.${Fr}`,s[S].propTypes[Fr])]):[])),returnType:i,body:g.body,externalMap:u});o.addDeclaration(`${e}fn ${l}${o.resolve(x)}${o.resolve(I)}`)}return l}},a=_chunkBF35NEOXcjs.j.call(void 0, t);return a!==void 0&&_chunkBF35NEOXcjs.k.call(void 0, n,a),n}function fn(t,e,r,n){let a=t.resolve(n).replace(/\s/g,"");if(!r)return a;let o=r.replace(/\s/g,"");if(o!==a)throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${e}, JS type "${a}", WGSL type "${o}".`);return r}function ma(t,e={}){let r=0,n=new Set;return Object.fromEntries(Object.entries(_nullishCoalesce(t, () => ({}))).map(([a,o])=>{let s=_chunk3K53YJSUcjs.h.call(void 0, o);if(s!==void 0){if(n.has(s))throw new Error("Duplicate custom location attributes found");n.add(s)}return[a,o]}).map(([a,o])=>{if(_chunk3K53YJSUcjs.qa.call(void 0, o))return[a,o];if(_chunk3K53YJSUcjs.h.call(void 0, o)!==void 0)return[a,o];if(e[a])return[a,_chunk3K53YJSUcjs.na.call(void 0, e[a],o)];for(;n.has(r);)r++;return[a,_chunk3K53YJSUcjs.na.call(void 0, r++,o)]}))}function X(t,e={}){return _chunk3K53YJSUcjs.i.call(void 0, t)?_chunkBF35NEOXcjs.Y.call(void 0, t)||_chunk3K53YJSUcjs.h.call(void 0, t)!==void 0?t:_chunk3K53YJSUcjs.na.call(void 0, 0,t):_chunk3K53YJSUcjs.sa.call(void 0, ma(t,e))}function Z(t,...e){return da(t)?fa(t,...e):t}function da(t){return Array.isArray(t)&&"raw"in t&&Array.isArray(t.raw)&&t.raw.every(e=>typeof e=="string")}function fa(t,...e){return t.slice(1).reduce((r,n,a)=>`${r}${e[a]}${n}`,t[0])}function gn(t){let e={argTypes:t.in&&Object.keys(t.in).length!==0?[X(t.in)]:[],returnType:_chunkBF35NEOXcjs.D,workgroupSize:[_nullishCoalesce(t.workgroupSize[0], () => (1)),_nullishCoalesce(t.workgroupSize[1], () => (1)),_nullishCoalesce(t.workgroupSize[2], () => (1))],isEntry:!0},r=(n,...a)=>ga(e,t.workgroupSize,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function ga(t,e,r){let n=J(r,`@compute @workgroup_size(${e.join(", ")}) `),a=t.argTypes[0];return{shell:t,$uses(s){return n.applyExternals(s),this},[_chunkBF35NEOXcjs.a]:!0,[_chunkBF35NEOXcjs.d]:n,$name(s){return _chunkBF35NEOXcjs.k.call(void 0, n,s),_chunkBF35NEOXcjs.l.call(void 0, a)&&a.$name(`${s}_Input`),this},"~resolve"(s){return n.resolve(s,t.argTypes,t.returnType)},toString(){return`computeFn:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, n), () => ("<unnamed>"))}`}}}function qt(t,e){let r={[_chunkBF35NEOXcjs.a]:!0,argTypes:t,returnType:_nullishCoalesce(e, () => (_chunkBF35NEOXcjs.D)),isEntry:!1};return Object.assign((a,...o)=>ya(r,Z(a,...o)),r)}function jt(t){return!!_optionalChain([t, 'optionalAccess', _13 => _13[_chunkBF35NEOXcjs.a]])&&_optionalChain([t, 'optionalAccess', _14 => _14.resourceType])==="function"}function ca([t,e]){return`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, t), () => ("<unnamed>"))}=${e}`}function ya(t,e){let r=J(e,""),n={[_chunkBF35NEOXcjs.a]:{implementation:e,argConversionHint:t.argTypes},shell:t,resourceType:"function",$uses(s){return r.applyExternals(s),this},[_chunkBF35NEOXcjs.d]:r,$name(s){return _chunkBF35NEOXcjs.k.call(void 0, r,s),this},with(s,i){return cn(o,[[_chunkBF35NEOXcjs.B.call(void 0, s)?s.slot:s,i]])},"~resolve"(s){return typeof e=="string"&&(on(e,t.argTypes,r.applyExternals),et(e,t.returnType,r.applyExternals)),r.resolve(s,t.argTypes,t.returnType)}},a=_chunkBF35NEOXcjs.ma.call(void 0, (...s)=>_chunkBF35NEOXcjs.fa.call(void 0, ()=>{try{if(typeof e=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");let i=s.map((u,l)=>_chunk3K53YJSUcjs.fa.call(void 0, t.argTypes[l],u));return e(...i)}catch(i){throw i instanceof _chunkBF35NEOXcjs.p?i.appendToTrace(o):new (0, _chunkBF35NEOXcjs.p)(i,[o])}}),(...s)=>_chunkBF35NEOXcjs.pa.call(void 0, new rt(o,s.map(i=>i.value)),_nullishCoalesce(t.returnType, () => (_chunk3K53YJSUcjs.j))),"tgpuFnCall",t.argTypes);a[_chunkBF35NEOXcjs.a].jsImpl=e;let o=Object.assign(a,n);return Object.defineProperty(o,"toString",{value(){return`fn:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}),o}function cn(t,e){let r={[_chunkBF35NEOXcjs.a]:{implementation:t[_chunkBF35NEOXcjs.a].implementation,argConversionHint:t[_chunkBF35NEOXcjs.a].argConversionHint},resourceType:"function",shell:t.shell,[_chunkBF35NEOXcjs.e]:{inner:t,pairs:e},$uses(o){return t.$uses(o),this},[_chunkBF35NEOXcjs.d]:t,$name(o){return t.$name(o),this},with(o,s){return cn(a,[...e,[_chunkBF35NEOXcjs.B.call(void 0, o)?o.slot:o,s]])}},n=_chunkBF35NEOXcjs.ma.call(void 0, (...o)=>t(...o),(...o)=>_chunkBF35NEOXcjs.pa.call(void 0, new rt(a,o.map(s=>s.value)),_nullishCoalesce(t.shell.returnType, () => (_chunk3K53YJSUcjs.j))),"tgpuFnCall",t.shell.argTypes),a=Object.assign(n,r);return Object.defineProperty(a,"toString",{value(){return`fn:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, t), () => ("<unnamed>"))}[${e.map(ca).join(", ")}]`}}),a[_chunkBF35NEOXcjs.a].implementation=t[_chunkBF35NEOXcjs.a].implementation,a}var rt=class{constructor(e,r){this._fn=e;this._params=r;this[_chunkBF35NEOXcjs.d]=e}"~resolve"(e){return e.resolve(`${e.resolve(this._fn)}(${this._params.map(r=>e.resolve(r)).join(", ")})`)}toString(){return`call:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}};function yn(t){let e={in:t.in,out:t.out,returnType:X(t.out),isEntry:!0},r=(n,...a)=>Ta(e,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function Ta(t,e){let r=J(e,"@fragment "),n=t.returnType;return typeof e=="string"&&et(e,n,o=>r.applyExternals(o)),{shell:t,outputType:n,$uses(o){return r.applyExternals(o),this},[_chunkBF35NEOXcjs.a]:!0,[_chunkBF35NEOXcjs.d]:r,$name(o){return _chunkBF35NEOXcjs.k.call(void 0, r,o),_chunkBF35NEOXcjs.l.call(void 0, n)&&n.$name(`${o}_Output`),this},"~resolve"(o){let s=t.in?X(t.in,o.varyingLocations).$name(`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => (""))}_Input`):void 0;return s&&r.applyExternals({In:s}),r.applyExternals({Out:n}),r.resolve(o,s?[s]:[],t.returnType)},toString(){return`fragmentFn:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}}function Tn(t){if(Object.keys(t.out).length===0)throw new Error("A vertexFn output cannot be empty since it must include the 'position' builtin.");let e={in:t.in,out:t.out,argTypes:t.in&&Object.keys(t.in).length!==0?[X(t.in)]:[],isEntry:!0},r=(n,...a)=>xa(e,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function xa(t,e){let r=J(e,"@vertex "),n=t.argTypes[0];return{shell:t,$uses(o){return r.applyExternals(o),this},[_chunkBF35NEOXcjs.a]:!0,[_chunkBF35NEOXcjs.d]:r,$name(o){return _chunkBF35NEOXcjs.k.call(void 0, r,o),_chunkBF35NEOXcjs.l.call(void 0, n)&&n.$name(`${o}_Input`),this},"~resolve"(o){let s=X(t.out,o.varyingLocations).$name(`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => (""))}_Output`);return typeof e=="string"&&(n&&r.applyExternals({In:n}),r.applyExternals({Out:s})),r.resolve(o,t.argTypes,s)},toString(){return`vertexFn:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, r), () => ("<unnamed>"))}`}}}var ue= (_class3 =class{constructor() { _class3.prototype.__init3.call(this); }__init3() {this.lastUniqueId=0}makeUnique(e){let r;return e?(r=e.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}}, _class3),W= (_class4 =class{constructor() { _class4.prototype.__init4.call(this); }__init4() {this._usedNames=new Set}makeUnique(e){if(e===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=e;for(;this._usedNames.has(n);)r++,n=`${e}_${r}`;return this._usedNames.add(n),n}}, _class4);function Be(t){return typeof _optionalChain([t, 'optionalAccess', _15 => _15.format])=="string"}function xn(t,e){let r=[];if(_chunk3K53YJSUcjs.i.call(void 0, t)){if(!Be(e))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(e._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:e._layout.stride,stepMode:e._layout.stepMode,attributes:[{format:e.format,offset:e.offset,shaderLocation:_nullishCoalesce(_chunk3K53YJSUcjs.h.call(void 0, t), () => (0))}]}]}}let n=[],a=new WeakMap,o=0;for(let[s,i]of Object.entries(t)){if(_chunk3K53YJSUcjs.qa.call(void 0, i))continue;let u=e[s];if(!u)throw new Error(`An attribute by the name of '${s}' was not provided to the shader.`);let l=u._layout,f=a.get(l);f||(r.push(l),f=[],n.push({arrayStride:l.stride,stepMode:l.stepMode,attributes:f}),a.set(l,f)),o=_nullishCoalesce(_chunk3K53YJSUcjs.h.call(void 0, i), () => (o)),f.push({format:u.format,offset:u.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var ha=["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"];function ba(t){return ha.includes(t.type)}function Qt(t,[e,r]){return` ${_chunk3K53YJSUcjs.ra.call(void 0, r)}${e}: ${t.resolve(r)},
3
- `}function wa(t,e){let r=t.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, e));return t.addDeclaration(`struct ${r} {
4
- ${Object.entries(e.propTypes).map(n=>Qt(t,n)).join("")}}`),r}function Sa(t,e){let r=t.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, e));return t.addDeclaration(`struct ${r} {
5
- ${Object.entries(e.propTypes).map(n=>Be(n[1])?Qt(t,[n[0],_chunk3K53YJSUcjs.k[n[1].format]]):Qt(t,n)).join("")}
6
- }`),r}function va(t,e){let r=t.resolve(e.elementType);return e.elementCount===0?`array<${r}>`:`array<${r}, ${e.elementCount}>`}function Ia(t,e){let r=t.resolve(Be(e.elementType)?_chunk3K53YJSUcjs.k[e.elementType.format]:e.elementType);return e.elementCount===0?`array<${r}>`:`array<${r}, ${e.elementCount}>`}function Ht(t,e){if(_chunk3K53YJSUcjs.d.call(void 0, e))return e.type==="unstruct"?Sa(t,e):e.type==="disarray"?Ia(t,e):e.type==="loose-decorated"?t.resolve(Be(e.inner)?_chunk3K53YJSUcjs.k[e.inner.format]:e.inner):t.resolve(_chunk3K53YJSUcjs.k[e.type]);if(ba(e))return e.type;if(e.type==="struct")return wa(t,e);if(e.type==="array")return va(t,e);if(e.type==="atomic")return`atomic<${Ht(t,e.inner)}>`;if(e.type==="decorated")return t.resolve(e.inner);if(e.type==="ptr")return e.addressSpace==="storage"?`ptr<storage, ${t.resolve(e.inner)}, ${e.access==="read-write"?"read_write":e.access}>`:`ptr<${e.addressSpace}, ${t.resolve(e.inner)}>`;if(e.type==="abstractInt"||e.type==="abstractFloat"||e.type==="void"||e.type==="u16")throw new Error(`${e.type} has no representation in WGSL`);_chunk3K53YJSUcjs.ia.call(void 0, e,"resolveData")}var be=class t{constructor(e){this.bindings=e}with(e,r){return new t([...this.bindings,[_chunkBF35NEOXcjs.B.call(void 0, e)?e.slot:e,r]])}pipe(e){let r=e(this);return new t([...this.bindings,...r.bindings])}};function*hn(t){let e=0;for(;;)t.has(e)||(yield e),e++}var _typedbinary = require('typed-binary');function Da(t,e){let r="size"in t?t.size:t.currentByteOffset,n=e-1,a=r&n;"skipBytes"in t?t.skipBytes(e-a&n):t.add(e-a&n)}var F=Da;var bn=new WeakMap;function nt(t){let e=bn.get(t);if(e)return e;let r=new _typedbinary.Measurer,n={},a;for(let o in t.propTypes){let s=t.propTypes[o];if(s===void 0)throw new Error(`Property ${o} is undefined in struct`);let i=r.size;F(r,_chunk3K53YJSUcjs.f.call(void 0, t)?_chunk3K53YJSUcjs.ba.call(void 0, s):_chunk3K53YJSUcjs.aa.call(void 0, s)),a&&(a.padding=r.size-i);let u=_chunk3K53YJSUcjs.da.call(void 0, s);n[o]={offset:r.size,size:u},a=n[o],r.add(u)}return a&&(a.padding=_chunk3K53YJSUcjs.a.call(void 0, _chunk3K53YJSUcjs.da.call(void 0, t),_chunk3K53YJSUcjs.aa.call(void 0, t))-r.size),bn.set(t,n),n}var Ua=(()=>{try{return new Function("return true"),!0}catch (e2){return!1}})(),Kt=new WeakMap,at={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"},Pa={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"},ot={u32:"setUint32",i32:"setInt32",f32:"setFloat32",u16:"setUint16",i16:"setInt16",f16:"setFloat16",u8:"setUint8",i8:"setInt8"},Ba={unorm8:t=>`Math.round(${t} * 255)`,unorm8x2:t=>`Math.round(${t} * 255)`,unorm8x4:t=>`Math.round(${t} * 255)`,snorm8:t=>`Math.round(${t} * 127)`,snorm8x2:t=>`Math.round(${t} * 127)`,snorm8x4:t=>`Math.round(${t} * 127)`,unorm16:t=>`Math.round(${t} * 65535)`,unorm16x2:t=>`Math.round(${t} * 65535)`,unorm16x4:t=>`Math.round(${t} * 65535)`,snorm16:t=>`Math.round(${t} * 32767)`,snorm16x2:t=>`Math.round(${t} * 32767)`,snorm16x4:t=>`Math.round(${t} * 32767)`},wn={"unorm10-10-10-2":{writeFunction:"setUint32",generator:(t,e)=>`output.setUint32(${t}, ((${e}.x*1023&0x3FF)<<22)|((${e}.y*1023&0x3FF)<<12)|((${e}.z*1023&0x3FF)<<2)|(${e}.w*3&3), littleEndian);
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 _class31; var _class32; var _class33; var _class34; var _class35;var _chunkCYZBRBPDcjs = require('./chunk-CYZBRBPD.cjs');var _chunk2VTISQYPcjs = require('./chunk-2VTISQYP.cjs');function rn(t){if(typeof _optionalChain([t, 'optionalAccess', _2 => _2[_chunk2VTISQYPcjs.c]])=="function")return t[_chunk2VTISQYPcjs.c].bind(t)}var k={get(t,e){if(e in t)return Reflect.get(t,e);if(e!==_chunk2VTISQYPcjs.e)return e==="toString"||e===Symbol.toStringTag||e===Symbol.toPrimitive?()=>t.toString():new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":r=>`${r.resolve(t)}.${String(e)}`,toString:()=>`.value(...).${String(e)}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, t), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:_chunk2VTISQYPcjs.jb.call(void 0, t[_chunk2VTISQYPcjs.b],String(e))},k)}};function Pe(t,e){let r=e,n;for(;n=rn(r);)r=n(t);return r}function nn(t,e){return new kt(t,e)}var kt= (_class =class{constructor(e,r){;_class.prototype.__init.call(this);this.dataType=e;this.#e=r}__init() {this[_chunk2VTISQYPcjs.a]={}}#e;$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.resolve(this.#e,this.dataType),a=e.resolve(this.dataType);return e.addDeclaration(`const ${r}: ${a} = ${n};`),r}toString(){return`const:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](){return new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:this.dataType},k)}get value(){return _chunk2VTISQYPcjs.ga.call(void 0, )?this[_chunk2VTISQYPcjs.c]():this.#e}get $(){return this.value}}, _class);function Y(t,e){for(let[r,n]of Object.entries(e))t[r]=n,_chunk2VTISQYPcjs.i.call(void 0, n)&&_chunk2VTISQYPcjs.g.call(void 0, n)===void 0&&n.$name(r)}function an(t,e,r){let n=[...t.matchAll(/:\s*(?<arg>.*?)\s*[,)]/g)].map(a=>a?a[1]:void 0);r(Object.fromEntries(e.flatMap((a,o)=>{let s=n?n[o]:void 0;return _chunk2VTISQYPcjs.K.call(void 0, a)&&s!==void 0?[[s,a]]:[]})))}function et(t,e,r){let n=t.match(/->\s(?<output>[\w\d_]+)\s{/),a=n?_optionalChain([n, 'access', _3 => _3[1], 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]):void 0;_chunk2VTISQYPcjs.K.call(void 0, e)&&a&&!/\s/g.test(a)&&r({[a]:e})}function ra(t){return new RegExp(`(?<![\\w\\$_.])${t.replaceAll(".","\\.").replaceAll("$","\\$")}(?![\\w\\$_])`,"g")}function ie(t,e,r){return Object.entries(e).reduce((n,[a,o])=>_chunk2VTISQYPcjs.Y.call(void 0, o)||_chunk2VTISQYPcjs.ja.call(void 0, o)?n.replaceAll(ra(a),t.resolve(o)):o!==null&&typeof o=="object"?(_nullishCoalesce([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.").replaceAll("$","\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`,"g"))].map(i=>i[1]), () => ([]))).reduce((i,p)=>p&&p in o?ie(t,{[`${a}.${p}`]:o[p]},i):i,n):n,r)}function on(t){return new Mt(t)}var Mt= (_class2 =class{constructor(e){;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);this.declaration=e}__init2() {this[_chunk2VTISQYPcjs.a]=!0}__init3() {this.externalsToApply=[]}$uses(e){return this.externalsToApply.push(e),this}"~resolve"(e){let r={};for(let a of this.externalsToApply)Y(r,a);let n=ie(e,r,this.declaration);return e.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}}, _class2);var _tinyest = require('tinyest');function pn(t){let{strippedCode:e,argRange:r}=na(t),n=new tt(e);n.consume("(");let a=[];for(;!n.isAt(")");){let s=[];for(;n.isAt("@");)n.parseUntil(sn,un),n.consume(")"),s.push(n.lastParsed);n.parseUntil(oa);let i=n.lastParsed,p;n.isAt(":")&&(n.consume(":"),n.parseUntil(sa,ua),p=n.lastParsed),a.push({identifier:i,attributes:s,type:p}),n.isAt(",")&&n.consume(",")}n.consume(")");let o;if(n.isAt("->")){n.consume("->");let s=[];for(;n.isAt("@");)n.parseUntil(sn,un),n.consume(")"),s.push(n.lastParsed);o={type:n.str.slice(n.pos),attributes:s}}return{args:a,ret:o,range:{begin:r[0],end:r[1]}}}function na(t){let e=new tt(t),r="",n;for(;!e.isFinished();){if(e.isAt(aa)){e.advanceBy(1);continue}if(e.isAt("//")){e.consume("//"),e.parseUntil(ln),e.advanceBy(1);continue}if(e.isAt("/*")){e.parseUntil(ia,pa),e.consume("*/");continue}if(e.isAt("{"))return{strippedCode:r,argRange:[n,e.pos]};e.isAt("(")&&n===void 0&&(n=e.pos),n!==void 0&&(r+=e.str[e.pos]),e.advanceBy(1)}throw new Error("Invalid wgsl code!")}var tt=class{constructor(e){this.str=e;this.#t=0}#e;#t;get pos(){return this.#t}get lastParsed(){if(this.#e===void 0)throw new Error("Parse was not called yet!");return this.str.slice(this.#e,this.pos)}isFinished(){return this.#t>=this.str.length}isAt(e){if(typeof e=="string"){for(let r=0;r<e.length;r++)if(this.str[this.#t+r]!==e[r])return!1;return!0}for(let r of e)if(this.isAt(r))return!0;return!1}parseUntil(e,r){this.#e=this.#t;let n=0;for(;this.#t<this.str.length;){if(r&&this.isAt(r[0])&&(n+=1),r&&this.isAt(r[1])&&(n-=1),n===0&&this.isAt(e))return this.#t;this.#t+=1}throw new Error("Reached the end of the string without finding a match!")}advanceBy(e){this.#t+=e}consume(e){if(!this.isAt(e))throw new Error(`Expected '${e}' at position ${this.#t}, but found '${this.str.slice(this.#t,this.#t+e.length)}'`);this.advanceBy(e.length)}},ln=new Set([`
2
+ `,"\v","\f","\r","\x85","\u2028","\u2029"]),aa=new Set([...ln," "," ","\u200E","\u200F"]),sn=new Set([")"]),oa=new Set([":",",",")"]),sa=new Set([",",")"]),ia=new Set(["*/"]),un=["(",")"],ua=["<",">"],pa=["/*","*/"];function J(t,e=""){let r=[],n={applyExternals(o){r.push(o)},resolve(o,s,i){let p={};for(let f of r)Y(p,f);let l=o.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this));if(typeof t=="string"){let f=ie(o,p,t),g="",c="";if(e!==""){let y=_chunk2VTISQYPcjs.K.call(void 0, s[0])?`(in: ${o.resolve(s[0])})`:"()",x=_chunk2VTISQYPcjs.I.call(void 0, i)?_chunkCYZBRBPDcjs.m.call(void 0, i):"",I=i!==_chunk2VTISQYPcjs.z?_chunk2VTISQYPcjs.K.call(void 0, i)?`-> ${o.resolve(i)}`:`-> ${x!==""?x:"@location(0)"} ${o.resolve(i)}`:"";g=`${y} ${I} `,c=f}else{let y=pn(f);if(y.args.length!==s.length)throw new Error(`WGSL implementation has ${y.args.length} arguments, while the shell has ${s.length} arguments.`);let x=y.args.map((w,S)=>`${w.identifier}: ${dn(o,`parameter ${w.identifier}`,w.type,s[S])}`).join(", "),I=i===_chunk2VTISQYPcjs.z?"":`-> ${dn(o,"return type",_optionalChain([y, 'access', _6 => _6.ret, 'optionalAccess', _7 => _7.type]),i)}`;g=`(${x}) ${I}`,c=f.slice(y.range.end)}o.addDeclaration(`${e}fn ${l}${g}${c}`)}else{let f=_chunk2VTISQYPcjs.j.call(void 0, t);if(_optionalChain([f, 'optionalAccess', _8 => _8.externals])){let w=Object.fromEntries(Object.entries(f.externals).filter(([S])=>!(S in p)));Y(p,w)}let g=_optionalChain([f, 'optionalAccess', _9 => _9.ast]);if(!g)throw new Error("Missing metadata for tgpu.fn function body (either missing 'kernel' directive, or misconfigured `unplugin-typegpu`)");let c=g.externalNames.filter(w=>!(w in p));if(c.length>0)throw new (0, _chunk2VTISQYPcjs.p)(_chunk2VTISQYPcjs.g.call(void 0, this),c);let y=g.params[1];y&&y.type==="i"&&e!==""&&Y(p,{[y.name]:_chunk2VTISQYPcjs.ta.call(void 0, i)});let{head:x,body:I}=o.fnToWgsl({args:s.map((w,S)=>_chunk2VTISQYPcjs.wa.call(void 0, _optionalChain([g, 'access', _10 => _10.params, 'access', _11 => _11[S], 'optionalAccess', _12 => _12.type])===_tinyest.FuncParameterType.identifier?g.params[S].name:`_arg_${S}`,w)),argAliases:Object.fromEntries(g.params.flatMap((w,S)=>w.type===_tinyest.FuncParameterType.destructuredObject?w.props.map(({name:vr,alias:ta})=>[ta,_chunk2VTISQYPcjs.wa.call(void 0, `_arg_${S}.${vr}`,s[S].propTypes[vr])]):[])),returnType:i,body:g.body,externalMap:p});o.addDeclaration(`${e}fn ${l}${o.resolve(x)}${o.resolve(I)}`)}return l}},a=_chunk2VTISQYPcjs.g.call(void 0, t);return a!==void 0&&_chunk2VTISQYPcjs.h.call(void 0, n,a),n}function dn(t,e,r,n){let a=t.resolve(n).replace(/\s/g,"");if(!r)return a;let o=r.replace(/\s/g,"");if(o!==a)throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${e}, JS type "${a}", WGSL type "${o}".`);return r}function la(t,e={}){let r=0,n=new Set;return Object.fromEntries(Object.entries(_nullishCoalesce(t, () => ({}))).map(([a,o])=>{let s=_chunk2VTISQYPcjs.pa.call(void 0, o);if(s!==void 0){if(n.has(s))throw new Error("Duplicate custom location attributes found");n.add(s)}return[a,o]}).map(([a,o])=>{if(_chunkCYZBRBPDcjs.l.call(void 0, o))return[a,o];if(_chunk2VTISQYPcjs.pa.call(void 0, o)!==void 0)return[a,o];if(e[a])return[a,_chunkCYZBRBPDcjs.i.call(void 0, e[a],o)];for(;n.has(r);)r++;return[a,_chunkCYZBRBPDcjs.i.call(void 0, r++,o)]}))}function X(t,e={}){return _chunk2VTISQYPcjs.qa.call(void 0, t)?_chunk2VTISQYPcjs.T.call(void 0, t)||_chunk2VTISQYPcjs.pa.call(void 0, t)!==void 0?t:_chunkCYZBRBPDcjs.i.call(void 0, 0,t):_chunk2VTISQYPcjs.jc.call(void 0, la(t,e))}function Z(t,...e){return ma(t)?da(t,...e):t}function ma(t){return Array.isArray(t)&&"raw"in t&&Array.isArray(t.raw)&&t.raw.every(e=>typeof e=="string")}function da(t,...e){return t.slice(1).reduce((r,n,a)=>`${r}${e[a]}${n}`,t[0])}function fn(t){let e={argTypes:t.in&&Object.keys(t.in).length!==0?[X(t.in)]:[],returnType:_chunk2VTISQYPcjs.z,workgroupSize:[_nullishCoalesce(t.workgroupSize[0], () => (1)),_nullishCoalesce(t.workgroupSize[1], () => (1)),_nullishCoalesce(t.workgroupSize[2], () => (1))],isEntry:!0},r=(n,...a)=>fa(e,t.workgroupSize,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function fa(t,e,r){let n=J(r,`@compute @workgroup_size(${e.join(", ")}) `),a=t.argTypes[0];return{shell:t,$uses(s){return n.applyExternals(s),this},[_chunk2VTISQYPcjs.a]:!0,[_chunk2VTISQYPcjs.d]:n,$name(s){return _chunk2VTISQYPcjs.h.call(void 0, n,s),_chunk2VTISQYPcjs.i.call(void 0, a)&&a.$name(`${s}_Input`),this},"~resolve"(s){return n.resolve(s,t.argTypes,t.returnType)},toString(){return`computeFn:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, n), () => ("<unnamed>"))}`}}}function Wt(t,e){let r={[_chunk2VTISQYPcjs.a]:!0,argTypes:t,returnType:_nullishCoalesce(e, () => (_chunk2VTISQYPcjs.z)),isEntry:!1};return Object.assign((a,...o)=>ca(r,Z(a,...o)),r)}function Nt(t){return!!_optionalChain([t, 'optionalAccess', _13 => _13[_chunk2VTISQYPcjs.a]])&&_optionalChain([t, 'optionalAccess', _14 => _14.resourceType])==="function"}function ga([t,e]){return`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, t), () => ("<unnamed>"))}=${e}`}function ca(t,e){let r=J(e,""),n={shell:t,resourceType:"function",$uses(s){return r.applyExternals(s),this},[_chunk2VTISQYPcjs.d]:r,$name(s){return _chunk2VTISQYPcjs.h.call(void 0, r,s),this},with(s,i){return gn(o,[[_chunk2VTISQYPcjs.y.call(void 0, s)?s.slot:s,i]])},"~resolve"(s){return typeof e=="string"&&(an(e,t.argTypes,r.applyExternals),et(e,t.returnType,r.applyExternals)),r.resolve(s,t.argTypes,t.returnType)}},a=_chunk2VTISQYPcjs.ya.call(void 0, (...s)=>_chunk2VTISQYPcjs.aa.call(void 0, ()=>{try{if(typeof e=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");let i=s.map((p,l)=>_chunk2VTISQYPcjs.ic.call(void 0, t.argTypes[l],p));return e(...i)}catch(i){throw i instanceof _chunk2VTISQYPcjs.m?i.appendToTrace(o):new (0, _chunk2VTISQYPcjs.m)(i,[o])}}),(...s)=>_chunk2VTISQYPcjs.wa.call(void 0, new rt(o,s),t.returnType),"tgpuFnCall",t.argTypes),o=Object.assign(a,n);return o[_chunk2VTISQYPcjs.a].implementation=e,Object.defineProperty(o,"toString",{value(){return`fn:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, r), () => ("<unnamed>"))}`}}),o}function gn(t,e){let r={resourceType:"function",shell:t.shell,[_chunk2VTISQYPcjs.e]:{inner:t,pairs:e},$uses(o){return t.$uses(o),this},[_chunk2VTISQYPcjs.d]:t,$name(o){return t.$name(o),this},with(o,s){return gn(a,[...e,[_chunk2VTISQYPcjs.y.call(void 0, o)?o.slot:o,s]])}},n=_chunk2VTISQYPcjs.ya.call(void 0, (...o)=>t(...o),(...o)=>_chunk2VTISQYPcjs.wa.call(void 0, new rt(a,o),t.shell.returnType),"tgpuFnCall",t.shell.argTypes),a=Object.assign(n,r);return a[_chunk2VTISQYPcjs.a].implementation=t[_chunk2VTISQYPcjs.a].implementation,Object.defineProperty(a,"toString",{value(){return`fn:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, t), () => ("<unnamed>"))}[${e.map(ga).join(", ")}]`}}),a[_chunk2VTISQYPcjs.a].implementation=t[_chunk2VTISQYPcjs.a].implementation,a}var rt= (_class3 =class{__init4() {this[_chunk2VTISQYPcjs.a]=!0}#e;#t;constructor(e,r){;_class3.prototype.__init4.call(this);this.#e=e,this.#t=r,this[_chunk2VTISQYPcjs.d]=e}"~resolve"(e){return e.withResetIndentLevel(()=>_chunk2VTISQYPcjs.xa`${e.resolve(this.#e)}(${this.#t})`)}toString(){return`call:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class3);function cn(t){let e={in:t.in,out:t.out,returnType:X(t.out),isEntry:!0},r=(n,...a)=>ya(e,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function ya(t,e){let r=J(e,"@fragment "),n=t.returnType;return typeof e=="string"&&et(e,n,o=>r.applyExternals(o)),{shell:t,outputType:n,$uses(o){return r.applyExternals(o),this},[_chunk2VTISQYPcjs.a]:!0,[_chunk2VTISQYPcjs.d]:r,$name(o){return _chunk2VTISQYPcjs.h.call(void 0, r,o),_chunk2VTISQYPcjs.i.call(void 0, n)&&n.$name(`${o}_Output`),this},"~resolve"(o){let s=t.in?X(t.in,o.varyingLocations).$name(`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => (""))}_Input`):void 0;return s&&r.applyExternals({In:s}),r.applyExternals({Out:n}),r.resolve(o,s?[s]:[],t.returnType)},toString(){return`fragmentFn:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, r), () => ("<unnamed>"))}`}}}function yn(t){if(Object.keys(t.out).length===0)throw new Error("A vertexFn output cannot be empty since it must include the 'position' builtin.");let e={in:t.in,out:t.out,argTypes:t.in&&Object.keys(t.in).length!==0?[X(t.in)]:[],isEntry:!0},r=(n,...a)=>Ta(e,Z(n,...a));return Object.assign(Object.assign(r,e),{does:r})}function Ta(t,e){let r=J(e,"@vertex "),n=t.argTypes[0];return{shell:t,$uses(o){return r.applyExternals(o),this},[_chunk2VTISQYPcjs.a]:!0,[_chunk2VTISQYPcjs.d]:r,$name(o){return _chunk2VTISQYPcjs.h.call(void 0, r,o),_chunk2VTISQYPcjs.i.call(void 0, n)&&n.$name(`${o}_Input`),this},"~resolve"(o){let s=X(t.out,o.varyingLocations).$name(`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => (""))}_Output`);return typeof e=="string"&&(n&&r.applyExternals({In:n}),r.applyExternals({Out:s})),r.resolve(o,t.argTypes,s)},toString(){return`vertexFn:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, r), () => ("<unnamed>"))}`}}}var ue= (_class4 =class{constructor() { _class4.prototype.__init5.call(this); }__init5() {this.lastUniqueId=0}makeUnique(e){let r;return e?(r=e.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}}, _class4),W= (_class5 =class{constructor() { _class5.prototype.__init6.call(this); }__init6() {this._usedNames=new Set}makeUnique(e){if(e===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=e;for(;this._usedNames.has(n);)r++,n=`${e}_${r}`;return this._usedNames.add(n),n}}, _class5);function Be(t){return typeof _optionalChain([t, 'optionalAccess', _15 => _15.format])=="string"}function Tn(t,e){let r=[];if(_chunk2VTISQYPcjs.qa.call(void 0, t)){if(!Be(e))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(e._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:e._layout.stride,stepMode:e._layout.stepMode,attributes:[{format:e.format,offset:e.offset,shaderLocation:_nullishCoalesce(_chunk2VTISQYPcjs.pa.call(void 0, t), () => (0))}]}]}}let n=[],a=new WeakMap,o=0;for(let[s,i]of Object.entries(t)){if(_chunkCYZBRBPDcjs.l.call(void 0, i))continue;let p=e[s];if(!p)throw new Error(`An attribute by the name of '${s}' was not provided to the shader.`);let l=p._layout,f=a.get(l);f||(r.push(l),f=[],n.push({arrayStride:l.stride,stepMode:l.stepMode,attributes:f}),a.set(l,f)),o=_nullishCoalesce(_chunk2VTISQYPcjs.pa.call(void 0, i), () => (o)),f.push({format:p.format,offset:p.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var xa=["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"];function ha(t){return xa.includes(t.type)}function zt(t,[e,r]){return` ${_chunkCYZBRBPDcjs.m.call(void 0, r)}${e}: ${t.resolve(r)},
3
+ `}function ba(t,e){if(e[_chunk2VTISQYPcjs.a].isAbstruct)throw new Error("Cannot resolve abstract struct types to WGSL.");let r=t.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, e));return t.addDeclaration(`struct ${r} {
4
+ ${Object.entries(e.propTypes).map(n=>zt(t,n)).join("")}}`),r}function wa(t,e){let r=t.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, e));return t.addDeclaration(`struct ${r} {
5
+ ${Object.entries(e.propTypes).map(n=>Be(n[1])?zt(t,[n[0],_chunk2VTISQYPcjs.sb[n[1].format]]):zt(t,n)).join("")}
6
+ }`),r}function Sa(t,e){let r=t.resolve(e.elementType);return e.elementCount===0?`array<${r}>`:`array<${r}, ${e.elementCount}>`}function va(t,e){let r=t.resolve(Be(e.elementType)?_chunk2VTISQYPcjs.sb[e.elementType.format]:e.elementType);return e.elementCount===0?`array<${r}>`:`array<${r}, ${e.elementCount}>`}function qt(t,e){if(_chunk2VTISQYPcjs.ja.call(void 0, e))return e.type==="unstruct"?wa(t,e):e.type==="disarray"?va(t,e):e.type==="loose-decorated"?t.resolve(Be(e.inner)?_chunk2VTISQYPcjs.sb[e.inner.format]:e.inner):t.resolve(_chunk2VTISQYPcjs.sb[e.type]);if(ha(e))return e.type;if(e.type==="struct")return ba(t,e);if(e.type==="array")return Sa(t,e);if(e.type==="atomic")return`atomic<${qt(t,e.inner)}>`;if(e.type==="decorated")return t.resolve(e.inner);if(e.type==="ptr")return e.addressSpace==="storage"?`ptr<storage, ${t.resolve(e.inner)}, ${e.access==="read-write"?"read_write":e.access}>`:`ptr<${e.addressSpace}, ${t.resolve(e.inner)}>`;if(e.type==="abstractInt"||e.type==="abstractFloat"||e.type==="void"||e.type==="u16")throw new Error(`${e.type} has no representation in WGSL`);_chunk2VTISQYPcjs.ib.call(void 0, e,"resolveData")}var be=class t{constructor(e){this.bindings=e}with(e,r){return new t([...this.bindings,[_chunk2VTISQYPcjs.y.call(void 0, e)?e.slot:e,r]])}pipe(e){let r=e(this);return new t([...this.bindings,...r.bindings])}};function*xn(t){let e=0;for(;;)t.has(e)||(yield e),e++}var _typedbinary = require('typed-binary');function Da(t,e){let r="size"in t?t.size:t.currentByteOffset,n=e-1,a=r&n;"skipBytes"in t?t.skipBytes(e-a&n):t.add(e-a&n)}var F=Da;var hn=new WeakMap;function nt(t){let e=hn.get(t);if(e)return e;let r=new _typedbinary.Measurer,n={},a;for(let o in t.propTypes){let s=t.propTypes[o];if(s===void 0)throw new Error(`Property ${o} is undefined in struct`);let i=r.size;F(r,_chunk2VTISQYPcjs.la.call(void 0, t)?_chunkCYZBRBPDcjs.b.call(void 0, s):_chunkCYZBRBPDcjs.a.call(void 0, s)),a&&(a.padding=r.size-i);let p=_chunkCYZBRBPDcjs.e.call(void 0, s);n[o]={offset:r.size,size:p},a=n[o],r.add(p)}return a&&(a.padding=_chunkCYZBRBPDcjs.d.call(void 0, _chunkCYZBRBPDcjs.e.call(void 0, t),_chunkCYZBRBPDcjs.a.call(void 0, t))-r.size),hn.set(t,n),n}var Fa=(()=>{try{return new Function("return true"),!0}catch (e2){return!1}})(),jt=new WeakMap,at={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"},Ua={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"},ot={u32:"setUint32",i32:"setInt32",f32:"setFloat32",u16:"setUint16",i16:"setInt16",f16:"setFloat16",u8:"setUint8",i8:"setInt8"},Pa={unorm8:t=>`Math.round(${t} * 255)`,unorm8x2:t=>`Math.round(${t} * 255)`,unorm8x4:t=>`Math.round(${t} * 255)`,snorm8:t=>`Math.round(${t} * 127)`,snorm8x2:t=>`Math.round(${t} * 127)`,snorm8x4:t=>`Math.round(${t} * 127)`,unorm16:t=>`Math.round(${t} * 65535)`,unorm16x2:t=>`Math.round(${t} * 65535)`,unorm16x4:t=>`Math.round(${t} * 65535)`,snorm16:t=>`Math.round(${t} * 32767)`,snorm16x2:t=>`Math.round(${t} * 32767)`,snorm16x4:t=>`Math.round(${t} * 32767)`},bn={"unorm10-10-10-2":{writeFunction:"setUint32",generator:(t,e)=>`output.setUint32(${t}, ((${e}.x*1023&0x3FF)<<22)|((${e}.y*1023&0x3FF)<<12)|((${e}.z*1023&0x3FF)<<2)|(${e}.w*3&3), littleEndian);
7
7
  `},"unorm8x4-bgra":{writeFunction:"setUint8",generator:(t,e)=>{let r=["z","y","x","w"],n="";for(let a=0;a<4;a++)n+=`output.setUint8((${t} + ${a}), Math.round(${e}.${r[a]} * 255), littleEndian);
8
- `;return n}}};function st(t,e,r){if(_chunkBF35NEOXcjs.R.call(void 0, t)||_chunkBF35NEOXcjs.X.call(void 0, t))return st(t.inner,e,r);if(_chunkBF35NEOXcjs.P.call(void 0, t)||_chunk3K53YJSUcjs.f.call(void 0, t)){let a=nt(t),o="";for(let[s,i]of Object.entries(a)){let u=t.propTypes[s];u&&(o+=st(u,`(${e} + ${i.offset})`,`${r}.${s}`))}return o}if(_chunkBF35NEOXcjs.O.call(void 0, t)||_chunk3K53YJSUcjs.e.call(void 0, t)){let a=_chunk3K53YJSUcjs.a.call(void 0, _chunk3K53YJSUcjs.da.call(void 0, t.elementType),_chunk3K53YJSUcjs.aa.call(void 0, t)),o="";return o+=`for (let i = 0; i < ${t.elementCount}; i++) {
8
+ `;return n}}};function st(t,e,r){if(_chunk2VTISQYPcjs.M.call(void 0, t)||_chunk2VTISQYPcjs.S.call(void 0, t))return st(t.inner,e,r);if(_chunk2VTISQYPcjs.K.call(void 0, t)||_chunk2VTISQYPcjs.la.call(void 0, t)){let a=nt(t),o="";for(let[s,i]of Object.entries(a)){let p=t.propTypes[s];p&&(o+=st(p,`(${e} + ${i.offset})`,`${r}.${s}`))}return o}if(_chunk2VTISQYPcjs.J.call(void 0, t)||_chunk2VTISQYPcjs.ka.call(void 0, t)){let a=_chunkCYZBRBPDcjs.d.call(void 0, _chunkCYZBRBPDcjs.e.call(void 0, t.elementType),_chunkCYZBRBPDcjs.a.call(void 0, t)),o="";return o+=`for (let i = 0; i < ${t.elementCount}; i++) {
9
9
  `,o+=st(t.elementType,`(${e} + i * ${a})`,`${r}[i]`),o+=`}
10
- `,o}if(_chunkBF35NEOXcjs.I.call(void 0, t)){let a=at[t.type],o="",s=ot[a],i=["x","y","z","w"],u=_chunkBF35NEOXcjs.F.call(void 0, t)?2:_chunkBF35NEOXcjs.G.call(void 0, t)?3:4;for(let l=0;l<u;l++)o+=`output.${s}((${e} + ${l*4}), ${r}.${i[l]}, littleEndian);
11
- `;return o}if(_chunkBF35NEOXcjs.M.call(void 0, t)){let a=at[t.type],o=ot[a],s=_chunkBF35NEOXcjs.K.call(void 0, t)?2:_chunkBF35NEOXcjs.L.call(void 0, t)?3:4,i=s*s,u=_chunk3K53YJSUcjs.a.call(void 0, s*4,8),l="";for(let f=0;f<i;f++){let g=Math.floor(f/s),c=f%s,y=g*u+c*4;l+=`output.${o}((${e} + ${y}), ${r}.columns[${g}].${["x","y","z","w"][c]}, littleEndian);
12
- `}return l}if(_chunk3K53YJSUcjs.$.call(void 0, t)){let a=t.type;if(a in wn)return wn[a].generator(e,r);let o=Pa[a],s=ot[o],i=_chunk3K53YJSUcjs.k[a],u=_chunkBF35NEOXcjs.H.call(void 0, i)?4:_chunkBF35NEOXcjs.G.call(void 0, i)?3:_chunkBF35NEOXcjs.F.call(void 0, i)?2:1,l=o==="u8"||o==="i8"?1:o==="u16"||o==="i16"||o==="f16"?2:4,f=["x","y","z","w"],g=Ba[a],c="";for(let y=0;y<u;y++){let x=u===1?r:`${r}.${f[y]}`,I=g?g(x):x;c+=`output.${s}((${e} + ${y*l}), ${I}, littleEndian);
10
+ `,o}if(_chunk2VTISQYPcjs.E.call(void 0, t)){let a=at[t.type],o="",s=ot[a],i=["x","y","z","w"],p=_chunk2VTISQYPcjs.B.call(void 0, t)?2:_chunk2VTISQYPcjs.C.call(void 0, t)?3:4;for(let l=0;l<p;l++)o+=`output.${s}((${e} + ${l*4}), ${r}.${i[l]}, littleEndian);
11
+ `;return o}if(_chunk2VTISQYPcjs.H.call(void 0, t)){let a=at[t.type],o=ot[a],s=_chunk2VTISQYPcjs.F.call(void 0, t)?2:_chunk2VTISQYPcjs.G.call(void 0, t)?3:4,i=s*s,p=_chunkCYZBRBPDcjs.d.call(void 0, s*4,8),l="";for(let f=0;f<i;f++){let g=Math.floor(f/s),c=f%s,y=g*p+c*4;l+=`output.${o}((${e} + ${y}), ${r}.columns[${g}].${["x","y","z","w"][c]}, littleEndian);
12
+ `}return l}if(_chunk2VTISQYPcjs.hc.call(void 0, t)){let a=t.type;if(a in bn)return bn[a].generator(e,r);let o=Ua[a],s=ot[o],i=_chunk2VTISQYPcjs.sb[a],p=_chunk2VTISQYPcjs.D.call(void 0, i)?4:_chunk2VTISQYPcjs.C.call(void 0, i)?3:_chunk2VTISQYPcjs.B.call(void 0, i)?2:1,l=o==="u8"||o==="i8"?1:o==="u16"||o==="i16"||o==="f16"?2:4,f=["x","y","z","w"],g=Pa[a],c="";for(let y=0;y<p;y++){let x=p===1?r:`${r}.${f[y]}`,I=g?g(x):x;c+=`output.${s}((${e} + ${y*l}), ${I}, littleEndian);
13
13
  `}return c}if(!Object.hasOwn(at,t.type))throw new Error(`Primitive ${t.type} is unsupported by compiled writer`);let n=at[t.type];return`output.${ot[n]}(${e}, ${r}, littleEndian);
14
- `}function Yt(t){if(!Ua){console.warn("This environment does not allow eval - using default writer as fallback");return}if(Kt.has(t))return Kt.get(t);try{let e=st(t,"offset","value"),r=new Function("output","offset","value","littleEndian=true",e);return Kt.set(t,r),r}catch(e){console.warn(`Failed to compile writer for schema: ${t}
14
+ `}function Qt(t){if(!Fa){console.warn("This environment does not allow eval - using default writer as fallback");return}if(jt.has(t))return jt.get(t);try{let e=st(t,"offset","value"),r=new Function("output","offset","value","littleEndian=true",e);return jt.set(t,r),r}catch(e){console.warn(`Failed to compile writer for schema: ${t}
15
15
  Reason: ${e instanceof Error?e.message:String(e)}
16
- Falling back to default writer`)}}var we={bool(){throw new Error("Booleans are not host-shareable")},f32(t,e,r){t.writeFloat32(r)},f16(t,e,r){t.writeFloat16(r)},i32(t,e,r){t.writeInt32(r)},u32(t,e,r){t.writeUint32(r)},u16(t,e,r){t.writeUint16(r)},vec2f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y)},vec2h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y)},vec2i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y)},vec2u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y)},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},vec3f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z)},vec3h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z)},vec3i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z)},vec3u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z)},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},vec4f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z),t.writeFloat32(r.w)},vec4h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z),t.writeFloat16(r.w)},vec4i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z),t.writeInt32(r.w)},vec4u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z),t.writeUint32(r.w)},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},mat3x3f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},mat4x4f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},struct(t,e,r){let n=_chunk3K53YJSUcjs.aa.call(void 0, e);F(t,n);for(let[a,o]of Object.entries(e.propTypes))F(t,_chunk3K53YJSUcjs.aa.call(void 0, o)),pe(t,o,r[a]);F(t,n)},array(t,e,r){if(e.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunk3K53YJSUcjs.aa.call(void 0, e);F(t,n);let a=t.currentByteOffset;for(let o=0;o<Math.min(e.elementCount,r.length);o++)F(t,n),pe(t,e.elementType,r[o]);t.seekTo(a+_chunk3K53YJSUcjs.da.call(void 0, e))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(t,e,r){_optionalChain([we, 'access', _16 => _16[e.inner.type], 'optionalCall', _17 => _17(t,e,r)])},decorated(t,e,r){let n=_chunk3K53YJSUcjs.ba.call(void 0, e);F(t,n);let a=t.currentByteOffset;_optionalChain([we, 'access', _18 => _18[_optionalChain([e, 'access', _19 => _19.inner, 'optionalAccess', _20 => _20.type])], 'optionalCall', _21 => _21(t,e.inner,r)]),t.seekTo(a+_chunk3K53YJSUcjs.da.call(void 0, e))},uint8(t,e,r){t.writeUint8(r)},uint8x2(t,e,r){t.writeUint8(r.x),t.writeUint8(r.y)},uint8x4(t,e,r){t.writeUint8(r.x),t.writeUint8(r.y),t.writeUint8(r.z),t.writeUint8(r.w)},sint8(t,e,r){t.writeInt8(r)},sint8x2(t,e,r){t.writeInt8(r.x),t.writeInt8(r.y)},sint8x4(t,e,r){t.writeInt8(r.x),t.writeInt8(r.y),t.writeInt8(r.z),t.writeInt8(r.w)},unorm8(t,e,r){t.writeUint8(Math.round(r*255))},unorm8x2(t,e,r){t.writeUint8(Math.round(r.x*255)),t.writeUint8(Math.round(r.y*255))},unorm8x4(t,e,r){t.writeUint8(Math.round(r.x*255)),t.writeUint8(Math.round(r.y*255)),t.writeUint8(Math.round(r.z*255)),t.writeUint8(Math.round(r.w*255))},snorm8(t,e,r){t.writeInt8(Math.round(r*127))},snorm8x2(t,e,r){t.writeInt8(Math.round(r.x*127)),t.writeInt8(Math.round(r.y*127))},snorm8x4(t,e,r){t.writeInt8(Math.round(r.x*127)),t.writeInt8(Math.round(r.y*127)),t.writeInt8(Math.round(r.z*127)),t.writeInt8(Math.round(r.w*127))},uint16(t,e,r){t.writeUint16(r)},uint16x2(t,e,r){t.writeUint16(r.x),t.writeUint16(r.y)},uint16x4(t,e,r){t.writeUint16(r.x),t.writeUint16(r.y),t.writeUint16(r.z),t.writeUint16(r.w)},sint16(t,e,r){t.writeInt16(r)},sint16x2(t,e,r){t.writeInt16(r.x),t.writeInt16(r.y)},sint16x4(t,e,r){t.writeInt16(r.x),t.writeInt16(r.y),t.writeInt16(r.z),t.writeInt16(r.w)},unorm16(t,e,r){t.writeUint16(r*65535)},unorm16x2(t,e,r){t.writeUint16(r.x*65535),t.writeUint16(r.y*65535)},unorm16x4(t,e,r){t.writeUint16(r.x*65535),t.writeUint16(r.y*65535),t.writeUint16(r.z*65535),t.writeUint16(r.w*65535)},snorm16(t,e,r){t.writeInt16(Math.round(r*32767))},snorm16x2(t,e,r){t.writeInt16(Math.round(r.x*32767)),t.writeInt16(Math.round(r.y*32767))},snorm16x4(t,e,r){t.writeInt16(Math.round(r.x*32767)),t.writeInt16(Math.round(r.y*32767)),t.writeInt16(Math.round(r.z*32767)),t.writeInt16(Math.round(r.w*32767))},float16(t,e,r){t.writeFloat16(r)},float16x2(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y)},float16x4(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z),t.writeFloat16(r.w)},float32(t,e,r){t.writeFloat32(r)},float32x2(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y)},float32x3(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z)},float32x4(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z),t.writeFloat32(r.w)},uint32(t,e,r){t.writeUint32(r)},uint32x2(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y)},uint32x3(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z)},uint32x4(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z),t.writeUint32(r.w)},sint32(t,e,r){t.writeInt32(r)},sint32x2(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y)},sint32x3(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z)},sint32x4(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z),t.writeInt32(r.w)},"unorm10-10-10-2"(t,e,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,t.writeUint32(n)},"unorm8x4-bgra"(t,e,r){t.writeUint8(r.z*255),t.writeUint8(r.y*255),t.writeUint8(r.x*255),t.writeUint8(r.w*255)},disarray(t,e,r){let n=_chunk3K53YJSUcjs.aa.call(void 0, e);F(t,n);let a=t.currentByteOffset;for(let o=0;o<Math.min(e.elementCount,r.length);o++)F(t,n),_optionalChain([we, 'access', _22 => _22[_optionalChain([e, 'access', _23 => _23.elementType, 'optionalAccess', _24 => _24.type])], 'optionalCall', _25 => _25(t,e.elementType,r[o])]);t.seekTo(a+_chunk3K53YJSUcjs.da.call(void 0, e))},unstruct(t,e,r){let n=e.propTypes;for(let[a,o]of Object.entries(n))_optionalChain([we, 'access', _26 => _26[o.type], 'optionalCall', _27 => _27(t,o,r[a])])},"loose-decorated"(t,e,r){let n=_chunk3K53YJSUcjs.ba.call(void 0, e);F(t,n);let a=t.currentByteOffset,o=we[_optionalChain([e, 'access', _28 => _28.inner, 'optionalAccess', _29 => _29.type])];return _optionalChain([o, 'optionalCall', _30 => _30(t,e.inner,r)]),t.seekTo(a+_chunk3K53YJSUcjs.da.call(void 0, e)),r}};function pe(t,e,r){let n=we[e.type];if(!n)throw new Error(`Cannot write data of type '${e.type}'.`);n(t,e,r)}var Aa={bool(){throw new Error("Booleans are not host-shareable")},f32(t){return t.readFloat32()},f16(t){return t.readFloat16()},i32(t){return t.readInt32()},u32(t){return t.readUint32()},u16(t){return t.readUint16()},vec2f(t){return _chunkBF35NEOXcjs.za.call(void 0, t.readFloat32(),t.readFloat32())},vec3f(t){return _chunkBF35NEOXcjs.Ea.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32())},vec4f(t){return _chunkBF35NEOXcjs.Ja.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},vec2h(t){return _chunkBF35NEOXcjs.Aa.call(void 0, t.readFloat16(),t.readFloat16())},vec3h(t){return _chunkBF35NEOXcjs.Fa.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16())},vec4h(t){return _chunkBF35NEOXcjs.Ka.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16())},vec2i(t){return _chunkBF35NEOXcjs.Ba.call(void 0, t.readInt32(),t.readInt32())},vec3i(t){return _chunkBF35NEOXcjs.Ga.call(void 0, t.readInt32(),t.readInt32(),t.readInt32())},vec4i(t){return _chunkBF35NEOXcjs.La.call(void 0, t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32())},vec2u(t){return _chunkBF35NEOXcjs.Ca.call(void 0, t.readUint32(),t.readUint32())},vec3u(t){return _chunkBF35NEOXcjs.Ha.call(void 0, t.readUint32(),t.readUint32(),t.readUint32())},vec4u(t){return _chunkBF35NEOXcjs.Ma.call(void 0, t.readUint32(),t.readUint32(),t.readUint32(),t.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(t){return _chunkBF35NEOXcjs.Ya.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},mat3x3f(t){let e=()=>{let r=t.readFloat32();return t.readFloat32(),r};return _chunkBF35NEOXcjs.Za.call(void 0, t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e())},mat4x4f(t){return _chunkBF35NEOXcjs._a.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},struct(t,e){let r=_chunk3K53YJSUcjs.aa.call(void 0, e);F(t,r);let n={},a=e.propTypes;for(let[o,s]of Object.entries(a))F(t,_chunk3K53YJSUcjs.aa.call(void 0, s)),n[o]=E(t,s);return F(t,r),n},array(t,e){if(e.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunk3K53YJSUcjs.aa.call(void 0, e),n=[];for(let a=0;a<e.elementCount;a++){F(t,r);let o=e.elementType,s=E(t,o);n.push(s)}return F(t,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(t,e){return E(t,e.inner)},decorated(t,e){let r=_chunk3K53YJSUcjs.ba.call(void 0, e);F(t,r);let n=t.currentByteOffset,a=E(t,e.inner);return t.seekTo(n+_chunk3K53YJSUcjs.da.call(void 0, e)),a},uint8:t=>t.readUint8(),uint8x2:t=>_chunkBF35NEOXcjs.Ca.call(void 0, t.readUint8(),t.readUint8()),uint8x4:t=>_chunkBF35NEOXcjs.Ma.call(void 0, t.readUint8(),t.readUint8(),t.readUint8(),t.readUint8()),sint8:t=>t.readInt8(),sint8x2:t=>_chunkBF35NEOXcjs.Ba.call(void 0, t.readInt8(),t.readInt8()),sint8x4:t=>_chunkBF35NEOXcjs.La.call(void 0, t.readInt8(),t.readInt8(),t.readInt8(),t.readInt8()),unorm8:t=>t.readUint8()/255,unorm8x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readUint8()/255,t.readUint8()/255),unorm8x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readUint8()/255,t.readUint8()/255,t.readUint8()/255,t.readUint8()/255),snorm8:t=>t.readInt8()/127,snorm8x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readInt8()/127,t.readInt8()/127),snorm8x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readInt8()/127,t.readInt8()/127,t.readInt8()/127,t.readInt8()/127),uint16:t=>t.readUint16(),uint16x2:t=>_chunkBF35NEOXcjs.Ca.call(void 0, t.readUint16(),t.readUint16()),uint16x4:t=>_chunkBF35NEOXcjs.Ma.call(void 0, t.readUint16(),t.readUint16(),t.readUint16(),t.readUint16()),sint16:t=>t.readInt16(),sint16x2:t=>_chunkBF35NEOXcjs.Ba.call(void 0, t.readInt16(),t.readInt16()),sint16x4:t=>_chunkBF35NEOXcjs.La.call(void 0, t.readInt16(),t.readInt16(),t.readInt16(),t.readInt16()),unorm16:t=>t.readUint16()/65535,unorm16x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readUint16()/65535,t.readUint16()/65535),unorm16x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535),snorm16:t=>t.readInt16()/32767,snorm16x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readInt16()/32767,t.readInt16()/32767),snorm16x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readInt16()/32767,t.readInt16()/32767,t.readInt16()/32767,t.readInt16()/32767),float16(t){return t.readFloat16()},float16x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readFloat16(),t.readFloat16()),float16x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16()),float32:t=>t.readFloat32(),float32x2:t=>_chunkBF35NEOXcjs.za.call(void 0, t.readFloat32(),t.readFloat32()),float32x3:t=>_chunkBF35NEOXcjs.Ea.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32()),float32x4:t=>_chunkBF35NEOXcjs.Ja.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()),uint32:t=>t.readUint32(),uint32x2:t=>_chunkBF35NEOXcjs.Ca.call(void 0, t.readUint32(),t.readUint32()),uint32x3:t=>_chunkBF35NEOXcjs.Ha.call(void 0, t.readUint32(),t.readUint32(),t.readUint32()),uint32x4:t=>_chunkBF35NEOXcjs.Ma.call(void 0, t.readUint32(),t.readUint32(),t.readUint32(),t.readUint32()),sint32:t=>t.readInt32(),sint32x2:t=>_chunkBF35NEOXcjs.Ba.call(void 0, t.readInt32(),t.readInt32()),sint32x3:t=>_chunkBF35NEOXcjs.Ga.call(void 0, t.readInt32(),t.readInt32(),t.readInt32()),sint32x4:t=>_chunkBF35NEOXcjs.La.call(void 0, t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32()),"unorm10-10-10-2"(t){let e=t.readUint32(),r=(e>>22)/1023,n=(e>>12&1023)/1023,a=(e>>2&1023)/1023,o=(e&3)/3;return _chunkBF35NEOXcjs.Ja.call(void 0, r,n,a,o)},"unorm8x4-bgra"(t){let e=t.readByte()/255,r=t.readByte()/255,n=t.readByte()/255,a=t.readByte()/255;return _chunkBF35NEOXcjs.Ja.call(void 0, n,r,e,a)},unstruct(t,e){let r={},n=e.propTypes;for(let[a,o]of Object.entries(n))r[a]=E(t,o);return r},disarray(t,e){let r=_chunk3K53YJSUcjs.aa.call(void 0, e),n=[];for(let a=0;a<e.elementCount;a++)F(t,r),n.push(E(t,e.elementType));return F(t,r),n},"loose-decorated"(t,e){F(t,_chunk3K53YJSUcjs.ba.call(void 0, e));let r=t.currentByteOffset,n=E(t,e.inner);return t.seekTo(r+_chunk3K53YJSUcjs.da.call(void 0, e)),n}};function E(t,e){let r=Aa[e.type];if(!r)throw new Error(`Cannot read data of type '${e.type}'.`);return r(t,e)}function Sn(t,e){let r=_chunk3K53YJSUcjs.da.call(void 0, t);if(r===0||e===void 0||e===null)return[];let n=new ArrayBuffer(r),a=new (0, _typedbinary.BufferWriter)(n),o=[];function s(l,f,g,c){if(f!=null){if(_chunkBF35NEOXcjs.P.call(void 0, l)||_chunk3K53YJSUcjs.f.call(void 0, l)){let y=nt(l);for(let[x,I]of Object.entries(y)){let w=l.propTypes[x];if(!w)continue;let S=f[x];S!==void 0&&s(w,S,g+I.offset,_nullishCoalesce(I.padding, () => (c)))}return}if(_chunkBF35NEOXcjs.O.call(void 0, l)||_chunk3K53YJSUcjs.e.call(void 0, l)){let y=l,x=_chunk3K53YJSUcjs.a.call(void 0, _chunk3K53YJSUcjs.da.call(void 0, y.elementType),_chunk3K53YJSUcjs.aa.call(void 0, y.elementType));if(!Array.isArray(f))throw new Error("Partial value for array must be an array");let I=_nullishCoalesce(f, () => ([]));I.sort((w,S)=>w.idx-S.idx);for(let{idx:w,value:S}of I)s(y.elementType,S,g+w*x,x-_chunk3K53YJSUcjs.da.call(void 0, y.elementType))}else{let y=_chunk3K53YJSUcjs.da.call(void 0, l);a.seekTo(g),pe(a,l,f),o.push({start:g,end:g+y,padding:c})}}}if(s(t,e,0),o.length===0)return[];let i=[],u=o[0];for(let l=1;l<o.length;l++){let f=o[l];if(!f||!u)throw new Error("Internal error: missing segment");f.start===u.end+(_nullishCoalesce(u.padding, () => (0)))?(u.end=f.end,u.padding=f.padding):(i.push({data:new Uint8Array(n,u.start,u.end-u.start)}),u=f)}if(!u)throw new Error("Internal error: missing segment");return i.push({data:new Uint8Array(n,u.start,u.end-u.start)}),i}function le(t){return!!_optionalChain([t, 'optionalAccess', _31 => _31.usableAsStorage])}var Ae=class t extends Error{constructor(e){super(`Resource '${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, e), () => ("<unnamed>"))}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,t.prototype)}};function it(t){return!!t.usableAsUniform}var Fn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Re= (_class5 =class{constructor(e,r){;_class5.prototype.__init5.call(this);this.usage=e;this.buffer=r;this[_chunkBF35NEOXcjs.a]={dataType:r.dataType},this[_chunkBF35NEOXcjs.d]=r}__init5() {this.resourceType="buffer-usage"}$name(e){return this.buffer.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),o=Fn[this.usage];return e.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${e.resolve(this.buffer.dataType)};`),r}toString(){return`${this.usage}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](){return new Proxy({"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:this.buffer.dataType},k)}get $(){let e=_chunkBF35NEOXcjs.ka.call(void 0, ),r=_chunkBF35NEOXcjs.ga.call(void 0, );if(e.type==="normal")throw new (0, _chunkBF35NEOXcjs.w)(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 e.type==="codegen"?this[_chunkBF35NEOXcjs.c]():e.type==="simulate"?(e.buffers.has(this.buffer)||e.buffers.set(this.buffer,_nullishCoalesce(_chunk3K53YJSUcjs.fa.call(void 0, this.buffer.dataType,this.buffer.initial), () => (_chunk3K53YJSUcjs.ga.call(void 0, this.buffer.dataType)))),e.buffers.get(this.buffer)):_chunk3K53YJSUcjs.ia.call(void 0, e,"bufferUsage.ts#TgpuFixedBufferImpl/$")}get value(){return this.$}set $(e){let r=_chunkBF35NEOXcjs.ka.call(void 0, ),n=_chunkBF35NEOXcjs.ga.call(void 0, );if(r.type==="normal")throw new (0, _chunkBF35NEOXcjs.w)(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,e);return}_chunk3K53YJSUcjs.ia.call(void 0, r,"bufferUsage.ts#TgpuFixedBufferImpl/$")}set value(e){this.$=e}}, _class5),Ce= (_class6 =class{constructor(e,r,n){;_class6.prototype.__init6.call(this);this.usage=e;this.dataType=r;this._membership=n;this[_chunkBF35NEOXcjs.a]={dataType:r},_chunkBF35NEOXcjs.k.call(void 0, this,n.key)}__init6() {this.resourceType="buffer-usage"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=Fn[this.usage];return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${e.resolve(this.dataType)};`),r}toString(){return`${this.usage}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](){return new Proxy({"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:this.dataType},k)}get $(){if(_chunkBF35NEOXcjs.la.call(void 0, ))return this[_chunkBF35NEOXcjs.c]();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.$}}, _class6),vn=new WeakMap;function Un(t){if(!le(t))throw new Error(`Cannot pass ${t} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let e=vn.get(t);return e||(e=new Re("mutable",t),vn.set(t,e)),e}var In=new WeakMap;function Pn(t){if(!le(t))throw new Error(`Cannot pass ${t} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let e=In.get(t);return e||(e=new Re("readonly",t),In.set(t,e)),e}var Dn=new WeakMap;function Bn(t){if(!it(t))throw new Error(`Cannot pass ${t} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let e=Dn.get(t);return e||(e=new Re("uniform",t),Dn.set(t,e)),e}var Ga={uniform:Bn,mutable:Un,readonly:Pn};function Ge(t,e,r){return _chunkBF35NEOXcjs.N.call(void 0, e)?new ut(t,e,r):new ut(t,e,r,["storage","uniform"])}function ee(t){return t.resourceType==="buffer"}function Va(t){return!!t.usableAsVertex}var $a=_typedbinary.getSystemEndianness.call(void 0, ),ut= (_class7 =class{constructor(e,r,n,a){;_class7.prototype.__init7.call(this);_class7.prototype.__init8.call(this);_class7.prototype.__init9.call(this);_class7.prototype.__init10.call(this);_class7.prototype.__init11.call(this);_class7.prototype.__init12.call(this);_class7.prototype.__init13.call(this);_class7.prototype.__init14.call(this);_class7.prototype.__init15.call(this);this._group=e;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;_chunkBF35NEOXcjs.ca.call(void 0, n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}__init7() {this[_chunkBF35NEOXcjs.a]=!0}__init8() {this.resourceType="buffer"}__init9() {this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC}__init10() {this._buffer=null}__init11() {this._destroyed=!1}__init12() {this.usableAsUniform=!1}__init13() {this.usableAsStorage=!1}__init14() {this.usableAsVertex=!1}__init15() {this.usableAsIndex=!1}get buffer(){let e=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=e.createBuffer({size:_chunk3K53YJSUcjs.da.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}),this.initial)){let r=new (0, _typedbinary.BufferWriter)(this._buffer.getMappedRange());pe(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this._buffer&&(this._buffer.label=e),this}$usage(...e){for(let r of e){if(_optionalChain([this, 'access', _32 => _32._disallowedUsages, 'optionalAccess', _33 => _33.includes, 'call', _34 => _34(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(e){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return e&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):e&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=e,this)}compileWriter(){Yt(this.dataType)}_writeToTarget(e,r){let n=Yt(this.dataType);if(n)try{n(new DataView(e),0,r,$a==="little");return}catch(a){console.error(`Error when using compiled writer for buffer ${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
17
- Using fallback writer instead.`,a)}pe(new (0, _typedbinary.BufferWriter)(e),this.dataType,r)}write(e){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let o=r.getMappedRange();this._writeToTarget(o,e);return}let a=_chunk3K53YJSUcjs.da.call(void 0, this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),this._writeToTarget(this._hostBuffer,e),n.queue.writeBuffer(r,0,this._hostBuffer,0,a)}writePartial(e){let r=this.buffer,n=this._group.device,a=Sn(this.dataType,e);if(r.mapState==="mapped"){let o=r.getMappedRange(),s=new Uint8Array(o);for(let i of a)s.set(i.data,i.data.byteOffset)}else for(let o of a)n.queue.writeBuffer(r,o.data.byteOffset,o.data,0,o.data.byteLength)}copyFrom(e){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunk3K53YJSUcjs.da.call(void 0, this.dataType);this._group.commandEncoder.copyBufferToBuffer(e.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let e=this.buffer,r=this._group.device;if(e.mapState==="mapped"){let s=e.getMappedRange();return E(new (0, _typedbinary.BufferReader)(s),this.dataType)}if(e.usage&GPUBufferUsage.MAP_READ){await e.mapAsync(GPUMapMode.READ);let s=e.getMappedRange(),i=E(new (0, _typedbinary.BufferReader)(s),this.dataType);return e.unmap(),i}let n=r.createBuffer({size:_chunk3K53YJSUcjs.da.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(e,0,n,0,_chunk3K53YJSUcjs.da.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunk3K53YJSUcjs.da.call(void 0, this.dataType));let o=E(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(e){return _optionalChain([Ga, 'access', _35 => _35[e], 'optionalCall', _36 => _36(this)])}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&_optionalChain([this, 'access', _37 => _37._buffer, 'optionalAccess', _38 => _38.destroy, 'call', _39 => _39()]))}toString(){return`buffer:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class7);function Rn(t){return new Xt(t)}function Cn(t){return new Zt(t)}function Ve(t){let e=t;return _optionalChain([e, 'optionalAccess', _40 => _40.resourceType])==="sampler"&&!!e[_chunkBF35NEOXcjs.a]}function $e(t){let e=t;return _optionalChain([e, 'optionalAccess', _41 => _41.resourceType])==="sampler-comparison"&&!!e[_chunkBF35NEOXcjs.a]}var pt= (_class8 =class{constructor(e){;_class8.prototype.__init16.call(this);this._membership=e;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={},_chunkBF35NEOXcjs.k.call(void 0, this,e.key)}__init16() {this.resourceType="sampler"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class8),lt= (_class9 =class{constructor(e){;_class9.prototype.__init17.call(this);this._membership=e;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={},_chunkBF35NEOXcjs.k.call(void 0, this,e.key)}__init17() {this.resourceType="sampler-comparison"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class9),Xt= (_class10 =class{constructor(e){;_class10.prototype.__init18.call(this);_class10.prototype.__init19.call(this);this._props=e;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={unwrap:r=>(this._sampler||(this._sampler=r.device.createSampler({...this._props,label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))})),this._sampler)},this._filtering=e.minFilter==="linear"||e.magFilter==="linear"||e.mipmapFilter==="linear"}__init18() {this.resourceType="sampler"}__init19() {this._sampler=null}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class10),Zt= (_class11 =class{constructor(e){;_class11.prototype.__init20.call(this);_class11.prototype.__init21.call(this);this._props=e;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={unwrap:r=>(this._sampler||(this._sampler=r.device.createSampler({...this._props,label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))})),this._sampler)}}__init20() {this.resourceType="sampler-comparison"}__init21() {this._sampler=null}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({sampler:"comparison"},this);return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class11);var mt= (_class12 =class{constructor(e){;_class12.prototype.__init22.call(this);this._membership=e;_chunkBF35NEOXcjs.k.call(void 0, this,e.key)}__init22() {this.resourceType="external-texture"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class12);var Gn={r8unorm:_chunkBF35NEOXcjs.wa,r8snorm:_chunkBF35NEOXcjs.wa,r8uint:_chunkBF35NEOXcjs.ta,r8sint:_chunkBF35NEOXcjs.va,r16uint:_chunkBF35NEOXcjs.ta,r16sint:_chunkBF35NEOXcjs.va,r16float:_chunkBF35NEOXcjs.wa,rg8unorm:_chunkBF35NEOXcjs.wa,rg8snorm:_chunkBF35NEOXcjs.wa,rg8uint:_chunkBF35NEOXcjs.ta,rg8sint:_chunkBF35NEOXcjs.va,r32uint:_chunkBF35NEOXcjs.ta,r32sint:_chunkBF35NEOXcjs.va,r32float:_chunkBF35NEOXcjs.wa,rg16uint:_chunkBF35NEOXcjs.ta,rg16sint:_chunkBF35NEOXcjs.va,rg16float:_chunkBF35NEOXcjs.wa,rgba8unorm:_chunkBF35NEOXcjs.wa,"rgba8unorm-srgb":_chunkBF35NEOXcjs.wa,rgba8snorm:_chunkBF35NEOXcjs.wa,rgba8uint:_chunkBF35NEOXcjs.ta,rgba8sint:_chunkBF35NEOXcjs.va,bgra8unorm:_chunkBF35NEOXcjs.wa,"bgra8unorm-srgb":_chunkBF35NEOXcjs.wa,rgb9e5ufloat:_chunkBF35NEOXcjs.wa,rgb10a2uint:_chunkBF35NEOXcjs.ta,rgb10a2unorm:_chunkBF35NEOXcjs.wa,rg11b10ufloat:_chunkBF35NEOXcjs.wa,rg32uint:_chunkBF35NEOXcjs.ta,rg32sint:_chunkBF35NEOXcjs.va,rg32float:_chunkBF35NEOXcjs.wa,rgba16uint:_chunkBF35NEOXcjs.ta,rgba16sint:_chunkBF35NEOXcjs.va,rgba16float:_chunkBF35NEOXcjs.wa,rgba32uint:_chunkBF35NEOXcjs.ta,rgba32sint:_chunkBF35NEOXcjs.va,rgba32float:_chunkBF35NEOXcjs.wa,stencil8:_chunkBF35NEOXcjs.wa,depth16unorm:_chunkBF35NEOXcjs.wa,depth24plus:_chunkBF35NEOXcjs.wa,"depth24plus-stencil8":_chunkBF35NEOXcjs.wa,depth32float:_chunkBF35NEOXcjs.wa,"depth32float-stencil8":_chunkBF35NEOXcjs.wa,"bc1-rgba-unorm":_chunkBF35NEOXcjs.wa,"bc1-rgba-unorm-srgb":_chunkBF35NEOXcjs.wa,"bc2-rgba-unorm":_chunkBF35NEOXcjs.wa,"bc2-rgba-unorm-srgb":_chunkBF35NEOXcjs.wa,"bc3-rgba-unorm":_chunkBF35NEOXcjs.wa,"bc3-rgba-unorm-srgb":_chunkBF35NEOXcjs.wa,"bc4-r-unorm":_chunkBF35NEOXcjs.wa,"bc4-r-snorm":_chunkBF35NEOXcjs.wa,"bc5-rg-unorm":_chunkBF35NEOXcjs.wa,"bc5-rg-snorm":_chunkBF35NEOXcjs.wa,"bc6h-rgb-ufloat":_chunkBF35NEOXcjs.wa,"bc6h-rgb-float":_chunkBF35NEOXcjs.wa,"bc7-rgba-unorm":_chunkBF35NEOXcjs.wa,"bc7-rgba-unorm-srgb":_chunkBF35NEOXcjs.wa,"etc2-rgb8unorm":_chunkBF35NEOXcjs.wa,"etc2-rgb8unorm-srgb":_chunkBF35NEOXcjs.wa,"etc2-rgb8a1unorm":_chunkBF35NEOXcjs.wa,"etc2-rgb8a1unorm-srgb":_chunkBF35NEOXcjs.wa,"etc2-rgba8unorm":_chunkBF35NEOXcjs.wa,"etc2-rgba8unorm-srgb":_chunkBF35NEOXcjs.wa,"eac-r11unorm":_chunkBF35NEOXcjs.wa,"eac-r11snorm":_chunkBF35NEOXcjs.wa,"eac-rg11unorm":_chunkBF35NEOXcjs.wa,"eac-rg11snorm":_chunkBF35NEOXcjs.wa,"astc-4x4-unorm":_chunkBF35NEOXcjs.wa,"astc-4x4-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-5x4-unorm":_chunkBF35NEOXcjs.wa,"astc-5x4-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-5x5-unorm":_chunkBF35NEOXcjs.wa,"astc-5x5-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-6x5-unorm":_chunkBF35NEOXcjs.wa,"astc-6x5-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-6x6-unorm":_chunkBF35NEOXcjs.wa,"astc-6x6-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-8x5-unorm":_chunkBF35NEOXcjs.wa,"astc-8x5-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-8x6-unorm":_chunkBF35NEOXcjs.wa,"astc-8x6-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-8x8-unorm":_chunkBF35NEOXcjs.wa,"astc-8x8-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-10x5-unorm":_chunkBF35NEOXcjs.wa,"astc-10x5-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-10x6-unorm":_chunkBF35NEOXcjs.wa,"astc-10x6-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-10x8-unorm":_chunkBF35NEOXcjs.wa,"astc-10x8-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-10x10-unorm":_chunkBF35NEOXcjs.wa,"astc-10x10-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-12x10-unorm":_chunkBF35NEOXcjs.wa,"astc-12x10-unorm-srgb":_chunkBF35NEOXcjs.wa,"astc-12x12-unorm":_chunkBF35NEOXcjs.wa,"astc-12x12-unorm-srgb":_chunkBF35NEOXcjs.wa,r16snorm:_chunkBF35NEOXcjs.wa,r16unorm:_chunkBF35NEOXcjs.wa,rg16unorm:_chunkBF35NEOXcjs.wa,rg16snorm:_chunkBF35NEOXcjs.wa,rgba16unorm:_chunkBF35NEOXcjs.wa,rgba16snorm:_chunkBF35NEOXcjs.wa},_e={rgba8unorm:_chunkBF35NEOXcjs.Ja,rgba8snorm:_chunkBF35NEOXcjs.Ja,rgba8uint:_chunkBF35NEOXcjs.Ma,rgba8sint:_chunkBF35NEOXcjs.La,rgba16uint:_chunkBF35NEOXcjs.Ma,rgba16sint:_chunkBF35NEOXcjs.La,rgba16float:_chunkBF35NEOXcjs.Ja,r32uint:_chunkBF35NEOXcjs.Ma,r32sint:_chunkBF35NEOXcjs.La,r32float:_chunkBF35NEOXcjs.Ja,rg32uint:_chunkBF35NEOXcjs.Ma,rg32sint:_chunkBF35NEOXcjs.La,rg32float:_chunkBF35NEOXcjs.Ja,rgba32uint:_chunkBF35NEOXcjs.Ma,rgba32sint:_chunkBF35NEOXcjs.La,rgba32float:_chunkBF35NEOXcjs.Ja,bgra8unorm:_chunkBF35NEOXcjs.Ja},Vn={f32:"float",u32:"uint",i32:"sint"},$n={float:_chunkBF35NEOXcjs.wa,"unfilterable-float":_chunkBF35NEOXcjs.wa,uint:_chunkBF35NEOXcjs.ta,sint:_chunkBF35NEOXcjs.va,depth:_chunkBF35NEOXcjs.wa};function _n(t,e){return new er(t,e)}function N(t){return _optionalChain([t, 'optionalAccess', _42 => _42.resourceType])==="texture"&&!!t[_chunkBF35NEOXcjs.a]}function Ee(t){return _optionalChain([t, 'optionalAccess', _43 => _43.resourceType])==="texture-storage-view"&&!!t[_chunkBF35NEOXcjs.a]}function Le(t){return _optionalChain([t, 'optionalAccess', _44 => _44.resourceType])==="texture-sampled-view"&&!!t[_chunkBF35NEOXcjs.a]}var En={mutable:"read_write",readonly:"read",writeonly:"write"},er= (_class13 =class{constructor(e,r){;_class13.prototype.__init23.call(this);_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);_class13.prototype.__init28.call(this);_class13.prototype.__init29.call(this);this.props=e;this._branch=r;this[_chunkBF35NEOXcjs.a]={unwrap:()=>{if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>")),format:this.props.format,size:this.props.size,usage:this._flags,dimension:_nullishCoalesce(this.props.dimension, () => ("2d")),viewFormats:_nullishCoalesce(this.props.viewFormats, () => ([])),mipLevelCount:_nullishCoalesce(this.props.mipLevelCount, () => (1)),sampleCount:_nullishCoalesce(this.props.sampleCount, () => (1))})),this._texture}}}__init23() {this.resourceType="texture"}__init24() {this.usableAsSampled=!1}__init25() {this.usableAsStorage=!1}__init26() {this.usableAsRender=!1}__init27() {this._destroyed=!1}__init28() {this._flags=GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC}__init29() {this._texture=null}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}$usage(...e){let r=e.includes("storage"),n=e.includes("sampled"),a=e.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||=r,this.usableAsSampled||=n,this.usableAsRender||=a,this}createView(e,r){if(e==="sampled")return this._asSampled(r);let n=r;switch(e){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(e,r){if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _45 => _45.format]), () => (this.props.format)),a=_e[n];return _chunkBF35NEOXcjs.n.call(void 0, !!a,`Unsupported storage texture format: ${n}`),new tr(_nullishCoalesce(e, () => ({})),r,this)}_asReadonly(e){return this._asStorage(e,"readonly")}_asWriteonly(e){return this._asStorage(e,"writeonly")}_asMutable(e){return this._asStorage(e,"mutable")}_asSampled(e){if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _46 => _46.format]), () => (this.props.format));if(!_e[r])throw new Error(`Unsupported storage texture format: ${r}`);return new rr(e,this)}destroy(){this._destroyed||(this._destroyed=!0,_optionalChain([this, 'access', _47 => _47._texture, 'optionalAccess', _48 => _48.destroy, 'call', _49 => _49()]))}}, _class13),gt={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},tr= (_class14 =class{constructor(e,r,n){;_class14.prototype.__init30.call(this);this.access=r;this._texture=n;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={unwrap:()=>(this._view||(this._view=this._texture[_chunkBF35NEOXcjs.a].unwrap().createView({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - View`,format:this._format,dimension:this.dimension})),this._view)},this[_chunkBF35NEOXcjs.d]=n,this.dimension=_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _50 => _50.dimension]), () => (n.props.dimension)), () => ("2d")),this._format=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _51 => _51.format]), () => (n.props.format)),this.texelDataType=_e[this._format]}__init30() {this.resourceType="texture-storage-view"}$name(e){return this._texture.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),o=`texture_storage_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${En[this.access]}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class14),dt= (_class15 =class{constructor(e,r,n,a){;_class15.prototype.__init31.call(this);this._format=e;this.dimension=r;this.access=n;this._membership=a;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={},this.texelDataType=_e[this._format],_chunkBF35NEOXcjs.k.call(void 0, this,a.key)}__init31() {this.resourceType="texture-storage-view"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=`texture_storage_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${En[this.access]}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class15),rr= (_class16 =class{constructor(e,r){;_class16.prototype.__init32.call(this);this._props=e;this._texture=r;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={unwrap:()=>(this._view||(this._view=this._texture[_chunkBF35NEOXcjs.a].unwrap().createView({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - View`,...this._props})),this._view)},this[_chunkBF35NEOXcjs.d]=r,this.dimension=_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _52 => _52.dimension]), () => (r.props.dimension)), () => ("2d")),this._format=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _53 => _53.format]), () => (r.props.format)),this.channelDataType=Gn[this._format]}__init32() {this.resourceType="texture-sampled-view"}$name(e){return this._texture.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=(_nullishCoalesce(this._texture.props.sampleCount, () => (1)))>1,{group:a,binding:o}=e.allocateFixedEntry({texture:Vn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return e.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${s}<${e.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class16),ft= (_class17 =class{constructor(e,r,n,a){;_class17.prototype.__init33.call(this);this.dimension=r;this._multisampled=n;this._membership=a;this[_chunkBF35NEOXcjs.b]=this,this[_chunkBF35NEOXcjs.a]={},_chunkBF35NEOXcjs.k.call(void 0, this,a.key),this.channelDataType=$n[e]}__init33() {this.resourceType="texture-sampled-view"}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=this._multisampled?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${e.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}}, _class17);function nr(t){return!!_optionalChain([t, 'optionalAccess', _54 => _54.usableAsSampled])}function _a(t){return!!_optionalChain([t, 'optionalAccess', _55 => _55.usableAsRender])}var ct=class t extends Error{constructor(e){super(`Resource '${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, e), () => ("<unnamed>"))}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,t.prototype)}};function yt(t){return new or(t)}function Tt(t){return!!t&&t.resourceType==="bind-group-layout"}function sr(t){return!!t&&t.resourceType==="bind-group"}var ar=class t extends Error{constructor(e,r){super(`Bind group '${_nullishCoalesce(e, () => ("<unnamed>"))}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,t.prototype)}},Ln=["compute"],Se=["compute","vertex","fragment"],or= (_class18 =class{constructor(e){;_class18.prototype.__init34.call(this);_class18.prototype.__init35.call(this);_class18.prototype.__init36.call(this);_class18.prototype.__init37.call(this);_class18.prototype.__init38.call(this);this.entries=e;let r=0;for(let[n,a]of Object.entries(e)){if(a===null){r++;continue}let o={layout:this,key:n,idx:r};if("uniform"in a&&(this.bound[n]=new Ce("uniform",a.uniform,o)),"storage"in a){let s="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Ce(_nullishCoalesce(a.access, () => ("readonly")),s,o)}"texture"in a&&(this.bound[n]=new ft(a.texture,_nullishCoalesce(a.viewDimension, () => ("2d")),_nullishCoalesce(a.multisampled, () => (!1)),o)),"storageTexture"in a&&(this.bound[n]=new dt(a.storageTexture,_nullishCoalesce(a.viewDimension, () => ("2d")),_nullishCoalesce(a.access, () => ("writeonly")),o)),"externalTexture"in a&&(this.bound[n]=new mt(o)),"sampler"in a&&(a.sampler==="comparison"?this.bound[n]=new lt(o):this.bound[n]=new pt(o)),"texture"in a||"storageTexture"in a||"externalTexture"in a||"sampler"in a?this.value[n]=this.bound[n]:Object.defineProperty(this.value,n,{get:()=>this.bound[n].value}),r++}}__init34() {this[_chunkBF35NEOXcjs.a]=!0}__init35() {this.resourceType="bind-group-layout"}__init36() {this.bound={}}__init37() {this.value={}}__init38() {this.$=this.value}toString(){return`bindGroupLayout:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get index(){return this._index}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}$idx(e){return this._index=e,this}unwrap(e){return e.device.createBindGroupLayout({label:_nullishCoalesce(_chunkBF35NEOXcjs.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, () => (Se)),s.buffer={type:"uniform"};else if("storage"in n)o=_nullishCoalesce(o, () => ((n.access==="mutable"?Ln:Se))),s.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=_nullishCoalesce(o, () => (Se)),s.sampler={type:n.sampler};else if("texture"in n)o=_nullishCoalesce(o, () => (Se)),s.texture={sampleType:n.texture,viewDimension:_nullishCoalesce(n.viewDimension, () => ("2d")),multisampled:_nullishCoalesce(n.multisampled, () => (!1))};else if("storageTexture"in n){let i=_nullishCoalesce(n.access, () => ("writeonly"));o=_nullishCoalesce(o, () => ((i==="readonly"?Se:Ln))),s.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[i],viewDimension:_nullishCoalesce(n.viewDimension, () => ("2d"))}}else"externalTexture"in n&&(o=_nullishCoalesce(o, () => (Se)),s.externalTexture={});return _optionalChain([o, 'optionalAccess', _56 => _56.includes, 'call', _57 => _57("compute")])&&(s.visibility|=GPUShaderStage.COMPUTE),_optionalChain([o, 'optionalAccess', _58 => _58.includes, 'call', _59 => _59("vertex")])&&(s.visibility|=GPUShaderStage.VERTEX),_optionalChain([o, 'optionalAccess', _60 => _60.includes, 'call', _61 => _61("fragment")])&&(s.visibility|=GPUShaderStage.FRAGMENT),s}).filter(n=>n!==null)})}}, _class18),ve= (_class19 =class{constructor(e,r){;_class19.prototype.__init39.call(this);this.layout=e;this.entries=r;for(let n of Object.keys(e.entries))if(e.entries[n]!==null&&!(n in r))throw new ar(_chunkBF35NEOXcjs.j.call(void 0, e),n)}__init39() {this.resourceType="bind-group"}unwrap(e){return e.device.createBindGroup({label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this.layout), () => ("<unnamed>")),layout:e.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(_chunkBF35NEOXcjs.j.call(void 0, this.layout), () => ("<unnamed>"))}'.`);if("uniform"in a){let i;if(ee(s)){if(!it(s))throw new (0, _chunkBF35NEOXcjs.r)(s);i={buffer:e.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("storage"in a){let i;if(ee(s)){if(!le(s))throw new Ae(s);i={buffer:e.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("texture"in a){let i;if(N(s)){if(!nr(s))throw new ct(s);i=e.unwrap(s.createView("sampled"))}else Le(s)?i=e.unwrap(s):i=s;return{binding:o,resource:i}}if("storageTexture"in a){let i;if(N(s)){if(!le(s))throw new Ae(s);a.access==="readonly"?i=e.unwrap(s.createView("readonly")):a.access==="mutable"?i=e.unwrap(s.createView("mutable")):i=e.unwrap(s.createView("writeonly"))}else Ee(s)?i=e.unwrap(s):i=s;return{binding:o,resource:i}}if("sampler"in a)return Ve(s)||$e(s)?{binding:o,resource:e.unwrap(s)}:{binding:o,resource:s};if("externalTexture"in a)return{binding:o,resource:s};throw new Error(`Malformed bind group entry: ${s} (${JSON.stringify(s)})`)}).filter(n=>n!==null)})}}, _class19);var On="#CATCHALL#",ur= (_class20 =class{constructor() { _class20.prototype.__init40.call(this);_class20.prototype.__init41.call(this); }__init40() {this._stack=[]}__init41() {this._itemDepth=0}get itemDepth(){return this._itemDepth}get topItem(){let e=this._stack[this._stack.length-1];if(!e||e.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return e}get topFunctionReturnType(){let e=this._stack.findLast(r=>r.type==="functionScope");if(!e)throw new Error("Internal error, expected function scope to be present.");return e.returnType}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}popItem(){this.pop("item")}pushSlotBindings(e){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(e)})}popSlotBindings(){this.pop("slotBinding")}pushFunctionScope(e,r,n,a){this._stack.push({type:"functionScope",args:e,argAliases:r,returnType:n,externalMap:a})}popFunctionScope(){this.pop("functionScope")}pushBlockScope(){this._stack.push({type:"blockScope",declarations:new Map})}popBlockScope(){this.pop("blockScope")}pop(e){let r=this._stack[this._stack.length-1];if(!r||e&&r.type!==e)throw new Error(`Internal error, expected a ${e} layer to be on top.`);this._stack.pop(),e==="item"&&this._itemDepth--}readSlot(e){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _62 => _62.type])==="item")n.usedSlots.add(e);else if(_optionalChain([n, 'optionalAccess', _63 => _63.type])==="slotBinding"){let a=n.bindingMap.get(e);if(a!==void 0)return a}else if(!(_optionalChain([n, 'optionalAccess', _64 => _64.type])==="functionScope"||_optionalChain([n, 'optionalAccess', _65 => _65.type])==="blockScope"))throw new Error("Unknown layer type.")}return e.defaultValue}getSnippetById(e){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _66 => _66.type])==="functionScope"){let a=n.args.find(s=>s.value===e);if(a!==void 0)return a;if(n.argAliases[e])return n.argAliases[e];let o=n.externalMap[e];return o!=null?_chunk3K53YJSUcjs.ka.call(void 0, o):void 0}if(_optionalChain([n, 'optionalAccess', _67 => _67.type])==="blockScope"){let a=n.declarations.get(e);if(a!==void 0)return _chunkBF35NEOXcjs.pa.call(void 0, e,a)}}}defineBlockVariable(e,r){if(r.type==="unknown")throw Error(`Tried to define variable '${e}' of unknown type`);for(let n=this._stack.length-1;n>=0;--n){let a=this._stack[n];if(_optionalChain([a, 'optionalAccess', _68 => _68.type])==="blockScope")return a.declarations.set(e,r),_chunkBF35NEOXcjs.pa.call(void 0, e,r)}throw new Error("No block scope found to define a variable in.")}}, _class20),xt=[""," "," "," "," "," "," "," "," "],ir=xt.length-1,pr= (_class21 =class{constructor() { _class21.prototype.__init42.call(this); }__init42() {this.identLevel=0}get pre(){return _nullishCoalesce(xt[this.identLevel], () => (xt[ir].repeat(this.identLevel/ir)+xt[this.identLevel%ir]))}indent(){let e=this.pre;return this.identLevel++,e}dedent(){return this.identLevel--,this.pre}withResetLevel(e){let r=this.identLevel;this.identLevel=0;try{return e()}finally{this.identLevel=r}}}, _class21),Oe= (_class22 =class{__init43() {this._memoizedResolves=new WeakMap}__init44() {this._memoizedDerived=new WeakMap}__init45() {this._indentController=new pr}__init46() {this._itemStateStack=new ur}#e=[];__init47() {this._declarations=[]}get varyingLocations(){return this._varyingLocations}__init48() {this[_chunkBF35NEOXcjs.a]={itemStateStack:this._itemStateStack}}__init49() {this.bindGroupLayoutsToPlaceholderMap=new Map}__init50() {this._nextFreeLayoutPlaceholderIdx=0}__init51() {this.fixedBindings=[]}constructor(e){;_class22.prototype.__init43.call(this);_class22.prototype.__init44.call(this);_class22.prototype.__init45.call(this);_class22.prototype.__init46.call(this);_class22.prototype.__init47.call(this);_class22.prototype.__init48.call(this);_class22.prototype.__init49.call(this);_class22.prototype.__init50.call(this);_class22.prototype.__init51.call(this);this.names=e.names}get pre(){return this._indentController.pre}get topFunctionReturnType(){return this._itemStateStack.topFunctionReturnType}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}withResetIndentLevel(e){return this._indentController.withResetLevel(e)}getById(e){let r=this._itemStateStack.getSnippetById(e);return r===void 0?null:r}defineVariable(e,r){return this._itemStateStack.defineBlockVariable(e,r)}pushBlockScope(){this._itemStateStack.pushBlockScope()}popBlockScope(){this._itemStateStack.popBlockScope()}fnToWgsl(e){this._itemStateStack.pushFunctionScope(e.args,e.argAliases,e.returnType,e.externalMap);try{return{head:Ea(this,e.args,e.returnType),body:_chunk3K53YJSUcjs.ta.call(void 0, this,e.body)}}finally{this._itemStateStack.popFunctionScope()}}addDeclaration(e){this._declarations.push(e)}allocateLayoutEntry(e){let r=this.bindGroupLayoutsToPlaceholderMap,n=r.get(e);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,r.set(e,n)),n}allocateFixedEntry(e,r){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:e,resource:r}),{group:On,binding:n}}readSlot(e){let r=this._itemStateStack.readSlot(e);if(r===void 0)throw new (0, _chunkBF35NEOXcjs.q)(e);return r}withSlots(e,r){this._itemStateStack.pushSlotBindings(e);try{return r()}finally{this._itemStateStack.popSlotBindings()}}withVaryingLocations(e,r){this._varyingLocations=e;try{return r()}finally{this._varyingLocations=void 0}}unwrap(e){if(_chunkBF35NEOXcjs.A.call(void 0, e))return this.withSlots(e[_chunkBF35NEOXcjs.e].pairs,()=>this.unwrap(e[_chunkBF35NEOXcjs.e].inner));let r=e;for(;;)if(_chunkBF35NEOXcjs.y.call(void 0, r))r=this.readSlot(r);else if(_chunkBF35NEOXcjs.z.call(void 0, r))r=this._getOrCompute(r);else break;return r}_getOrCompute(e){let r=_nullishCoalesce(this._memoizedDerived.get(e), () => ([]));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 _chunkBF35NEOXcjs.Z);let n;try{n=e["~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._memoizedDerived.set(e,r),n}catch(n){throw n instanceof _chunkBF35NEOXcjs.o?n.appendToTrace(e):new (0, _chunkBF35NEOXcjs.o)(n,[e])}finally{this._itemStateStack.popItem()}}_getOrInstantiate(e){let r=_nullishCoalesce(this._memoizedResolves.get(e), () => ([]));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;_chunk3K53YJSUcjs.i.call(void 0, e)?n=Ht(this,e):_chunkBF35NEOXcjs.z.call(void 0, e)||_chunkBF35NEOXcjs.y.call(void 0, e)?n=this.resolve(this.unwrap(e)):_chunkBF35NEOXcjs.aa.call(void 0, e)?n=e["~resolve"](this):n=this.resolveValue(e);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._memoizedResolves.set(e,r),n}catch(n){throw n instanceof _chunkBF35NEOXcjs.o?n.appendToTrace(e):new (0, _chunkBF35NEOXcjs.o)(n,[e])}finally{this._itemStateStack.popItem()}}resolve(e){if(_chunkBF35NEOXcjs.A.call(void 0, e))return this.withSlots(e[_chunkBF35NEOXcjs.e].pairs,()=>this.resolve(e[_chunkBF35NEOXcjs.e].inner));if(e&&typeof e=="object"||typeof e=="function"){if(this._itemStateStack.itemDepth===0)try{this.pushMode(new _chunkBF35NEOXcjs._);let r=_chunkBF35NEOXcjs.ha.call(void 0, this,()=>this._getOrInstantiate(e));return`${[...this._declarations].join(`
16
+ Falling back to default writer`)}}var we={bool(){throw new Error("Booleans are not host-shareable")},f32(t,e,r){t.writeFloat32(r)},f16(t,e,r){t.writeFloat16(r)},i32(t,e,r){t.writeInt32(r)},u32(t,e,r){t.writeUint32(r)},u16(t,e,r){t.writeUint16(r)},vec2f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y)},vec2h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y)},vec2i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y)},vec2u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y)},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},vec3f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z)},vec3h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z)},vec3i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z)},vec3u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z)},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},vec4f(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z),t.writeFloat32(r.w)},vec4h(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z),t.writeFloat16(r.w)},vec4i(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z),t.writeInt32(r.w)},vec4u(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z),t.writeUint32(r.w)},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},mat3x3f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},mat4x4f(t,e,r){for(let n=0;n<r.length;++n)t.writeFloat32(r[n])},struct(t,e,r){let n=_chunkCYZBRBPDcjs.a.call(void 0, e);F(t,n);for(let[a,o]of Object.entries(e.propTypes))F(t,_chunkCYZBRBPDcjs.a.call(void 0, o)),pe(t,o,r[a]);F(t,n)},array(t,e,r){if(e.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkCYZBRBPDcjs.a.call(void 0, e);F(t,n);let a=t.currentByteOffset;for(let o=0;o<Math.min(e.elementCount,r.length);o++)F(t,n),pe(t,e.elementType,r[o]);t.seekTo(a+_chunkCYZBRBPDcjs.e.call(void 0, e))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(t,e,r){_optionalChain([we, 'access', _16 => _16[e.inner.type], 'optionalCall', _17 => _17(t,e,r)])},decorated(t,e,r){let n=_chunkCYZBRBPDcjs.b.call(void 0, e);F(t,n);let a=t.currentByteOffset;_optionalChain([we, 'access', _18 => _18[_optionalChain([e, 'access', _19 => _19.inner, 'optionalAccess', _20 => _20.type])], 'optionalCall', _21 => _21(t,e.inner,r)]),t.seekTo(a+_chunkCYZBRBPDcjs.e.call(void 0, e))},uint8(t,e,r){t.writeUint8(r)},uint8x2(t,e,r){t.writeUint8(r.x),t.writeUint8(r.y)},uint8x4(t,e,r){t.writeUint8(r.x),t.writeUint8(r.y),t.writeUint8(r.z),t.writeUint8(r.w)},sint8(t,e,r){t.writeInt8(r)},sint8x2(t,e,r){t.writeInt8(r.x),t.writeInt8(r.y)},sint8x4(t,e,r){t.writeInt8(r.x),t.writeInt8(r.y),t.writeInt8(r.z),t.writeInt8(r.w)},unorm8(t,e,r){t.writeUint8(Math.round(r*255))},unorm8x2(t,e,r){t.writeUint8(Math.round(r.x*255)),t.writeUint8(Math.round(r.y*255))},unorm8x4(t,e,r){t.writeUint8(Math.round(r.x*255)),t.writeUint8(Math.round(r.y*255)),t.writeUint8(Math.round(r.z*255)),t.writeUint8(Math.round(r.w*255))},snorm8(t,e,r){t.writeInt8(Math.round(r*127))},snorm8x2(t,e,r){t.writeInt8(Math.round(r.x*127)),t.writeInt8(Math.round(r.y*127))},snorm8x4(t,e,r){t.writeInt8(Math.round(r.x*127)),t.writeInt8(Math.round(r.y*127)),t.writeInt8(Math.round(r.z*127)),t.writeInt8(Math.round(r.w*127))},uint16(t,e,r){t.writeUint16(r)},uint16x2(t,e,r){t.writeUint16(r.x),t.writeUint16(r.y)},uint16x4(t,e,r){t.writeUint16(r.x),t.writeUint16(r.y),t.writeUint16(r.z),t.writeUint16(r.w)},sint16(t,e,r){t.writeInt16(r)},sint16x2(t,e,r){t.writeInt16(r.x),t.writeInt16(r.y)},sint16x4(t,e,r){t.writeInt16(r.x),t.writeInt16(r.y),t.writeInt16(r.z),t.writeInt16(r.w)},unorm16(t,e,r){t.writeUint16(r*65535)},unorm16x2(t,e,r){t.writeUint16(r.x*65535),t.writeUint16(r.y*65535)},unorm16x4(t,e,r){t.writeUint16(r.x*65535),t.writeUint16(r.y*65535),t.writeUint16(r.z*65535),t.writeUint16(r.w*65535)},snorm16(t,e,r){t.writeInt16(Math.round(r*32767))},snorm16x2(t,e,r){t.writeInt16(Math.round(r.x*32767)),t.writeInt16(Math.round(r.y*32767))},snorm16x4(t,e,r){t.writeInt16(Math.round(r.x*32767)),t.writeInt16(Math.round(r.y*32767)),t.writeInt16(Math.round(r.z*32767)),t.writeInt16(Math.round(r.w*32767))},float16(t,e,r){t.writeFloat16(r)},float16x2(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y)},float16x4(t,e,r){t.writeFloat16(r.x),t.writeFloat16(r.y),t.writeFloat16(r.z),t.writeFloat16(r.w)},float32(t,e,r){t.writeFloat32(r)},float32x2(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y)},float32x3(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z)},float32x4(t,e,r){t.writeFloat32(r.x),t.writeFloat32(r.y),t.writeFloat32(r.z),t.writeFloat32(r.w)},uint32(t,e,r){t.writeUint32(r)},uint32x2(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y)},uint32x3(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z)},uint32x4(t,e,r){t.writeUint32(r.x),t.writeUint32(r.y),t.writeUint32(r.z),t.writeUint32(r.w)},sint32(t,e,r){t.writeInt32(r)},sint32x2(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y)},sint32x3(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z)},sint32x4(t,e,r){t.writeInt32(r.x),t.writeInt32(r.y),t.writeInt32(r.z),t.writeInt32(r.w)},"unorm10-10-10-2"(t,e,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,t.writeUint32(n)},"unorm8x4-bgra"(t,e,r){t.writeUint8(r.z*255),t.writeUint8(r.y*255),t.writeUint8(r.x*255),t.writeUint8(r.w*255)},disarray(t,e,r){let n=_chunkCYZBRBPDcjs.a.call(void 0, e);F(t,n);let a=t.currentByteOffset;for(let o=0;o<Math.min(e.elementCount,r.length);o++)F(t,n),_optionalChain([we, 'access', _22 => _22[_optionalChain([e, 'access', _23 => _23.elementType, 'optionalAccess', _24 => _24.type])], 'optionalCall', _25 => _25(t,e.elementType,r[o])]);t.seekTo(a+_chunkCYZBRBPDcjs.e.call(void 0, e))},unstruct(t,e,r){let n=e.propTypes;for(let[a,o]of Object.entries(n))_optionalChain([we, 'access', _26 => _26[o.type], 'optionalCall', _27 => _27(t,o,r[a])])},"loose-decorated"(t,e,r){let n=_chunkCYZBRBPDcjs.b.call(void 0, e);F(t,n);let a=t.currentByteOffset,o=we[_optionalChain([e, 'access', _28 => _28.inner, 'optionalAccess', _29 => _29.type])];return _optionalChain([o, 'optionalCall', _30 => _30(t,e.inner,r)]),t.seekTo(a+_chunkCYZBRBPDcjs.e.call(void 0, e)),r}};function pe(t,e,r){let n=we[e.type];if(!n)throw new Error(`Cannot write data of type '${e.type}'.`);n(t,e,r)}var Ba={bool(){throw new Error("Booleans are not host-shareable")},f32(t){return t.readFloat32()},f16(t){return t.readFloat16()},i32(t){return t.readInt32()},u32(t){return t.readUint32()},u16(t){return t.readUint16()},vec2f(t){return _chunk2VTISQYPcjs.Ia.call(void 0, t.readFloat32(),t.readFloat32())},vec3f(t){return _chunk2VTISQYPcjs.Na.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32())},vec4f(t){return _chunk2VTISQYPcjs.Sa.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},vec2h(t){return _chunk2VTISQYPcjs.Ja.call(void 0, t.readFloat16(),t.readFloat16())},vec3h(t){return _chunk2VTISQYPcjs.Oa.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16())},vec4h(t){return _chunk2VTISQYPcjs.Ta.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16())},vec2i(t){return _chunk2VTISQYPcjs.Ka.call(void 0, t.readInt32(),t.readInt32())},vec3i(t){return _chunk2VTISQYPcjs.Pa.call(void 0, t.readInt32(),t.readInt32(),t.readInt32())},vec4i(t){return _chunk2VTISQYPcjs.Ua.call(void 0, t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32())},vec2u(t){return _chunk2VTISQYPcjs.La.call(void 0, t.readUint32(),t.readUint32())},vec3u(t){return _chunk2VTISQYPcjs.Qa.call(void 0, t.readUint32(),t.readUint32(),t.readUint32())},vec4u(t){return _chunk2VTISQYPcjs.Va.call(void 0, t.readUint32(),t.readUint32(),t.readUint32(),t.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(t){return _chunk2VTISQYPcjs.eb.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},mat3x3f(t){let e=()=>{let r=t.readFloat32();return t.readFloat32(),r};return _chunk2VTISQYPcjs.fb.call(void 0, t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e(),t.readFloat32(),t.readFloat32(),e())},mat4x4f(t){return _chunk2VTISQYPcjs.gb.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32())},struct(t,e){let r=_chunkCYZBRBPDcjs.a.call(void 0, e);F(t,r);let n={},a=e.propTypes;for(let[o,s]of Object.entries(a))F(t,_chunkCYZBRBPDcjs.a.call(void 0, s)),n[o]=E(t,s);return F(t,r),n},array(t,e){if(e.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkCYZBRBPDcjs.a.call(void 0, e),n=[];for(let a=0;a<e.elementCount;a++){F(t,r);let o=e.elementType,s=E(t,o);n.push(s)}return F(t,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(t,e){return E(t,e.inner)},decorated(t,e){let r=_chunkCYZBRBPDcjs.b.call(void 0, e);F(t,r);let n=t.currentByteOffset,a=E(t,e.inner);return t.seekTo(n+_chunkCYZBRBPDcjs.e.call(void 0, e)),a},uint8:t=>t.readUint8(),uint8x2:t=>_chunk2VTISQYPcjs.La.call(void 0, t.readUint8(),t.readUint8()),uint8x4:t=>_chunk2VTISQYPcjs.Va.call(void 0, t.readUint8(),t.readUint8(),t.readUint8(),t.readUint8()),sint8:t=>t.readInt8(),sint8x2:t=>_chunk2VTISQYPcjs.Ka.call(void 0, t.readInt8(),t.readInt8()),sint8x4:t=>_chunk2VTISQYPcjs.Ua.call(void 0, t.readInt8(),t.readInt8(),t.readInt8(),t.readInt8()),unorm8:t=>t.readUint8()/255,unorm8x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readUint8()/255,t.readUint8()/255),unorm8x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readUint8()/255,t.readUint8()/255,t.readUint8()/255,t.readUint8()/255),snorm8:t=>t.readInt8()/127,snorm8x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readInt8()/127,t.readInt8()/127),snorm8x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readInt8()/127,t.readInt8()/127,t.readInt8()/127,t.readInt8()/127),uint16:t=>t.readUint16(),uint16x2:t=>_chunk2VTISQYPcjs.La.call(void 0, t.readUint16(),t.readUint16()),uint16x4:t=>_chunk2VTISQYPcjs.Va.call(void 0, t.readUint16(),t.readUint16(),t.readUint16(),t.readUint16()),sint16:t=>t.readInt16(),sint16x2:t=>_chunk2VTISQYPcjs.Ka.call(void 0, t.readInt16(),t.readInt16()),sint16x4:t=>_chunk2VTISQYPcjs.Ua.call(void 0, t.readInt16(),t.readInt16(),t.readInt16(),t.readInt16()),unorm16:t=>t.readUint16()/65535,unorm16x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readUint16()/65535,t.readUint16()/65535),unorm16x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535,t.readUint16()/65535),snorm16:t=>t.readInt16()/32767,snorm16x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readInt16()/32767,t.readInt16()/32767),snorm16x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readInt16()/32767,t.readInt16()/32767,t.readInt16()/32767,t.readInt16()/32767),float16(t){return t.readFloat16()},float16x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readFloat16(),t.readFloat16()),float16x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readFloat16(),t.readFloat16(),t.readFloat16(),t.readFloat16()),float32:t=>t.readFloat32(),float32x2:t=>_chunk2VTISQYPcjs.Ia.call(void 0, t.readFloat32(),t.readFloat32()),float32x3:t=>_chunk2VTISQYPcjs.Na.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32()),float32x4:t=>_chunk2VTISQYPcjs.Sa.call(void 0, t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()),uint32:t=>t.readUint32(),uint32x2:t=>_chunk2VTISQYPcjs.La.call(void 0, t.readUint32(),t.readUint32()),uint32x3:t=>_chunk2VTISQYPcjs.Qa.call(void 0, t.readUint32(),t.readUint32(),t.readUint32()),uint32x4:t=>_chunk2VTISQYPcjs.Va.call(void 0, t.readUint32(),t.readUint32(),t.readUint32(),t.readUint32()),sint32:t=>t.readInt32(),sint32x2:t=>_chunk2VTISQYPcjs.Ka.call(void 0, t.readInt32(),t.readInt32()),sint32x3:t=>_chunk2VTISQYPcjs.Pa.call(void 0, t.readInt32(),t.readInt32(),t.readInt32()),sint32x4:t=>_chunk2VTISQYPcjs.Ua.call(void 0, t.readInt32(),t.readInt32(),t.readInt32(),t.readInt32()),"unorm10-10-10-2"(t){let e=t.readUint32(),r=(e>>22)/1023,n=(e>>12&1023)/1023,a=(e>>2&1023)/1023,o=(e&3)/3;return _chunk2VTISQYPcjs.Sa.call(void 0, r,n,a,o)},"unorm8x4-bgra"(t){let e=t.readByte()/255,r=t.readByte()/255,n=t.readByte()/255,a=t.readByte()/255;return _chunk2VTISQYPcjs.Sa.call(void 0, n,r,e,a)},unstruct(t,e){let r={},n=e.propTypes;for(let[a,o]of Object.entries(n))r[a]=E(t,o);return r},disarray(t,e){let r=_chunkCYZBRBPDcjs.a.call(void 0, e),n=[];for(let a=0;a<e.elementCount;a++)F(t,r),n.push(E(t,e.elementType));return F(t,r),n},"loose-decorated"(t,e){F(t,_chunkCYZBRBPDcjs.b.call(void 0, e));let r=t.currentByteOffset,n=E(t,e.inner);return t.seekTo(r+_chunkCYZBRBPDcjs.e.call(void 0, e)),n}};function E(t,e){let r=Ba[e.type];if(!r)throw new Error(`Cannot read data of type '${e.type}'.`);return r(t,e)}function wn(t,e){let r=_chunkCYZBRBPDcjs.e.call(void 0, t);if(r===0||e===void 0||e===null)return[];let n=new ArrayBuffer(r),a=new (0, _typedbinary.BufferWriter)(n),o=[];function s(l,f,g,c){if(f!=null){if(_chunk2VTISQYPcjs.K.call(void 0, l)||_chunk2VTISQYPcjs.la.call(void 0, l)){let y=nt(l);for(let[x,I]of Object.entries(y)){let w=l.propTypes[x];if(!w)continue;let S=f[x];S!==void 0&&s(w,S,g+I.offset,_nullishCoalesce(I.padding, () => (c)))}return}if(_chunk2VTISQYPcjs.J.call(void 0, l)||_chunk2VTISQYPcjs.ka.call(void 0, l)){let y=l,x=_chunkCYZBRBPDcjs.d.call(void 0, _chunkCYZBRBPDcjs.e.call(void 0, y.elementType),_chunkCYZBRBPDcjs.a.call(void 0, y.elementType));if(!Array.isArray(f))throw new Error("Partial value for array must be an array");let I=_nullishCoalesce(f, () => ([]));I.sort((w,S)=>w.idx-S.idx);for(let{idx:w,value:S}of I)s(y.elementType,S,g+w*x,x-_chunkCYZBRBPDcjs.e.call(void 0, y.elementType))}else{let y=_chunkCYZBRBPDcjs.e.call(void 0, l);a.seekTo(g),pe(a,l,f),o.push({start:g,end:g+y,padding:c})}}}if(s(t,e,0),o.length===0)return[];let i=[],p=o[0];for(let l=1;l<o.length;l++){let f=o[l];if(!f||!p)throw new Error("Internal error: missing segment");f.start===p.end+(_nullishCoalesce(p.padding, () => (0)))?(p.end=f.end,p.padding=f.padding):(i.push({data:new Uint8Array(n,p.start,p.end-p.start)}),p=f)}if(!p)throw new Error("Internal error: missing segment");return i.push({data:new Uint8Array(n,p.start,p.end-p.start)}),i}function le(t){return!!_optionalChain([t, 'optionalAccess', _31 => _31.usableAsStorage])}var Ae=class t extends Error{constructor(e){super(`Resource '${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, e), () => ("<unnamed>"))}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,t.prototype)}};function it(t){return!!t.usableAsUniform}var In={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},Ce= (_class6 =class{constructor(e,r){;_class6.prototype.__init7.call(this);this.usage=e;this.buffer=r;this[_chunk2VTISQYPcjs.a]={dataType:r.dataType},this[_chunk2VTISQYPcjs.d]=r}__init7() {this.resourceType="buffer-usage"}$name(e){return this.buffer.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),o=In[this.usage];return e.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${e.resolve(this.buffer.dataType)};`),r}toString(){return`${this.usage}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](){return new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:this.buffer.dataType},k)}get $(){let e=_chunk2VTISQYPcjs.fa.call(void 0, ),r=_chunk2VTISQYPcjs.ba.call(void 0, );if(e.type==="normal")throw new (0, _chunk2VTISQYPcjs.t)(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 e.type==="codegen"?this[_chunk2VTISQYPcjs.c]():e.type==="simulate"?(e.buffers.has(this.buffer)||e.buffers.set(this.buffer,_chunk2VTISQYPcjs.ic.call(void 0, this.buffer.dataType,this.buffer.initial)),e.buffers.get(this.buffer)):_chunk2VTISQYPcjs.ib.call(void 0, e,"bufferUsage.ts#TgpuFixedBufferImpl/$")}get value(){return this.$}set $(e){let r=_chunk2VTISQYPcjs.fa.call(void 0, ),n=_chunk2VTISQYPcjs.ba.call(void 0, );if(r.type==="normal")throw new (0, _chunk2VTISQYPcjs.t)(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,e);return}_chunk2VTISQYPcjs.ib.call(void 0, r,"bufferUsage.ts#TgpuFixedBufferImpl/$")}set value(e){this.$=e}}, _class6),Re= (_class7 =class{constructor(e,r,n){;_class7.prototype.__init8.call(this);this.usage=e;this.dataType=r;this._membership=n;this[_chunk2VTISQYPcjs.a]={dataType:r},_chunk2VTISQYPcjs.h.call(void 0, this,n.key)}__init8() {this.resourceType="buffer-usage"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=In[this.usage];return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${e.resolve(this.dataType)};`),r}toString(){return`${this.usage}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](){return new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:this.dataType},k)}get $(){if(_chunk2VTISQYPcjs.ga.call(void 0, ))return this[_chunk2VTISQYPcjs.c]();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),Sn=new WeakMap;function Fn(t){if(!le(t))throw new Error(`Cannot pass ${t} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let e=Sn.get(t);return e||(e=new Ce("mutable",t),Sn.set(t,e)),e}var vn=new WeakMap;function Un(t){if(!le(t))throw new Error(`Cannot pass ${t} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let e=vn.get(t);return e||(e=new Ce("readonly",t),vn.set(t,e)),e}var Dn=new WeakMap;function Pn(t){if(!it(t))throw new Error(`Cannot pass ${t} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let e=Dn.get(t);return e||(e=new Ce("uniform",t),Dn.set(t,e)),e}var Ra={uniform:Pn,mutable:Fn,readonly:Un};function Ge(t,e,r){return _chunk2VTISQYPcjs.I.call(void 0, e)?new ut(t,e,r):new ut(t,e,r,["storage","uniform"])}function ee(t){return t.resourceType==="buffer"}function Ga(t){return!!t.usableAsVertex}var Va=_typedbinary.getSystemEndianness.call(void 0, ),ut= (_class8 =class{constructor(e,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._group=e;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;_chunk2VTISQYPcjs.Z.call(void 0, n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}__init9() {this[_chunk2VTISQYPcjs.a]=!0}__init10() {this.resourceType="buffer"}__init11() {this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC}__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(){let e=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=e.createBuffer({size:_chunkCYZBRBPDcjs.e.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}),this.initial)){let r=new (0, _typedbinary.BufferWriter)(this._buffer.getMappedRange());pe(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this._buffer&&(this._buffer.label=e),this}$usage(...e){for(let r of e){if(_optionalChain([this, 'access', _32 => _32._disallowedUsages, 'optionalAccess', _33 => _33.includes, 'call', _34 => _34(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(e){if(!this._ownBuffer)throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");return e&GPUBufferUsage.MAP_READ?(this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this):e&GPUBufferUsage.MAP_WRITE?(this.flags=GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,this):(this.flags|=e,this)}compileWriter(){Qt(this.dataType)}_writeToTarget(e,r){let n=Qt(this.dataType);if(n)try{n(new DataView(e),0,r,Va==="little");return}catch(a){console.error(`Error when using compiled writer for buffer ${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
17
+ Using fallback writer instead.`,a)}pe(new (0, _typedbinary.BufferWriter)(e),this.dataType,r)}write(e){let r=this.buffer,n=this._group.device;if(r.mapState==="mapped"){let o=r.getMappedRange();this._writeToTarget(o,e);return}let a=_chunkCYZBRBPDcjs.e.call(void 0, this.dataType);this._hostBuffer||(this._hostBuffer=new ArrayBuffer(a)),this._group.flush(),this._writeToTarget(this._hostBuffer,e),n.queue.writeBuffer(r,0,this._hostBuffer,0,a)}writePartial(e){let r=this.buffer,n=this._group.device,a=wn(this.dataType,e);if(r.mapState==="mapped"){let o=r.getMappedRange(),s=new Uint8Array(o);for(let i of a)s.set(i.data,i.data.byteOffset)}else for(let o of a)n.queue.writeBuffer(r,o.data.byteOffset,o.data,0,o.data.byteLength)}copyFrom(e){if(this.buffer.mapState==="mapped")throw new Error("Cannot copy to a mapped buffer.");let r=_chunkCYZBRBPDcjs.e.call(void 0, this.dataType);this._group.commandEncoder.copyBufferToBuffer(e.buffer,0,this.buffer,0,r)}async read(){this._group.flush();let e=this.buffer,r=this._group.device;if(e.mapState==="mapped"){let s=e.getMappedRange();return E(new (0, _typedbinary.BufferReader)(s),this.dataType)}if(e.usage&GPUBufferUsage.MAP_READ){await e.mapAsync(GPUMapMode.READ);let s=e.getMappedRange(),i=E(new (0, _typedbinary.BufferReader)(s),this.dataType);return e.unmap(),i}let n=r.createBuffer({size:_chunkCYZBRBPDcjs.e.call(void 0, this.dataType),usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder();a.copyBufferToBuffer(e,0,n,0,_chunkCYZBRBPDcjs.e.call(void 0, this.dataType)),r.queue.submit([a.finish()]),await r.queue.onSubmittedWorkDone(),await n.mapAsync(GPUMapMode.READ,0,_chunkCYZBRBPDcjs.e.call(void 0, this.dataType));let o=E(new (0, _typedbinary.BufferReader)(n.getMappedRange()),this.dataType);return n.unmap(),n.destroy(),o}as(e){return _optionalChain([Ra, 'access', _35 => _35[e], 'optionalCall', _36 => _36(this)])}destroy(){this._destroyed||(this._destroyed=!0,this._ownBuffer&&_optionalChain([this, 'access', _37 => _37._buffer, 'optionalAccess', _38 => _38.destroy, 'call', _39 => _39()]))}toString(){return`buffer:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class8);function An(t){return new Kt(t)}function Cn(t){return new Yt(t)}function Ve(t){let e=t;return _optionalChain([e, 'optionalAccess', _40 => _40.resourceType])==="sampler"&&!!e[_chunk2VTISQYPcjs.a]}function $e(t){let e=t;return _optionalChain([e, 'optionalAccess', _41 => _41.resourceType])==="sampler-comparison"&&!!e[_chunk2VTISQYPcjs.a]}var pt= (_class9 =class{constructor(e){;_class9.prototype.__init18.call(this);this._membership=e;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={},_chunk2VTISQYPcjs.h.call(void 0, this,e.key)}__init18() {this.resourceType="sampler"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class9),lt= (_class10 =class{constructor(e){;_class10.prototype.__init19.call(this);this._membership=e;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={},_chunk2VTISQYPcjs.h.call(void 0, this,e.key)}__init19() {this.resourceType="sampler-comparison"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class10),Kt= (_class11 =class{constructor(e){;_class11.prototype.__init20.call(this);_class11.prototype.__init21.call(this);this._props=e;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={unwrap:r=>(this._sampler||(this._sampler=r.device.createSampler({...this._props,label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))})),this._sampler)},this._filtering=e.minFilter==="linear"||e.magFilter==="linear"||e.mipmapFilter==="linear"}__init20() {this.resourceType="sampler"}__init21() {this._sampler=null}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({sampler:this._filtering?"filtering":"non-filtering"},this);return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class11),Yt= (_class12 =class{constructor(e){;_class12.prototype.__init22.call(this);_class12.prototype.__init23.call(this);this._props=e;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={unwrap:r=>(this._sampler||(this._sampler=r.device.createSampler({...this._props,label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))})),this._sampler)}}__init22() {this.resourceType="sampler-comparison"}__init23() {this._sampler=null}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({sampler:"comparison"},this);return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class12);var mt= (_class13 =class{constructor(e){;_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);this._membership=e;_chunk2VTISQYPcjs.h.call(void 0, this,e.key)}__init24() {this[_chunk2VTISQYPcjs.a]=!0}__init25() {this.resourceType="external-texture"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout);return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class13);var Rn={r8unorm:_chunk2VTISQYPcjs.Fa,r8snorm:_chunk2VTISQYPcjs.Fa,r8uint:_chunk2VTISQYPcjs.Ca,r8sint:_chunk2VTISQYPcjs.Ea,r16uint:_chunk2VTISQYPcjs.Ca,r16sint:_chunk2VTISQYPcjs.Ea,r16float:_chunk2VTISQYPcjs.Fa,rg8unorm:_chunk2VTISQYPcjs.Fa,rg8snorm:_chunk2VTISQYPcjs.Fa,rg8uint:_chunk2VTISQYPcjs.Ca,rg8sint:_chunk2VTISQYPcjs.Ea,r32uint:_chunk2VTISQYPcjs.Ca,r32sint:_chunk2VTISQYPcjs.Ea,r32float:_chunk2VTISQYPcjs.Fa,rg16uint:_chunk2VTISQYPcjs.Ca,rg16sint:_chunk2VTISQYPcjs.Ea,rg16float:_chunk2VTISQYPcjs.Fa,rgba8unorm:_chunk2VTISQYPcjs.Fa,"rgba8unorm-srgb":_chunk2VTISQYPcjs.Fa,rgba8snorm:_chunk2VTISQYPcjs.Fa,rgba8uint:_chunk2VTISQYPcjs.Ca,rgba8sint:_chunk2VTISQYPcjs.Ea,bgra8unorm:_chunk2VTISQYPcjs.Fa,"bgra8unorm-srgb":_chunk2VTISQYPcjs.Fa,rgb9e5ufloat:_chunk2VTISQYPcjs.Fa,rgb10a2uint:_chunk2VTISQYPcjs.Ca,rgb10a2unorm:_chunk2VTISQYPcjs.Fa,rg11b10ufloat:_chunk2VTISQYPcjs.Fa,rg32uint:_chunk2VTISQYPcjs.Ca,rg32sint:_chunk2VTISQYPcjs.Ea,rg32float:_chunk2VTISQYPcjs.Fa,rgba16uint:_chunk2VTISQYPcjs.Ca,rgba16sint:_chunk2VTISQYPcjs.Ea,rgba16float:_chunk2VTISQYPcjs.Fa,rgba32uint:_chunk2VTISQYPcjs.Ca,rgba32sint:_chunk2VTISQYPcjs.Ea,rgba32float:_chunk2VTISQYPcjs.Fa,stencil8:_chunk2VTISQYPcjs.Fa,depth16unorm:_chunk2VTISQYPcjs.Fa,depth24plus:_chunk2VTISQYPcjs.Fa,"depth24plus-stencil8":_chunk2VTISQYPcjs.Fa,depth32float:_chunk2VTISQYPcjs.Fa,"depth32float-stencil8":_chunk2VTISQYPcjs.Fa,"bc1-rgba-unorm":_chunk2VTISQYPcjs.Fa,"bc1-rgba-unorm-srgb":_chunk2VTISQYPcjs.Fa,"bc2-rgba-unorm":_chunk2VTISQYPcjs.Fa,"bc2-rgba-unorm-srgb":_chunk2VTISQYPcjs.Fa,"bc3-rgba-unorm":_chunk2VTISQYPcjs.Fa,"bc3-rgba-unorm-srgb":_chunk2VTISQYPcjs.Fa,"bc4-r-unorm":_chunk2VTISQYPcjs.Fa,"bc4-r-snorm":_chunk2VTISQYPcjs.Fa,"bc5-rg-unorm":_chunk2VTISQYPcjs.Fa,"bc5-rg-snorm":_chunk2VTISQYPcjs.Fa,"bc6h-rgb-ufloat":_chunk2VTISQYPcjs.Fa,"bc6h-rgb-float":_chunk2VTISQYPcjs.Fa,"bc7-rgba-unorm":_chunk2VTISQYPcjs.Fa,"bc7-rgba-unorm-srgb":_chunk2VTISQYPcjs.Fa,"etc2-rgb8unorm":_chunk2VTISQYPcjs.Fa,"etc2-rgb8unorm-srgb":_chunk2VTISQYPcjs.Fa,"etc2-rgb8a1unorm":_chunk2VTISQYPcjs.Fa,"etc2-rgb8a1unorm-srgb":_chunk2VTISQYPcjs.Fa,"etc2-rgba8unorm":_chunk2VTISQYPcjs.Fa,"etc2-rgba8unorm-srgb":_chunk2VTISQYPcjs.Fa,"eac-r11unorm":_chunk2VTISQYPcjs.Fa,"eac-r11snorm":_chunk2VTISQYPcjs.Fa,"eac-rg11unorm":_chunk2VTISQYPcjs.Fa,"eac-rg11snorm":_chunk2VTISQYPcjs.Fa,"astc-4x4-unorm":_chunk2VTISQYPcjs.Fa,"astc-4x4-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-5x4-unorm":_chunk2VTISQYPcjs.Fa,"astc-5x4-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-5x5-unorm":_chunk2VTISQYPcjs.Fa,"astc-5x5-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-6x5-unorm":_chunk2VTISQYPcjs.Fa,"astc-6x5-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-6x6-unorm":_chunk2VTISQYPcjs.Fa,"astc-6x6-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-8x5-unorm":_chunk2VTISQYPcjs.Fa,"astc-8x5-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-8x6-unorm":_chunk2VTISQYPcjs.Fa,"astc-8x6-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-8x8-unorm":_chunk2VTISQYPcjs.Fa,"astc-8x8-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-10x5-unorm":_chunk2VTISQYPcjs.Fa,"astc-10x5-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-10x6-unorm":_chunk2VTISQYPcjs.Fa,"astc-10x6-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-10x8-unorm":_chunk2VTISQYPcjs.Fa,"astc-10x8-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-10x10-unorm":_chunk2VTISQYPcjs.Fa,"astc-10x10-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-12x10-unorm":_chunk2VTISQYPcjs.Fa,"astc-12x10-unorm-srgb":_chunk2VTISQYPcjs.Fa,"astc-12x12-unorm":_chunk2VTISQYPcjs.Fa,"astc-12x12-unorm-srgb":_chunk2VTISQYPcjs.Fa,r16snorm:_chunk2VTISQYPcjs.Fa,r16unorm:_chunk2VTISQYPcjs.Fa,rg16unorm:_chunk2VTISQYPcjs.Fa,rg16snorm:_chunk2VTISQYPcjs.Fa,rgba16unorm:_chunk2VTISQYPcjs.Fa,rgba16snorm:_chunk2VTISQYPcjs.Fa},_e={rgba8unorm:_chunk2VTISQYPcjs.Sa,rgba8snorm:_chunk2VTISQYPcjs.Sa,rgba8uint:_chunk2VTISQYPcjs.Va,rgba8sint:_chunk2VTISQYPcjs.Ua,rgba16uint:_chunk2VTISQYPcjs.Va,rgba16sint:_chunk2VTISQYPcjs.Ua,rgba16float:_chunk2VTISQYPcjs.Sa,r32uint:_chunk2VTISQYPcjs.Va,r32sint:_chunk2VTISQYPcjs.Ua,r32float:_chunk2VTISQYPcjs.Sa,rg32uint:_chunk2VTISQYPcjs.Va,rg32sint:_chunk2VTISQYPcjs.Ua,rg32float:_chunk2VTISQYPcjs.Sa,rgba32uint:_chunk2VTISQYPcjs.Va,rgba32sint:_chunk2VTISQYPcjs.Ua,rgba32float:_chunk2VTISQYPcjs.Sa,bgra8unorm:_chunk2VTISQYPcjs.Sa},Gn={f32:"float",u32:"uint",i32:"sint"},Vn={float:_chunk2VTISQYPcjs.Fa,"unfilterable-float":_chunk2VTISQYPcjs.Fa,uint:_chunk2VTISQYPcjs.Ca,sint:_chunk2VTISQYPcjs.Ea,depth:_chunk2VTISQYPcjs.Fa};function $n(t,e){return new Jt(t,e)}function N(t){return _optionalChain([t, 'optionalAccess', _42 => _42.resourceType])==="texture"&&!!t[_chunk2VTISQYPcjs.a]}function Ee(t){return _optionalChain([t, 'optionalAccess', _43 => _43.resourceType])==="texture-storage-view"&&!!t[_chunk2VTISQYPcjs.a]}function Le(t){return _optionalChain([t, 'optionalAccess', _44 => _44.resourceType])==="texture-sampled-view"&&!!t[_chunk2VTISQYPcjs.a]}var _n={mutable:"read_write",readonly:"read",writeonly:"write"},Jt= (_class14 =class{constructor(e,r){;_class14.prototype.__init26.call(this);_class14.prototype.__init27.call(this);_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.props=e;this._branch=r;this[_chunk2VTISQYPcjs.a]={unwrap:()=>{if(this._destroyed)throw new Error("This texture has been destroyed");return this._texture||(this._texture=this._branch.device.createTexture({label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>")),format:this.props.format,size:this.props.size,usage:this._flags,dimension:_nullishCoalesce(this.props.dimension, () => ("2d")),viewFormats:_nullishCoalesce(this.props.viewFormats, () => ([])),mipLevelCount:_nullishCoalesce(this.props.mipLevelCount, () => (1)),sampleCount:_nullishCoalesce(this.props.sampleCount, () => (1))})),this._texture}}}__init26() {this.resourceType="texture"}__init27() {this.usableAsSampled=!1}__init28() {this.usableAsStorage=!1}__init29() {this.usableAsRender=!1}__init30() {this._destroyed=!1}__init31() {this._flags=GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC}__init32() {this._texture=null}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}$usage(...e){let r=e.includes("storage"),n=e.includes("sampled"),a=e.includes("render");return this._flags|=n?GPUTextureUsage.TEXTURE_BINDING:0,this._flags|=r?GPUTextureUsage.STORAGE_BINDING:0,this._flags|=a?GPUTextureUsage.RENDER_ATTACHMENT:0,this.usableAsStorage||=r,this.usableAsSampled||=n,this.usableAsRender||=a,this}createView(e,r){if(e==="sampled")return this._asSampled(r);let n=r;switch(e){case"mutable":return this._asMutable(n);case"readonly":return this._asReadonly(n);case"writeonly":return this._asWriteonly(n)}}_asStorage(e,r){if(!this.usableAsStorage)throw new Error("Unusable as storage");let n=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _45 => _45.format]), () => (this.props.format)),a=_e[n];return _chunk2VTISQYPcjs.k.call(void 0, !!a,`Unsupported storage texture format: ${n}`),new Xt(_nullishCoalesce(e, () => ({})),r,this)}_asReadonly(e){return this._asStorage(e,"readonly")}_asWriteonly(e){return this._asStorage(e,"writeonly")}_asMutable(e){return this._asStorage(e,"mutable")}_asSampled(e){if(!this.usableAsSampled)throw new Error("Unusable as sampled");let r=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _46 => _46.format]), () => (this.props.format));if(!_e[r])throw new Error(`Unsupported storage texture format: ${r}`);return new Zt(e,this)}destroy(){this._destroyed||(this._destroyed=!0,_optionalChain([this, 'access', _47 => _47._texture, 'optionalAccess', _48 => _48.destroy, 'call', _49 => _49()]))}}, _class14),gt={"1d":"1d","2d":"2d","2d-array":"2d_array",cube:"cube","cube-array":"cube_array","3d":"3d"},Xt= (_class15 =class{constructor(e,r,n){;_class15.prototype.__init33.call(this);this.access=r;this._texture=n;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={unwrap:()=>(this._view||(this._view=this._texture[_chunk2VTISQYPcjs.a].unwrap().createView({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - View`,format:this._format,dimension:this.dimension})),this._view)},this[_chunk2VTISQYPcjs.d]=n,this.dimension=_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _50 => _50.dimension]), () => (n.props.dimension)), () => ("2d")),this._format=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _51 => _51.format]), () => (n.props.format)),this.texelDataType=_e[this._format]}__init33() {this.resourceType="texture-storage-view"}$name(e){return this._texture.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),{group:n,binding:a}=e.allocateFixedEntry({storageTexture:this._format,access:this.access,viewDimension:this.dimension},this),o=`texture_storage_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${o}<${this._format}, ${_n[this.access]}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class15),dt= (_class16 =class{constructor(e,r,n,a){;_class16.prototype.__init34.call(this);this._format=e;this.dimension=r;this.access=n;this._membership=a;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={},this.texelDataType=_e[this._format],_chunk2VTISQYPcjs.h.call(void 0, this,a.key)}__init34() {this.resourceType="texture-storage-view"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=`texture_storage_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${_n[this.access]}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class16),Zt= (_class17 =class{constructor(e,r){;_class17.prototype.__init35.call(this);this._props=e;this._texture=r;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={unwrap:()=>(this._view||(this._view=this._texture[_chunk2VTISQYPcjs.a].unwrap().createView({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - View`,...this._props})),this._view)},this[_chunk2VTISQYPcjs.d]=r,this.dimension=_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _52 => _52.dimension]), () => (r.props.dimension)), () => ("2d")),this._format=_nullishCoalesce(_optionalChain([e, 'optionalAccess', _53 => _53.format]), () => (r.props.format)),this.channelDataType=Rn[this._format]}__init35() {this.resourceType="texture-sampled-view"}$name(e){return this._texture.$name(e),this}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=(_nullishCoalesce(this._texture.props.sampleCount, () => (1)))>1,{group:a,binding:o}=e.allocateFixedEntry({texture:Gn[this.channelDataType.type],viewDimension:this.dimension,multisampled:n},this),s=n?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return e.addDeclaration(`@group(${a}) @binding(${o}) var ${r}: ${s}<${e.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class17),ft= (_class18 =class{constructor(e,r,n,a){;_class18.prototype.__init36.call(this);this.dimension=r;this._multisampled=n;this._membership=a;this[_chunk2VTISQYPcjs.b]=this,this[_chunk2VTISQYPcjs.a]={},_chunk2VTISQYPcjs.h.call(void 0, this,a.key),this.channelDataType=Vn[e]}__init36() {this.resourceType="texture-sampled-view"}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this)),n=e.allocateLayoutEntry(this._membership.layout),a=this._multisampled?"texture_multisampled_2d":`texture_${gt[this.dimension]}`;return e.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${e.resolve(this.channelDataType)}>;`),r}toString(){return`${this.resourceType}:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}}, _class18);function er(t){return!!_optionalChain([t, 'optionalAccess', _54 => _54.usableAsSampled])}function $a(t){return!!_optionalChain([t, 'optionalAccess', _55 => _55.usableAsRender])}var ct=class t extends Error{constructor(e){super(`Resource '${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, e), () => ("<unnamed>"))}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`),Object.setPrototypeOf(this,t.prototype)}};function yt(t){return new rr(t)}function Tt(t){return!!t&&t.resourceType==="bind-group-layout"}function nr(t){return!!t&&t.resourceType==="bind-group"}var tr=class t extends Error{constructor(e,r){super(`Bind group '${_nullishCoalesce(e, () => ("<unnamed>"))}' is missing a required binding '${r}'`),Object.setPrototypeOf(this,t.prototype)}},En=["compute"],Se=["compute","vertex","fragment"],rr= (_class19 =class{constructor(e){;_class19.prototype.__init37.call(this);_class19.prototype.__init38.call(this);_class19.prototype.__init39.call(this);_class19.prototype.__init40.call(this);_class19.prototype.__init41.call(this);this.entries=e;let r=0;for(let[n,a]of Object.entries(e)){if(a===null){r++;continue}let o={layout:this,key:n,idx:r};if("uniform"in a&&(this.bound[n]=new Re("uniform",a.uniform,o)),"storage"in a){let s="type"in a.storage?a.storage:a.storage(0);this.bound[n]=new Re(_nullishCoalesce(a.access, () => ("readonly")),s,o)}"texture"in a&&(this.bound[n]=new ft(a.texture,_nullishCoalesce(a.viewDimension, () => ("2d")),_nullishCoalesce(a.multisampled, () => (!1)),o)),"storageTexture"in a&&(this.bound[n]=new dt(a.storageTexture,_nullishCoalesce(a.viewDimension, () => ("2d")),_nullishCoalesce(a.access, () => ("writeonly")),o)),"externalTexture"in a&&(this.bound[n]=new mt(o)),"sampler"in a&&(a.sampler==="comparison"?this.bound[n]=new lt(o):this.bound[n]=new pt(o)),"texture"in a||"storageTexture"in a||"externalTexture"in a||"sampler"in a?this.value[n]=this.bound[n]:Object.defineProperty(this.value,n,{get:()=>this.bound[n].value}),r++}}__init37() {this[_chunk2VTISQYPcjs.a]=!0}__init38() {this.resourceType="bind-group-layout"}__init39() {this.bound={}}__init40() {this.value={}}__init41() {this.$=this.value}[_chunk2VTISQYPcjs.c](){return this.$}toString(){return`bindGroupLayout:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}get index(){return this._index}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}$idx(e){return this._index=e,this}unwrap(e){return e.device.createBindGroupLayout({label:_nullishCoalesce(_chunk2VTISQYPcjs.g.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, () => (Se)),s.buffer={type:"uniform"};else if("storage"in n)o=_nullishCoalesce(o, () => ((n.access==="mutable"?En:Se))),s.buffer={type:n.access==="mutable"?"storage":"read-only-storage"};else if("sampler"in n)o=_nullishCoalesce(o, () => (Se)),s.sampler={type:n.sampler};else if("texture"in n)o=_nullishCoalesce(o, () => (Se)),s.texture={sampleType:n.texture,viewDimension:_nullishCoalesce(n.viewDimension, () => ("2d")),multisampled:_nullishCoalesce(n.multisampled, () => (!1))};else if("storageTexture"in n){let i=_nullishCoalesce(n.access, () => ("writeonly"));o=_nullishCoalesce(o, () => ((i==="readonly"?Se:En))),s.storageTexture={format:n.storageTexture,access:{mutable:"read-write",readonly:"read-only",writeonly:"write-only"}[i],viewDimension:_nullishCoalesce(n.viewDimension, () => ("2d"))}}else"externalTexture"in n&&(o=_nullishCoalesce(o, () => (Se)),s.externalTexture={});return _optionalChain([o, 'optionalAccess', _56 => _56.includes, 'call', _57 => _57("compute")])&&(s.visibility|=GPUShaderStage.COMPUTE),_optionalChain([o, 'optionalAccess', _58 => _58.includes, 'call', _59 => _59("vertex")])&&(s.visibility|=GPUShaderStage.VERTEX),_optionalChain([o, 'optionalAccess', _60 => _60.includes, 'call', _61 => _61("fragment")])&&(s.visibility|=GPUShaderStage.FRAGMENT),s}).filter(n=>n!==null)})}}, _class19),ve= (_class20 =class{constructor(e,r){;_class20.prototype.__init42.call(this);this.layout=e;this.entries=r;for(let n of Object.keys(e.entries))if(e.entries[n]!==null&&!(n in r))throw new tr(_chunk2VTISQYPcjs.g.call(void 0, e),n)}__init42() {this.resourceType="bind-group"}unwrap(e){return e.device.createBindGroup({label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this.layout), () => ("<unnamed>")),layout:e.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(_chunk2VTISQYPcjs.g.call(void 0, this.layout), () => ("<unnamed>"))}'.`);if("uniform"in a){let i;if(ee(s)){if(!it(s))throw new (0, _chunk2VTISQYPcjs.o)(s);i={buffer:e.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("storage"in a){let i;if(ee(s)){if(!le(s))throw new Ae(s);i={buffer:e.unwrap(s)}}else i={buffer:s};return{binding:o,resource:i}}if("texture"in a){let i;if(N(s)){if(!er(s))throw new ct(s);i=e.unwrap(s.createView("sampled"))}else Le(s)?i=e.unwrap(s):i=s;return{binding:o,resource:i}}if("storageTexture"in a){let i;if(N(s)){if(!le(s))throw new Ae(s);a.access==="readonly"?i=e.unwrap(s.createView("readonly")):a.access==="mutable"?i=e.unwrap(s.createView("mutable")):i=e.unwrap(s.createView("writeonly"))}else Ee(s)?i=e.unwrap(s):i=s;return{binding:o,resource:i}}if("sampler"in a)return Ve(s)||$e(s)?{binding:o,resource:e.unwrap(s)}:{binding:o,resource:s};if("externalTexture"in a)return{binding:o,resource:s};throw new Error(`Malformed bind group entry: ${s} (${JSON.stringify(s)})`)}).filter(n=>n!==null)})}}, _class20);var Ln="#CATCHALL#",or= (_class21 =class{constructor() { _class21.prototype.__init43.call(this);_class21.prototype.__init44.call(this); }__init43() {this._stack=[]}__init44() {this._itemDepth=0}get itemDepth(){return this._itemDepth}get topItem(){let e=this._stack[this._stack.length-1];if(!e||e.type!=="item")throw new Error("Internal error, expected item layer to be on top.");return e}get topFunctionReturnType(){let e=this._stack.findLast(r=>r.type==="functionScope");if(!e)throw new Error("Internal error, expected function scope to be present.");return e.returnType}pushItem(){this._itemDepth++,this._stack.push({type:"item",usedSlots:new Set})}popItem(){this.pop("item")}pushSlotBindings(e){this._stack.push({type:"slotBinding",bindingMap:new WeakMap(e)})}popSlotBindings(){this.pop("slotBinding")}pushFunctionScope(e,r,n,a){this._stack.push({type:"functionScope",args:e,argAliases:r,returnType:n,externalMap:a})}popFunctionScope(){this.pop("functionScope")}pushBlockScope(){this._stack.push({type:"blockScope",declarations:new Map})}popBlockScope(){this.pop("blockScope")}pop(e){let r=this._stack[this._stack.length-1];if(!r||e&&r.type!==e)throw new Error(`Internal error, expected a ${e} layer to be on top.`);this._stack.pop(),e==="item"&&this._itemDepth--}readSlot(e){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _62 => _62.type])==="item")n.usedSlots.add(e);else if(_optionalChain([n, 'optionalAccess', _63 => _63.type])==="slotBinding"){let a=n.bindingMap.get(e);if(a!==void 0)return a}else if(!(_optionalChain([n, 'optionalAccess', _64 => _64.type])==="functionScope"||_optionalChain([n, 'optionalAccess', _65 => _65.type])==="blockScope"))throw new Error("Unknown layer type.")}return e.defaultValue}getSnippetById(e){for(let r=this._stack.length-1;r>=0;--r){let n=this._stack[r];if(_optionalChain([n, 'optionalAccess', _66 => _66.type])==="functionScope"){let a=n.args.find(s=>s.value===e);if(a!==void 0)return a;if(n.argAliases[e])return n.argAliases[e];let o=n.externalMap[e];return o!=null?_chunk2VTISQYPcjs.rb.call(void 0, o):void 0}if(_optionalChain([n, 'optionalAccess', _67 => _67.type])==="blockScope"){let a=n.declarations.get(e);if(a!==void 0)return _chunk2VTISQYPcjs.wa.call(void 0, e,a)}}}defineBlockVariable(e,r){if(r.type==="unknown")throw Error(`Tried to define variable '${e}' of unknown type`);for(let n=this._stack.length-1;n>=0;--n){let a=this._stack[n];if(_optionalChain([a, 'optionalAccess', _68 => _68.type])==="blockScope")return a.declarations.set(e,r),_chunk2VTISQYPcjs.wa.call(void 0, e,r)}throw new Error("No block scope found to define a variable in.")}}, _class21),xt=[""," "," "," "," "," "," "," "," "],ar=xt.length-1,sr= (_class22 =class{constructor() { _class22.prototype.__init45.call(this); }__init45() {this.identLevel=0}get pre(){return _nullishCoalesce(xt[this.identLevel], () => (xt[ar].repeat(this.identLevel/ar)+xt[this.identLevel%ar]))}indent(){let e=this.pre;return this.identLevel++,e}dedent(){return this.identLevel--,this.pre}withResetLevel(e){let r=this.identLevel;this.identLevel=0;try{return e()}finally{this.identLevel=r}}}, _class22),Oe= (_class23 =class{__init46() {this._memoizedResolves=new WeakMap}__init47() {this._memoizedDerived=new WeakMap}__init48() {this._indentController=new sr}__init49() {this._itemStateStack=new or}#e=[];__init50() {this._declarations=[]}get varyingLocations(){return this._varyingLocations}__init51() {this[_chunk2VTISQYPcjs.a]={itemStateStack:this._itemStateStack}}__init52() {this.bindGroupLayoutsToPlaceholderMap=new Map}__init53() {this._nextFreeLayoutPlaceholderIdx=0}__init54() {this.fixedBindings=[]}constructor(e){;_class23.prototype.__init46.call(this);_class23.prototype.__init47.call(this);_class23.prototype.__init48.call(this);_class23.prototype.__init49.call(this);_class23.prototype.__init50.call(this);_class23.prototype.__init51.call(this);_class23.prototype.__init52.call(this);_class23.prototype.__init53.call(this);_class23.prototype.__init54.call(this);this.names=e.names}get pre(){return this._indentController.pre}get topFunctionReturnType(){return this._itemStateStack.topFunctionReturnType}indent(){return this._indentController.indent()}dedent(){return this._indentController.dedent()}withResetIndentLevel(e){return this._indentController.withResetLevel(e)}getById(e){let r=this._itemStateStack.getSnippetById(e);return r===void 0?null:r}defineVariable(e,r){return this._itemStateStack.defineBlockVariable(e,r)}pushBlockScope(){this._itemStateStack.pushBlockScope()}popBlockScope(){this._itemStateStack.popBlockScope()}fnToWgsl(e){this._itemStateStack.pushFunctionScope(e.args,e.argAliases,e.returnType,e.externalMap);try{return{head:_a(this,e.args,e.returnType),body:_chunkCYZBRBPDcjs.o.call(void 0, this,e.body)}}finally{this._itemStateStack.popFunctionScope()}}addDeclaration(e){this._declarations.push(e)}allocateLayoutEntry(e){let r=this.bindGroupLayoutsToPlaceholderMap,n=r.get(e);return n||(n=`#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`,r.set(e,n)),n}allocateFixedEntry(e,r){let n=this.fixedBindings.length;return this.fixedBindings.push({layoutEntry:e,resource:r}),{group:Ln,binding:n}}readSlot(e){let r=this._itemStateStack.readSlot(e);if(r===void 0)throw new (0, _chunk2VTISQYPcjs.n)(e);return r}withSlots(e,r){this._itemStateStack.pushSlotBindings(e);try{return r()}finally{this._itemStateStack.popSlotBindings()}}withVaryingLocations(e,r){this._varyingLocations=e;try{return r()}finally{this._varyingLocations=void 0}}unwrap(e){if(_chunk2VTISQYPcjs.x.call(void 0, e))return this.withSlots(e[_chunk2VTISQYPcjs.e].pairs,()=>this.unwrap(e[_chunk2VTISQYPcjs.e].inner));let r=e;for(;;)if(_chunk2VTISQYPcjs.v.call(void 0, r))r=this.readSlot(r);else if(_chunk2VTISQYPcjs.w.call(void 0, r))r=this._getOrCompute(r);else break;return r}_getOrCompute(e){let r=_nullishCoalesce(this._memoizedDerived.get(e), () => ([]));this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([i,p])=>i.areEqual(this._itemStateStack.readSlot(i),p)))return o.result;this.pushMode(new _chunk2VTISQYPcjs.U);let n;try{n=e["~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._memoizedDerived.set(e,r),n}catch(n){throw n instanceof _chunk2VTISQYPcjs.l?n.appendToTrace(e):new (0, _chunk2VTISQYPcjs.l)(n,[e])}finally{this._itemStateStack.popItem()}}_getOrInstantiate(e){let r=_nullishCoalesce(this._memoizedResolves.get(e), () => ([]));this._itemStateStack.pushItem();try{for(let o of r)if([...o.slotToValueMap.entries()].every(([i,p])=>i.areEqual(this._itemStateStack.readSlot(i),p)))return o.result;let n;if(_chunk2VTISQYPcjs.qa.call(void 0, e))n=qt(this,e);else if(_chunk2VTISQYPcjs.w.call(void 0, e)||_chunk2VTISQYPcjs.v.call(void 0, e))n=this.resolve(this.unwrap(e));else if(_chunk2VTISQYPcjs.X.call(void 0, e))n=e["~resolve"](this);else throw new TypeError(`Unresolvable internal value: ${e} (as json: ${JSON.stringify(e)})`);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._memoizedResolves.set(e,r),n}catch(n){throw n instanceof _chunk2VTISQYPcjs.l?n.appendToTrace(e):new (0, _chunk2VTISQYPcjs.l)(n,[e])}finally{this._itemStateStack.popItem()}}resolve(e,r){if(_chunk2VTISQYPcjs.x.call(void 0, e))return this.withSlots(e[_chunk2VTISQYPcjs.e].pairs,()=>this.resolve(e[_chunk2VTISQYPcjs.e].inner,r));if(_chunk2VTISQYPcjs.$.call(void 0, e)){if(this._itemStateStack.itemDepth===0)try{this.pushMode(new _chunk2VTISQYPcjs.V);let n=_chunk2VTISQYPcjs.ca.call(void 0, this,()=>this._getOrInstantiate(e));return`${[...this._declarations].join(`
18
18
 
19
- `)}${r}`}finally{this.popMode("codegen")}return this._getOrInstantiate(e)}return String(e)}resolveValue(e,r){if(_chunkBF35NEOXcjs.ba.call(void 0, e))return this.resolve(e);if(r&&_chunkBF35NEOXcjs.O.call(void 0, r))return`array(${e.map(n=>this.resolveValue(n,r.elementType))})`;if(Array.isArray(e))return`array(${e.map(n=>this.resolveValue(n))})`;if(r&&_chunkBF35NEOXcjs.P.call(void 0, r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolveValue(e[n],a))})`;throw new Error(`Value ${e} (as json: ${JSON.stringify(e)}) of schema ${r} is not resolvable to WGSL`)}pushMode(e){this.#e.push(e)}popMode(e){let r=this.#e.pop();e!==void 0&&_chunkBF35NEOXcjs.n.call(void 0, _optionalChain([r, 'optionalAccess', _69 => _69.type])===e,"Unexpected mode")}get mode(){return _nullishCoalesce(this.#e[this.#e.length-1], () => (_chunkBF35NEOXcjs.ja))}}, _class22);function te(t,e,r){let n=new Oe(e),a=r?n.withSlots(r(new be([])).bindings,()=>n.resolve(t)):n.resolve(t),o=n.bindGroupLayoutsToPlaceholderMap,s=[],i=new Set([...o.keys()].map(c=>c.index).filter(c=>c!==void 0)),u=hn(i),l=n.fixedBindings.map((c,y)=>[String(y),c.layoutEntry]),f=()=>{let c=u.next().value,y=yt(Object.fromEntries(l));return s[c]=y,a=a.replaceAll(On,String(c)),[c,new ve(y,Object.fromEntries(n.fixedBindings.map((x,I)=>[String(I),x.resource])))]},g=l.length>0?f():void 0;for(let[c,y]of o.entries()){let x=_nullishCoalesce(c.index, () => (u.next().value));s[x]=c,a=a.replaceAll(y,String(x))}return{code:a,usedBindGroupLayouts:s,catchall:g}}function Ea(t,e,r){let n=e.map(a=>`${a.value}: ${t.resolve(a.dataType)}`).join(", ");return r.type!=="void"?`(${n}) -> ${_chunk3K53YJSUcjs.ra.call(void 0, r)}${t.resolve(r)} `:`(${n}) `}function lr(t){let{externals:e,template:r,names:n,config:a}=t,o={};return Y(o,_nullishCoalesce(e, () => ({}))),te({"~resolve"(i){return ie(i,o,_nullishCoalesce(r, () => ("")))},toString:()=>"<root>"},{names:n==="strict"?new W:new ue},a)}function kn(t){return lr(t).code}function Mn(t){let e=_nullishCoalesce(_chunkBF35NEOXcjs.ia.call(void 0, ), () => (new Oe({names:new W}))),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,f)=>Array.from({length:a[1]},(g,c)=>Array.from({length:a[2]},(y,x)=>{let I=Math.floor(f/n[0]),w=Math.floor(c/n[1]),S=Math.floor(x/n[2]);return new (0, _chunkBF35NEOXcjs.$)(o,{private:i[f][c][x],workgroup:s[I][w][S]})})));e.pushMode(u[0][0][0]);try{return{value:_chunkBF35NEOXcjs.ha.call(void 0, e,t),buffers:o,privateVars:i,workgroupVars:s}}finally{e.popMode("simulate")}}function Wn(t,e,r,n){return new mr(t,e,r,n)}function ke(t){let e=t;return _optionalChain([e, 'optionalAccess', _70 => _70.resourceType])==="query-set"&&!!e[_chunkBF35NEOXcjs.a]}var mr= (_class23 =class{constructor(e,r,n,a){;_class23.prototype.__init52.call(this);_class23.prototype.__init53.call(this);_class23.prototype.__init54.call(this);_class23.prototype.__init55.call(this);_class23.prototype.__init56.call(this);_class23.prototype.__init57.call(this);this._group=e;this.type=r;this.count=n;this.rawQuerySet=a;this._ownQuerySet=!a,this._querySet=a||null}__init52() {this.resourceType="query-set"}__init53() {this._querySet=null}__init54() {this._destroyed=!1}__init55() {this._available=!0}__init56() {this._readBuffer=null}__init57() {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._group.device.createQuerySet({type:this.type,count:this.count}),this._querySet)}get destroyed(){return this._destroyed}get available(){return this._available}get[_chunkBF35NEOXcjs.a](){let e=this;return{get readBuffer(){return e._readBuffer||(e._readBuffer=e._group.device.createBuffer({size:e.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})),e._readBuffer},get resolveBuffer(){return e._resolveBuffer||(e._resolveBuffer=e._group.device.createBuffer({size:e.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),e._resolveBuffer}}}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this._querySet&&(this._querySet.label=e),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 e=this._group.device.createCommandEncoder();e.resolveQuerySet(this.querySet,0,this.count,this[_chunkBF35NEOXcjs.a].resolveBuffer,0),this._group.device.queue.submit([e.finish()])}async read(){if(this._group.flush(),!this._resolveBuffer)throw new Error("QuerySet must be resolved before reading.");this._available=!1;try{let e=this._group.device.createCommandEncoder();e.copyBufferToBuffer(this[_chunkBF35NEOXcjs.a].resolveBuffer,0,this[_chunkBF35NEOXcjs.a].readBuffer,0,this.count*BigUint64Array.BYTES_PER_ELEMENT),this._group.device.queue.submit([e.finish()]),await this._group.device.queue.onSubmittedWorkDone();let r=this[_chunkBF35NEOXcjs.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', _71 => _71._readBuffer, 'optionalAccess', _72 => _72.destroy, 'call', _73 => _73()]),_optionalChain([this, 'access', _74 => _74._resolveBuffer, 'optionalAccess', _75 => _75.destroy, 'call', _76 => _76()]),this._readBuffer=this._resolveBuffer=null)}}, _class23);var Me= (_class24 =class{constructor(e){;_class24.prototype.__init58.call(this);this._make=e}__init58() {this._map=new WeakMap}getOrMake(e,...r){if(this._map.has(e))return this._map.get(e);let n=this._make(e,...r);return this._map.set(e,n),n}}, _class24);function ht(t,e,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Performance callback requires the "timestamp-query" feature to be enabled on GPU device.');return t.timestampWrites?{...t,performanceCallback:e}:{...t,performanceCallback:e,hasAutoQuerySet:!0,timestampWrites:{querySet:r.createQuerySet("timestamp",2),beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}}function bt(t,e,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Timestamp writes require the "timestamp-query" feature to be enabled on GPU device.');t.hasAutoQuerySet&&t.timestampWrites&&t.timestampWrites.querySet.destroy();let n={querySet:e.querySet};return e.beginningOfPassWriteIndex!==void 0&&(n.beginningOfPassWriteIndex=e.beginningOfPassWriteIndex),e.endOfPassWriteIndex!==void 0&&(n.endOfPassWriteIndex=e.endOfPassWriteIndex),{...t,hasAutoQuerySet:!1,timestampWrites:n}}function wt(t,e){if(!t.timestampWrites)return{};let{querySet:r,beginningOfPassWriteIndex:n,endOfPassWriteIndex:a}=t.timestampWrites,o={querySet:ke(r)?e.unwrap(r):r};return n!==void 0&&(o.beginningOfPassWriteIndex=n),a!==void 0&&(o.endOfPassWriteIndex=a),{timestampWrites:o}}function We({root:t,priors:e}){let r=_optionalChain([e, 'access', _77 => _77.timestampWrites, 'optionalAccess', _78 => _78.querySet]),n=e.performanceCallback;if(!r)throw new Error("Cannot dispatch workgroups with performance callback without a query set.");if(!ke(r))throw new Error("Performance callback with raw GPUQuerySet is not supported. Use TgpuQuerySet instead.");t.commandEncoder.resolveQuerySet(t.unwrap(r),0,r.count,r[_chunkBF35NEOXcjs.a].resolveBuffer,0),t.flush(),t.device.queue.onSubmittedWorkDone().then(async()=>{if(!r.available)return;let a=await r.read(),o=a[_nullishCoalesce(_optionalChain([e, 'access', _79 => _79.timestampWrites, 'optionalAccess', _80 => _80.beginningOfPassWriteIndex]), () => (0))],s=a[_nullishCoalesce(_optionalChain([e, 'access', _81 => _81.timestampWrites, 'optionalAccess', _82 => _82.endOfPassWriteIndex]), () => (1))];if(o===void 0||s===void 0)throw new Error("QuerySet did not return valid timestamps.");await n(o,s)})}function Nn(t,e,r){return new dr(new fr(t,e,r),{})}function zn(t){let e=t;return _optionalChain([e, 'optionalAccess', _83 => _83.resourceType])==="compute-pipeline"&&!!e[_chunkBF35NEOXcjs.a]}var dr= (_class25 =class t{constructor(e,r){;_class25.prototype.__init59.call(this);this._core=e;this._priors=r;this[_chunkBF35NEOXcjs.a]={get rawPipeline(){return e.unwrap().pipeline},get priors(){return r}},this[_chunkBF35NEOXcjs.d]=e}__init59() {this.resourceType="compute-pipeline"}"~resolve"(e){return e.resolve(this._core)}toString(){return`computePipeline:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}get rawPipeline(){return this._core.unwrap().pipeline}with(e,r){return new t(this._core,{...this._priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(this._priors.bindGroupLayoutMap, () => ([])),[e,r]])})}withPerformanceCallback(e){let r=ht(this._priors,e,this._core.branch);return new t(this._core,r)}withTimestampWrites(e){let r=bt(this._priors,e,this._core.branch);return new t(this._core,r)}dispatchWorkgroups(e,r,n){let a=this._core.unwrap(),{branch:o}=this._core,s={label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this._core), () => ("<unnamed>")),...wt(this._priors,o)},i=o.commandEncoder.beginComputePass(s);i.setPipeline(a.pipeline);let u=new Set(a.usedBindGroupLayouts);if(a.usedBindGroupLayouts.forEach((l,f)=>{if(a.catchall&&f===a.catchall[0])i.setBindGroup(f,o.unwrap(a.catchall[1])),u.delete(l);else{let g=_optionalChain([this, 'access', _84 => _84._priors, 'access', _85 => _85.bindGroupLayoutMap, 'optionalAccess', _86 => _86.get, 'call', _87 => _87(l)]);g!==void 0&&(u.delete(l),i.setBindGroup(f,o.unwrap(g)))}}),u.size>0)throw new (0, _chunkBF35NEOXcjs.t)(u);i.dispatchWorkgroups(e,r,n),i.end(),this._priors.performanceCallback&&We({root:o,priors:this._priors})}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this._core,e),this}}, _class25),fr=class{constructor(e,r,n){this.branch=e;this._slotBindings=r;this._entryFn=n}"~resolve"(e){return e.withSlots(this._slotBindings,()=>(e.resolve(this._entryFn),""))}toString(){return"computePipelineCore"}unwrap(){if(this._memo===void 0){let e=this.branch.device,r,n;if(_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _88 => _88.enabled])){let u=performance.mark("typegpu:resolution:start");r=te(this,{names:this.branch.nameRegistry}),n=performance.measure("typegpu:resolution",{start:u.name})}else r=te(this,{names:this.branch.nameRegistry});let{code:a,usedBindGroupLayouts:o,catchall:s}=r;s!==void 0&&_optionalChain([o, 'access', _89 => _89[s[0]], 'optionalAccess', _90 => _90.$name, 'call', _91 => _91(`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let i=e.createShaderModule({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:a});this._memo={pipeline:e.createComputePipeline({label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>")),layout:e.createPipelineLayout({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:o.map(u=>this.branch.unwrap(u))}),compute:{module:i}}),usedBindGroupLayouts:o,catchall:s},_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _92 => _92.enabled])&&(async()=>{let u=performance.mark("typegpu:compile-start");await e.queue.onSubmittedWorkDone();let l=performance.measure("typegpu:compiled",{start:u.name});_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _93 => _93.record, 'call', _94 => _94("resolution",{resolveDuration:_optionalChain([n, 'optionalAccess', _95 => _95.duration]),compileDuration:l.duration,wgslSize:a.length})])})()}return this._memo}};function yr(t,e="vertex"){return new cr(t,e)}function vt(t){return _optionalChain([t, 'optionalAccess', _96 => _96.resourceType])==="vertex-layout"}var gr=Symbol("defaultAttribEntry");function St(t,e,r,n,a){if(_chunkBF35NEOXcjs.X.call(void 0, e)||_chunk3K53YJSUcjs.g.call(void 0, e)){let o=_chunk3K53YJSUcjs.h.call(void 0, e);return o!==void 0&&(n[_nullishCoalesce(a, () => (gr))]=o),St(t,e.inner,_chunk3K53YJSUcjs.a.call(void 0, r,_chunk3K53YJSUcjs.ba.call(void 0, e)),n)}if(_chunkBF35NEOXcjs.P.call(void 0, e)){let o=r,s=e.propTypes;return Object.fromEntries(Object.entries(s).map(([i,u])=>{o=_chunk3K53YJSUcjs.a.call(void 0, o,_chunk3K53YJSUcjs.aa.call(void 0, u));let l=[i,St(t,u,o,n,i)];return o+=_chunk3K53YJSUcjs.da.call(void 0, u),l}))}if(_chunk3K53YJSUcjs.f.call(void 0, e)){let o=r,s=e.propTypes;return Object.fromEntries(Object.entries(s).map(([i,u])=>{o=_chunk3K53YJSUcjs.a.call(void 0, o,_chunk3K53YJSUcjs.ba.call(void 0, u));let l=[i,St(t,u,o,n,i)];return o+=_chunk3K53YJSUcjs.da.call(void 0, u),l}))}if("type"in e&&typeof e.type=="string"){if(_chunk3K53YJSUcjs.b.includes(e.type))return{_layout:t,format:e.type,offset:r};let o=_chunk3K53YJSUcjs.c[e.type];if(o)return{_layout:t,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(e)}`)}var cr= (_class26 =class{constructor(e,r){;_class26.prototype.__init60.call(this);_class26.prototype.__init61.call(this);_class26.prototype.__init62.call(this);this.schemaForCount=e;this.stepMode=r;let n=e(0);this.stride=_chunk3K53YJSUcjs.a.call(void 0, _chunk3K53YJSUcjs.da.call(void 0, n.elementType),_chunk3K53YJSUcjs.aa.call(void 0, n)),this.attrib=St(this,n.elementType,0,this._customLocationMap)}__init60() {this[_chunkBF35NEOXcjs.a]=!0}__init61() {this.resourceType="vertex-layout"}__init62() {this._customLocationMap={}}get vertexLayout(){if(this._customLocationMap[gr]!==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[gr]}]}}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(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}}, _class26);function La(t){return typeof _optionalChain([t, 'optionalAccess', _97 => _97.loadOp])=="string"}function qn(t,e){if(_chunk3K53YJSUcjs.i.call(void 0, t)){if(!La(e))throw new Error("Expected a single color attachment, not a record.");return[e]}let r=[];for(let n of Object.keys(t)){let a=e[n];if(!a)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function Oa(t){return typeof _optionalChain([t, 'optionalAccess', _98 => _98.format])=="string"}function jn(t,e){if(_chunk3K53YJSUcjs.i.call(void 0, t)){if(_chunkBF35NEOXcjs.Y.call(void 0, t))return[];if(!Oa(e))throw new Error("Expected a single color target configuration, not a record.");return[e]}let r=[];for(let n of Object.keys(t)){let a=e[n];if(!a)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function Qn(t){return new Tr(new xr(t),{})}function Hn(t){let e=t;return _optionalChain([e, 'optionalAccess', _99 => _99.resourceType])==="render-pipeline"&&!!e[_chunkBF35NEOXcjs.a]}var Tr= (_class27 =class t{__init63() {this.resourceType="render-pipeline"}__init64() {this.hasIndexBuffer=!1}constructor(e,r){;_class27.prototype.__init63.call(this);_class27.prototype.__init64.call(this);this[_chunkBF35NEOXcjs.a]={core:e,priors:r},this[_chunkBF35NEOXcjs.d]=e}"~resolve"(e){return e.resolve(this[_chunkBF35NEOXcjs.a].core)}toString(){return`renderPipeline:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this[_chunkBF35NEOXcjs.a].core,e),this}with(e,r){let n=this[_chunkBF35NEOXcjs.a];if(Tt(e))return new t(n.core,{...n.priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(n.priors.bindGroupLayoutMap, () => ([])),[e,r]])});if(vt(e))return new t(n.core,{...n.priors,vertexLayoutMap:new Map([..._nullishCoalesce(n.priors.vertexLayoutMap, () => ([])),[e,r]])});throw new Error("Unsupported value passed into .with()")}withPerformanceCallback(e){let r=this[_chunkBF35NEOXcjs.a],n=ht(r.priors,e,r.core.options.branch);return new t(r.core,n)}withTimestampWrites(e){let r=this[_chunkBF35NEOXcjs.a],n=bt(r.priors,e,r.core.options.branch);return new t(r.core,n)}withColorAttachment(e){let r=this[_chunkBF35NEOXcjs.a];return new t(r.core,{...r.priors,colorAttachment:e})}withDepthStencilAttachment(e){let r=this[_chunkBF35NEOXcjs.a];return new t(r.core,{...r.priors,depthStencilAttachment:e})}withIndexBuffer(e,r,n,a){let o=this[_chunkBF35NEOXcjs.a];if(_chunkBF35NEOXcjs.ca.call(void 0, e)){if(typeof r!="string")throw new Error("If a GPUBuffer is passed, indexFormat must be provided.");return new t(o.core,{...o.priors,indexBuffer:{buffer:e,indexFormat:r,offsetBytes:n,sizeBytes:a}})}let s={u32:"uint32",u16:"uint16"},i=e.dataType.elementType;return new t(o.core,{...o.priors,indexBuffer:{buffer:e,indexFormat:s[i.type],offsetBytes:r!==void 0?r*_chunk3K53YJSUcjs.ea.call(void 0, i):void 0,sizeBytes:a!==void 0?a*_chunk3K53YJSUcjs.ea.call(void 0, i):void 0}})}setupRenderPass(){let e=this[_chunkBF35NEOXcjs.a],r=e.core.unwrap(),{branch:n,fragmentFn:a}=e.core.options,o=qn(a.shell.out,_nullishCoalesce(e.priors.colorAttachment, () => ({}))).map(g=>N(g.view)?{...g,view:n.unwrap(g.view).createView()}:g),s={label:_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, e.core), () => ("<unnamed>")),colorAttachments:o,...wt(e.priors,n)};if(e.priors.depthStencilAttachment!==void 0){let g=e.priors.depthStencilAttachment;N(g.view)?s.depthStencilAttachment={...g,view:n.unwrap(g.view).createView()}:s.depthStencilAttachment=g}let i=n.commandEncoder.beginRenderPass(s);i.setPipeline(r.pipeline);let u=new Set(r.usedBindGroupLayouts);r.usedBindGroupLayouts.forEach((g,c)=>{if(r.catchall&&c===r.catchall[0])i.setBindGroup(c,n.unwrap(r.catchall[1])),u.delete(g);else{let y=_optionalChain([e, 'access', _100 => _100.priors, 'access', _101 => _101.bindGroupLayoutMap, 'optionalAccess', _102 => _102.get, 'call', _103 => _103(g)]);y!==void 0&&(u.delete(g),i.setBindGroup(c,n.unwrap(y)))}});let l=new Set(e.core.usedVertexLayouts);if(e.core.usedVertexLayouts.forEach((g,c)=>{let y=_optionalChain([e, 'access', _104 => _104.priors, 'access', _105 => _105.vertexLayoutMap, 'optionalAccess', _106 => _106.get, 'call', _107 => _107(g)]);y&&(l.delete(g),i.setVertexBuffer(c,n.unwrap(y)))}),u.size>0)throw new (0, _chunkBF35NEOXcjs.t)(u);if(l.size>0)throw new (0, _chunkBF35NEOXcjs.u)(l);return i}draw(e,r,n,a){let o=this[_chunkBF35NEOXcjs.a],s=this.setupRenderPass(),{branch:i}=o.core.options;s.draw(e,r,n,a),s.end(),o.priors.performanceCallback?We({root:i,priors:o.priors}):i.flush()}drawIndexed(e,r,n,a,o){let s=this[_chunkBF35NEOXcjs.a];if(!s.priors.indexBuffer)throw new Error("No index buffer set for this render pipeline.");let{buffer:i,indexFormat:u,offsetBytes:l,sizeBytes:f}=s.priors.indexBuffer,g=this.setupRenderPass(),{branch:c}=s.core.options;_chunkBF35NEOXcjs.ca.call(void 0, i)?g.setIndexBuffer(i,u,l,f):g.setIndexBuffer(c.unwrap(i),u,l,f),g.drawIndexed(e,r,n,a,o),g.end(),s.priors.performanceCallback?We({root:c,priors:s.priors}):c.flush()}}, _class27),xr=class{constructor(e){this.options=e;let r=xn(_nullishCoalesce(e.vertexFn.shell.in, () => ({})),e.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=jn(e.fragmentFn.shell.out,e.targets)}"~resolve"(e){let{vertexFn:r,fragmentFn:n,slotBindings:a}=this.options,o=ka(r.shell.out,n.shell.in,_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, r), () => ("<unnamed>")),_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, n), () => ("<unnamed>")));return e.withVaryingLocations(o,()=>e.withSlots(a,()=>(e.resolve(r),e.resolve(n),"")))}toString(){return"renderPipelineCore"}unwrap(){if(this._memo===void 0){let{branch:e,primitiveState:r,depthStencilState:n,multisampleState:a}=this.options,o=e.device,s,i;if(_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _108 => _108.enabled])){let x=performance.mark("typegpu:resolution:start");s=te(this,{names:e.nameRegistry}),i=performance.measure("typegpu:resolution",{start:x.name})}else s=te(this,{names:e.nameRegistry});let{code:u,usedBindGroupLayouts:l,catchall:f}=s;f!==void 0&&_optionalChain([l, 'access', _109 => _109[f[0]], 'optionalAccess', _110 => _110.$name, 'call', _111 => _111(`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let g=o.createShaderModule({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:u}),c={layout:o.createPipelineLayout({label:`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:l.map(x=>e.unwrap(x))}),vertex:{module:g,buffers:this._vertexBufferLayouts},fragment:{module:g,targets:this._targets}},y=_chunkBF35NEOXcjs.j.call(void 0, this);y!==void 0&&(c.label=y),r&&(_chunkBF35NEOXcjs.N.call(void 0, r.stripIndexFormat)?c.primitive={...r,stripIndexFormat:{u32:"uint32",u16:"uint16"}[r.stripIndexFormat.type]}:c.primitive=r),n&&(c.depthStencil=n),a&&(c.multisample=a),this._memo={pipeline:o.createRenderPipeline(c),usedBindGroupLayouts:l,catchall:f},_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _112 => _112.enabled])&&(async()=>{let x=performance.mark("typegpu:compile-start");await o.queue.onSubmittedWorkDone();let I=performance.measure("typegpu:compiled",{start:x.name});_optionalChain([_chunkBF35NEOXcjs.i, 'optionalAccess', _113 => _113.record, 'call', _114 => _114("resolution",{resolveDuration:_optionalChain([i, 'optionalAccess', _115 => _115.duration]),compileDuration:I.duration,wgslSize:u.length})])})()}return this._memo}};function ka(t,e,r,n){let a={},o=new Set;function s(u,l){a[u]=l,o.add(l)}for(let[u,l]of Object.entries(t)){let f=_chunk3K53YJSUcjs.h.call(void 0, l);f!==void 0&&s(u,f)}for(let[u,l]of Object.entries(_nullishCoalesce(e, () => ({})))){let f=_chunk3K53YJSUcjs.h.call(void 0, l);f!==void 0&&(a[u]===void 0?s(u,f):a[u]!==f&&console.warn(`Mismatched location between vertexFn (${r}) output (${a[u]}) and fragmentFn (${n}) input (${f}) for the key "${u}", using the location set on vertex output.`))}let i=0;for(let u of Object.keys(_nullishCoalesce(t, () => ({}))))if(!(_chunk3K53YJSUcjs.qa.call(void 0, t[u])||a[u]!==void 0)){for(;o.has(i);)i++;s(u,i)}return a}function hr(t){return t instanceof me}var me= (_class28 =class{constructor(e,r){;_class28.prototype.__init65.call(this);this.resourceType=e;this.buffer=r;this[_chunkBF35NEOXcjs.d]=r,this.#e=this.buffer.as(this.resourceType)}__init65() {this[_chunkBF35NEOXcjs.a]=!0}#e;$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this[_chunkBF35NEOXcjs.d],e),this}write(e){this.buffer.write(e)}writePartial(e){this.buffer.writePartial(e)}read(){return this.buffer.read()}get $(){return this.#e.$}get value(){return this.$}"~resolve"(e){return e.resolve(this.#e)}}, _class28);var br=class t{constructor(e,r){this._getRoot=e;this._slotBindings=r}with(e,r){return new t(this._getRoot,[...this._slotBindings,[_chunkBF35NEOXcjs.B.call(void 0, e)?e.slot:e,r]])}withCompute(e){return new wr(this._getRoot(),this._slotBindings,e)}withVertex(e,r){return new Sr({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:e,vertexAttribs:r,multisampleState:void 0})}pipe(e){let r=e(new be([]));return new t(this._getRoot,[...this._slotBindings,...r.bindings])}},wr=class{constructor(e,r,n){this._root=e;this._slotBindings=r;this._entryFn=n}createPipeline(){return Nn(this._root,this._slotBindings,this._entryFn)}},Sr=class{constructor(e){this._options=e}withFragment(e,r,n){return _chunkBF35NEOXcjs.n.call(void 0, typeof e!="string","Just type mismatch validation"),_chunkBF35NEOXcjs.n.call(void 0, typeof r!="string","Just type mismatch validation"),new vr({...this._options,fragmentFn:e,targets:r})}},vr=class t{constructor(e){this._options=e}withPrimitive(e){return new t({...this._options,primitiveState:e})}withDepthStencil(e){return new t({...this._options,depthStencilState:e})}withMultisample(e){return new t({...this._options,multisampleState:e})}createPipeline(){return Qn(this._options)}},It= (_class29 =class extends br{constructor(r,n,a){super(()=>this,[]);_class29.prototype.__init66.call(this);_class29.prototype.__init67.call(this);_class29.prototype.__init68.call(this);_class29.prototype.__init69.call(this);;this.device=r;this.nameRegistry=n;this._ownDevice=a;this["~unstable"]=this}__init66() {this._disposables=[]}__init67() {this._unwrappedBindGroupLayouts=new Me(r=>r.unwrap(this))}__init68() {this._unwrappedBindGroups=new Me(r=>r.unwrap(this))}__init69() {this._commandEncoder=null}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}get enabledFeatures(){return new Set(this.device.features)}createBuffer(r,n){let a=Ge(this,r,n);return this._disposables.push(a),a}createUniform(r,n){let a=Ge(this,r,n).$usage("uniform");return this._disposables.push(a),new me("uniform",a)}createMutable(r,n){let a=Ge(this,r,n).$usage("storage");return this._disposables.push(a),new me("mutable",a)}createReadonly(r,n){let a=Ge(this,r,n).$usage("storage");return this._disposables.push(a),new me("readonly",a)}createQuerySet(r,n,a){return Wn(this,r,n,a)}createBindGroup(r,n){return new ve(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=_n(r,this);return this._disposables.push(n),n}unwrap(r){if(zn(r))return r[_chunkBF35NEOXcjs.a].rawPipeline;if(Hn(r))return r[_chunkBF35NEOXcjs.a].core.unwrap().pipeline;if(Tt(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(sr(r))return this._unwrappedBindGroups.getOrMake(r);if(ee(r))return r.buffer;if(N(r))return r[_chunkBF35NEOXcjs.a].unwrap();if(Ee(r)){if(r[_chunkBF35NEOXcjs.a].unwrap)return r[_chunkBF35NEOXcjs.a].unwrap();throw new Error("Cannot unwrap laid-out texture view.")}if(Le(r)){if(r[_chunkBF35NEOXcjs.a].unwrap)return r[_chunkBF35NEOXcjs.a].unwrap();throw new Error("Cannot unwrap laid-out texture view.")}if(vt(r))return r.vertexLayout;if(Ve(r)){if(r[_chunkBF35NEOXcjs.a].unwrap)return r[_chunkBF35NEOXcjs.a].unwrap(this);throw new Error("Cannot unwrap laid-out sampler.")}if($e(r)){if(r[_chunkBF35NEOXcjs.a].unwrap)return r[_chunkBF35NEOXcjs.a].unwrap(this);throw new Error("Cannot unwrap laid-out comparison sampler.")}if(ke(r))return r.querySet;throw new Error(`Unknown resource type: ${r}`)}beginRenderPass(r,n){let a=this.commandEncoder.beginRenderPass(r),o=new Map,s=new Map,i,u=()=>{if(!i)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:l,priors:f}=i[_chunkBF35NEOXcjs.a],g=l.unwrap();a.setPipeline(g.pipeline);let c=new Set(g.usedBindGroupLayouts);g.usedBindGroupLayouts.forEach((x,I)=>{if(g.catchall&&I===g.catchall[0])a.setBindGroup(I,this.unwrap(g.catchall[1])),c.delete(x);else{let w=_nullishCoalesce(_optionalChain([f, 'access', _116 => _116.bindGroupLayoutMap, 'optionalAccess', _117 => _117.get, 'call', _118 => _118(x)]), () => (o.get(x)));w!==void 0&&(c.delete(x),sr(w)?a.setBindGroup(I,this.unwrap(w)):a.setBindGroup(I,w))}});let y=new Set;if(l.usedVertexLayouts.forEach((x,I)=>{let w=_optionalChain([f, 'access', _119 => _119.vertexLayoutMap, 'optionalAccess', _120 => _120.get, 'call', _121 => _121(x)]),S=w?{buffer:w,offset:void 0,size:void 0}:s.get(x);!S||!S.buffer?y.add(x):ee(S.buffer)?a.setVertexBuffer(I,this.unwrap(S.buffer),S.offset,S.size):a.setVertexBuffer(I,S.buffer,S.offset,S.size)}),c.size>0)throw new (0, _chunkBF35NEOXcjs.t)(c);if(y.size>0)throw new (0, _chunkBF35NEOXcjs.u)(y)};n({setViewport(...l){a.setViewport(...l)},setScissorRect(...l){a.setScissorRect(...l)},setBlendConstant(...l){a.setBlendConstant(...l)},setStencilReference(...l){a.setStencilReference(...l)},beginOcclusionQuery(...l){a.beginOcclusionQuery(...l)},endOcclusionQuery(...l){a.endOcclusionQuery(...l)},executeBundles(...l){a.executeBundles(...l)},setPipeline(l){i=l},setIndexBuffer:(l,f,g,c)=>{ee(l)?a.setIndexBuffer(this.unwrap(l),f,g,c):a.setIndexBuffer(l,f,g,c)},setVertexBuffer(l,f,g,c){s.set(l,{buffer:f,offset:g,size:c})},setBindGroup(l,f){o.set(l,f)},draw(l,f,g,c){u(),a.draw(l,f,g,c)},drawIndexed(...l){u(),a.drawIndexed(...l)},drawIndirect(...l){u(),a.drawIndirect(...l)},drawIndexedIndirect(...l){u(),a.drawIndexedIndirect(...l)}}),a.end()}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}}, _class29);async function Kn(t){let{adapter:e,device:r,unstable_names:n="random"}=_nullishCoalesce(t, () => ({}));if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let a=await navigator.gpu.requestAdapter(e);if(!a)throw new Error("Could not find a compatible GPU");let o=[];for(let s of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _122 => _122.requiredFeatures]), () => ([]))){if(!a.features.has(s))throw new Error(`Requested feature "${s}" is not supported by the adapter.`);o.push(s)}for(let s of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _123 => _123.optionalFeatures]), () => ([])))a.features.has(s)?o.push(s):console.warn(`Optional feature "${s}" is not supported by the adapter.`);return new It(await a.requestDevice({...r,requiredFeatures:o}),n==="random"?new ue:new W,!0)}function Yn(t){let{device:e,unstable_names:r="random"}=_nullishCoalesce(t, () => ({}));return new It(e,r==="random"?new ue:new W,!1)}function Ne(t){return new Ir(t)}var Ir= (_class30 =class{constructor(e=void 0){;_class30.prototype.__init70.call(this);_class30.prototype.__init71.call(this);this.defaultValue=e}__init70() {this[_chunkBF35NEOXcjs.a]=!0}__init71() {this.resourceType="slot"}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}areEqual(e,r){return Object.is(e,r)}toString(){return`slot:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](e){return Pe(e,e.unwrap(this))}get value(){let e=_chunkBF35NEOXcjs.ia.call(void 0, );if(!e)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return this[_chunkBF35NEOXcjs.c](e)}get $(){return this.value}}, _class30);function Jn(t,e){return new Dr(t,e)}var Dr= (_class31 =class{constructor(e,r=void 0){;_class31.prototype.__init72.call(this);_class31.prototype.__init73.call(this);this.schema=e;this.defaultValue=r;this.slot=Ne(r),this[_chunkBF35NEOXcjs.d]=this.slot}__init72() {this[_chunkBF35NEOXcjs.a]=!0}__init73() {this.resourceType="accessor"}$name(e){return this.slot.$name(e),this}toString(){return`accessor:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](){return new Proxy({"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:this.schema},k)}get value(){if(_chunkBF35NEOXcjs.la.call(void 0, ))return this[_chunkBF35NEOXcjs.c]();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}"~resolve"(e){let r=e.unwrap(this.slot);return _chunkBF35NEOXcjs.da.call(void 0, r)||hr(r)?e.resolve(r):jt(r)?`${e.resolve(r)}()`:e.resolveValue(r,this.schema)}}, _class31);function Xn(t){return Wa(t)}function Ma([t,e]){return`${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, t), () => ("<unnamed>"))}=${e}`}function Wa(t){if(_chunkBF35NEOXcjs.ia.call(void 0, ))throw new Error("Cannot create tgpu.derived objects at the resolution stage.");return{resourceType:"derived","~compute":t,[_chunkBF35NEOXcjs.f]:void 0,[_chunkBF35NEOXcjs.g]:void 0,[_chunkBF35NEOXcjs.c](r){return Pe(r,r.unwrap(this))},get value(){let r=_chunkBF35NEOXcjs.ia.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return this[_chunkBF35NEOXcjs.c](r)},get $(){return this.value},with(r,n){return Zn(this,[[r,n]])},toString(){return"derived"}}}function Zn(t,e){return{resourceType:"derived",[_chunkBF35NEOXcjs.f]:void 0,[_chunkBF35NEOXcjs.g]:void 0,"~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},[_chunkBF35NEOXcjs.e]:{inner:t,pairs:e},[_chunkBF35NEOXcjs.c](n){return Pe(n,n.unwrap(this))},get value(){let n=_chunkBF35NEOXcjs.ia.call(void 0, );if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return this[_chunkBF35NEOXcjs.c](n)},get $(){return this.value},with(n,a){return Zn(t,[...e,[n,a]])},toString(){return`derived[${e.map(Ma).join(", ")}]`}}}function ea(t,e){return new Dt("private",t,e)}function ta(t){return new Dt("workgroup",t)}var Dt= (_class32 =class{__init74() {this[_chunkBF35NEOXcjs.a]={}}#e;#t;#r;constructor(e,r,n){;_class32.prototype.__init74.call(this);this.#e=e,this.#t=r,this.#r=n}"~resolve"(e){let r=e.names.makeUnique(_chunkBF35NEOXcjs.j.call(void 0, this));return this.#r?e.addDeclaration(`var<${this.#e}> ${r}: ${e.resolve(this.#t)} = ${e.resolveValue(this.#r,this.#t)};`):e.addDeclaration(`var<${this.#e}> ${r}: ${e.resolve(this.#t)};`),r}$name(e){return _chunkBF35NEOXcjs.k.call(void 0, this,e),this}toString(){return`var:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBF35NEOXcjs.c](){return new Proxy({"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBF35NEOXcjs.j.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBF35NEOXcjs.b]:this.#t},k)}get $(){let e=_chunkBF35NEOXcjs.ka.call(void 0, ),r=_chunkBF35NEOXcjs.ga.call(void 0, );if(e.type==="normal")throw new (0, _chunkBF35NEOXcjs.v)(r?`Cannot access variable '${_nullishCoalesce(_chunkBF35NEOXcjs.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 e.type==="codegen"?this[_chunkBF35NEOXcjs.c]():e.type==="simulate"?(e.vars[this.#e].has(this)||e.vars[this.#e].set(this,this.#r),e.vars[this.#e].get(this)):_chunk3K53YJSUcjs.ia.call(void 0, e,"tgpuVariable.ts#TgpuVarImpl/$")}set $(e){let r=_chunkBF35NEOXcjs.ka.call(void 0, ),n=_chunkBF35NEOXcjs.ga.call(void 0, );if(r.type==="normal")throw new (0, _chunkBF35NEOXcjs.v)(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,e);return}_chunk3K53YJSUcjs.ia.call(void 0, r,"tgpuVariable.ts#TgpuVarImpl/$")}get value(){return this.$}set value(e){this.$=e}}, _class32);var Na={fn:qt,bindGroupLayout:yt,vertexLayout:yr,slot:Ne,init:Kn,initFromDevice:Yn,resolve:kn,resolveWithContext:lr,"~unstable":{fn:qt,fragmentFn:yn,vertexFn:Tn,computeFn:gn,vertexLayout:yr,derived:Xn,slot:Ne,accessor:Jn,privateVar:ea,workgroupVar:ta,const:an,declare:sn,sampler:Rn,comparisonSampler:Cn,simulate:Mn}},vl= exports.default =Na;exports.MissingBindGroupsError = _chunkBF35NEOXcjs.t; exports.MissingLinksError = _chunkBF35NEOXcjs.s; exports.MissingSlotValueError = _chunkBF35NEOXcjs.q; exports.MissingVertexBuffersError = _chunkBF35NEOXcjs.u; exports.NotUniformError = _chunkBF35NEOXcjs.r; exports.ResolutionError = _chunkBF35NEOXcjs.o; exports.default = vl; exports.isBuffer = ee; exports.isBufferShorthand = hr; exports.isComparisonSampler = $e; exports.isDerived = _chunkBF35NEOXcjs.z; exports.isSampledTextureView = Le; exports.isSampler = Ve; exports.isSlot = _chunkBF35NEOXcjs.y; exports.isStorageTextureView = Ee; exports.isTexture = N; exports.isTgpuFn = jt; exports.isUsableAsRender = _a; exports.isUsableAsSampled = nr; exports.isUsableAsStorage = le; exports.isUsableAsUniform = it; exports.isUsableAsVertex = Va; exports.tgpu = Na;
19
+ `)}${n}`}finally{this.popMode("codegen")}return this._getOrInstantiate(e)}if(typeof e=="number"){if(_optionalChain([r, 'optionalAccess', _69 => _69.type])==="abstractInt"||_optionalChain([r, 'optionalAccess', _70 => _70.type])==="u32"||_optionalChain([r, 'optionalAccess', _71 => _71.type])==="i32")return String(e);let n=e.toExponential(),a=String(e);return n.length<a.length?n:a}if(typeof e!="object"&&typeof e!="function")return String(e);if(r&&_chunk2VTISQYPcjs.J.call(void 0, r)){if(!Array.isArray(e))throw new (0, _chunk2VTISQYPcjs.u)(`Cannot coerce ${e} into value of type '${r}'`);if(r.elementCount!==e.length)throw new (0, _chunk2VTISQYPcjs.u)(`Cannot create value of type '${r}' from an array of length: ${e.length}`);return`array<${this.resolve(r.elementType)}, ${r.elementCount}>(${e.map(a=>this.resolve(a,r.elementType))})`}if(Array.isArray(e))return`array(${e.map(n=>this.resolve(n))})`;if(r&&_chunk2VTISQYPcjs.K.call(void 0, r))return`${this.resolve(r)}(${Object.entries(r.propTypes).map(([n,a])=>this.resolve(e[n],a))})`;throw new (0, _chunk2VTISQYPcjs.u)(`Value ${e} (as json: ${JSON.stringify(e)}) is not resolvable${r?` to type ${r}`:""}`)}pushMode(e){this.#e.push(e)}popMode(e){let r=this.#e.pop();e!==void 0&&_chunk2VTISQYPcjs.k.call(void 0, _optionalChain([r, 'optionalAccess', _72 => _72.type])===e,"Unexpected mode")}get mode(){return _nullishCoalesce(this.#e[this.#e.length-1], () => (_chunk2VTISQYPcjs.ea))}}, _class23);function te(t,e,r){let n=new Oe(e),a=r?n.withSlots(r(new be([])).bindings,()=>n.resolve(t)):n.resolve(t),o=n.bindGroupLayoutsToPlaceholderMap,s=[],i=new Set([...o.keys()].map(c=>c.index).filter(c=>c!==void 0)),p=xn(i),l=n.fixedBindings.map((c,y)=>[String(y),c.layoutEntry]),f=()=>{let c=p.next().value,y=yt(Object.fromEntries(l));return s[c]=y,a=a.replaceAll(Ln,String(c)),[c,new ve(y,Object.fromEntries(n.fixedBindings.map((x,I)=>[String(I),x.resource])))]},g=l.length>0?f():void 0;for(let[c,y]of o.entries()){let x=_nullishCoalesce(c.index, () => (p.next().value));s[x]=c,a=a.replaceAll(y,String(x))}return{code:a,usedBindGroupLayouts:s,catchall:g}}function _a(t,e,r){let n=e.map(a=>`${a.value}: ${t.resolve(a.dataType)}`).join(", ");return r.type!=="void"?`(${n}) -> ${_chunkCYZBRBPDcjs.m.call(void 0, r)}${t.resolve(r)} `:`(${n}) `}function ir(t){let{externals:e,template:r,names:n,config:a}=t,o={};Y(o,_nullishCoalesce(e, () => ({})));let s={[_chunk2VTISQYPcjs.a]:!0,"~resolve"(i){return ie(i,o,_nullishCoalesce(r, () => ("")))},toString:()=>"<root>"};return te(s,{names:n==="strict"?new W:new ue},a)}function On(t){return ir(t).code}function kn(t){let e=_nullishCoalesce(_chunk2VTISQYPcjs.da.call(void 0, ), () => (new Oe({names:new W}))),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))),p=Array.from({length:a[0]},(l,f)=>Array.from({length:a[1]},(g,c)=>Array.from({length:a[2]},(y,x)=>{let I=Math.floor(f/n[0]),w=Math.floor(c/n[1]),S=Math.floor(x/n[2]);return new (0, _chunk2VTISQYPcjs.W)(o,{private:i[f][c][x],workgroup:s[I][w][S]})})));e.pushMode(p[0][0][0]);try{return{value:_chunk2VTISQYPcjs.ca.call(void 0, e,t),buffers:o,privateVars:i,workgroupVars:s}}finally{e.popMode("simulate")}}function Mn(t,e,r,n){return new ur(t,e,r,n)}function ke(t){let e=t;return _optionalChain([e, 'optionalAccess', _73 => _73.resourceType])==="query-set"&&!!e[_chunk2VTISQYPcjs.a]}var ur= (_class24 =class{constructor(e,r,n,a){;_class24.prototype.__init55.call(this);_class24.prototype.__init56.call(this);_class24.prototype.__init57.call(this);_class24.prototype.__init58.call(this);_class24.prototype.__init59.call(this);_class24.prototype.__init60.call(this);this._group=e;this.type=r;this.count=n;this.rawQuerySet=a;this._ownQuerySet=!a,this._querySet=a||null}__init55() {this.resourceType="query-set"}__init56() {this._querySet=null}__init57() {this._destroyed=!1}__init58() {this._available=!0}__init59() {this._readBuffer=null}__init60() {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._group.device.createQuerySet({type:this.type,count:this.count}),this._querySet)}get destroyed(){return this._destroyed}get available(){return this._available}get[_chunk2VTISQYPcjs.a](){let e=this;return{get readBuffer(){return e._readBuffer||(e._readBuffer=e._group.device.createBuffer({size:e.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})),e._readBuffer},get resolveBuffer(){return e._resolveBuffer||(e._resolveBuffer=e._group.device.createBuffer({size:e.count*BigUint64Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC})),e._resolveBuffer}}}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this._querySet&&(this._querySet.label=e),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 e=this._group.device.createCommandEncoder();e.resolveQuerySet(this.querySet,0,this.count,this[_chunk2VTISQYPcjs.a].resolveBuffer,0),this._group.device.queue.submit([e.finish()])}async read(){if(this._group.flush(),!this._resolveBuffer)throw new Error("QuerySet must be resolved before reading.");this._available=!1;try{let e=this._group.device.createCommandEncoder();e.copyBufferToBuffer(this[_chunk2VTISQYPcjs.a].resolveBuffer,0,this[_chunk2VTISQYPcjs.a].readBuffer,0,this.count*BigUint64Array.BYTES_PER_ELEMENT),this._group.device.queue.submit([e.finish()]),await this._group.device.queue.onSubmittedWorkDone();let r=this[_chunk2VTISQYPcjs.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', _74 => _74._readBuffer, 'optionalAccess', _75 => _75.destroy, 'call', _76 => _76()]),_optionalChain([this, 'access', _77 => _77._resolveBuffer, 'optionalAccess', _78 => _78.destroy, 'call', _79 => _79()]),this._readBuffer=this._resolveBuffer=null)}}, _class24);var Me= (_class25 =class{constructor(e){;_class25.prototype.__init61.call(this);this._make=e}__init61() {this._map=new WeakMap}getOrMake(e,...r){if(this._map.has(e))return this._map.get(e);let n=this._make(e,...r);return this._map.set(e,n),n}}, _class25);function ht(t,e,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Performance callback requires the "timestamp-query" feature to be enabled on GPU device.');return t.timestampWrites?{...t,performanceCallback:e}:{...t,performanceCallback:e,hasAutoQuerySet:!0,timestampWrites:{querySet:r.createQuerySet("timestamp",2),beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}}function bt(t,e,r){if(!r.enabledFeatures.has("timestamp-query"))throw new Error('Timestamp writes require the "timestamp-query" feature to be enabled on GPU device.');t.hasAutoQuerySet&&t.timestampWrites&&t.timestampWrites.querySet.destroy();let n={querySet:e.querySet};return e.beginningOfPassWriteIndex!==void 0&&(n.beginningOfPassWriteIndex=e.beginningOfPassWriteIndex),e.endOfPassWriteIndex!==void 0&&(n.endOfPassWriteIndex=e.endOfPassWriteIndex),{...t,hasAutoQuerySet:!1,timestampWrites:n}}function wt(t,e){if(!t.timestampWrites)return{};let{querySet:r,beginningOfPassWriteIndex:n,endOfPassWriteIndex:a}=t.timestampWrites,o={querySet:ke(r)?e.unwrap(r):r};return n!==void 0&&(o.beginningOfPassWriteIndex=n),a!==void 0&&(o.endOfPassWriteIndex=a),{timestampWrites:o}}function We({root:t,priors:e}){let r=_optionalChain([e, 'access', _80 => _80.timestampWrites, 'optionalAccess', _81 => _81.querySet]),n=e.performanceCallback;if(!r)throw new Error("Cannot dispatch workgroups with performance callback without a query set.");if(!ke(r))throw new Error("Performance callback with raw GPUQuerySet is not supported. Use TgpuQuerySet instead.");t.commandEncoder.resolveQuerySet(t.unwrap(r),0,r.count,r[_chunk2VTISQYPcjs.a].resolveBuffer,0),t.flush(),t.device.queue.onSubmittedWorkDone().then(async()=>{if(!r.available)return;let a=await r.read(),o=a[_nullishCoalesce(_optionalChain([e, 'access', _82 => _82.timestampWrites, 'optionalAccess', _83 => _83.beginningOfPassWriteIndex]), () => (0))],s=a[_nullishCoalesce(_optionalChain([e, 'access', _84 => _84.timestampWrites, 'optionalAccess', _85 => _85.endOfPassWriteIndex]), () => (1))];if(o===void 0||s===void 0)throw new Error("QuerySet did not return valid timestamps.");await n(o,s)})}function Wn(t,e,r){return new pr(new lr(t,e,r),{})}function Nn(t){let e=t;return _optionalChain([e, 'optionalAccess', _86 => _86.resourceType])==="compute-pipeline"&&!!e[_chunk2VTISQYPcjs.a]}var pr= (_class26 =class t{constructor(e,r){;_class26.prototype.__init62.call(this);this._core=e;this._priors=r;this[_chunk2VTISQYPcjs.a]={get rawPipeline(){return e.unwrap().pipeline},get priors(){return r}},this[_chunk2VTISQYPcjs.d]=e}__init62() {this.resourceType="compute-pipeline"}"~resolve"(e){return e.resolve(this._core)}toString(){return`computePipeline:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}get rawPipeline(){return this._core.unwrap().pipeline}with(e,r){return new t(this._core,{...this._priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(this._priors.bindGroupLayoutMap, () => ([])),[e,r]])})}withPerformanceCallback(e){let r=ht(this._priors,e,this._core.branch);return new t(this._core,r)}withTimestampWrites(e){let r=bt(this._priors,e,this._core.branch);return new t(this._core,r)}dispatchWorkgroups(e,r,n){let a=this._core.unwrap(),{branch:o}=this._core,s={label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this._core), () => ("<unnamed>")),...wt(this._priors,o)},i=o.commandEncoder.beginComputePass(s);i.setPipeline(a.pipeline);let p=new Set(a.usedBindGroupLayouts);if(a.usedBindGroupLayouts.forEach((l,f)=>{if(a.catchall&&f===a.catchall[0])i.setBindGroup(f,o.unwrap(a.catchall[1])),p.delete(l);else{let g=_optionalChain([this, 'access', _87 => _87._priors, 'access', _88 => _88.bindGroupLayoutMap, 'optionalAccess', _89 => _89.get, 'call', _90 => _90(l)]);g!==void 0&&(p.delete(l),i.setBindGroup(f,o.unwrap(g)))}}),p.size>0)throw new (0, _chunk2VTISQYPcjs.q)(p);i.dispatchWorkgroups(e,r,n),i.end(),this._priors.performanceCallback&&We({root:o,priors:this._priors})}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this._core,e),this}}, _class26),lr= (_class27 =class{constructor(e,r,n){;_class27.prototype.__init63.call(this);this.branch=e;this._slotBindings=r;this._entryFn=n}__init63() {this[_chunk2VTISQYPcjs.a]=!0}"~resolve"(e){return e.withSlots(this._slotBindings,()=>(e.resolve(this._entryFn),""))}toString(){return"computePipelineCore"}unwrap(){if(this._memo===void 0){let e=this.branch.device,r,n;if(_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _91 => _91.enabled])){let p=performance.mark("typegpu:resolution:start");r=te(this,{names:this.branch.nameRegistry}),n=performance.measure("typegpu:resolution",{start:p.name})}else r=te(this,{names:this.branch.nameRegistry});let{code:a,usedBindGroupLayouts:o,catchall:s}=r;s!==void 0&&_optionalChain([o, 'access', _92 => _92[s[0]], 'optionalAccess', _93 => _93.$name, 'call', _94 => _94(`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let i=e.createShaderModule({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:a});this._memo={pipeline:e.createComputePipeline({label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>")),layout:e.createPipelineLayout({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:o.map(p=>this.branch.unwrap(p))}),compute:{module:i}}),usedBindGroupLayouts:o,catchall:s},_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _95 => _95.enabled])&&(async()=>{let p=performance.mark("typegpu:compile-start");await e.queue.onSubmittedWorkDone();let l=performance.measure("typegpu:compiled",{start:p.name});_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _96 => _96.record, 'call', _97 => _97("resolution",{resolveDuration:_optionalChain([n, 'optionalAccess', _98 => _98.duration]),compileDuration:l.duration,wgslSize:a.length})])})()}return this._memo}}, _class27);function fr(t,e="vertex"){return new dr(t,e)}function vt(t){return _optionalChain([t, 'optionalAccess', _99 => _99.resourceType])==="vertex-layout"}var mr=Symbol("defaultAttribEntry");function St(t,e,r,n,a){if(_chunk2VTISQYPcjs.S.call(void 0, e)||_chunk2VTISQYPcjs.ma.call(void 0, e)){let o=_chunk2VTISQYPcjs.pa.call(void 0, e);return o!==void 0&&(n[_nullishCoalesce(a, () => (mr))]=o),St(t,e.inner,_chunkCYZBRBPDcjs.d.call(void 0, r,_chunkCYZBRBPDcjs.b.call(void 0, e)),n)}if(_chunk2VTISQYPcjs.K.call(void 0, e)){let o=r,s=e.propTypes;return Object.fromEntries(Object.entries(s).map(([i,p])=>{o=_chunkCYZBRBPDcjs.d.call(void 0, o,_chunkCYZBRBPDcjs.a.call(void 0, p));let l=[i,St(t,p,o,n,i)];return o+=_chunkCYZBRBPDcjs.e.call(void 0, p),l}))}if(_chunk2VTISQYPcjs.la.call(void 0, e)){let o=r,s=e.propTypes;return Object.fromEntries(Object.entries(s).map(([i,p])=>{o=_chunkCYZBRBPDcjs.d.call(void 0, o,_chunkCYZBRBPDcjs.b.call(void 0, p));let l=[i,St(t,p,o,n,i)];return o+=_chunkCYZBRBPDcjs.e.call(void 0, p),l}))}if("type"in e&&typeof e.type=="string"){if(_chunk2VTISQYPcjs.ha.includes(e.type))return{_layout:t,format:e.type,offset:r};let o=_chunk2VTISQYPcjs.ia[e.type];if(o)return{_layout:t,format:o,offset:r}}throw new Error(`Unsupported data used in vertex layout: ${String(e)}`)}var dr= (_class28 =class{constructor(e,r){;_class28.prototype.__init64.call(this);_class28.prototype.__init65.call(this);_class28.prototype.__init66.call(this);this.schemaForCount=e;this.stepMode=r;let n=e(0);this.stride=_chunkCYZBRBPDcjs.d.call(void 0, _chunkCYZBRBPDcjs.e.call(void 0, n.elementType),_chunkCYZBRBPDcjs.a.call(void 0, n)),this.attrib=St(this,n.elementType,0,this._customLocationMap)}__init64() {this[_chunk2VTISQYPcjs.a]=!0}__init65() {this.resourceType="vertex-layout"}__init66() {this._customLocationMap={}}get vertexLayout(){if(this._customLocationMap[mr]!==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[mr]}]}}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(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}}, _class28);function Ea(t){return typeof _optionalChain([t, 'optionalAccess', _100 => _100.loadOp])=="string"}function zn(t,e){if(_chunk2VTISQYPcjs.qa.call(void 0, t)){if(!Ea(e))throw new Error("Expected a single color attachment, not a record.");return[e]}let r=[];for(let n of Object.keys(t)){let a=e[n];if(!a)throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function La(t){return typeof _optionalChain([t, 'optionalAccess', _101 => _101.format])=="string"}function qn(t,e){if(_chunk2VTISQYPcjs.qa.call(void 0, t)){if(_chunk2VTISQYPcjs.T.call(void 0, t))return[];if(!La(e))throw new Error("Expected a single color target configuration, not a record.");return[e]}let r=[];for(let n of Object.keys(t)){let a=e[n];if(!a)throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);r.push(a)}return r}function jn(t){return new gr(new cr(t),{})}function Qn(t){let e=t;return _optionalChain([e, 'optionalAccess', _102 => _102.resourceType])==="render-pipeline"&&!!e[_chunk2VTISQYPcjs.a]}var gr= (_class29 =class t{__init67() {this.resourceType="render-pipeline"}__init68() {this.hasIndexBuffer=!1}constructor(e,r){;_class29.prototype.__init67.call(this);_class29.prototype.__init68.call(this);this[_chunk2VTISQYPcjs.a]={core:e,priors:r},this[_chunk2VTISQYPcjs.d]=e}"~resolve"(e){return e.resolve(this[_chunk2VTISQYPcjs.a].core)}toString(){return`renderPipeline:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this[_chunk2VTISQYPcjs.a].core,e),this}with(e,r){let n=this[_chunk2VTISQYPcjs.a];if(Tt(e))return new t(n.core,{...n.priors,bindGroupLayoutMap:new Map([..._nullishCoalesce(n.priors.bindGroupLayoutMap, () => ([])),[e,r]])});if(vt(e))return new t(n.core,{...n.priors,vertexLayoutMap:new Map([..._nullishCoalesce(n.priors.vertexLayoutMap, () => ([])),[e,r]])});throw new Error("Unsupported value passed into .with()")}withPerformanceCallback(e){let r=this[_chunk2VTISQYPcjs.a],n=ht(r.priors,e,r.core.options.branch);return new t(r.core,n)}withTimestampWrites(e){let r=this[_chunk2VTISQYPcjs.a],n=bt(r.priors,e,r.core.options.branch);return new t(r.core,n)}withColorAttachment(e){let r=this[_chunk2VTISQYPcjs.a];return new t(r.core,{...r.priors,colorAttachment:e})}withDepthStencilAttachment(e){let r=this[_chunk2VTISQYPcjs.a];return new t(r.core,{...r.priors,depthStencilAttachment:e})}withIndexBuffer(e,r,n,a){let o=this[_chunk2VTISQYPcjs.a];if(_chunk2VTISQYPcjs.Z.call(void 0, e)){if(typeof r!="string")throw new Error("If a GPUBuffer is passed, indexFormat must be provided.");return new t(o.core,{...o.priors,indexBuffer:{buffer:e,indexFormat:r,offsetBytes:n,sizeBytes:a}})}let s={u32:"uint32",u16:"uint16"},i=e.dataType.elementType;return new t(o.core,{...o.priors,indexBuffer:{buffer:e,indexFormat:s[i.type],offsetBytes:r!==void 0?r*_chunkCYZBRBPDcjs.f.call(void 0, i):void 0,sizeBytes:a!==void 0?a*_chunkCYZBRBPDcjs.f.call(void 0, i):void 0}})}setupRenderPass(){let e=this[_chunk2VTISQYPcjs.a],r=e.core.unwrap(),{branch:n,fragmentFn:a}=e.core.options,o=zn(a.shell.out,_nullishCoalesce(e.priors.colorAttachment, () => ({}))).map(g=>N(g.view)?{...g,view:n.unwrap(g.view).createView()}:g),s={label:_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, e.core), () => ("<unnamed>")),colorAttachments:o,...wt(e.priors,n)};if(e.priors.depthStencilAttachment!==void 0){let g=e.priors.depthStencilAttachment;N(g.view)?s.depthStencilAttachment={...g,view:n.unwrap(g.view).createView()}:s.depthStencilAttachment=g}let i=n.commandEncoder.beginRenderPass(s);i.setPipeline(r.pipeline);let p=new Set(r.usedBindGroupLayouts);r.usedBindGroupLayouts.forEach((g,c)=>{if(r.catchall&&c===r.catchall[0])i.setBindGroup(c,n.unwrap(r.catchall[1])),p.delete(g);else{let y=_optionalChain([e, 'access', _103 => _103.priors, 'access', _104 => _104.bindGroupLayoutMap, 'optionalAccess', _105 => _105.get, 'call', _106 => _106(g)]);y!==void 0&&(p.delete(g),i.setBindGroup(c,n.unwrap(y)))}});let l=new Set(e.core.usedVertexLayouts);if(e.core.usedVertexLayouts.forEach((g,c)=>{let y=_optionalChain([e, 'access', _107 => _107.priors, 'access', _108 => _108.vertexLayoutMap, 'optionalAccess', _109 => _109.get, 'call', _110 => _110(g)]);y&&(l.delete(g),i.setVertexBuffer(c,n.unwrap(y)))}),p.size>0)throw new (0, _chunk2VTISQYPcjs.q)(p);if(l.size>0)throw new (0, _chunk2VTISQYPcjs.r)(l);return i}draw(e,r,n,a){let o=this[_chunk2VTISQYPcjs.a],s=this.setupRenderPass(),{branch:i}=o.core.options;s.draw(e,r,n,a),s.end(),o.priors.performanceCallback?We({root:i,priors:o.priors}):i.flush()}drawIndexed(e,r,n,a,o){let s=this[_chunk2VTISQYPcjs.a];if(!s.priors.indexBuffer)throw new Error("No index buffer set for this render pipeline.");let{buffer:i,indexFormat:p,offsetBytes:l,sizeBytes:f}=s.priors.indexBuffer,g=this.setupRenderPass(),{branch:c}=s.core.options;_chunk2VTISQYPcjs.Z.call(void 0, i)?g.setIndexBuffer(i,p,l,f):g.setIndexBuffer(c.unwrap(i),p,l,f),g.drawIndexed(e,r,n,a,o),g.end(),s.priors.performanceCallback?We({root:c,priors:s.priors}):c.flush()}}, _class29),cr= (_class30 =class{constructor(e){;_class30.prototype.__init69.call(this);this.options=e;let r=Tn(_nullishCoalesce(e.vertexFn.shell.in, () => ({})),e.vertexAttribs);this._vertexBufferLayouts=r.bufferDefinitions,this.usedVertexLayouts=r.usedVertexLayouts,this._targets=qn(e.fragmentFn.shell.out,e.targets)}__init69() {this[_chunk2VTISQYPcjs.a]=!0}"~resolve"(e){let{vertexFn:r,fragmentFn:n,slotBindings:a}=this.options,o=Oa(r.shell.out,n.shell.in,_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, r), () => ("<unnamed>")),_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, n), () => ("<unnamed>")));return e.withVaryingLocations(o,()=>e.withSlots(a,()=>(e.resolve(r),e.resolve(n),"")))}toString(){return"renderPipelineCore"}unwrap(){if(this._memo===void 0){let{branch:e,primitiveState:r,depthStencilState:n,multisampleState:a}=this.options,o=e.device,s,i;if(_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _111 => _111.enabled])){let x=performance.mark("typegpu:resolution:start");s=te(this,{names:e.nameRegistry}),i=performance.measure("typegpu:resolution",{start:x.name})}else s=te(this,{names:e.nameRegistry});let{code:p,usedBindGroupLayouts:l,catchall:f}=s;f!==void 0&&_optionalChain([l, 'access', _112 => _112[f[0]], 'optionalAccess', _113 => _113.$name, 'call', _114 => _114(`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Automatic Bind Group & Layout`)]);let g=o.createShaderModule({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Shader`,code:p}),c={layout:o.createPipelineLayout({label:`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))} - Pipeline Layout`,bindGroupLayouts:l.map(x=>e.unwrap(x))}),vertex:{module:g,buffers:this._vertexBufferLayouts},fragment:{module:g,targets:this._targets}},y=_chunk2VTISQYPcjs.g.call(void 0, this);y!==void 0&&(c.label=y),r&&(_chunk2VTISQYPcjs.I.call(void 0, r.stripIndexFormat)?c.primitive={...r,stripIndexFormat:{u32:"uint32",u16:"uint16"}[r.stripIndexFormat.type]}:c.primitive=r),n&&(c.depthStencil=n),a&&(c.multisample=a),this._memo={pipeline:o.createRenderPipeline(c),usedBindGroupLayouts:l,catchall:f},_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _115 => _115.enabled])&&(async()=>{let x=performance.mark("typegpu:compile-start");await o.queue.onSubmittedWorkDone();let I=performance.measure("typegpu:compiled",{start:x.name});_optionalChain([_chunk2VTISQYPcjs.f, 'optionalAccess', _116 => _116.record, 'call', _117 => _117("resolution",{resolveDuration:_optionalChain([i, 'optionalAccess', _118 => _118.duration]),compileDuration:I.duration,wgslSize:p.length})])})()}return this._memo}}, _class30);function Oa(t,e,r,n){let a={},o=new Set;function s(p,l){a[p]=l,o.add(l)}for(let[p,l]of Object.entries(t)){let f=_chunk2VTISQYPcjs.pa.call(void 0, l);f!==void 0&&s(p,f)}for(let[p,l]of Object.entries(_nullishCoalesce(e, () => ({})))){let f=_chunk2VTISQYPcjs.pa.call(void 0, l);f!==void 0&&(a[p]===void 0?s(p,f):a[p]!==f&&console.warn(`Mismatched location between vertexFn (${r}) output (${a[p]}) and fragmentFn (${n}) input (${f}) for the key "${p}", using the location set on vertex output.`))}let i=0;for(let p of Object.keys(_nullishCoalesce(t, () => ({}))))if(!(_chunkCYZBRBPDcjs.l.call(void 0, t[p])||a[p]!==void 0)){for(;o.has(i);)i++;s(p,i)}return a}function yr(t){return t instanceof me}var me= (_class31 =class{constructor(e,r){;_class31.prototype.__init70.call(this);this.resourceType=e;this.buffer=r;this[_chunk2VTISQYPcjs.d]=r,this.#e=this.buffer.as(this.resourceType)}__init70() {this[_chunk2VTISQYPcjs.a]=!0}#e;$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this[_chunk2VTISQYPcjs.d],e),this}write(e){this.buffer.write(e)}writePartial(e){this.buffer.writePartial(e)}read(){return this.buffer.read()}[_chunk2VTISQYPcjs.c](e){return this.#e.$}get $(){return this.#e.$}get value(){return this.$}"~resolve"(e){return e.resolve(this.#e)}}, _class31);var Tr=class t{constructor(e,r){this._getRoot=e;this._slotBindings=r}with(e,r){return new t(this._getRoot,[...this._slotBindings,[_chunk2VTISQYPcjs.y.call(void 0, e)?e.slot:e,r]])}withCompute(e){return new xr(this._getRoot(),this._slotBindings,e)}withVertex(e,r){return new hr({branch:this._getRoot(),primitiveState:void 0,depthStencilState:void 0,slotBindings:this._slotBindings,vertexFn:e,vertexAttribs:r,multisampleState:void 0})}pipe(e){let r=e(new be([]));return new t(this._getRoot,[...this._slotBindings,...r.bindings])}},xr=class{constructor(e,r,n){this._root=e;this._slotBindings=r;this._entryFn=n}createPipeline(){return Wn(this._root,this._slotBindings,this._entryFn)}},hr=class{constructor(e){this._options=e}withFragment(e,r,n){return _chunk2VTISQYPcjs.k.call(void 0, typeof e!="string","Just type mismatch validation"),_chunk2VTISQYPcjs.k.call(void 0, typeof r!="string","Just type mismatch validation"),new br({...this._options,fragmentFn:e,targets:r})}},br=class t{constructor(e){this._options=e}withPrimitive(e){return new t({...this._options,primitiveState:e})}withDepthStencil(e){return new t({...this._options,depthStencilState:e})}withMultisample(e){return new t({...this._options,multisampleState:e})}createPipeline(){return jn(this._options)}},Dt= (_class32 =class extends Tr{constructor(r,n,a){super(()=>this,[]);_class32.prototype.__init71.call(this);_class32.prototype.__init72.call(this);_class32.prototype.__init73.call(this);_class32.prototype.__init74.call(this);;this.device=r;this.nameRegistry=n;this._ownDevice=a;this["~unstable"]=this}__init71() {this._disposables=[]}__init72() {this._unwrappedBindGroupLayouts=new Me(r=>r.unwrap(this))}__init73() {this._unwrappedBindGroups=new Me(r=>r.unwrap(this))}__init74() {this._commandEncoder=null}get commandEncoder(){return this._commandEncoder||(this._commandEncoder=this.device.createCommandEncoder()),this._commandEncoder}get enabledFeatures(){return new Set(this.device.features)}createBuffer(r,n){let a=Ge(this,r,n);return this._disposables.push(a),a}createUniform(r,n){let a=Ge(this,r,n).$usage("uniform");return this._disposables.push(a),new me("uniform",a)}createMutable(r,n){let a=Ge(this,r,n).$usage("storage");return this._disposables.push(a),new me("mutable",a)}createReadonly(r,n){let a=Ge(this,r,n).$usage("storage");return this._disposables.push(a),new me("readonly",a)}createQuerySet(r,n,a){return Mn(this,r,n,a)}createBindGroup(r,n){return new ve(r,n)}destroy(){for(let r of this._disposables)r.destroy();this._ownDevice&&this.device.destroy()}createTexture(r){let n=$n(r,this);return this._disposables.push(n),n}unwrap(r){if(Nn(r))return r[_chunk2VTISQYPcjs.a].rawPipeline;if(Qn(r))return r[_chunk2VTISQYPcjs.a].core.unwrap().pipeline;if(Tt(r))return this._unwrappedBindGroupLayouts.getOrMake(r);if(nr(r))return this._unwrappedBindGroups.getOrMake(r);if(ee(r))return r.buffer;if(N(r))return r[_chunk2VTISQYPcjs.a].unwrap();if(Ee(r)){if(r[_chunk2VTISQYPcjs.a].unwrap)return r[_chunk2VTISQYPcjs.a].unwrap();throw new Error("Cannot unwrap laid-out texture view.")}if(Le(r)){if(r[_chunk2VTISQYPcjs.a].unwrap)return r[_chunk2VTISQYPcjs.a].unwrap();throw new Error("Cannot unwrap laid-out texture view.")}if(vt(r))return r.vertexLayout;if(Ve(r)){if(r[_chunk2VTISQYPcjs.a].unwrap)return r[_chunk2VTISQYPcjs.a].unwrap(this);throw new Error("Cannot unwrap laid-out sampler.")}if($e(r)){if(r[_chunk2VTISQYPcjs.a].unwrap)return r[_chunk2VTISQYPcjs.a].unwrap(this);throw new Error("Cannot unwrap laid-out comparison sampler.")}if(ke(r))return r.querySet;throw new Error(`Unknown resource type: ${r}`)}beginRenderPass(r,n){let a=this.commandEncoder.beginRenderPass(r),o=new Map,s=new Map,i,p=()=>{if(!i)throw new Error("Cannot draw without a call to pass.setPipeline");let{core:l,priors:f}=i[_chunk2VTISQYPcjs.a],g=l.unwrap();a.setPipeline(g.pipeline);let c=new Set(g.usedBindGroupLayouts);g.usedBindGroupLayouts.forEach((x,I)=>{if(g.catchall&&I===g.catchall[0])a.setBindGroup(I,this.unwrap(g.catchall[1])),c.delete(x);else{let w=_nullishCoalesce(_optionalChain([f, 'access', _119 => _119.bindGroupLayoutMap, 'optionalAccess', _120 => _120.get, 'call', _121 => _121(x)]), () => (o.get(x)));w!==void 0&&(c.delete(x),nr(w)?a.setBindGroup(I,this.unwrap(w)):a.setBindGroup(I,w))}});let y=new Set;if(l.usedVertexLayouts.forEach((x,I)=>{let w=_optionalChain([f, 'access', _122 => _122.vertexLayoutMap, 'optionalAccess', _123 => _123.get, 'call', _124 => _124(x)]),S=w?{buffer:w,offset:void 0,size:void 0}:s.get(x);!S||!S.buffer?y.add(x):ee(S.buffer)?a.setVertexBuffer(I,this.unwrap(S.buffer),S.offset,S.size):a.setVertexBuffer(I,S.buffer,S.offset,S.size)}),c.size>0)throw new (0, _chunk2VTISQYPcjs.q)(c);if(y.size>0)throw new (0, _chunk2VTISQYPcjs.r)(y)};n({setViewport(...l){a.setViewport(...l)},setScissorRect(...l){a.setScissorRect(...l)},setBlendConstant(...l){a.setBlendConstant(...l)},setStencilReference(...l){a.setStencilReference(...l)},beginOcclusionQuery(...l){a.beginOcclusionQuery(...l)},endOcclusionQuery(...l){a.endOcclusionQuery(...l)},executeBundles(...l){a.executeBundles(...l)},setPipeline(l){i=l},setIndexBuffer:(l,f,g,c)=>{ee(l)?a.setIndexBuffer(this.unwrap(l),f,g,c):a.setIndexBuffer(l,f,g,c)},setVertexBuffer(l,f,g,c){s.set(l,{buffer:f,offset:g,size:c})},setBindGroup(l,f){o.set(l,f)},draw(l,f,g,c){p(),a.draw(l,f,g,c)},drawIndexed(...l){p(),a.drawIndexed(...l)},drawIndirect(...l){p(),a.drawIndirect(...l)},drawIndexedIndirect(...l){p(),a.drawIndexedIndirect(...l)}}),a.end()}flush(){this._commandEncoder&&(this.device.queue.submit([this._commandEncoder.finish()]),this._commandEncoder=null)}}, _class32);async function Hn(t){let{adapter:e,device:r,unstable_names:n="random"}=_nullishCoalesce(t, () => ({}));if(!navigator.gpu)throw new Error("WebGPU is not supported by this browser.");let a=await navigator.gpu.requestAdapter(e);if(!a)throw new Error("Could not find a compatible GPU");let o=[];for(let s of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _125 => _125.requiredFeatures]), () => ([]))){if(!a.features.has(s))throw new Error(`Requested feature "${s}" is not supported by the adapter.`);o.push(s)}for(let s of _nullishCoalesce(_optionalChain([r, 'optionalAccess', _126 => _126.optionalFeatures]), () => ([])))a.features.has(s)?o.push(s):console.warn(`Optional feature "${s}" is not supported by the adapter.`);return new Dt(await a.requestDevice({...r,requiredFeatures:o}),n==="random"?new ue:new W,!0)}function Kn(t){let{device:e,unstable_names:r="random"}=_nullishCoalesce(t, () => ({}));return new Dt(e,r==="random"?new ue:new W,!1)}function Ne(t){return new wr(t)}var wr= (_class33 =class{constructor(e=void 0){;_class33.prototype.__init75.call(this);_class33.prototype.__init76.call(this);this.defaultValue=e}__init75() {this[_chunk2VTISQYPcjs.a]=!0}__init76() {this.resourceType="slot"}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}areEqual(e,r){return Object.is(e,r)}toString(){return`slot:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](e){return Pe(e,e.unwrap(this))}get value(){let e=_chunk2VTISQYPcjs.da.call(void 0, );if(!e)throw new Error("Cannot access tgpu.slot's value outside of resolution.");return this[_chunk2VTISQYPcjs.c](e)}get $(){return this.value}}, _class33);function Yn(t,e){return new Sr(t,e)}var Sr= (_class34 =class{constructor(e,r=void 0){;_class34.prototype.__init77.call(this);_class34.prototype.__init78.call(this);this.schema=e;this.defaultValue=r;this.slot=Ne(r),this[_chunk2VTISQYPcjs.d]=this.slot}__init77() {this[_chunk2VTISQYPcjs.a]=!0}__init78() {this.resourceType="accessor"}$name(e){return this.slot.$name(e),this}toString(){return`accessor:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](){return new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:this.schema},k)}get value(){if(_chunk2VTISQYPcjs.ga.call(void 0, ))return this[_chunk2VTISQYPcjs.c]();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}"~resolve"(e){let r=e.unwrap(this.slot);return _chunk2VTISQYPcjs._.call(void 0, r)||yr(r)?e.resolve(r):Nt(r)?`${e.resolve(r)}()`:e.resolve(r,this.schema)}}, _class34);function Jn(t){return Ma(t)}function ka([t,e]){return`${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, t), () => ("<unnamed>"))}=${e}`}function Ma(t){if(_chunk2VTISQYPcjs.da.call(void 0, ))throw new Error("Cannot create tgpu.derived objects at the resolution stage.");return{[_chunk2VTISQYPcjs.a]:!0,resourceType:"derived","~compute":t,[_chunk2VTISQYPcjs.c](r){return Pe(r,r.unwrap(this))},get value(){let r=_chunk2VTISQYPcjs.da.call(void 0, );if(!r)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return this[_chunk2VTISQYPcjs.c](r)},get $(){return this.value},with(r,n){return Xn(this,[[r,n]])},toString(){return"derived"}}}function Xn(t,e){return{[_chunk2VTISQYPcjs.a]:!0,resourceType:"derived","~compute"(){throw new Error("'~compute' should never be read on bound derived items.")},[_chunk2VTISQYPcjs.e]:{inner:t,pairs:e},[_chunk2VTISQYPcjs.c](n){return Pe(n,n.unwrap(this))},get value(){let n=_chunk2VTISQYPcjs.da.call(void 0, );if(!n)throw new Error("Cannot access tgpu.derived's value outside of resolution.");return this[_chunk2VTISQYPcjs.c](n)},get $(){return this.value},with(n,a){return Xn(t,[...e,[n,a]])},toString(){return`derived[${e.map(ka).join(", ")}]`}}}function Zn(t,e){return new It("private",t,e)}function ea(t){return new It("workgroup",t)}var It= (_class35 =class{__init79() {this[_chunk2VTISQYPcjs.a]={}}#e;#t;#r;constructor(e,r,n){;_class35.prototype.__init79.call(this);this.#e=e,this.#t=r,this.#r=n}"~resolve"(e){let r=e.names.makeUnique(_chunk2VTISQYPcjs.g.call(void 0, this));return this.#r?e.addDeclaration(`var<${this.#e}> ${r}: ${e.resolve(this.#t)} = ${e.resolve(this.#r,this.#t)};`):e.addDeclaration(`var<${this.#e}> ${r}: ${e.resolve(this.#t)};`),r}$name(e){return _chunk2VTISQYPcjs.h.call(void 0, this,e),this}toString(){return`var:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`}[_chunk2VTISQYPcjs.c](){return new Proxy({[_chunk2VTISQYPcjs.a]:!0,"~resolve":e=>e.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunk2VTISQYPcjs.g.call(void 0, this), () => ("<unnamed>"))}`,[_chunk2VTISQYPcjs.b]:this.#t},k)}get $(){let e=_chunk2VTISQYPcjs.fa.call(void 0, ),r=_chunk2VTISQYPcjs.ba.call(void 0, );if(e.type==="normal")throw new (0, _chunk2VTISQYPcjs.s)(r?`Cannot access variable '${_nullishCoalesce(_chunk2VTISQYPcjs.g.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 e.type==="codegen"?this[_chunk2VTISQYPcjs.c]():e.type==="simulate"?(e.vars[this.#e].has(this)||e.vars[this.#e].set(this,this.#r),e.vars[this.#e].get(this)):_chunk2VTISQYPcjs.ib.call(void 0, e,"tgpuVariable.ts#TgpuVarImpl/$")}set $(e){let r=_chunk2VTISQYPcjs.fa.call(void 0, ),n=_chunk2VTISQYPcjs.ba.call(void 0, );if(r.type==="normal")throw new (0, _chunk2VTISQYPcjs.s)(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,e);return}_chunk2VTISQYPcjs.ib.call(void 0, r,"tgpuVariable.ts#TgpuVarImpl/$")}get value(){return this.$}set value(e){this.$=e}}, _class35);var Wa={fn:Wt,bindGroupLayout:yt,vertexLayout:fr,slot:Ne,init:Hn,initFromDevice:Kn,resolve:On,resolveWithContext:ir,"~unstable":{fn:Wt,fragmentFn:cn,vertexFn:yn,computeFn:fn,vertexLayout:fr,derived:Jn,slot:Ne,accessor:Yn,privateVar:Zn,workgroupVar:ea,const:nn,declare:on,sampler:An,comparisonSampler:Cn,simulate:kn}},Sl= exports.default =Wa;exports.MissingBindGroupsError = _chunk2VTISQYPcjs.q; exports.MissingLinksError = _chunk2VTISQYPcjs.p; exports.MissingSlotValueError = _chunk2VTISQYPcjs.n; exports.MissingVertexBuffersError = _chunk2VTISQYPcjs.r; exports.NotUniformError = _chunk2VTISQYPcjs.o; exports.ResolutionError = _chunk2VTISQYPcjs.l; exports.default = Sl; exports.isBuffer = ee; exports.isBufferShorthand = yr; exports.isComparisonSampler = $e; exports.isDerived = _chunk2VTISQYPcjs.w; exports.isSampledTextureView = Le; exports.isSampler = Ve; exports.isSlot = _chunk2VTISQYPcjs.v; exports.isStorageTextureView = Ee; exports.isTexture = N; exports.isTgpuFn = Nt; exports.isUsableAsRender = $a; exports.isUsableAsSampled = er; exports.isUsableAsStorage = le; exports.isUsableAsUniform = it; exports.isUsableAsVertex = Ga; exports.tgpu = Wa;
20
20
  //# sourceMappingURL=index.cjs.map