@luma.gl/webgpu 9.2.5 → 9.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/adapter/resources/webgpu-fence.d.ts +13 -0
  2. package/dist/adapter/resources/webgpu-fence.d.ts.map +1 -0
  3. package/dist/adapter/resources/webgpu-fence.js +25 -0
  4. package/dist/adapter/resources/webgpu-fence.js.map +1 -0
  5. package/dist/adapter/resources/webgpu-texture.d.ts +12 -3
  6. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  7. package/dist/adapter/resources/webgpu-texture.js +143 -26
  8. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  9. package/dist/adapter/webgpu-adapter.d.ts.map +1 -1
  10. package/dist/adapter/webgpu-adapter.js +34 -34
  11. package/dist/adapter/webgpu-adapter.js.map +1 -1
  12. package/dist/adapter/webgpu-canvas-context.d.ts +4 -3
  13. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  14. package/dist/adapter/webgpu-canvas-context.js +22 -21
  15. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  16. package/dist/adapter/webgpu-device.d.ts +3 -1
  17. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  18. package/dist/adapter/webgpu-device.js +14 -3
  19. package/dist/adapter/webgpu-device.js.map +1 -1
  20. package/dist/dist.dev.js +6438 -274
  21. package/dist/dist.min.js +10 -6
  22. package/dist/index.cjs +347 -86
  23. package/dist/index.cjs.map +4 -4
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/wgsl/get-shader-layout-wgsl.d.ts +8 -0
  29. package/dist/wgsl/get-shader-layout-wgsl.d.ts.map +1 -0
  30. package/dist/wgsl/get-shader-layout-wgsl.js +136 -0
  31. package/dist/wgsl/get-shader-layout-wgsl.js.map +1 -0
  32. package/package.json +5 -4
  33. package/src/adapter/resources/webgpu-fence.ts +30 -0
  34. package/src/adapter/resources/webgpu-texture.ts +202 -88
  35. package/src/adapter/webgpu-adapter.ts +40 -42
  36. package/src/adapter/webgpu-canvas-context.ts +25 -23
  37. package/src/adapter/webgpu-device.ts +19 -4
  38. package/src/index.ts +3 -0
  39. package/src/wgsl/get-shader-layout-wgsl.ts +156 -0
package/dist/dist.min.js CHANGED
@@ -4,11 +4,15 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- "use strict";var __exports__=(()=>{var rt=Object.create;var k=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var d=(i,e)=>()=>(i&&(e=i(i=0)),e);var at=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),ge=(i,e)=>{for(var t in e)k(i,t,{get:e[t],enumerable:!0})},U=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of nt(e))!ot.call(i,n)&&n!==t&&k(i,n,{get:()=>e[n],enumerable:!(r=it(e,n))||r.enumerable});return i},V=(i,e,t)=>(U(i,e,"default"),t&&U(t,e,"default")),p=(i,e,t)=>(t=i!=null?rt(st(i)):{},U(e||!i||!i.__esModule?k(t,"default",{value:i,enumerable:!0}):t,i)),dt=i=>U(k({},"__esModule",{value:!0}),i);var h=at((gt,be)=>{be.exports=globalThis.luma});var g,v,se=d(()=>{"use strict";g=p(h(),1),v=class extends g.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=t.byteLength||t.data?.byteLength||0;let r=Boolean(this.props.onMapped||t.data),n=Math.ceil(this.byteLength/4)*4;if(this.device.pushErrorScope("out-of-memory"),this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createBuffer({label:this.props.id,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:r,size:n}),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} creation failed ${s.message}`),this)(),this.device.debug()}),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} out of memory: ${s.message}`),this)(),this.device.debug()}),this.device.pushErrorScope("validation"),t.data||t.onMapped)try{let s=this.handle.getMappedRange();if(t.data){let o=t.data;new o.constructor(s).set(o)}else t.onMapped?.(s,"mapped")}finally{this.handle.unmap()}this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} creation failed ${s.message}`),this)(),this.device.debug()})}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){let r=ArrayBuffer.isView(e)?e.buffer:e,n=ArrayBuffer.isView(e)?e.byteOffset:0;this.device.pushErrorScope("validation"),this.device.handle.queue.writeBuffer(this.handle,t,r,n,e.byteLength),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this}.write() ${s.message}`),this)(),this.device.debug()})}async mapAndWriteAsync(e,t=0,r=this.byteLength-t){let s=(this.usage&g.Buffer.MAP_WRITE)!==0?null:this._getMappableBuffer(g.Buffer.MAP_WRITE|g.Buffer.COPY_SRC,0,this.byteLength),o=s||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),await o.handle.mapAsync(GPUMapMode.WRITE,t,r);let a=o.handle.getMappedRange(t,r);await e(a,"mapped"),o.handle.unmap(),s&&this._copyBuffer(s,t,r)}finally{this.device.popErrorScope(a=>{this.device.reportError(new Error(`${this}.mapAndWriteAsync() ${a.message}`),this)(),this.device.debug()}),s?.destroy()}}async readAsync(e=0,t=this.byteLength-e){return this.mapAndReadAsync(r=>new Uint8Array(r.slice(0)),e,t)}async mapAndReadAsync(e,t=0,r=this.byteLength-t){if(t%8!==0||r%4!==0)throw new Error("byteOffset must be multiple of 8 and byteLength multiple of 4");if(t+r>this.handle.size)throw new Error("Mapping range exceeds buffer size");let s=(this.usage&g.Buffer.MAP_READ)!==0?null:this._getMappableBuffer(g.Buffer.MAP_READ|g.Buffer.COPY_DST,0,this.byteLength),o=s||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),s&&s._copyBuffer(this),await o.handle.mapAsync(GPUMapMode.READ,t,r);let a=o.handle.getMappedRange(t,r),l=await e(a,"mapped");return o.handle.unmap(),l}finally{this.device.popErrorScope(a=>{this.device.reportError(new Error(`${this}.mapAndReadAsync() ${a.message}`),this)(),this.device.debug()}),s?.destroy()}}readSyncWebGL(e,t){throw new Error("Not implemented")}_getMappableBuffer(e,t,r){return g.log.warn(`${this} is not readable, creating a temporary Buffer`),new v(this.device,{usage:e,byteLength:r})}_copyBuffer(e,t=0,r=this.byteLength){this.device.pushErrorScope("validation");let n=this.device.handle.createCommandEncoder();n.copyBufferToBuffer(e.handle,t,this.handle,t,r),this.device.handle.queue.submit([n.finish()]),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this}._getReadableBuffer() ${s.message}`),this)(),this.device.debug()})}}});function E(i){if(i.includes("webgl"))throw new Error("webgl-only format");return i}var oe=d(()=>{"use strict"});var ye,u,D=d(()=>{"use strict";ye=p(h(),1),u=class extends ye.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props,mipmapFilter:void 0};t.type!=="comparison-sampler"&&delete r.compare,t.mipmapFilter&&t.mipmapFilter!=="none"&&(r.mipmapFilter=t.mipmapFilter),this.handle=t.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}}});var ve,I,we=d(()=>{"use strict";ve=p(h(),1),I=class extends ve.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.device.pushErrorScope("validation"),this.handle=this.texture.handle.createView({format:this.props.format||this.texture.format,dimension:this.props.dimension||this.texture.dimension,aspect:this.props.aspect,baseMipLevel:this.props.baseMipLevel,mipLevelCount:this.props.mipLevelCount,baseArrayLayer:this.props.baseArrayLayer,arrayLayerCount:this.props.arrayLayerCount}),this.device.popErrorScope(r=>{this.device.reportError(new Error(`TextureView constructor: ${r.message}`),this)(),this.device.debug()}),this.handle.label=this.props.id}destroy(){this.handle=null}}});var B,P,ae=d(()=>{"use strict";B=p(h(),1);oe();D();we();P=class extends B.Texture{device;handle;sampler;view;constructor(e,t){super(e,t),this.device=e,this.dimension==="cube"&&(this.depth=6),this.device.pushErrorScope("out-of-memory"),this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createTexture({label:this.id,size:{width:this.width,height:this.height,depthOrArrayLayers:this.depth},usage:this.props.usage||B.Texture.TEXTURE|B.Texture.COPY_DST,dimension:this.baseDimension,format:E(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples}),this.device.popErrorScope(r=>{this.device.reportError(new Error(`${this} constructor: ${r.message}`),this)(),this.device.debug()}),this.device.popErrorScope(r=>{this.device.reportError(new Error(`${this} out of memory: ${r.message}`),this)(),this.device.debug()}),this.props.handle&&(this.handle.label||=this.id,this.width=this.handle.width,this.height=this.handle.height),this.sampler=t.sampler instanceof u?t.sampler:new u(this.device,t.sampler||{}),this.view=new I(this.device,{...this.props,texture:this,mipLevelCount:this.mipLevels,arrayLayerCount:this.dimension!=="3d"?this.depth:1}),this._initializeData(t.data)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new I(this.device,{...e,texture:this})}copyImageData(e){let{width:t,height:r,depth:n}=this,s=this._normalizeCopyImageDataOptions(e);this.device.pushErrorScope("validation"),this.device.handle.queue.writeTexture({texture:this.handle,mipLevel:s.mipLevel,aspect:s.aspect,origin:[s.x,s.y,s.z]},s.data,{offset:s.byteOffset,bytesPerRow:s.bytesPerRow,rowsPerImage:s.rowsPerImage},[t,r,n]),this.device.popErrorScope(o=>{this.device.reportError(new Error(`copyImageData: ${o.message}`),this)(),this.device.debug()})}copyExternalImage(e){let t=this._normalizeCopyExternalImageOptions(e);return this.device.pushErrorScope("validation"),this.device.handle.queue.copyExternalImageToTexture({source:t.image,origin:[t.sourceX,t.sourceY],flipY:t.flipY},{texture:this.handle,origin:[t.x,t.y,0],mipLevel:t.mipLevel,aspect:t.aspect,colorSpace:t.colorSpace,premultipliedAlpha:t.premultipliedAlpha},[t.width,t.height,1]),this.device.popErrorScope(r=>{this.device.reportError(new Error(`copyExternalImage: ${r.message}`),this)(),this.device.debug()}),{width:t.width,height:t.height}}generateMipmapsWebGL(){B.log.warn(`${this}: generateMipmaps not supported in WebGPU`)()}}});var xe,z,Se=d(()=>{"use strict";xe=p(h(),1);D();z=class extends xe.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}}});var Ee,C,de=d(()=>{"use strict";Ee=p(h(),1),C=class extends Ee.Shader{device;handle;constructor(e,t){super(e,t),this.device=e;let r=t.source.includes("#version");if(this.props.language==="glsl"||r)throw new Error("GLSL shaders are not supported in WebGPU");this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createShaderModule({code:t.source}),this.device.popErrorScope(n=>{this.device.reportError(new Error(`${this} creation failed:
8
- "${n.message}"`),this,this.props.source)(),this.device.debug()}),this.handle.label=this.props.id,this._checkCompilationError()}get asyncCompilationStatus(){return this.getCompilationInfo().then(()=>this.compilationStatus)}async _checkCompilationError(){let e=await this.getCompilationInfo(),t=Boolean(e.find(r=>r.type==="error"));this.compilationStatus=t?"error":"success",this.debugShader(),this.compilationStatus==="error"&&(this.device.reportError(new Error("Shader compilation error"),this,e)(),this.device.debug())}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}}});function b(i){return i.depthStencil=i.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},i.depthStencil}function q(i){return b(i).stencilFront}function Q(i){return b(i).stencilBack}function f(i,e,t){N.log.warn(`${i} parameter not supported in WebGPU`)()}function Be(i,e={}){Object.assign(i,{...pt,...i}),lt(i,e)}function lt(i,e){for(let[t,r]of Object.entries(e)){let n=ht[t];n?n(t,r,i):N.log.error(`Illegal parameter ${t} in WebGPU`)()}}function Pe(i,e){return i.fragment.targets=i.fragment?.targets||[],Array.isArray(i.fragment?.targets)||N.log.warn("parameters: no targets array")(),i.fragment?.targets?.length===0&&i.fragment.targets?.push({}),i.fragment?.targets?.[0]}function w(i,e){let t=Pe(i,e);return t.blend=t.blend||{color:{},alpha:{}},t.blend}var N,ht,pt,Ce=d(()=>{"use strict";N=p(h(),1);ht={cullMode:(i,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(i,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(i,e,t)=>{if(e){let r=b(t);r.depthWriteEnabled=e}},depthCompare:(i,e,t)=>{let r=b(t);r.depthCompare=e},depthFormat:(i,e,t)=>{let r=b(t);r.format=e},depthBias:(i,e,t)=>{let r=b(t);r.depthBias=e},depthBiasSlopeScale:(i,e,t)=>{let r=b(t);r.depthBiasSlopeScale=e},depthBiasClamp:(i,e,t)=>{let r=b(t);r.depthBiasClamp=e},stencilReadMask:(i,e,t)=>{let r=b(t);r.stencilReadMask=e},stencilWriteMask:(i,e,t)=>{let r=b(t);r.stencilWriteMask=e},stencilCompare:(i,e,t)=>{let r=q(t),n=Q(t);r.compare=e,n.compare=e},stencilPassOperation:(i,e,t)=>{let r=q(t),n=Q(t);r.passOp=e,n.passOp=e},stencilFailOperation:(i,e,t)=>{let r=q(t),n=Q(t);r.failOp=e,n.failOp=e},stencilDepthFailOperation:(i,e,t)=>{let r=q(t),n=Q(t);r.depthFailOp=e,n.depthFailOp=e},sampleCount:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(i,e,t)=>{let r=Pe(t,0);r.writeMask=e},blend:(i,e,t)=>{e&&w(t,0)},blendColorOperation:(i,e,t)=>{let r=w(t,0);r.color=r.color||{},r.color.operation=e},blendColorSrcFactor:(i,e,t)=>{let r=w(t,0);r.color=r.color||{},r.color.srcFactor=e},blendColorDstFactor:(i,e,t)=>{let r=w(t,0);r.color.dstFactor=e},blendAlphaOperation:(i,e,t)=>{let r=w(t,0);r.alpha=r.alpha||{},r.alpha.operation=e},blendAlphaSrcFactor:(i,e,t)=>{let r=w(t,0);r.alpha=r.alpha||{},r.alpha.srcFactor=e},blendAlphaDstFactor:(i,e,t)=>{let r=w(t,0);r.alpha=r.alpha||{},r.alpha.dstFactor=e},unclippedDepth:f,provokingVertex:f,polygonMode:f,polygonOffsetLine:f,clipDistance0:f,clipDistance1:f,clipDistance2:f,clipDistance3:f,clipDistance4:f,clipDistance5:f,clipDistance6:f,clipDistance7:f};pt={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"}});function j(i,e,t,r){let n=ct(r,t);i.pushErrorScope("validation");let s=i.createBindGroup({layout:e,entries:n});return i.popErrorScope().then(o=>{o&&m.log.error(`bindGroup creation: ${o.message}`,s)()}),s}function _e(i,e,t){let r=i.bindings.find(n=>n.name===e||`${n.name.toLocaleLowerCase()}uniforms`===e.toLocaleLowerCase());return!r&&!t?.ignoreWarnings&&m.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),r||null}function ct(i,e){let t=[];for(let[r,n]of Object.entries(i)){let s=_e(e,r);if(s){let o=Ae(n,s.location);o&&t.push(o)}if(n instanceof m.Texture&&(s=_e(e,`${r}Sampler`,{ignoreWarnings:!0}),s)){let o=Ae(n,s.location,{sampler:!0});o&&t.push(o)}}return t}function Ae(i,e,t){return i instanceof m.Buffer?{binding:e,resource:{buffer:i.handle}}:i instanceof m.Sampler?{binding:e,resource:i.handle}:i instanceof m.Texture?t?.sampler?{binding:e,resource:i.sampler.handle}:{binding:e,resource:i.view.handle}:(m.log.warn(`invalid binding ${name}`,i),null)}var m,he=d(()=>{"use strict";m=p(h(),1)});function pe(i){if(i.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${i}`);return i}function Ge(i,e){let t=[],r=new Set;for(let n of e){let s=[],o="vertex",a=0,l=n.format;if(n.attributes)for(let c of n.attributes){let T=c.attribute,S=Le(i,T,r),O=S?.location;l=c.format||n.format,o=S?.stepMode||(S?.name.startsWith("instance")?"instance":"vertex"),s.push({format:pe(l),offset:c.byteOffset,shaderLocation:O}),a+=(0,_.getVertexFormatInfo)(l).byteLength}else{let c=Le(i,n.name,r);if(!c)continue;a=(0,_.getVertexFormatInfo)(l).byteLength,o=c.stepMode||(c.name.startsWith("instance")?"instance":"vertex"),s.push({format:pe(l),offset:0,shaderLocation:c.location})}t.push({arrayStride:n.byteStride||a,stepMode:o,attributes:s})}for(let n of i.attributes)r.has(n.name)||t.push({arrayStride:(0,_.getVertexFormatInfo)("float32x3").byteLength,stepMode:n.stepMode||(n.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:pe("float32x3"),offset:0,shaderLocation:n.location}]});return t.sort((n,s)=>{let o=Math.min(...Array.from(n.attributes,l=>l.shaderLocation)),a=Math.min(...Array.from(s.attributes,l=>l.shaderLocation));return o-a}),t}function Le(i,e,t){let r=i.attributes.find(n=>n.name===e);if(!r)return _.log.warn(`Supplied attribute not present in shader layout: ${e}`)(),null;if(t){if(t.has(e))throw new Error(`Found multiple entries for attribute: ${e}`);t.add(e)}return r}var _,Te=d(()=>{"use strict";_=p(h(),1)});var A,Y,De=d(()=>{"use strict";A=p(h(),1);Ce();oe();he();Te();Y=class extends A.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;get[Symbol.toStringTag](){return"WebGPURenderPipeline"}constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();A.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),A.log.probe(1,JSON.stringify(r,null,2))(),A.log.groupEnd(1)(),this.device.pushErrorScope("validation"),this.handle=this.device.handle.createRenderPipeline(r),this.device.popErrorScope(n=>{this.device.reportError(new Error(`${this} creation failed:
9
- "${n.message}"`),this)(),this.device.debug()})}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){for(let[t,r]of Object.entries(e))this._bindings[t]!==r&&(this._bindGroup=null);Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;this.device.pushErrorScope("validation"),t.handle.setPipeline(this.handle),this.device.popErrorScope(n=>{this.device.reportError(new Error(`${this} setPipeline failed:
10
- "${n.message}"`),this)(),this.device.debug()});let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||j(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:Ge(this.shaderLayout,this.props.bufferLayout)},t=[];if(this.props.colorAttachmentFormats)for(let a of this.props.colorAttachmentFormats)t.push(a?{format:E(a)}:null);else t.push({format:E(this.device.preferredColorFormat)});let r={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:t},n=this.device.createPipelineLayout({shaderLayout:this.shaderLayout}),s={vertex:e,fragment:r,primitive:{topology:this.props.topology},layout:n.handle},o=this.props.depthStencilAttachmentFormat||this.device.preferredDepthFormat;return this.props.parameters.depthWriteEnabled&&(s.depthStencil={format:E(o)}),Be(s,this.props.parameters),s}}});var Ie,L,le=d(()=>{"use strict";Ie=p(h(),1),L=class extends Ie.Framebuffer{device;handle=null;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}updateAttachments(){}}});var Fe,H,We=d(()=>{"use strict";Fe=p(h(),1);he();H=class extends Fe.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||j(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}}});var Ot,Ut,kt,Me,Re=d(()=>{Ot=globalThis.document||{},Ut=globalThis.process||{},kt=globalThis.console,Me=globalThis.navigator||{}});function X(i){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=i||e;return Boolean(t&&t.indexOf("Electron")>=0)}var ce=d(()=>{});function $e(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||X()}var Oe=d(()=>{ce()});function ue(i){return!i&&!$e()?"Node":X(i)?"Electron":(i||Me.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var Ue=d(()=>{Oe();ce();Re()});var ke=d(()=>{Ue()});var F,J,Ve=d(()=>{"use strict";F=p(h(),1);ke();J=class extends F.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle=null;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let n=e,s=this.indexBuffer;s?.handle&&(F.log.info(3,"setting index buffer",s?.handle,s?.indexType)(),n.handle.setIndexBuffer(s?.handle,s?.indexType));for(let o=0;o<this.maxVertexAttributes;o++){let a=this.attributes[o];a?.handle&&(F.log.info(3,`setting vertex buffer ${o}`,a?.handle)(),n.handle.setVertexBuffer(o,a?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return ue()==="Chrome"}}});var G,W,ze=d(()=>{"use strict";G=p(h(),1);le();W=class extends G.CanvasContext{device;handle;depthStencilAttachment=null;get[Symbol.toStringTag](){return"WebGPUCanvasContext"}constructor(e,t,r){super(r);let n=this.canvas.getContext("webgpu");if(!n)throw new Error(`${this}: Failed to create WebGPU canvas context`);this.device=e,this.handle=n,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._updateDevice()}destroy(){this.handle.unconfigure(),super.destroy()}getCurrentFramebuffer(e={depthStencilFormat:"depth24plus"}){let t=this.getCurrentTexture();if(t.width!==this.drawingBufferWidth||t.height!==this.drawingBufferHeight){let[r,n]=this.getDrawingBufferSize();this.drawingBufferWidth=t.width,this.drawingBufferHeight=t.height,G.log.log(1,`${this}: Resized to compensate for initial canvas size mismatch ${r}x${n} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e?.depthStencilFormat),new L(this.device,{colorAttachments:[t],depthStencilAttachment:this.depthStencilAttachment})}_updateDevice(){this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.handle.configure({device:this.device.handle,format:this.device.preferredColorFormat,colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode})}getCurrentTexture(){let e=this.handle.getCurrentTexture();return this.device.createTexture({id:`${this.id}#color-texture`,handle:e,format:this.device.preferredColorFormat,width:e.width,height:e.height})}_createDepthStencilAttachment(e){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,usage:G.Texture.RENDER_ATTACHMENT,format:e,width:this.drawingBufferWidth,height:this.drawingBufferHeight})),this.depthStencilAttachment}}});var qe,Z,Qe=d(()=>{"use strict";qe=p(h(),1),Z=class extends qe.CommandBuffer{device;handle;constructor(e,t){super(e.device,{}),this.device=e.device,this.handle=this.props.handle||e.handle.finish({label:t?.id||"unnamed-command-buffer"})}}});function ut(i){return{r:i[0],g:i[1],b:i[2],a:i[3]}}var x,K,Ne=d(()=>{"use strict";x=p(h(),1),K=class extends x.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),n=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(n.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let o=t.timestampQuerySet;n.timestampWrites=o?{querySet:o.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.device.pushErrorScope("validation"),this.handle=this.props.handle||e.commandEncoder.handle.beginRenderPass(n),this.device.popErrorScope(o=>{this.device.reportError(new Error(`${this} creation failed:
11
- "${o.message}"`),this)(),this.device.debug()}),this.handle.label=this.props.id,x.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),x.log.probe(3,JSON.stringify(n,null,2))(),x.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.device.pushErrorScope("validation"),this.handle.setPipeline(this.pipeline.handle),this.device.popErrorScope(t=>{this.device.reportError(new Error(`${this} setPipeline failed:
12
- "${t.message}"`),this)(),this.device.debug()})}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,n){this.handle.setIndexBuffer(e.handle,t,r,n)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:n,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),n&&this.handle.setScissorRect(n[0],n[1],n[2],n[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4]??0,s[5]??1)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map((r,n)=>({loadOp:this.props.clearColor!==!1?"clear":"load",clearValue:ut(this.props.clearColors?.[n]||this.props.clearColor||x.RenderPass.defaultClearColor),storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),this.props.clearDepth!==!1&&(r.depthClearValue=this.props.clearDepth),!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}}});var je,ee,Ye=d(()=>{"use strict";je=p(h(),1),ee=class extends je.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let n=t.timestampQuerySet;n&&(r={querySet:n.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder.handle.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}}});var He,te,Xe=d(()=>{"use strict";He=p(h(),1);Qe();Ne();Ye();te=class extends He.CommandEncoder{device;handle;constructor(e,t={}){super(e,t),this.device=e,this.handle=t.handle||this.device.handle.createCommandEncoder({label:this.props.id}),this.handle.label=this.props.id}destroy(){}finish(e){this.device.pushErrorScope("validation");let t=new Z(this,{id:e?.id||"unnamed-command-buffer"});return this.device.popErrorScope(r=>{let n=`${this} command encoding: ${r.message}. Maybe add depthWriteEnabled to your Model?`;this.device.reportError(new Error(n),this)(),this.device.debug()}),t}beginRenderPass(e){return new K(this.device,e)}beginComputePass(e){return new ee(this.device,e)}copyBufferToBuffer(e){let t=e.sourceBuffer,r=e.destinationBuffer;this.handle.copyBufferToBuffer(t.handle,e.sourceOffset??0,r.handle,e.destinationOffset??0,e.size??0)}copyBufferToTexture(e){let t=e.sourceBuffer,r=e.destinationTexture;this.handle.copyBufferToTexture({buffer:t.handle,offset:e.offset??0,bytesPerRow:e.bytesPerRow,rowsPerImage:e.rowsPerImage},{texture:r.handle,mipLevel:e.mipLevel??0,origin:e.origin??{}},{width:e.extent?.[0],height:e.extent?.[1],depthOrArrayLayers:e.extent?.[2]})}copyTextureToBuffer(e){}copyTextureToTexture(e){}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}resolveQuerySet(e,t,r){let n=e,s=t;this.handle.resolveQuerySet(n.handle,r?.firstQuery||0,r?.queryCount||e.props.count-(r?.firstQuery||0),s.handle,r?.destinationOffset||0)}}});var Je,re,Ze=d(()=>{"use strict";Je=p(h(),1),re=class extends Je.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}}});var ne,ie,ft,Ke=d(()=>{"use strict";ne=p(h(),1),ie=class extends ne.PipelineLayout{device;handle;constructor(e,t){super(e,t),this.device=e;let r=this.mapShaderLayoutToBindGroupEntries();this.handle=this.device.handle.createPipelineLayout({label:t?.id??"unnamed-pipeline-layout",bindGroupLayouts:[this.device.handle.createBindGroupLayout({label:"bind-group-layout",entries:r})]})}destroy(){this.handle=null}mapShaderLayoutToBindGroupEntries(){let e=[];for(let t=0;t<this.props.shaderLayout.bindings.length;t++){let r=this.props.shaderLayout.bindings[t],n={};switch(r.type){case"uniform":{n.buffer={type:"uniform",hasDynamicOffset:r.hasDynamicOffset,minBindingSize:r.minBindingSize};break}case"read-only-storage":{n.buffer={type:"read-only-storage",hasDynamicOffset:r.hasDynamicOffset,minBindingSize:r.minBindingSize};break}case"sampler":{n.sampler={type:r.samplerType};break}case"storage":{ft(r)?n.storageTexture={format:r.format,access:r.access,viewDimension:r.viewDimension}:n.buffer={type:"storage",hasDynamicOffset:r.hasDynamicOffset,minBindingSize:r.minBindingSize};break}case"texture":{n.texture={multisampled:r.multisampled,sampleType:r.sampleType,viewDimension:r.viewDimension};break}default:ne.log.warn("unhandled binding type when creating pipeline descriptor")()}let s=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE;e.push({binding:r.location,visibility:r.visibility||s,...n})}return e}},ft=i=>i.format!==void 0});var et={};ge(et,{WebGPUDevice:()=>R});var M,R,fe=d(()=>{"use strict";M=p(h(),1);se();ae();Se();D();de();De();le();We();Ve();ze();Xe();Ze();Ke();R=class extends M.Device{handle;adapter;adapterInfo;type="webgpu";preferredColorFormat=navigator.gpu.getPreferredCanvasFormat();preferredDepthFormat="depth24plus";features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder;get[Symbol.toStringTag](){return"WebGPUDevice"}toString(){return`WebGPUDevice(${this.id})`}constructor(e,t,r,n){super({...e,id:e.id||"webgpu-device"}),this.handle=t,this.adapter=r,this.adapterInfo=n,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,t.addEventListener("uncapturederror",o=>{o.preventDefault();let a=o instanceof GPUUncapturedErrorEvent?o.error.message:"Unknown WebGPU error";this.reportError(new Error(a),this)(),this.debug()}),this.lost=new Promise(async o=>{let a=await this.handle.lost;this._isLost=!0,o({reason:"destroyed",message:a.message})});let s=M.Device._getCanvasContextProps(e);s&&(this.canvasContext=new W(this,this.adapter,s)),this.commandEncoder=this.createCommandEncoder({})}destroy(){this.handle.destroy()}get isLost(){return this._isLost}isVertexFormatSupported(e){return!this.getVertexFormatInfo(e).webglOnly}getTextureByteAlignment(){return 1}createBuffer(e){let t=this._normalizeBufferProps(e);return new v(this,t)}createTexture(e){return new P(this,e)}createExternalTexture(e){return new z(this,e)}createShader(e){return new C(this,e)}createSampler(e){return new u(this,e)}createRenderPipeline(e){return new Y(this,e)}createFramebuffer(e){return new L(this,e)}createComputePipeline(e){return new H(this,e)}createVertexArray(e){return new J(this,e)}createCommandEncoder(e){return new te(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new re(this,e)}createCanvasContext(e){return new W(this,this.adapter,e)}createPipelineLayout(e){return new ie(this,e)}submit(e){e||(e=this.commandEncoder.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:`${this.id}-default-encoder`})),this.pushErrorScope("validation"),this.handle.queue.submit([e.handle]),this.popErrorScope(t=>{this.reportError(new Error(`${this} command submission: ${t.message}`),this)(),this.debug()})}pushErrorScope(e){this.handle.pushErrorScope(e)}popErrorScope(e){this.handle.popErrorScope().then(t=>{t&&e(t)})}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",n=e||"",s=t||"",o=r==="apple"?"apple":"unknown",a=this.adapterInfo.architecture||"unknown",l=this.adapterInfo.backend||"unknown",c=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:n,version:s,gpu:o,gpuType:c,gpuBackend:l,gpuArchitecture:a,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new M.DeviceFeatures(Array.from(e),this.props._disabledFeatures)}_getDeviceSpecificTextureFormatCapabilities(e){let{format:t}=e;return t.includes("webgl")?{format:t,create:!1,render:!1,filter:!1,blend:!1,store:!1}:e}}});var $={};ge($,{WebGPUBuffer:()=>v,WebGPUDevice:()=>R,WebGPUSampler:()=>u,WebGPUShader:()=>C,WebGPUTexture:()=>P,webgpuAdapter:()=>tt});V($,p(h(),1));var y=p(h(),1),me=class extends y.Adapter{type="webgpu";isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}isDeviceHandle(e){return!!(typeof GPUDevice<"u"&&e instanceof GPUDevice||e?.queue)}async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Recent Chrome browsers should work.");y.log.groupCollapsed(1,"WebGPUDevice created")();try{let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=t.info||await t.requestAdapterInfo?.();y.log.probe(2,"Adapter available",r)();let n=[],s={};if(e._requestMaxLimits){n.push(...Array.from(t.features));let c=Object.keys(t.limits).filter(T=>!["minSubgroupSize","maxSubgroupSize"].includes(T));for(let T of c){let S=T,O=t.limits[S];typeof O=="number"&&(s[S]=O)}}let o=await t.requestDevice({requiredFeatures:n,requiredLimits:s});y.log.probe(1,"GPUDevice available")();let{WebGPUDevice:a}=await Promise.resolve().then(()=>(fe(),et)),l=new a(e,o,t,r);return y.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),y.log.table(1,l.info)(),l}finally{y.log.groupEnd(1)()}}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},tt=new me;fe();se();ae();D();de();return dt($);})();
7
+ "use strict";var __exports__=(()=>{var Br=Object.create;var ot=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var Pr=Object.getPrototypeOf,Vr=Object.prototype.hasOwnProperty;var C=(u,e)=>()=>(u&&(e=u(u=0)),e);var Fr=(u,e)=>()=>(e||u((e={exports:{}}).exports,e),e.exports),Fn=(u,e)=>{for(var t in e)ot(u,t,{get:e[t],enumerable:!0})},at=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Or(e))!Vr.call(u,r)&&r!==t&&ot(u,r,{get:()=>e[r],enumerable:!(n=Dr(e,r))||n.enumerable});return u},lt=(u,e,t)=>(at(u,e,"default"),t&&at(t,e,"default")),O=(u,e,t)=>(t=u!=null?Br(Pr(u)):{},at(e||!u||!u.__esModule?ot(t,"default",{value:u,enumerable:!0}):t,u)),Nr=u=>at(ot({},"__esModule",{value:!0}),u);var B=Fr((ss,Nn)=>{Nn.exports=globalThis.luma});var ie,pe,en=C(()=>{"use strict";ie=O(B(),1),pe=class extends ie.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=t.byteLength||t.data?.byteLength||0;let n=Boolean(this.props.onMapped||t.data),r=Math.ceil(this.byteLength/4)*4;if(this.device.pushErrorScope("out-of-memory"),this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createBuffer({label:this.props.id,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:n,size:r}),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} creation failed ${s.message}`),this)(),this.device.debug()}),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} out of memory: ${s.message}`),this)(),this.device.debug()}),this.device.pushErrorScope("validation"),t.data||t.onMapped)try{let s=this.handle.getMappedRange();if(t.data){let a=t.data;new a.constructor(s).set(a)}else t.onMapped?.(s,"mapped")}finally{this.handle.unmap()}this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} creation failed ${s.message}`),this)(),this.device.debug()})}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){let n=ArrayBuffer.isView(e)?e.buffer:e,r=ArrayBuffer.isView(e)?e.byteOffset:0;this.device.pushErrorScope("validation"),this.device.handle.queue.writeBuffer(this.handle,t,n,r,e.byteLength),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this}.write() ${s.message}`),this)(),this.device.debug()})}async mapAndWriteAsync(e,t=0,n=this.byteLength-t){let s=(this.usage&ie.Buffer.MAP_WRITE)!==0?null:this._getMappableBuffer(ie.Buffer.MAP_WRITE|ie.Buffer.COPY_SRC,0,this.byteLength),a=s||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),await a.handle.mapAsync(GPUMapMode.WRITE,t,n);let i=a.handle.getMappedRange(t,n);await e(i,"mapped"),a.handle.unmap(),s&&this._copyBuffer(s,t,n)}finally{this.device.popErrorScope(i=>{this.device.reportError(new Error(`${this}.mapAndWriteAsync() ${i.message}`),this)(),this.device.debug()}),s?.destroy()}}async readAsync(e=0,t=this.byteLength-e){return this.mapAndReadAsync(n=>new Uint8Array(n.slice(0)),e,t)}async mapAndReadAsync(e,t=0,n=this.byteLength-t){if(t%8!==0||n%4!==0)throw new Error("byteOffset must be multiple of 8 and byteLength multiple of 4");if(t+n>this.handle.size)throw new Error("Mapping range exceeds buffer size");let s=(this.usage&ie.Buffer.MAP_READ)!==0?null:this._getMappableBuffer(ie.Buffer.MAP_READ|ie.Buffer.COPY_DST,0,this.byteLength),a=s||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),s&&s._copyBuffer(this),await a.handle.mapAsync(GPUMapMode.READ,t,n);let i=a.handle.getMappedRange(t,n),o=await e(i,"mapped");return a.handle.unmap(),o}finally{this.device.popErrorScope(i=>{this.device.reportError(new Error(`${this}.mapAndReadAsync() ${i.message}`),this)(),this.device.debug()}),s?.destroy()}}readSyncWebGL(e,t){throw new Error("Not implemented")}_getMappableBuffer(e,t,n){return ie.log.warn(`${this} is not readable, creating a temporary Buffer`),new pe(this.device,{usage:e,byteLength:n})}_copyBuffer(e,t=0,n=this.byteLength){this.device.pushErrorScope("validation");let r=this.device.handle.createCommandEncoder();r.copyBufferToBuffer(e.handle,t,this.handle,t,n),this.device.handle.queue.submit([r.finish()]),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this}._getReadableBuffer() ${s.message}`),this)(),this.device.debug()})}}});function ke(u){if(u.includes("webgl"))throw new Error("webgl-only format");return u}var tn=C(()=>{"use strict"});var Mn,Y,Me=C(()=>{"use strict";Mn=O(B(),1),Y=class extends Mn.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let n={...this.props,mipmapFilter:void 0};t.type!=="comparison-sampler"&&delete n.compare,t.mipmapFilter&&t.mipmapFilter!=="none"&&(n.mipmapFilter=t.mipmapFilter),this.handle=t.handle||this.device.handle.createSampler(n),this.handle.label=this.props.id}destroy(){this.handle=null}}});var Wn,We,Un=C(()=>{"use strict";Wn=O(B(),1),We=class extends Wn.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.device.pushErrorScope("validation"),this.handle=this.texture.handle.createView({format:this.props.format||this.texture.format,dimension:this.props.dimension||this.texture.dimension,aspect:this.props.aspect,baseMipLevel:this.props.baseMipLevel,mipLevelCount:this.props.mipLevelCount,baseArrayLayer:this.props.baseArrayLayer,arrayLayerCount:this.props.arrayLayerCount}),this.device.popErrorScope(n=>{this.device.reportError(new Error(`TextureView constructor: ${n.message}`),this)(),this.device.debug()}),this.handle.label=this.props.id}destroy(){this.handle=null}}});var ee,Ie,nn=C(()=>{"use strict";ee=O(B(),1);tn();Me();Un();Ie=class extends ee.Texture{device;handle;sampler;view;constructor(e,t){super(e,t,{byteAlignment:256}),this.device=e,this.device.pushErrorScope("out-of-memory"),this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createTexture({label:this.id,size:{width:this.width,height:this.height,depthOrArrayLayers:this.depth},usage:this.props.usage||ee.Texture.TEXTURE|ee.Texture.COPY_DST,dimension:this.baseDimension,format:ke(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples}),this.device.popErrorScope(n=>{this.device.reportError(new Error(`${this} constructor: ${n.message}`),this)(),this.device.debug()}),this.device.popErrorScope(n=>{this.device.reportError(new Error(`${this} out of memory: ${n.message}`),this)(),this.device.debug()}),this.props.handle&&(this.handle.label||=this.id,this.width=this.handle.width,this.height=this.handle.height),this.sampler=t.sampler instanceof Y?t.sampler:new Y(this.device,t.sampler||{}),this.view=new We(this.device,{...this.props,texture:this,mipLevelCount:this.mipLevels,arrayLayerCount:this.dimension!=="3d"?this.depth:1}),this._initializeData(t.data)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new We(this.device,{...e,texture:this})}copyExternalImage(e){let t=this._normalizeCopyExternalImageOptions(e);return this.device.pushErrorScope("validation"),this.device.handle.queue.copyExternalImageToTexture({source:t.image,origin:[t.sourceX,t.sourceY],flipY:!1},{texture:this.handle,origin:[t.x,t.y,t.z],mipLevel:t.mipLevel,aspect:t.aspect,colorSpace:t.colorSpace,premultipliedAlpha:t.premultipliedAlpha},[t.width,t.height,t.depth]),this.device.popErrorScope(n=>{this.device.reportError(new Error(`copyExternalImage: ${n.message}`),this)(),this.device.debug()}),{width:t.width,height:t.height}}copyImageData(e){let{width:t,height:n,depth:r}=this,s=this._normalizeCopyImageDataOptions(e);this.device.pushErrorScope("validation"),this.device.handle.queue.writeTexture({texture:this.handle,mipLevel:s.mipLevel,aspect:s.aspect,origin:[s.x,s.y,s.z]},s.data,{offset:s.byteOffset,bytesPerRow:s.bytesPerRow,rowsPerImage:s.rowsPerImage},[t,n,r]),this.device.popErrorScope(a=>{this.device.reportError(new Error(`copyImageData: ${a.message}`),this)(),this.device.debug()})}generateMipmapsWebGL(){ee.log.warn(`${this}: generateMipmaps not supported in WebGPU`)()}getImageDataLayout(e){return{byteLength:0,bytesPerRow:0,rowsPerImage:0}}readBuffer(e={},t){let{x:n=0,y:r=0,z:s=0,width:a=this.width,height:i=this.height,depthOrArrayLayers:o=this.depth,mipLevel:c=0,aspect:l="all"}=e,f=this.computeMemoryLayout(e),{bytesPerRow:_,rowsPerImage:v,byteLength:k}=f,A=t||this.device.createBuffer({byteLength:k,usage:ee.Buffer.COPY_DST|ee.Buffer.MAP_READ}),E=A.handle,V=this.device.handle;this.device.pushErrorScope("validation");let W=V.createCommandEncoder();W.copyTextureToBuffer({texture:this.handle,origin:{x:n,y:r,z:s},mipLevel:c,aspect:l},{buffer:E,offset:0,bytesPerRow:_,rowsPerImage:v},{width:a,height:i,depthOrArrayLayers:o});let S=W.finish();return this.device.handle.queue.submit([S]),this.device.popErrorScope(T=>{this.device.reportError(new Error(`${this} readBuffer: ${T.message}`),this)(),this.device.debug()}),A}async readDataAsync(e={}){let t=this.readBuffer(e),n=await t.readAsync();return t.destroy(),n.buffer}writeBuffer(e,t={}){let{x:n=0,y:r=0,z:s=0,width:a=this.width,height:i=this.height,depthOrArrayLayers:o=this.depth,mipLevel:c=0,aspect:l="all"}=t,f=this.computeMemoryLayout(t),{bytesPerRow:_,rowsPerImage:v}=f,k=this.device.handle;this.device.pushErrorScope("validation");let A=k.createCommandEncoder();A.copyBufferToTexture({buffer:e.handle,offset:0,bytesPerRow:_,rowsPerImage:v},{texture:this.handle,origin:{x:n,y:r,z:s},mipLevel:c,aspect:l},{width:a,height:i,depthOrArrayLayers:o});let E=A.finish();this.device.handle.queue.submit([E]),this.device.popErrorScope(V=>{this.device.reportError(new Error(`${this} writeBuffer: ${V.message}`),this)(),this.device.debug()})}writeData(e,t={}){let n=this.device,{x:r=0,y:s=0,z:a=0,width:i=this.width,height:o=this.height,depthOrArrayLayers:c=this.depth,mipLevel:l=0,aspect:f="all"}=t,_=ee.textureFormatDecoder.computeMemoryLayout({format:this.format,width:this.width,height:this.height,depth:this.depth,byteAlignment:this.byteAlignment}),{bytesPerRow:v,rowsPerImage:k}=_;this.device.pushErrorScope("validation"),n.handle.queue.writeTexture({texture:this.handle,mipLevel:l,aspect:f,origin:{x:r,y:s,z:a}},e,{offset:0,bytesPerRow:v,rowsPerImage:k},{width:i,height:o,depthOrArrayLayers:c}),this.device.popErrorScope(A=>{this.device.reportError(new Error(`${this} writeData: ${A.message}`),this)(),this.device.debug()})}}});var Gn,ct,qn=C(()=>{"use strict";Gn=O(B(),1);Me();ct=class extends Gn.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof Y?e:new Y(this.device,e),this}}});var Rn,Se,rn=C(()=>{"use strict";Rn=O(B(),1),Se=class extends Rn.Shader{device;handle;constructor(e,t){super(e,t),this.device=e;let n=t.source.includes("#version");if(this.props.language==="glsl"||n)throw new Error("GLSL shaders are not supported in WebGPU");this.device.pushErrorScope("validation"),this.handle=this.props.handle||this.device.handle.createShaderModule({code:t.source}),this.device.popErrorScope(r=>{this.device.reportError(new Error(`${this} creation failed:
8
+ "${r.message}"`),this,this.props.source)(),this.device.debug()}),this.handle.label=this.props.id,this._checkCompilationError()}get asyncCompilationStatus(){return this.getCompilationInfo().then(()=>this.compilationStatus)}async _checkCompilationError(){let e=await this.getCompilationInfo(),t=Boolean(e.find(n=>n.type==="error"));this.compilationStatus=t?"error":"success",this.debugShader(),this.compilationStatus==="error"&&(this.device.reportError(new Error("Shader compilation error"),this,e)(),this.device.debug())}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}}});function ae(u){return u.depthStencil=u.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},u.depthStencil}function ut(u){return ae(u).stencilFront}function ht(u){return ae(u).stencilBack}function Z(u,e,t){ft.log.warn(`${u} parameter not supported in WebGPU`)()}function zn(u,e={}){Object.assign(u,{...Wr,...u}),Ur(u,e)}function Ur(u,e){for(let[t,n]of Object.entries(e)){let r=Mr[t];r?r(t,n,u):ft.log.error(`Illegal parameter ${t} in WebGPU`)()}}function Hn(u,e){return u.fragment.targets=u.fragment?.targets||[],Array.isArray(u.fragment?.targets)||ft.log.warn("parameters: no targets array")(),u.fragment?.targets?.length===0&&u.fragment.targets?.push({}),u.fragment?.targets?.[0]}function ge(u,e){let t=Hn(u,e);return t.blend=t.blend||{color:{},alpha:{}},t.blend}var ft,Mr,Wr,Qn=C(()=>{"use strict";ft=O(B(),1);Mr={cullMode:(u,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(u,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(u,e,t)=>{if(e){let n=ae(t);n.depthWriteEnabled=e}},depthCompare:(u,e,t)=>{let n=ae(t);n.depthCompare=e},depthFormat:(u,e,t)=>{let n=ae(t);n.format=e},depthBias:(u,e,t)=>{let n=ae(t);n.depthBias=e},depthBiasSlopeScale:(u,e,t)=>{let n=ae(t);n.depthBiasSlopeScale=e},depthBiasClamp:(u,e,t)=>{let n=ae(t);n.depthBiasClamp=e},stencilReadMask:(u,e,t)=>{let n=ae(t);n.stencilReadMask=e},stencilWriteMask:(u,e,t)=>{let n=ae(t);n.stencilWriteMask=e},stencilCompare:(u,e,t)=>{let n=ut(t),r=ht(t);n.compare=e,r.compare=e},stencilPassOperation:(u,e,t)=>{let n=ut(t),r=ht(t);n.passOp=e,r.passOp=e},stencilFailOperation:(u,e,t)=>{let n=ut(t),r=ht(t);n.failOp=e,r.failOp=e},stencilDepthFailOperation:(u,e,t)=>{let n=ut(t),r=ht(t);n.depthFailOp=e,r.depthFailOp=e},sampleCount:(u,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(u,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(u,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(u,e,t)=>{let n=Hn(t,0);n.writeMask=e},blend:(u,e,t)=>{e&&ge(t,0)},blendColorOperation:(u,e,t)=>{let n=ge(t,0);n.color=n.color||{},n.color.operation=e},blendColorSrcFactor:(u,e,t)=>{let n=ge(t,0);n.color=n.color||{},n.color.srcFactor=e},blendColorDstFactor:(u,e,t)=>{let n=ge(t,0);n.color.dstFactor=e},blendAlphaOperation:(u,e,t)=>{let n=ge(t,0);n.alpha=n.alpha||{},n.alpha.operation=e},blendAlphaSrcFactor:(u,e,t)=>{let n=ge(t,0);n.alpha=n.alpha||{},n.alpha.srcFactor=e},blendAlphaDstFactor:(u,e,t)=>{let n=ge(t,0);n.alpha=n.alpha||{},n.alpha.dstFactor=e},unclippedDepth:Z,provokingVertex:Z,polygonMode:Z,polygonOffsetLine:Z,clipDistance0:Z,clipDistance1:Z,clipDistance2:Z,clipDistance3:Z,clipDistance4:Z,clipDistance5:Z,clipDistance6:Z,clipDistance7:Z};Wr={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"}});function pt(u,e,t,n){let r=Gr(n,t);u.pushErrorScope("validation");let s=u.createBindGroup({layout:e,entries:r});return u.popErrorScope().then(a=>{a&&te.log.error(`bindGroup creation: ${a.message}`,s)()}),s}function Xn(u,e,t){let n=u.bindings.find(r=>r.name===e||`${r.name.toLocaleLowerCase()}uniforms`===e.toLocaleLowerCase());return!n&&!t?.ignoreWarnings&&te.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),n||null}function Gr(u,e){let t=[];for(let[n,r]of Object.entries(u)){let s=Xn(e,n);if(s){let a=jn(r,s.location);a&&t.push(a)}if(r instanceof te.Texture&&(s=Xn(e,`${n}Sampler`,{ignoreWarnings:!0}),s)){let a=jn(r,s.location,{sampler:!0});a&&t.push(a)}}return t}function jn(u,e,t){return u instanceof te.Buffer?{binding:e,resource:{buffer:u.handle}}:u instanceof te.Sampler?{binding:e,resource:u.handle}:u instanceof te.Texture?t?.sampler?{binding:e,resource:u.sampler.handle}:{binding:e,resource:u.view.handle}:(te.log.warn(`invalid binding ${name}`,u),null)}var te,sn=C(()=>{"use strict";te=O(B(),1)});function an(u){if(u.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${u}`);return u}function Zn(u,e){let t=[],n=new Set;for(let r of e){let s=[],a="vertex",i=0,o=r.format;if(r.attributes)for(let c of r.attributes){let l=c.attribute,f=Yn(u,l,n),_=f?.location;o=c.format||r.format,a=f?.stepMode||(f?.name.startsWith("instance")?"instance":"vertex"),s.push({format:an(o),offset:c.byteOffset,shaderLocation:_}),i+=(0,Te.getVertexFormatInfo)(o).byteLength}else{let c=Yn(u,r.name,n);if(!c)continue;i=(0,Te.getVertexFormatInfo)(o).byteLength,a=c.stepMode||(c.name.startsWith("instance")?"instance":"vertex"),s.push({format:an(o),offset:0,shaderLocation:c.location})}t.push({arrayStride:r.byteStride||i,stepMode:a,attributes:s})}for(let r of u.attributes)n.has(r.name)||t.push({arrayStride:(0,Te.getVertexFormatInfo)("float32x3").byteLength,stepMode:r.stepMode||(r.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:an("float32x3"),offset:0,shaderLocation:r.location}]});return t.sort((r,s)=>{let a=Math.min(...Array.from(r.attributes,o=>o.shaderLocation)),i=Math.min(...Array.from(s.attributes,o=>o.shaderLocation));return a-i}),t}function Yn(u,e,t){let n=u.attributes.find(r=>r.name===e);if(!n)return Te.log.warn(`Supplied attribute not present in shader layout: ${e}`)(),null;if(t){if(t.has(e))throw new Error(`Found multiple entries for attribute: ${e}`);t.add(e)}return n}var Te,Jn=C(()=>{"use strict";Te=O(B(),1)});var Ee,dt,Kn=C(()=>{"use strict";Ee=O(B(),1);Qn();tn();sn();Jn();dt=class extends Ee.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;get[Symbol.toStringTag](){return"WebGPURenderPipeline"}constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let n=this._getRenderPipelineDescriptor();Ee.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),Ee.log.probe(1,JSON.stringify(n,null,2))(),Ee.log.groupEnd(1)(),this.device.pushErrorScope("validation"),this.handle=this.device.handle.createRenderPipeline(n),this.device.popErrorScope(r=>{this.device.reportError(new Error(`${this} creation failed:
9
+ "${r.message}"`),this)(),this.device.debug()})}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){for(let[t,n]of Object.entries(e))this._bindings[t]!==n&&(this._bindGroup=null);Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;this.device.pushErrorScope("validation"),t.handle.setPipeline(this.handle),this.device.popErrorScope(r=>{this.device.reportError(new Error(`${this} setPipeline failed:
10
+ "${r.message}"`),this)(),this.device.debug()});let n=this._getBindGroup();return n&&t.handle.setBindGroup(0,n),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||pt(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:Zn(this.shaderLayout,this.props.bufferLayout)},t=[];if(this.props.colorAttachmentFormats)for(let i of this.props.colorAttachmentFormats)t.push(i?{format:ke(i)}:null);else t.push({format:ke(this.device.preferredColorFormat)});let n={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:t},r=this.device.createPipelineLayout({shaderLayout:this.shaderLayout}),s={vertex:e,fragment:n,primitive:{topology:this.props.topology},layout:r.handle},a=this.props.depthStencilAttachmentFormat||this.device.preferredDepthFormat;return this.props.parameters.depthWriteEnabled&&(s.depthStencil={format:ke(a)}),zn(s,this.props.parameters),s}}});var er,Ae,on=C(()=>{"use strict";er=O(B(),1),Ae=class extends er.Framebuffer{device;handle=null;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}updateAttachments(){}}});var tr,mt,nr=C(()=>{"use strict";tr=O(B(),1);sn();mt=class extends tr.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let n=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:n.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||pt(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}}});var Es,As,Ls,rr,sr=C(()=>{Es=globalThis.document||{},As=globalThis.process||{},Ls=globalThis.console,rr=globalThis.navigator||{}});function gt(u){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=u||e;return Boolean(t&&t.indexOf("Electron")>=0)}var ln=C(()=>{});function ir(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||gt()}var ar=C(()=>{ln()});function cn(u){return!u&&!ir()?"Node":gt(u)?"Electron":(u||rr.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var or=C(()=>{ar();ln();sr()});var lr=C(()=>{or()});var Ue,xt,cr=C(()=>{"use strict";Ue=O(B(),1);lr();xt=class extends Ue.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle=null;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,n){let r=e,s=this.indexBuffer;s?.handle&&(Ue.log.info(3,"setting index buffer",s?.handle,s?.indexType)(),r.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let i=this.attributes[a];i?.handle&&(Ue.log.info(3,`setting vertex buffer ${a}`,i?.handle)(),r.handle.setVertexBuffer(a,i?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return cn()==="Chrome"}}});var Le,Ge,ur=C(()=>{"use strict";Le=O(B(),1);on();Ge=class extends Le.CanvasContext{device;handle;depthStencilAttachment=null;get[Symbol.toStringTag](){return"WebGPUCanvasContext"}constructor(e,t,n){super(n);let r=this.canvas.getContext("webgpu");if(!r)throw new Error(`${this}: Failed to create WebGPU canvas context`);this.device=e,this.handle=r,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._configureDevice()}destroy(){this.handle.unconfigure(),super.destroy()}_configureDevice(){this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.handle.configure({device:this.device.handle,format:this.device.preferredColorFormat,colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode})}_getCurrentFramebuffer(e={depthStencilFormat:"depth24plus"}){let t=this._getCurrentTexture();if(t.width!==this.drawingBufferWidth||t.height!==this.drawingBufferHeight){let[n,r]=this.getDrawingBufferSize();this.drawingBufferWidth=t.width,this.drawingBufferHeight=t.height,Le.log.log(1,`${this}: Resized to compensate for initial canvas size mismatch ${n}x${r} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e?.depthStencilFormat),new Ae(this.device,{colorAttachments:[t],depthStencilAttachment:this.depthStencilAttachment})}_getCurrentTexture(){let e=this.handle.getCurrentTexture();return this.device.createTexture({id:`${this.id}#color-texture`,handle:e,format:this.device.preferredColorFormat,width:e.width,height:e.height})}_createDepthStencilAttachment(e){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,usage:Le.Texture.RENDER_ATTACHMENT,format:e,width:this.drawingBufferWidth,height:this.drawingBufferHeight})),this.depthStencilAttachment}}});var hr,yt,fr=C(()=>{"use strict";hr=O(B(),1),yt=class extends hr.CommandBuffer{device;handle;constructor(e,t){super(e.device,{}),this.device=e.device,this.handle=this.props.handle||e.handle.finish({label:t?.id||"unnamed-command-buffer"})}}});function qr(u){return{r:u[0],g:u[1],b:u[2],a:u[3]}}var xe,_t,pr=C(()=>{"use strict";xe=O(B(),1),_t=class extends xe.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let n=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),r=this.getRenderPassDescriptor(n),s=t.timestampQuerySet;if(s&&(r.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;r.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.device.pushErrorScope("validation"),this.handle=this.props.handle||e.commandEncoder.handle.beginRenderPass(r),this.device.popErrorScope(a=>{this.device.reportError(new Error(`${this} creation failed:
11
+ "${a.message}"`),this)(),this.device.debug()}),this.handle.label=this.props.id,xe.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),xe.log.probe(3,JSON.stringify(r,null,2))(),xe.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.device.pushErrorScope("validation"),this.handle.setPipeline(this.pipeline.handle),this.device.popErrorScope(t=>{this.device.reportError(new Error(`${this} setPipeline failed:
12
+ "${t.message}"`),this)(),this.device.debug()})}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,n=0,r){this.handle.setIndexBuffer(e.handle,t,n,r)}setVertexBuffer(e,t,n=0){this.handle.setVertexBuffer(e,t.handle,n)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:n,scissorRect:r,viewport:s}=e;t&&this.handle.setBlendConstant(t),n&&this.handle.setStencilReference(n),r&&this.handle.setScissorRect(r[0],r[1],r[2],r[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4]??0,s[5]??1)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map((n,r)=>({loadOp:this.props.clearColor!==!1?"clear":"load",clearValue:qr(this.props.clearColors?.[r]||this.props.clearColor||xe.RenderPass.defaultClearColor),storeOp:this.props.discard?"discard":"store",view:n.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:n}=t;this.props.depthReadOnly&&(n.depthReadOnly=!0),this.props.clearDepth!==!1&&(n.depthClearValue=this.props.clearDepth),!0&&(n.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",n.depthStoreOp="store"),!1&&(n.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",n.stencilStoreOp="store")}return t}}});var dr,bt,mr=C(()=>{"use strict";dr=O(B(),1),bt=class extends dr.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let n;if(e.features.has("timestamp-query")){let r=t.timestampQuerySet;r&&(n={querySet:r.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder.handle.beginComputePass({label:this.props.id,timestampWrites:n})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,n){this.handle.dispatchWorkgroups(e,t,n)}dispatchIndirect(e,t=0){let n=e;this.handle.dispatchWorkgroupsIndirect(n.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}}});var gr,vt,xr=C(()=>{"use strict";gr=O(B(),1);fr();pr();mr();vt=class extends gr.CommandEncoder{device;handle;constructor(e,t={}){super(e,t),this.device=e,this.handle=t.handle||this.device.handle.createCommandEncoder({label:this.props.id}),this.handle.label=this.props.id}destroy(){}finish(e){this.device.pushErrorScope("validation");let t=new yt(this,{id:e?.id||"unnamed-command-buffer"});return this.device.popErrorScope(n=>{let r=`${this} command encoding: ${n.message}. Maybe add depthWriteEnabled to your Model?`;this.device.reportError(new Error(r),this)(),this.device.debug()}),t}beginRenderPass(e){return new _t(this.device,e)}beginComputePass(e){return new bt(this.device,e)}copyBufferToBuffer(e){let t=e.sourceBuffer,n=e.destinationBuffer;this.handle.copyBufferToBuffer(t.handle,e.sourceOffset??0,n.handle,e.destinationOffset??0,e.size??0)}copyBufferToTexture(e){let t=e.sourceBuffer,n=e.destinationTexture;this.handle.copyBufferToTexture({buffer:t.handle,offset:e.offset??0,bytesPerRow:e.bytesPerRow,rowsPerImage:e.rowsPerImage},{texture:n.handle,mipLevel:e.mipLevel??0,origin:e.origin??{}},{width:e.extent?.[0],height:e.extent?.[1],depthOrArrayLayers:e.extent?.[2]})}copyTextureToBuffer(e){}copyTextureToTexture(e){}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}resolveQuerySet(e,t,n){let r=e,s=t;this.handle.resolveQuerySet(r.handle,n?.firstQuery||0,n?.queryCount||e.props.count-(n?.firstQuery||0),s.handle,n?.destinationOffset||0)}}});var yr,wt,_r=C(()=>{"use strict";yr=O(B(),1),wt=class extends yr.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}}});var It,kt,Rr,br=C(()=>{"use strict";It=O(B(),1),kt=class extends It.PipelineLayout{device;handle;constructor(e,t){super(e,t),this.device=e;let n=this.mapShaderLayoutToBindGroupEntries();this.handle=this.device.handle.createPipelineLayout({label:t?.id??"unnamed-pipeline-layout",bindGroupLayouts:[this.device.handle.createBindGroupLayout({label:"bind-group-layout",entries:n})]})}destroy(){this.handle=null}mapShaderLayoutToBindGroupEntries(){let e=[];for(let t=0;t<this.props.shaderLayout.bindings.length;t++){let n=this.props.shaderLayout.bindings[t],r={};switch(n.type){case"uniform":{r.buffer={type:"uniform",hasDynamicOffset:n.hasDynamicOffset,minBindingSize:n.minBindingSize};break}case"read-only-storage":{r.buffer={type:"read-only-storage",hasDynamicOffset:n.hasDynamicOffset,minBindingSize:n.minBindingSize};break}case"sampler":{r.sampler={type:n.samplerType};break}case"storage":{Rr(n)?r.storageTexture={format:n.format,access:n.access,viewDimension:n.viewDimension}:r.buffer={type:"storage",hasDynamicOffset:n.hasDynamicOffset,minBindingSize:n.minBindingSize};break}case"texture":{r.texture={multisampled:n.multisampled,sampleType:n.sampleType,viewDimension:n.viewDimension};break}default:It.log.warn("unhandled binding type when creating pipeline descriptor")()}let s=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE;e.push({binding:n.location,visibility:n.visibility||s,...r})}return e}},Rr=u=>u.format!==void 0});var vr,Ce,un=C(()=>{"use strict";vr=O(B(),1),Ce=class extends vr.Fence{device;handle=null;signaled;_signaled=!1;constructor(e,t={}){super(e,{}),this.device=e,this.signaled=e.handle.queue.onSubmittedWorkDone().then(()=>{this._signaled=!0})}isSignaled(){return this._signaled}destroy(){}}});function Hr(u){Ir[0]=u;let e=zr[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return U[0]=t<<15|31744|(r!==0?512:0),U[0];if(n===0){if(r===0)return U[0]=t<<15,U[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),U[0]=t<<15|n<<10|r>>13,U[0]):(U[0]=t<<15,U[0])}return n=n-127+15,n>=31?(U[0]=t<<15|31744,U[0]):n<=0?n<-10?(U[0]=t<<15,U[0]):(r=(8388608|r)>>1-n,U[0]=t<<15|r>>13,U[0]):(r>>=13,U[0]=t<<15|n<<10|r,U[0])}function wr(u){let e=112+(u>>6&31)<<23|(63&u)<<17;return Cn[0]=e,Sr[0]}function Qr(u,e,t,n,r,s,a,i,o){let c=n*(a>>=r)*(s>>=r)+t*a+e*i;switch(o){case"r8unorm":return[L(u,c,"8unorm",1)[0]];case"r8snorm":return[L(u,c,"8snorm",1)[0]];case"r8uint":return[L(u,c,"8uint",1)[0]];case"r8sint":return[L(u,c,"8sint",1)[0]];case"rg8unorm":{let l=L(u,c,"8unorm",2);return[l[0],l[1]]}case"rg8snorm":{let l=L(u,c,"8snorm",2);return[l[0],l[1]]}case"rg8uint":{let l=L(u,c,"8uint",2);return[l[0],l[1]]}case"rg8sint":{let l=L(u,c,"8sint",2);return[l[0],l[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let l=L(u,c,"8unorm",4);return[l[0],l[1],l[2],l[3]]}case"rgba8snorm":{let l=L(u,c,"8snorm",4);return[l[0],l[1],l[2],l[3]]}case"rgba8uint":{let l=L(u,c,"8uint",4);return[l[0],l[1],l[2],l[3]]}case"rgba8sint":{let l=L(u,c,"8sint",4);return[l[0],l[1],l[2],l[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let l=L(u,c,"8unorm",4);return[l[2],l[1],l[0],l[3]]}case"r16uint":return[L(u,c,"16uint",1)[0]];case"r16sint":return[L(u,c,"16sint",1)[0]];case"r16float":return[L(u,c,"16float",1)[0]];case"rg16uint":{let l=L(u,c,"16uint",2);return[l[0],l[1]]}case"rg16sint":{let l=L(u,c,"16sint",2);return[l[0],l[1]]}case"rg16float":{let l=L(u,c,"16float",2);return[l[0],l[1]]}case"rgba16uint":{let l=L(u,c,"16uint",4);return[l[0],l[1],l[2],l[3]]}case"rgba16sint":{let l=L(u,c,"16sint",4);return[l[0],l[1],l[2],l[3]]}case"rgba16float":{let l=L(u,c,"16float",4);return[l[0],l[1],l[2],l[3]]}case"r32uint":return[L(u,c,"32uint",1)[0]];case"r32sint":return[L(u,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[L(u,c,"32float",1)[0]];case"rg32uint":{let l=L(u,c,"32uint",2);return[l[0],l[1]]}case"rg32sint":{let l=L(u,c,"32sint",2);return[l[0],l[1]]}case"rg32float":{let l=L(u,c,"32float",2);return[l[0],l[1]]}case"rgba32uint":{let l=L(u,c,"32uint",4);return[l[0],l[1],l[2],l[3]]}case"rgba32sint":{let l=L(u,c,"32sint",4);return[l[0],l[1],l[2],l[3]]}case"rgba32float":{let l=L(u,c,"32float",4);return[l[0],l[1],l[2],l[3]]}case"rg11b10ufloat":{let l=new Uint32Array(u.buffer,c,1)[0],f=(4192256&l)>>11,_=(4290772992&l)>>22;return[wr(2047&l),wr(f),function(v){let k=112+(v>>5&31)<<23|(31&v)<<18;return Cn[0]=k,Sr[0]}(_),1]}}return null}function L(u,e,t,n){let r=[0,0,0,0];for(let c=0;c<n;++c)switch(t){case"8unorm":r[c]=u[e]/255,e++;break;case"8snorm":r[c]=u[e]/255*2-1,e++;break;case"8uint":r[c]=u[e],e++;break;case"8sint":r[c]=u[e]-127,e++;break;case"16uint":r[c]=u[e]|u[e+1]<<8,e+=2;break;case"16sint":r[c]=(u[e]|u[e+1]<<8)-32768,e+=2;break;case"16float":r[c]=(s=u[e]|u[e+1]<<8,a=void 0,i=void 0,o=void 0,a=(32768&s)>>15,o=1023&s,(i=(31744&s)>>10)==0?(a?-1:1)*Math.pow(2,-14)*(o/Math.pow(2,10)):i==31?o?NaN:1/0*(a?-1:1):(a?-1:1)*Math.pow(2,i-15)*(1+o/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":r[c]=u[e]|u[e+1]<<8|u[e+2]<<16|u[e+3]<<24,e+=4;break;case"32float":r[c]=new Float32Array(u.buffer,e,1)[0],e+=4}var s,a,i,o;return r}function $(u,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":u[e]=255*r[s],e++;break;case"8snorm":u[e]=.5*(r[s]+1)*255,e++;break;case"8uint":u[e]=r[s],e++;break;case"8sint":u[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(u.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(u.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{let a=Hr(r[s]);new Uint16Array(u.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(u.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(u.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(u.buffer,e,1)[0]=r[s],e+=4}return r}function Xr(u,e,t){let n=e.length;return n===2?t==="f32"?new p(new Float32Array(e),u.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new p(new Int32Array(e),u.getTypeInfo("vec2i")):t==="u32"?new p(new Uint32Array(e),u.getTypeInfo("vec2u")):t==="f16"?new p(new Float32Array(e),u.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new p(new Float32Array(e),u.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new p(new Int32Array(e),u.getTypeInfo("vec3i")):t==="u32"?new p(new Uint32Array(e),u.getTypeInfo("vec3u")):t==="f16"?new p(new Float32Array(e),u.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new p(new Float32Array(e),u.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new p(new Int32Array(e),u.getTypeInfo("vec4i")):t==="u32"?new p(new Uint32Array(e),u.getTypeInfo("vec4u")):t==="f16"?new p(new Float32Array(e),u.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}function w(u){return Array.isArray(u)||u?.buffer instanceof ArrayBuffer}function kr(u,e,t){if(e===t)return u;if(e==="f32"){if(t==="i32"||t==="x32")return jt[0]=u,jr[0];if(t==="u32")return jt[0]=u,Yr[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return Yt[0]=u,Zr[0];if(t==="u32")return Yt[0]=u,Jr[0]}else if(e==="u32"){if(t==="f32")return Zt[0]=u,Kr[0];if(t==="i32"||t==="x32")return Zt[0]=u,es[0]}return console.error(`Unsupported cast from ${e} to ${t}`),u}var R,St,le,ce,Re,he,oe,$e,pn,dn,Tt,mn,gn,xn,yn,Ir,zr,U,Cn,Sr,hn,z,Fe,Ne,Tr,D,ve,_n,Et,ze,At,se,He,_e,Oe,Be,qe,y,g,Lt,Ct,Qe,$t,Bt,Dt,Ot,bn,vn,Pt,Xe,wn,Vt,Ft,b,Nt,ne,x,Pe,be,ye,j,fe,J,je,q,Mt,N,Wt,me,Ut,F,X,Gt,Ve,qt,Rt,zt,kn,Ht,Qt,H,Ye,de,d,p,I,P,re,m,h,Xt,In,jt,jr,Yr,Yt,Zr,Jr,Zt,Kr,es,Sn,De,K,$n,Ze,Je,Ke,Tn,En,fn,G,M,An,Ln,Jt,Er=C(()=>{R=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}get isPointer(){return!1}getTypeName(){return this.name}},St=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},le=class extends R{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},ce=class extends R{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}},Re=class extends R{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},he=class extends R{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};(u=>{u[u.Uniform=0]="Uniform",u[u.Storage=1]="Storage",u[u.Texture=2]="Texture",u[u.Sampler=3]="Sampler",u[u.StorageTexture=4]="StorageTexture"})(oe||(oe={}));$e=class{constructor(e,t,n,r,s,a,i){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=a,this.access=i}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},pn=class{constructor(e,t){this.name=e,this.type=t}},dn=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},Tt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},mn=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},gn=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},xn=class{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n}},yn=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Ir=new Float32Array(1),zr=new Int32Array(Ir.buffer),U=new Uint16Array(1);Cn=new Uint32Array(1),Sr=new Float32Array(Cn.buffer,0,1);hn={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},z=class{constructor(){this.id=z._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Fe.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Ne.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};z._id=0;Fe=class extends z{};Fe.instance=new Fe;Ne=class extends z{};Ne.instance=new Ne;Tr=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),D=class extends z{constructor(){super()}},ve=class extends D{constructor(e,t,n,r,s,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(let t of this.attributes)e(t);e(this);for(let t of this.args)e(t);this.searchBlock(this.body,e)}},_n=class extends D{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},Et=class extends D{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},ze=class extends D{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},At=class extends D{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}},se=class extends D{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},He=class extends D{constructor(e,t,n){super(),this.attributes=null,this.name=e,this.type=t,this.value=n}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},_e=class extends D{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Oe=class extends D{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}};(u=>{u.increment="++",u.decrement="--"})(Be||(Be={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return u[t]}})(Be||(Be={}));Lt=class extends D{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(u=>{u.assign="=",u.addAssign="+=",u.subtractAssin="-=",u.multiplyAssign="*=",u.divideAssign="/=",u.moduloAssign="%=",u.andAssign="&=",u.orAssign="|=",u.xorAssign="^=",u.shiftLeftAssign="<<=",u.shiftRightAssign=">>="})(qe||(qe={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(qe||(qe={}));Ct=class extends D{constructor(e,t,n){super(),this.operator=e,this.variable=t,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Qe=class extends D{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Tr.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},$t=class extends D{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},Bt=class extends D{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}search(e){e(this);for(let t of this.cases)t.search(e)}},Dt=class extends D{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},Ot=class extends D{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},bn=class extends D{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},vn=class extends D{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},Pt=class extends D{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},Xe=class extends D{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},wn=class extends D{constructor(){super()}get astNodeType(){return"discard"}},Vt=class extends D{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},Ft=class extends D{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},b=class extends D{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=b._priority.get(t.name);b._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?b.i32:t}getTypeName(){return this.name}};b.x32=new b("x32"),b.f32=new b("f32"),b.i32=new b("i32"),b.u32=new b("u32"),b.f16=new b("f16"),b.bool=new b("bool"),b.void=new b("void"),b._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);Nt=class extends b{constructor(e){super(e)}},ne=class extends b{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(let t of this.members)e(t)}},x=class extends b{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};x.vec2f=new x("vec2",b.f32,null),x.vec3f=new x("vec3",b.f32,null),x.vec4f=new x("vec4",b.f32,null),x.vec2i=new x("vec2",b.i32,null),x.vec3i=new x("vec3",b.i32,null),x.vec4i=new x("vec4",b.i32,null),x.vec2u=new x("vec2",b.u32,null),x.vec3u=new x("vec3",b.u32,null),x.vec4u=new x("vec4",b.u32,null),x.vec2h=new x("vec2",b.f16,null),x.vec3h=new x("vec3",b.f16,null),x.vec4h=new x("vec4",b.f16,null),x.vec2b=new x("vec2",b.bool,null),x.vec3b=new x("vec3",b.bool,null),x.vec4b=new x("vec4",b.bool,null),x.mat2x2f=new x("mat2x2",b.f32,null),x.mat2x3f=new x("mat2x3",b.f32,null),x.mat2x4f=new x("mat2x4",b.f32,null),x.mat3x2f=new x("mat3x2",b.f32,null),x.mat3x3f=new x("mat3x3",b.f32,null),x.mat3x4f=new x("mat3x4",b.f32,null),x.mat4x2f=new x("mat4x2",b.f32,null),x.mat4x3f=new x("mat4x3",b.f32,null),x.mat4x4f=new x("mat4x4",b.f32,null),x.mat2x2h=new x("mat2x2",b.f16,null),x.mat2x3h=new x("mat2x3",b.f16,null),x.mat2x4h=new x("mat2x4",b.f16,null),x.mat3x2h=new x("mat3x2",b.f16,null),x.mat3x3h=new x("mat3x3",b.f16,null),x.mat3x4h=new x("mat3x4",b.f16,null),x.mat4x2h=new x("mat4x2",b.f16,null),x.mat4x3h=new x("mat4x3",b.f16,null),x.mat4x4h=new x("mat4x4",b.f16,null),x.mat2x2i=new x("mat2x2",b.i32,null),x.mat2x3i=new x("mat2x3",b.i32,null),x.mat2x4i=new x("mat2x4",b.i32,null),x.mat3x2i=new x("mat3x2",b.i32,null),x.mat3x3i=new x("mat3x3",b.i32,null),x.mat3x4i=new x("mat3x4",b.i32,null),x.mat4x2i=new x("mat4x2",b.i32,null),x.mat4x3i=new x("mat4x3",b.i32,null),x.mat4x4i=new x("mat4x4",b.i32,null),x.mat2x2u=new x("mat2x2",b.u32,null),x.mat2x3u=new x("mat2x3",b.u32,null),x.mat2x4u=new x("mat2x4",b.u32,null),x.mat3x2u=new x("mat3x2",b.u32,null),x.mat3x3u=new x("mat3x3",b.u32,null),x.mat3x4u=new x("mat3x4",b.u32,null),x.mat4x2u=new x("mat4x2",b.u32,null),x.mat4x3u=new x("mat4x3",b.u32,null),x.mat4x4u=new x("mat4x4",b.u32,null);Pe=class extends b{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},be=class extends b{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},ye=class extends b{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},j=class extends z{constructor(){super(),this.postfix=null}},fe=class extends j{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},J=class extends j{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}},je=class extends j{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return Tr.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(let t of this.args)t.search(e);e(this)}},q=class extends j{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,t){return e.evalExpression(this,e.context)}},Mt=class extends j{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},N=class extends j{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof d}get isVector(){return this.value instanceof p||this.value instanceof I}get scalarValue(){return this.value instanceof d?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof p||this.value instanceof I?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},Wt=class extends j{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},me=class extends j{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ut=class extends j{constructor(){super()}},F=class extends Ut{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},X=class extends Ut{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?b.f32:e.name==="u32"||t.name==="u32"?b.u32:b.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Gt=class extends z{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}},Ve=class extends j{constructor(){super()}get astNodeType(){return"default"}},qt=class extends Gt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Rt=class extends Gt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},zt=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},kn=class extends z{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Ht=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},Qt=class extends z{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},H=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=H._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.getTypeName()}>`}};H._id=0;Ye=class extends H{constructor(){super(new R("void",null),null)}toString(){return"void"}};Ye.void=new Ye;de=class extends H{constructor(e){super(new Re("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}toString(){return`&${this.reference.toString()}`}},d=class extends H{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!=0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new d(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new d(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new d(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}};p=class extends H{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new p(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new p(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new p(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof fe?console.error("TODO: Set vector postfix"):t instanceof p?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof he)r=this.typeInfo.format||r;else{let a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?r=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?r=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?r=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?r=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof me){let a=t.index,i=-1;if(a instanceof N){if(!(a.value instanceof d))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value}else{let o=e.evalExpression(a,n);if(!(o instanceof d))return console.error("GetSubData: Unknown index type",a),null;i=o.value}if(i<0||i>=s.data.length)return console.error("GetSubData: Index out of range",i),null;if(s.data instanceof Float32Array){let o=new Float32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new d(o,r)}if(s.data instanceof Int32Array){let o=new Int32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new d(o,r)}if(s.data instanceof Uint32Array){let o=new Uint32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new d(o,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof fe))return console.error("GetSubData: Unknown postfix",t),null;{let a=t.value.toLowerCase();if(a.length===1){let o=0;if(a==="x"||a==="r")o=0;else if(a==="y"||a==="g")o=1;else if(a==="z"||a==="b")o=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;o=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new d(c,r,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new d(c,r,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new d(c,r,this)}}let i=[];for(let o of a)o==="x"||o==="r"?i.push(this.data[0]):o==="y"||o==="g"?i.push(this.data[1]):o==="z"||o==="b"?i.push(this.data[2]):o==="w"||o==="a"?i.push(this.data[3]):console.error(`GetDataValue: Unknown member ${o}`);s=Xr(e,i,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},I=class extends H{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new I(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof fe?console.error("TODO: Set matrix postfix"):t instanceof I?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof he)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof me){let s=t.index,a=-1;if(s instanceof N){if(!(s.value instanceof d))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;a=s.value.value}else{let c=e.evalExpression(s,n);if(!(c instanceof d))return console.error("GetDataValue: Unknown index type",s),null;a=c.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;let i=r.endsWith("h")?"h":"f",o;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")o=new p(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${i}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")o=new p(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${i}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;o=new p(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${i}`))}return t.postfix?o.getSubData(e,t.postfix,n):o}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},P=class extends H{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new P(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,a=this.typeInfo;for(;n;){if(n instanceof me)if(a instanceof ce){let i=n.index;if(i instanceof N){if(!(i.value instanceof d))return void console.error(`SetDataValue: Invalid index type ${i.value}`);s+=i.value.value*a.stride}else{let o=e.evalExpression(i,r);if(!(o instanceof d))return void console.error("SetDataValue: Unknown index type",i);s+=o.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof fe))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(a instanceof le){let o=!1;for(let c of a.members)if(c.name===i){s+=c.offset,a=c.type,o=!0;break}if(!o)return void console.error(`SetDataValue: Member ${i} not found`)}else if(a instanceof R){let o=a.getTypeName(),c=0;if(i==="x"||i==="r")c=0;else if(i==="y"||i==="g")c=1;else if(i==="z"||i==="b")c=2;else{if(i!=="w"&&i!=="a")return void console.error(`SetDataValue: Unknown member ${i}`);c=3}if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let l=t.value;return o==="vec2f"?void(new Float32Array(this.buffer,s,2)[c]=l):o==="vec3f"?void(new Float32Array(this.buffer,s,3)[c]=l):o==="vec4f"?void(new Float32Array(this.buffer,s,4)[c]=l):o==="vec2i"?void(new Int32Array(this.buffer,s,2)[c]=l):o==="vec3i"?void(new Int32Array(this.buffer,s,3)[c]=l):o==="vec4i"?void(new Int32Array(this.buffer,s,4)[c]=l):o==="vec2u"?void(new Uint32Array(this.buffer,s,2)[c]=l):o==="vec3u"?void(new Uint32Array(this.buffer,s,3)[c]=l):o==="vec4u"?void(new Uint32Array(this.buffer,s,4)[c]=l):void console.error(`SetDataValue: Type ${o} is not a struct`)}}}n=n.postfix}this.setData(e,t,a,s,r)}setData(e,t,n,r,s){let a=n.getTypeName();if(a!=="f32"&&a!=="f16")if(a!=="i32"&&a!=="atomic<i32>"&&a!=="x32")if(a!=="u32"&&a!=="atomic<u32>")if(a!=="bool")if(a!=="vec2f"&&a!=="vec2h")if(a!=="vec3f"&&a!=="vec3h")if(a!=="vec4f"&&a!=="vec4h")if(a!=="vec2i")if(a!=="vec3i")if(a!=="vec4i")if(a!=="vec2u")if(a!=="vec3u")if(a!=="vec4u")if(a!=="vec2b")if(a!=="vec3b")if(a!=="vec4b")if(a!=="mat2x2f"&&a!=="mat2x2h")if(a!=="mat2x3f"&&a!=="mat2x3h")if(a!=="mat2x4f"&&a!=="mat2x4h")if(a!=="mat3x2f"&&a!=="mat3x2h")if(a!=="mat3x3f"&&a!=="mat3x3h")if(a!=="mat3x4f"&&a!=="mat3x4h")if(a!=="mat4x2f"&&a!=="mat4x2h")if(a!=="mat4x3f"&&a!=="mat4x3h")if(a!=="mat4x4f"&&a!=="mat4x4h")if(t instanceof P){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",a,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${a}`);else{let i=new Float32Array(this.buffer,r,16);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7],i[8]=t.data[8],i[9]=t.data[9],i[10]=t.data[10],i[11]=t.data[11],i[12]=t.data[12],i[13]=t.data[13],i[14]=t.data[14],i[15]=t.data[15]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15])}else{let i=new Float32Array(this.buffer,r,12);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7],i[8]=t.data[8],i[9]=t.data[9],i[10]=t.data[10],i[11]=t.data[11]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11])}else{let i=new Float32Array(this.buffer,r,8);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7])}else{let i=new Float32Array(this.buffer,r,12);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7],i[8]=t.data[8],i[9]=t.data[9],i[10]=t.data[10],i[11]=t.data[11]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11])}else{let i=new Float32Array(this.buffer,r,9);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7],i[8]=t.data[8]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8])}else{let i=new Float32Array(this.buffer,r,6);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5])}else{let i=new Float32Array(this.buffer,r,8);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5],i[6]=t.data[6],i[7]=t.data[7]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7])}else{let i=new Float32Array(this.buffer,r,6);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3],i[4]=t.data[4],i[5]=t.data[5]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5])}else{let i=new Float32Array(this.buffer,r,4);t instanceof I?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3])}else{let i=new Uint32Array(this.buffer,r,4);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3])}else{let i=new Uint32Array(this.buffer,r,3);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2]):(i[0]=t[0],i[1]=t[1],i[2]=t[2])}else{let i=new Uint32Array(this.buffer,r,2);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1])}else{let i=new Uint32Array(this.buffer,r,4);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3])}else{let i=new Uint32Array(this.buffer,r,3);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2]):(i[0]=t[0],i[1]=t[1],i[2]=t[2])}else{let i=new Uint32Array(this.buffer,r,2);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1])}else{let i=new Int32Array(this.buffer,r,4);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3])}else{let i=new Int32Array(this.buffer,r,3);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2]):(i[0]=t[0],i[1]=t[1],i[2]=t[2])}else{let i=new Int32Array(this.buffer,r,2);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1])}else{let i=new Float32Array(this.buffer,r,4);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2],i[3]=t.data[3]):(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3])}else{let i=new Float32Array(this.buffer,r,3);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1],i[2]=t.data[2]):(i[0]=t[0],i[1]=t[1],i[2]=t[2])}else{let i=new Float32Array(this.buffer,r,2);t instanceof p?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1])}else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,s,a;if(t===null)return this;let i=this.offset,o=this.typeInfo;for(;t;){if(t instanceof me){let l=t.index,f=l instanceof j?e.evalExpression(l,n):l,_=0;if(f instanceof d?_=f.value:typeof f=="number"?_=f:console.error("GetDataValue: Invalid index type",l),o instanceof ce)i+=_*o.stride,o=o.format;else{let v=o.getTypeName();v==="mat4x4"||v==="mat4x4f"||v==="mat4x4h"?(i+=16*_,o=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${o.getTypeName()} is not an array`)}}else{if(!(t instanceof fe))return console.error("GetDataValue: Unknown postfix type",t),null;{let l=t.value;if(o instanceof le){let f=!1;for(let _ of o.members)if(_.name===l){i+=_.offset,o=_.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${l} not found`),null}else if(o instanceof R){let f=o.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(l.length>0&&l.length<5){let _="f",v=[];for(let k=0;k<l.length;++k){let A=l[k].toLowerCase(),E=0;if(A==="x"||A==="r")E=0;else if(A==="y"||A==="g")E=1;else if(A==="z"||A==="b")E=2;else{if(A!=="w"&&A!=="a")return console.error(`Unknown member ${l}`),null;E=3}if(l.length===1){if(f.endsWith("f"))return this.buffer.byteLength<i+4*E+4?(console.log("Insufficient buffer data"),null):new d(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new d(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new d(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new d(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new d(new Uint32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")v.push(new Float32Array(this.buffer,i,2)[E]);else if(f==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let V=new Float32Array(this.buffer,i,3);v.push(V[E])}else if(f==="vec4f")v.push(new Float32Array(this.buffer,i,4)[E]);else if(f==="vec2i")_="i",v.push(new Int32Array(this.buffer,i,2)[E]);else if(f==="vec3i")_="i",v.push(new Int32Array(this.buffer,i,3)[E]);else if(f==="vec4i")_="i",v.push(new Int32Array(this.buffer,i,4)[E]);else if(f==="vec2u"){_="u";let V=new Uint32Array(this.buffer,i,2);v.push(V[E])}else f==="vec3u"?(_="u",v.push(new Uint32Array(this.buffer,i,3)[E])):f==="vec4u"&&(_="u",v.push(new Uint32Array(this.buffer,i,4)[E]))}return v.length===2?o=e.getTypeInfo(`vec2${_}`):v.length===3?o=e.getTypeInfo(`vec3${_}`):v.length===4?o=e.getTypeInfo(`vec4${_}`):console.error(`GetDataValue: Invalid vector length ${v.length}`),new p(v,o,null)}return console.error(`GetDataValue: Unknown member ${l}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}let c=o.getTypeName();return c==="f32"?new d(new Float32Array(this.buffer,i,1),o,this):c==="i32"?new d(new Int32Array(this.buffer,i,1),o,this):c==="u32"?new d(new Uint32Array(this.buffer,i,1),o,this):c==="vec2f"?new p(new Float32Array(this.buffer,i,2),o,this):c==="vec3f"?new p(new Float32Array(this.buffer,i,3),o,this):c==="vec4f"?new p(new Float32Array(this.buffer,i,4),o,this):c==="vec2i"?new p(new Int32Array(this.buffer,i,2),o,this):c==="vec3i"?new p(new Int32Array(this.buffer,i,3),o,this):c==="vec4i"?new p(new Int32Array(this.buffer,i,4),o,this):c==="vec2u"?new p(new Uint32Array(this.buffer,i,2),o,this):c==="vec3u"?new p(new Uint32Array(this.buffer,i,3),o,this):c==="vec4u"?new p(new Uint32Array(this.buffer,i,4),o,this):o instanceof he&&o.name==="atomic"?((r=o.format)===null||r===void 0?void 0:r.name)==="u32"?new d(new Uint32Array(this.buffer,i,1)[0],o.format,this):((s=o.format)===null||s===void 0?void 0:s.name)==="i32"?new d(new Int32Array(this.buffer,i,1)[0],o.format,this):(console.error(`GetDataValue: Invalid atomic format ${(a=o.format)===null||a===void 0?void 0:a.name}`),null):new P(this.buffer,o,i,this)}toString(){let e="";if(this.typeInfo instanceof ce)if(this.typeInfo.format.name==="f32"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){let t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){let t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof le?e+="{...}":e="[...]";return e}},re=class extends H{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new re(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){let e=this.format,t=hn[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=hn[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=hn[e],n=this.width;if(!e||n<=0||!t)return-1;let r=this.height,s=this.depthOrArrayLayers,a=this.dimension;return n/t.blockWidth*(a==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,a=this.bytesPerRow,i=this.height,o=this.data[r];return Qr(new Uint8Array(o),e,t,n,r,i,a,s,this.format)}setPixel(e,t,n,r,s){let a=this.texelByteSize,i=this.bytesPerRow,o=this.height,c=this.data[r];(function(l,f,_,v,k,A,E,V,W,S){let T=v*(E>>=k)*(A>>=k)+_*E+f*V;switch(W){case"r8unorm":return void $(l,T,"8unorm",1,S);case"r8snorm":return void $(l,T,"8snorm",1,S);case"r8uint":return void $(l,T,"8uint",1,S);case"r8sint":return void $(l,T,"8sint",1,S);case"rg8unorm":return void $(l,T,"8unorm",2,S);case"rg8snorm":return void $(l,T,"8snorm",2,S);case"rg8uint":return void $(l,T,"8uint",2,S);case"rg8sint":return void $(l,T,"8sint",2,S);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void $(l,T,"8unorm",4,S);case"rgba8snorm":return void $(l,T,"8snorm",4,S);case"rgba8uint":return void $(l,T,"8uint",4,S);case"rgba8sint":return void $(l,T,"8sint",4,S);case"r16uint":return void $(l,T,"16uint",1,S);case"r16sint":return void $(l,T,"16sint",1,S);case"r16float":return void $(l,T,"16float",1,S);case"rg16uint":return void $(l,T,"16uint",2,S);case"rg16sint":return void $(l,T,"16sint",2,S);case"rg16float":return void $(l,T,"16float",2,S);case"rgba16uint":return void $(l,T,"16uint",4,S);case"rgba16sint":return void $(l,T,"16sint",4,S);case"rgba16float":return void $(l,T,"16float",4,S);case"r32uint":return void $(l,T,"32uint",1,S);case"r32sint":return void $(l,T,"32sint",1,S);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void $(l,T,"32float",1,S);case"rg32uint":return void $(l,T,"32uint",2,S);case"rg32sint":return void $(l,T,"32sint",2,S);case"rg32float":return void $(l,T,"32float",2,S);case"rgba32uint":return void $(l,T,"32uint",4,S);case"rgba32sint":return void $(l,T,"32sint",4,S);case"rgba32float":return void $(l,T,"32float",4,S);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,n,r,o,i,a,this.format,s)}};(u=>{u[u.token=0]="token",u[u.keyword=1]="keyword",u[u.reserved=2]="reserved"})(g||(g={}));m=class{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}},h=class{};y=h,h.none=new m("",g.reserved,""),h.eof=new m("EOF",g.token,""),h.reserved={asm:new m("asm",g.reserved,"asm"),bf16:new m("bf16",g.reserved,"bf16"),do:new m("do",g.reserved,"do"),enum:new m("enum",g.reserved,"enum"),f16:new m("f16",g.reserved,"f16"),f64:new m("f64",g.reserved,"f64"),handle:new m("handle",g.reserved,"handle"),i8:new m("i8",g.reserved,"i8"),i16:new m("i16",g.reserved,"i16"),i64:new m("i64",g.reserved,"i64"),mat:new m("mat",g.reserved,"mat"),premerge:new m("premerge",g.reserved,"premerge"),regardless:new m("regardless",g.reserved,"regardless"),typedef:new m("typedef",g.reserved,"typedef"),u8:new m("u8",g.reserved,"u8"),u16:new m("u16",g.reserved,"u16"),u64:new m("u64",g.reserved,"u64"),unless:new m("unless",g.reserved,"unless"),using:new m("using",g.reserved,"using"),vec:new m("vec",g.reserved,"vec"),void:new m("void",g.reserved,"void")},h.keywords={array:new m("array",g.keyword,"array"),atomic:new m("atomic",g.keyword,"atomic"),bool:new m("bool",g.keyword,"bool"),f32:new m("f32",g.keyword,"f32"),i32:new m("i32",g.keyword,"i32"),mat2x2:new m("mat2x2",g.keyword,"mat2x2"),mat2x3:new m("mat2x3",g.keyword,"mat2x3"),mat2x4:new m("mat2x4",g.keyword,"mat2x4"),mat3x2:new m("mat3x2",g.keyword,"mat3x2"),mat3x3:new m("mat3x3",g.keyword,"mat3x3"),mat3x4:new m("mat3x4",g.keyword,"mat3x4"),mat4x2:new m("mat4x2",g.keyword,"mat4x2"),mat4x3:new m("mat4x3",g.keyword,"mat4x3"),mat4x4:new m("mat4x4",g.keyword,"mat4x4"),ptr:new m("ptr",g.keyword,"ptr"),sampler:new m("sampler",g.keyword,"sampler"),sampler_comparison:new m("sampler_comparison",g.keyword,"sampler_comparison"),struct:new m("struct",g.keyword,"struct"),texture_1d:new m("texture_1d",g.keyword,"texture_1d"),texture_2d:new m("texture_2d",g.keyword,"texture_2d"),texture_2d_array:new m("texture_2d_array",g.keyword,"texture_2d_array"),texture_3d:new m("texture_3d",g.keyword,"texture_3d"),texture_cube:new m("texture_cube",g.keyword,"texture_cube"),texture_cube_array:new m("texture_cube_array",g.keyword,"texture_cube_array"),texture_multisampled_2d:new m("texture_multisampled_2d",g.keyword,"texture_multisampled_2d"),texture_storage_1d:new m("texture_storage_1d",g.keyword,"texture_storage_1d"),texture_storage_2d:new m("texture_storage_2d",g.keyword,"texture_storage_2d"),texture_storage_2d_array:new m("texture_storage_2d_array",g.keyword,"texture_storage_2d_array"),texture_storage_3d:new m("texture_storage_3d",g.keyword,"texture_storage_3d"),texture_depth_2d:new m("texture_depth_2d",g.keyword,"texture_depth_2d"),texture_depth_2d_array:new m("texture_depth_2d_array",g.keyword,"texture_depth_2d_array"),texture_depth_cube:new m("texture_depth_cube",g.keyword,"texture_depth_cube"),texture_depth_cube_array:new m("texture_depth_cube_array",g.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new m("texture_depth_multisampled_2d",g.keyword,"texture_depth_multisampled_2d"),texture_external:new m("texture_external",g.keyword,"texture_external"),u32:new m("u32",g.keyword,"u32"),vec2:new m("vec2",g.keyword,"vec2"),vec3:new m("vec3",g.keyword,"vec3"),vec4:new m("vec4",g.keyword,"vec4"),bitcast:new m("bitcast",g.keyword,"bitcast"),block:new m("block",g.keyword,"block"),break:new m("break",g.keyword,"break"),case:new m("case",g.keyword,"case"),continue:new m("continue",g.keyword,"continue"),continuing:new m("continuing",g.keyword,"continuing"),default:new m("default",g.keyword,"default"),diagnostic:new m("diagnostic",g.keyword,"diagnostic"),discard:new m("discard",g.keyword,"discard"),else:new m("else",g.keyword,"else"),enable:new m("enable",g.keyword,"enable"),fallthrough:new m("fallthrough",g.keyword,"fallthrough"),false:new m("false",g.keyword,"false"),fn:new m("fn",g.keyword,"fn"),for:new m("for",g.keyword,"for"),function:new m("function",g.keyword,"function"),if:new m("if",g.keyword,"if"),let:new m("let",g.keyword,"let"),const:new m("const",g.keyword,"const"),loop:new m("loop",g.keyword,"loop"),while:new m("while",g.keyword,"while"),private:new m("private",g.keyword,"private"),read:new m("read",g.keyword,"read"),read_write:new m("read_write",g.keyword,"read_write"),return:new m("return",g.keyword,"return"),requires:new m("requires",g.keyword,"requires"),storage:new m("storage",g.keyword,"storage"),switch:new m("switch",g.keyword,"switch"),true:new m("true",g.keyword,"true"),alias:new m("alias",g.keyword,"alias"),type:new m("type",g.keyword,"type"),uniform:new m("uniform",g.keyword,"uniform"),var:new m("var",g.keyword,"var"),override:new m("override",g.keyword,"override"),workgroup:new m("workgroup",g.keyword,"workgroup"),write:new m("write",g.keyword,"write"),r8unorm:new m("r8unorm",g.keyword,"r8unorm"),r8snorm:new m("r8snorm",g.keyword,"r8snorm"),r8uint:new m("r8uint",g.keyword,"r8uint"),r8sint:new m("r8sint",g.keyword,"r8sint"),r16uint:new m("r16uint",g.keyword,"r16uint"),r16sint:new m("r16sint",g.keyword,"r16sint"),r16float:new m("r16float",g.keyword,"r16float"),rg8unorm:new m("rg8unorm",g.keyword,"rg8unorm"),rg8snorm:new m("rg8snorm",g.keyword,"rg8snorm"),rg8uint:new m("rg8uint",g.keyword,"rg8uint"),rg8sint:new m("rg8sint",g.keyword,"rg8sint"),r32uint:new m("r32uint",g.keyword,"r32uint"),r32sint:new m("r32sint",g.keyword,"r32sint"),r32float:new m("r32float",g.keyword,"r32float"),rg16uint:new m("rg16uint",g.keyword,"rg16uint"),rg16sint:new m("rg16sint",g.keyword,"rg16sint"),rg16float:new m("rg16float",g.keyword,"rg16float"),rgba8unorm:new m("rgba8unorm",g.keyword,"rgba8unorm"),rgba8unorm_srgb:new m("rgba8unorm_srgb",g.keyword,"rgba8unorm_srgb"),rgba8snorm:new m("rgba8snorm",g.keyword,"rgba8snorm"),rgba8uint:new m("rgba8uint",g.keyword,"rgba8uint"),rgba8sint:new m("rgba8sint",g.keyword,"rgba8sint"),bgra8unorm:new m("bgra8unorm",g.keyword,"bgra8unorm"),bgra8unorm_srgb:new m("bgra8unorm_srgb",g.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new m("rgb10a2unorm",g.keyword,"rgb10a2unorm"),rg11b10float:new m("rg11b10float",g.keyword,"rg11b10float"),rg32uint:new m("rg32uint",g.keyword,"rg32uint"),rg32sint:new m("rg32sint",g.keyword,"rg32sint"),rg32float:new m("rg32float",g.keyword,"rg32float"),rgba16uint:new m("rgba16uint",g.keyword,"rgba16uint"),rgba16sint:new m("rgba16sint",g.keyword,"rgba16sint"),rgba16float:new m("rgba16float",g.keyword,"rgba16float"),rgba32uint:new m("rgba32uint",g.keyword,"rgba32uint"),rgba32sint:new m("rgba32sint",g.keyword,"rgba32sint"),rgba32float:new m("rgba32float",g.keyword,"rgba32float"),static_assert:new m("static_assert",g.keyword,"static_assert")},h.tokens={decimal_float_literal:new m("decimal_float_literal",g.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new m("hex_float_literal",g.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new m("int_literal",g.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new m("uint_literal",g.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new m("name",g.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new m("ident",g.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new m("and",g.token,"&"),and_and:new m("and_and",g.token,"&&"),arrow:new m("arrow ",g.token,"->"),attr:new m("attr",g.token,"@"),forward_slash:new m("forward_slash",g.token,"/"),bang:new m("bang",g.token,"!"),bracket_left:new m("bracket_left",g.token,"["),bracket_right:new m("bracket_right",g.token,"]"),brace_left:new m("brace_left",g.token,"{"),brace_right:new m("brace_right",g.token,"}"),colon:new m("colon",g.token,":"),comma:new m("comma",g.token,","),equal:new m("equal",g.token,"="),equal_equal:new m("equal_equal",g.token,"=="),not_equal:new m("not_equal",g.token,"!="),greater_than:new m("greater_than",g.token,">"),greater_than_equal:new m("greater_than_equal",g.token,">="),shift_right:new m("shift_right",g.token,">>"),less_than:new m("less_than",g.token,"<"),less_than_equal:new m("less_than_equal",g.token,"<="),shift_left:new m("shift_left",g.token,"<<"),modulo:new m("modulo",g.token,"%"),minus:new m("minus",g.token,"-"),minus_minus:new m("minus_minus",g.token,"--"),period:new m("period",g.token,"."),plus:new m("plus",g.token,"+"),plus_plus:new m("plus_plus",g.token,"++"),or:new m("or",g.token,"|"),or_or:new m("or_or",g.token,"||"),paren_left:new m("paren_left",g.token,"("),paren_right:new m("paren_right",g.token,")"),semicolon:new m("semicolon",g.token,";"),star:new m("star",g.token,"*"),tilde:new m("tilde",g.token,"~"),underscore:new m("underscore",g.token,"_"),xor:new m("xor",g.token,"^"),plus_equal:new m("plus_equal",g.token,"+="),minus_equal:new m("minus_equal",g.token,"-="),times_equal:new m("times_equal",g.token,"*="),division_equal:new m("division_equal",g.token,"/="),modulo_equal:new m("modulo_equal",g.token,"%="),and_equal:new m("and_equal",g.token,"&="),or_equal:new m("or_equal",g.token,"|="),xor_equal:new m("xor_equal",g.token,"^="),shift_right_equal:new m("shift_right_equal",g.token,">>="),shift_left_equal:new m("shift_left_equal",g.token,"<<=")},h.simpleTokens={"@":y.tokens.attr,"{":y.tokens.brace_left,"}":y.tokens.brace_right,":":y.tokens.colon,",":y.tokens.comma,"(":y.tokens.paren_left,")":y.tokens.paren_right,";":y.tokens.semicolon},h.literalTokens={"&":y.tokens.and,"&&":y.tokens.and_and,"->":y.tokens.arrow,"/":y.tokens.forward_slash,"!":y.tokens.bang,"[":y.tokens.bracket_left,"]":y.tokens.bracket_right,"=":y.tokens.equal,"==":y.tokens.equal_equal,"!=":y.tokens.not_equal,">":y.tokens.greater_than,">=":y.tokens.greater_than_equal,">>":y.tokens.shift_right,"<":y.tokens.less_than,"<=":y.tokens.less_than_equal,"<<":y.tokens.shift_left,"%":y.tokens.modulo,"-":y.tokens.minus,"--":y.tokens.minus_minus,".":y.tokens.period,"+":y.tokens.plus,"++":y.tokens.plus_plus,"|":y.tokens.or,"||":y.tokens.or_or,"*":y.tokens.star,"~":y.tokens.tilde,_:y.tokens.underscore,"^":y.tokens.xor,"+=":y.tokens.plus_equal,"-=":y.tokens.minus_equal,"*=":y.tokens.times_equal,"/=":y.tokens.division_equal,"%=":y.tokens.modulo_equal,"&=":y.tokens.and_equal,"|=":y.tokens.or_equal,"^=":y.tokens.xor_equal,">>=":y.tokens.shift_right_equal,"<<=":y.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:y.tokens.decimal_float_literal,hex_float_literal:y.tokens.hex_float_literal,int_literal:y.tokens.int_literal,uint_literal:y.tokens.uint_literal,ident:y.tokens.ident},h.storage_class=[y.keywords.function,y.keywords.private,y.keywords.workgroup,y.keywords.uniform,y.keywords.storage],h.access_mode=[y.keywords.read,y.keywords.write,y.keywords.read_write],h.sampler_type=[y.keywords.sampler,y.keywords.sampler_comparison],h.sampled_texture_type=[y.keywords.texture_1d,y.keywords.texture_2d,y.keywords.texture_2d_array,y.keywords.texture_3d,y.keywords.texture_cube,y.keywords.texture_cube_array],h.multisampled_texture_type=[y.keywords.texture_multisampled_2d],h.storage_texture_type=[y.keywords.texture_storage_1d,y.keywords.texture_storage_2d,y.keywords.texture_storage_2d_array,y.keywords.texture_storage_3d],h.depth_texture_type=[y.keywords.texture_depth_2d,y.keywords.texture_depth_2d_array,y.keywords.texture_depth_cube,y.keywords.texture_depth_cube_array,y.keywords.texture_depth_multisampled_2d],h.texture_external_type=[y.keywords.texture_external],h.any_texture_type=[...y.sampled_texture_type,...y.multisampled_texture_type,...y.storage_texture_type,...y.depth_texture_type,...y.texture_external_type],h.texel_format=[y.keywords.r8unorm,y.keywords.r8snorm,y.keywords.r8uint,y.keywords.r8sint,y.keywords.r16uint,y.keywords.r16sint,y.keywords.r16float,y.keywords.rg8unorm,y.keywords.rg8snorm,y.keywords.rg8uint,y.keywords.rg8sint,y.keywords.r32uint,y.keywords.r32sint,y.keywords.r32float,y.keywords.rg16uint,y.keywords.rg16sint,y.keywords.rg16float,y.keywords.rgba8unorm,y.keywords.rgba8unorm_srgb,y.keywords.rgba8snorm,y.keywords.rgba8uint,y.keywords.rgba8sint,y.keywords.bgra8unorm,y.keywords.bgra8unorm_srgb,y.keywords.rgb10a2unorm,y.keywords.rg11b10float,y.keywords.rg32uint,y.keywords.rg32sint,y.keywords.rg32float,y.keywords.rgba16uint,y.keywords.rgba16sint,y.keywords.rgba16float,y.keywords.rgba32uint,y.keywords.rgba32sint,y.keywords.rgba32float],h.const_literal=[y.tokens.int_literal,y.tokens.uint_literal,y.tokens.decimal_float_literal,y.tokens.hex_float_literal,y.keywords.true,y.keywords.false],h.literal_or_ident=[y.tokens.ident,y.tokens.int_literal,y.tokens.uint_literal,y.tokens.decimal_float_literal,y.tokens.hex_float_literal,y.tokens.name],h.element_count_expression=[y.tokens.int_literal,y.tokens.uint_literal,y.tokens.ident],h.template_types=[y.keywords.vec2,y.keywords.vec3,y.keywords.vec4,y.keywords.mat2x2,y.keywords.mat2x3,y.keywords.mat2x4,y.keywords.mat3x2,y.keywords.mat3x3,y.keywords.mat3x4,y.keywords.mat4x2,y.keywords.mat4x3,y.keywords.mat4x4,y.keywords.atomic,y.keywords.bitcast,...y.any_texture_type],h.attribute_name=[y.tokens.ident,y.keywords.block,y.keywords.diagnostic],h.assignment_operators=[y.tokens.equal,y.tokens.plus_equal,y.tokens.minus_equal,y.tokens.times_equal,y.tokens.division_equal,y.tokens.modulo_equal,y.tokens.and_equal,y.tokens.or_equal,y.tokens.xor_equal,y.tokens.shift_right_equal,y.tokens.shift_left_equal],h.increment_operators=[y.tokens.plus_plus,y.tokens.minus_minus];Xt=class{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return h.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},In=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Xt(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
13
+ `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
14
+ `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let a=1;for(;a>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
15
+ `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let t=h.simpleTokens[e];if(t)return this._addToken(t),!0;let n=h.none,r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(r){let a=h.keywords[e];if(a)return this._addToken(a),!0}if(r||s)return this._addToken(h.tokens.ident),!0;for(;;){let a=this._findType(e),i=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(i=="=")return this._current++,e+=i,this._addToken(h.tokens.minus_equal),!0;if(i=="-")return this._current++,e+=i,this._addToken(h.tokens.minus_minus),!0;let o=this._tokens.length-1;if((h.literal_or_ident.indexOf(this._tokens[o].type)!=-1||this._tokens[o].type==h.tokens.paren_right)&&i!=">")return this._addToken(a),!0}if(e==">"&&(i==">"||i=="=")){let o=!1,c=this._tokens.length-1;for(let l=0;l<5&&c>=0&&h.assignment_operators.indexOf(this._tokens[c].type)===-1;++l,--c)if(this._tokens[c].type===h.tokens.less_than){c>0&&this._tokens[c-1].isArrayOrTemplateType()&&(o=!0);break}if(o)return this._addToken(a),!0}if(a===h.none){let o=e,c=0,l=2;for(let f=0;f<l;++f)if(o+=this._peekAhead(f),a=this._findType(o),a!==h.none){c=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=o,this._current+=c+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==h.none&&(this._addToken(n),!0)}_findType(e){for(let n in h.regexTokens){let r=h.regexTokens[n];if(this._match(e,r.rule))return r}return h.literalTokens[e]||h.none}_match(e,t){let n=t.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
16
+ `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Xt(e,t,this._line,this._start,this._current))}};jt=new Float32Array(1),jr=new Uint32Array(jt.buffer),Yr=new Uint32Array(jt.buffer),Yt=new Int32Array(1),Zr=new Float32Array(Yt.buffer),Jr=new Uint32Array(Yt.buffer),Zt=new Uint32Array(1),Kr=new Float32Array(Zt.buffer),es=new Int32Array(Zt.buffer);Sn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},De=class{constructor(e,t){this.align=e,this.size=t}},K=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new yn,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let t of e)t instanceof ve&&this._functions.set(t.name,new Sn(t));for(let t of e)if(t instanceof ne){let n=this.getTypeInfo(t,null);n instanceof le&&this.structs.push(n)}for(let t of e)if(t instanceof Xe)this.aliases.push(this._getAliasInfo(t));else if(t instanceof He){let n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new mn(n.name,s,n.attributes,r))}else if(this._isUniformVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new $e(n.name,a,r,s,n.attributes,oe.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i)}else if(this._isStorageVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),o=new $e(n.name,a,r,s,n.attributes,i?oe.StorageTexture:oe.Storage,n.access);o.access||(o.access="read"),this.storage.push(o)}else if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),o=new $e(n.name,a,r,s,n.attributes,i?oe.StorageTexture:oe.Texture,n.access);o.access||(o.access="read"),i?this.storage.push(o):this.textures.push(o)}else if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new $e(n.name,a,r,s,n.attributes,oe.Sampler,n.access);this.samplers.push(i)}for(let t of e)if(t instanceof ve){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),a=n||r||s,i=new xn(t.name,a?.name,t.attributes);i.attributes=t.attributes,i.startLine=t.startLine,i.endLine=t.endLine,this.functions.push(i),this._functions.get(t.name).info=i,a&&(this._functions.get(t.name).inUse=!0,i.inUse=!0,i.resources=this._findResources(t,!!a),i.inputs=this._getInputs(t.args),i.outputs=this._getOutputs(t.returnType),this.entry[a.name].push(i)),i.arguments=t.args.map(o=>new gn(o.name,this.getTypeInfo(o.type,o.attributes),o.attributes)),i.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null}for(let t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(let t of this._functions.values())t.node.search(n=>{var r,s,a;if(n instanceof Qt){if(n.value)if(w(n.value))for(let i of n.value)for(let o of this.overrides)i===o.name&&((r=t.info)===null||r===void 0||r.overrides.push(o));else for(let i of this.overrides)n.value===i.name&&((s=t.info)===null||s===void 0||s.overrides.push(i))}else if(n instanceof q)for(let i of this.overrides)n.name===i.name&&((a=t.info)===null||a===void 0||a.overrides.push(i))});for(let t of this.uniforms)this._markStructsInUse(t.type);for(let t of this.storage)this._markStructsInUse(t.type)}getStructInfo(e){for(let t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(let t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(let r of e.calls){let s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(let r of this.entry.compute)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.vertex)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.fragment)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}}for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let n=[],r=this,s=[];return e.search(a=>{if(a instanceof Fe)s.push({});else if(a instanceof Ne)s.pop();else if(a instanceof se){let i=a;t&&i.type!==null&&this._markStructsFromAST(i.type),s.length>0&&(s[s.length-1][i.name]=i)}else if(a instanceof J){let i=a;t&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof _e){let i=a;t&&i.type!==null&&this._markStructsFromAST(i.type),s.length>0&&(s[s.length-1][i.name]=i)}else if(a instanceof q){let i=a;if(s.length>0&&s[s.length-1][i.name])return;let o=r._findResource(i.name);o&&n.push(o)}else if(a instanceof je){let i=a,o=r._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),o.resources===null&&(o.resources=r._findResources(o.node,t)),n.push(...o.resources))}else if(a instanceof Qe){let i=a,o=r._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),o.resources===null&&(o.resources=r._findResources(o.node,t)),n.push(...o.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(let n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof ne)this._getStructOutputs(e,t);else{let n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(let n of e.members)if(n.type instanceof ne)this._getStructOutputs(n.type,t);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let s=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(r.value),i=new Tt(n.name,s,r.name,a);t.push(i)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new Tt("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof ne)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(let n of e.members)if(n.type instanceof ne)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),a=new dn(e.name,r,t.name,s);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new pn(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let t of this.structs)if(t.name==e)return t;for(let t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof Pe){let r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new Re(e.name,r,t);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof be){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,a=new ce(r.name,t);return a.format=s,a.count=r.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof ne){let r=e,s=new le(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let a of r.members){let i=this.getTypeInfo(a.type,a.attributes);s.members.push(new St(a.name,i,a.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof ye){let r=e,s=r.format instanceof b,a=r.format?s?this.getTypeInfo(r.format,null):new R(r.format,null):null,i=new he(r.name,a,t,r.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof x){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,a=new he(r.name,s,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new R(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;let s=this._getTypeSize(e);if(e.size=(t=s?.size)!==null&&t!==void 0?t:0,e instanceof ce&&e.format){let a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(r=a?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof Re&&this._updateTypeInfo(e.format),e instanceof le&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,a=0;for(let i=0,o=e.members.length;i<o;++i){let c=e.members[i],l=this._getTypeSize(c);if(!l)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;let f=l.align,_=l.size;n=this._roundUp(f,n+r),r=_,s=n,a=Math.max(a,f),c.offset=n,c.size=_,this._updateTypeInfo(c.type)}e.size=this._roundUp(a,s+r),e.align=a}_getTypeSize(e){var t,n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof St&&(e=e.type),e instanceof R){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=K._typeInfo[e.name];if(a!==void 0){let i=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new De(Math.max(s,a.align/i),Math.max(r,a.size/i))}}{let a=K._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let i=e.name[e.name.length-1]==="h"?2:1;return new De(Math.max(s,a.align/i),Math.max(r,a.size/i))}}if(e instanceof ce){let a=e,i=8,o=8,c=this._getTypeSize(a.format);return c!==null&&(o=c.size,i=c.align),o=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,o)),r&&(o=r),new De(Math.max(s,i),Math.max(r,o))}if(e instanceof le){let a=0,i=0,o=0,c=0,l=0;for(let f of e.members){let _=this._getTypeSize(f.type);_!==null&&(a=Math.max(_.align,a),o=this._roundUp(_.align,o+c),c=_.size,l=o)}return i=this._roundUp(a,l+c),new De(Math.max(s,a),Math.max(r,i))}return null}_isUniformVar(e){return e instanceof se&&e.storage=="uniform"}_isStorageVar(e){return e instanceof se&&e.storage=="storage"}_isTextureVar(e){return e instanceof se&&e.type!==null&&K._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof se&&e.type!==null&&K._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let n=e;if(!n||!n.attributes)return null;let r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}};K._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},K._textureTypes=h.any_texture_type.map(u=>u.name),K._samplerTypes=h.sampler_type.map(u=>u.name);$n=0,Ze=class{constructor(e,t,n){this.id=$n++,this.name=e,this.value=t,this.node=n}clone(){return new Ze(this.name,this.value,this.node)}},Je=class{constructor(e){this.id=$n++,this.name=e.name,this.node=e}clone(){return new Je(this.node)}},Ke=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=$n++,e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?(t=this.variables.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?(t=this.functions.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,n){this.variables.set(e,new Ze(e,t,n??null))}setVariable(e,t,n){let r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;let n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new Ke(this)}},Tn=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},En=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){let n=this.exec.evalExpression(e.args[0],t),r=!0;if(n instanceof p)return n.data.forEach(s=>{s||(r=!1)}),new d(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=n.data.some(s=>s);return new d(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){let n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof d))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof P&&r.typeInfo.size===0){let s=r.typeInfo,a=r.buffer.byteLength/s.stride;return new d(a,this.getTypeInfo("u32"))}return new d(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new d(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new d(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new d(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new d(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new d(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new d(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new d(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>Math.atan2(i,r.data[o])),n.typeInfo);let s=n,a=r;return new d(Math.atan2(s.value,a.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new d(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((c,l)=>this._clamp(c,r.data[l],s.data[l])),n.typeInfo);let a=n,i=r,o=s;return new d(this._clamp(a.value,i.value,o.value),n.typeInfo)}Cos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new d(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new d(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new d(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let s=n.data,a=r.data;return new p([s[1]*a[2]-a[1]*s[2],s[2]*a[0]-a[2]*s[0],s[0]*a[1]-a[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){let n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof p?new p(n.data.map(s=>s*r),n.typeInfo):new d(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof I){let r=n.data,s=n.typeInfo.getTypeName(),a=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new d(r[0]*r[3]-r[1]*r[2],a);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let i=0;for(let o=0;o<n.data.length;++o)i+=(n.data[o]-r.data[o])*(n.data[o]-r.data[o]);return new d(Math.sqrt(i),this.getTypeInfo("f32"))}let s=n,a=r;return new d(Math.abs(s.value-a.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof p&&r instanceof p?new d(this._dot(n.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new d(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new d(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let a=r.value,i=s.value;if(n instanceof p)return new p(n.data.map(c=>c>>a&(1<<i)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let o=n.value;return new d(o>>a&(1<<i)-1,this.getTypeInfo("i32"))}FaceForward(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p){let a=this._dot(r.data,s.data);return new p(a<0?Array.from(n.data):n.data.map(i=>-i),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new d(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new d(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new d(Math.floor(r.value),n.typeInfo)}Fma(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new p(n.data.map((c,l)=>c*r.data[l]+s.data[l]),n.typeInfo);let a=n,i=r,o=s;return new d(a.value*i.value+o.value,a.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new d(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),a=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let i=s.value,o=(1<<a.value)-1<<i,c=~o;if(n instanceof p&&r instanceof p)return new p(n.data.map((_,v)=>_&c|r.data[v]<<i&o),n.typeInfo);let l=n.value,f=r.value;return new d(l&c|f<<i&o,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new d(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let s=0;return n.data.forEach(a=>{s+=a*a}),new d(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new d(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new d(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new d(Math.log2(r.value),n.typeInfo)}Max(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>Math.max(i,r.data[o])),n.typeInfo);let s=n,a=r;return new d(Math.max(s.value,a.value),n.typeInfo)}Min(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>Math.min(i,r.data[o])),n.typeInfo);let s=n,a=r;return new d(Math.min(s.value,a.value),n.typeInfo)}Mix(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((o,c)=>n.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),n.typeInfo);let a=r,i=s;return new d(n.value*(1-i.value)+a.value*i.value,n.typeInfo)}Modf(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((a,i)=>a%r.data[i]),n.typeInfo);let s=r;return new d(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=this.Length(e,t).value;return new p(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>Math.pow(i,r.data[o])),n.typeInfo);let s=n,a=r;return new d(Math.pow(s.value,a.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r),n.typeInfo):new d(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r*Math.PI/180),n.typeInfo):new d(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let s=this._dot(n.data,r.data);return new p(n.data.map((a,i)=>a-2*s*r.data[i]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof d){let a=this._dot(r.data,n.data);return new p(n.data.map((i,o)=>{let c=1-s.value*s.value*(1-a*a);if(c<0)return 0;let l=Math.sqrt(c);return s.value*i-(s.value*a+l)*r.data[o]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new d(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new d(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new d(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new d(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new d(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){let r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof p&&n instanceof p&&r instanceof p)return new p(s.data.map((c,l)=>this._smoothstep(n.data[l],r.data[l],c)),s.typeInfo);let a=n,i=r,o=s;return new d(this._smoothstep(a.value,i.value,o.value),s.typeInfo)}Sqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new d(Math.sqrt(r.value),n.typeInfo)}Step(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof p&&n instanceof p)return new p(r.data.map((a,i)=>a<n.data[i]?0:1),r.typeInfo);let s=n;return new d(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new d(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new d(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){let t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){let n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof I))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let s=n.data;return new I([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let s=n.data;return new I([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let s=n.data;return new I([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let s=n.data;return new I([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new d(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){let n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof q){let s=n.name,a=t.getVariableValue(s);if(a instanceof re){if(r<0||r>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let i=a.getMipLevelSize(r),o=a.dimension;return o==="1d"?new d(i[0],this.getTypeInfo("u32")):o==="3d"?new p(i,this.getTypeInfo("vec3u")):o==="2d"?new p(i.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${o} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof q){let a=n.name,i=t.getVariableValue(a);if(i instanceof re){let o=Math.floor(r.data[0]),c=Math.floor(r.data[1]);if(o<0||o>=i.width||c<0||c>=i.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;let l=i.getPixel(o,c,0,s);return l===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new p(l,this.getTypeInfo("vec4f"))}return console.error(`Texture ${a} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){let n=e.args[0];if(n instanceof q){let r=n.name,s=t.getVariableValue(r);return s instanceof re?new d(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){let n=e.args[0];if(n instanceof q){let r=n.name,s=t.getVariableValue(r);return s instanceof re?new d(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){let n=e.args[0];if(n instanceof q){let r=n.name,s=t.getVariableValue(r);return s instanceof re?new d(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,a=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(a.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof q){let i=n.name,o=t.getVariableValue(i);if(o instanceof re){let c=o.getMipLevelSize(0),l=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return l<0||l>=c[0]||f<0||f>=c[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(o.setPixel(l,f,0,s,Array.from(a)),null)}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t);return o instanceof d&&i instanceof d&&(o.value=i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value+=i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value-=i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=Math.max(o.value,i.value)),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=Math.min(o.value,i.value)),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=o.value&i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=o.value|i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=o.value^i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof F&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],i=this.exec.evalExpression(a,t),o=s.value.getSubData(this.exec,n.postfix,t),c=new d(o.value,o.typeInfo);return o instanceof d&&i instanceof d&&(o.value=i.value),s.value instanceof P&&s.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}},fn={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},G={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]},M=class extends Tn{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new K,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new Ke,this.builtins=new En(this),this.typeInfo={bool:this.getTypeInfo(b.bool),i32:this.getTypeInfo(b.i32),u32:this.getTypeInfo(b.u32),f32:this.getTypeInfo(b.f32),f16:this.getTypeInfo(b.f16),vec2f:this.getTypeInfo(x.vec2f),vec2u:this.getTypeInfo(x.vec2u),vec2i:this.getTypeInfo(x.vec2i),vec2h:this.getTypeInfo(x.vec2h),vec3f:this.getTypeInfo(x.vec3f),vec3u:this.getTypeInfo(x.vec3u),vec3i:this.getTypeInfo(x.vec3i),vec3h:this.getTypeInfo(x.vec3h),vec4f:this.getTypeInfo(x.vec4f),vec4u:this.getTypeInfo(x.vec4u),vec4i:this.getTypeInfo(x.vec4i),vec4h:this.getTypeInfo(x.vec4h),mat2x2f:this.getTypeInfo(x.mat2x2f),mat2x3f:this.getTypeInfo(x.mat2x3f),mat2x4f:this.getTypeInfo(x.mat2x4f),mat3x2f:this.getTypeInfo(x.mat3x2f),mat3x3f:this.getTypeInfo(x.mat3x3f),mat3x4f:this.getTypeInfo(x.mat3x4f),mat4x2f:this.getTypeInfo(x.mat4x2f),mat4x3f:this.getTypeInfo(x.mat4x3f),mat4x4f:this.getTypeInfo(x.mat4x4f)}}getVariableValue(e){var t,n;let r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof d)return r.value;if(r instanceof p||r instanceof I)return Array.from(r.data);if(r instanceof P&&r.typeInfo instanceof ce){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){let s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);let a=s.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}let i=t[0],o=t[1],c=t[2],l=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new p(t,l));for(let f in n)for(let _ in n[f]){let v=n[f][_];s.variables.forEach(k=>{var A;let E=k.node;if(E?.attributes){let V=null,W=null;for(let S of E.attributes)S.name==="binding"?V=S.value:S.name==="group"&&(W=S.value);if(_==V&&f==W)if(v.texture!==void 0&&v.descriptor!==void 0){let S=new re(v.texture,this.getTypeInfo(E.type),v.descriptor,(A=v.texture.view)!==null&&A!==void 0?A:null);k.value=S}else v.uniform!==void 0?k.value=new P(v.uniform,this.getTypeInfo(E.type)):k.value=new P(v,this.getTypeInfo(E.type))}})}for(let f=0;f<c;++f)for(let _=0;_<o;++_)for(let v=0;v<i;++v)s.setVariable("@workgroup_id",new p([v,_,f],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[v,_,f],s)}execStatement(e,t){if(e instanceof Ot)return this.evalExpression(e.value,t);if(e instanceof Vt){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof d))throw new Error("Invalid break-if condition");if(!n.value)return null}return M._breakObj}if(e instanceof Ft)return M._continueObj;if(e instanceof _e)this._let(e,t);else if(e instanceof se)this._var(e,t);else if(e instanceof Oe)this._const(e,t);else if(e instanceof ve)this._function(e,t);else{if(e instanceof Dt)return this._if(e,t);if(e instanceof Bt)return this._switch(e,t);if(e instanceof At)return this._for(e,t);if(e instanceof Et)return this._while(e,t);if(e instanceof $t)return this._loop(e,t);if(e instanceof ze){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof Ct)this._assign(e,t);else if(e instanceof Lt)this._increment(e,t);else{if(e instanceof ne)return null;if(e instanceof He){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new d(0,this.getTypeInfo("u32")))}else if(e instanceof Qe)this._call(e,t);else{if(e instanceof Pt||e instanceof Xe)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof X?this._evalBinaryOp(e,t):e instanceof N?this._evalLiteral(e,t):e instanceof q?this._evalVariable(e,t):e instanceof je?this._evalCall(e,t):e instanceof J?this._evalCreate(e,t):e instanceof Mt?this._evalConst(e,t):e instanceof Wt?this._evalBitcast(e,t):e instanceof F?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof b){let r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(let n in e){let r=e[n],s=this.reflection.getOverrideInfo(n);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(n,new d(r,s.type)):s.type.name==="bool"?t.setVariable(n,new d(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(n,new p(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){let r=[1,1,1];for(let l of e.node.attributes)if(l.name==="workgroup_size"){if(l.value.length>0){let f=n.getVariableValue(l.value[0]);r[0]=f instanceof d?f.value:parseInt(l.value[0])}if(l.value.length>1){let f=n.getVariableValue(l.value[1]);r[1]=f instanceof d?f.value:parseInt(l.value[1])}if(l.value.length>2){let f=n.getVariableValue(l.value[2]);r[2]=f instanceof d?f.value:parseInt(l.value[2])}}let s=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new p(r,s));let i=r[0],o=r[1],c=r[2];for(let l=0,f=0;l<c;++l)for(let _=0;_<o;++_)for(let v=0;v<i;++v,++f){let k=[v,_,l],A=[v+t[0]*r[0],_+t[1]*r[1],l+t[2]*r[2]];n.setVariable("@local_invocation_id",new p(k,s)),n.setVariable("@global_invocation_id",new p(A,s)),n.setVariable("@local_invocation_index",new d(f,a)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(let n of e.node.args)for(let r of n.attributes)if(r.name==="builtin"){let s=`@${r.value}`,a=t.getVariable(s);a!==void 0&&t.variables.set(n.name,a)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof F;)e=e.right;return e instanceof q?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(let n of e){if(n instanceof Array){let s=t.clone(),a=this._execStatements(n,s);if(a)return a;continue}let r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],i=this.evalExpression(e.args[s],n);n.setVariable(a.name,i,a)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){let n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof d?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof d?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof q){let n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof F){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof de?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,t);return new de(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof F){let o=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),l=e.operator;if(l==="="){if(o instanceof d||o instanceof p||o instanceof I){if(c instanceof d||c instanceof p||c instanceof I&&o.data.length===c.data.length)return void o.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(o instanceof P&&c instanceof P&&o.buffer.byteLength-o.offset>=c.buffer.byteLength-c.offset)return void(o.buffer.byteLength%4==0?new Uint32Array(o.buffer,o.offset,o.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(o.buffer,o.offset,o.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(l==="+=")return o instanceof d||o instanceof p||o instanceof I?c instanceof d||c instanceof p||c instanceof I?void o.data.set(c.data.map((f,_)=>o.data[_]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(l==="-=")return(o instanceof d||o instanceof p||o instanceof I)&&(c instanceof d||c instanceof p||c instanceof I)?void o.data.set(c.data.map((f,_)=>o.data[_]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof F){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let o=t.getVariable(r);if(!(o&&o.value instanceof de))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=o.value.reference;let c=e.variable.postfix;if(!c){let l=e.variable.right;for(;l instanceof F;){if(l.postfix){c=l.postfix;break}l=l.right}}c&&(n=n.getSubData(this,c,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);let o=t.getVariable(r);if(o===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=o.value}if(n instanceof de&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let a=this.evalExpression(e.value,t),i=e.operator;if(i==="=")if(n instanceof P)n.setDataValue(this,a,s,t);else if(s){if(!(n instanceof p||n instanceof I))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof me){let o=this.evalExpression(s.index,t).value;if(n instanceof p){if(!(a instanceof d))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[o]=a.value}else{if(!(n instanceof I))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let c=this.evalExpression(s.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let l=n.typeInfo.getTypeName();if(l==="mat2x2"||l==="mat2x2f"||l==="mat2x2h"){if(!(c<2&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(l==="mat2x3"||l==="mat2x3f"||l==="mat2x3h"){if(!(c<2&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else if(l==="mat2x4"||l==="mat2x4f"||l==="mat2x4h"){if(!(c<2&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}else if(l==="mat3x2"||l==="mat3x2f"||l==="mat3x2h"){if(!(c<3&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(l==="mat3x3"||l==="mat3x3f"||l==="mat3x3h"){if(!(c<3&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else if(l==="mat3x4"||l==="mat3x4f"||l==="mat3x4h"){if(!(c<3&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}else if(l==="mat4x2"||l==="mat4x2f"||l==="mat4x2h"){if(!(c<4&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(l==="mat4x3"||l==="mat4x3f"||l==="mat4x3h"){if(!(c<4&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else{if(l!=="mat4x4"&&l!=="mat4x4f"&&l!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(c<4&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}}}}}else if(s instanceof fe){let o=s.value;if(!(n instanceof p))return void console.error(`Invalid assignment to ${o}. Variable ${r} is not a vector. Line ${e.line}`);if(a instanceof d){if(o.length>1)return void console.error(`Invalid assignment to ${o} for variable ${r}. Line ${e.line}`);if(o==="x")n.data[0]=a.value;else if(o==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${o} for variable ${r}. Line ${e.line}`);n.data[1]=a.value}else if(o==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${o} for variable ${r}. Line ${e.line}`);n.data[2]=a.value}else if(o==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${o} for variable ${r}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(o.length!==a.data.length)return void console.error(`Invalid assignment to ${o} for variable ${r}. Line ${e.line}`);for(let c=0;c<o.length;++c){let l=o[c];if(l==="x"||l==="r")n.data[0]=a.data[c];else if(l==="y"||l==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[1]=a.data[c]}else if(l==="z"||l==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[2]=a.data[c]}else{if(l!=="w"&&l!=="a")return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[3]=a.data[c]}}}}}else n instanceof d&&a instanceof d?n.value=a.value:n instanceof p&&a instanceof p||n instanceof I&&a instanceof I?n.data.set(a.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`);else{let o=n.getSubData(this,s,t);if(o instanceof p&&a instanceof d){let c=o.data,l=a.value;if(i==="+=")for(let f=0;f<c.length;++f)c[f]+=l;else if(i==="-=")for(let f=0;f<c.length;++f)c[f]-=l;else if(i==="*=")for(let f=0;f<c.length;++f)c[f]*=l;else if(i==="/=")for(let f=0;f<c.length;++f)c[f]/=l;else if(i==="%=")for(let f=0;f<c.length;++f)c[f]%=l;else if(i==="&=")for(let f=0;f<c.length;++f)c[f]&=l;else if(i==="|=")for(let f=0;f<c.length;++f)c[f]|=l;else if(i==="^=")for(let f=0;f<c.length;++f)c[f]^=l;else if(i==="<<=")for(let f=0;f<c.length;++f)c[f]<<=l;else if(i===">>=")for(let f=0;f<c.length;++f)c[f]>>=l;else console.error(`Invalid operator ${i}. Line ${e.line}`)}else if(o instanceof p&&a instanceof p){let c=o.data,l=a.data;if(c.length!==l.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(i==="+=")for(let f=0;f<c.length;++f)c[f]+=l[f];else if(i==="-=")for(let f=0;f<c.length;++f)c[f]-=l[f];else if(i==="*=")for(let f=0;f<c.length;++f)c[f]*=l[f];else if(i==="/=")for(let f=0;f<c.length;++f)c[f]/=l[f];else if(i==="%=")for(let f=0;f<c.length;++f)c[f]%=l[f];else if(i==="&=")for(let f=0;f<c.length;++f)c[f]&=l[f];else if(i==="|=")for(let f=0;f<c.length;++f)c[f]|=l[f];else if(i==="^=")for(let f=0;f<c.length;++f)c[f]^=l[f];else if(i==="<<=")for(let f=0;f<c.length;++f)c[f]<<=l[f];else if(i===">>=")for(let f=0;f<c.length;++f)c[f]>>=l[f];else console.error(`Invalid operator ${i}. Line ${e.line}`)}else{if(!(o instanceof d&&a instanceof d))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);i==="+="?o.value+=a.value:i==="-="?o.value-=a.value:i==="*="?o.value*=a.value:i==="/="?o.value/=a.value:i==="%="?o.value%=a.value:i==="&="?o.value&=a.value:i==="|="?o.value|=a.value:i==="^="?o.value^=a.value:i==="<<="?o.value<<=a.value:i===">>="?o.value>>=a.value:console.error(`Invalid operator ${i}. Line ${e.line}`)}n instanceof P&&n.setDataValue(this,o,s,t)}}_function(e,t){let n=new Je(e);t.functions.set(e.name,n)}_const(e,t){let n=null;e.value!==null&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e)}_let(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof F||(n=n.clone())}else{let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){let s=new J(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof F||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof be||e.type instanceof ne||e.type instanceof x){let s=new J(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof qt)for(let a of s.selectors){if(a instanceof Ve){r=s;continue}let i=this.evalExpression(a,t);if(!(i instanceof d))return console.error(`Invalid case selector. Line ${e.line}`),null;if(i.value===n.value)return this._execStatements(s.body,t)}else s instanceof Rt&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(let r of e.elseif){let s=this.evalExpression(r.condition,t);if(!(s instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof d?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===M._breakObj)break;if(n!==null&&n!==M._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){let n=this._execStatements(e.body,t);if(n===M._breakObj)break;if(n===M._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===M._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===M._breakObj)break;if(n!==M._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof d){let s=kr(n.value,n.typeInfo.name,r.name);return new d(s,this.getTypeInfo(r))}if(n instanceof p){let s=n.typeInfo.getTypeName(),a="";if(s.endsWith("f"))a="f32";else if(s.endsWith("i"))a="i32";else if(s.endsWith("u"))a="u32";else if(s.endsWith("b"))a="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;a="f16"}let i=r.getTypeName(),o="";if(i.endsWith("f"))o="f32";else if(i.endsWith("i"))o="i32";else if(i.endsWith("u"))o="u32";else if(i.endsWith("b"))o="bool";else{if(!i.endsWith("h"))return console.error(`Unknown vector type ${o}. Line ${e.line}`),null;o="f16"}let c=function(l,f,_){if(f===_)return l;let v=new Array(l.length);for(let k=0;k<l.length;k++)v[k]=kr(l[k],f,_);return v}(Array.from(n.data),a,o);return new p(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof J){if(e.type===null)return Ye.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}let r=e instanceof J?e.type.name:e.name,s=e instanceof J?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;let a=new P(new ArrayBuffer(s.size),s,0);if(s instanceof le){if(e.args)for(let i=0;i<e.args.length;++i){let o=s.members[i],c=e.args[i],l=this.evalExpression(c,t);a.setData(this,l,o.type,o.offset,t)}}else if(s instanceof ce){let i=0;if(e.args)for(let o=0;o<e.args.length;++o){let c=e.args[o],l=this.evalExpression(c,t);s.format===null&&(((n=l.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=l.typeInfo),a.setData(this,l,s.format,i,t),i+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof J?a.getSubData(this,e.postfix,t):a}_evalLiteral(e,t){let n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new d(e.scalarValue,n):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){let n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=M._priority.get(t.name);M._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){let n=this.evalExpression(e.right,t);if(e.operator==="&")return new de(n);if(e.operator==="*")return n instanceof de?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof d?n.value:n instanceof p?Array.from(n.data):null;switch(e.operator){case"+":{if(w(r)){let i=r.map((o,c)=>+o);return new p(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(+s,a)}case"-":{if(w(r)){let i=r.map((o,c)=>-o);return new p(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(-s,a)}case"!":{if(w(r)){let i=r.map((o,c)=>o?0:1);return new p(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(s?0:1,a)}case"~":{if(w(r)){let i=r.map((o,c)=>~o);return new p(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(~s,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){let n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof d?n.value:n instanceof p||n instanceof I?Array.from(n.data):null,a=r instanceof d?r.value:r instanceof p||r instanceof I?Array.from(r.data):null;switch(e.operator){case"+":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v+f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_+l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l+_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i+o,c)}case"-":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v-f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_-l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l-_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i-o,c)}case"*":{if(w(s)&&w(a)){let l=s,f=a;if(n instanceof I&&r instanceof I){let _=function(E,V,W,S){if(G[V.name]===void 0||G[S.name]===void 0)return null;let T=G[V.name][0],ue=G[V.name][1],Q=G[S.name][0];if(T!==G[S.name][1])return null;let Pn=new Array(Q*ue);for(let rt=0;rt<ue;rt++)for(let st=0;st<Q;st++){let Vn=0;for(let it=0;it<T;it++)Vn+=E[it*ue+rt]*W[st*T+it];Pn[rt*Q+st]=Vn}return Pn}(l,n.typeInfo,f,r.typeInfo);if(_===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let v=G[r.typeInfo.name][0],k=G[n.typeInfo.name][1],A=this.getTypeInfo(`mat${v}x${k}f`);return new I(_,A)}if(n instanceof I&&r instanceof p){let _=function(v,k,A,E){if(G[k.name]===void 0||fn[E.name]===void 0)return null;let V=G[k.name][0],W=G[k.name][1];if(V!==A.length)return null;let S=new Array(W);for(let T=0;T<W;T++){let ue=0;for(let Q=0;Q<V;Q++)ue+=v[Q*W+T]*A[Q];S[T]=ue}return S}(l,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,r.typeInfo)}if(n instanceof p&&r instanceof I){let _=function(v,k,A,E){if(fn[k.name]===void 0||G[E.name]===void 0)return null;let V=G[E.name][0],W=G[E.name][1];if(W!==v.length)return null;let S=[];for(let T=0;T<V;T++){let ue=0;for(let Q=0;Q<W;Q++)ue+=v[Q]*A[Q*V+T];S[T]=ue}return S}(l,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,n.typeInfo)}{if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v*f[k]);return new p(_,n.typeInfo)}}if(w(s)){let l=a,f=s.map((_,v)=>_*l);return n instanceof I?new I(f,n.typeInfo):new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l*_);return r instanceof I?new I(f,r.typeInfo):new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i*o,c)}case"%":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v%f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_%l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l%_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i%o,c)}case"/":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v/f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_/l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l/_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i/o,c)}case"&":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v&f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_&l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l&_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i&o,c)}case"|":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v|f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_|l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l|_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i|o,c)}case"^":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v^f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_^l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l^_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i^o,c)}case"<<":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v<<f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_<<l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l<<_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i<<o,c)}case">>":{if(w(s)&&w(a)){let l=s,f=a;if(l.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=l.map((v,k)=>v>>f[k]);return new p(_,n.typeInfo)}if(w(s)){let l=a,f=s.map((_,v)=>_>>l);return new p(f,n.typeInfo)}if(w(a)){let l=s,f=a.map((_,v)=>l>>_);return new p(f,r.typeInfo)}let i=s,o=a,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(i>>o,c)}case">":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l>o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c>i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i>c?1:0);return new p(o,r.typeInfo)}return new d(s>a?1:0,this.getTypeInfo("bool"));case"<":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l<o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c<i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i<c?1:0);return new p(o,r.typeInfo)}return new d(s<a?1:0,this.getTypeInfo("bool"));case"==":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l===o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c==i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i==c?1:0);return new p(o,r.typeInfo)}return new d(s===a?1:0,this.getTypeInfo("bool"));case"!=":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l!==o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c!==i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i!==c?1:0);return new p(o,r.typeInfo)}return new d(s!==a?1:0,this.getTypeInfo("bool"));case">=":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l>=o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c>=i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i>=c?1:0);return new p(o,r.typeInfo)}return new d(s>=a?1:0,this.getTypeInfo("bool"));case"<=":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l<=o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c<=i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i<=c?1:0);return new p(o,r.typeInfo)}return new d(s<=a?1:0,this.getTypeInfo("bool"));case"&&":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l&&o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c&&i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i&&c?1:0);return new p(o,r.typeInfo)}return new d(s&&a?1:0,this.getTypeInfo("bool"));case"||":if(w(s)&&w(a)){let i=s,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=i.map((l,f)=>l||o[f]?1:0);return new p(c,n.typeInfo)}if(w(s)){let i=a,o=s.map((c,l)=>c||i?1:0);return new p(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((c,l)=>i||c?1:0);return new p(o,r.typeInfo)}return new d(s||a?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],i=this.evalExpression(e.args[s],n);n.createVariable(a.name,i,a)}return this._execStatements(r.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothStep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}let n=t.getFunction(e.name);if(n){let r=t.clone();for(let s=0;s<n.node.args.length;++s){let a=n.node.args[s],i=this.evalExpression(e.args[s],r);r.setVariable(a.name,i,a)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new d(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=fn[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof N)if(e.isVector){let i=e.vectorValue;for(let o of i)a.push(o)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let o=this.evalExpression(i,t);if(o instanceof p){let c=o.data;for(let l=0;l<c.length;++l){let f=c[l];a.push(f)}}else if(o instanceof d){let c=o.value;a.push(c)}}if(e.type instanceof x&&e.type.format===null&&(e.type.format=x.f32),a.length===0){let i=new Array(s).fill(0);return new p(i,n).getSubData(this,e.postfix,t)}if(a.length===1)for(;a.length<s;)a.push(a[0]);return a.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new p(a.length>s?a.slice(0,s):a,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=G[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof N)if(e.isVector){let i=e.vectorValue;for(let o of i)a.push(o)}else a.push(e.scalarValue);else if(e.args)for(let i of e.args){let o=this.evalExpression(i,t);o instanceof p?a.push(...o.data):o instanceof d?a.push(o.value):o instanceof I&&a.push(...o.data)}if(n instanceof he&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let i=new Array(s[2]).fill(0);return new I(i,n).getSubData(this,e.postfix,t)}return a.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new I(a,n).getSubData(this,e.postfix,t)}};M._breakObj=new H(new R("BREAK",null),null),M._continueObj=new H(new R("CONTINUE",null),null),M._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);An=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Ln=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new An,this._exec=new M,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,s=n.countNode;if(s instanceof q){let a=s.name,i=this._context.constants.get(a);if(i)try{let o=i.constEvaluate(this._exec);r.count=o}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof Ht||r instanceof Pe?r.type=this._forwardType(r.type):r instanceof be?r.format=this._forwardType(r.format):r instanceof se||r instanceof _e||r instanceof Oe?r.type=this._forwardType(r.type):r instanceof ve?r.returnType=this._forwardType(r.returnType):r instanceof zt&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof Nt){let t=this._getType(e.name);if(t)return t}else e instanceof Pe?e.type=this._forwardType(e.type):e instanceof be&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new In(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==h.eof}_match(e){if(e instanceof m)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){let r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let n=t.type,r=!1;for(let s of e){if(n===s)return!0;s===h.tokens.name&&(r=!0)}if(r){let s=h.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===h.tokens.name){let n=h.tokens.name.rule.exec(t.lexeme);return n&&n.index==0&&n[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._match(h.keywords.alias)){let t=this._type_alias();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.diagnostic)){let t=this._diagnostic();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.requires)){let t=this._requires_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.enable)){let t=this._enable_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}let e=this._attribute();if(this._check(h.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(h.keywords.fn))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected function name.").toString();this._consume(h.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(h.tokens.paren_right))do{if(this._check(h.tokens.paren_right))break;let i=this._attribute(),o=this._consume(h.tokens.name,"Expected argument name.").toString();this._consume(h.tokens.colon,"Expected ':' for argument type.");let c=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=c,n.push(this._updateNode(new zt(o,l,i))))}while(this._match(h.tokens.comma));this._consume(h.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(h.tokens.arrow)){let i=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=i)}let s=this._compound_statement(),a=this._currentLine;return this._updateNode(new ve(t,n,r,s,e,a),e)}_compound_statement(){let e=[];for(this._consume(h.tokens.brace_left,"Expected '{' for block.");!this._check(h.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(h.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._check(h.tokens.attr)&&this._attribute(),this._check(h.keywords.if))return this._if_statement();if(this._check(h.keywords.switch))return this._switch_statement();if(this._check(h.keywords.loop))return this._loop_statement();if(this._check(h.keywords.for))return this._for_statement();if(this._check(h.keywords.while))return this._while_statement();if(this._check(h.keywords.continuing))return this._continuing_statement();if(this._check(h.keywords.static_assert))return this._static_assert_statement();if(this._check(h.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(h.keywords.return))e=this._return_statement();else if(this._check([h.keywords.var,h.keywords.let,h.keywords.const]))e=this._variable_statement();else if(this._match(h.keywords.discard))e=this._updateNode(new wn);else if(this._match(h.keywords.break)){let t=this._updateNode(new Vt);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t,this._check(h.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(h.keywords.continue)){let t=this._updateNode(new Ft);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(h.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(h.keywords.static_assert))return null;let e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new _n(t),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new Et(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(h.keywords.continuing))return null;let t=this._currentLine,n=this._compound_statement();return this._updateNode(new ze(n,e),t)}_for_statement(){if(!this._match(h.keywords.for))return null;this._consume(h.tokens.paren_left,"Expected '('.");let e=this._updateNode(new At(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(h.tokens.semicolon)?null:this._for_init(),this._consume(h.tokens.semicolon,"Expected ';'."),e.condition=this._check(h.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(h.tokens.semicolon,"Expected ';'."),e.increment=this._check(h.tokens.paren_right)?null:this._for_increment(),this._consume(h.tokens.paren_right,"Expected ')'."),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(h.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(h.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new se(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(h.keywords.let)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return this._updateNode(new _e(t,n,null,null,r),e)}if(this._match(h.keywords.const)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return n===null&&r instanceof N&&(n=r.type),this._updateNode(new Oe(t,n,null,null,r),e)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(h.increment_operators))return this._current=e,null;let n=this._consume(h.increment_operators,"Expected increment operator");return this._updateNode(new Lt(n.type===h.tokens.plus_plus?Be.increment:Be.decrement,t))}_assignment_statement(){let e=null,t=this._currentLine;if(this._check(h.tokens.brace_right))return null;let n=this._match(h.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;let r=this._consume(h.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new Ct(qe.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(h.tokens.ident))return null;let e=this._currentLine,t=this._current,n=this._consume(h.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new Qe(n.lexeme,r),e)}_loop_statement(){if(!this._match(h.keywords.loop))return null;this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new $t([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof ze){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(h.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(h.keywords.switch))return null;let e=this._updateNode(new Bt(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(h.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],t=!1;for(;this._check([h.keywords.default,h.keywords.case]);){if(this._match(h.keywords.case)){let n=this._case_selectors();for(let s of n)if(s instanceof Ve){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new qt(n,r)))}if(this._match(h.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Rt(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new Ve)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new Ve)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(h.keywords.if))return null;let e=this._currentLine,t=this._optional_paren_expression();this._check(h.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(h.keywords.else)&&(this._check(h.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new Dt(t,n,r,s),e)}_match_elseif(){return this._tokens[this._current].type===h.keywords.else&&this._tokens[this._current+1].type===h.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new kn(t,n))),this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(h.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new Ot(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new X(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(h.tokens.and_and);)e=this._updateNode(new X(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(h.tokens.or);)e=this._updateNode(new X(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(h.tokens.xor);)e=this._updateNode(new X(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(h.tokens.and);)e=this._updateNode(new X(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([h.tokens.equal_equal,h.tokens.not_equal])?this._updateNode(new X(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([h.tokens.less_than,h.tokens.greater_than,h.tokens.less_than_equal,h.tokens.greater_than_equal]);)e=this._updateNode(new X(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([h.tokens.shift_left,h.tokens.shift_right]);)e=this._updateNode(new X(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([h.tokens.plus,h.tokens.minus]);)e=this._updateNode(new X(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([h.tokens.star,h.tokens.forward_slash,h.tokens.modulo]);)e=this._updateNode(new X(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([h.tokens.minus,h.tokens.bang,h.tokens.tilde,h.tokens.star,h.tokens.and])?this._updateNode(new F(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(h.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(h.tokens.bracket_right,"Expected ']'.");let t=this._updateNode(new me(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(h.tokens.period)){let e=this._consume(h.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new fe(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return b.void;case"bool":return b.bool;case"i32":return b.i32;case"u32":return b.u32;case"f32":return b.f32;case"f16":return b.f16;case"vec2f":return x.vec2f;case"vec3f":return x.vec3f;case"vec4f":return x.vec4f;case"vec2i":return x.vec2i;case"vec3i":return x.vec3i;case"vec4i":return x.vec4i;case"vec2u":return x.vec2u;case"vec3u":return x.vec3u;case"vec4u":return x.vec4u;case"vec2h":return x.vec2h;case"vec3h":return x.vec3h;case"vec4h":return x.vec4h;case"mat2x2f":return x.mat2x2f;case"mat2x3f":return x.mat2x3f;case"mat2x4f":return x.mat2x4f;case"mat3x2f":return x.mat3x2f;case"mat3x3f":return x.mat3x3f;case"mat3x4f":return x.mat3x4f;case"mat4x2f":return x.mat4x2f;case"mat4x3f":return x.mat4x3f;case"mat4x4f":return x.mat4x4f;case"mat2x2h":return x.mat2x2h;case"mat2x3h":return x.mat2x3h;case"mat2x4h":return x.mat2x4h;case"mat3x2h":return x.mat3x2h;case"mat3x3h":return x.mat3x3h;case"mat3x4h":return x.mat3x4h;case"mat4x2h":return x.mat4x2h;case"mat4x3h":return x.mat4x3h;case"mat4x4h":return x.mat4x4h;case"mat2x2i":return x.mat2x2i;case"mat2x3i":return x.mat2x3i;case"mat2x4i":return x.mat2x4i;case"mat3x2i":return x.mat3x2i;case"mat3x3i":return x.mat3x3i;case"mat3x4i":return x.mat3x4i;case"mat4x2i":return x.mat4x2i;case"mat4x3i":return x.mat4x3i;case"mat4x4i":return x.mat4x4i;case"mat2x2u":return x.mat2x2u;case"mat2x3u":return x.mat2x3u;case"mat2x4u":return x.mat2x4u;case"mat3x2u":return x.mat3x2u;case"mat3x3u":return x.mat3x3u;case"mat3x4u":return x.mat3x4u;case"mat4x2u":return x.mat4x2u;case"mat4x3u":return x.mat4x3u;case"mat4x4u":return x.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new J(s,r)):this._updateNode(new je(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new Mt(n,r.value))}return this._updateNode(new q(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?b.i32:n.endsWith("u")||n.endsWith("U")?b.u32:b.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new N(new d(s,this._exec.getTypeInfo(r)),r))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,b.u32),this._updateNode(new N(new d(n,this._exec.getTypeInfo(b.u32)),b.u32))}if(this._match([h.tokens.decimal_float_literal,h.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));let s=parseFloat(n);this._validateTypeRange(s,r?b.f16:b.f32);let a=r?b.f16:b.f32;return this._updateNode(new N(new d(s,this._exec.getTypeInfo(a)),a))}if(this._match([h.keywords.true,h.keywords.false])){let n=this._previous().toString()===h.keywords.true.rule;return this._updateNode(new N(new d(n?1:0,this._exec.getTypeInfo(b.bool)),b.bool))}if(this._check(h.tokens.paren_left))return this._paren_expression();if(this._match(h.keywords.bitcast)){this._consume(h.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(h.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return this._updateNode(new Wt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new J(e,t))}_argument_expression_list(){if(!this._match(h.tokens.paren_left))return null;let e=[];do{if(this._check(h.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(h.tokens.comma));return this._consume(h.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(h.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(h.tokens.paren_right),e}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected name for struct.").toString();this._consume(h.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(h.tokens.brace_right);){let a=this._attribute(),i=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let o=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=o),this._check(h.tokens.brace_right)?this._match(h.tokens.comma):this._consume(h.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Ht(i,c,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new ne(t,n,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(h.tokens.equal)){let t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof N){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof N&&(e.type=e.value.type.name==="x32"?b.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(h.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(h.keywords.const))return null;let t=this._consume(h.tokens.name,"Expected variable name"),n=this._currentLine,r=null;if(this._match(h.tokens.colon)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let s=null;this._consume(h.tokens.equal,"const declarations require an assignment");let a=this._short_circuit_or_expression();try{let o=[b.f32],c=a.constEvaluate(this._exec,o);c instanceof d&&this._validateTypeRange(c.value,o[0]),o[0]instanceof x&&o[0].format===null&&c.typeInfo instanceof he&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?o[0].format=b.f16:c.typeInfo.format.name==="f32"?o[0].format=b.f32:c.typeInfo.format.name==="i32"?o[0].format=b.i32:c.typeInfo.format.name==="u32"?o[0].format=b.u32:c.typeInfo.format.name==="bool"?o[0].format=b.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new N(c,o[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=a}if(r!==null&&s instanceof N){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof N&&(r=(e=s?.type)!==null&&e!==void 0?e:b.f32,r===b.x32&&(r=b.i32));let i=this._updateNode(new Oe(t.toString(),r,"","",s),n);return this._context.constants.set(i.name,i),i}_global_let_decl(){if(!this._match(h.keywords.let))return null;let e=this._currentLine,t=this._consume(h.tokens.name,"Expected variable name"),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(h.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof N){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof N&&(n=r.type.name==="x32"?b.i32:r.type);return r instanceof N&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new _e(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(h.keywords.var))return null;let e=this._currentLine,t="",n="";this._match(h.tokens.less_than)&&(t=this._consume(h.storage_class,"Expected storage_class.").toString(),this._match(h.tokens.comma)&&(n=this._consume(h.access_mode,"Expected access_mode.").toString()),this._consume(h.tokens.greater_than,"Expected '>'."));let r=this._consume(h.tokens.name,"Expected variable name"),s=null;if(this._match(h.tokens.colon)){let a=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=a)}return this._updateNode(new se(r.toString(),s,t,n,null),e)}_override_decl(){if(!this._match(h.keywords.override))return null;let e=this._consume(h.tokens.name,"Expected variable name"),t=null;if(this._match(h.tokens.colon)){let n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new He(e.toString(),t,null))}_diagnostic(){this._consume(h.tokens.paren_left,"Expected '('");let e=this._consume(h.tokens.ident,"Expected severity control name.");this._consume(h.tokens.comma,"Expected ','");let t=this._consume(h.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(h.tokens.period)&&(t+=`.${this._consume(h.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(h.tokens.paren_right,"Expected ')'"),this._updateNode(new Pt(e.toString(),t))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new bn(e.toString()))}_requires_directive(){let e=[this._consume(h.tokens.ident,"identity expected.").toString()];for(;this._match(h.tokens.comma);){let t=this._consume(h.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new vn(e))}_type_alias(){let e=this._consume(h.tokens.ident,"identity expected.");this._consume(h.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let n=this._updateNode(new Xe(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let r=this._updateNode(new Nt(n));return this._forwardTypeCount++,r}return this._updateNode(new b(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(h.template_types)){let n=this._advance().toString(),r=null,s=null;return this._match(h.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(h.tokens.comma)&&(s=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new x(n,r,s))}if(this._match(h.keywords.ptr)){let n=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),a=null;return this._match(h.tokens.comma)&&(a=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Pe(n,r.toString(),s,a))}let t=this._attribute();if(this._match(h.keywords.array)){let n=null,r=-1,s=this._previous(),a=null;if(this._match(h.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let o="";if(this._match(h.tokens.comma)){a=this._shift_expression();try{o=a.constEvaluate(this._exec).toString(),a=null}catch{o="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),r=o?parseInt(o):0}let i=this._updateNode(new be(s.toString(),t,n,r));return a&&this._deferArrayCountEval.push({arrayType:i,countNode:a}),i}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new ye(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new ye(this._previous().toString(),null,null));if(this._match(h.sampled_texture_type)||this._match(h.multisampled_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new ye(e.toString(),t,null))}if(this._match(h.storage_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(h.texel_format,"Invalid texel format.").toString();this._consume(h.tokens.comma,"Expected ',' after texel format.");let n=this._consume(h.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new ye(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(h.tokens.attr);){let t=this._consume(h.attribute_name,"Expected attribute name"),n=this._updateNode(new Qt(t.toString(),null));if(this._match(h.tokens.paren_left)){if(n.value=this._consume(h.literal_or_ident,"Expected attribute value").toString(),this._check(h.tokens.comma)){this._advance();do{let r=this._consume(h.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(h.tokens.comma))}this._consume(h.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}},Jt=class extends K{constructor(e){super(),e&&this.update(e)}update(e){let t=new Ln().parse(e);this.updateAST(t)}}});function Kt(u){let e={attributes:[],bindings:[]},t;try{t=ts(u)}catch(s){return Lr.log.error(s.message)(),e}for(let s of t.uniforms){let a=[];for(let i of s.type?.members||[])a.push({name:i.name,type:Ar(i.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:a})}for(let s of t.textures){let a={type:"texture",name:s.name,group:s.group,location:s.binding,...ns(s)};e.bindings.push(a)}for(let s of t.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let n=t.entry.vertex[0],r=n?.inputs.length||0;for(let s=0;s<r;s++){let a=n.inputs[s];if(a.locationType==="location"){let i=Ar(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:i})}}return e}function Ar(u){return u?.format?`${u.name}<${u.format.name}>`:u.name}function ts(u){try{return new Jt(u)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&e?.message&&(t+=`: ${e.message} `),typeof e=="object"&&e?.token&&(t+=e.token.line||""),new Error(t,{cause:e})}}function ns(u,e){if(u.resourceType!==oe.Texture)throw new Error("Not a texture binding");let t=u.type.name,n=u.type.format?.name,r=t.includes("cube_array")?"cube-array":t.includes("cube")?"cube":t.includes("2d_array")?"2d-array":t.includes("3d")?"3d":t.includes("1d")?"1d":"2d",s=t==="texture_multisampled_2d",a;return t.startsWith("texture_depth")?a="depth":n==="i32"?a="sint":n==="u32"?a="uint":a="float",{viewDimension:r,sampleType:a,multisampled:s}}var Lr,Bn=C(()=>{"use strict";Lr=O(B(),1);Er()});var Cr={};Fn(Cr,{WebGPUDevice:()=>tt});var et,tt,Dn=C(()=>{"use strict";et=O(B(),1);en();nn();qn();Me();rn();Kn();on();nr();cr();ur();xr();_r();br();un();Bn();tt=class extends et.Device{handle;adapter;adapterInfo;type="webgpu";preferredColorFormat=navigator.gpu.getPreferredCanvasFormat();preferredDepthFormat="depth24plus";features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder;get[Symbol.toStringTag](){return"WebGPUDevice"}toString(){return`WebGPUDevice(${this.id})`}constructor(e,t,n,r){super({...e,id:e.id||"webgpu-device"}),this.handle=t,this.adapter=n,this.adapterInfo=r,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,t.addEventListener("uncapturederror",a=>{a.preventDefault();let i=a instanceof GPUUncapturedErrorEvent?a.error.message:"Unknown WebGPU error";this.reportError(new Error(i),this)(),this.debug()}),this.lost=new Promise(async a=>{let i=await this.handle.lost;this._isLost=!0,a({reason:"destroyed",message:i.message})});let s=et.Device._getCanvasContextProps(e);s&&(this.canvasContext=new Ge(this,this.adapter,s)),this.commandEncoder=this.createCommandEncoder({})}destroy(){this.handle.destroy()}get isLost(){return this._isLost}getShaderLayout(e){return Kt(e)}isVertexFormatSupported(e){return!this.getVertexFormatInfo(e).webglOnly}createBuffer(e){let t=this._normalizeBufferProps(e);return new pe(this,t)}createTexture(e){return new Ie(this,e)}createExternalTexture(e){return new ct(this,e)}createShader(e){return new Se(this,e)}createSampler(e){return new Y(this,e)}createRenderPipeline(e){return new dt(this,e)}createFramebuffer(e){return new Ae(this,e)}createComputePipeline(e){return new mt(this,e)}createVertexArray(e){return new xt(this,e)}createCommandEncoder(e){return new vt(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new wt(this,e)}createFence(){return new Ce(this)}createCanvasContext(e){return new Ge(this,this.adapter,e)}createPipelineLayout(e){return new kt(this,e)}submit(e){e||(e=this.commandEncoder.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:`${this.id}-default-encoder`})),this.pushErrorScope("validation"),this.handle.queue.submit([e.handle]),this.popErrorScope(t=>{this.reportError(new Error(`${this} command submission: ${t.message}`),this)(),this.debug()})}pushErrorScope(e){this.handle.pushErrorScope(e)}popErrorScope(e){this.handle.popErrorScope().then(t=>{t&&e(t)})}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),n=this.adapterInfo.vendor||this.adapter.__brand||"unknown",r=e||"",s=t||"",a=n==="apple"?"apple":"unknown",i=this.adapterInfo.architecture||"unknown",o=this.adapterInfo.backend||"unknown",c=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:n,renderer:r,version:s,gpu:a,gpuType:c,gpuBackend:o,gpuArchitecture:i,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl"),this.handle.features.has("chromium-experimental-norm16-texture-formats")&&e.add("norm16-renderable-webgl"),this.handle.features.has("chromium-experimental-snorm16-texture-formats")&&e.add("snorm16-renderable-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let n of t)e.add(n);return new et.DeviceFeatures(Array.from(e),this.props._disabledFeatures)}_getDeviceSpecificTextureFormatCapabilities(e){let{format:t}=e;return t.includes("webgl")?{format:t,create:!1,render:!1,filter:!1,blend:!1,store:!1}:e}}});var nt={};Fn(nt,{WebGPUBuffer:()=>pe,WebGPUDevice:()=>tt,WebGPUFence:()=>Ce,WebGPUSampler:()=>Y,WebGPUShader:()=>Se,WebGPUTexture:()=>Ie,getShaderLayoutFromWGSL:()=>Kt,webgpuAdapter:()=>$r});lt(nt,O(B(),1));var we=O(B(),1),On=class extends we.Adapter{type="webgpu";isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}isDeviceHandle(e){return!!(typeof GPUDevice<"u"&&e instanceof GPUDevice||e?.queue)}async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Recent Chrome browsers should work.");let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let n=t.info||await t.requestAdapterInfo?.(),r=[],s={};if(e._requestMaxLimits){r.push(...Array.from(t.features));let o=Object.keys(t.limits).filter(c=>!["minSubgroupSize","maxSubgroupSize"].includes(c));for(let c of o){let l=c,f=t.limits[l];typeof f=="number"&&(s[l]=f)}}let a=await t.requestDevice({requiredFeatures:r,requiredLimits:s}),{WebGPUDevice:i}=await Promise.resolve().then(()=>(Dn(),Cr));we.log.groupCollapsed(1,"WebGPUDevice created")();try{let o=new i(e,a,t,n);return we.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),we.log.table(1,o.info)(),o}finally{we.log.groupEnd(1)()}}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},$r=new On;Dn();en();nn();Me();rn();un();Bn();return Nr(nt);})();
13
17
  return __exports__;
14
18
  });