@luma.gl/webgpu 9.3.0-alpha.2 → 9.3.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/helpers/cpu-hotspot-profiler.d.ts +54 -0
- package/dist/adapter/helpers/cpu-hotspot-profiler.d.ts.map +1 -0
- package/dist/adapter/helpers/cpu-hotspot-profiler.js +26 -0
- package/dist/adapter/helpers/cpu-hotspot-profiler.js.map +1 -0
- package/dist/adapter/helpers/generate-mipmaps-webgpu.d.ts +7 -0
- package/dist/adapter/helpers/generate-mipmaps-webgpu.d.ts.map +1 -0
- package/dist/adapter/helpers/generate-mipmaps-webgpu.js +490 -0
- package/dist/adapter/helpers/generate-mipmaps-webgpu.js.map +1 -0
- package/dist/adapter/helpers/get-bind-group.d.ts +2 -1
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +31 -21
- package/dist/adapter/helpers/get-bind-group.js.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts +7 -0
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +58 -15
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-buffer.js +1 -1
- package/dist/adapter/resources/webgpu-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +5 -4
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +23 -5
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +14 -6
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +19 -3
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +6 -0
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +16 -0
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-pipeline-layout.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-pipeline-layout.js +1 -2
- package/dist/adapter/resources/webgpu-pipeline-layout.js.map +1 -1
- package/dist/adapter/resources/webgpu-query-set.d.ts +33 -4
- package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-query-set.js +145 -4
- package/dist/adapter/resources/webgpu-query-set.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +3 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +74 -30
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +7 -4
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +26 -15
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +4 -0
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture-view.d.ts +6 -0
- package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture-view.js +47 -11
- package/dist/adapter/resources/webgpu-texture-view.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture.d.ts +10 -4
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +116 -57
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -1
- package/dist/adapter/webgpu-canvas-context.d.ts +2 -0
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +78 -19
- package/dist/adapter/webgpu-canvas-context.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts +5 -1
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +113 -9
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/adapter/webgpu-presentation-context.d.ts +25 -0
- package/dist/adapter/webgpu-presentation-context.d.ts.map +1 -0
- package/dist/adapter/webgpu-presentation-context.js +144 -0
- package/dist/adapter/webgpu-presentation-context.js.map +1 -0
- package/dist/dist.dev.js +2864 -1702
- package/dist/dist.min.js +167 -8
- package/dist/index.cjs +1363 -225
- package/dist/index.cjs.map +4 -4
- package/package.json +5 -5
- package/src/adapter/helpers/cpu-hotspot-profiler.ts +70 -0
- package/src/adapter/helpers/generate-mipmaps-webgpu.ts +583 -0
- package/src/adapter/helpers/get-bind-group.ts +37 -22
- package/src/adapter/resources/webgpu-buffer.ts +61 -15
- package/src/adapter/resources/webgpu-command-buffer.ts +1 -1
- package/src/adapter/resources/webgpu-command-encoder.ts +32 -6
- package/src/adapter/resources/webgpu-compute-pass.ts +14 -6
- package/src/adapter/resources/webgpu-compute-pipeline.ts +21 -3
- package/src/adapter/resources/webgpu-framebuffer.ts +21 -0
- package/src/adapter/resources/webgpu-pipeline-layout.ts +1 -2
- package/src/adapter/resources/webgpu-query-set.ts +185 -9
- package/src/adapter/resources/webgpu-render-pass.ts +82 -34
- package/src/adapter/resources/webgpu-render-pipeline.ts +36 -19
- package/src/adapter/resources/webgpu-sampler.ts +5 -0
- package/src/adapter/resources/webgpu-texture-view.ts +51 -11
- package/src/adapter/resources/webgpu-texture.ts +142 -93
- package/src/adapter/resources/webgpu-vertex-array.ts +1 -1
- package/src/adapter/webgpu-canvas-context.ts +91 -26
- package/src/adapter/webgpu-device.ts +128 -9
- package/src/adapter/webgpu-presentation-context.ts +180 -0
package/dist/dist.min.js
CHANGED
|
@@ -4,15 +4,174 @@
|
|
|
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 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
|
|
9
|
-
"${r.message}"`),this)(),this.device.debug()})}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings=
|
|
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
|
-
"${
|
|
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==`
|
|
7
|
+
"use strict";var __exports__=(()=>{var Yr=Object.create;var yt=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var Zr=Object.getOwnPropertyNames;var Kr=Object.getPrototypeOf,Jr=Object.prototype.hasOwnProperty;var B=(u,e)=>()=>(u&&(e=u(u=0)),e);var es=(u,e)=>()=>(e||u((e={exports:{}}).exports,e),e.exports),Xn=(u,e)=>{for(var t in e)yt(u,t,{get:e[t],enumerable:!0})},gt=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Zr(e))!Jr.call(u,r)&&r!==t&&yt(u,r,{get:()=>e[r],enumerable:!(n=jr(e,r))||n.enumerable});return u},xt=(u,e,t)=>(gt(u,e,"default"),t&>(t,e,"default")),F=(u,e,t)=>(t=u!=null?Yr(Kr(u)):{},gt(e||!u||!u.__esModule?yt(t,"default",{value:u,enumerable:!0}):t,u)),ts=u=>gt(yt({},"__esModule",{value:!0}),u);var M=es((Ps,Yn)=>{Yn.exports=globalThis.luma});var ue,ye,dn=B(()=>{"use strict";ue=F(M(),1),ye=class extends ue.Buffer{device;handle;byteLength;paddedByteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=t.byteLength||t.data?.byteLength||0,this.paddedByteLength=Math.ceil(this.byteLength/4)*4;let n=Boolean(this.props.onMapped||t.data),r=this.paddedByteLength;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()}),this.props.handle?this.trackReferencedMemory(r,"Buffer"):this.trackAllocatedMemory(r)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.props.handle?this.trackDeallocatedReferencedMemory("Buffer"):(this.trackDeallocatedMemory(),this.handle.destroy()),this.destroyed=!0,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 r=Math.ceil(n/4)*4,a=(this.usage&ue.Buffer.MAP_WRITE)!==0?null:this._getMappableBuffer(ue.Buffer.MAP_WRITE|ue.Buffer.COPY_SRC,0,this.paddedByteLength),i=a||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),await i.handle.mapAsync(GPUMapMode.WRITE,t,r);let o=i.handle.getMappedRange(t,r),l=o.slice(0,n);await e(l,"mapped"),new Uint8Array(o).set(new Uint8Array(l),0),i.handle.unmap(),a&&this._copyBuffer(a,t,r)}finally{this.device.popErrorScope(o=>{this.device.reportError(new Error(`${this}.mapAndWriteAsync() ${o.message}`),this)(),this.device.debug()}),a?.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){let r=t+n;if(r>this.byteLength)throw new Error("Mapping range exceeds buffer size");let s=t,a=n,i=0,o="mapped";if((t%8!==0||n%4!==0)&&(s=Math.floor(t/8)*8,a=Math.ceil(r/4)*4-s,i=t-s,o="copied"),s+a>this.paddedByteLength)throw new Error("Mapping range exceeds buffer size");let c=(this.usage&ue.Buffer.MAP_READ)!==0?null:this._getMappableBuffer(ue.Buffer.MAP_READ|ue.Buffer.COPY_DST,0,this.paddedByteLength),f=c||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),c&&c._copyBuffer(this,s,a),await f.handle.mapAsync(GPUMapMode.READ,s,a);let b=f.handle.getMappedRange(s,a),v=o==="mapped"?b:b.slice(i,i+n),k=await e(v,o);return f.handle.unmap(),k}finally{this.device.popErrorScope(b=>{this.device.reportError(new Error(`${this}.mapAndReadAsync() ${b.message}`),this)(),this.device.debug()}),c?.destroy()}}readSyncWebGL(e,t){throw new Error("Not implemented")}_getMappableBuffer(e,t,n){return ue.log.warn(`${this} is not readable, creating a temporary Buffer`),new ye(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 $e(u){if(u.includes("webgl"))throw new Error("webgl-only format");return u}var pn=B(()=>{"use strict"});var jn,Z,Ye=B(()=>{"use strict";jn=F(M(),1),Z=class extends jn.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.destroyed||(this.destroyResource(),this.handle=null)}}});function Q(u){let e=u.userData[ns];return e?.enabled?e:null}function bt(u){return u.userData[Zn]||null}function mn(u,e){u.userData[Zn]=e}function C(){return globalThis.performance?.now?.()??Date.now()}var ns,Zn,we=B(()=>{"use strict";ns="cpu-hotspot-profiler",Zn="cpu-hotspot-submit-reason"});var Kn,je,Jn=B(()=>{"use strict";Kn=F(M(),1);we();je=class extends Kn.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.destroyed||(this.destroyResource(),this.handle=null)}_reinitialize(e){this.texture=e;let t=Q(this.device);this.device.pushErrorScope("validation");let n=t?C():0,r=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});t&&(t.textureViewReinitializeCount=(t.textureViewReinitializeCount||0)+1,t.textureViewReinitializeTimeMs=(t.textureViewReinitializeTimeMs||0)+(C()-n)),this.device.popErrorScope(s=>{this.device.reportError(new Error(`TextureView constructor: ${s.message}`),this)(),this.device.debug()}),r.label=this.props.id,this.handle=r}}});var se,De,gn=B(()=>{"use strict";se=F(M(),1);pn();Ye();Jn();De=class extends se.Texture{device;handle;sampler;view;_allocatedByteLength=0;constructor(e,t){super(e,t,{byteAlignment:256}),this.device=e,t.sampler instanceof Z?this.sampler=t.sampler:t.sampler===void 0?this.sampler=this.device.getDefaultSampler():(this.sampler=new Z(this.device,t.sampler||{}),this.attachResource(this.sampler)),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||se.Texture.TEXTURE|se.Texture.COPY_DST,dimension:this.baseDimension,format:$e(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.view=new je(this.device,{...this.props,texture:this,mipLevelCount:this.mipLevels,arrayLayerCount:this.dimension!=="3d"?this.depth:1}),this.attachResource(this.view),this._initializeData(t.data),this._allocatedByteLength=this.getAllocatedByteLength(),this.props.handle?this.trackReferencedMemory(this._allocatedByteLength,"Texture"):this.trackAllocatedMemory(this._allocatedByteLength,"Texture")}destroy(){this.destroyed||(!this.props.handle&&this.handle?(this.trackDeallocatedMemory("Texture"),this.handle.destroy()):this.handle&&this.trackDeallocatedReferencedMemory("Texture"),this.destroyResource(),this.handle=null)}createView(e){return new je(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}}generateMipmapsWebGL(){se.log.warn(`${this}: generateMipmaps not supported in WebGPU`)()}getImageDataLayout(e){return{byteLength:0,bytesPerRow:0,rowsPerImage:0}}readBuffer(e={},t){let{x:n,y:r,z:s,width:a,height:i,depthOrArrayLayers:o,mipLevel:l,aspect:c}=this._getSupportedColorReadOptions(e),f=this.computeMemoryLayout({x:n,y:r,z:s,width:a,height:i,depthOrArrayLayers:o,mipLevel:l}),{bytesPerRow:b,rowsPerImage:v,byteLength:k}=f,E=t||this.device.createBuffer({byteLength:k,usage:se.Buffer.COPY_DST|se.Buffer.MAP_READ});if(E.byteLength<k)throw new Error(`${this} readBuffer target is too small (${E.byteLength} < ${k})`);let A=E.handle,L=this.device.handle;this.device.pushErrorScope("validation");let D=L.createCommandEncoder();D.copyTextureToBuffer({texture:this.handle,origin:{x:n,y:r,z:s},mipLevel:l,aspect:c},{buffer:A,offset:0,bytesPerRow:b,rowsPerImage:v},{width:a,height:i,depthOrArrayLayers:o});let I=D.finish();return this.device.handle.queue.submit([I]),this.device.popErrorScope(S=>{this.device.reportError(new Error(`${this} readBuffer: ${S.message}`),this)(),this.device.debug()}),E}async readDataAsync(e={}){let t=this.readBuffer(e),n=await t.readAsync();return t.destroy(),n.buffer}writeBuffer(e,t={}){let n=this._normalizeTextureWriteOptions(t),{x:r,y:s,z:a,width:i,height:o,depthOrArrayLayers:l,mipLevel:c,aspect:f,byteOffset:b,bytesPerRow:v,rowsPerImage:k}=n,E=this.device.handle;this.device.pushErrorScope("validation");let A=E.createCommandEncoder();A.copyBufferToTexture({buffer:e.handle,offset:b,bytesPerRow:v,rowsPerImage:k},{texture:this.handle,origin:{x:r,y:s,z:a},mipLevel:c,aspect:f},{width:i,height:o,depthOrArrayLayers:l});let L=A.finish();this.device.handle.queue.submit([L]),this.device.popErrorScope(D=>{this.device.reportError(new Error(`${this} writeBuffer: ${D.message}`),this)(),this.device.debug()})}writeData(e,t={}){let n=this.device,r=this._normalizeTextureWriteOptions(t),{x:s,y:a,z:i,width:o,height:l,depthOrArrayLayers:c,mipLevel:f,aspect:b,byteOffset:v}=r,k=e,E=this.device.getTextureFormatInfo(this.format),A=se.textureFormatDecoder.computeMemoryLayout({format:this.format,width:o,height:l,depth:c,byteAlignment:1}),L=t.bytesPerRow??A.bytesPerRow,D=t.rowsPerImage??A.rowsPerImage,I=o,S=l;if(E.compressed){let O=E.blockWidth||1,V=E.blockHeight||1;I=Math.ceil(o/O)*O,S=Math.ceil(l/V)*V}this.device.pushErrorScope("validation"),n.handle.queue.writeTexture({texture:this.handle,mipLevel:f,aspect:b,origin:{x:s,y:a,z:i}},k,{offset:v,bytesPerRow:L,rowsPerImage:D},{width:I,height:S,depthOrArrayLayers:c}),this.device.popErrorScope(O=>{this.device.reportError(new Error(`${this} writeData: ${O.message}`),this)(),this.device.debug()})}_reinitialize(e,t){let n=t?.width??e.width??this.width,r=t?.height??e.height??this.height,s=t?.depth??this.depth,a=t?.format??this.format,i=n!==this.width||r!==this.height||s!==this.depth||a!==this.format;if(e.label||=this.id,this.handle=e,this.width=n,this.height=r,t?.depth!==void 0&&(this.depth=s),t?.format!==void 0&&(this.format=a),this.props.handle=e,t?.width!==void 0&&(this.props.width=t.width),t?.height!==void 0&&(this.props.height=t.height),t?.depth!==void 0&&(this.props.depth=t.depth),t?.format!==void 0&&(this.props.format=t.format),i){let o=this.getAllocatedByteLength();o!==this._allocatedByteLength&&(this._allocatedByteLength=o,this.trackReferencedMemory(o,"Texture"))}this.view._reinitialize(this)}}});var er,_t,tr=B(()=>{"use strict";er=F(M(),1);Ye();_t=class extends er.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 Z?e:new Z(this.device,e),this}}});var nr,Pe,yn=B(()=>{"use strict";nr=F(M(),1),Pe=class extends nr.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 le(u){return u.depthStencil=u.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},u.depthStencil}function vt(u){return le(u).stencilFront}function wt(u){return le(u).stencilBack}function te(u,e,t){kt.log.warn(`${u} parameter not supported in WebGPU`)()}function rr(u,e={}){Object.assign(u,{...ss,...u}),is(u,e)}function is(u,e){for(let[t,n]of Object.entries(e)){let r=rs[t];r?r(t,n,u):kt.log.error(`Illegal parameter ${t} in WebGPU`)()}}function sr(u,e){return u.fragment.targets=u.fragment?.targets||[],Array.isArray(u.fragment?.targets)||kt.log.warn("parameters: no targets array")(),u.fragment?.targets?.length===0&&u.fragment.targets?.push({}),u.fragment?.targets?.[0]}function ke(u,e){let t=sr(u,e);return t.blend=t.blend||{color:{},alpha:{}},t.blend}var kt,rs,ss,ir=B(()=>{"use strict";kt=F(M(),1);rs={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=le(t);n.depthWriteEnabled=e}},depthCompare:(u,e,t)=>{let n=le(t);n.depthCompare=e},depthFormat:(u,e,t)=>{let n=le(t);n.format=e},depthBias:(u,e,t)=>{let n=le(t);n.depthBias=e},depthBiasSlopeScale:(u,e,t)=>{let n=le(t);n.depthBiasSlopeScale=e},depthBiasClamp:(u,e,t)=>{let n=le(t);n.depthBiasClamp=e},stencilReadMask:(u,e,t)=>{let n=le(t);n.stencilReadMask=e},stencilWriteMask:(u,e,t)=>{let n=le(t);n.stencilWriteMask=e},stencilCompare:(u,e,t)=>{let n=vt(t),r=wt(t);n.compare=e,r.compare=e},stencilPassOperation:(u,e,t)=>{let n=vt(t),r=wt(t);n.passOp=e,r.passOp=e},stencilFailOperation:(u,e,t)=>{let n=vt(t),r=wt(t);n.failOp=e,r.failOp=e},stencilDepthFailOperation:(u,e,t)=>{let n=vt(t),r=wt(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=sr(t,0);n.writeMask=e},blend:(u,e,t)=>{e&&ke(t,0)},blendColorOperation:(u,e,t)=>{let n=ke(t,0);n.color=n.color||{},n.color.operation=e},blendColorSrcFactor:(u,e,t)=>{let n=ke(t,0);n.color=n.color||{},n.color.srcFactor=e},blendColorDstFactor:(u,e,t)=>{let n=ke(t,0);n.color.dstFactor=e},blendAlphaOperation:(u,e,t)=>{let n=ke(t,0);n.alpha=n.alpha||{},n.alpha.operation=e},blendAlphaSrcFactor:(u,e,t)=>{let n=ke(t,0);n.alpha=n.alpha||{},n.alpha.srcFactor=e},blendAlphaDstFactor:(u,e,t)=>{let n=ke(t,0);n.alpha=n.alpha||{},n.alpha.dstFactor=e},unclippedDepth:te,provokingVertex:te,polygonMode:te,polygonOffsetLine:te,clipDistance0:te,clipDistance1:te,clipDistance2:te,clipDistance3:te,clipDistance4:te,clipDistance5:te,clipDistance6:te,clipDistance7:te};ss={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"}});function Ze(u,e,t,n){let r=as(n,t);u.pushErrorScope("validation");let s=u.handle.createBindGroup({layout:e,entries:r});return u.popErrorScope(a=>{K.log.error(`bindGroup creation: ${a.message}`,s)()}),s}function ar(u,e,t){let n=u.bindings.find(r=>r.name===e||`${r.name.toLocaleLowerCase()}uniforms`===e.toLocaleLowerCase());return!n&&!t?.ignoreWarnings&&K.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),n||null}function as(u,e){let t=[];for(let[n,r]of Object.entries(u)){let s=e.bindings.find(o=>o.name===n),a=s||ar(e,n);if(!(!s&&a?a.name in u:!1)){let o=a?or(r,a.location,void 0,n):null;if(o&&t.push(o),r instanceof K.Texture){let l=ar(e,`${n}Sampler`,{ignoreWarnings:!0}),c=l?or(r,l.location,{sampler:!0},n):null;c&&t.push(c)}}}return t}function or(u,e,t,n="unknown"){return u instanceof K.Buffer?{binding:e,resource:{buffer:u.handle}}:u instanceof K.Sampler?{binding:e,resource:u.handle}:u instanceof K.TextureView?{binding:e,resource:u.handle}:u instanceof K.Texture?t?.sampler?{binding:e,resource:u.sampler.handle}:{binding:e,resource:u.view.handle}:(K.log.warn(`invalid binding ${n}`,u),null)}var K,xn=B(()=>{"use strict";K=F(M(),1)});function bn(u){if(u.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${u}`);return u}function ur(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 l of r.attributes){let c=l.attribute,f=cr(u,c,n),b=f?.location;o=l.format||r.format,a=f?.stepMode||(f?.name.startsWith("instance")?"instance":"vertex"),s.push({format:bn(o),offset:l.byteOffset,shaderLocation:b}),i+=(0,Oe.getVertexFormatInfo)(o).byteLength}else{let l=cr(u,r.name,n);if(!l)continue;i=(0,Oe.getVertexFormatInfo)(o).byteLength,a=l.stepMode||(l.name.startsWith("instance")?"instance":"vertex"),s.push({format:bn(o),offset:0,shaderLocation:l.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,Oe.getVertexFormatInfo)("float32x3").byteLength,stepMode:r.stepMode||(r.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:bn("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 cr(u,e,t){let n=u.attributes.find(r=>r.name===e);if(!n)return Oe.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 Oe,lr=B(()=>{"use strict";Oe=F(M(),1)});var Me,hr,St,fr=B(()=>{"use strict";Me=F(M(),1);ir();pn();xn();lr();hr={},St=class extends Me.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();Me.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),Me.log.probe(1,JSON.stringify(n,null,2))(),Me.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=t.bindings||hr}destroy(){this.handle=null}setBindings(e){let t=!1;for(let[n,r]of Object.entries(e))this._bindings[n]!==r&&(t||((this._bindings===this.props.bindings||this._bindings===hr)&&(this._bindings={...this._bindings}),t=!0),this._bindings[n]=r);t&&(this._bindGroup=null)}draw(e){let t=e.renderPass,n=e.instanceCount&&e.instanceCount>0?e.instanceCount:1;this.device.pushErrorScope("validation"),t.handle.setPipeline(this.handle),this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} setPipeline failed:
|
|
10
|
+
"${s.message}"`),this)(),this.device.debug()});let r=this._getBindGroup(e.bindings);return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,n,e.firstIndex||0,e.baseVertex||0,e.firstInstance||0):t.handle.draw(e.vertexCount||0,n,e.firstVertex||0,e.firstInstance||0),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(e){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),e?Ze(this.device,this._bindGroupLayout,this.shaderLayout,e):(this._bindGroup=this._bindGroup||Ze(this.device,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup))}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:ur(this.shaderLayout,this.props.bufferLayout)},t=[];if(this.props.colorAttachmentFormats)for(let i of this.props.colorAttachmentFormats)t.push(i?{format:$e(i)}:null);else t.push({format:$e(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:$e(a)}),rr(s,this.props.parameters),s}}});var dr,xe,It=B(()=>{"use strict";dr=F(M(),1),xe=class extends dr.Framebuffer{device;handle=null;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}updateAttachments(){}_reinitialize(e,t){this.colorAttachments[0]=e,this.depthStencilAttachment=t,this.width=e.texture.width,this.height=e.texture.height,this.props.width=this.width,this.props.height=this.height,this.props.colorAttachments=[e.texture],this.props.depthStencilAttachment=t?.texture||null}}});var mr,pr,Tt,gr=B(()=>{"use strict";mr=F(M(),1);xn();pr={},Tt=class extends mr.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"}),this._bindings=pr}setBindings(e){let t=!1;for(let[n,r]of Object.entries(e))this._bindings[n]!==r&&(t||(this._bindings===pr&&(this._bindings={}),t=!0),this._bindings[n]=r);t&&(this._bindGroup=null)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||Ze(this.device,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}}});var ii,ai,oi,yr,xr=B(()=>{ii=globalThis.document||{},ai=globalThis.process||{},oi=globalThis.console,yr=globalThis.navigator||{}});function At(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 _n=B(()=>{});function br(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||At()}var _r=B(()=>{_n()});function vn(u){return!u&&!br()?"Node":At(u)?"Electron":(u||yr.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var vr=B(()=>{_r();_n();xr()});var wr=B(()=>{vr()});var Ke,Et,kr=B(()=>{"use strict";Ke=F(M(),1);wr();Et=class extends Ke.VertexArray{get[Symbol.toStringTag](){return"VertexArray"}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&&(Ke.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&&(Ke.log.info(3,`setting vertex buffer ${a}`,i?.handle)(),r.handle.setVertexBuffer(a,i?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return vn()==="Chrome"}}});var Fe,Je,Sr=B(()=>{"use strict";Fe=F(M(),1);It();we();Je=class extends Fe.CanvasContext{device;handle;colorAttachment=null;depthStencilAttachment=null;framebuffer=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(),this._startObservers()}destroy(){this.framebuffer&&(this.framebuffer.destroy(),this.framebuffer=null),this.colorAttachment&&(this.colorAttachment.destroy(),this.colorAttachment=null),this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),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}),this._createDepthStencilAttachment(this.device.preferredDepthFormat)}_getCurrentFramebuffer(e={depthStencilFormat:"depth24plus"}){let t=Q(this.device),n=t?C():0;t&&(t.framebufferAcquireCount=(t.framebufferAcquireCount||0)+1,t.activeDefaultFramebufferAcquireDepth=(t.activeDefaultFramebufferAcquireDepth||0)+1);try{let r=this._getCurrentTexture();if(r.width!==this.drawingBufferWidth||r.height!==this.drawingBufferHeight){let[s,a]=this.getDrawingBufferSize();this.drawingBufferWidth=r.width,this.drawingBufferHeight=r.height,Fe.log.log(1,`${this}: Resized to compensate for initial canvas size mismatch ${s}x${a} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e?.depthStencilFormat),this.framebuffer||=new xe(this.device,{id:`${this.id}#framebuffer`,colorAttachments:[r],depthStencilAttachment:null}),this.framebuffer._reinitialize(r.view,e?.depthStencilFormat&&this.depthStencilAttachment?.view||null),this.framebuffer}finally{t&&(t.activeDefaultFramebufferAcquireDepth=(t.activeDefaultFramebufferAcquireDepth||1)-1,t.framebufferAcquireTimeMs=(t.framebufferAcquireTimeMs||0)+(C()-n))}}_getCurrentTexture(){let e=Q(this.device),t=e?C():0,n=this.handle.getCurrentTexture();return e&&(e.currentTextureAcquireCount=(e.currentTextureAcquireCount||0)+1,e.currentTextureAcquireTimeMs=(e.currentTextureAcquireTimeMs||0)+(C()-t)),this.colorAttachment?(this.colorAttachment._reinitialize(n,{handle:n,format:this.device.preferredColorFormat,width:n.width,height:n.height}),this.colorAttachment):(this.colorAttachment=this.device.createTexture({id:`${this.id}#color-texture`,handle:n,format:this.device.preferredColorFormat,width:n.width,height:n.height}),this.colorAttachment)}_createDepthStencilAttachment(e){return(!this.depthStencilAttachment||this.depthStencilAttachment.width!==this.drawingBufferWidth||this.depthStencilAttachment.height!==this.drawingBufferHeight||this.depthStencilAttachment.format!==e)&&(this.depthStencilAttachment?.destroy(),this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,usage:Fe.Texture.RENDER_ATTACHMENT,format:e,width:this.drawingBufferWidth,height:this.drawingBufferHeight})),this.depthStencilAttachment}}});var Ve,Ct,Ir=B(()=>{"use strict";Ve=F(M(),1);It();we();Ct=class extends Ve.PresentationContext{device;handle;colorAttachment=null;depthStencilAttachment=null;framebuffer=null;get[Symbol.toStringTag](){return"WebGPUPresentationContext"}constructor(e,t={}){super(t);let n=`${this[Symbol.toStringTag]}(${this.id})`,r=this.canvas.getContext("webgpu");if(!r)throw new Error(`${n}: Failed to create WebGPU presentation context`);this.device=e,this.handle=r,this._setAutoCreatedCanvasId(`${this.device.id}-presentation-canvas`),this._configureDevice(),this._startObservers()}destroy(){this.framebuffer&&(this.framebuffer.destroy(),this.framebuffer=null),this.colorAttachment&&(this.colorAttachment.destroy(),this.colorAttachment=null),this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.handle.unconfigure(),super.destroy()}present(){this.device.submit()}_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}),this._createDepthStencilAttachment(this.device.preferredDepthFormat)}_getCurrentFramebuffer(e={depthStencilFormat:"depth24plus"}){let t=Q(this.device),n=t?C():0;t&&(t.framebufferAcquireCount=(t.framebufferAcquireCount||0)+1);try{let r=this._getCurrentTexture();if(r.width!==this.drawingBufferWidth||r.height!==this.drawingBufferHeight){let[s,a]=this.getDrawingBufferSize();this.drawingBufferWidth=r.width,this.drawingBufferHeight=r.height,Ve.log.log(1,`${this[Symbol.toStringTag]}(${this.id}): Resized to compensate for initial canvas size mismatch ${s}x${a} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e.depthStencilFormat),this.framebuffer||=new xe(this.device,{id:`${this.id}#framebuffer`,colorAttachments:[r],depthStencilAttachment:null}),this.framebuffer._reinitialize(r.view,e?.depthStencilFormat&&this.depthStencilAttachment?.view||null),this.framebuffer}finally{t&&(t.framebufferAcquireTimeMs=(t.framebufferAcquireTimeMs||0)+(C()-n))}}_getCurrentTexture(){let e=Q(this.device),t=e?C():0,n=this.handle.getCurrentTexture();return e&&(e.currentTextureAcquireCount=(e.currentTextureAcquireCount||0)+1,e.currentTextureAcquireTimeMs=(e.currentTextureAcquireTimeMs||0)+(C()-t)),this.colorAttachment?(this.colorAttachment._reinitialize(n,{handle:n,format:this.device.preferredColorFormat,width:n.width,height:n.height}),this.colorAttachment):(this.colorAttachment=this.device.createTexture({id:`${this.id}#color-texture`,handle:n,format:this.device.preferredColorFormat,width:n.width,height:n.height}),this.colorAttachment)}_createDepthStencilAttachment(e){return(!this.depthStencilAttachment||this.depthStencilAttachment.width!==this.drawingBufferWidth||this.depthStencilAttachment.height!==this.drawingBufferHeight||this.depthStencilAttachment.format!==e)&&(this.depthStencilAttachment?.destroy(),this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,usage:Ve.Texture.RENDER_ATTACHMENT,format:e,width:this.drawingBufferWidth,height:this.drawingBufferHeight})),this.depthStencilAttachment}}});var Tr,Lt,Ar=B(()=>{"use strict";Tr=F(M(),1),Lt=class extends Tr.CommandBuffer{device;handle;constructor(e,t){super(e.device,t),this.device=e.device,this.handle=this.props.handle||e.handle.finish({label:t?.id||"unnamed-command-buffer"})}}});function os(u){return{r:u[0],g:u[1],b:u[2],a:u[3]}}var Se,Bt,Er=B(()=>{"use strict";Se=F(M(),1);we();Bt=class extends Se.RenderPass{device;handle;framebuffer;pipeline=null;bindings={};constructor(e,t={}){super(e,t),this.device=e;let{props:n}=this;this.framebuffer=n.framebuffer||e.getCanvasContext().getCurrentFramebuffer();let r=Q(this.device);if(r){let a=n.framebuffer?"explicitFramebufferRenderPassCount":"defaultFramebufferRenderPassCount";r[a]=(r[a]||0)+1}let s=r?C():0;try{let a=r?C():0,i=this.getRenderPassDescriptor(this.framebuffer);if(n.occlusionQuerySet&&(i.occlusionQuerySet=n.occlusionQuerySet.handle),n.timestampQuerySet){let l=n.timestampQuerySet;l?._invalidateResults(),i.timestampWrites=l?{querySet:l.handle,beginningOfPassWriteIndex:n.beginTimestampIndex,endOfPassWriteIndex:n.endTimestampIndex}:void 0}if(r&&(r.renderPassDescriptorAssemblyCount=(r.renderPassDescriptorAssemblyCount||0)+1,r.renderPassDescriptorAssemblyTimeMs=(r.renderPassDescriptorAssemblyTimeMs||0)+(C()-a)),!e.commandEncoder)throw new Error("commandEncoder not available");this.device.pushErrorScope("validation");let o=r?C():0;this.handle=this.props.handle||e.commandEncoder.handle.beginRenderPass(i),r&&(r.renderPassBeginCount=(r.renderPassBeginCount||0)+1,r.renderPassBeginTimeMs=(r.renderPassBeginTimeMs||0)+(C()-o)),this.device.popErrorScope(l=>{this.device.reportError(new Error(`${this} creation failed:
|
|
11
|
+
"${l.message}"`),this)(),this.device.debug()}),this.handle.label=this.props.id,Se.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),Se.log.probe(3,JSON.stringify(i,null,2))(),Se.log.groupEnd(3)()}finally{r&&(r.renderPassSetupCount=(r.renderPassSetupCount||0)+1,r.renderPassSetupTimeMs=(r.renderPassSetupTimeMs||0)+(C()-s))}}destroy(){this.destroyResource()}end(){this.destroyed||(this.handle.end(),this.destroy())}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.bindings=e;let t=this.pipeline?._getBindGroup(e);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:os(this.props.clearColors?.[r]||this.props.clearColor||Se.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 Cr,$t,Lr=B(()=>{"use strict";Cr=F(M(),1),$t=class extends Cr.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t={}){super(e,t),this.device=e;let{props:n}=this,r;if(n.timestampQuerySet){let s=n.timestampQuerySet;s&&(s._invalidateResults(),r={querySet:s.handle,beginningOfPassWriteIndex:n.beginTimestampIndex,endOfPassWriteIndex:n.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder.handle.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){this.destroyResource()}end(){this.destroyed||(this.handle.end(),this.destroy())}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 Br,Dt,$r=B(()=>{"use strict";Br=F(M(),1);Ar();Er();Lr();Dt=class extends Br.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(){this.destroyResource()}finish(e){this.device.pushErrorScope("validation");let t=new Lt(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()}),this.destroy(),t}beginRenderPass(e={}){return new Bt(this.device,this._applyTimeProfilingToPassProps(e))}beginComputePass(e={}){return new $t(this.device,this._applyTimeProfilingToPassProps(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)}writeTimestamp(e,t){e._invalidateResults();let n=this.handle.writeTimestamp;if(n){n.call(this.handle,e.handle,t);return}this.handle.beginComputePass({timestampWrites:{querySet:e.handle,beginningOfPassWriteIndex:t}}).end()}}});var Ie,et,Dr=B(()=>{"use strict";Ie=F(M(),1);we();et=class extends Ie.QuerySet{device;handle;_resolveBuffer=null;_readBuffer=null;_cachedResults=null;_readResultsPromise=null;_resultsPendingResolution=!1;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.destroyed||(this.handle?.destroy(),this.destroyResource(),this.handle=null)}isResultAvailable(e){return this._cachedResults?e===void 0?!0:e>=0&&e<this._cachedResults.length:!1}async readResults(e){let t=e?.firstQuery||0,n=e?.queryCount||this.props.count-t;if(t<0||n<0||t+n>this.props.count)throw new Error("Query read range is out of bounds");let r=!0;for(;r;){this._readResultsPromise||(this._readResultsPromise=this._readAllResults());let a=await this._readResultsPromise;if(r=this._resultsPendingResolution,!r)return a.slice(t,t+n)}throw new Error("Query read unexpectedly failed to resolve")}async readTimestampDuration(e,t){if(this.props.type!=="timestamp")throw new Error("Timestamp durations require a timestamp QuerySet");if(e<0||t<=e||t>=this.props.count)throw new Error("Timestamp duration range is out of bounds");let n=await this.readResults({firstQuery:e,queryCount:t-e+1});return Number(n[n.length-1]-n[0])/1e6}_invalidateResults(){this._cachedResults=null,this._resultsPendingResolution=!0}async _readAllResults(){this._ensureBuffers();try{if(this._resultsPendingResolution){let n=this.device.createCommandEncoder({id:`${this.id}-read-results`});n.resolveQuerySet(this,this._resolveBuffer),n.copyBufferToBuffer({sourceBuffer:this._resolveBuffer,destinationBuffer:this._readBuffer,size:this._resolveBuffer.byteLength});let r=n.finish({id:`${this.id}-read-results-command-buffer`}),s=bt(this.device)||void 0;mn(this.device,"query-readback");try{this.device.submit(r)}finally{mn(this.device,s)}}let e=await this._readBuffer.readAsync(0,this._readBuffer.byteLength),t=new BigUint64Array(e.buffer,e.byteOffset,this.props.count);return this._cachedResults=Array.from(t,n=>n),this._resultsPendingResolution=!1,this._cachedResults}finally{this._readResultsPromise=null}}_ensureBuffers(){if(this._resolveBuffer&&this._readBuffer)return;let e=this.props.count*8;this._resolveBuffer=this.device.createBuffer({id:`${this.id}-resolve-buffer`,usage:Ie.Buffer.QUERY_RESOLVE|Ie.Buffer.COPY_SRC,byteLength:e}),this.attachResource(this._resolveBuffer),this._readBuffer=this.device.createBuffer({id:`${this.id}-read-buffer`,usage:Ie.Buffer.COPY_DST|Ie.Buffer.MAP_READ,byteLength:e}),this.attachResource(this._readBuffer)}_encodeResolveToReadBuffer(e,t){if(!this._resultsPendingResolution||this._readResultsPromise)return!1;this._ensureBuffers();let n=t?.firstQuery||0,r=t?.queryCount||this.props.count-n,s=r*BigUint64Array.BYTES_PER_ELEMENT,a=n*BigUint64Array.BYTES_PER_ELEMENT;return e.resolveQuerySet(this,this._resolveBuffer,{firstQuery:n,queryCount:r,destinationOffset:a}),e.copyBufferToBuffer({sourceBuffer:this._resolveBuffer,sourceOffset:a,destinationBuffer:this._readBuffer,destinationOffset:a,size:s}),this._resultsPendingResolution=!1,!0}}});var Ot,Pt,cs,Pr=B(()=>{"use strict";Ot=F(M(),1),Pt=class extends Ot.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 of this.props.shaderLayout.bindings){let n={};switch(t.type){case"uniform":{n.buffer={type:"uniform",hasDynamicOffset:t.hasDynamicOffset,minBindingSize:t.minBindingSize};break}case"read-only-storage":{n.buffer={type:"read-only-storage",hasDynamicOffset:t.hasDynamicOffset,minBindingSize:t.minBindingSize};break}case"sampler":{n.sampler={type:t.samplerType};break}case"storage":{cs(t)?n.storageTexture={format:t.format,access:t.access,viewDimension:t.viewDimension}:n.buffer={type:"storage",hasDynamicOffset:t.hasDynamicOffset,minBindingSize:t.minBindingSize};break}case"texture":{n.texture={multisampled:t.multisampled,sampleType:t.sampleType,viewDimension:t.viewDimension};break}default:Ot.log.warn("unhandled binding type when creating pipeline descriptor")()}let r=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE;e.push({binding:t.location,visibility:t.visibility||r,...n})}return e}},cs=u=>u.format!==void 0});var Or,Ne,wn=B(()=>{"use strict";Or=F(M(),1),Ne=class extends Or.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 us(u){var e=(32768&u)>>15,t=(31744&u)>>10,n=1023&u;return t==0?(e?-1:1)*Math.pow(2,-14)*(n/Math.pow(2,10)):t==31?n?NaN:1/0*(e?-1:1):(e?-1:1)*Math.pow(2,t-15)*(1+n/Math.pow(2,10))}function hs(u){Vr[0]=u;let e=ls[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return G[0]=t<<15|31744|(r!==0?512:0),G[0];if(n===0){if(r===0)return G[0]=t<<15,G[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),G[0]=t<<15|n<<10|r>>13,G[0]):(G[0]=t<<15,G[0])}return n=n-127+15,n>=31?(G[0]=t<<15|31744,G[0]):n<=0?n<-10?(G[0]=t<<15,G[0]):(r=(8388608|r)>>1-n,G[0]=t<<15|r>>13,G[0]):(r>>=13,G[0]=t<<15|n<<10|r,G[0])}function Mr(u){let e=112+(u>>6&31)<<23|(63&u)<<17;return Rn[0]=e,Nr[0]}function fs(u,e,t,n,r,s,a,i,o){let l=n*(a>>=r)*(s>>=r)+t*a+e*i;switch(o){case"r8unorm":return[$(u,l,"8unorm",1)[0]];case"r8snorm":return[$(u,l,"8snorm",1)[0]];case"r8uint":return[$(u,l,"8uint",1)[0]];case"r8sint":return[$(u,l,"8sint",1)[0]];case"rg8unorm":{let c=$(u,l,"8unorm",2);return[c[0],c[1]]}case"rg8snorm":{let c=$(u,l,"8snorm",2);return[c[0],c[1]]}case"rg8uint":{let c=$(u,l,"8uint",2);return[c[0],c[1]]}case"rg8sint":{let c=$(u,l,"8sint",2);return[c[0],c[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let c=$(u,l,"8unorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8snorm":{let c=$(u,l,"8snorm",4);return[c[0],c[1],c[2],c[3]]}case"rgba8uint":{let c=$(u,l,"8uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba8sint":{let c=$(u,l,"8sint",4);return[c[0],c[1],c[2],c[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let c=$(u,l,"8unorm",4);return[c[2],c[1],c[0],c[3]]}case"r16uint":return[$(u,l,"16uint",1)[0]];case"r16sint":return[$(u,l,"16sint",1)[0]];case"r16float":return[$(u,l,"16float",1)[0]];case"rg16uint":{let c=$(u,l,"16uint",2);return[c[0],c[1]]}case"rg16sint":{let c=$(u,l,"16sint",2);return[c[0],c[1]]}case"rg16float":{let c=$(u,l,"16float",2);return[c[0],c[1]]}case"rgba16uint":{let c=$(u,l,"16uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16sint":{let c=$(u,l,"16sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba16float":{let c=$(u,l,"16float",4);return[c[0],c[1],c[2],c[3]]}case"r32uint":return[$(u,l,"32uint",1)[0]];case"r32sint":return[$(u,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[$(u,l,"32float",1)[0]];case"rg32uint":{let c=$(u,l,"32uint",2);return[c[0],c[1]]}case"rg32sint":{let c=$(u,l,"32sint",2);return[c[0],c[1]]}case"rg32float":{let c=$(u,l,"32float",2);return[c[0],c[1]]}case"rgba32uint":{let c=$(u,l,"32uint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32sint":{let c=$(u,l,"32sint",4);return[c[0],c[1],c[2],c[3]]}case"rgba32float":{let c=$(u,l,"32float",4);return[c[0],c[1],c[2],c[3]]}case"rg11b10ufloat":{let c=new Uint32Array(u.buffer,l,1)[0],f=(4192256&c)>>11,b=(4290772992&c)>>22;return[Mr(2047&c),Mr(f),function(v){let k=112+(v>>5&31)<<23|(31&v)<<18;return Rn[0]=k,Nr[0]}(b),1]}}return null}function $(u,e,t,n){let r=[0,0,0,0];for(let s=0;s<n;++s)switch(t){case"8unorm":r[s]=u[e]/255,e++;break;case"8snorm":r[s]=u[e]/255*2-1,e++;break;case"8uint":r[s]=u[e],e++;break;case"8sint":r[s]=u[e]-127,e++;break;case"16uint":r[s]=u[e]|u[e+1]<<8,e+=2;break;case"16sint":r[s]=(u[e]|u[e+1]<<8)-32768,e+=2;break;case"16float":r[s]=us(u[e]|u[e+1]<<8),e+=2;break;case"32uint":case"32sint":r[s]=u[e]|u[e+1]<<8|u[e+2]<<16|u[e+3]<<24,e+=4;break;case"32float":r[s]=new Float32Array(u.buffer,e,1)[0],e+=4}return r}function P(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=hs(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 ds(u,e,t){let n=e.length;return n===2?t==="f32"?new d(new Float32Array(e),u.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new d(new Int32Array(e),u.getTypeInfo("vec2i")):t==="u32"?new d(new Uint32Array(e),u.getTypeInfo("vec2u")):t==="f16"?new d(new Float32Array(e),u.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new d(new Float32Array(e),u.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new d(new Int32Array(e),u.getTypeInfo("vec3i")):t==="u32"?new d(new Uint32Array(e),u.getTypeInfo("vec3u")):t==="f16"?new d(new Float32Array(e),u.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new d(new Float32Array(e),u.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new d(new Int32Array(e),u.getTypeInfo("vec4i")):t==="u32"?new d(new Uint32Array(e),u.getTypeInfo("vec4u")):t==="f16"?new d(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 Fr(u,e,t){if(e===t)return u;if(e==="f32"){if(t==="i32"||t==="x32")return on[0]=u,ps[0];if(t==="u32")return on[0]=u,ms[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return cn[0]=u,gs[0];if(t==="u32")return cn[0]=u,ys[0]}else if(e==="u32"){if(t==="f32")return un[0]=u,xs[0];if(t==="i32"||t==="x32")return un[0]=u,bs[0]}return console.error(`Unsupported cast from ${e} to ${t}`),u}var X,Mt,fe,de,nt,me,he,We,In,Tn,Ft,An,En,Cn,Ln,Vr,ls,G,Rn,Nr,kn,Y,He,Qe,Wr,N,Ce,Bn,Vt,rt,Nt,oe,st,Ae,qe,Ue,tt,x,g,Wt,Ut,it,Rt,qt,Gt,zt,$n,Dn,Ht,at,Pn,Qt,Xt,_,Yt,ie,y,Ge,Ee,Te,ee,ge,ne,ot,H,jt,R,Zt,_e,Kt,U,J,Jt,ze,en,tn,nn,On,rn,sn,j,ct,be,p,d,T,W,ae,m,h,an,Mn,on,ps,ms,cn,gs,ys,un,xs,bs,Fn,Re,re,qn,ut,lt,ht,Vn,Nn,Sn,z,q,Wn,Un,ln,Ur=B(()=>{X=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}},Mt=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}},fe=class extends X{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},de=class extends X{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}},nt=class extends X{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},me=class extends X{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"})(he||(he={}));We=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}},In=class{constructor(e,t){this.name=e,this.type=t}},Tn=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},Ft=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},An=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},En=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},Cn=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}},Ln=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}};Vr=new Float32Array(1),ls=new Int32Array(Vr.buffer),G=new Uint16Array(1);Rn=new Uint32Array(1),Nr=new Float32Array(Rn.buffer,0,1);kn={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}},Y=class{constructor(){this.id=Y._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(He.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Qe.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};Y._id=0;He=class extends Y{};He.instance=new He;Qe=class extends Y{};Qe.instance=new Qe;Wr=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"]),N=class extends Y{constructor(){super()}},Ce=class extends N{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)}},Bn=class extends N{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},Vt=class extends N{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)}},rt=class extends N{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},Nt=class extends N{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)}},oe=class extends N{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)}},st=class extends N{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)}},Ae=class extends N{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)}},qe=class extends N{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="--"})(Ue||(Ue={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return u[t]}})(Ue||(Ue={}));Wt=class extends N{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=">>="})(tt||(tt={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(tt||(tt={}));Ut=class extends N{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)}},it=class extends N{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Wr.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},Rt=class extends N{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}search(e){var t;this.searchBlock(this.body,e),(t=this.continuing)===null||t===void 0||t.search(e)}},qt=class extends N{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)}},Gt=class extends N{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)}},zt=class extends N{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},$n=class extends N{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},Dn=class extends N{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},Ht=class extends N{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},at=class extends N{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},Pn=class extends N{constructor(){super()}get astNodeType(){return"discard"}},Qt=class extends N{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},Xt=class extends N{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},_=class extends N{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=_._priority.get(t.name);_._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?_.i32:t}getTypeName(){return this.name}};_.x32=new _("x32"),_.f32=new _("f32"),_.i32=new _("i32"),_.u32=new _("u32"),_.f16=new _("f16"),_.bool=new _("bool"),_.void=new _("void"),_._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);Yt=class extends _{constructor(e){super(e)}},ie=class extends _{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)}},y=class extends _{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}};y.vec2f=new y("vec2",_.f32,null),y.vec3f=new y("vec3",_.f32,null),y.vec4f=new y("vec4",_.f32,null),y.vec2i=new y("vec2",_.i32,null),y.vec3i=new y("vec3",_.i32,null),y.vec4i=new y("vec4",_.i32,null),y.vec2u=new y("vec2",_.u32,null),y.vec3u=new y("vec3",_.u32,null),y.vec4u=new y("vec4",_.u32,null),y.vec2h=new y("vec2",_.f16,null),y.vec3h=new y("vec3",_.f16,null),y.vec4h=new y("vec4",_.f16,null),y.vec2b=new y("vec2",_.bool,null),y.vec3b=new y("vec3",_.bool,null),y.vec4b=new y("vec4",_.bool,null),y.mat2x2f=new y("mat2x2",_.f32,null),y.mat2x3f=new y("mat2x3",_.f32,null),y.mat2x4f=new y("mat2x4",_.f32,null),y.mat3x2f=new y("mat3x2",_.f32,null),y.mat3x3f=new y("mat3x3",_.f32,null),y.mat3x4f=new y("mat3x4",_.f32,null),y.mat4x2f=new y("mat4x2",_.f32,null),y.mat4x3f=new y("mat4x3",_.f32,null),y.mat4x4f=new y("mat4x4",_.f32,null),y.mat2x2h=new y("mat2x2",_.f16,null),y.mat2x3h=new y("mat2x3",_.f16,null),y.mat2x4h=new y("mat2x4",_.f16,null),y.mat3x2h=new y("mat3x2",_.f16,null),y.mat3x3h=new y("mat3x3",_.f16,null),y.mat3x4h=new y("mat3x4",_.f16,null),y.mat4x2h=new y("mat4x2",_.f16,null),y.mat4x3h=new y("mat4x3",_.f16,null),y.mat4x4h=new y("mat4x4",_.f16,null),y.mat2x2i=new y("mat2x2",_.i32,null),y.mat2x3i=new y("mat2x3",_.i32,null),y.mat2x4i=new y("mat2x4",_.i32,null),y.mat3x2i=new y("mat3x2",_.i32,null),y.mat3x3i=new y("mat3x3",_.i32,null),y.mat3x4i=new y("mat3x4",_.i32,null),y.mat4x2i=new y("mat4x2",_.i32,null),y.mat4x3i=new y("mat4x3",_.i32,null),y.mat4x4i=new y("mat4x4",_.i32,null),y.mat2x2u=new y("mat2x2",_.u32,null),y.mat2x3u=new y("mat2x3",_.u32,null),y.mat2x4u=new y("mat2x4",_.u32,null),y.mat3x2u=new y("mat3x2",_.u32,null),y.mat3x3u=new y("mat3x3",_.u32,null),y.mat3x4u=new y("mat3x4",_.u32,null),y.mat4x2u=new y("mat4x2",_.u32,null),y.mat4x3u=new y("mat4x3",_.u32,null),y.mat4x4u=new y("mat4x4",_.u32,null);Ge=class extends _{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},Ee=class extends _{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},Te=class extends _{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},ee=class extends Y{constructor(){super(),this.postfix=null}},ge=class extends ee{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},ne=class extends ee{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)}},ot=class extends ee{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 Wr.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)}},H=class extends ee{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)}},jt=class extends ee{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)}},R=class extends ee{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 p}get isVector(){return this.value instanceof d||this.value instanceof T}get scalarValue(){return this.value instanceof p?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof d||this.value instanceof T?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},Zt=class extends ee{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},_e=class extends ee{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Kt=class extends ee{constructor(){super()}},U=class extends Kt{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)}},J=class extends Kt{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"?_.f32:e.name==="u32"||t.name==="u32"?_.u32:_.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Jt=class extends Y{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}},ze=class extends ee{constructor(){super()}get astNodeType(){return"default"}},en=class extends Jt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},tn=class extends Jt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},nn=class extends Y{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},On=class extends Y{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)}},rn=class extends Y{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},sn=class extends Y{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},j=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=j._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()}>`}};j._id=0;ct=class extends j{constructor(){super(new X("void",null),null)}toString(){return"void"}};ct.void=new ct;be=class extends j{constructor(e){super(new nt("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()}`}},p=class extends j{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 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"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 p))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}`}};d=class extends j{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 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"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof ge?console.error("TODO: Set vector postfix"):t instanceof d?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 me)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 _e){let a=t.index,i=-1;if(a instanceof R){if(!(a.value instanceof p))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value}else{let o=e.evalExpression(a,n);if(!(o instanceof p))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 p(o,r)}if(s.data instanceof Int32Array){let o=new Int32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new p(o,r)}if(s.data instanceof Uint32Array){let o=new Uint32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new p(o,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof ge))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 l=new Float32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(l,r,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(l,r,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(l,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=ds(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}},T=class extends j{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new T(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof ge?console.error("TODO: Set matrix postfix"):t instanceof T?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 me)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 _e){let s=t.index,a=-1;if(s instanceof R){if(!(s.value instanceof p))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;a=s.value.value}else{let l=e.evalExpression(s,n);if(!(l instanceof p))return console.error("GetDataValue: Unknown index type",s),null;a=l.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 d(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 d(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 d(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}},W=class extends j{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 W(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 _e)if(a instanceof de){let i=n.index;if(i instanceof R){if(!(i.value instanceof p))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 p))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 ge))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(a instanceof fe){let o=!1;for(let l of a.members)if(l.name===i){s+=l.offset,a=l.type,o=!0;break}if(!o)return void console.error(`SetDataValue: Member ${i} not found`)}else if(a instanceof X){let o=a.getTypeName(),l=0;if(i==="x"||i==="r")l=0;else if(i==="y"||i==="g")l=1;else if(i==="z"||i==="b")l=2;else{if(i!=="w"&&i!=="a")return void console.error(`SetDataValue: Unknown member ${i}`);l=3}if(!(t instanceof p))return void console.error("SetDataValue: Invalid value",t);let c=t.value;return o==="vec2f"?void(new Float32Array(this.buffer,s,2)[l]=c):o==="vec3f"?void(new Float32Array(this.buffer,s,3)[l]=c):o==="vec4f"?void(new Float32Array(this.buffer,s,4)[l]=c):o==="vec2i"?void(new Int32Array(this.buffer,s,2)[l]=c):o==="vec3i"?void(new Int32Array(this.buffer,s,3)[l]=c):o==="vec4i"?void(new Int32Array(this.buffer,s,4)[l]=c):o==="vec2u"?void(new Uint32Array(this.buffer,s,2)[l]=c):o==="vec3u"?void(new Uint32Array(this.buffer,s,3)[l]=c):o==="vec4u"?void(new Uint32Array(this.buffer,s,4)[l]=c):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"){let i=new Float32Array(this.buffer,r,2);return void(t instanceof d?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1]))}if(a==="vec3f"||a==="vec3h"){let i=new Float32Array(this.buffer,r,3);return void(t instanceof d?(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]))}if(a==="vec4f"||a==="vec4h"){let i=new Float32Array(this.buffer,r,4);return void(t instanceof d?(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]))}if(a==="vec2i"){let i=new Int32Array(this.buffer,r,2);return void(t instanceof d?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1]))}if(a==="vec3i"){let i=new Int32Array(this.buffer,r,3);return void(t instanceof d?(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]))}if(a==="vec4i"){let i=new Int32Array(this.buffer,r,4);return void(t instanceof d?(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]))}if(a==="vec2u"){let i=new Uint32Array(this.buffer,r,2);return void(t instanceof d?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1]))}if(a==="vec3u"){let i=new Uint32Array(this.buffer,r,3);return void(t instanceof d?(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]))}if(a==="vec4u"){let i=new Uint32Array(this.buffer,r,4);return void(t instanceof d?(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]))}if(a==="vec2b"){let i=new Uint32Array(this.buffer,r,2);return void(t instanceof d?(i[0]=t.data[0],i[1]=t.data[1]):(i[0]=t[0],i[1]=t[1]))}if(a==="vec3b"){let i=new Uint32Array(this.buffer,r,3);return void(t instanceof d?(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]))}if(a==="vec4b"){let i=new Uint32Array(this.buffer,r,4);return void(t instanceof d?(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]))}if(a==="mat2x2f"||a==="mat2x2h"){let i=new Float32Array(this.buffer,r,4);return void(t instanceof T?(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]))}if(a==="mat2x3f"||a==="mat2x3h"){let i=new Float32Array(this.buffer,r,6);return void(t instanceof T?(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]))}if(a==="mat2x4f"||a==="mat2x4h"){let i=new Float32Array(this.buffer,r,8);return void(t instanceof T?(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]))}if(a==="mat3x2f"||a==="mat3x2h"){let i=new Float32Array(this.buffer,r,6);return void(t instanceof T?(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]))}if(a==="mat3x3f"||a==="mat3x3h"){let i=new Float32Array(this.buffer,r,9);return void(t instanceof T?(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]))}if(a==="mat3x4f"||a==="mat3x4h"){let i=new Float32Array(this.buffer,r,12);return void(t instanceof T?(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]))}if(a==="mat4x2f"||a==="mat4x2h"){let i=new Float32Array(this.buffer,r,8);return void(t instanceof T?(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]))}if(a==="mat4x3f"||a==="mat4x3h"){let i=new Float32Array(this.buffer,r,12);return void(t instanceof T?(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]))}if(a==="mat4x4f"||a==="mat4x4h"){let i=new Float32Array(this.buffer,r,16);return void(t instanceof T?(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]))}if(t instanceof W){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 t instanceof p&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof p&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof p&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof p&&(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 _e){let c=t.index,f=c instanceof ee?e.evalExpression(c,n):c,b=0;if(f instanceof p?b=f.value:typeof f=="number"?b=f:console.error("GetDataValue: Invalid index type",c),o instanceof de)i+=b*o.stride,o=o.format;else{let v=o.getTypeName();v==="mat4x4"||v==="mat4x4f"||v==="mat4x4h"?(i+=16*b,o=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${o.getTypeName()} is not an array`)}}else{if(!(t instanceof ge))return console.error("GetDataValue: Unknown postfix type",t),null;{let c=t.value;if(o instanceof fe){let f=!1;for(let b of o.members)if(b.name===c){i+=b.offset,o=b.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${c} not found`),null}else if(o instanceof X){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(c.length>0&&c.length<5){let b="f",v=[];for(let k=0;k<c.length;++k){let E=c[k].toLowerCase(),A=0;if(E==="x"||E==="r")A=0;else if(E==="y"||E==="g")A=1;else if(E==="z"||E==="b")A=2;else{if(E!=="w"&&E!=="a")return console.error(`Unknown member ${c}`),null;A=3}if(c.length===1){if(f.endsWith("f"))return this.buffer.byteLength<i+4*A+4?(console.log("Insufficient buffer data"),null):new p(new Float32Array(this.buffer,i+4*A,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new p(new Float32Array(this.buffer,i+4*A,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new p(new Int32Array(this.buffer,i+4*A,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new p(new Int32Array(this.buffer,i+4*A,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new p(new Uint32Array(this.buffer,i+4*A,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")v.push(new Float32Array(this.buffer,i,2)[A]);else if(f==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let L=new Float32Array(this.buffer,i,3);v.push(L[A])}else if(f==="vec4f")v.push(new Float32Array(this.buffer,i,4)[A]);else if(f==="vec2i")b="i",v.push(new Int32Array(this.buffer,i,2)[A]);else if(f==="vec3i")b="i",v.push(new Int32Array(this.buffer,i,3)[A]);else if(f==="vec4i")b="i",v.push(new Int32Array(this.buffer,i,4)[A]);else if(f==="vec2u"){b="u";let L=new Uint32Array(this.buffer,i,2);v.push(L[A])}else f==="vec3u"?(b="u",v.push(new Uint32Array(this.buffer,i,3)[A])):f==="vec4u"&&(b="u",v.push(new Uint32Array(this.buffer,i,4)[A]))}return v.length===2?o=e.getTypeInfo(`vec2${b}`):v.length===3?o=e.getTypeInfo(`vec3${b}`):v.length===4?o=e.getTypeInfo(`vec4${b}`):console.error(`GetDataValue: Invalid vector length ${v.length}`),new d(v,o,null)}return console.error(`GetDataValue: Unknown member ${c}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}let l=o.getTypeName();return l==="f32"?new p(new Float32Array(this.buffer,i,1),o,this):l==="i32"?new p(new Int32Array(this.buffer,i,1),o,this):l==="u32"?new p(new Uint32Array(this.buffer,i,1),o,this):l==="vec2f"?new d(new Float32Array(this.buffer,i,2),o,this):l==="vec3f"?new d(new Float32Array(this.buffer,i,3),o,this):l==="vec4f"?new d(new Float32Array(this.buffer,i,4),o,this):l==="vec2i"?new d(new Int32Array(this.buffer,i,2),o,this):l==="vec3i"?new d(new Int32Array(this.buffer,i,3),o,this):l==="vec4i"?new d(new Int32Array(this.buffer,i,4),o,this):l==="vec2u"?new d(new Uint32Array(this.buffer,i,2),o,this):l==="vec3u"?new d(new Uint32Array(this.buffer,i,3),o,this):l==="vec4u"?new d(new Uint32Array(this.buffer,i,4),o,this):o instanceof me&&o.name==="atomic"?((r=o.format)===null||r===void 0?void 0:r.name)==="u32"?new p(new Uint32Array(this.buffer,i,1)[0],o.format,this):((s=o.format)===null||s===void 0?void 0:s.name)==="i32"?new p(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 W(this.buffer,o,i,this)}toString(){let e="";if(this.typeInfo instanceof de)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 fe?e+="{...}":e="[...]";return e}},ae=class extends j{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new ae(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=kn[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=kn[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=kn[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 fs(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,l=this.data[r];(function(c,f,b,v,k,E,A,L,D,I){let S=v*(A>>=k)*(E>>=k)+b*A+f*L;switch(D){case"r8unorm":return void P(c,S,"8unorm",1,I);case"r8snorm":return void P(c,S,"8snorm",1,I);case"r8uint":return void P(c,S,"8uint",1,I);case"r8sint":return void P(c,S,"8sint",1,I);case"rg8unorm":return void P(c,S,"8unorm",2,I);case"rg8snorm":return void P(c,S,"8snorm",2,I);case"rg8uint":return void P(c,S,"8uint",2,I);case"rg8sint":return void P(c,S,"8sint",2,I);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void P(c,S,"8unorm",4,I);case"rgba8snorm":return void P(c,S,"8snorm",4,I);case"rgba8uint":return void P(c,S,"8uint",4,I);case"rgba8sint":return void P(c,S,"8sint",4,I);case"r16uint":return void P(c,S,"16uint",1,I);case"r16sint":return void P(c,S,"16sint",1,I);case"r16float":return void P(c,S,"16float",1,I);case"rg16uint":return void P(c,S,"16uint",2,I);case"rg16sint":return void P(c,S,"16sint",2,I);case"rg16float":return void P(c,S,"16float",2,I);case"rgba16uint":return void P(c,S,"16uint",4,I);case"rgba16sint":return void P(c,S,"16sint",4,I);case"rgba16float":return void P(c,S,"16float",4,I);case"r32uint":return void P(c,S,"32uint",1,I);case"r32sint":return void P(c,S,"32sint",1,I);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void P(c,S,"32float",1,I);case"rg32uint":return void P(c,S,"32uint",2,I);case"rg32sint":return void P(c,S,"32sint",2,I);case"rg32float":return void P(c,S,"32float",2,I);case"rgba32uint":return void P(c,S,"32uint",4,I);case"rgba32sint":return void P(c,S,"32sint",4,I);case"rgba32float":return void P(c,S,"32float",4,I);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),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{};x=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={"@":x.tokens.attr,"{":x.tokens.brace_left,"}":x.tokens.brace_right,":":x.tokens.colon,",":x.tokens.comma,"(":x.tokens.paren_left,")":x.tokens.paren_right,";":x.tokens.semicolon},h.literalTokens={"&":x.tokens.and,"&&":x.tokens.and_and,"->":x.tokens.arrow,"/":x.tokens.forward_slash,"!":x.tokens.bang,"[":x.tokens.bracket_left,"]":x.tokens.bracket_right,"=":x.tokens.equal,"==":x.tokens.equal_equal,"!=":x.tokens.not_equal,">":x.tokens.greater_than,">=":x.tokens.greater_than_equal,">>":x.tokens.shift_right,"<":x.tokens.less_than,"<=":x.tokens.less_than_equal,"<<":x.tokens.shift_left,"%":x.tokens.modulo,"-":x.tokens.minus,"--":x.tokens.minus_minus,".":x.tokens.period,"+":x.tokens.plus,"++":x.tokens.plus_plus,"|":x.tokens.or,"||":x.tokens.or_or,"*":x.tokens.star,"~":x.tokens.tilde,_:x.tokens.underscore,"^":x.tokens.xor,"+=":x.tokens.plus_equal,"-=":x.tokens.minus_equal,"*=":x.tokens.times_equal,"/=":x.tokens.division_equal,"%=":x.tokens.modulo_equal,"&=":x.tokens.and_equal,"|=":x.tokens.or_equal,"^=":x.tokens.xor_equal,">>=":x.tokens.shift_right_equal,"<<=":x.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:x.tokens.decimal_float_literal,hex_float_literal:x.tokens.hex_float_literal,int_literal:x.tokens.int_literal,uint_literal:x.tokens.uint_literal,ident:x.tokens.ident},h.storage_class=[x.keywords.function,x.keywords.private,x.keywords.workgroup,x.keywords.uniform,x.keywords.storage],h.access_mode=[x.keywords.read,x.keywords.write,x.keywords.read_write],h.sampler_type=[x.keywords.sampler,x.keywords.sampler_comparison],h.sampled_texture_type=[x.keywords.texture_1d,x.keywords.texture_2d,x.keywords.texture_2d_array,x.keywords.texture_3d,x.keywords.texture_cube,x.keywords.texture_cube_array],h.multisampled_texture_type=[x.keywords.texture_multisampled_2d],h.storage_texture_type=[x.keywords.texture_storage_1d,x.keywords.texture_storage_2d,x.keywords.texture_storage_2d_array,x.keywords.texture_storage_3d],h.depth_texture_type=[x.keywords.texture_depth_2d,x.keywords.texture_depth_2d_array,x.keywords.texture_depth_cube,x.keywords.texture_depth_cube_array,x.keywords.texture_depth_multisampled_2d],h.texture_external_type=[x.keywords.texture_external],h.any_texture_type=[...x.sampled_texture_type,...x.multisampled_texture_type,...x.storage_texture_type,...x.depth_texture_type,...x.texture_external_type],h.texel_format=[x.keywords.r8unorm,x.keywords.r8snorm,x.keywords.r8uint,x.keywords.r8sint,x.keywords.r16uint,x.keywords.r16sint,x.keywords.r16float,x.keywords.rg8unorm,x.keywords.rg8snorm,x.keywords.rg8uint,x.keywords.rg8sint,x.keywords.r32uint,x.keywords.r32sint,x.keywords.r32float,x.keywords.rg16uint,x.keywords.rg16sint,x.keywords.rg16float,x.keywords.rgba8unorm,x.keywords.rgba8unorm_srgb,x.keywords.rgba8snorm,x.keywords.rgba8uint,x.keywords.rgba8sint,x.keywords.bgra8unorm,x.keywords.bgra8unorm_srgb,x.keywords.rgb10a2unorm,x.keywords.rg11b10float,x.keywords.rg32uint,x.keywords.rg32sint,x.keywords.rg32float,x.keywords.rgba16uint,x.keywords.rgba16sint,x.keywords.rgba16float,x.keywords.rgba32uint,x.keywords.rgba32sint,x.keywords.rgba32float],h.const_literal=[x.tokens.int_literal,x.tokens.uint_literal,x.tokens.decimal_float_literal,x.tokens.hex_float_literal,x.keywords.true,x.keywords.false],h.literal_or_ident=[x.tokens.ident,x.tokens.int_literal,x.tokens.uint_literal,x.tokens.decimal_float_literal,x.tokens.hex_float_literal,x.tokens.name],h.element_count_expression=[x.tokens.int_literal,x.tokens.uint_literal,x.tokens.ident],h.template_types=[x.keywords.vec2,x.keywords.vec3,x.keywords.vec4,x.keywords.mat2x2,x.keywords.mat2x3,x.keywords.mat2x4,x.keywords.mat3x2,x.keywords.mat3x3,x.keywords.mat3x4,x.keywords.mat4x2,x.keywords.mat4x3,x.keywords.mat4x4,x.keywords.atomic,x.keywords.bitcast,...x.any_texture_type],h.attribute_name=[x.tokens.ident,x.keywords.block,x.keywords.diagnostic],h.assignment_operators=[x.tokens.equal,x.tokens.plus_equal,x.tokens.minus_equal,x.tokens.times_equal,x.tokens.division_equal,x.tokens.modulo_equal,x.tokens.and_equal,x.tokens.or_equal,x.tokens.xor_equal,x.tokens.shift_right_equal,x.tokens.shift_left_equal],h.increment_operators=[x.tokens.plus_plus,x.tokens.minus_minus];an=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()}},Mn=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 an(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
13
13
|
`)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
|
|
14
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,
|
|
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);})();
|
|
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,l=this._tokens.length-1;for(let c=0;c<5&&l>=0&&h.assignment_operators.indexOf(this._tokens[l].type)===-1;++c,--l)if(this._tokens[l].type===h.tokens.less_than){l>0&&this._tokens[l-1].isArrayOrTemplateType()&&(o=!0);break}if(o)return this._addToken(a),!0}if(a===h.none){let o=e,l=0,c=2;for(let f=0;f<c;++f)if(o+=this._peekAhead(f),a=this._findType(o),a!==h.none){l=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=o,this._current+=l+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 an(e,t,this._line,this._start,this._current))}};on=new Float32Array(1),ps=new Uint32Array(on.buffer),ms=new Uint32Array(on.buffer),cn=new Int32Array(1),gs=new Float32Array(cn.buffer),ys=new Uint32Array(cn.buffer),un=new Uint32Array(1),xs=new Float32Array(un.buffer),bs=new Int32Array(un.buffer);Fn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},Re=class{constructor(e,t){this.align=e,this.size=t}},re=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Ln,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 Ce&&this._functions.set(t.name,new Fn(t));for(let t of e)if(t instanceof ie){let n=this.getTypeInfo(t,null);n instanceof fe&&this.structs.push(n)}for(let t of e)if(t instanceof at)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof st){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 An(n.name,s,n.attributes,r));continue}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 We(n.name,a,r,s,n.attributes,he.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i);continue}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 We(n.name,a,r,s,n.attributes,i?he.StorageTexture:he.Storage,n.access);o.access||(o.access="read"),this.storage.push(o);continue}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 We(n.name,a,r,s,n.attributes,i?he.StorageTexture:he.Texture,n.access);o.access||(o.access="read"),i?this.storage.push(o):this.textures.push(o);continue}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 We(n.name,a,r,s,n.attributes,he.Sampler,n.access);this.samplers.push(i);continue}}for(let t of e)if(t instanceof Ce){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),a=n||r||s,i=new Cn(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 En(o.name,this.getTypeInfo(o.type,o.attributes),o.attributes)),i.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}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 sn){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 H)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)}getFunctionInfo(e){for(let t of this.functions)if(t.name==e)return t;return null}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 He)s.push({});else if(a instanceof Qe)s.pop();else if(a instanceof oe){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 ne){let i=a;t&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof Ae){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 H){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 ot){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 it){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 ie)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 ie)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 Ft(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 Ft("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof ie)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 ie)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 Tn(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 In(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 Ge){let r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new nt(e.name,r,t);return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Ee){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,a=new de(r.name,t);return a.format=s,a.count=r.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof ie){let r=e,s=new fe(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 Mt(a.name,i,a.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Te){let r=e,s=r.format instanceof _,a=r.format?s?this.getTypeInfo(r.format,null):new X(r.format,null):null,i=new me(r.name,a,t,r.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof y){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,a=new me(r.name,s,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new X(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 de&&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 nt&&this._updateTypeInfo(e.format),e instanceof fe&&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 l=e.members[i],c=this._getTypeSize(l);if(!c)continue;(t=this._getAlias(l.type.name))!==null&&t!==void 0||l.type;let f=c.align,b=c.size;n=this._roundUp(f,n+r),r=b,s=n,a=Math.max(a,f),l.offset=n,l.size=b,this._updateTypeInfo(l.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 Mt&&(e=e.type),e instanceof X){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=re._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 Re(Math.max(s,a.align/i),Math.max(r,a.size/i))}}{let a=re._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let i=e.name[e.name.length-1]==="h"?2:1;return new Re(Math.max(s,a.align/i),Math.max(r,a.size/i))}}if(e instanceof de){let a=e,i=8,o=8,l=this._getTypeSize(a.format);return l!==null&&(o=l.size,i=l.align),o=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,o)),r&&(o=r),new Re(Math.max(s,i),Math.max(r,o))}if(e instanceof fe){let a=0,i=0,o=0,l=0,c=0;for(let f of e.members){let b=this._getTypeSize(f.type);b!==null&&(a=Math.max(b.align,a),o=this._roundUp(b.align,o+l),l=b.size,c=o)}return i=this._roundUp(a,c+l),new Re(Math.max(s,a),Math.max(r,i))}return null}_isUniformVar(e){return e instanceof oe&&e.storage=="uniform"}_isStorageVar(e){return e instanceof oe&&e.storage=="storage"}_isTextureVar(e){return e instanceof oe&&e.type!==null&&re._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof oe&&e.type!==null&&re._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}};re._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}},re._textureTypes=h.any_texture_type.map(u=>u.name),re._samplerTypes=h.sampler_type.map(u=>u.name);qn=0,ut=class{constructor(e,t,n){this.id=qn++,this.name=e,this.value=t,this.node=n}clone(){return new ut(this.name,this.value,this.node)}},lt=class{constructor(e){this.id=qn++,this.name=e.name,this.node=e}clone(){return new lt(this.node)}},ht=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=qn++,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 ut(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 ht(this)}},Vn=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},Nn=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 d)return n.data.forEach(s=>{s||(r=!1)}),new p(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 d){let r=n.data.some(s=>s);return new p(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 p))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 U&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof W&&r.typeInfo.size===0){let s=r.typeInfo,a=r.buffer.byteLength/s.stride;return new p(a,this.getTypeInfo("u32"))}return new p(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new p(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new p(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new p(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new p(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new p(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new p(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new p(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 d&&r instanceof d)return new d(n.data.map((i,o)=>Math.atan2(i,r.data[o])),n.typeInfo);let s=n,a=r;return new p(Math.atan2(s.value,a.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new p(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 d&&r instanceof d&&s instanceof d)return new d(n.data.map((l,c)=>this._clamp(l,r.data[c],s.data[c])),n.typeInfo);let a=n,i=r,o=s;return new p(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 d)return new d(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new p(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new p(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new p(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 d)return new d(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new p(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 d)return new d(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new p(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 d&&r instanceof d){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 d([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 d?new d(n.data.map(s=>s*r),n.typeInfo):new p(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof T){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 p(r[0]*r[3]-r[1]*r[2],a);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new p(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 p(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 d&&r instanceof d){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 p(Math.sqrt(i),this.getTypeInfo("f32"))}let s=n,a=r;return new p(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 d&&r instanceof d?new p(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 d)return new d(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new p(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new p(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 d)return new d(n.data.map(l=>l>>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 p(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 d&&r instanceof d&&s instanceof d){let a=this._dot(r.data,s.data);return new d(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 d)return new d(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new p(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 d)return new d(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new p(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new p(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 d&&r instanceof d&&s instanceof d)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 d(n.data.map((l,c)=>l*r.data[c]+s.data[c]),n.typeInfo);let a=n,i=r,o=s;return new p(a.value*i.value+o.value,a.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new p(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,l=~o;if(n instanceof d&&r instanceof d)return new d(n.data.map((b,v)=>b&l|r.data[v]<<i&o),n.typeInfo);let c=n.value,f=r.value;return new p(c&l|f<<i&o,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new p(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 d){let s=0;return n.data.forEach(a=>{s+=a*a}),new p(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new p(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new p(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new p(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 d&&r instanceof d)return new d(n.data.map((i,o)=>Math.max(i,r.data[o])),n.typeInfo);let s=n,a=r;return new p(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 d&&r instanceof d)return new d(n.data.map((i,o)=>Math.min(i,r.data[o])),n.typeInfo);let s=n,a=r;return new p(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 d&&r instanceof d&&s instanceof d)return new d(n.data.map((o,l)=>n.data[l]*(1-s.data[l])+r.data[l]*s.data[l]),n.typeInfo);let a=r,i=s;return new p(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 d&&r instanceof d)return new d(n.data.map((a,i)=>a%r.data[i]),n.typeInfo);let s=r;return new p(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d){let r=this.Length(e,t).value;return new d(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 d&&r instanceof d)return new d(n.data.map((i,o)=>Math.pow(i,r.data[o])),n.typeInfo);let s=n,a=r;return new p(Math.pow(s.value,a.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof d?new d(n.data.map(r=>r),n.typeInfo):new p(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof d?new d(n.data.map(r=>r*Math.PI/180),n.typeInfo):new p(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 d&&r instanceof d){let s=this._dot(n.data,r.data);return new d(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 d&&r instanceof d&&s instanceof p){let a=this._dot(r.data,n.data);return new d(n.data.map((i,o)=>{let l=1-s.value*s.value*(1-a*a);if(l<0)return 0;let c=Math.sqrt(l);return s.value*i-(s.value*a+c)*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 d)return new d(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new p(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new p(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 d)return new d(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new p(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new p(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new p(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 d&&n instanceof d&&r instanceof d)return new d(s.data.map((l,c)=>this._smoothstep(n.data[c],r.data[c],l)),s.typeInfo);let a=n,i=r,o=s;return new p(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 d)return new d(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new p(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 d&&n instanceof d)return new d(r.data.map((a,i)=>a<n.data[i]?0:1),r.typeInfo);let s=n;return new p(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new p(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new p(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 T))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 T([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 T([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 T([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 T([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 T([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 T([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 T([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 T([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 T([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 d)return new d(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new p(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 H){let s=n.name,a=t.getVariableValue(s);if(a instanceof ae){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 p(i[0],this.getTypeInfo("u32")):o==="3d"?new d(i,this.getTypeInfo("vec3u")):o==="2d"?new d(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 d)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof H){let a=n.name,i=t.getVariableValue(a);if(i instanceof ae){let o=Math.floor(r.data[0]),l=Math.floor(r.data[1]);if(o<0||o>=i.width||l<0||l>=i.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;let c=i.getPixel(o,l,0,s);return c===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new d(c,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 H){let r=n.name,s=t.getVariableValue(r);return s instanceof ae?new p(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 H){let r=n.name,s=t.getVariableValue(r);return s instanceof ae?new p(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 H){let r=n.name,s=t.getVariableValue(r);return s instanceof ae?new p(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 d)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof H){let i=n.name,o=t.getVariableValue(i);if(o instanceof ae){let l=o.getMipLevelSize(0),c=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return c<0||c>=l[0]||f<0||f>=l[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(o.setPixel(c,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 U&&(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 U&&(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 p&&i instanceof p&&(o.value=i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value+=i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicSub(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value-=i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicMax(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=Math.max(o.value,i.value)),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicMin(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=Math.min(o.value,i.value)),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicAnd(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value&i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicOr(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value|i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicXor(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value^i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}AtomicExchange(e,t){let n=e.args[0];n instanceof U&&(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),l=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=i.value),s.value instanceof W&&s.value.setDataValue(this.exec,o,n.postfix,t),l}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}},Sn={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},z={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]},q=class extends Vn{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new re,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new ht,this.builtins=new Nn(this),this.typeInfo={bool:this.getTypeInfo(_.bool),i32:this.getTypeInfo(_.i32),u32:this.getTypeInfo(_.u32),f32:this.getTypeInfo(_.f32),f16:this.getTypeInfo(_.f16),vec2f:this.getTypeInfo(y.vec2f),vec2u:this.getTypeInfo(y.vec2u),vec2i:this.getTypeInfo(y.vec2i),vec2h:this.getTypeInfo(y.vec2h),vec3f:this.getTypeInfo(y.vec3f),vec3u:this.getTypeInfo(y.vec3u),vec3i:this.getTypeInfo(y.vec3i),vec3h:this.getTypeInfo(y.vec3h),vec4f:this.getTypeInfo(y.vec4f),vec4u:this.getTypeInfo(y.vec4u),vec4i:this.getTypeInfo(y.vec4i),vec4h:this.getTypeInfo(y.vec4h),mat2x2f:this.getTypeInfo(y.mat2x2f),mat2x3f:this.getTypeInfo(y.mat2x3f),mat2x4f:this.getTypeInfo(y.mat2x4f),mat3x2f:this.getTypeInfo(y.mat3x2f),mat3x3f:this.getTypeInfo(y.mat3x3f),mat3x4f:this.getTypeInfo(y.mat3x4f),mat4x2f:this.getTypeInfo(y.mat4x2f),mat4x3f:this.getTypeInfo(y.mat4x3f),mat4x4f:this.getTypeInfo(y.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 p)return r.value;if(r instanceof d||r instanceof T)return Array.from(r.data);if(r instanceof W&&r.typeInfo instanceof de){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],l=t[2],c=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new d(t,c));let f=this.reflection.getFunctionInfo(e);f===null&&console.error(`Function ${e} not found in reflection data`);for(let b in n)for(let v in n[b]){let k=n[b][v];s.variables.forEach(E=>{var A;let L=E.node;if(L?.attributes){let D=null,I=null;for(let S of L.attributes)S.name==="binding"?D=S.value:S.name==="group"&&(I=S.value);if(v==D&&b==I){let S=!1;for(let O of f.resources)if(O.name===E.name&&O.group===parseInt(b)&&O.binding===parseInt(v)){S=!0;break}if(S)if(k.texture!==void 0&&k.descriptor!==void 0){let O=new ae(k.texture,this.getTypeInfo(L.type),k.descriptor,(A=k.texture.view)!==null&&A!==void 0?A:null);E.value=O}else k.uniform!==void 0?E.value=new W(k.uniform,this.getTypeInfo(L.type)):E.value=new W(k,this.getTypeInfo(L.type))}}})}for(let b=0;b<l;++b)for(let v=0;v<o;++v)for(let k=0;k<i;++k)s.setVariable("@workgroup_id",new d([k,v,b],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[k,v,b],s)}execStatement(e,t){if(e instanceof zt)return this.evalExpression(e.value,t);if(e instanceof Qt){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof p))throw new Error("Invalid break-if condition");if(!n.value)return null}return q._breakObj}if(e instanceof Xt)return q._continueObj;if(e instanceof Ae)this._let(e,t);else if(e instanceof oe)this._var(e,t);else if(e instanceof qe)this._const(e,t);else if(e instanceof Ce)this._function(e,t);else{if(e instanceof Gt)return this._if(e,t);if(e instanceof qt)return this._switch(e,t);if(e instanceof Nt)return this._for(e,t);if(e instanceof Vt)return this._while(e,t);if(e instanceof Rt)return this._loop(e,t);if(e instanceof rt){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof Ut)this._assign(e,t);else if(e instanceof Wt)this._increment(e,t);else{if(e instanceof ie)return null;if(e instanceof st){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new p(0,this.getTypeInfo("u32")))}else if(e instanceof it)this._call(e,t);else{if(e instanceof Ht||e instanceof at)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof J?this._evalBinaryOp(e,t):e instanceof R?this._evalLiteral(e,t):e instanceof H?this._evalVariable(e,t):e instanceof ot?this._evalCall(e,t):e instanceof ne?this._evalCreate(e,t):e instanceof jt?this._evalConst(e,t):e instanceof Zt?this._evalBitcast(e,t):e instanceof U?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof _){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 p(r,s.type)):s.type.name==="bool"?t.setVariable(n,new p(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 d(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 c of e.node.attributes)if(c.name==="workgroup_size"){if(c.value.length>0){let f=n.getVariableValue(c.value[0]);r[0]=f instanceof p?f.value:parseInt(c.value[0])}if(c.value.length>1){let f=n.getVariableValue(c.value[1]);r[1]=f instanceof p?f.value:parseInt(c.value[1])}if(c.value.length>2){let f=n.getVariableValue(c.value[2]);r[2]=f instanceof p?f.value:parseInt(c.value[2])}}let s=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new d(r,s));let i=r[0],o=r[1],l=r[2];for(let c=0,f=0;c<l;++c)for(let b=0;b<o;++b)for(let v=0;v<i;++v,++f){let k=[v,b,c],E=[v+t[0]*r[0],b+t[1]*r[1],c+t[2]*r[2]];n.setVariable("@local_invocation_id",new d(k,s)),n.setVariable("@global_invocation_id",new d(E,s)),n.setVariable("@local_invocation_index",new p(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 U;)e=e.right;return e instanceof H?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 p?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof p?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 H){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 U){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof be?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 be(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof U){let o=this._getVariableData(e.variable,t),l=this.evalExpression(e.value,t),c=e.operator;if(c==="="){if(o instanceof p||o instanceof d||o instanceof T){if(l instanceof p||l instanceof d||l instanceof T&&o.data.length===l.data.length)return void o.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(o instanceof W&&l instanceof W&&o.buffer.byteLength-o.offset>=l.buffer.byteLength-l.offset)return void(o.buffer.byteLength%4==0?new Uint32Array(o.buffer,o.offset,o.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(o.buffer,o.offset,o.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(c==="+=")return o instanceof p||o instanceof d||o instanceof T?l instanceof p||l instanceof d||l instanceof T?void o.data.set(l.data.map((f,b)=>o.data[b]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(c==="-=")return(o instanceof p||o instanceof d||o instanceof T)&&(l instanceof p||l instanceof d||l instanceof T)?void o.data.set(l.data.map((f,b)=>o.data[b]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof U){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let o=t.getVariable(r);if(!(o&&o.value instanceof be))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=o.value.reference;let l=e.variable.postfix;if(!l){let c=e.variable.right;for(;c instanceof U;){if(c.postfix){l=c.postfix;break}c=c.right}}l&&(n=n.getSubData(this,l,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 be&&(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!=="="){let o=n.getSubData(this,s,t);if(o instanceof d&&a instanceof p){let l=o.data,c=a.value;if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c;else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c;else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c;else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c;else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c;else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c;else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c;else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c;else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c;else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c;else console.error(`Invalid operator ${i}. Line ${e.line}`)}else if(o instanceof d&&a instanceof d){let l=o.data,c=a.data;if(l.length!==c.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(i==="+=")for(let f=0;f<l.length;++f)l[f]+=c[f];else if(i==="-=")for(let f=0;f<l.length;++f)l[f]-=c[f];else if(i==="*=")for(let f=0;f<l.length;++f)l[f]*=c[f];else if(i==="/=")for(let f=0;f<l.length;++f)l[f]/=c[f];else if(i==="%=")for(let f=0;f<l.length;++f)l[f]%=c[f];else if(i==="&=")for(let f=0;f<l.length;++f)l[f]&=c[f];else if(i==="|=")for(let f=0;f<l.length;++f)l[f]|=c[f];else if(i==="^=")for(let f=0;f<l.length;++f)l[f]^=c[f];else if(i==="<<=")for(let f=0;f<l.length;++f)l[f]<<=c[f];else if(i===">>=")for(let f=0;f<l.length;++f)l[f]>>=c[f];else console.error(`Invalid operator ${i}. Line ${e.line}`)}else{if(!(o instanceof p&&a instanceof p))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}`)}return void(n instanceof W&&n.setDataValue(this,o,s,t))}if(n instanceof W)n.setDataValue(this,a,s,t);else if(s){if(!(n instanceof d||n instanceof T))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof _e){let o=this.evalExpression(s.index,t).value;if(n instanceof d){if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[o]=a.value}else{if(!(n instanceof T))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let l=this.evalExpression(s.index,t).value;if(l<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(a instanceof d))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let c=n.typeInfo.getTypeName();if(c==="mat2x2"||c==="mat2x2f"||c==="mat2x2h"){if(!(l<2&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat2x3"||c==="mat2x3f"||c==="mat2x3h"){if(!(l<2&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat2x4"||c==="mat2x4f"||c==="mat2x4h"){if(!(l<2&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat3x2"||c==="mat3x2f"||c==="mat3x2h"){if(!(l<3&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat3x3"||c==="mat3x3f"||c==="mat3x3h"){if(!(l<3&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(c==="mat3x4"||c==="mat3x4f"||c==="mat3x4h"){if(!(l<3&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(c==="mat4x2"||c==="mat4x2f"||c==="mat4x2h"){if(!(l<4&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(c==="mat4x3"||c==="mat4x3f"||c==="mat4x3h"){if(!(l<4&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else{if(c!=="mat4x4"&&c!=="mat4x4f"&&c!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(l<4&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}}}}}else if(s instanceof ge){let o=s.value;if(!(n instanceof d))return void console.error(`Invalid assignment to ${o}. Variable ${r} is not a vector. Line ${e.line}`);if(a instanceof p){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 d))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 l=0;l<o.length;++l){let c=o[l];if(c==="x"||c==="r")n.data[0]=a.data[l];else if(c==="y"||c==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[1]=a.data[l]}else if(c==="z"||c==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[2]=a.data[l]}else{if(c!=="w"&&c!=="a")return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[3]=a.data[l]}}}}}else n instanceof p&&a instanceof p?n.value=a.value:n instanceof d&&a instanceof d||n instanceof T&&a instanceof T?n.data.set(a.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`)}_function(e,t){let n=new lt(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 U||(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 ne(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 U||(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 Ee||e.type instanceof ie||e.type instanceof y){let s=new ne(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 p))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof en)for(let a of s.selectors){if(a instanceof ze){r=s;continue}let i=this.evalExpression(a,t);if(!(i instanceof p))return console.error(`Invalid case selector. Line ${e.line}`),null;if(i.value===n.value)return this._execStatements(s.body,t)}else s instanceof tn&&(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 p))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 p))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 p?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===q._breakObj)break;if(n!==null&&n!==q._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===q._breakObj)break;if(n===q._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===q._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===q._breakObj)break;if(n!==q._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof p){let s=Fr(n.value,n.typeInfo.name,r.name);return new p(s,this.getTypeInfo(r))}if(n instanceof d){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 l=function(c,f,b){if(f===b)return c;let v=new Array(c.length);for(let k=0;k<c.length;k++)v[k]=Fr(c[k],f,b);return v}(Array.from(n.data),a,o);return new d(l,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 ne){if(e.type===null)return ct.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 ne?e.type.name:e.name,s=e instanceof ne?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 W(new ArrayBuffer(s.size),s,0);if(s instanceof fe){if(e.args)for(let i=0;i<e.args.length;++i){let o=s.members[i],l=e.args[i],c=this.evalExpression(l,t);a.setData(this,c,o.type,o.offset,t)}}else if(s instanceof de){let i=0;if(e.args)for(let o=0;o<e.args.length;++o){let l=e.args[o],c=this.evalExpression(l,t);s.format===null&&(((n=c.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=c.typeInfo),a.setData(this,c,s.format,i,t),i+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof ne?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 p(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=q._priority.get(t.name);q._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 be(n);if(e.operator==="*")return n instanceof be?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof p?n.value:n instanceof d?Array.from(n.data):null;switch(e.operator){case"+":{if(w(r)){let i=r.map((o,l)=>+o);return new d(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(+s,a)}case"-":{if(w(r)){let i=r.map((o,l)=>-o);return new d(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(-s,a)}case"!":{if(w(r)){let i=r.map((o,l)=>o?0:1);return new d(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(s?0:1,a)}case"~":{if(w(r)){let i=r.map((o,l)=>~o);return new d(i,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(~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 p?n.value:n instanceof d||n instanceof T?Array.from(n.data):null,a=r instanceof p?r.value:r instanceof d||r instanceof T?Array.from(r.data):null;switch(e.operator){case"+":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v+f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b+c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c+b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i+o,l)}case"-":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v-f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b-c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c-b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i-o,l)}case"*":{if(w(s)&&w(a)){let c=s,f=a;if(n instanceof T&&r instanceof T){let b=function(A,L,D,I){if(z[L.name]===void 0||z[I.name]===void 0)return null;let S=z[L.name][0],O=z[L.name][1],V=z[I.name][0];if(S!==z[I.name][1])return null;let pe=new Array(V*O);for(let ve=0;ve<O;ve++)for(let ce=0;ce<V;ce++){let Qn=0;for(let mt=0;mt<S;mt++)Qn+=A[mt*O+ve]*D[ce*S+mt];pe[ve*V+ce]=Qn}return pe}(c,n.typeInfo,f,r.typeInfo);if(b===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let v=z[r.typeInfo.name][0],k=z[n.typeInfo.name][1],E=this.getTypeInfo(`mat${v}x${k}f`);return new T(b,E)}if(n instanceof T&&r instanceof d){let b=function(v,k,E,A){if(z[k.name]===void 0||Sn[A.name]===void 0)return null;let L=z[k.name][0],D=z[k.name][1];if(L!==E.length)return null;let I=new Array(D);for(let S=0;S<D;S++){let O=0;for(let V=0;V<L;V++)O+=v[V*D+S]*E[V];I[S]=O}return I}(c,n.typeInfo,f,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(b,r.typeInfo)}if(n instanceof d&&r instanceof T){let b=function(v,k,E,A){if(Sn[k.name]===void 0||z[A.name]===void 0)return null;let L=z[A.name][0],D=z[A.name][1];if(D!==v.length)return null;let I=[];for(let S=0;S<L;S++){let O=0;for(let V=0;V<D;V++)O+=v[V]*E[V*L+S];I[S]=O}return I}(c,n.typeInfo,f,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(b,n.typeInfo)}{if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v*f[k]);return new d(b,n.typeInfo)}}if(w(s)){let c=a,f=s.map((b,v)=>b*c);return n instanceof T?new T(f,n.typeInfo):new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c*b);return r instanceof T?new T(f,r.typeInfo):new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i*o,l)}case"%":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v%f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b%c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c%b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i%o,l)}case"/":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v/f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b/c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c/b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i/o,l)}case"&":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v&f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b&c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c&b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i&o,l)}case"|":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v|f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b|c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c|b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i|o,l)}case"^":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v^f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b^c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c^b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i^o,l)}case"<<":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v<<f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b<<c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c<<b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i<<o,l)}case">>":{if(w(s)&&w(a)){let c=s,f=a;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,k)=>v>>f[k]);return new d(b,n.typeInfo)}if(w(s)){let c=a,f=s.map((b,v)=>b>>c);return new d(f,n.typeInfo)}if(w(a)){let c=s,f=a.map((b,v)=>c>>b);return new d(f,r.typeInfo)}let i=s,o=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i>>o,l)}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 l=i.map((c,f)=>c>o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l>i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i>l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c<o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l<i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i<l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c===o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l==i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i==l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c!==o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l!==i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i!==l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c>=o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l>=i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i>=l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c<=o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l<=i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i<=l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c&&o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l&&i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i&&l?1:0);return new d(o,r.typeInfo)}return new p(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 l=i.map((c,f)=>c||o[f]?1:0);return new d(l,n.typeInfo)}if(w(s)){let i=a,o=s.map((l,c)=>l||i?1:0);return new d(o,n.typeInfo)}if(w(a)){let i=s,o=a.map((l,c)=>i||l?1:0);return new d(o,r.typeInfo)}return new p(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 p(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=Sn[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof R)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 d){let l=o.data;for(let c=0;c<l.length;++c){let f=l[c];a.push(f)}}else if(o instanceof p){let l=o.value;a.push(l)}}if(e.type instanceof y&&e.type.format===null&&(e.type.format=y.f32),a.length===0){let i=new Array(s).fill(0);return new d(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 d(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=z[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof R)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 d?a.push(...o.data):o instanceof p?a.push(o.value):o instanceof T&&a.push(...o.data)}if(n instanceof me&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let i=new Array(s[2]).fill(0);return new T(i,n).getSubData(this,e.postfix,t)}return a.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new T(a,n).getSubData(this,e.postfix,t)}};q._breakObj=new j(new X("BREAK",null),null),q._continueObj=new j(new X("CONTINUE",null),null),q._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);Wn=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Un=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Wn,this._exec=new q,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 H){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 rn||r instanceof Ge?r.type=this._forwardType(r.type):r instanceof Ee?r.format=this._forwardType(r.format):r instanceof oe||r instanceof Ae||r instanceof qe?r.type=this._forwardType(r.type):r instanceof Ce?r.returnType=this._forwardType(r.returnType):r instanceof nn&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof Yt){let t=this._getType(e.name);if(t)return t}else e instanceof Ge?e.type=this._forwardType(e.type):e instanceof Ee&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new Mn(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 l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l,n.push(this._updateNode(new nn(o,c,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 Ce(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 Pn);else if(this._match(h.keywords.break)){let t=this._updateNode(new Qt);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 Xt);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 Bn(t),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new Vt(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 rt(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 Nt(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 oe(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 Ae(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 R&&(n=r.type),this._updateNode(new qe(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 Wt(n.type===h.tokens.plus_plus?Ue.increment:Ue.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 Ut(tt.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 it(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 Rt([],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 rt){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 qt(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 ze){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 en(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 tn(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new ze)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new ze)):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 Gt(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 On(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 zt(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new J(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 J(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 J(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 J(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 J(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 J(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 J(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 J(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 J(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 J(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 U(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 _e(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 ge(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 _.void;case"bool":return _.bool;case"i32":return _.i32;case"u32":return _.u32;case"f32":return _.f32;case"f16":return _.f16;case"vec2f":return y.vec2f;case"vec3f":return y.vec3f;case"vec4f":return y.vec4f;case"vec2i":return y.vec2i;case"vec3i":return y.vec3i;case"vec4i":return y.vec4i;case"vec2u":return y.vec2u;case"vec3u":return y.vec3u;case"vec4u":return y.vec4u;case"vec2h":return y.vec2h;case"vec3h":return y.vec3h;case"vec4h":return y.vec4h;case"mat2x2f":return y.mat2x2f;case"mat2x3f":return y.mat2x3f;case"mat2x4f":return y.mat2x4f;case"mat3x2f":return y.mat3x2f;case"mat3x3f":return y.mat3x3f;case"mat3x4f":return y.mat3x4f;case"mat4x2f":return y.mat4x2f;case"mat4x3f":return y.mat4x3f;case"mat4x4f":return y.mat4x4f;case"mat2x2h":return y.mat2x2h;case"mat2x3h":return y.mat2x3h;case"mat2x4h":return y.mat2x4h;case"mat3x2h":return y.mat3x2h;case"mat3x3h":return y.mat3x3h;case"mat3x4h":return y.mat3x4h;case"mat4x2h":return y.mat4x2h;case"mat4x3h":return y.mat4x3h;case"mat4x4h":return y.mat4x4h;case"mat2x2i":return y.mat2x2i;case"mat2x3i":return y.mat2x3i;case"mat2x4i":return y.mat2x4i;case"mat3x2i":return y.mat3x2i;case"mat3x3i":return y.mat3x3i;case"mat3x4i":return y.mat3x4i;case"mat4x2i":return y.mat4x2i;case"mat4x3i":return y.mat4x3i;case"mat4x4i":return y.mat4x4i;case"mat2x2u":return y.mat2x2u;case"mat2x3u":return y.mat2x3u;case"mat2x4u":return y.mat2x4u;case"mat3x2u":return y.mat3x2u;case"mat3x3u":return y.mat3x3u;case"mat3x4u":return y.mat3x4u;case"mat4x2u":return y.mat4x2u;case"mat4x3u":return y.mat4x3u;case"mat4x4u":return y.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 ne(s,r)):this._updateNode(new ot(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new jt(n,r.value))}return this._updateNode(new H(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?_.i32:n.endsWith("u")||n.endsWith("U")?_.u32:_.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new R(new p(s,this._exec.getTypeInfo(r)),r))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,_.u32),this._updateNode(new R(new p(n,this._exec.getTypeInfo(_.u32)),_.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?_.f16:_.f32);let a=r?_.f16:_.f32;return this._updateNode(new R(new p(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 R(new p(n?1:0,this._exec.getTypeInfo(_.bool)),_.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 Zt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new ne(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(),l=this._type_decl();l!=null&&(l.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 rn(i,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new ie(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 R){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 R&&(e.type=e.value.type.name==="x32"?_.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=[_.f32],l=a.constEvaluate(this._exec,o);l instanceof p&&this._validateTypeRange(l.value,o[0]),o[0]instanceof y&&o[0].format===null&&l.typeInfo instanceof me&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?o[0].format=_.f16:l.typeInfo.format.name==="f32"?o[0].format=_.f32:l.typeInfo.format.name==="i32"?o[0].format=_.i32:l.typeInfo.format.name==="u32"?o[0].format=_.u32:l.typeInfo.format.name==="bool"?o[0].format=_.bool:console.error(`TODO: impelement template format type ${l.typeInfo.format.name}`)),s=this._updateNode(new R(l,o[0])),this._exec.context.setVariable(t.toString(),l)}catch{s=a}if(r!==null&&s instanceof R){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 R&&(r=(e=s?.type)!==null&&e!==void 0?e:_.f32,r===_.x32&&(r=_.i32));let i=this._updateNode(new qe(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 R){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 R&&(n=r.type.name==="x32"?_.i32:r.type);return r instanceof R&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new Ae(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 oe(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 st(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 Ht(e.toString(),t))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new $n(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 Dn(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 at(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 Yt(n));return this._forwardTypeCount++,r}return this._updateNode(new _(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 y(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 Ge(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 Ee(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 Te(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new Te(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 Te(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 Te(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 sn(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}},ln=class extends re{constructor(e){super(),e&&this.update(e)}update(e){let t=new Un().parse(e);this.updateAST(t)}}});function hn(u){let e={attributes:[],bindings:[]},t;try{t=_s(u)}catch(s){return qr.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:Rr(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,...vs(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=Rr(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:i})}}return e}function Rr(u){return u?.format?`${u.name}<${u.format.name}>`:u.name}function _s(u){try{return new ln(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 vs(u,e){if(u.resourceType!==he.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 qr,Gn=B(()=>{"use strict";qr=F(M(),1);Ur()});function Gr(u,e){if(!(e.mipLevels<=1)){if(e.dimension==="3d"){As(u,e);return}if(ws.includes(e.dimension)){Ts(u,e);return}throw new Error(`Cannot generate mipmaps for texture dimension "${e.dimension}" with WebGPU.`)}}function Ts(u,e){fn(u,e,["render","filter"],"render");let t=zr(e.format,"render",e.dimension),n=e.dimension,r=Cs(n),s=u.createSampler({minFilter:"linear",magFilter:"linear"}),a=u.createBuffer({byteLength:16,usage:Le.Buffer.UNIFORM|Le.Buffer.COPY_DST}),i=new Uint32Array(1),c={attributes:[],bindings:[ks,{type:"texture",name:"sourceTexture",group:0,location:1,viewDimension:n,sampleType:"float"},{type:"uniform",name:"uniforms",group:0,location:2}]},f=u.createShader({id:"mipmap-generation-render-vs",source:r,language:"wgsl",stage:"vertex"}),b=u.createShader({id:"mipmap-generation-render-fs",source:r,language:"wgsl",stage:"fragment"}),v=u.createRenderPipeline({id:`mipmap-generation-render:${e.dimension}:${e.format}`,vs:f,fs:b,shaderLayout:c,colorAttachmentFormats:[t],topology:"triangle-list"}),k=e.width,E=e.height,A=e.dimension==="2d"?1:e.depth;function L(D,I,S,O,V){i[0]=S,a.write(i);let pe=e.createView({dimension:"2d",baseMipLevel:I,mipLevelCount:1,baseArrayLayer:S,arrayLayerCount:1}),ve=u.createFramebuffer({colorAttachments:[pe]}),ce=u.beginRenderPass({id:`mipmap-generation:${e.format}:${I}:${S}`,framebuffer:ve});try{ce.setPipeline(v),ce.setBindings({sourceSampler:s,sourceTexture:D,uniforms:a}),ce.setParameters({viewport:[0,0,O,V,0,1],scissorRect:[0,0,O,V]}),ce.draw({vertexCount:3}),ce.end(),u.submit()}finally{pe.destroy(),ve.destroy()}}try{for(let D=1;D<e.mipLevels;++D){fn(u,e,["render","filter"],"render");let I=D-1,S=Math.max(1,k>>1),O=Math.max(1,E>>1),V=e.createView({dimension:n,baseMipLevel:I,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:e.depth});try{for(let pe=0;pe<A;++pe)L(V,D,pe,S,O)}finally{V.destroy()}k=S,E=O}}finally{v.destroy(),f.destroy(),b.destroy(),s.destroy(),a.destroy()}}function zr(u,e,t){if(Le.textureFormatDecoder.isColor(u))return u;throw new Error(`Cannot run ${e} mipmap generation for ${t} texture with format "${u}". Only color textures can be used for this operation. Required capabilities: color. Actual capabilities: color=false.`)}function As(u,e){fn(u,e,["filter","store"],"compute");let t=zr(e.format,"compute",e.dimension),n=Bs(t),s={bindings:[Ss,{type:"storage",name:"destinationTexture",group:0,location:1,format:t,viewDimension:"3d",access:"write-only"},Is]},a=u.createShader({id:"mipmap-generation-compute",source:n,language:"wgsl",stage:"compute"}),i=u.createComputePipeline({id:`mipmap-generation-compute:${e.format}`,shader:a,shaderLayout:s}),o=u.createBuffer({byteLength:32,usage:Le.Buffer.UNIFORM|Le.Buffer.COPY_DST}),l=new Uint32Array(8),c=e.width,f=e.height,b=e.depth;try{for(let v=1;v<e.mipLevels;++v){fn(u,e,["filter","store"],"compute");let k=Math.max(1,c>>1),E=Math.max(1,f>>1),A=Math.max(1,b>>1);l[0]=c,l[1]=f,l[2]=b,l[3]=k,l[4]=E,l[5]=A,l[6]=0,o.write(l);let L=e.createView({dimension:"3d",baseMipLevel:v-1,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}),D=e.createView({dimension:"3d",baseMipLevel:v,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1});i.setBindings({sourceTexture:L,destinationTexture:D,uniforms:o});try{let I=Math.ceil(k/Xe.x),S=Math.ceil(E/Xe.y),O=Math.ceil(A/Xe.z),V=u.beginComputePass({});V.setPipeline(i),V.dispatch(I,S,O),V.end(),u.submit()}finally{L.destroy(),D.destroy()}c=k,f=E,b=A}}finally{i.destroy(),a.destroy(),o.destroy()}}function fn(u,e,t,n){let{format:r,dimension:s}=e,a=u.getTextureFormatCapabilities(r);if(t.filter(o=>!a[o]).length>0){let o=t.join(" + "),l=t.map(c=>`${c}=${a[c]}`).join(", ");throw new Error(`Cannot run ${n} mipmap generation for ${s} texture with format "${r}". Required capabilities: ${o}. Actual capabilities: ${l}.`)}}function Es(u){switch(u){case"2d":return"texture_2d<f32>";case"2d-array":return"texture_2d_array<f32>";case"cube":return"texture_cube<f32>";case"cube-array":return"texture_cube_array<f32>";default:throw new Error(`Unsupported render dimension "${u}" for mipmap generation.`)}}function Cs(u){let e=Ls(u);return`
|
|
17
|
+
struct MipmapUniforms {
|
|
18
|
+
sourceLayer: u32,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
fn _touchUniform(uniforms: MipmapUniforms) {
|
|
22
|
+
let unusedSourceLayer = uniforms.sourceLayer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const faceMat = array(
|
|
26
|
+
mat3x3f(
|
|
27
|
+
0.0, 0.0, -2.0,
|
|
28
|
+
0.0, -2.0, 0.0,
|
|
29
|
+
1.0, 1.0, 1.0
|
|
30
|
+
), // pos-x
|
|
31
|
+
mat3x3f(
|
|
32
|
+
0.0, 0.0, 2.0,
|
|
33
|
+
0.0, -2.0, 0.0,
|
|
34
|
+
-1.0, 1.0, -1.0
|
|
35
|
+
), // neg-x
|
|
36
|
+
mat3x3f(
|
|
37
|
+
2.0, 0.0, 0.0,
|
|
38
|
+
0.0, 0.0, 2.0,
|
|
39
|
+
-1.0, 1.0, -1.0
|
|
40
|
+
), // pos-y
|
|
41
|
+
mat3x3f(
|
|
42
|
+
2.0, 0.0, 0.0,
|
|
43
|
+
0.0, 0.0, -2.0,
|
|
44
|
+
-1.0, -1.0, 1.0
|
|
45
|
+
), // neg-y
|
|
46
|
+
mat3x3f(
|
|
47
|
+
2.0, 0.0, 0.0,
|
|
48
|
+
0.0, -2.0, 0.0,
|
|
49
|
+
-1.0, 1.0, 1.0
|
|
50
|
+
), // pos-z
|
|
51
|
+
mat3x3f(
|
|
52
|
+
-2.0, 0.0, 0.0,
|
|
53
|
+
0.0, -2.0, 0.0,
|
|
54
|
+
1.0, 1.0, -1.0
|
|
55
|
+
) // neg-z
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
struct FragmentInputs {
|
|
59
|
+
@builtin(position) position: vec4f,
|
|
60
|
+
@location(0) texcoord: vec2f
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
struct VertexOutput {
|
|
64
|
+
@builtin(position) position: vec4f,
|
|
65
|
+
@location(0) texcoord: vec2f
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
@group(0) @binding(0) var sourceSampler: sampler;
|
|
69
|
+
@group(0) @binding(1) var sourceTexture: ${Es(u)};
|
|
70
|
+
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
71
|
+
|
|
72
|
+
@vertex
|
|
73
|
+
fn vertexMain(
|
|
74
|
+
@builtin(vertex_index) vertexIndex: u32
|
|
75
|
+
) -> VertexOutput {
|
|
76
|
+
const positions = array(
|
|
77
|
+
vec2f(-1.0, -1.0),
|
|
78
|
+
vec2f(-1.0, 3.0),
|
|
79
|
+
vec2f( 3.0, -1.0)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
let xy = positions[vertexIndex];
|
|
83
|
+
return VertexOutput(
|
|
84
|
+
vec4f(xy, 0.0, 1.0),
|
|
85
|
+
xy * vec2f(0.5, -0.5) + vec2f(0.5)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@fragment
|
|
90
|
+
fn fragmentMain(fsInput: VertexOutput) -> @location(0) vec4f {
|
|
91
|
+
_touchUniform(uniforms);
|
|
92
|
+
return ${e};
|
|
93
|
+
}
|
|
94
|
+
`}function Ls(u){let e="uniforms.sourceLayer";switch(u){case"2d":return"textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, 0.0)";case"2d-array":return`textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, i32(${e}), 0.0)`;case"cube":return`textureSampleLevel(sourceTexture, sourceSampler, faceMat[i32(${e})] * vec3f(fract(fsInput.texcoord), 1.0), 0.0)`;case"cube-array":return`textureSampleLevel(sourceTexture, sourceSampler, faceMat[i32(${e} % 6u)] * vec3f(fract(fsInput.texcoord), 1.0), i32(${e} / 6u), 0.0)`;default:throw new Error(`Unsupported render dimension "${u}" for mipmap generation.`)}}function Bs(u){return`
|
|
95
|
+
struct MipmapUniforms {
|
|
96
|
+
sourceWidth: u32,
|
|
97
|
+
sourceHeight: u32,
|
|
98
|
+
sourceDepth: u32,
|
|
99
|
+
destinationWidth: u32,
|
|
100
|
+
destinationHeight: u32,
|
|
101
|
+
destinationDepth: u32,
|
|
102
|
+
padding: u32,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
@group(0) @binding(0) var sourceTexture: texture_3d<f32>;
|
|
106
|
+
@group(0) @binding(1) var destinationTexture: texture_storage_3d<${u}, write>;
|
|
107
|
+
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
108
|
+
|
|
109
|
+
@compute @workgroup_size(${Xe.x}, ${Xe.y}, ${Xe.z})
|
|
110
|
+
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
|
|
111
|
+
if (
|
|
112
|
+
id.x >= uniforms.destinationWidth ||
|
|
113
|
+
id.y >= uniforms.destinationHeight ||
|
|
114
|
+
id.z >= uniforms.destinationDepth
|
|
115
|
+
) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let sourceBase = id * 2u;
|
|
120
|
+
let sourceX0 = min(sourceBase.x, uniforms.sourceWidth - 1u);
|
|
121
|
+
let sourceY0 = min(sourceBase.y, uniforms.sourceHeight - 1u);
|
|
122
|
+
let sourceZ0 = min(sourceBase.z, uniforms.sourceDepth - 1u);
|
|
123
|
+
|
|
124
|
+
let sourceX1 = min(sourceBase.x + 1u, uniforms.sourceWidth - 1u);
|
|
125
|
+
let sourceY1 = min(sourceBase.y + 1u, uniforms.sourceHeight - 1u);
|
|
126
|
+
let sourceZ1 = min(sourceBase.z + 1u, uniforms.sourceDepth - 1u);
|
|
127
|
+
|
|
128
|
+
var sum = textureLoad(
|
|
129
|
+
sourceTexture,
|
|
130
|
+
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ0)),
|
|
131
|
+
0
|
|
132
|
+
);
|
|
133
|
+
sum += textureLoad(
|
|
134
|
+
sourceTexture,
|
|
135
|
+
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ0)),
|
|
136
|
+
0
|
|
137
|
+
);
|
|
138
|
+
sum += textureLoad(
|
|
139
|
+
sourceTexture,
|
|
140
|
+
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ0)),
|
|
141
|
+
0
|
|
142
|
+
);
|
|
143
|
+
sum += textureLoad(
|
|
144
|
+
sourceTexture,
|
|
145
|
+
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ0)),
|
|
146
|
+
0
|
|
147
|
+
);
|
|
148
|
+
sum += textureLoad(
|
|
149
|
+
sourceTexture,
|
|
150
|
+
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ1)),
|
|
151
|
+
0
|
|
152
|
+
);
|
|
153
|
+
sum += textureLoad(
|
|
154
|
+
sourceTexture,
|
|
155
|
+
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ1)),
|
|
156
|
+
0
|
|
157
|
+
);
|
|
158
|
+
sum += textureLoad(
|
|
159
|
+
sourceTexture,
|
|
160
|
+
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ1)),
|
|
161
|
+
0
|
|
162
|
+
);
|
|
163
|
+
sum += textureLoad(
|
|
164
|
+
sourceTexture,
|
|
165
|
+
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ1)),
|
|
166
|
+
0
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
textureStore(
|
|
170
|
+
destinationTexture,
|
|
171
|
+
vec3<i32>(i32(id.x), i32(id.y), i32(id.z)),
|
|
172
|
+
vec4<f32>(sum.xyz / 8.0, sum.w / 8.0)
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
`}var Le,ws,Xe,ks,Ss,Is,Hr=B(()=>{"use strict";Le=F(M(),1),ws=["2d","2d-array","cube","cube-array"],Xe={x:4,y:4,z:4},ks={type:"sampler",name:"sourceSampler",group:0,location:0},Ss={type:"texture",name:"sourceTexture",group:0,location:0,viewDimension:"3d",sampleType:"float"},Is={type:"uniform",name:"uniforms",group:0,location:2}});var Qr={};Xn(Qr,{WebGPUDevice:()=>dt});function $s(u){if(globalThis.queueMicrotask){globalThis.queueMicrotask(u);return}Promise.resolve().then(u).catch(()=>{})}var ft,dt,zn=B(()=>{"use strict";ft=F(M(),1);dn();gn();tr();Ye();yn();fr();It();gr();kr();Sr();Ir();$r();Dr();Pr();wn();Gn();Hr();we();dt=class extends ft.Device{handle;adapter;adapterInfo;type="webgpu";preferredColorFormat=navigator.gpu.getPreferredCanvasFormat();preferredDepthFormat="depth24plus";features;info;limits;lost;canvasContext=null;_isLost=!1;_defaultSampler=null;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=ft.Device._getCanvasContextProps(e);s&&(this.canvasContext=new Je(this,this.adapter,s)),this.commandEncoder=this.createCommandEncoder({})}destroy(){this.commandEncoder?.destroy(),this._defaultSampler?.destroy(),this._defaultSampler=null,this.handle.destroy()}get isLost(){return this._isLost}getShaderLayout(e){return hn(e)}isVertexFormatSupported(e){return!this.getVertexFormatInfo(e).webglOnly}createBuffer(e){let t=this._normalizeBufferProps(e);return new ye(this,t)}createTexture(e){return new De(this,e)}createExternalTexture(e){return new _t(this,e)}createShader(e){return new Pe(this,e)}createSampler(e){return new Z(this,e)}getDefaultSampler(){return this._defaultSampler||=new Z(this,{id:`${this.id}-default-sampler`}),this._defaultSampler}createRenderPipeline(e){return new St(this,e)}createFramebuffer(e){return new xe(this,e)}createComputePipeline(e){return new Tt(this,e)}createVertexArray(e){return new Et(this,e)}createCommandEncoder(e){return new Dt(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new et(this,e)}createFence(){return new Ne(this)}createCanvasContext(e){return new Je(this,this.adapter,e)}createPresentationContext(e){return new Ct(this,e)}createPipelineLayout(e){return new Pt(this,e)}generateMipmapsWebGPU(e){Gr(this,e)}submit(e){let t=null;e||(t=this.commandEncoder,t.getTimeProfilingSlotCount()>0&&t.getTimeProfilingQuerySet()instanceof et&&t.getTimeProfilingQuerySet()._encodeResolveToReadBuffer(t,{firstQuery:0,queryCount:t.getTimeProfilingSlotCount()}),e=t.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:t.props.id,timeProfilingQuerySet:t.getTimeProfilingQuerySet()}));let n=Q(this),r=n?C():0,s=bt(this);try{this.pushErrorScope("validation");let a=n?C():0;if(this.handle.queue.submit([e.handle]),n&&(n.queueSubmitCount=(n.queueSubmitCount||0)+1,n.queueSubmitTimeMs=(n.queueSubmitTimeMs||0)+(C()-a)),this.popErrorScope(i=>{this.reportError(new Error(`${this} command submission: ${i.message}`),this)(),this.debug()}),t){let i=n?C():0;$s(()=>{t.resolveTimeProfilingQuerySet().then(()=>{this.commandEncoder._gpuTimeMs=t._gpuTimeMs}).catch(()=>{})}),n&&(n.submitResolveKickoffCount=(n.submitResolveKickoffCount||0)+1,n.submitResolveKickoffTimeMs=(n.submitResolveKickoffTimeMs||0)+(C()-i))}}finally{if(n){n.submitCount=(n.submitCount||0)+1,n.submitTimeMs=(n.submitTimeMs||0)+(C()-r);let i=s==="query-readback"?"queryReadbackSubmitCount":"defaultSubmitCount",o=s==="query-readback"?"queryReadbackSubmitTimeMs":"defaultSubmitTimeMs";n[i]=(n[i]||0)+1,n[o]=(n[o]||0)+(C()-r)}let a=n?C():0;e.destroy(),n&&(n.commandBufferDestroyCount=(n.commandBufferDestroyCount||0)+1,n.commandBufferDestroyTimeMs=(n.commandBufferDestroyTimeMs||0)+(C()-a))}}pushErrorScope(e){if(!this.props.debug)return;let t=Q(this),n=t?C():0;this.handle.pushErrorScope(e),t&&(t.errorScopePushCount=(t.errorScopePushCount||0)+1,t.errorScopeTimeMs=(t.errorScopeTimeMs||0)+(C()-n))}popErrorScope(e){if(!this.props.debug)return;let t=Q(this),n=t?C():0;this.handle.popErrorScope().then(r=>{r&&e(r)}),t&&(t.errorScopePopCount=(t.errorScopePopCount||0)+1,t.errorScopeTimeMs=(t.errorScopeTimeMs||0)+(C()-n))}_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",l=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:n,renderer:r,version:s,gpu:a,gpuType:l,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=["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 ft.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 pt={};Xn(pt,{WebGPUBuffer:()=>ye,WebGPUDevice:()=>dt,WebGPUFence:()=>Ne,WebGPUSampler:()=>Z,WebGPUShader:()=>Pe,WebGPUTexture:()=>De,getShaderLayoutFromWGSL:()=>hn,webgpuAdapter:()=>Xr});xt(pt,F(M(),1));var Be=F(M(),1),Hn=class extends Be.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(l=>!["minSubgroupSize","maxSubgroupSize"].includes(l));for(let l of o){let c=l,f=t.limits[c];typeof f=="number"&&(s[c]=f)}}let a=await t.requestDevice({requiredFeatures:r,requiredLimits:s}),{WebGPUDevice:i}=await Promise.resolve().then(()=>(zn(),Qr));Be.log.groupCollapsed(1,"WebGPUDevice created")();try{let o=new i(e,a,t,n);return Be.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),Be.log.table(1,o.info)(),o}finally{Be.log.groupEnd(1)()}}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},Xr=new Hn;zn();dn();gn();Ye();yn();wn();Gn();return ts(pt);})();
|
|
17
176
|
return __exports__;
|
|
18
177
|
});
|