@luma.gl/webgpu 9.3.0-alpha.6 → 9.3.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/adapter/helpers/get-bind-group.d.ts +3 -6
  2. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  3. package/dist/adapter/helpers/get-bind-group.js +11 -14
  4. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +3 -1
  6. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  7. package/dist/adapter/helpers/get-vertex-buffer-layout.js +17 -12
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  9. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  10. package/dist/adapter/helpers/webgpu-parameters.js +1 -0
  11. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-command-encoder.d.ts +3 -13
  13. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-command-encoder.js +68 -29
  15. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  16. package/dist/adapter/resources/webgpu-compute-pass.d.ts +3 -3
  17. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgpu-compute-pass.js +17 -7
  19. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  20. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +7 -9
  21. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-compute-pipeline.js +26 -29
  23. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  24. package/dist/adapter/resources/webgpu-fence.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgpu-fence.js +9 -1
  26. package/dist/adapter/resources/webgpu-fence.js.map +1 -1
  27. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts +1 -1
  28. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-pipeline-layout.js +10 -16
  30. package/dist/adapter/resources/webgpu-pipeline-layout.js.map +1 -1
  31. package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -4
  32. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgpu-render-pass.js +10 -10
  34. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  35. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +10 -9
  36. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  37. package/dist/adapter/resources/webgpu-render-pipeline.js +48 -38
  38. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  39. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgpu-shader.js +17 -1
  41. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  42. package/dist/adapter/resources/webgpu-texture.d.ts +8 -1
  43. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-texture.js +35 -43
  45. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  46. package/dist/adapter/webgpu-device.d.ts +6 -2
  47. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  48. package/dist/adapter/webgpu-device.js +60 -18
  49. package/dist/adapter/webgpu-device.js.map +1 -1
  50. package/dist/dist.dev.js +508 -311
  51. package/dist/dist.min.js +13 -13
  52. package/dist/index.cjs +439 -319
  53. package/dist/index.cjs.map +4 -4
  54. package/dist/wgsl/get-shader-layout-wgsl.d.ts.map +1 -1
  55. package/dist/wgsl/get-shader-layout-wgsl.js +8 -0
  56. package/dist/wgsl/get-shader-layout-wgsl.js.map +1 -1
  57. package/package.json +3 -3
  58. package/src/adapter/helpers/get-bind-group.ts +18 -27
  59. package/src/adapter/helpers/get-vertex-buffer-layout.ts +31 -12
  60. package/src/adapter/helpers/webgpu-parameters.ts +2 -0
  61. package/src/adapter/resources/webgpu-command-encoder.ts +99 -46
  62. package/src/adapter/resources/webgpu-compute-pass.ts +35 -8
  63. package/src/adapter/resources/webgpu-compute-pipeline.ts +43 -30
  64. package/src/adapter/resources/webgpu-fence.ts +11 -3
  65. package/src/adapter/resources/webgpu-pipeline-layout.ts +16 -14
  66. package/src/adapter/resources/webgpu-render-pass.ts +18 -14
  67. package/src/adapter/resources/webgpu-render-pipeline.ts +68 -46
  68. package/src/adapter/resources/webgpu-shader.ts +16 -1
  69. package/src/adapter/resources/webgpu-texture.ts +61 -44
  70. package/src/adapter/webgpu-device.ts +101 -25
  71. package/src/wgsl/get-shader-layout-wgsl.ts +9 -0
  72. package/dist/adapter/helpers/accessor-to-format.d.ts +0 -1
  73. package/dist/adapter/helpers/accessor-to-format.d.ts.map +0 -1
  74. package/dist/adapter/helpers/accessor-to-format.js +0 -105
  75. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  76. package/src/adapter/helpers/accessor-to-format.ts +0 -104
package/dist/dist.min.js CHANGED
@@ -4,16 +4,16 @@
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 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&&gt(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==`
7
+ "use strict";var __exports__=(()=>{var Hr=Object.create;var xt=Object.defineProperty;var Qr=Object.getOwnPropertyDescriptor;var Xr=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Yr=Object.prototype.hasOwnProperty;var L=(u,e)=>()=>(u&&(e=u(u=0)),e);var Kr=(u,e)=>()=>(e||u((e={exports:{}}).exports,e),e.exports),Xn=(u,e)=>{for(var t in e)xt(u,t,{get:e[t],enumerable:!0})},yt=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Xr(e))!Yr.call(u,r)&&r!==t&&xt(u,r,{get:()=>e[r],enumerable:!(n=Qr(e,r))||n.enumerable});return u},bt=(u,e,t)=>(yt(u,e,"default"),t&&yt(t,e,"default")),F=(u,e,t)=>(t=u!=null?Hr(jr(u)):{},yt(e||!u||!u.__esModule?xt(t,"default",{value:u,enumerable:!0}):t,u)),Zr=u=>yt(xt({},"__esModule",{value:!0}),u);var M=Kr((Ds,jn)=>{jn.exports=globalThis.luma});var ue,xe,pn=L(()=>{"use strict";ue=F(M(),1),xe=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 o=t.data;new o.constructor(s).set(o)}else t.onMapped?.(s,"mapped")}finally{this.handle.unmap()}this.device.popErrorScope(s=>{this.device.reportError(new Error(`${this} creation failed ${s.message}`),this)(),this.device.debug()}),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,o=(this.usage&ue.Buffer.MAP_WRITE)!==0?null:this._getMappableBuffer(ue.Buffer.MAP_WRITE|ue.Buffer.COPY_SRC,0,this.paddedByteLength),i=o||this;this.device.pushErrorScope("validation");try{await this.device.handle.queue.onSubmittedWorkDone(),await i.handle.mapAsync(GPUMapMode.WRITE,t,r);let a=i.handle.getMappedRange(t,r),l=a.slice(0,n);await e(l,"mapped"),new Uint8Array(a).set(new Uint8Array(l),0),i.handle.unmap(),o&&this._copyBuffer(o,t,r)}finally{this.device.popErrorScope(a=>{this.device.reportError(new Error(`${this}.mapAndWriteAsync() ${a.message}`),this)(),this.device.debug()}),o?.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,o=n,i=0,a="mapped";if((t%8!==0||n%4!==0)&&(s=Math.floor(t/8)*8,o=Math.ceil(r/4)*4-s,i=t-s,a="copied"),s+o>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,o),await f.handle.mapAsync(GPUMapMode.READ,s,o);let b=f.handle.getMappedRange(s,o),v=a==="mapped"?b:b.slice(i,i+n),w=await e(v,a);return f.handle.unmap(),w}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 xe(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 De(u){if(u.includes("webgl"))throw new Error("webgl-only format");return u}var mn=L(()=>{"use strict"});var Yn,Z,Ye=L(()=>{"use strict";Yn=F(M(),1),Z=class extends Yn.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 X(u){let e=u.userData[Jr];return e?.enabled?e:null}function _t(u){return u.userData[Kn]||null}function gn(u,e){u.userData[Kn]=e}function C(){return globalThis.performance?.now?.()??Date.now()}var Jr,Kn,Se=L(()=>{"use strict";Jr="cpu-hotspot-profiler",Kn="cpu-hotspot-submit-reason"});var Zn,Ke,Jn=L(()=>{"use strict";Zn=F(M(),1);Se();Ke=class extends Zn.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=X(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 be,Pe,yn=L(()=>{"use strict";be=F(M(),1);mn();Ye();Jn();Pe=class extends be.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||be.Texture.TEXTURE|be.Texture.COPY_DST,dimension:this.baseDimension,format:De(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 Ke(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 Ke(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(){be.log.warn(`${this}: generateMipmaps not supported in WebGPU`)()}getImageDataLayout(e){return{byteLength:0,bytesPerRow:0,rowsPerImage:0}}readBuffer(e={},t){if(!t)throw new Error(`${this} readBuffer requires a destination buffer`);let{x:n,y:r,z:s,width:o,height:i,depthOrArrayLayers:a,mipLevel:l,aspect:c}=this._getSupportedColorReadOptions(e),f=e.byteOffset??0,b=this.computeMemoryLayout({width:o,height:i,depthOrArrayLayers:a,mipLevel:l}),{byteLength:v}=b;if(t.byteLength<f+v)throw new Error(`${this} readBuffer target is too small (${t.byteLength} < ${f+v})`);let w=this.device.handle;this.device.pushErrorScope("validation");let E=w.createCommandEncoder();this.copyToBuffer(E,{x:n,y:r,z:s,width:o,height:i,depthOrArrayLayers:a,mipLevel:l,aspect:c,byteOffset:f},t);let A=E.finish();return this.device.handle.queue.submit([A]),this.device.popErrorScope(B=>{this.device.reportError(new Error(`${this} readBuffer: ${B.message}`),this)(),this.device.debug()}),t}async readDataAsync(e={}){throw new Error(`${this} readDataAsync is deprecated; use readBuffer() with an explicit destination buffer or DynamicTexture.readAsync()`)}copyToBuffer(e,t={},n){let{byteOffset:r=0,bytesPerRow:s,rowsPerImage:o,...i}=t,{x:a,y:l,z:c,width:f,height:b,depthOrArrayLayers:v,mipLevel:w,aspect:E}=this._getSupportedColorReadOptions(i),A=this.computeMemoryLayout({width:f,height:b,depthOrArrayLayers:v,mipLevel:w}),B=s??A.bytesPerRow,P=o??A.rowsPerImage,I=n;e.copyTextureToBuffer({texture:this.handle,origin:{x:a,y:l,z:c},mipLevel:w,aspect:E},{buffer:I.handle,offset:r,bytesPerRow:B,rowsPerImage:P},{width:f,height:b,depthOrArrayLayers:v})}writeBuffer(e,t={}){let n=this._normalizeTextureWriteOptions(t),{x:r,y:s,z:o,width:i,height:a,depthOrArrayLayers:l,mipLevel:c,aspect:f,byteOffset:b,bytesPerRow:v,rowsPerImage:w}=n,E=this.device.handle;this.device.pushErrorScope("validation");let A=E.createCommandEncoder();A.copyBufferToTexture({buffer:e.handle,offset:b,bytesPerRow:v,rowsPerImage:w},{texture:this.handle,origin:{x:r,y:s,z:o},mipLevel:c,aspect:f},{width:i,height:a,depthOrArrayLayers:l});let B=A.finish();this.device.handle.queue.submit([B]),this.device.popErrorScope(P=>{this.device.reportError(new Error(`${this} writeBuffer: ${P.message}`),this)(),this.device.debug()})}writeData(e,t={}){let n=this.device,r=this._normalizeTextureWriteOptions(t),{x:s,y:o,z:i,width:a,height:l,depthOrArrayLayers:c,mipLevel:f,aspect:b,byteOffset:v}=r,w=e,E=this.device.getTextureFormatInfo(this.format),A=be.textureFormatDecoder.computeMemoryLayout({format:this.format,width:a,height:l,depth:c,byteAlignment:1}),B=t.bytesPerRow??A.bytesPerRow,P=t.rowsPerImage??A.rowsPerImage,I=a,S=l;if(E.compressed){let O=E.blockWidth||1,V=E.blockHeight||1;I=Math.ceil(a/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:o,z:i}},w,{offset:v,bytesPerRow:B,rowsPerImage:P},{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,o=t?.format??this.format,i=n!==this.width||r!==this.height||s!==this.depth||o!==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=o),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 a=this.getAllocatedByteLength();a!==this._allocatedByteLength&&(this._allocatedByteLength=a,this.trackReferencedMemory(a,"Texture"))}this.view._reinitialize(this)}}});var er,vt,tr=L(()=>{"use strict";er=F(M(),1);Ye();vt=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,Oe,xn=L(()=>{"use strict";nr=F(M(),1),Oe=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(){let e=this.handle;if(!e)return[];let t;try{t=await e.getCompilationInfo()}catch(n){if(this.device.shouldIgnoreDroppedInstanceError(n,"getCompilationInfo"))return[];throw n}return t.messages}}});function le(u){return u.depthStencil=u.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},u.depthStencil}function wt(u){return le(u).stencilFront}function kt(u){return le(u).stencilBack}function J(u,e,t){St.log.warn(`${u} parameter not supported in WebGPU`)()}function rr(u,e={}){Object.assign(u,{...ts,...u}),ns(u,e)}function ns(u,e){for(let[t,n]of Object.entries(e)){let r=es[t];r?r(t,n,u):St.log.error(`Illegal parameter ${t} in WebGPU`)()}}function sr(u,e){return u.fragment.targets=u.fragment?.targets||[],Array.isArray(u.fragment?.targets)||St.log.warn("parameters: no targets array")(),u.fragment?.targets?.length===0&&u.fragment.targets?.push({}),u.fragment?.targets?.[0]}function Ie(u,e){let t=sr(u,e);return t.blend=t.blend||{color:{},alpha:{}},t.blend}var St,es,ts,ir=L(()=>{"use strict";St=F(M(),1);es={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},clearDepth:J,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=wt(t),r=kt(t);n.compare=e,r.compare=e},stencilPassOperation:(u,e,t)=>{let n=wt(t),r=kt(t);n.passOp=e,r.passOp=e},stencilFailOperation:(u,e,t)=>{let n=wt(t),r=kt(t);n.failOp=e,r.failOp=e},stencilDepthFailOperation:(u,e,t)=>{let n=wt(t),r=kt(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&&Ie(t,0)},blendColorOperation:(u,e,t)=>{let n=Ie(t,0);n.color=n.color||{},n.color.operation=e},blendColorSrcFactor:(u,e,t)=>{let n=Ie(t,0);n.color=n.color||{},n.color.srcFactor=e},blendColorDstFactor:(u,e,t)=>{let n=Ie(t,0);n.color.dstFactor=e},blendAlphaOperation:(u,e,t)=>{let n=Ie(t,0);n.alpha=n.alpha||{},n.alpha.operation=e},blendAlphaSrcFactor:(u,e,t)=>{let n=Ie(t,0);n.alpha=n.alpha||{},n.alpha.srcFactor=e},blendAlphaDstFactor:(u,e,t)=>{let n=Ie(t,0);n.alpha=n.alpha||{},n.alpha.dstFactor=e},unclippedDepth:J,provokingVertex:J,polygonMode:J,polygonOffsetLine:J,clipDistance0:J,clipDistance1:J,clipDistance2:J,clipDistance3:J,clipDistance4:J,clipDistance5:J,clipDistance6:J,clipDistance7:J};ts={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"}});function bn(u){if(u.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${u}`);return u}function ar(u,e,t){let n=[],r=new Set,s=u.attributes||[];for(let o of e){let i=[],a="vertex",l=0,c=o.format;if(o.attributes)for(let f of o.attributes){let b=f.attribute,v=or(u,b,r,t),w=v?.location;c=f.format||o.format,a=v?.stepMode||(v?.name.startsWith("instance")?"instance":"vertex"),i.push({format:bn(c),offset:f.byteOffset,shaderLocation:w}),l+=Me.vertexFormatDecoder.getVertexFormatInfo(c).byteLength}else{let f=or(u,o.name,r,t);if(!f)continue;l=Me.vertexFormatDecoder.getVertexFormatInfo(c).byteLength,a=f.stepMode||(f.name.startsWith("instance")?"instance":"vertex"),i.push({format:bn(c),offset:0,shaderLocation:f.location})}n.push({arrayStride:o.byteStride||l,stepMode:a,attributes:i})}for(let o of s)r.has(o.name)||n.push({arrayStride:Me.vertexFormatDecoder.getVertexFormatInfo("float32x3").byteLength,stepMode:o.stepMode||(o.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:bn("float32x3"),offset:0,shaderLocation:o.location}]});return n.sort((o,i)=>{let a=Math.min(...Array.from(o.attributes,c=>c.shaderLocation)),l=Math.min(...Array.from(i.attributes,c=>c.shaderLocation));return a-l}),n}function or(u,e,t,n){let r=u.attributes?.find(s=>s.name===e);if(!r){let s=n?.pipelineId?`RenderPipeline(${n.pipelineId})`:"RenderPipeline";return Me.log.warn(`${s}: Ignoring "${e}" attribute, since it is not present in shader layout.`)(),null}if(t){if(t.has(e))throw new Error(`Found multiple entries for attribute: ${e}`);t.add(e)}return r}var Me,cr=L(()=>{"use strict";Me=F(M(),1)});function rs(u){let e={};for(let[t,n]of Object.entries(u))n&&Object.keys(n).length>0&&(e[Number(t)]={});return e}var se,It,ur=L(()=>{"use strict";se=F(M(),1);ir();mn();cr();It=class extends se.RenderPipeline{device;handle;descriptor;vs;fs=null;_bindingsByGroup;_bindGroupCacheKeysByGroup={};get[Symbol.toStringTag](){return"WebGPURenderPipeline"}constructor(e,t){super(e,t),this.device=e,this.shaderLayout||=this.device.getShaderLayout(t.vs.source)||{attributes:[],bindings:[]},this.handle=this.props.handle;let n=null;this.handle||(n=this._getRenderPipelineDescriptor(),se.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),se.log.probe(1,JSON.stringify(n,null,2))(),se.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.descriptor=n,this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindingsByGroup=t.bindGroups||(0,se.normalizeBindingsByGroup)(this.shaderLayout,t.bindings),this._bindGroupCacheKeysByGroup=rs(this._bindingsByGroup)}destroy(){this.handle=null}setBindings(e){let t=(0,se.normalizeBindingsByGroup)(this.shaderLayout,e);for(let[n,r]of Object.entries(t)){let s=Number(n);for(let[o,i]of Object.entries(r||{})){let a=this._bindingsByGroup[s]||{};a[o]!==i&&((!this._bindingsByGroup[s]||this._bindingsByGroup[s]===a)&&(this._bindingsByGroup[s]={...a}),this._bindingsByGroup[s][o]=i,this._bindGroupCacheKeysByGroup[s]={})}}}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(o=>{this.device.reportError(new Error(`${this} setPipeline failed:
10
+ "${o.message}"`),this)(),this.device.debug()});let r=Boolean(e.bindGroups||e.bindings),s=(0,se._getDefaultBindGroupFactory)(this.device).getBindGroups(this,r?e.bindGroups||e.bindings:this._bindingsByGroup,r?e._bindGroupCacheKeys:this._bindGroupCacheKeysByGroup);for(let[o,i]of Object.entries(s))i&&t.handle.setBindGroup(Number(o),i);return 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}_getBindingsByGroupWebGPU(){return this._bindingsByGroup}_getBindGroupCacheKeysWebGPU(){return this._bindGroupCacheKeysByGroup}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:ar(this.shaderLayout,this.props.bufferLayout,{pipelineId:this.id})},t=[];if(this.props.colorAttachmentFormats)for(let i of this.props.colorAttachmentFormats)t.push(i?{format:De(i)}:null);else t.push({format:De(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},o=this.props.depthStencilAttachmentFormat||this.device.preferredDepthFormat;return this.props.parameters.depthWriteEnabled&&(s.depthStencil={format:De(o)}),rr(s,this.props.parameters),s}}});var lr,_e,Tt=L(()=>{"use strict";lr=F(M(),1),_e=class extends lr.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 Fe,ss,At,hr=L(()=>{"use strict";Fe=F(M(),1),ss={},At=class extends Fe.ComputePipeline{device;handle;_bindingsByGroup;_bindGroupCacheKeysByGroup;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._bindingsByGroup=ss,this._bindGroupCacheKeysByGroup={}}setBindings(e){let t=(0,Fe.normalizeBindingsByGroup)(this.shaderLayout,e);for(let[n,r]of Object.entries(t)){let s=Number(n);for(let[o,i]of Object.entries(r||{})){let a=this._bindingsByGroup[s]||{};a[o]!==i&&((!this._bindingsByGroup[s]||this._bindingsByGroup[s]===a)&&(this._bindingsByGroup[s]={...a}),this._bindingsByGroup[s][o]=i,this._bindGroupCacheKeysByGroup[s]={})}}}_getBindGroups(e,t){let n=Boolean(e);return(0,Fe._getDefaultBindGroupFactory)(this.device).getBindGroups(this,n?e:this._bindingsByGroup,n?t:this._bindGroupCacheKeysByGroup)}_getBindingsByGroupWebGPU(){return this._bindingsByGroup}_getBindGroupCacheKeysWebGPU(){return this._bindGroupCacheKeysByGroup}}});var ti,ni,ri,fr,dr=L(()=>{ti=globalThis.document||{},ni=globalThis.process||{},ri=globalThis.console,fr=globalThis.navigator||{}});function Et(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=L(()=>{});function pr(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||Et()}var mr=L(()=>{_n()});function vn(u){return!u&&!pr()?"Node":Et(u)?"Electron":(u||fr.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var gr=L(()=>{mr();_n();dr()});var yr=L(()=>{gr()});var Ze,Bt,xr=L(()=>{"use strict";Ze=F(M(),1);yr();Bt=class extends Ze.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&&(Ze.log.info(3,"setting index buffer",s?.handle,s?.indexType)(),r.handle.setIndexBuffer(s?.handle,s?.indexType));for(let o=0;o<this.maxVertexAttributes;o++){let i=this.attributes[o];i?.handle&&(Ze.log.info(3,`setting vertex buffer ${o}`,i?.handle)(),r.handle.setVertexBuffer(o,i?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return vn()==="Chrome"}}});var Ve,Je,br=L(()=>{"use strict";Ve=F(M(),1);Tt();Se();Je=class extends Ve.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=X(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,o]=this.getDrawingBufferSize();this.drawingBufferWidth=r.width,this.drawingBufferHeight=r.height,Ve.log.log(1,`${this}: Resized to compensate for initial canvas size mismatch ${s}x${o} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e?.depthStencilFormat),this.framebuffer||=new _e(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=X(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 Ne,Ct,_r=L(()=>{"use strict";Ne=F(M(),1);Tt();Se();Ct=class extends Ne.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=X(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,o]=this.getDrawingBufferSize();this.drawingBufferWidth=r.width,this.drawingBufferHeight=r.height,Ne.log.log(1,`${this[Symbol.toStringTag]}(${this.id}): Resized to compensate for initial canvas size mismatch ${s}x${o} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)()}return e?.depthStencilFormat&&this._createDepthStencilAttachment(e.depthStencilFormat),this.framebuffer||=new _e(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=X(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:Ne.Texture.RENDER_ATTACHMENT,format:e,width:this.drawingBufferWidth,height:this.drawingBufferHeight})),this.depthStencilAttachment}}});var vr,Lt,wr=L(()=>{"use strict";vr=F(M(),1),Lt=class extends vr.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 is(u){return{r:u[0],g:u[1],b:u[2],a:u[3]}}var me,$t,kr=L(()=>{"use strict";me=F(M(),1);Se();$t=class extends me.RenderPass{device;handle;framebuffer;pipeline=null;bindings={};constructor(e,t={},n=e.commandEncoder.handle){super(e,t),this.device=e;let{props:r}=this;this.framebuffer=r.framebuffer||e.getCanvasContext().getCurrentFramebuffer();let s=X(this.device);if(s){let i=r.framebuffer?"explicitFramebufferRenderPassCount":"defaultFramebufferRenderPassCount";s[i]=(s[i]||0)+1}let o=s?C():0;try{let i=s?C():0,a=this.getRenderPassDescriptor(this.framebuffer);if(r.occlusionQuerySet&&(a.occlusionQuerySet=r.occlusionQuerySet.handle),r.timestampQuerySet){let c=r.timestampQuerySet;c?._invalidateResults(),a.timestampWrites=c?{querySet:c.handle,beginningOfPassWriteIndex:r.beginTimestampIndex,endOfPassWriteIndex:r.endTimestampIndex}:void 0}s&&(s.renderPassDescriptorAssemblyCount=(s.renderPassDescriptorAssemblyCount||0)+1,s.renderPassDescriptorAssemblyTimeMs=(s.renderPassDescriptorAssemblyTimeMs||0)+(C()-i)),this.device.pushErrorScope("validation");let l=s?C():0;this.handle=this.props.handle||n.beginRenderPass(a),s&&(s.renderPassBeginCount=(s.renderPassBeginCount||0)+1,s.renderPassBeginTimeMs=(s.renderPassBeginTimeMs||0)+(C()-l)),this.device.popErrorScope(c=>{this.device.reportError(new Error(`${this} creation failed:
11
+ "${c.message}"`),this)(),this.device.debug()}),this.handle.label=this.props.id,me.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),me.log.probe(3,JSON.stringify(a,null,2))(),me.log.groupEnd(3)()}finally{s&&(s.renderPassSetupCount=(s.renderPassSetupCount||0)+1,s.renderPassSetupTimeMs=(s.renderPassSetupTimeMs||0)+(C()-o))}}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&&(0,me._getDefaultBindGroupFactory)(this.device).getBindGroups(this.pipeline,e)||{};for(let[n,r]of Object.entries(t))r&&this.handle.setBindGroup(Number(n),r)}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:is(this.props.clearColors?.[r]||this.props.clearColor||me.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 et,Dt,Sr=L(()=>{"use strict";et=F(M(),1),Dt=class extends et.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t={},n=e.commandEncoder.handle){super(e,t),this.device=e;let{props:r}=this,s;if(r.timestampQuerySet){let o=r.timestampQuerySet;o&&(o._invalidateResults(),s={querySet:o.handle,beginningOfPassWriteIndex:r.beginTimestampIndex,endOfPassWriteIndex:r.endTimestampIndex})}this.handle=this.props.handle||n.beginComputePass({label:this.props.id,timestampWrites:s})}destroy(){this.destroyResource()}end(){this.destroyed||(this.handle.end(),this.destroy())}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t;let n=(0,et._getDefaultBindGroupFactory)(this.device).getBindGroups(this._webgpuPipeline,this._webgpuPipeline._getBindingsByGroupWebGPU(),this._webgpuPipeline._getBindGroupCacheKeysWebGPU());for(let[r,s]of Object.entries(n))s&&this.handle.setBindGroup(Number(r),s)}setBindings(e){let t=this._webgpuPipeline&&(0,et._getDefaultBindGroupFactory)(this.device).getBindGroups(this._webgpuPipeline,e)||{};for(let[n,r]of Object.entries(t))r&&this.handle.setBindGroup(Number(n),r)}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 Ir,Pt,Tr=L(()=>{"use strict";Ir=F(M(),1);wr();kr();Sr();Pt=class extends Ir.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 $t(this.device,this._applyTimeProfilingToPassProps(e),this.handle)}beginComputePass(e={}){return new Dt(this.device,this._applyTimeProfilingToPassProps(e),this.handle)}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,r=e.origin??[0,0,0],s=e.size;this.handle.copyBufferToTexture({buffer:t.handle,offset:e.byteOffset??0,bytesPerRow:e.bytesPerRow,rowsPerImage:e.rowsPerImage},{texture:n.handle,mipLevel:e.mipLevel??0,origin:{x:r[0]??0,y:r[1]??0,z:r[2]??0},aspect:e.aspect},{width:s[0],height:s[1],depthOrArrayLayers:s[2]})}copyTextureToBuffer(e){let{sourceTexture:t,destinationBuffer:n,origin:r=[0,0,0],byteOffset:s=0,width:o,height:i,depthOrArrayLayers:a,mipLevel:l,aspect:c}=e;t.copyToBuffer(this.handle,{x:r[0]??0,y:r[1]??0,z:r[2]??0,width:o,height:i,depthOrArrayLayers:a,mipLevel:l,aspect:c,byteOffset:s,bytesPerRow:e.bytesPerRow,rowsPerImage:e.rowsPerImage},n)}copyTextureToTexture(e){let t=e.sourceTexture,n=e.destinationTexture,r=t._normalizeTextureReadOptions({x:e.origin?.[0]??0,y:e.origin?.[1]??0,z:e.origin?.[2]??0,width:e.width,height:e.height,depthOrArrayLayers:e.depthOrArrayLayers,mipLevel:e.mipLevel??0,aspect:e.aspect??"all"});this.handle.copyTextureToTexture({texture:t.handle,mipLevel:r.mipLevel,origin:{x:r.x,y:r.y,z:r.z},aspect:r.aspect},{texture:n.handle,mipLevel:e.destinationMipLevel??0,origin:{x:e.destinationOrigin?.[0]??0,y:e.destinationOrigin?.[1]??0,z:e.destinationOrigin?.[2]??0},aspect:e.destinationAspect??r.aspect},{width:r.width,height:r.height,depthOrArrayLayers:r.depthOrArrayLayers})}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 Te,tt,Ar=L(()=>{"use strict";Te=F(M(),1);Se();tt=class extends Te.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 o=await this._readResultsPromise;if(r=this._resultsPendingResolution,!r)return o.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=_t(this.device)||void 0;gn(this.device,"query-readback");try{this.device.submit(r)}finally{gn(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:Te.Buffer.QUERY_RESOLVE|Te.Buffer.COPY_SRC,byteLength:e}),this.attachResource(this._resolveBuffer),this._readBuffer=this.device.createBuffer({id:`${this.id}-read-buffer`,usage:Te.Buffer.COPY_DST|Te.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,o=n*BigUint64Array.BYTES_PER_ELEMENT;return e.resolveQuerySet(this,this._resolveBuffer,{firstQuery:n,queryCount:r,destinationOffset:o}),e.copyBufferToBuffer({sourceBuffer:this._resolveBuffer,sourceOffset:o,destinationBuffer:this._readBuffer,destinationOffset:o,size:s}),this._resultsPendingResolution=!1,!0}}});var Mt,Ot,os,Er=L(()=>{"use strict";Mt=F(M(),1),Ot=class extends Mt.PipelineLayout{device;handle;constructor(e,t){super(e,t),this.device=e;let n=this.mapShaderLayoutToBindGroupEntriesByGroup();this.handle=this.device.handle.createPipelineLayout({label:t?.id??"unnamed-pipeline-layout",bindGroupLayouts:n.map((r,s)=>this.device.handle.createBindGroupLayout({label:`bind-group-layout-${s}`,entries:r}))})}destroy(){this.handle=null}mapShaderLayoutToBindGroupEntriesByGroup(){let e=this.props.shaderLayout.bindings.reduce((n,r)=>Math.max(n,r.group),-1),t=Array.from({length:e+1},()=>[]);for(let n of this.props.shaderLayout.bindings){let 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":{os(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:Mt.log.warn("unhandled binding type when creating pipeline descriptor")()}let s=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE;t[n.group].push({binding:n.location,visibility:n.visibility||s,...r})}return t}},os=u=>u.format!==void 0});var Br,Ue,wn=L(()=>{"use strict";Br=F(M(),1),Ue=class extends Br.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}).catch(n=>{if(!this.device.shouldIgnoreDroppedInstanceError(n))throw n})}isSignaled(){return this._signaled}destroy(){}}});function as(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 us(u){$r[0]=u;let e=cs[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return q[0]=t<<15|31744|(r!==0?512:0),q[0];if(n===0){if(r===0)return q[0]=t<<15,q[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),q[0]=t<<15|n<<10|r>>13,q[0]):(q[0]=t<<15,q[0])}return n=n-127+15,n>=31?(q[0]=t<<15|31744,q[0]):n<=0?n<-10?(q[0]=t<<15,q[0]):(r=(8388608|r)>>1-n,q[0]=t<<15|r>>13,q[0]):(r>>=13,q[0]=t<<15|n<<10|r,q[0])}function Cr(u){let e=112+(u>>6&31)<<23|(63&u)<<17;return Rn[0]=e,Dr[0]}function ls(u,e,t,n,r,s,o,i,a){let l=n*(o>>=r)*(s>>=r)+t*o+e*i;switch(a){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[Cr(2047&c),Cr(f),function(v){let w=112+(v>>5&31)<<23|(31&v)<<18;return Rn[0]=w,Dr[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]=as(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 D(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 o=us(r[s]);new Uint16Array(u.buffer,e,1)[0]=o,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 hs(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 k(u){return Array.isArray(u)||u?.buffer instanceof ArrayBuffer}function Lr(u,e,t){if(e===t)return u;if(e==="f32"){if(t==="i32"||t==="x32")return cn[0]=u,fs[0];if(t==="u32")return cn[0]=u,ds[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return un[0]=u,ps[0];if(t==="u32")return un[0]=u,ms[0]}else if(e==="u32"){if(t==="f32")return ln[0]=u,gs[0];if(t==="i32"||t==="x32")return ln[0]=u,ys[0]}return console.error(`Unsupported cast from ${e} to ${t}`),u}var j,Ft,fe,de,rt,ge,he,We,In,Tn,Vt,An,En,Bn,Cn,$r,cs,q,Rn,Dr,kn,Y,Qe,Xe,Pr,N,Ce,Ln,Nt,st,Ut,ae,it,Ee,qe,Re,nt,x,g,Wt,Rt,ot,Gt,qt,zt,Ht,$n,Dn,Qt,at,Pn,Xt,jt,_,Yt,ie,y,ze,Be,Ae,te,ye,ne,ct,H,Kt,R,Zt,we,Jt,W,ee,en,He,tn,nn,rn,On,sn,on,K,ut,ve,p,d,T,U,oe,m,h,an,Mn,cn,fs,ds,un,ps,ms,ln,gs,ys,Fn,Ge,re,Gn,lt,ht,ft,Vn,Nn,Sn,z,G,Un,Wn,hn,Or=L(()=>{j=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}},Ft=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 j{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 j{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}},rt=class extends j{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}},ge=class extends j{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,o,i){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=o,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}},Vt=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}},Bn=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}},Cn=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}};$r=new Float32Array(1),cs=new Int32Array($r.buffer),q=new Uint16Array(1);Rn=new Uint32Array(1),Dr=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(Qe.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Xe.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};Y._id=0;Qe=class extends Y{};Qe.instance=new Qe;Xe=class extends Y{};Xe.instance=new Xe;Pr=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,o){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=o}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)}},Ln=class extends N{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},Nt=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)}},st=class extends N{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},Ut=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)}},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"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},it=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)}},Ee=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="--"})(Re||(Re={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return u[t]}})(Re||(Re={}));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=">>="})(nt||(nt={})),(u=>{u.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(nt||(nt={}));Rt=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)}},ot=class extends N{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Pr.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},Gt=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)}},zt=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)}},Ht=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"}},Qt=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"}},Xt=class extends N{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},jt=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);ze=class extends _{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},Be=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}},Ae=class extends _{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},te=class extends Y{constructor(){super(),this.postfix=null}},ye=class extends te{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},ne=class extends te{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)}},ct=class extends te{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 Pr.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 te{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)}},Kt=class extends te{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 te{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 te{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},we=class extends te{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Jt=class extends te{constructor(){super()}},W=class extends Jt{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)}},ee=class extends Jt{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)}},en=class extends Y{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}},He=class extends te{constructor(){super()}get astNodeType(){return"default"}},tn=class extends en{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},nn=class extends en{constructor(e){super(e)}get astNodeType(){return"default"}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"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)}},sn=class extends Y{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},on=class extends Y{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},K=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=K._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()}>`}};K._id=0;ut=class extends K{constructor(){super(new j("void",null),null)}toString(){return"void"}};ut.void=new ut;ve=class extends K{constructor(e){super(new rt("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 K{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 K{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 ye?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 ge)r=this.typeInfo.format||r;else{let o=this.typeInfo.name;o==="vec2f"||o==="vec3f"||o==="vec4f"?r=e.getTypeInfo("f32"):o==="vec2i"||o==="vec3i"||o==="vec4i"?r=e.getTypeInfo("i32"):o==="vec2b"||o==="vec3b"||o==="vec4b"?r=e.getTypeInfo("bool"):o==="vec2u"||o==="vec3u"||o==="vec4u"?r=e.getTypeInfo("u32"):o==="vec2h"||o==="vec3h"||o==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${o}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof we){let o=t.index,i=-1;if(o instanceof R){if(!(o.value instanceof p))return console.error(`GetSubData: Invalid array index ${o.value}`),null;i=o.value.value}else{let a=e.evalExpression(o,n);if(!(a instanceof p))return console.error("GetSubData: Unknown index type",o),null;i=a.value}if(i<0||i>=s.data.length)return console.error("GetSubData: Index out of range",i),null;if(s.data instanceof Float32Array){let a=new Float32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new p(a,r)}if(s.data instanceof Int32Array){let a=new Int32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new p(a,r)}if(s.data instanceof Uint32Array){let a=new Uint32Array(s.data.buffer,s.data.byteOffset+4*i,1);return new p(a,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof ye))return console.error("GetSubData: Unknown postfix",t),null;{let o=t.value.toLowerCase();if(o.length===1){let a=0;if(o==="x"||o==="r")a=0;else if(o==="y"||o==="g")a=1;else if(o==="z"||o==="b")a=2;else{if(o!=="w"&&o!=="a")return console.error(`GetSubData: Unknown member ${o}`),null;a=3}if(this.data instanceof Float32Array){let l=new Float32Array(this.data.buffer,this.data.byteOffset+4*a,1);return new p(l,r,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*a,1);return new p(l,r,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*a,1);return new p(l,r,this)}}let i=[];for(let a of o)a==="x"||a==="r"?i.push(this.data[0]):a==="y"||a==="g"?i.push(this.data[1]):a==="z"||a==="b"?i.push(this.data[2]):a==="w"||a==="a"?i.push(this.data[3]):console.error(`GetDataValue: Unknown member ${a}`);s=hs(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 K{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 ye?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 ge)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 we){let s=t.index,o=-1;if(s instanceof R){if(!(s.value instanceof p))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;o=s.value.value}else{let l=e.evalExpression(s,n);if(!(l instanceof p))return console.error("GetDataValue: Unknown index type",s),null;o=l.value}if(o<0||o>=this.data.length)return console.error("GetDataValue: Index out of range",o),null;let i=r.endsWith("h")?"h":"f",a;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")a=new d(new Float32Array(this.data.buffer,this.data.byteOffset+2*o*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")a=new d(new Float32Array(this.data.buffer,this.data.byteOffset+3*o*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;a=new d(new Float32Array(this.data.buffer,this.data.byteOffset+4*o*4,4),e.getTypeInfo(`vec4${i}`))}return t.postfix?a.getSubData(e,t.postfix,n):a}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}},U=class extends K{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 U(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,o=this.typeInfo;for(;n;){if(n instanceof we)if(o 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*o.stride}else{let a=e.evalExpression(i,r);if(!(a instanceof p))return void console.error("SetDataValue: Unknown index type",i);s+=a.value*o.stride}o=o.format}else console.error(`SetDataValue: Type ${o.getTypeName()} is not an array`);else{if(!(n instanceof ye))return void console.error("SetDataValue: Unknown postfix type",n);{let i=n.value;if(o instanceof fe){let a=!1;for(let l of o.members)if(l.name===i){s+=l.offset,o=l.type,a=!0;break}if(!a)return void console.error(`SetDataValue: Member ${i} not found`)}else if(o instanceof j){let a=o.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 a==="vec2f"?void(new Float32Array(this.buffer,s,2)[l]=c):a==="vec3f"?void(new Float32Array(this.buffer,s,3)[l]=c):a==="vec4f"?void(new Float32Array(this.buffer,s,4)[l]=c):a==="vec2i"?void(new Int32Array(this.buffer,s,2)[l]=c):a==="vec3i"?void(new Int32Array(this.buffer,s,3)[l]=c):a==="vec4i"?void(new Int32Array(this.buffer,s,4)[l]=c):a==="vec2u"?void(new Uint32Array(this.buffer,s,2)[l]=c):a==="vec3u"?void(new Uint32Array(this.buffer,s,3)[l]=c):a==="vec4u"?void(new Uint32Array(this.buffer,s,4)[l]=c):void console.error(`SetDataValue: Type ${a} is not a struct`)}}}n=n.postfix}this.setData(e,t,o,s,r)}setData(e,t,n,r,s){let o=n.getTypeName();if(o!=="f32"&&o!=="f16")if(o!=="i32"&&o!=="atomic<i32>"&&o!=="x32")if(o!=="u32"&&o!=="atomic<u32>")if(o!=="bool"){if(o==="vec2f"||o==="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(o==="vec3f"||o==="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(o==="vec4f"||o==="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(o==="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(o==="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(o==="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(o==="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(o==="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(o==="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(o==="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(o==="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(o==="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(o==="mat2x2f"||o==="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(o==="mat2x3f"||o==="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(o==="mat2x4f"||o==="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(o==="mat3x2f"||o==="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(o==="mat3x3f"||o==="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(o==="mat3x4f"||o==="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(o==="mat4x2f"||o==="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(o==="mat4x3f"||o==="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(o==="mat4x4f"||o==="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 U){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",o,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${o}`)}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,o;if(t===null)return this;let i=this.offset,a=this.typeInfo;for(;t;){if(t instanceof we){let c=t.index,f=c instanceof te?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),a instanceof de)i+=b*a.stride,a=a.format;else{let v=a.getTypeName();v==="mat4x4"||v==="mat4x4f"||v==="mat4x4h"?(i+=16*b,a=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${a.getTypeName()} is not an array`)}}else{if(!(t instanceof ye))return console.error("GetDataValue: Unknown postfix type",t),null;{let c=t.value;if(a instanceof fe){let f=!1;for(let b of a.members)if(b.name===c){i+=b.offset,a=b.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${c} not found`),null}else if(a instanceof j){let f=a.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 w=0;w<c.length;++w){let E=c[w].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 B=new Float32Array(this.buffer,i,3);v.push(B[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 B=new Uint32Array(this.buffer,i,2);v.push(B[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?a=e.getTypeInfo(`vec2${b}`):v.length===3?a=e.getTypeInfo(`vec3${b}`):v.length===4?a=e.getTypeInfo(`vec4${b}`):console.error(`GetDataValue: Invalid vector length ${v.length}`),new d(v,a,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=a.getTypeName();return l==="f32"?new p(new Float32Array(this.buffer,i,1),a,this):l==="i32"?new p(new Int32Array(this.buffer,i,1),a,this):l==="u32"?new p(new Uint32Array(this.buffer,i,1),a,this):l==="vec2f"?new d(new Float32Array(this.buffer,i,2),a,this):l==="vec3f"?new d(new Float32Array(this.buffer,i,3),a,this):l==="vec4f"?new d(new Float32Array(this.buffer,i,4),a,this):l==="vec2i"?new d(new Int32Array(this.buffer,i,2),a,this):l==="vec3i"?new d(new Int32Array(this.buffer,i,3),a,this):l==="vec4i"?new d(new Int32Array(this.buffer,i,4),a,this):l==="vec2u"?new d(new Uint32Array(this.buffer,i,2),a,this):l==="vec3u"?new d(new Uint32Array(this.buffer,i,3),a,this):l==="vec4u"?new d(new Uint32Array(this.buffer,i,4),a,this):a instanceof ge&&a.name==="atomic"?((r=a.format)===null||r===void 0?void 0:r.name)==="u32"?new p(new Uint32Array(this.buffer,i,1)[0],a.format,this):((s=a.format)===null||s===void 0?void 0:s.name)==="i32"?new p(new Int32Array(this.buffer,i,1)[0],a.format,this):(console.error(`GetDataValue: Invalid atomic format ${(o=a.format)===null||o===void 0?void 0:o.name}`),null):new U(this.buffer,a,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}},oe=class extends K{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new oe(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,o=this.dimension;return n/t.blockWidth*(o==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,o=this.bytesPerRow,i=this.height,a=this.data[r];return ls(new Uint8Array(a),e,t,n,r,i,o,s,this.format)}setPixel(e,t,n,r,s){let o=this.texelByteSize,i=this.bytesPerRow,a=this.height,l=this.data[r];(function(c,f,b,v,w,E,A,B,P,I){let S=v*(A>>=w)*(E>>=w)+b*A+f*B;switch(P){case"r8unorm":return void D(c,S,"8unorm",1,I);case"r8snorm":return void D(c,S,"8snorm",1,I);case"r8uint":return void D(c,S,"8uint",1,I);case"r8sint":return void D(c,S,"8sint",1,I);case"rg8unorm":return void D(c,S,"8unorm",2,I);case"rg8snorm":return void D(c,S,"8snorm",2,I);case"rg8uint":return void D(c,S,"8uint",2,I);case"rg8sint":return void D(c,S,"8sint",2,I);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void D(c,S,"8unorm",4,I);case"rgba8snorm":return void D(c,S,"8snorm",4,I);case"rgba8uint":return void D(c,S,"8uint",4,I);case"rgba8sint":return void D(c,S,"8sint",4,I);case"r16uint":return void D(c,S,"16uint",1,I);case"r16sint":return void D(c,S,"16sint",1,I);case"r16float":return void D(c,S,"16float",1,I);case"rg16uint":return void D(c,S,"16uint",2,I);case"rg16sint":return void D(c,S,"16sint",2,I);case"rg16float":return void D(c,S,"16float",2,I);case"rgba16uint":return void D(c,S,"16uint",4,I);case"rgba16sint":return void D(c,S,"16sint",4,I);case"rgba16float":return void D(c,S,"16float",4,I);case"r32uint":return void D(c,S,"32uint",1,I);case"r32sint":return void D(c,S,"32sint",1,I);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void D(c,S,"32float",1,I);case"rg32uint":return void D(c,S,"32uint",2,I);case"rg32sint":return void D(c,S,"32sint",2,I);case"rg32float":return void D(c,S,"32float",2,I);case"rgba32uint":return void D(c,S,"32uint",4,I);case"rgba32sint":return void D(c,S,"32sint",4,I);case"rgba32float":return void D(c,S,"32float",4,I);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),e,t,n,r,a,i,o,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
- `;){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,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`
14
+ `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let o=1;for(;o>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
15
+ `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),o--,o==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),o++)}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 o=this._peekAhead();for(;this._isAlphaNumeric(o);)e+=this._advance(),o=this._peekAhead()}if(r){let o=h.keywords[e];if(o)return this._addToken(o),!0}if(r||s)return this._addToken(h.tokens.ident),!0;for(;;){let o=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 a=this._tokens.length-1;if((h.literal_or_ident.indexOf(this._tokens[a].type)!=-1||this._tokens[a].type==h.tokens.paren_right)&&i!=">")return this._addToken(o),!0}if(e==">"&&(i==">"||i=="=")){let a=!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()&&(a=!0);break}if(a)return this._addToken(o),!0}if(o===h.none){let a=e,l=0,c=2;for(let f=0;f<c;++f)if(a+=this._peekAhead(f),o=this._findType(a),o!==h.none){l=f;break}if(o===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=a,this._current+=l+1}if(n=o,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))}};cn=new Float32Array(1),fs=new Uint32Array(cn.buffer),ds=new Uint32Array(cn.buffer),un=new Int32Array(1),ps=new Float32Array(un.buffer),ms=new Uint32Array(un.buffer),ln=new Uint32Array(1),gs=new Float32Array(ln.buffer),ys=new Int32Array(ln.buffer);Fn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},Ge=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 Cn,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 it){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),o=this.getTypeInfo(n.type,n.attributes),i=new We(n.name,o,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),o=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(o),a=new We(n.name,o,r,s,n.attributes,i?he.StorageTexture:he.Storage,n.access);a.access||(a.access="read"),this.storage.push(a);continue}if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(o),a=new We(n.name,o,r,s,n.attributes,i?he.StorageTexture:he.Texture,n.access);a.access||(a.access="read"),i?this.storage.push(a):this.textures.push(a);continue}if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),o=this.getTypeInfo(n.type,n.attributes),i=new We(n.name,o,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"),o=n||r||s,i=new Bn(t.name,o?.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,o&&(this._functions.get(t.name).inUse=!0,i.inUse=!0,i.resources=this._findResources(t,!!o),i.inputs=this._getInputs(t.args),i.outputs=this._getOutputs(t.returnType),this.entry[o.name].push(i)),i.arguments=t.args.map(a=>new En(a.name,this.getTypeInfo(a.type,a.attributes),a.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,o;if(n instanceof on){if(n.value)if(k(n.value))for(let i of n.value)for(let a of this.overrides)i===a.name&&((r=t.info)===null||r===void 0||r.overrides.push(a));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&&((o=t.info)===null||o===void 0||o.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(o=>{if(o instanceof Qe)s.push({});else if(o instanceof Xe)s.pop();else if(o instanceof ae){let i=o;t&&i.type!==null&&this._markStructsFromAST(i.type),s.length>0&&(s[s.length-1][i.name]=i)}else if(o instanceof ne){let i=o;t&&i.type!==null&&this._markStructsFromAST(i.type)}else if(o instanceof Ee){let i=o;t&&i.type!==null&&this._markStructsFromAST(i.type),s.length>0&&(s[s.length-1][i.name]=i)}else if(o instanceof H){let i=o;if(s.length>0&&s[s.length-1][i.name])return;let a=r._findResource(i.name);a&&n.push(a)}else if(o instanceof ct){let i=o,a=r._functions.get(i.name);a&&(t&&(a.inUse=!0),e.calls.add(a.node),a.resources===null&&(a.resources=r._findResources(a.node,t)),n.push(...a.resources))}else if(o instanceof ot){let i=o,a=r._functions.get(i.name);a&&(t&&(a.inUse=!0),e.calls.add(a.node),a.resources===null&&(a.resources=r._findResources(a.node,t)),n.push(...a.resources))}}),[...new Map(n.map(o=>[o.name,o])).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),o=this._parseInt(r.value),i=new Vt(n.name,s,r.name,o);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 Vt("",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),o=new Tn(e.name,r,t.name,s);return n!==null&&(o.interpolation=this._parseString(n.value)),o}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 ze){let r=e.type?this.getTypeInfo(e.type,e.attributes):null,s=new rt(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,o=new de(r.name,t);return o.format=s,o.count=r.count,this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof ie){let r=e,s=new fe(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let o of r.members){let i=this.getTypeInfo(o.type,o.attributes);s.members.push(new Ft(o.name,i,o.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof Ae){let r=e,s=r.format instanceof _,o=r.format?s?this.getTypeInfo(r.format,null):new j(r.format,null):null,i=new ge(r.name,o,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,o=new ge(r.name,s,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}let n=new j(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 o=this._getTypeSize(e.format);e.stride=Math.max((n=o?.size)!==null&&n!==void 0?n:0,(r=o?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof rt&&this._updateTypeInfo(e.format),e instanceof fe&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,o=0;for(let i=0,a=e.members.length;i<a;++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,o=Math.max(o,f),l.offset=n,l.size=b,this._updateTypeInfo(l.type)}e.size=this._roundUp(o,s+r),e.align=o}_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 Ft&&(e=e.type),e instanceof j){let o=this._getAlias(e.name);o!==null&&(e=o)}{let o=re._typeInfo[e.name];if(o!==void 0){let i=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new Ge(Math.max(s,o.align/i),Math.max(r,o.size/i))}}{let o=re._typeInfo[e.name.substring(0,e.name.length-1)];if(o){let i=e.name[e.name.length-1]==="h"?2:1;return new Ge(Math.max(s,o.align/i),Math.max(r,o.size/i))}}if(e instanceof de){let o=e,i=8,a=8,l=this._getTypeSize(o.format);return l!==null&&(a=l.size,i=l.align),a=o.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,a)),r&&(a=r),new Ge(Math.max(s,i),Math.max(r,a))}if(e instanceof fe){let o=0,i=0,a=0,l=0,c=0;for(let f of e.members){let b=this._getTypeSize(f.type);b!==null&&(o=Math.max(b.align,o),a=this._roundUp(b.align,a+l),l=b.size,c=a)}return i=this._roundUp(o,c+l),new Ge(Math.max(s,o),Math.max(r,i))}return null}_isUniformVar(e){return e instanceof ae&&e.storage=="uniform"}_isStorageVar(e){return e instanceof ae&&e.storage=="storage"}_isTextureVar(e){return e instanceof ae&&e.type!==null&&re._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ae&&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);Gn=0,lt=class{constructor(e,t,n){this.id=Gn++,this.name=e,this.value=t,this.node=n}clone(){return new lt(this.name,this.value,this.node)}},ht=class{constructor(e){this.id=Gn++,this.name=e.name,this.node=e}clone(){return new ht(this.node)}},ft=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=Gn++,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 lt(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 ft(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 W&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof U&&r.typeInfo.size===0){let s=r.typeInfo,o=r.buffer.byteLength/s.stride;return new p(o,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,a)=>Math.atan2(i,r.data[a])),n.typeInfo);let s=n,o=r;return new p(Math.atan2(s.value,o.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 o=n,i=r,a=s;return new p(this._clamp(o.value,i.value,a.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,o=r.data;return new d([s[1]*o[2]-o[1]*s[2],s[2]*o[0]-o[2]*s[0],s[0]*o[1]-o[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(),o=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],o);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]),o);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]),o);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 a=0;a<n.data.length;++a)i+=(n.data[a]-r.data[a])*(n.data[a]-r.data[a]);return new p(Math.sqrt(i),this.getTypeInfo("f32"))}let s=n,o=r;return new p(Math.abs(s.value-o.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 o=r.value,i=s.value;if(n instanceof d)return new d(n.data.map(l=>l>>o&(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 a=n.value;return new p(a>>o&(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 o=this._dot(r.data,s.data);return new d(o<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 o=n,i=r,a=s;return new p(o.value*i.value+a.value,o.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),o=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,a=(1<<o.value)-1<<i,l=~a;if(n instanceof d&&r instanceof d)return new d(n.data.map((b,v)=>b&l|r.data[v]<<i&a),n.typeInfo);let c=n.value,f=r.value;return new p(c&l|f<<i&a,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(o=>{s+=o*o}),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,a)=>Math.max(i,r.data[a])),n.typeInfo);let s=n,o=r;return new p(Math.max(s.value,o.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,a)=>Math.min(i,r.data[a])),n.typeInfo);let s=n,o=r;return new p(Math.min(s.value,o.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((a,l)=>n.data[l]*(1-s.data[l])+r.data[l]*s.data[l]),n.typeInfo);let o=r,i=s;return new p(n.value*(1-i.value)+o.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((o,i)=>o%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,a)=>Math.pow(i,r.data[a])),n.typeInfo);let s=n,o=r;return new p(Math.pow(s.value,o.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((o,i)=>o-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 o=this._dot(r.data,n.data);return new d(n.data.map((i,a)=>{let l=1-s.value*s.value*(1-o*o);if(l<0)return 0;let c=Math.sqrt(l);return s.value*i-(s.value*o+c)*r.data[a]}),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 o=n,i=r,a=s;return new p(this._smoothstep(o.value,i.value,a.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((o,i)=>o<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,o=t.getVariableValue(s);if(o instanceof oe){if(r<0||r>=o.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let i=o.getMipLevelSize(r),a=o.dimension;return a==="1d"?new p(i[0],this.getTypeInfo("u32")):a==="3d"?new d(i,this.getTypeInfo("vec3u")):a==="2d"?new d(i.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${a} 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 o=n.name,i=t.getVariableValue(o);if(i instanceof oe){let a=Math.floor(r.data[0]),l=Math.floor(r.data[1]);if(a<0||a>=i.width||l<0||l>=i.height)return console.error(`Texture ${o} out of bounds. Line ${e.line}`),null;let c=i.getPixel(a,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 ${o} 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 oe?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 oe?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 oe?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,o=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(o.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,a=t.getVariableValue(i);if(a instanceof oe){let l=a.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):(a.setPixel(c,f,0,s,Array.from(o)),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 W&&(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 W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t);return a instanceof p&&i instanceof p&&(a.value=i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value+=i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicSub(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value-=i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicMax(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=Math.max(a.value,i.value)),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicMin(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=Math.min(a.value,i.value)),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicAnd(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=a.value&i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicOr(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=a.value|i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicXor(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=a.value^i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,n.postfix,t),l}AtomicExchange(e,t){let n=e.args[0];n instanceof W&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),o=e.args[1],i=this.exec.evalExpression(o,t),a=s.value.getSubData(this.exec,n.postfix,t),l=new p(a.value,a.typeInfo);return a instanceof p&&i instanceof p&&(a.value=i.value),s.value instanceof U&&s.value.setDataValue(this.exec,a,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]},G=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 ft,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 U&&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 o=s.getFunction(e);if(!o)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],a=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 w=n[b][v];s.variables.forEach(E=>{var A;let B=E.node;if(B?.attributes){let P=null,I=null;for(let S of B.attributes)S.name==="binding"?P=S.value:S.name==="group"&&(I=S.value);if(v==P&&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(w.texture!==void 0&&w.descriptor!==void 0){let O=new oe(w.texture,this.getTypeInfo(B.type),w.descriptor,(A=w.texture.view)!==null&&A!==void 0?A:null);E.value=O}else w.uniform!==void 0?E.value=new U(w.uniform,this.getTypeInfo(B.type)):E.value=new U(w,this.getTypeInfo(B.type))}}})}for(let b=0;b<l;++b)for(let v=0;v<a;++v)for(let w=0;w<i;++w)s.setVariable("@workgroup_id",new d([w,v,b],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(o,[w,v,b],s)}execStatement(e,t){if(e instanceof Ht)return this.evalExpression(e.value,t);if(e instanceof Xt){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 G._breakObj}if(e instanceof jt)return G._continueObj;if(e instanceof Ee)this._let(e,t);else if(e instanceof ae)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 zt)return this._if(e,t);if(e instanceof qt)return this._switch(e,t);if(e instanceof Ut)return this._for(e,t);if(e instanceof Nt)return this._while(e,t);if(e instanceof Gt)return this._loop(e,t);if(e instanceof st){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof Rt)this._assign(e,t);else if(e instanceof Wt)this._increment(e,t);else{if(e instanceof ie)return null;if(e instanceof it){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new p(0,this.getTypeInfo("u32")))}else if(e instanceof ot)this._call(e,t);else{if(e instanceof Qt||e instanceof at)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof ee?this._evalBinaryOp(e,t):e instanceof R?this._evalLiteral(e,t):e instanceof H?this._evalVariable(e,t):e instanceof ct?this._evalCall(e,t):e instanceof ne?this._evalCreate(e,t):e instanceof Kt?this._evalConst(e,t):e instanceof Zt?this._evalBitcast(e,t):e instanceof W?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"),o=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new d(r,s));let i=r[0],a=r[1],l=r[2];for(let c=0,f=0;c<l;++c)for(let b=0;b<a;++b)for(let v=0;v<i;++v,++f){let w=[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(w,s)),n.setVariable("@global_invocation_id",new d(E,s)),n.setVariable("@local_invocation_index",new p(f,o)),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}`,o=t.getVariable(s);o!==void 0&&t.variables.set(n.name,o)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof W;)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(),o=this._execStatements(n,s);if(o)return o;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 o=r.node.args[s],i=this.evalExpression(e.args[s],n);n.setVariable(o.name,i,o)}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 W){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof ve?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 ve(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof W){let a=this._getVariableData(e.variable,t),l=this.evalExpression(e.value,t),c=e.operator;if(c==="="){if(a instanceof p||a instanceof d||a instanceof T){if(l instanceof p||l instanceof d||l instanceof T&&a.data.length===l.data.length)return void a.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(a instanceof U&&l instanceof U&&a.buffer.byteLength-a.offset>=l.buffer.byteLength-l.offset)return void(a.buffer.byteLength%4==0?new Uint32Array(a.buffer,a.offset,a.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(a.buffer,a.offset,a.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(c==="+=")return a instanceof p||a instanceof d||a instanceof T?l instanceof p||l instanceof d||l instanceof T?void a.data.set(l.data.map((f,b)=>a.data[b]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(c==="-=")return(a instanceof p||a instanceof d||a instanceof T)&&(l instanceof p||l instanceof d||l instanceof T)?void a.data.set(l.data.map((f,b)=>a.data[b]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof W){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let a=t.getVariable(r);if(!(a&&a.value instanceof ve))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=a.value.reference;let l=e.variable.postfix;if(!l){let c=e.variable.right;for(;c instanceof W;){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 a=t.getVariable(r);if(a===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=a.value}if(n instanceof ve&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let o=this.evalExpression(e.value,t),i=e.operator;if(i!=="="){let a=n.getSubData(this,s,t);if(a instanceof d&&o instanceof p){let l=a.data,c=o.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(a instanceof d&&o instanceof d){let l=a.data,c=o.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(!(a instanceof p&&o instanceof p))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);i==="+="?a.value+=o.value:i==="-="?a.value-=o.value:i==="*="?a.value*=o.value:i==="/="?a.value/=o.value:i==="%="?a.value%=o.value:i==="&="?a.value&=o.value:i==="|="?a.value|=o.value:i==="^="?a.value^=o.value:i==="<<="?a.value<<=o.value:i===">>="?a.value>>=o.value:console.error(`Invalid operator ${i}. Line ${e.line}`)}return void(n instanceof U&&n.setDataValue(this,a,s,t))}if(n instanceof U)n.setDataValue(this,o,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 we){let a=this.evalExpression(s.index,t).value;if(n instanceof d){if(!(o instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[a]=o.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(!(o 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&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=o.data[0],n.data[2*l+1]=o.data[1]}else if(c==="mat2x3"||c==="mat2x3f"||c==="mat2x3h"){if(!(l<2&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=o.data[0],n.data[3*l+1]=o.data[1],n.data[3*l+2]=o.data[2]}else if(c==="mat2x4"||c==="mat2x4f"||c==="mat2x4h"){if(!(l<2&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=o.data[0],n.data[4*l+1]=o.data[1],n.data[4*l+2]=o.data[2],n.data[4*l+3]=o.data[3]}else if(c==="mat3x2"||c==="mat3x2f"||c==="mat3x2h"){if(!(l<3&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=o.data[0],n.data[2*l+1]=o.data[1]}else if(c==="mat3x3"||c==="mat3x3f"||c==="mat3x3h"){if(!(l<3&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=o.data[0],n.data[3*l+1]=o.data[1],n.data[3*l+2]=o.data[2]}else if(c==="mat3x4"||c==="mat3x4f"||c==="mat3x4h"){if(!(l<3&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=o.data[0],n.data[4*l+1]=o.data[1],n.data[4*l+2]=o.data[2],n.data[4*l+3]=o.data[3]}else if(c==="mat4x2"||c==="mat4x2f"||c==="mat4x2h"){if(!(l<4&&o.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=o.data[0],n.data[2*l+1]=o.data[1]}else if(c==="mat4x3"||c==="mat4x3f"||c==="mat4x3h"){if(!(l<4&&o.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=o.data[0],n.data[3*l+1]=o.data[1],n.data[3*l+2]=o.data[2]}else{if(c!=="mat4x4"&&c!=="mat4x4f"&&c!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(l<4&&o.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=o.data[0],n.data[4*l+1]=o.data[1],n.data[4*l+2]=o.data[2],n.data[4*l+3]=o.data[3]}}}}}else if(s instanceof ye){let a=s.value;if(!(n instanceof d))return void console.error(`Invalid assignment to ${a}. Variable ${r} is not a vector. Line ${e.line}`);if(o instanceof p){if(a.length>1)return void console.error(`Invalid assignment to ${a} for variable ${r}. Line ${e.line}`);if(a==="x")n.data[0]=o.value;else if(a==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${a} for variable ${r}. Line ${e.line}`);n.data[1]=o.value}else if(a==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${a} for variable ${r}. Line ${e.line}`);n.data[2]=o.value}else if(a==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${a} for variable ${r}. Line ${e.line}`);n.data[3]=o.value}}else{if(!(o instanceof d))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(a.length!==o.data.length)return void console.error(`Invalid assignment to ${a} for variable ${r}. Line ${e.line}`);for(let l=0;l<a.length;++l){let c=a[l];if(c==="x"||c==="r")n.data[0]=o.data[l];else if(c==="y"||c==="g"){if(o.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[1]=o.data[l]}else if(c==="z"||c==="b"){if(o.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[2]=o.data[l]}else{if(c!=="w"&&c!=="a")return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);if(o.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[3]=o.data[l]}}}}}else n instanceof p&&o instanceof p?n.value=o.value:n instanceof d&&o instanceof d||n instanceof T&&o instanceof T?n.data.set(o.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`)}_function(e,t){let n=new ht(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 W||(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 W||(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 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 tn)for(let o of s.selectors){if(o instanceof He){r=s;continue}let i=this.evalExpression(o,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 nn&&(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===G._breakObj)break;if(n!==null&&n!==G._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===G._breakObj)break;if(n===G._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===G._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===G._breakObj)break;if(n!==G._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=Lr(n.value,n.typeInfo.name,r.name);return new p(s,this.getTypeInfo(r))}if(n instanceof d){let s=n.typeInfo.getTypeName(),o="";if(s.endsWith("f"))o="f32";else if(s.endsWith("i"))o="i32";else if(s.endsWith("u"))o="u32";else if(s.endsWith("b"))o="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;o="f16"}let i=r.getTypeName(),a="";if(i.endsWith("f"))a="f32";else if(i.endsWith("i"))a="i32";else if(i.endsWith("u"))a="u32";else if(i.endsWith("b"))a="bool";else{if(!i.endsWith("h"))return console.error(`Unknown vector type ${a}. Line ${e.line}`),null;a="f16"}let l=function(c,f,b){if(f===b)return c;let v=new Array(c.length);for(let w=0;w<c.length;w++)v[w]=Lr(c[w],f,b);return v}(Array.from(n.data),o,a);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 ut.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 o=new U(new ArrayBuffer(s.size),s,0);if(s instanceof fe){if(e.args)for(let i=0;i<e.args.length;++i){let a=s.members[i],l=e.args[i],c=this.evalExpression(l,t);o.setData(this,c,a.type,a.offset,t)}}else if(s instanceof de){let i=0;if(e.args)for(let a=0;a<e.args.length;++a){let l=e.args[a],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),o.setData(this,c,s.format,i,t),i+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof ne?o.getSubData(this,e.postfix,t):o}_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=G._priority.get(t.name);G._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 ve(n);if(e.operator==="*")return n instanceof ve?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(k(r)){let i=r.map((a,l)=>+a);return new d(i,n.typeInfo)}let s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(+s,o)}case"-":{if(k(r)){let i=r.map((a,l)=>-a);return new d(i,n.typeInfo)}let s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(-s,o)}case"!":{if(k(r)){let i=r.map((a,l)=>a?0:1);return new d(i,n.typeInfo)}let s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(s?0:1,o)}case"~":{if(k(r)){let i=r.map((a,l)=>~a);return new d(i,n.typeInfo)}let s=r,o=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(~s,o)}}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,o=r instanceof p?r.value:r instanceof d||r instanceof T?Array.from(r.data):null;switch(e.operator){case"+":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v+f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b+c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c+b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i+a,l)}case"-":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v-f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b-c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c-b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i-a,l)}case"*":{if(k(s)&&k(o)){let c=s,f=o;if(n instanceof T&&r instanceof T){let b=function(A,B,P,I){if(z[B.name]===void 0||z[I.name]===void 0)return null;let S=z[B.name][0],O=z[B.name][1],V=z[I.name][0];if(S!==z[I.name][1])return null;let pe=new Array(V*O);for(let ke=0;ke<O;ke++)for(let ce=0;ce<V;ce++){let Qn=0;for(let gt=0;gt<S;gt++)Qn+=A[gt*O+ke]*P[ce*S+gt];pe[ke*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],w=z[n.typeInfo.name][1],E=this.getTypeInfo(`mat${v}x${w}f`);return new T(b,E)}if(n instanceof T&&r instanceof d){let b=function(v,w,E,A){if(z[w.name]===void 0||Sn[A.name]===void 0)return null;let B=z[w.name][0],P=z[w.name][1];if(B!==E.length)return null;let I=new Array(P);for(let S=0;S<P;S++){let O=0;for(let V=0;V<B;V++)O+=v[V*P+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,w,E,A){if(Sn[w.name]===void 0||z[A.name]===void 0)return null;let B=z[A.name][0],P=z[A.name][1];if(P!==v.length)return null;let I=[];for(let S=0;S<B;S++){let O=0;for(let V=0;V<P;V++)O+=v[V]*E[V*B+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,w)=>v*f[w]);return new d(b,n.typeInfo)}}if(k(s)){let c=o,f=s.map((b,v)=>b*c);return n instanceof T?new T(f,n.typeInfo):new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c*b);return r instanceof T?new T(f,r.typeInfo):new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i*a,l)}case"%":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v%f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b%c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c%b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i%a,l)}case"/":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v/f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b/c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c/b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i/a,l)}case"&":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v&f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b&c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c&b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i&a,l)}case"|":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v|f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b|c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c|b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i|a,l)}case"^":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v^f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b^c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c^b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i^a,l)}case"<<":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v<<f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b<<c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c<<b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i<<a,l)}case">>":{if(k(s)&&k(o)){let c=s,f=o;if(c.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=c.map((v,w)=>v>>f[w]);return new d(b,n.typeInfo)}if(k(s)){let c=o,f=s.map((b,v)=>b>>c);return new d(f,n.typeInfo)}if(k(o)){let c=s,f=o.map((b,v)=>c>>b);return new d(f,r.typeInfo)}let i=s,a=o,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new p(i>>a,l)}case">":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l>i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i>l?1:0);return new d(a,r.typeInfo)}return new p(s>o?1:0,this.getTypeInfo("bool"));case"<":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l<i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i<l?1:0);return new d(a,r.typeInfo)}return new p(s<o?1:0,this.getTypeInfo("bool"));case"==":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c===a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l==i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i==l?1:0);return new d(a,r.typeInfo)}return new p(s===o?1:0,this.getTypeInfo("bool"));case"!=":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c!==a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l!==i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i!==l?1:0);return new d(a,r.typeInfo)}return new p(s!==o?1:0,this.getTypeInfo("bool"));case">=":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c>=a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l>=i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i>=l?1:0);return new d(a,r.typeInfo)}return new p(s>=o?1:0,this.getTypeInfo("bool"));case"<=":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c<=a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l<=i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i<=l?1:0);return new d(a,r.typeInfo)}return new p(s<=o?1:0,this.getTypeInfo("bool"));case"&&":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c&&a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l&&i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i&&l?1:0);return new d(a,r.typeInfo)}return new p(s&&o?1:0,this.getTypeInfo("bool"));case"||":if(k(s)&&k(o)){let i=s,a=o;if(i.length!==a.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=i.map((c,f)=>c||a[f]?1:0);return new d(l,n.typeInfo)}if(k(s)){let i=o,a=s.map((l,c)=>l||i?1:0);return new d(a,n.typeInfo)}if(k(o)){let i=s,a=o.map((l,c)=>i||l?1:0);return new d(a,r.typeInfo)}return new p(s||o?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 o=r.node.args[s],i=this.evalExpression(e.args[s],n);n.createVariable(o.name,i,o)}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 o=n.node.args[s],i=this.evalExpression(e.args[s],r);r.setVariable(o.name,i,o)}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 o=[];if(e instanceof R)if(e.isVector){let i=e.vectorValue;for(let a of i)o.push(a)}else o.push(e.scalarValue);else if(e.args)for(let i of e.args){let a=this.evalExpression(i,t);if(a instanceof d){let l=a.data;for(let c=0;c<l.length;++c){let f=l[c];o.push(f)}}else if(a instanceof p){let l=a.value;o.push(l)}}if(e.type instanceof y&&e.type.format===null&&(e.type.format=y.f32),o.length===0){let i=new Array(s).fill(0);return new d(i,n).getSubData(this,e.postfix,t)}if(o.length===1)for(;o.length<s;)o.push(o[0]);return o.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new d(o.length>s?o.slice(0,s):o,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 o=[];if(e instanceof R)if(e.isVector){let i=e.vectorValue;for(let a of i)o.push(a)}else o.push(e.scalarValue);else if(e.args)for(let i of e.args){let a=this.evalExpression(i,t);a instanceof d?o.push(...a.data):a instanceof p?o.push(a.value):a instanceof T&&o.push(...a.data)}if(n instanceof ge&&n.format===null&&(n.format=this.getTypeInfo("f32")),o.length===0){let i=new Array(s[2]).fill(0);return new T(i,n).getSubData(this,e.postfix,t)}return o.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new T(o,n).getSubData(this,e.postfix,t)}};G._breakObj=new K(new j("BREAK",null),null),G._continueObj=new K(new j("CONTINUE",null),null),G._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);Un=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Wn=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new Un,this._exec=new G,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 o=s.name,i=this._context.constants.get(o);if(i)try{let a=i.constEvaluate(this._exec);r.count=a}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof sn||r instanceof ze?r.type=this._forwardType(r.type):r instanceof Be?r.format=this._forwardType(r.format):r instanceof ae||r instanceof Ee||r instanceof qe?r.type=this._forwardType(r.type):r instanceof Ce?r.returnType=this._forwardType(r.returnType):r instanceof rn&&(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 ze?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 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(),a=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 rn(a,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(),o=this._currentLine;return this._updateNode(new Ce(t,n,r,s,e,o),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 Xt);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 jt);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 Ln(t),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new Nt(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 st(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 Ut(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 ae(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 Ee(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?Re.increment:Re.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 Rt(nt.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 ot(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 Gt([],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 st){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 He){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 tn(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 nn(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new He)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new He)):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 zt(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 Ht(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new ee(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 ee(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 ee(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 ee(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 ee(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 ee(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 ee(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 ee(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 ee(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 ee(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 W(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 we(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 ye(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 ct(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new Kt(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 o=r?_.f16:_.f32;return this._updateNode(new R(new p(s,this._exec.getTypeInfo(o)),o))}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 o=this._attribute(),i=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let a=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=a),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 sn(i,l,o)))}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 a=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=a)}let s=null;this._consume(h.tokens.equal,"const declarations require an assignment");let o=this._short_circuit_or_expression();try{let a=[_.f32],l=o.constEvaluate(this._exec,a);l instanceof p&&this._validateTypeRange(l.value,a[0]),a[0]instanceof y&&a[0].format===null&&l.typeInfo instanceof ge&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?a[0].format=_.f16:l.typeInfo.format.name==="f32"?a[0].format=_.f32:l.typeInfo.format.name==="i32"?a[0].format=_.i32:l.typeInfo.format.name==="u32"?a[0].format=_.u32:l.typeInfo.format.name==="bool"?a[0].format=_.bool:console.error(`TODO: impelement template format type ${l.typeInfo.format.name}`)),s=this._updateNode(new R(l,a[0])),this._exec.context.setVariable(t.toString(),l)}catch{s=o}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 Ee(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 o=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=o)}return this._updateNode(new ae(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 it(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 Qt(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(),o=null;return this._match(h.tokens.comma)&&(o=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new ze(n,r.toString(),s,o))}let t=this._attribute();if(this._match(h.keywords.array)){let n=null,r=-1,s=this._previous(),o=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 a="";if(this._match(h.tokens.comma)){o=this._shift_expression();try{a=o.constEvaluate(this._exec).toString(),o=null}catch{a="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),r=a?parseInt(a):0}let i=this._updateNode(new Be(s.toString(),t,n,r));return o&&this._deferArrayCountEval.push({arrayType:i,countNode:o}),i}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new Ae(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new Ae(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 Ae(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 Ae(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 on(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}},hn=class extends re{constructor(e){super(),e&&this.update(e)}update(e){let t=new Wn().parse(e);this.updateAST(t)}}});function fn(u){let e={attributes:[],bindings:[]},t;try{t=xs(u)}catch(s){return Fr.log.error(s.message)(),e}for(let s of t.uniforms){let o=[];for(let i of s.type?.members||[])o.push({name:i.name,type:Mr(i.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:o})}for(let s of t.storage)e.bindings.push({type:s.access==="read"?"read-only-storage":"storage",name:s.name,group:s.group,location:s.binding});for(let s of t.textures){let o={type:"texture",name:s.name,group:s.group,location:s.binding,...bs(s)};e.bindings.push(o)}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 o=n.inputs[s];if(o.locationType==="location"){let i=Mr(o.type);e.attributes.push({name:o.name,location:Number(o.location),type:i})}}return e}function Mr(u){return u?.format?`${u.name}<${u.format.name}>`:u.name}function xs(u){try{return new hn(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 bs(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",o;return t.startsWith("texture_depth")?o="depth":n==="i32"?o="sint":n==="u32"?o="uint":o="float",{viewDimension:r,sampleType:o,multisampled:s}}var Fr,qn=L(()=>{"use strict";Fr=F(M(),1);Or()});function Vr(u,e){if(!(e.mipLevels<=1)){if(e.dimension==="3d"){Is(u,e);return}if(_s.includes(e.dimension)){Ss(u,e);return}throw new Error(`Cannot generate mipmaps for texture dimension "${e.dimension}" with WebGPU.`)}}function Ss(u,e){dn(u,e,["render","filter"],"render");let t=Nr(e.format,"render",e.dimension),n=e.dimension,r=As(n),s=u.createSampler({minFilter:"linear",magFilter:"linear"}),o=u.createBuffer({byteLength:16,usage:Le.Buffer.UNIFORM|Le.Buffer.COPY_DST}),i=new Uint32Array(1),c={attributes:[],bindings:[vs,{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"}),w=e.width,E=e.height,A=e.dimension==="2d"?1:e.depth;function B(P,I,S,O,V){i[0]=S,o.write(i);let pe=e.createView({dimension:"2d",baseMipLevel:I,mipLevelCount:1,baseArrayLayer:S,arrayLayerCount:1}),ke=u.createFramebuffer({colorAttachments:[pe]}),ce=u.beginRenderPass({id:`mipmap-generation:${e.format}:${I}:${S}`,framebuffer:ke});try{ce.setPipeline(v),ce.setBindings({sourceSampler:s,sourceTexture:P,uniforms:o}),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(),ke.destroy()}}try{for(let P=1;P<e.mipLevels;++P){dn(u,e,["render","filter"],"render");let I=P-1,S=Math.max(1,w>>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)B(V,P,pe,S,O)}finally{V.destroy()}w=S,E=O}}finally{v.destroy(),f.destroy(),b.destroy(),s.destroy(),o.destroy()}}function Nr(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 Is(u,e){dn(u,e,["filter","store"],"compute");let t=Nr(e.format,"compute",e.dimension),n=Bs(t),s={bindings:[ws,{type:"storage",name:"destinationTexture",group:0,location:1,format:t,viewDimension:"3d",access:"write-only"},ks]},o=u.createShader({id:"mipmap-generation-compute",source:n,language:"wgsl",stage:"compute"}),i=u.createComputePipeline({id:`mipmap-generation-compute:${e.format}`,shader:o,shaderLayout:s}),a=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){dn(u,e,["filter","store"],"compute");let w=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]=w,l[4]=E,l[5]=A,l[6]=0,a.write(l);let B=e.createView({dimension:"3d",baseMipLevel:v-1,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}),P=e.createView({dimension:"3d",baseMipLevel:v,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1});i.setBindings({sourceTexture:B,destinationTexture:P,uniforms:a});try{let I=Math.ceil(w/je.x),S=Math.ceil(E/je.y),O=Math.ceil(A/je.z),V=u.beginComputePass({});V.setPipeline(i),V.dispatch(I,S,O),V.end(),u.submit()}finally{B.destroy(),P.destroy()}c=w,f=E,b=A}}finally{i.destroy(),o.destroy(),a.destroy()}}function dn(u,e,t,n){let{format:r,dimension:s}=e,o=u.getTextureFormatCapabilities(r);if(t.filter(a=>!o[a]).length>0){let a=t.join(" + "),l=t.map(c=>`${c}=${o[c]}`).join(", ");throw new Error(`Cannot run ${n} mipmap generation for ${s} texture with format "${r}". Required capabilities: ${a}. Actual capabilities: ${l}.`)}}function Ts(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 As(u){let e=Es(u);return`
17
17
  struct MipmapUniforms {
18
18
  sourceLayer: u32,
19
19
  };
@@ -66,7 +66,7 @@ struct VertexOutput {
66
66
  };
67
67
 
68
68
  @group(0) @binding(0) var sourceSampler: sampler;
69
- @group(0) @binding(1) var sourceTexture: ${Es(u)};
69
+ @group(0) @binding(1) var sourceTexture: ${Ts(u)};
70
70
  @group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
71
71
 
72
72
  @vertex
@@ -91,7 +91,7 @@ fn fragmentMain(fsInput: VertexOutput) -> @location(0) vec4f {
91
91
  _touchUniform(uniforms);
92
92
  return ${e};
93
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`
94
+ `}function Es(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
95
  struct MipmapUniforms {
96
96
  sourceWidth: u32,
97
97
  sourceHeight: u32,
@@ -106,7 +106,7 @@ struct MipmapUniforms {
106
106
  @group(0) @binding(1) var destinationTexture: texture_storage_3d<${u}, write>;
107
107
  @group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
108
108
 
109
- @compute @workgroup_size(${Xe.x}, ${Xe.y}, ${Xe.z})
109
+ @compute @workgroup_size(${je.x}, ${je.y}, ${je.z})
110
110
  fn main(@builtin(global_invocation_id) id: vec3<u32>) {
111
111
  if (
112
112
  id.x >= uniforms.destinationWidth ||
@@ -172,6 +172,6 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
172
172
  vec4<f32>(sum.xyz / 8.0, sum.w / 8.0)
173
173
  );
174
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);})();
175
+ `}var Le,_s,je,vs,ws,ks,Ur=L(()=>{"use strict";Le=F(M(),1),_s=["2d","2d-array","cube","cube-array"],je={x:4,y:4,z:4},vs={type:"sampler",name:"sourceSampler",group:0,location:0},ws={type:"texture",name:"sourceTexture",group:0,location:0,viewDimension:"3d",sampleType:"float"},ks={type:"uniform",name:"uniforms",group:0,location:2}});function Rr(u,e,t,n,r){let s=Cs(n,t,r);if(s.length===0)return null;u.pushErrorScope("validation");let o=u.handle.createBindGroup({layout:e,entries:s});return u.popErrorScope(i=>{Q.log.error(`bindGroup creation: ${i.message}`,o)()}),o}function Cs(u,e,t){let n=[];for(let[r,s]of Object.entries(u)){let o=e.bindings.find(l=>l.name===r),i=o||(0,Q.getShaderLayoutBinding)(e,r);if(!(!o&&i?i.name in u:!1)&&i?.group===t){let l=i?Wr(s,i.location,void 0,r):null;if(l&&n.push(l),s instanceof Q.Texture){let c=(0,Q.getShaderLayoutBinding)(e,`${r}Sampler`,{ignoreWarnings:!0}),f=c&&c.group===t?Wr(s,c.location,{sampler:!0},r):null;f&&n.push(f)}}}return n}function Wr(u,e,t,n="unknown"){return u instanceof Q.Buffer?{binding:e,resource:{buffer:u.handle}}:u instanceof Q.Sampler?{binding:e,resource:u.handle}:u instanceof Q.TextureView?{binding:e,resource:u.handle}:u instanceof Q.Texture?t?.sampler?{binding:e,resource:u.sampler.handle}:{binding:e,resource:u.view.handle}:(Q.log.warn(`invalid binding ${n}`,u),null)}var Q,Gr=L(()=>{"use strict";Q=F(M(),1)});var qr={};Xn(qr,{WebGPUDevice:()=>pt});function Ls(u){if(globalThis.queueMicrotask){globalThis.queueMicrotask(u);return}Promise.resolve().then(u).catch(()=>{})}var dt,pt,zn=L(()=>{"use strict";dt=F(M(),1);pn();yn();tr();Ye();xn();ur();Tt();hr();xr();br();_r();Tr();Ar();Er();wn();qn();Ur();Gr();Se();pt=class extends dt.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",o=>{o.preventDefault();let i=o instanceof GPUUncapturedErrorEvent?o.error.message:"Unknown WebGPU error";this.reportError(new Error(i),this)(),this.debug()}),this.lost=new Promise(async o=>{let i=await this.handle.lost;this._isLost=!0,o({reason:"destroyed",message:i.message})});let s=dt.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 fn(e)}isVertexFormatSupported(e){return!this.getVertexFormatInfo(e).webglOnly}createBuffer(e){let t=this._normalizeBufferProps(e);return new xe(this,t)}createTexture(e){return new Pe(this,e)}createExternalTexture(e){return new vt(this,e)}createShader(e){return new Oe(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 It(this,e)}createFramebuffer(e){return new _e(this,e)}createComputePipeline(e){return new At(this,e)}createVertexArray(e){return new Bt(this,e)}createCommandEncoder(e){return new Pt(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new tt(this,e)}createFence(){return new Ue(this)}createCanvasContext(e){return new Je(this,this.adapter,e)}createPresentationContext(e){return new Ct(this,e)}createPipelineLayout(e){return new Ot(this,e)}generateMipmapsWebGPU(e){Vr(this,e)}_createBindGroupLayoutWebGPU(e,t){return e.handle.getBindGroupLayout(t)}_createBindGroupWebGPU(e,t,n,r){return Object.keys(n).length===0?this.handle.createBindGroup({layout:e,entries:[]}):Rr(this,e,t,n,r)}submit(e){let t=null;e||({submittedCommandEncoder:t,commandBuffer:e}=this._finalizeDefaultCommandEncoderForSubmit());let n=X(this),r=n?C():0,s=_t(this);try{this.pushErrorScope("validation");let o=n?C():0;if(this.handle.queue.submit([e.handle]),n&&(n.queueSubmitCount=(n.queueSubmitCount||0)+1,n.queueSubmitTimeMs=(n.queueSubmitTimeMs||0)+(C()-o)),this.popErrorScope(i=>{this.reportError(new Error(`${this} command submission: ${i.message}`),this)(),this.debug()}),t){let i=n?C():0;Ls(()=>{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",a=s==="query-readback"?"queryReadbackSubmitTimeMs":"defaultSubmitTimeMs";n[i]=(n[i]||0)+1,n[a]=(n[a]||0)+(C()-r)}let o=n?C():0;e.destroy(),n&&(n.commandBufferDestroyCount=(n.commandBufferDestroyCount||0)+1,n.commandBufferDestroyTimeMs=(n.commandBufferDestroyTimeMs||0)+(C()-o))}}_finalizeDefaultCommandEncoderForSubmit(){let e=this.commandEncoder;e.getTimeProfilingSlotCount()>0&&e.getTimeProfilingQuerySet()instanceof tt&&e.getTimeProfilingQuerySet()._encodeResolveToReadBuffer(e,{firstQuery:0,queryCount:e.getTimeProfilingSlotCount()});let t=e.finish();return this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:e.props.id,timeProfilingQuerySet:e.getTimeProfilingQuerySet()}),{submittedCommandEncoder:e,commandBuffer:t}}pushErrorScope(e){if(!this.props.debug)return;let t=X(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=X(this),n=t?C():0;this.handle.popErrorScope().then(r=>{r&&e(r)}).catch(r=>{if(this.shouldIgnoreDroppedInstanceError(r,"popErrorScope"))return;let s=r instanceof Error?r.message:String(r);this.reportError(new Error(`${this} popErrorScope failed: ${s}`),this)(),this.debug()}),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||"",o=Boolean(this.adapterInfo.isFallbackAdapter??this.adapter.isFallbackAdapter??!1),i=/SwiftShader/i.test(`${n} ${r} ${this.adapterInfo.architecture||""}`),a=n==="apple"?"apple":i||o?"software":"unknown",l=this.adapterInfo.architecture||"unknown",c=this.adapterInfo.backend||"unknown",f=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||(i||o?"cpu":"unknown");return{type:"webgpu",vendor:n,renderer:r,version:s,gpu:a,gpuType:f,gpuBackend:c,gpuArchitecture:l,fallback:o,shadingLanguage:"wgsl",shadingLanguageVersion:100}}shouldIgnoreDroppedInstanceError(e,t){let n=e instanceof Error?e.message:String(e);return n.includes("Instance dropped")&&(!t||n.includes(t))&&(this._isLost||this.info.gpu==="software"||this.info.gpuType==="cpu"||Boolean(this.info.fallback))}_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 dt.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 mt={};Xn(mt,{WebGPUBuffer:()=>xe,WebGPUDevice:()=>pt,WebGPUFence:()=>Ue,WebGPUSampler:()=>Z,WebGPUShader:()=>Oe,WebGPUTexture:()=>Pe,getShaderLayoutFromWGSL:()=>fn,webgpuAdapter:()=>zr});bt(mt,F(M(),1));var $e=F(M(),1),Hn=class extends $e.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 a=Object.keys(t.limits).filter(l=>!["minSubgroupSize","maxSubgroupSize"].includes(l));for(let l of a){let c=l,f=t.limits[c];typeof f=="number"&&(s[c]=f)}}let o=await t.requestDevice({requiredFeatures:r,requiredLimits:s}),{WebGPUDevice:i}=await Promise.resolve().then(()=>(zn(),qr));$e.log.groupCollapsed(1,"WebGPUDevice created")();try{let a=new i(e,o,t,n);return $e.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),$e.log.table(1,a.info)(),a}finally{$e.log.groupEnd(1)()}}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},zr=new Hn;zn();pn();yn();Ye();xn();wn();qn();return Zr(mt);})();
176
176
  return __exports__;
177
177
  });