tangram-core 0.2.0__cp313-cp313-win_amd64.whl

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 (171) hide show
  1. tangram_core/App.vue +335 -0
  2. tangram_core/__init__.py +5 -0
  3. tangram_core/__main__.py +141 -0
  4. tangram_core/_core.cp313-win_amd64.pyd +0 -0
  5. tangram_core/_core.pyi +38 -0
  6. tangram_core/api.ts +456 -0
  7. tangram_core/backend.py +335 -0
  8. tangram_core/colour.ts +71 -0
  9. tangram_core/config.py +122 -0
  10. tangram_core/dist-frontend/aggregation-layers.js +521 -0
  11. tangram_core/dist-frontend/aggregation-layers.js.map +1 -0
  12. tangram_core/dist-frontend/assets/_commonjsHelpers-CqkleIqs.js +2 -0
  13. tangram_core/dist-frontend/assets/_commonjsHelpers-CqkleIqs.js.map +1 -0
  14. tangram_core/dist-frontend/assets/array-utils-flat-wyE8tIYR.js +11 -0
  15. tangram_core/dist-frontend/assets/array-utils-flat-wyE8tIYR.js.map +1 -0
  16. tangram_core/dist-frontend/assets/assert-hrfsarFU.js +3 -0
  17. tangram_core/dist-frontend/assets/assert-hrfsarFU.js.map +1 -0
  18. tangram_core/dist-frontend/assets/b612-latin-400-italic-DePNXA0a.woff +0 -0
  19. tangram_core/dist-frontend/assets/b612-latin-400-italic-a-4GLPtl.woff2 +0 -0
  20. tangram_core/dist-frontend/assets/b612-latin-400-normal-CC98FVm_.woff2 +0 -0
  21. tangram_core/dist-frontend/assets/b612-latin-400-normal-JbZ7xwUX.woff +0 -0
  22. tangram_core/dist-frontend/assets/b612-latin-700-normal-B_Snq1wd.woff +0 -0
  23. tangram_core/dist-frontend/assets/b612-latin-700-normal-BinQrnoB.woff2 +0 -0
  24. tangram_core/dist-frontend/assets/clip-extension-DTCP51Ak.js +26 -0
  25. tangram_core/dist-frontend/assets/clip-extension-DTCP51Ak.js.map +1 -0
  26. tangram_core/dist-frontend/assets/color-CUNNsFV-.js +17 -0
  27. tangram_core/dist-frontend/assets/color-CUNNsFV-.js.map +1 -0
  28. tangram_core/dist-frontend/assets/cube-geometry-CzJ_uBWa.js +2 -0
  29. tangram_core/dist-frontend/assets/cube-geometry-CzJ_uBWa.js.map +1 -0
  30. tangram_core/dist-frontend/assets/deep-equal-uriyKJca.js +2 -0
  31. tangram_core/dist-frontend/assets/deep-equal-uriyKJca.js.map +1 -0
  32. tangram_core/dist-frontend/assets/fly-to-interpolator-DlKiy9_S.js +2 -0
  33. tangram_core/dist-frontend/assets/fly-to-interpolator-DlKiy9_S.js.map +1 -0
  34. tangram_core/dist-frontend/assets/geojson-layer-CLhXLxdI.js +1010 -0
  35. tangram_core/dist-frontend/assets/geojson-layer-CLhXLxdI.js.map +1 -0
  36. tangram_core/dist-frontend/assets/globe-view-DKhftlA1.js +94 -0
  37. tangram_core/dist-frontend/assets/globe-view-DKhftlA1.js.map +1 -0
  38. tangram_core/dist-frontend/assets/globe-viewport-CPES4D4P.js +2 -0
  39. tangram_core/dist-frontend/assets/globe-viewport-CPES4D4P.js.map +1 -0
  40. tangram_core/dist-frontend/assets/image-loader-ClbNCMXW.js +2 -0
  41. tangram_core/dist-frontend/assets/image-loader-ClbNCMXW.js.map +1 -0
  42. tangram_core/dist-frontend/assets/inconsolata-latin-400-normal-DTZQ6lD6.woff2 +0 -0
  43. tangram_core/dist-frontend/assets/inconsolata-latin-400-normal-HYADljCo.woff +0 -0
  44. tangram_core/dist-frontend/assets/inconsolata-latin-700-normal-ByjKuJjN.woff2 +0 -0
  45. tangram_core/dist-frontend/assets/inconsolata-latin-700-normal-DzgUY3Rl.woff +0 -0
  46. tangram_core/dist-frontend/assets/inconsolata-latin-ext-400-normal-BaHVOdFB.woff2 +0 -0
  47. tangram_core/dist-frontend/assets/inconsolata-latin-ext-400-normal-yvPjCxxx.woff +0 -0
  48. tangram_core/dist-frontend/assets/inconsolata-latin-ext-700-normal-D0Kpgs_9.woff2 +0 -0
  49. tangram_core/dist-frontend/assets/inconsolata-latin-ext-700-normal-Dlt-daqV.woff +0 -0
  50. tangram_core/dist-frontend/assets/inconsolata-vietnamese-400-normal-ByiM2lek.woff +0 -0
  51. tangram_core/dist-frontend/assets/inconsolata-vietnamese-400-normal-DfC_iMic.woff2 +0 -0
  52. tangram_core/dist-frontend/assets/inconsolata-vietnamese-700-normal-DLCFFAUf.woff +0 -0
  53. tangram_core/dist-frontend/assets/inconsolata-vietnamese-700-normal-DuasYmn8.woff2 +0 -0
  54. tangram_core/dist-frontend/assets/index-UPPakSLR.css +1 -0
  55. tangram_core/dist-frontend/assets/index-r8T0kY2p.js +821 -0
  56. tangram_core/dist-frontend/assets/index-r8T0kY2p.js.map +1 -0
  57. tangram_core/dist-frontend/assets/layer-DO63TrsS.js +555 -0
  58. tangram_core/dist-frontend/assets/layer-DO63TrsS.js.map +1 -0
  59. tangram_core/dist-frontend/assets/layer-extension-CZ3zsHuN.js +2 -0
  60. tangram_core/dist-frontend/assets/layer-extension-CZ3zsHuN.js.map +1 -0
  61. tangram_core/dist-frontend/assets/mesh-layers-BSECKarm.js +1123 -0
  62. tangram_core/dist-frontend/assets/mesh-layers-BSECKarm.js.map +1 -0
  63. tangram_core/dist-frontend/assets/orthographic-viewport-CzZmHDEZ.js +2 -0
  64. tangram_core/dist-frontend/assets/orthographic-viewport-CzZmHDEZ.js.map +1 -0
  65. tangram_core/dist-frontend/assets/pick-layers-pass-xhWsgZtf.js +2 -0
  66. tangram_core/dist-frontend/assets/pick-layers-pass-xhWsgZtf.js.map +1 -0
  67. tangram_core/dist-frontend/assets/project-CrvReKGW.js +760 -0
  68. tangram_core/dist-frontend/assets/project-CrvReKGW.js.map +1 -0
  69. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-italic-4qS3_zkX.woff2 +0 -0
  70. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-italic-CDK-EZBY.woff +0 -0
  71. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-normal-Bgns473E.woff +0 -0
  72. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-normal-_T2aQlWs.woff2 +0 -0
  73. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-500-normal-CvEVpWxD.woff +0 -0
  74. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-500-normal-s4PklZE0.woff2 +0 -0
  75. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-700-normal-9RN-Z7cI.woff2 +0 -0
  76. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-700-normal-BGMkBBYx.woff +0 -0
  77. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-italic-C7erd-g8.woff +0 -0
  78. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-italic-DR5R5TWx.woff2 +0 -0
  79. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-normal-DGo1Ayjq.woff2 +0 -0
  80. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-normal-WtM1l1qc.woff +0 -0
  81. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-500-normal-C8FNIdXm.woff2 +0 -0
  82. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-500-normal-TLDmfi3Q.woff +0 -0
  83. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-700-normal-CTXjXnze.woff2 +0 -0
  84. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-700-normal-CWPRiRXS.woff +0 -0
  85. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-italic-CR6qj4Z4.woff2 +0 -0
  86. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-italic-DHRaIs10.woff +0 -0
  87. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-normal-D5vBSIyg.woff2 +0 -0
  88. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-normal-FabMgVmk.woff +0 -0
  89. tangram_core/dist-frontend/assets/roboto-condensed-greek-500-normal-BIN62cw9.woff +0 -0
  90. tangram_core/dist-frontend/assets/roboto-condensed-greek-500-normal-Hsn-wDIp.woff2 +0 -0
  91. tangram_core/dist-frontend/assets/roboto-condensed-greek-700-normal-89Up2Xly.woff +0 -0
  92. tangram_core/dist-frontend/assets/roboto-condensed-greek-700-normal-DWMOA2VK.woff2 +0 -0
  93. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-italic-D_BR-3LG.woff2 +0 -0
  94. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-italic-om57GXsO.woff +0 -0
  95. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-normal-BICmKrXV.woff2 +0 -0
  96. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-normal-D2e7XwB1.woff +0 -0
  97. tangram_core/dist-frontend/assets/roboto-condensed-latin-500-normal-3p2daRJW.woff2 +0 -0
  98. tangram_core/dist-frontend/assets/roboto-condensed-latin-500-normal-Dc9bsamC.woff +0 -0
  99. tangram_core/dist-frontend/assets/roboto-condensed-latin-700-normal-BOl6B_hI.woff +0 -0
  100. tangram_core/dist-frontend/assets/roboto-condensed-latin-700-normal-DRbp0YnP.woff2 +0 -0
  101. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-italic-BXrkWnoY.woff +0 -0
  102. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-italic-Bhem1d5z.woff2 +0 -0
  103. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-normal-DT8nEsYA.woff +0 -0
  104. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-normal-OHaX69iP.woff2 +0 -0
  105. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-500-normal-CcSTXKtO.woff2 +0 -0
  106. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-500-normal-JgPl2bDS.woff +0 -0
  107. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-700-normal-B004qtqu.woff2 +0 -0
  108. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-700-normal-O6H_RRvN.woff +0 -0
  109. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-italic-BwUYFJ2t.woff2 +0 -0
  110. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-italic-DV8QogUk.woff +0 -0
  111. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-normal-0o1laQ-g.woff2 +0 -0
  112. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-normal-CPsdS8_S.woff +0 -0
  113. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-500-normal-G9shSJ2z.woff +0 -0
  114. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-500-normal-TFWhjk13.woff2 +0 -0
  115. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-700-normal-BtNeb9D6.woff +0 -0
  116. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-700-normal-D35V1G0s.woff2 +0 -0
  117. tangram_core/dist-frontend/assets/shader-BJmsOfPx.js +843 -0
  118. tangram_core/dist-frontend/assets/shader-BJmsOfPx.js.map +1 -0
  119. tangram_core/dist-frontend/assets/solid-polygon-layer-DiarVGxh.js +392 -0
  120. tangram_core/dist-frontend/assets/solid-polygon-layer-DiarVGxh.js.map +1 -0
  121. tangram_core/dist-frontend/assets/tesselator-49Dw9L5A.js +2 -0
  122. tangram_core/dist-frontend/assets/tesselator-49Dw9L5A.js.map +1 -0
  123. tangram_core/dist-frontend/assets/webgl-developer-tools-CZl8qVFg.js +7 -0
  124. tangram_core/dist-frontend/assets/webgl-developer-tools-CZl8qVFg.js.map +1 -0
  125. tangram_core/dist-frontend/assets/webgl-device-BY0-CUP6.js +3 -0
  126. tangram_core/dist-frontend/assets/webgl-device-BY0-CUP6.js.map +1 -0
  127. tangram_core/dist-frontend/assets/widget-BbOeHGj0.js +2 -0
  128. tangram_core/dist-frontend/assets/widget-BbOeHGj0.js.map +1 -0
  129. tangram_core/dist-frontend/core.js +60 -0
  130. tangram_core/dist-frontend/core.js.map +1 -0
  131. tangram_core/dist-frontend/extensions.js +609 -0
  132. tangram_core/dist-frontend/extensions.js.map +1 -0
  133. tangram_core/dist-frontend/favicon.ico +0 -0
  134. tangram_core/dist-frontend/favicon.png +0 -0
  135. tangram_core/dist-frontend/font-awesome.min.css +4 -0
  136. tangram_core/dist-frontend/fonts/FontAwesome.otf +0 -0
  137. tangram_core/dist-frontend/fonts/fontawesome-webfont.eot +0 -0
  138. tangram_core/dist-frontend/fonts/fontawesome-webfont.svg +2671 -0
  139. tangram_core/dist-frontend/fonts/fontawesome-webfont.ttf +0 -0
  140. tangram_core/dist-frontend/fonts/fontawesome-webfont.woff +0 -0
  141. tangram_core/dist-frontend/fonts/fontawesome-webfont.woff2 +0 -0
  142. tangram_core/dist-frontend/geo-layers.js +115 -0
  143. tangram_core/dist-frontend/geo-layers.js.map +1 -0
  144. tangram_core/dist-frontend/index.html +38 -0
  145. tangram_core/dist-frontend/json.js +3 -0
  146. tangram_core/dist-frontend/json.js.map +1 -0
  147. tangram_core/dist-frontend/layers.js +268 -0
  148. tangram_core/dist-frontend/layers.js.map +1 -0
  149. tangram_core/dist-frontend/lit-html.js +7 -0
  150. tangram_core/dist-frontend/lit-html.js.map +1 -0
  151. tangram_core/dist-frontend/mapbox.js +2 -0
  152. tangram_core/dist-frontend/mapbox.js.map +1 -0
  153. tangram_core/dist-frontend/maplibre-gl.js +59 -0
  154. tangram_core/dist-frontend/maplibre-gl.js.map +1 -0
  155. tangram_core/dist-frontend/mesh-layers.js +2 -0
  156. tangram_core/dist-frontend/mesh-layers.js.map +1 -0
  157. tangram_core/dist-frontend/rs1090_wasm.js +813 -0
  158. tangram_core/dist-frontend/rs1090_wasm_bg.wasm +0 -0
  159. tangram_core/dist-frontend/vue.esm-browser.prod.js +13 -0
  160. tangram_core/dist-frontend/widgets.js +3 -0
  161. tangram_core/dist-frontend/widgets.js.map +1 -0
  162. tangram_core/main.ts +16 -0
  163. tangram_core/plugin.py +70 -0
  164. tangram_core/plugin.ts +41 -0
  165. tangram_core/redis.py +89 -0
  166. tangram_core/user.css +114 -0
  167. tangram_core/vite-plugin-tangram.mjs +88 -0
  168. tangram_core-0.2.0.dist-info/METADATA +37 -0
  169. tangram_core-0.2.0.dist-info/RECORD +171 -0
  170. tangram_core-0.2.0.dist-info/WHEEL +4 -0
  171. tangram_core-0.2.0.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,843 @@
1
+ import{R as st,A as S,Z as Wt,B as ne,_ as Rt,$ as qt}from"./deep-equal-uriyKJca.js";import{g as Ht,a as zt,R as we,S as jt,b as pt,T as mt,c as Gt,d as Xt}from"./array-utils-flat-wyE8tIYR.js";import{a as Kt,S as Zt}from"./project-CrvReKGW.js";class Ae extends st{get[Symbol.toStringTag](){return"ComputePipeline"}hash="";shaderLayout;constructor(e,t){super(e,t,Ae.defaultProps),this.shaderLayout=t.shaderLayout}static defaultProps={...st.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0}}function Yt(l){return ArrayBuffer.isView(l)&&!(l instanceof DataView)}function Se(l){return Array.isArray(l)?l.length===0||typeof l[0]=="number":Yt(l)}const Qt=1024;class Jt{layout={};byteLength;constructor(e,t={}){let n=0;for(const[r,a]of Object.entries(e)){const i=Ht(a),{type:o,components:c}=i,u=c*(t?.[r]??1);n=Wt(n,u);const h=n;n+=u,this.layout[r]={type:o,size:u,offset:h}}n+=(4-n%4)%4;const s=n*4;this.byteLength=Math.max(s,Qt)}getData(e){const t=zt(this.byteLength),n={i32:new Int32Array(t),u32:new Uint32Array(t),f32:new Float32Array(t),f16:new Uint16Array(t)};for(const[s,r]of Object.entries(e)){const a=this.layout[s];if(!a){S.warn(`Supplied uniform value ${s} not present in uniform block layout`)();continue}const{type:i,size:o,offset:c}=a,u=n[i];if(o===1){if(typeof r!="number"&&typeof r!="boolean"){S.warn(`Supplied value for single component uniform ${s} is not a number: ${r}`)();continue}u[c]=Number(r)}else{if(!Se(r)){S.warn(`Supplied value for multi component / array uniform ${s} is not a numeric array: ${r}`)();continue}u.set(r,c)}}return new Uint8Array(t,0,this.byteLength)}has(e){return!!this.layout[e]}get(e){return this.layout[e]}}function en(l,e,t=16){if(l!==e)return!1;const n=l,s=e;if(!Se(n))return!1;if(Se(s)&&n.length===s.length){for(let r=0;r<n.length;++r)if(s[r]!==n[r])return!1}return!0}function tn(l){return Se(l)?l.slice():l}class nn{name;uniforms={};modifiedUniforms={};modified=!0;bindingLayout={};needsRedraw="initialized";constructor(e){if(this.name=e?.name||"unnamed",e?.name&&e?.shaderLayout){const t=e?.shaderLayout.bindings?.find(s=>s.type==="uniform"&&s.name===e?.name);if(!t)throw new Error(e?.name);const n=t;for(const s of n.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(const[t,n]of Object.entries(e))this._setUniform(t,n),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${n}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){en(this.uniforms[e],t)||(this.uniforms[e]=tn(t),this.modifiedUniforms[e]=!0,this.modified=!0)}}class sn{uniformBlocks=new Map;uniformBufferLayouts=new Map;uniformBuffers=new Map;constructor(e){for(const[t,n]of Object.entries(e)){const s=t,r=new Jt(n.uniformTypes??{},n.uniformSizes??{});this.uniformBufferLayouts.set(s,r);const a=new nn({name:t});a.setUniforms(n.defaultUniforms||{}),this.uniformBlocks.set(s,a)}}destroy(){for(const e of this.uniformBuffers.values())e.destroy()}setUniforms(e){for(const[t,n]of Object.entries(e))this.uniformBlocks.get(t)?.setUniforms(n);this.updateUniformBuffers()}getUniformBufferByteLength(e){return this.uniformBufferLayouts.get(e)?.byteLength||0}getUniformBufferData(e){const t=this.uniformBlocks.get(e)?.getAllUniforms()||{};return this.uniformBufferLayouts.get(e)?.getData(t)}createUniformBuffer(e,t,n){n&&this.setUniforms(n);const s=this.getUniformBufferByteLength(t),r=e.createBuffer({usage:ne.UNIFORM|ne.COPY_DST,byteLength:s}),a=this.getUniformBufferData(t);return r.write(a),r}getManagedUniformBuffer(e,t){if(!this.uniformBuffers.get(t)){const n=this.getUniformBufferByteLength(t),s=e.createBuffer({usage:ne.UNIFORM|ne.COPY_DST,byteLength:n});this.uniformBuffers.set(t,s)}return this.uniformBuffers.get(t)}updateUniformBuffers(){let e=!1;for(const t of this.uniformBlocks.keys()){const n=this.updateUniformBuffer(t);e||=n}return e&&S.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){const t=this.uniformBlocks.get(e);let n=this.uniformBuffers.get(e),s=!1;if(n&&t?.needsRedraw){s||=t.needsRedraw;const r=this.getUniformBufferData(e);n=this.uniformBuffers.get(e),n?.write(r);const a=this.uniformBlocks.get(e)?.getAllUniforms();S.log(4,`Writing to uniform buffer ${String(e)}`,r,a)()}return s}}class z{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}}class rt{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}}class se extends z{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}}class re extends z{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}getTypeName(){return`array<${this.format.getTypeName()}, ${this.count}>`}}class Ue extends z{constructor(e,t,n){super(e,n),this.format=t}get isPointer(){return!0}getTypeName(){return`&${this.format.getTypeName()}`}}class ae extends z{constructor(e,t,n,s){super(e,n),this.format=t,this.access=s}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}}var te;(l=>{l[l.Uniform=0]="Uniform",l[l.Storage=1]="Storage",l[l.Texture=2]="Texture",l[l.Sampler=3]="Sampler",l[l.StorageTexture=4]="StorageTexture"})(te||(te={}));class be{constructor(e,t,n,s,r,a,i){this.name=e,this.type=t,this.group=n,this.binding=s,this.attributes=r,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}}class rn{constructor(e,t){this.name=e,this.type=t}}class an{constructor(e,t,n,s){this.name=e,this.type=t,this.locationType=n,this.location=s,this.interpolation=null}}class it{constructor(e,t,n,s){this.name=e,this.type=t,this.locationType=n,this.location=s}}class on{constructor(e,t,n,s){this.name=e,this.type=t,this.attributes=n,this.id=s}}class un{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}}class cn{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}}class ln{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}}function fn(l){var e=(32768&l)>>15,t=(31744&l)>>10,n=1023&l;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))}const _t=new Float32Array(1),hn=new Int32Array(_t.buffer),V=new Uint16Array(1);function dn(l){_t[0]=l;const e=hn[0],t=e>>31&1;let n=e>>23&255,s=8388607&e;if(n===255)return V[0]=t<<15|31744|(s!==0?512:0),V[0];if(n===0){if(s===0)return V[0]=t<<15,V[0];s|=8388608;let r=113;for(;!(8388608&s);)s<<=1,r--;return n=127-r,s&=8388607,n>0?(s=(s>>126-n)+(s>>127-n&1),V[0]=t<<15|n<<10|s>>13,V[0]):(V[0]=t<<15,V[0])}return n=n-127+15,n>=31?(V[0]=t<<15|31744,V[0]):n<=0?n<-10?(V[0]=t<<15,V[0]):(s=(8388608|s)>>1-n,V[0]=t<<15|s>>13,V[0]):(s>>=13,V[0]=t<<15|n<<10|s,V[0])}const qe=new Uint32Array(1),gt=new Float32Array(qe.buffer,0,1);function at(l){const e=112+(l>>6&31)<<23|(63&l)<<17;return qe[0]=e,gt[0]}function pn(l,e,t,n,s,r,a,i,o){const c=n*(a>>=s)*(r>>=s)+t*a+e*i;switch(o){case"r8unorm":return[L(l,c,"8unorm",1)[0]];case"r8snorm":return[L(l,c,"8snorm",1)[0]];case"r8uint":return[L(l,c,"8uint",1)[0]];case"r8sint":return[L(l,c,"8sint",1)[0]];case"rg8unorm":{const u=L(l,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{const u=L(l,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{const u=L(l,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{const u=L(l,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{const u=L(l,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{const u=L(l,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{const u=L(l,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{const u=L(l,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{const u=L(l,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[L(l,c,"16uint",1)[0]];case"r16sint":return[L(l,c,"16sint",1)[0]];case"r16float":return[L(l,c,"16float",1)[0]];case"rg16uint":{const u=L(l,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{const u=L(l,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{const u=L(l,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{const u=L(l,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{const u=L(l,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{const u=L(l,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[L(l,c,"32uint",1)[0]];case"r32sint":return[L(l,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[L(l,c,"32float",1)[0]];case"rg32uint":{const u=L(l,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{const u=L(l,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{const u=L(l,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{const u=L(l,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{const u=L(l,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{const u=L(l,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{const u=new Uint32Array(l.buffer,c,1)[0],h=(4192256&u)>>11,x=(4290772992&u)>>22;return[at(2047&u),at(h),(function(v){const k=112+(v>>5&31)<<23|(31&v)<<18;return qe[0]=k,gt[0]})(x),1]}}return null}function L(l,e,t,n){const s=[0,0,0,0];for(let r=0;r<n;++r)switch(t){case"8unorm":s[r]=l[e]/255,e++;break;case"8snorm":s[r]=l[e]/255*2-1,e++;break;case"8uint":s[r]=l[e],e++;break;case"8sint":s[r]=l[e]-127,e++;break;case"16uint":s[r]=l[e]|l[e+1]<<8,e+=2;break;case"16sint":s[r]=(l[e]|l[e+1]<<8)-32768,e+=2;break;case"16float":s[r]=fn(l[e]|l[e+1]<<8),e+=2;break;case"32uint":case"32sint":s[r]=l[e]|l[e+1]<<8|l[e+2]<<16|l[e+3]<<24,e+=4;break;case"32float":s[r]=new Float32Array(l.buffer,e,1)[0],e+=4}return s}function O(l,e,t,n,s){for(let r=0;r<n;++r)switch(t){case"8unorm":l[e]=255*s[r],e++;break;case"8snorm":l[e]=.5*(s[r]+1)*255,e++;break;case"8uint":l[e]=s[r],e++;break;case"8sint":l[e]=s[r]+127,e++;break;case"16uint":new Uint16Array(l.buffer,e,1)[0]=s[r],e+=2;break;case"16sint":new Int16Array(l.buffer,e,1)[0]=s[r],e+=2;break;case"16float":{const a=dn(s[r]);new Uint16Array(l.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(l.buffer,e,1)[0]=s[r],e+=4;break;case"32sint":new Int32Array(l.buffer,e,1)[0]=s[r],e+=4;break;case"32float":new Float32Array(l.buffer,e,1)[0]=s[r],e+=4}return s}const Be={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}};class G{constructor(){this.id=G._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Ee.instance);for(const n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Le.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}}G._id=0;class Ee extends G{}Ee.instance=new Ee;class Le extends G{}Le.instance=new Le;const yt=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"]);class N extends G{constructor(){super()}}class _e extends N{constructor(e,t,n,s,r,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=s,this.startLine=r,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(const t of this.attributes)e(t);e(this);for(const t of this.args)e(t);this.searchBlock(this.body,e)}}class mn extends N{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}}class xt 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)}}class Me extends N{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}}class bt extends N{constructor(e,t,n,s){super(),this.init=e,this.condition=t,this.increment=n,this.body=s}get astNodeType(){return"for"}search(e){var t,n,s;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(s=this.increment)===null||s===void 0||s.search(e),this.searchBlock(this.body,e)}}class ee extends N{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class He 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)}}class de extends N{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}}class ke extends N{constructor(e,t,n,s,r){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=s,this.value=r}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)}}var ce,fe,y,m;(l=>{l.increment="++",l.decrement="--"})(ce||(ce={})),(l=>{l.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return l[t]}})(ce||(ce={}));class vt extends N{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}}(l=>{l.assign="=",l.addAssign="+=",l.subtractAssin="-=",l.multiplyAssign="*=",l.divideAssign="/=",l.moduloAssign="%=",l.andAssign="&=",l.orAssign="|=",l.xorAssign="^=",l.shiftLeftAssign="<<=",l.shiftRightAssign=">>="})(fe||(fe={})),(l=>{l.parse=function(e){const t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(fe||(fe={}));class wt 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)}}class ze extends N{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return yt.has(this.name)}search(e){for(const t of this.args)t.search(e);e(this)}}class kt 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)}}class It extends N{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}search(e){e(this);for(const t of this.cases)t.search(e)}}class Tt extends N{constructor(e,t,n,s){super(),this.condition=e,this.body=t,this.elseif=n,this.else=s}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)}}class At 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)}}class _n extends N{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}}class gn extends N{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}}class St extends N{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}}class je extends N{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}}class yn extends N{constructor(){super()}get astNodeType(){return"discard"}}class Et extends N{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}}class Lt extends N{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}}class b 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){const s=b._priority.get(t.name);b._priority.get(e[n].name)<s&&(t=e[n])}return t.name==="x32"?b.i32:t}getTypeName(){return this.name}}b.x32=new b("x32"),b.f32=new b("f32"),b.i32=new b("i32"),b.u32=new b("u32"),b.f16=new b("f16"),b.bool=new b("bool"),b.void=new b("void"),b._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class ot extends b{constructor(e){super(e)}}class Q extends b{constructor(e,t,n,s){super(e),this.members=t,this.startLine=n,this.endLine=s}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(const t of this.members)e(t)}}class g extends b{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}}g.vec2f=new g("vec2",b.f32,null),g.vec3f=new g("vec3",b.f32,null),g.vec4f=new g("vec4",b.f32,null),g.vec2i=new g("vec2",b.i32,null),g.vec3i=new g("vec3",b.i32,null),g.vec4i=new g("vec4",b.i32,null),g.vec2u=new g("vec2",b.u32,null),g.vec3u=new g("vec3",b.u32,null),g.vec4u=new g("vec4",b.u32,null),g.vec2h=new g("vec2",b.f16,null),g.vec3h=new g("vec3",b.f16,null),g.vec4h=new g("vec4",b.f16,null),g.vec2b=new g("vec2",b.bool,null),g.vec3b=new g("vec3",b.bool,null),g.vec4b=new g("vec4",b.bool,null),g.mat2x2f=new g("mat2x2",b.f32,null),g.mat2x3f=new g("mat2x3",b.f32,null),g.mat2x4f=new g("mat2x4",b.f32,null),g.mat3x2f=new g("mat3x2",b.f32,null),g.mat3x3f=new g("mat3x3",b.f32,null),g.mat3x4f=new g("mat3x4",b.f32,null),g.mat4x2f=new g("mat4x2",b.f32,null),g.mat4x3f=new g("mat4x3",b.f32,null),g.mat4x4f=new g("mat4x4",b.f32,null),g.mat2x2h=new g("mat2x2",b.f16,null),g.mat2x3h=new g("mat2x3",b.f16,null),g.mat2x4h=new g("mat2x4",b.f16,null),g.mat3x2h=new g("mat3x2",b.f16,null),g.mat3x3h=new g("mat3x3",b.f16,null),g.mat3x4h=new g("mat3x4",b.f16,null),g.mat4x2h=new g("mat4x2",b.f16,null),g.mat4x3h=new g("mat4x3",b.f16,null),g.mat4x4h=new g("mat4x4",b.f16,null),g.mat2x2i=new g("mat2x2",b.i32,null),g.mat2x3i=new g("mat2x3",b.i32,null),g.mat2x4i=new g("mat2x4",b.i32,null),g.mat3x2i=new g("mat3x2",b.i32,null),g.mat3x3i=new g("mat3x3",b.i32,null),g.mat3x4i=new g("mat3x4",b.i32,null),g.mat4x2i=new g("mat4x2",b.i32,null),g.mat4x3i=new g("mat4x3",b.i32,null),g.mat4x4i=new g("mat4x4",b.i32,null),g.mat2x2u=new g("mat2x2",b.u32,null),g.mat2x3u=new g("mat2x3",b.u32,null),g.mat2x4u=new g("mat2x4",b.u32,null),g.mat3x2u=new g("mat3x2",b.u32,null),g.mat3x3u=new g("mat3x3",b.u32,null),g.mat3x4u=new g("mat3x4",b.u32,null),g.mat4x2u=new g("mat4x2",b.u32,null),g.mat4x3u=new g("mat4x3",b.u32,null),g.mat4x4u=new g("mat4x4",b.u32,null);class Ie extends b{constructor(e,t,n,s){super(e),this.storage=t,this.type=n,this.access=s}get astNodeType(){return"pointer"}}class pe extends b{constructor(e,t,n,s){super(e),this.attributes=t,this.format=n,this.count=s}get astNodeType(){return"array"}get isArray(){return!0}}class he extends b{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}}class K extends G{constructor(){super(),this.postfix=null}}class oe extends K{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}}class Z extends K{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(const t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}}class Ge extends K{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 yt.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(const t of this.args)t.search(e);e(this)}}class H extends K{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)}}class Ot extends K{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){const 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)}}class P extends K{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))}}class $t extends K{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}}class le extends K{constructor(e){super(),this.index=e}search(e){this.index.search(e)}}class Nt extends K{constructor(){super()}}class F extends Nt{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)}}class X extends Nt{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?b.f32:e.name==="u32"||t.name==="u32"?b.u32:b.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}}class Dt extends G{constructor(e){super(),this.body=e}search(e){e(this),this.searchBlock(this.body,e)}}class Te extends K{constructor(){super()}get astNodeType(){return"default"}}class Bt extends Dt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}}class Ft extends Dt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}}class ut extends G{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}}class xn extends G{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)}}class ct extends G{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}}class Pt extends G{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}}class j{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,s){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;class We extends j{constructor(){super(new z("void",null),null)}toString(){return"void"}}We.void=new We;class ue extends j{constructor(e){super(new Ue("pointer",e.typeInfo,null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,s){this.reference.setDataValue(e,t,n,s)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}toString(){return`&${this.reference.toString()}`}}class p 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,s){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 r=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?r=Math.floor(r):this.typeInfo.name==="bool"&&(r=r?1:0),this.data[0]=r}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}}function bn(l,e,t){const n=e.length;return n===2?t==="f32"?new d(new Float32Array(e),l.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new d(new Int32Array(e),l.getTypeInfo("vec2i")):t==="u32"?new d(new Uint32Array(e),l.getTypeInfo("vec2u")):t==="f16"?new d(new Float32Array(e),l.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new d(new Float32Array(e),l.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new d(new Int32Array(e),l.getTypeInfo("vec3i")):t==="u32"?new d(new Uint32Array(e),l.getTypeInfo("vec3u")):t==="f16"?new d(new Float32Array(e),l.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new d(new Float32Array(e),l.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new d(new Int32Array(e),l.getTypeInfo("vec4i")):t==="u32"?new d(new Uint32Array(e),l.getTypeInfo("vec4u")):t==="f16"?new d(new Float32Array(e),l.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}class d extends j{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{const s=this.typeInfo.name;s==="vec2f"||s==="vec3f"||s==="vec4f"?this.data=new Float32Array(e):s==="vec2i"||s==="vec3i"||s==="vec4i"?this.data=new Int32Array(e):s==="vec2u"||s==="vec3u"||s==="vec4u"?this.data=new Uint32Array(e):s==="vec2h"||s==="vec3h"||s==="vec4h"?this.data=new Float32Array(e):s==="vec2b"||s==="vec3b"||s==="vec4b"?this.data=new Int32Array(e):s==="vec2"||s==="vec3"||s==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${s}`)}}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,s){n instanceof oe?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 s=e.getTypeInfo("f32");if(this.typeInfo instanceof ae)s=this.typeInfo.format||s;else{const a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?s=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?s=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?s=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?s=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?s=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let r=this;for(;t!==null&&r!==null;){if(t instanceof le){const a=t.index;let i=-1;if(a instanceof P){if(!(a.value instanceof p))return console.error(`GetSubData: Invalid array index ${a.value}`),null;i=a.value.value}else{const 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>=r.data.length)return console.error("GetSubData: Index out of range",i),null;if(r.data instanceof Float32Array){const o=new Float32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new p(o,s)}if(r.data instanceof Int32Array){const o=new Int32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new p(o,s)}if(r.data instanceof Uint32Array){const o=new Uint32Array(r.data.buffer,r.data.byteOffset+4*i,1);return new p(o,s)}throw"GetSubData: Invalid data type"}if(!(t instanceof oe))return console.error("GetSubData: Unknown postfix",t),null;{const a=t.value.toLowerCase();if(a.length===1){let o=0;if(a==="x"||a==="r")o=0;else if(a==="y"||a==="g")o=1;else if(a==="z"||a==="b")o=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;o=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(c,s,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(c,s,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*o,1);return new p(c,s,this)}}const i=[];for(const 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}`);r=bn(e,i,s.name)}t=t.postfix}return r}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}}class T 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,s){n instanceof oe?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;const s=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof ae)this.typeInfo.format;else if(s.endsWith("f"))e.getTypeInfo("f32");else if(s.endsWith("i"))e.getTypeInfo("i32");else if(s.endsWith("u"))e.getTypeInfo("u32");else{if(!s.endsWith("h"))return console.error(`GetDataValue: Unknown type ${s}`),null;e.getTypeInfo("f16")}if(t instanceof le){const r=t.index;let a=-1;if(r instanceof P){if(!(r.value instanceof p))return console.error(`GetDataValue: Invalid array index ${r.value}`),null;a=r.value.value}else{const c=e.evalExpression(r,n);if(!(c instanceof p))return console.error("GetDataValue: Unknown index type",r),null;a=c.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;const i=s.endsWith("h")?"h":"f";let o;if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h"||s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h")o=new d(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${i}`));else if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h"||s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h")o=new d(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${i}`));else{if(s!=="mat2x4"&&s!=="mat2x4f"&&s!=="mat2x4h"&&s!=="mat3x4"&&s!=="mat3x4f"&&s!=="mat3x4h"&&s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${s}`),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}}class B extends j{constructor(e,t,n=0,s=null){super(t,s),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){const e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new B(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,s){if(t===null)return void console.log("setDataValue: NULL data.");let r=this.offset,a=this.typeInfo;for(;n;){if(n instanceof le)if(a instanceof re){const i=n.index;if(i instanceof P){if(!(i.value instanceof p))return void console.error(`SetDataValue: Invalid index type ${i.value}`);r+=i.value.value*a.stride}else{const o=e.evalExpression(i,s);if(!(o instanceof p))return void console.error("SetDataValue: Unknown index type",i);r+=o.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof oe))return void console.error("SetDataValue: Unknown postfix type",n);{const i=n.value;if(a instanceof se){let o=!1;for(const c of a.members)if(c.name===i){r+=c.offset,a=c.type,o=!0;break}if(!o)return void console.error(`SetDataValue: Member ${i} not found`)}else if(a instanceof z){const o=a.getTypeName();let c=0;if(i==="x"||i==="r")c=0;else if(i==="y"||i==="g")c=1;else if(i==="z"||i==="b")c=2;else{if(i!=="w"&&i!=="a")return void console.error(`SetDataValue: Unknown member ${i}`);c=3}if(!(t instanceof p))return void console.error("SetDataValue: Invalid value",t);const u=t.value;return o==="vec2f"?void(new Float32Array(this.buffer,r,2)[c]=u):o==="vec3f"?void(new Float32Array(this.buffer,r,3)[c]=u):o==="vec4f"?void(new Float32Array(this.buffer,r,4)[c]=u):o==="vec2i"?void(new Int32Array(this.buffer,r,2)[c]=u):o==="vec3i"?void(new Int32Array(this.buffer,r,3)[c]=u):o==="vec4i"?void(new Int32Array(this.buffer,r,4)[c]=u):o==="vec2u"?void(new Uint32Array(this.buffer,r,2)[c]=u):o==="vec3u"?void(new Uint32Array(this.buffer,r,3)[c]=u):o==="vec4u"?void(new Uint32Array(this.buffer,r,4)[c]=u):void console.error(`SetDataValue: Type ${o} is not a struct`)}}}n=n.postfix}this.setData(e,t,a,r,s)}setData(e,t,n,s,r){const 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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Int32Array(this.buffer,s,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"){const i=new Int32Array(this.buffer,s,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"){const i=new Int32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Uint32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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"){const i=new Float32Array(this.buffer,s,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 B){if(n===t.typeInfo)return void new Uint8Array(this.buffer,s,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,s,1)[0]=t.value);else t instanceof p&&(new Uint32Array(this.buffer,s,1)[0]=t.value);else t instanceof p&&(new Int32Array(this.buffer,s,1)[0]=t.value);else t instanceof p&&(new Float32Array(this.buffer,s,1)[0]=t.value)}getSubData(e,t,n){var s,r,a;if(t===null)return this;let i=this.offset,o=this.typeInfo;for(;t;){if(t instanceof le){const u=t.index,h=u instanceof K?e.evalExpression(u,n):u;let x=0;if(h instanceof p?x=h.value:typeof h=="number"?x=h:console.error("GetDataValue: Invalid index type",u),o instanceof re)i+=x*o.stride,o=o.format;else{const v=o.getTypeName();v==="mat4x4"||v==="mat4x4f"||v==="mat4x4h"?(i+=16*x,o=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${o.getTypeName()} is not an array`)}}else{if(!(t instanceof oe))return console.error("GetDataValue: Unknown postfix type",t),null;{const u=t.value;if(o instanceof se){let h=!1;for(const x of o.members)if(x.name===u){i+=x.offset,o=x.type,h=!0;break}if(!h)return console.error(`GetDataValue: Member ${u} not found`),null}else if(o instanceof z){const h=o.getTypeName();if(h==="vec2f"||h==="vec3f"||h==="vec4f"||h==="vec2i"||h==="vec3i"||h==="vec4i"||h==="vec2u"||h==="vec3u"||h==="vec4u"||h==="vec2b"||h==="vec3b"||h==="vec4b"||h==="vec2h"||h==="vec3h"||h==="vec4h"||h==="vec2"||h==="vec3"||h==="vec4"){if(u.length>0&&u.length<5){let x="f";const v=[];for(let k=0;k<u.length;++k){const $=u[k].toLowerCase();let E=0;if($==="x"||$==="r")E=0;else if($==="y"||$==="g")E=1;else if($==="z"||$==="b")E=2;else{if($!=="w"&&$!=="a")return console.error(`Unknown member ${u}`),null;E=3}if(u.length===1){if(h.endsWith("f"))return this.buffer.byteLength<i+4*E+4?(console.log("Insufficient buffer data"),null):new p(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f32"),this);if(h.endsWith("h"))return new p(new Float32Array(this.buffer,i+4*E,1),e.getTypeInfo("f16"),this);if(h.endsWith("i"))return new p(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this);if(h.endsWith("b"))return new p(new Int32Array(this.buffer,i+4*E,1),e.getTypeInfo("bool"),this);if(h.endsWith("u"))return new p(new Uint32Array(this.buffer,i+4*E,1),e.getTypeInfo("i32"),this)}if(h==="vec2f")v.push(new Float32Array(this.buffer,i,2)[E]);else if(h==="vec3f"){if(i+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;const D=new Float32Array(this.buffer,i,3);v.push(D[E])}else if(h==="vec4f")v.push(new Float32Array(this.buffer,i,4)[E]);else if(h==="vec2i")x="i",v.push(new Int32Array(this.buffer,i,2)[E]);else if(h==="vec3i")x="i",v.push(new Int32Array(this.buffer,i,3)[E]);else if(h==="vec4i")x="i",v.push(new Int32Array(this.buffer,i,4)[E]);else if(h==="vec2u"){x="u";const D=new Uint32Array(this.buffer,i,2);v.push(D[E])}else h==="vec3u"?(x="u",v.push(new Uint32Array(this.buffer,i,3)[E])):h==="vec4u"&&(x="u",v.push(new Uint32Array(this.buffer,i,4)[E]))}return v.length===2?o=e.getTypeInfo(`vec2${x}`):v.length===3?o=e.getTypeInfo(`vec3${x}`):v.length===4?o=e.getTypeInfo(`vec4${x}`):console.error(`GetDataValue: Invalid vector length ${v.length}`),new d(v,o,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${h} is not a struct`),null}}}t=t.postfix}const c=o.getTypeName();return c==="f32"?new p(new Float32Array(this.buffer,i,1),o,this):c==="i32"?new p(new Int32Array(this.buffer,i,1),o,this):c==="u32"?new p(new Uint32Array(this.buffer,i,1),o,this):c==="vec2f"?new d(new Float32Array(this.buffer,i,2),o,this):c==="vec3f"?new d(new Float32Array(this.buffer,i,3),o,this):c==="vec4f"?new d(new Float32Array(this.buffer,i,4),o,this):c==="vec2i"?new d(new Int32Array(this.buffer,i,2),o,this):c==="vec3i"?new d(new Int32Array(this.buffer,i,3),o,this):c==="vec4i"?new d(new Int32Array(this.buffer,i,4),o,this):c==="vec2u"?new d(new Uint32Array(this.buffer,i,2),o,this):c==="vec3u"?new d(new Uint32Array(this.buffer,i,3),o,this):c==="vec4u"?new d(new Uint32Array(this.buffer,i,4),o,this):o instanceof ae&&o.name==="atomic"?((s=o.format)===null||s===void 0?void 0:s.name)==="u32"?new p(new Uint32Array(this.buffer,i,1)[0],o.format,this):((r=o.format)===null||r===void 0?void 0:r.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 B(this.buffer,o,i,this)}toString(){let e="";if(this.typeInfo instanceof re)if(this.typeInfo.format.name==="f32"){const 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"){const 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"){const 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"){const 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"){const 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"){const 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 se?e+="{...}":e="[...]";return e}}class J extends j{constructor(e,t,n,s){super(t,null),this.data=e,this.descriptor=n,this.view=s}clone(){return new J(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;const 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;const 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;const 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];const 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(){const e=this.format,t=Be[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){const e=this.format,t=Be[e];return!!t&&t.isDepthStencil}getGpuSize(){const e=this.format,t=Be[e],n=this.width;if(!e||n<=0||!t)return-1;const s=this.height,r=this.depthOrArrayLayers,a=this.dimension;return n/t.blockWidth*(a==="1d"?1:s/t.blockHeight)*t.bytesPerBlock*r}getPixel(e,t,n=0,s=0){const r=this.texelByteSize,a=this.bytesPerRow,i=this.height,o=this.data[s];return pn(new Uint8Array(o),e,t,n,s,i,a,r,this.format)}setPixel(e,t,n,s,r){const a=this.texelByteSize,i=this.bytesPerRow,o=this.height,c=this.data[s];(function(u,h,x,v,k,$,E,D,R,A){const I=v*(E>>=k)*($>>=k)+x*E+h*D;switch(R){case"r8unorm":return void O(u,I,"8unorm",1,A);case"r8snorm":return void O(u,I,"8snorm",1,A);case"r8uint":return void O(u,I,"8uint",1,A);case"r8sint":return void O(u,I,"8sint",1,A);case"rg8unorm":return void O(u,I,"8unorm",2,A);case"rg8snorm":return void O(u,I,"8snorm",2,A);case"rg8uint":return void O(u,I,"8uint",2,A);case"rg8sint":return void O(u,I,"8sint",2,A);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void O(u,I,"8unorm",4,A);case"rgba8snorm":return void O(u,I,"8snorm",4,A);case"rgba8uint":return void O(u,I,"8uint",4,A);case"rgba8sint":return void O(u,I,"8sint",4,A);case"r16uint":return void O(u,I,"16uint",1,A);case"r16sint":return void O(u,I,"16sint",1,A);case"r16float":return void O(u,I,"16float",1,A);case"rg16uint":return void O(u,I,"16uint",2,A);case"rg16sint":return void O(u,I,"16sint",2,A);case"rg16float":return void O(u,I,"16float",2,A);case"rgba16uint":return void O(u,I,"16uint",4,A);case"rgba16sint":return void O(u,I,"16sint",4,A);case"rgba16float":return void O(u,I,"16float",4,A);case"r32uint":return void O(u,I,"32uint",1,A);case"r32sint":return void O(u,I,"32sint",1,A);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void O(u,I,"32float",1,A);case"rg32uint":return void O(u,I,"32uint",2,A);case"rg32sint":return void O(u,I,"32sint",2,A);case"rg32float":return void O(u,I,"32float",2,A);case"rgba32uint":return void O(u,I,"32uint",4,A);case"rgba32sint":return void O(u,I,"32sint",4,A);case"rgba32float":return void O(u,I,"32float",4,A);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,n,s,o,i,a,this.format,r)}}(l=>{l[l.token=0]="token",l[l.keyword=1]="keyword",l[l.reserved=2]="reserved"})(m||(m={}));class _{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}}class f{}y=f,f.none=new _("",m.reserved,""),f.eof=new _("EOF",m.token,""),f.reserved={asm:new _("asm",m.reserved,"asm"),bf16:new _("bf16",m.reserved,"bf16"),do:new _("do",m.reserved,"do"),enum:new _("enum",m.reserved,"enum"),f16:new _("f16",m.reserved,"f16"),f64:new _("f64",m.reserved,"f64"),handle:new _("handle",m.reserved,"handle"),i8:new _("i8",m.reserved,"i8"),i16:new _("i16",m.reserved,"i16"),i64:new _("i64",m.reserved,"i64"),mat:new _("mat",m.reserved,"mat"),premerge:new _("premerge",m.reserved,"premerge"),regardless:new _("regardless",m.reserved,"regardless"),typedef:new _("typedef",m.reserved,"typedef"),u8:new _("u8",m.reserved,"u8"),u16:new _("u16",m.reserved,"u16"),u64:new _("u64",m.reserved,"u64"),unless:new _("unless",m.reserved,"unless"),using:new _("using",m.reserved,"using"),vec:new _("vec",m.reserved,"vec"),void:new _("void",m.reserved,"void")},f.keywords={array:new _("array",m.keyword,"array"),atomic:new _("atomic",m.keyword,"atomic"),bool:new _("bool",m.keyword,"bool"),f32:new _("f32",m.keyword,"f32"),i32:new _("i32",m.keyword,"i32"),mat2x2:new _("mat2x2",m.keyword,"mat2x2"),mat2x3:new _("mat2x3",m.keyword,"mat2x3"),mat2x4:new _("mat2x4",m.keyword,"mat2x4"),mat3x2:new _("mat3x2",m.keyword,"mat3x2"),mat3x3:new _("mat3x3",m.keyword,"mat3x3"),mat3x4:new _("mat3x4",m.keyword,"mat3x4"),mat4x2:new _("mat4x2",m.keyword,"mat4x2"),mat4x3:new _("mat4x3",m.keyword,"mat4x3"),mat4x4:new _("mat4x4",m.keyword,"mat4x4"),ptr:new _("ptr",m.keyword,"ptr"),sampler:new _("sampler",m.keyword,"sampler"),sampler_comparison:new _("sampler_comparison",m.keyword,"sampler_comparison"),struct:new _("struct",m.keyword,"struct"),texture_1d:new _("texture_1d",m.keyword,"texture_1d"),texture_2d:new _("texture_2d",m.keyword,"texture_2d"),texture_2d_array:new _("texture_2d_array",m.keyword,"texture_2d_array"),texture_3d:new _("texture_3d",m.keyword,"texture_3d"),texture_cube:new _("texture_cube",m.keyword,"texture_cube"),texture_cube_array:new _("texture_cube_array",m.keyword,"texture_cube_array"),texture_multisampled_2d:new _("texture_multisampled_2d",m.keyword,"texture_multisampled_2d"),texture_storage_1d:new _("texture_storage_1d",m.keyword,"texture_storage_1d"),texture_storage_2d:new _("texture_storage_2d",m.keyword,"texture_storage_2d"),texture_storage_2d_array:new _("texture_storage_2d_array",m.keyword,"texture_storage_2d_array"),texture_storage_3d:new _("texture_storage_3d",m.keyword,"texture_storage_3d"),texture_depth_2d:new _("texture_depth_2d",m.keyword,"texture_depth_2d"),texture_depth_2d_array:new _("texture_depth_2d_array",m.keyword,"texture_depth_2d_array"),texture_depth_cube:new _("texture_depth_cube",m.keyword,"texture_depth_cube"),texture_depth_cube_array:new _("texture_depth_cube_array",m.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new _("texture_depth_multisampled_2d",m.keyword,"texture_depth_multisampled_2d"),texture_external:new _("texture_external",m.keyword,"texture_external"),u32:new _("u32",m.keyword,"u32"),vec2:new _("vec2",m.keyword,"vec2"),vec3:new _("vec3",m.keyword,"vec3"),vec4:new _("vec4",m.keyword,"vec4"),bitcast:new _("bitcast",m.keyword,"bitcast"),block:new _("block",m.keyword,"block"),break:new _("break",m.keyword,"break"),case:new _("case",m.keyword,"case"),continue:new _("continue",m.keyword,"continue"),continuing:new _("continuing",m.keyword,"continuing"),default:new _("default",m.keyword,"default"),diagnostic:new _("diagnostic",m.keyword,"diagnostic"),discard:new _("discard",m.keyword,"discard"),else:new _("else",m.keyword,"else"),enable:new _("enable",m.keyword,"enable"),fallthrough:new _("fallthrough",m.keyword,"fallthrough"),false:new _("false",m.keyword,"false"),fn:new _("fn",m.keyword,"fn"),for:new _("for",m.keyword,"for"),function:new _("function",m.keyword,"function"),if:new _("if",m.keyword,"if"),let:new _("let",m.keyword,"let"),const:new _("const",m.keyword,"const"),loop:new _("loop",m.keyword,"loop"),while:new _("while",m.keyword,"while"),private:new _("private",m.keyword,"private"),read:new _("read",m.keyword,"read"),read_write:new _("read_write",m.keyword,"read_write"),return:new _("return",m.keyword,"return"),requires:new _("requires",m.keyword,"requires"),storage:new _("storage",m.keyword,"storage"),switch:new _("switch",m.keyword,"switch"),true:new _("true",m.keyword,"true"),alias:new _("alias",m.keyword,"alias"),type:new _("type",m.keyword,"type"),uniform:new _("uniform",m.keyword,"uniform"),var:new _("var",m.keyword,"var"),override:new _("override",m.keyword,"override"),workgroup:new _("workgroup",m.keyword,"workgroup"),write:new _("write",m.keyword,"write"),r8unorm:new _("r8unorm",m.keyword,"r8unorm"),r8snorm:new _("r8snorm",m.keyword,"r8snorm"),r8uint:new _("r8uint",m.keyword,"r8uint"),r8sint:new _("r8sint",m.keyword,"r8sint"),r16uint:new _("r16uint",m.keyword,"r16uint"),r16sint:new _("r16sint",m.keyword,"r16sint"),r16float:new _("r16float",m.keyword,"r16float"),rg8unorm:new _("rg8unorm",m.keyword,"rg8unorm"),rg8snorm:new _("rg8snorm",m.keyword,"rg8snorm"),rg8uint:new _("rg8uint",m.keyword,"rg8uint"),rg8sint:new _("rg8sint",m.keyword,"rg8sint"),r32uint:new _("r32uint",m.keyword,"r32uint"),r32sint:new _("r32sint",m.keyword,"r32sint"),r32float:new _("r32float",m.keyword,"r32float"),rg16uint:new _("rg16uint",m.keyword,"rg16uint"),rg16sint:new _("rg16sint",m.keyword,"rg16sint"),rg16float:new _("rg16float",m.keyword,"rg16float"),rgba8unorm:new _("rgba8unorm",m.keyword,"rgba8unorm"),rgba8unorm_srgb:new _("rgba8unorm_srgb",m.keyword,"rgba8unorm_srgb"),rgba8snorm:new _("rgba8snorm",m.keyword,"rgba8snorm"),rgba8uint:new _("rgba8uint",m.keyword,"rgba8uint"),rgba8sint:new _("rgba8sint",m.keyword,"rgba8sint"),bgra8unorm:new _("bgra8unorm",m.keyword,"bgra8unorm"),bgra8unorm_srgb:new _("bgra8unorm_srgb",m.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new _("rgb10a2unorm",m.keyword,"rgb10a2unorm"),rg11b10float:new _("rg11b10float",m.keyword,"rg11b10float"),rg32uint:new _("rg32uint",m.keyword,"rg32uint"),rg32sint:new _("rg32sint",m.keyword,"rg32sint"),rg32float:new _("rg32float",m.keyword,"rg32float"),rgba16uint:new _("rgba16uint",m.keyword,"rgba16uint"),rgba16sint:new _("rgba16sint",m.keyword,"rgba16sint"),rgba16float:new _("rgba16float",m.keyword,"rgba16float"),rgba32uint:new _("rgba32uint",m.keyword,"rgba32uint"),rgba32sint:new _("rgba32sint",m.keyword,"rgba32sint"),rgba32float:new _("rgba32float",m.keyword,"rgba32float"),static_assert:new _("static_assert",m.keyword,"static_assert")},f.tokens={decimal_float_literal:new _("decimal_float_literal",m.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 _("hex_float_literal",m.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 _("int_literal",m.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new _("uint_literal",m.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new _("name",m.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new _("ident",m.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new _("and",m.token,"&"),and_and:new _("and_and",m.token,"&&"),arrow:new _("arrow ",m.token,"->"),attr:new _("attr",m.token,"@"),forward_slash:new _("forward_slash",m.token,"/"),bang:new _("bang",m.token,"!"),bracket_left:new _("bracket_left",m.token,"["),bracket_right:new _("bracket_right",m.token,"]"),brace_left:new _("brace_left",m.token,"{"),brace_right:new _("brace_right",m.token,"}"),colon:new _("colon",m.token,":"),comma:new _("comma",m.token,","),equal:new _("equal",m.token,"="),equal_equal:new _("equal_equal",m.token,"=="),not_equal:new _("not_equal",m.token,"!="),greater_than:new _("greater_than",m.token,">"),greater_than_equal:new _("greater_than_equal",m.token,">="),shift_right:new _("shift_right",m.token,">>"),less_than:new _("less_than",m.token,"<"),less_than_equal:new _("less_than_equal",m.token,"<="),shift_left:new _("shift_left",m.token,"<<"),modulo:new _("modulo",m.token,"%"),minus:new _("minus",m.token,"-"),minus_minus:new _("minus_minus",m.token,"--"),period:new _("period",m.token,"."),plus:new _("plus",m.token,"+"),plus_plus:new _("plus_plus",m.token,"++"),or:new _("or",m.token,"|"),or_or:new _("or_or",m.token,"||"),paren_left:new _("paren_left",m.token,"("),paren_right:new _("paren_right",m.token,")"),semicolon:new _("semicolon",m.token,";"),star:new _("star",m.token,"*"),tilde:new _("tilde",m.token,"~"),underscore:new _("underscore",m.token,"_"),xor:new _("xor",m.token,"^"),plus_equal:new _("plus_equal",m.token,"+="),minus_equal:new _("minus_equal",m.token,"-="),times_equal:new _("times_equal",m.token,"*="),division_equal:new _("division_equal",m.token,"/="),modulo_equal:new _("modulo_equal",m.token,"%="),and_equal:new _("and_equal",m.token,"&="),or_equal:new _("or_equal",m.token,"|="),xor_equal:new _("xor_equal",m.token,"^="),shift_right_equal:new _("shift_right_equal",m.token,">>="),shift_left_equal:new _("shift_left_equal",m.token,"<<=")},f.simpleTokens={"@":y.tokens.attr,"{":y.tokens.brace_left,"}":y.tokens.brace_right,":":y.tokens.colon,",":y.tokens.comma,"(":y.tokens.paren_left,")":y.tokens.paren_right,";":y.tokens.semicolon},f.literalTokens={"&":y.tokens.and,"&&":y.tokens.and_and,"->":y.tokens.arrow,"/":y.tokens.forward_slash,"!":y.tokens.bang,"[":y.tokens.bracket_left,"]":y.tokens.bracket_right,"=":y.tokens.equal,"==":y.tokens.equal_equal,"!=":y.tokens.not_equal,">":y.tokens.greater_than,">=":y.tokens.greater_than_equal,">>":y.tokens.shift_right,"<":y.tokens.less_than,"<=":y.tokens.less_than_equal,"<<":y.tokens.shift_left,"%":y.tokens.modulo,"-":y.tokens.minus,"--":y.tokens.minus_minus,".":y.tokens.period,"+":y.tokens.plus,"++":y.tokens.plus_plus,"|":y.tokens.or,"||":y.tokens.or_or,"*":y.tokens.star,"~":y.tokens.tilde,_:y.tokens.underscore,"^":y.tokens.xor,"+=":y.tokens.plus_equal,"-=":y.tokens.minus_equal,"*=":y.tokens.times_equal,"/=":y.tokens.division_equal,"%=":y.tokens.modulo_equal,"&=":y.tokens.and_equal,"|=":y.tokens.or_equal,"^=":y.tokens.xor_equal,">>=":y.tokens.shift_right_equal,"<<=":y.tokens.shift_left_equal},f.regexTokens={decimal_float_literal:y.tokens.decimal_float_literal,hex_float_literal:y.tokens.hex_float_literal,int_literal:y.tokens.int_literal,uint_literal:y.tokens.uint_literal,ident:y.tokens.ident},f.storage_class=[y.keywords.function,y.keywords.private,y.keywords.workgroup,y.keywords.uniform,y.keywords.storage],f.access_mode=[y.keywords.read,y.keywords.write,y.keywords.read_write],f.sampler_type=[y.keywords.sampler,y.keywords.sampler_comparison],f.sampled_texture_type=[y.keywords.texture_1d,y.keywords.texture_2d,y.keywords.texture_2d_array,y.keywords.texture_3d,y.keywords.texture_cube,y.keywords.texture_cube_array],f.multisampled_texture_type=[y.keywords.texture_multisampled_2d],f.storage_texture_type=[y.keywords.texture_storage_1d,y.keywords.texture_storage_2d,y.keywords.texture_storage_2d_array,y.keywords.texture_storage_3d],f.depth_texture_type=[y.keywords.texture_depth_2d,y.keywords.texture_depth_2d_array,y.keywords.texture_depth_cube,y.keywords.texture_depth_cube_array,y.keywords.texture_depth_multisampled_2d],f.texture_external_type=[y.keywords.texture_external],f.any_texture_type=[...y.sampled_texture_type,...y.multisampled_texture_type,...y.storage_texture_type,...y.depth_texture_type,...y.texture_external_type],f.texel_format=[y.keywords.r8unorm,y.keywords.r8snorm,y.keywords.r8uint,y.keywords.r8sint,y.keywords.r16uint,y.keywords.r16sint,y.keywords.r16float,y.keywords.rg8unorm,y.keywords.rg8snorm,y.keywords.rg8uint,y.keywords.rg8sint,y.keywords.r32uint,y.keywords.r32sint,y.keywords.r32float,y.keywords.rg16uint,y.keywords.rg16sint,y.keywords.rg16float,y.keywords.rgba8unorm,y.keywords.rgba8unorm_srgb,y.keywords.rgba8snorm,y.keywords.rgba8uint,y.keywords.rgba8sint,y.keywords.bgra8unorm,y.keywords.bgra8unorm_srgb,y.keywords.rgb10a2unorm,y.keywords.rg11b10float,y.keywords.rg32uint,y.keywords.rg32sint,y.keywords.rg32float,y.keywords.rgba16uint,y.keywords.rgba16sint,y.keywords.rgba16float,y.keywords.rgba32uint,y.keywords.rgba32sint,y.keywords.rgba32float],f.const_literal=[y.tokens.int_literal,y.tokens.uint_literal,y.tokens.decimal_float_literal,y.tokens.hex_float_literal,y.keywords.true,y.keywords.false],f.literal_or_ident=[y.tokens.ident,y.tokens.int_literal,y.tokens.uint_literal,y.tokens.decimal_float_literal,y.tokens.hex_float_literal,y.tokens.name],f.element_count_expression=[y.tokens.int_literal,y.tokens.uint_literal,y.tokens.ident],f.template_types=[y.keywords.vec2,y.keywords.vec3,y.keywords.vec4,y.keywords.mat2x2,y.keywords.mat2x3,y.keywords.mat2x4,y.keywords.mat3x2,y.keywords.mat3x3,y.keywords.mat3x4,y.keywords.mat4x2,y.keywords.mat4x3,y.keywords.mat4x4,y.keywords.atomic,y.keywords.bitcast,...y.any_texture_type],f.attribute_name=[y.tokens.ident,y.keywords.block,y.keywords.diagnostic],f.assignment_operators=[y.tokens.equal,y.tokens.plus_equal,y.tokens.minus_equal,y.tokens.times_equal,y.tokens.division_equal,y.tokens.modulo_equal,y.tokens.and_equal,y.tokens.or_equal,y.tokens.xor_equal,y.tokens.shift_right_equal,y.tokens.shift_left_equal],f.increment_operators=[y.tokens.plus_plus,y.tokens.minus_minus];class lt{constructor(e,t,n,s,r){this.type=e,this.lexeme=t,this.line=n,this.start=s,this.end=r}toString(){return this.lexeme}isTemplateType(){return f.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==f.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}}class vn{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 lt(f.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
2
+ `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
3
+ `;){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==`
4
+ `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}const t=f.simpleTokens[e];if(t)return this._addToken(t),!0;let n=f.none;const s=this._isAlpha(e),r=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(s){const a=f.keywords[e];if(a)return this._addToken(a),!0}if(s||r)return this._addToken(f.tokens.ident),!0;for(;;){let a=this._findType(e);const i=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(i=="=")return this._current++,e+=i,this._addToken(f.tokens.minus_equal),!0;if(i=="-")return this._current++,e+=i,this._addToken(f.tokens.minus_minus),!0;const o=this._tokens.length-1;if((f.literal_or_ident.indexOf(this._tokens[o].type)!=-1||this._tokens[o].type==f.tokens.paren_right)&&i!=">")return this._addToken(a),!0}if(e==">"&&(i==">"||i=="=")){let o=!1,c=this._tokens.length-1;for(let u=0;u<5&&c>=0&&f.assignment_operators.indexOf(this._tokens[c].type)===-1;++u,--c)if(this._tokens[c].type===f.tokens.less_than){c>0&&this._tokens[c-1].isArrayOrTemplateType()&&(o=!0);break}if(o)return this._addToken(a),!0}if(a===f.none){let o=e,c=0;const u=2;for(let h=0;h<u;++h)if(o+=this._peekAhead(h),a=this._findType(o),a!==f.none){c=h;break}if(a===f.none)return n!==f.none&&(this._current--,this._addToken(n),!0);e=o,this._current+=c+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==f.none&&(this._addToken(n),!0)}_findType(e){for(const n in f.regexTokens){const s=f.regexTokens[n];if(this._match(e,s.rule))return s}return f.literalTokens[e]||f.none}_match(e,t){const 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!==`
5
+ `&&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){const t=this._source.substring(this._start,this._current);this._tokens.push(new lt(e,t,this._line,this._start,this._current))}}function w(l){return Array.isArray(l)||l?.buffer instanceof ArrayBuffer}const Oe=new Float32Array(1),wn=new Uint32Array(Oe.buffer),kn=new Uint32Array(Oe.buffer),$e=new Int32Array(1),In=new Float32Array($e.buffer),Tn=new Uint32Array($e.buffer),Ne=new Uint32Array(1),An=new Float32Array(Ne.buffer),Sn=new Int32Array(Ne.buffer);function ft(l,e,t){if(e===t)return l;if(e==="f32"){if(t==="i32"||t==="x32")return Oe[0]=l,wn[0];if(t==="u32")return Oe[0]=l,kn[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return $e[0]=l,In[0];if(t==="u32")return $e[0]=l,Tn[0]}else if(e==="u32"){if(t==="f32")return Ne[0]=l,An[0];if(t==="i32"||t==="x32")return Ne[0]=l,Sn[0]}return console.error(`Unsupported cast from ${e} to ${t}`),l}class En{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}}class ve{constructor(e,t){this.align=e,this.size=t}}class Y{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(const t of e)t instanceof _e&&this._functions.set(t.name,new En(t));for(const t of e)if(t instanceof Q){const n=this.getTypeInfo(t,null);n instanceof se&&this.structs.push(n)}for(const t of e)if(t instanceof je)this.aliases.push(this._getAliasInfo(t));else{if(t instanceof He){const n=t,s=this._getAttributeNum(n.attributes,"id",0),r=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new on(n.name,r,n.attributes,s));continue}if(this._isUniformVar(t)){const n=t,s=this._getAttributeNum(n.attributes,"group",0),r=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new be(n.name,a,s,r,n.attributes,te.Uniform,n.access);i.access||(i.access="read"),this.uniforms.push(i);continue}if(this._isStorageVar(t)){const n=t,s=this._getAttributeNum(n.attributes,"group",0),r=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),o=new be(n.name,a,s,r,n.attributes,i?te.StorageTexture:te.Storage,n.access);o.access||(o.access="read"),this.storage.push(o);continue}if(this._isTextureVar(t)){const n=t,s=this._getAttributeNum(n.attributes,"group",0),r=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=this._isStorageTexture(a),o=new be(n.name,a,s,r,n.attributes,i?te.StorageTexture:te.Texture,n.access);o.access||(o.access="read"),i?this.storage.push(o):this.textures.push(o);continue}if(this._isSamplerVar(t)){const n=t,s=this._getAttributeNum(n.attributes,"group",0),r=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),i=new be(n.name,a,s,r,n.attributes,te.Sampler,n.access);this.samplers.push(i);continue}}for(const t of e)if(t instanceof _e){const n=this._getAttribute(t,"vertex"),s=this._getAttribute(t,"fragment"),r=this._getAttribute(t,"compute"),a=n||s||r,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 un(o.name,this.getTypeInfo(o.type,o.attributes),o.attributes)),i.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null;continue}for(const t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(const t of this._functions.values())t.node.search(n=>{var s,r,a;if(n instanceof Pt){if(n.value)if(w(n.value))for(const i of n.value)for(const o of this.overrides)i===o.name&&((s=t.info)===null||s===void 0||s.overrides.push(o));else for(const i of this.overrides)n.value===i.name&&((r=t.info)===null||r===void 0||r.overrides.push(i))}else if(n instanceof H)for(const i of this.overrides)n.name===i.name&&((a=t.info)===null||a===void 0||a.overrides.push(i))});for(const t of this.uniforms)this._markStructsInUse(t.type);for(const t of this.storage)this._markStructsInUse(t.type)}getFunctionInfo(e){for(const t of this.functions)if(t.name==e)return t;return null}getStructInfo(e){for(const t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(const 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(const 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{const t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(const s of e.calls){const r=(n=this._functions.get(s.name))===null||n===void 0?void 0:n.info;r&&t.add(r)}}findResource(e,t,n){if(n){for(const s of this.entry.compute)if(s.name===n){for(const r of s.resources)if(r.group==e&&r.binding==t)return r}for(const s of this.entry.vertex)if(s.name===n){for(const r of s.resources)if(r.group==e&&r.binding==t)return r}for(const s of this.entry.fragment)if(s.name===n){for(const r of s.resources)if(r.group==e&&r.binding==t)return r}}for(const s of this.uniforms)if(s.group==e&&s.binding==t)return s;for(const s of this.storage)if(s.group==e&&s.binding==t)return s;for(const s of this.textures)if(s.group==e&&s.binding==t)return s;for(const s of this.samplers)if(s.group==e&&s.binding==t)return s;return null}_findResource(e){for(const t of this.uniforms)if(t.name==e)return t;for(const t of this.storage)if(t.name==e)return t;for(const t of this.textures)if(t.name==e)return t;for(const t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){const t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){const n=[],s=this,r=[];return e.search(a=>{if(a instanceof Ee)r.push({});else if(a instanceof Le)r.pop();else if(a instanceof ee){const i=a;t&&i.type!==null&&this._markStructsFromAST(i.type),r.length>0&&(r[r.length-1][i.name]=i)}else if(a instanceof Z){const i=a;t&&i.type!==null&&this._markStructsFromAST(i.type)}else if(a instanceof de){const i=a;t&&i.type!==null&&this._markStructsFromAST(i.type),r.length>0&&(r[r.length-1][i.name]=i)}else if(a instanceof H){const i=a;if(r.length>0&&r[r.length-1][i.name])return;const o=s._findResource(i.name);o&&n.push(o)}else if(a instanceof Ge){const i=a,o=s._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),o.resources===null&&(o.resources=s._findResources(o.node,t)),n.push(...o.resources))}else if(a instanceof ze){const i=a,o=s._functions.get(i.name);o&&(t&&(o.inUse=!0),e.calls.add(o.node),o.resources===null&&(o.resources=s._findResources(o.node,t)),n.push(...o.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){const e=[];function t(n,s){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),s>=e[n].length&&(e[n].length=s+1)}for(const n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(const n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(const 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 Q)this._getStructOutputs(e,t);else{const n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(const n of e.members)if(n.type instanceof Q)this._getStructOutputs(n.type,t);else{const s=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(s!==null){const r=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(s.value),i=new it(n.name,r,s.name,a);t.push(i)}}}_getOutputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const n=this.getTypeInfo(e,e.attributes),s=this._parseInt(t.value);return new it("",n,t.name,s)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(const n of e)if(n.type instanceof Q)this._getStructInputs(n.type,t);else{const s=this._getInputInfo(n);s!==null&&t.push(s)}return t}_getStructInputs(e,t){for(const n of e.members)if(n.type instanceof Q)this._getStructInputs(n.type,t);else{const s=this._getInputInfo(n);s!==null&&t.push(s)}}_getInputInfo(e){const t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){const n=this._getAttribute(e,"interpolation"),s=this.getTypeInfo(e.type,e.attributes),r=this._parseInt(t.value),a=new an(e.name,s,t.name,r);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]);const t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(const t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new rn(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(const t of this.structs)if(t.name==e)return t;for(const 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 Ie){const s=e.type?this.getTypeInfo(e.type,e.attributes):null,r=new Ue(e.name,s,t);return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof pe){const s=e,r=s.format?this.getTypeInfo(s.format,s.attributes):null,a=new re(s.name,t);return a.format=r,a.count=s.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof Q){const s=e,r=new se(s.name,t);r.startLine=s.startLine,r.endLine=s.endLine;for(const a of s.members){const i=this.getTypeInfo(a.type,a.attributes);r.members.push(new rt(a.name,i,a.attributes))}return this._types.set(e,r),this._updateTypeInfo(r),r}if(e instanceof he){const s=e,r=s.format instanceof b,a=s.format?r?this.getTypeInfo(s.format,null):new z(s.format,null):null,i=new ae(s.name,a,t,s.access);return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof g){const s=e,r=s.format?this.getTypeInfo(s.format,null):null,a=new ae(s.name,r,t,s.access);return this._types.set(e,a),this._updateTypeInfo(a),a}const n=new z(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,s;const r=this._getTypeSize(e);if(e.size=(t=r?.size)!==null&&t!==void 0?t:0,e instanceof re&&e.format){const a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(s=a?.align)!==null&&s!==void 0?s:0),this._updateTypeInfo(e.format)}e instanceof Ue&&this._updateTypeInfo(e.format),e instanceof se&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,s=0,r=0,a=0;for(let i=0,o=e.members.length;i<o;++i){const c=e.members[i],u=this._getTypeSize(c);if(!u)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;const h=u.align,x=u.size;n=this._roundUp(h,n+s),s=x,r=n,a=Math.max(a,h),c.offset=n,c.size=x,this._updateTypeInfo(c.type)}e.size=this._roundUp(a,r+s),e.align=a}_getTypeSize(e){var t,n;if(e==null)return null;const s=this._getAttributeNum(e.attributes,"size",0),r=this._getAttributeNum(e.attributes,"align",0);if(e instanceof rt&&(e=e.type),e instanceof z){const a=this._getAlias(e.name);a!==null&&(e=a)}{const a=Y._typeInfo[e.name];if(a!==void 0){const i=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new ve(Math.max(r,a.align/i),Math.max(s,a.size/i))}}{const a=Y._typeInfo[e.name.substring(0,e.name.length-1)];if(a){const i=e.name[e.name.length-1]==="h"?2:1;return new ve(Math.max(r,a.align/i),Math.max(s,a.size/i))}}if(e instanceof re){let a=e,i=8,o=8;const c=this._getTypeSize(a.format);return c!==null&&(o=c.size,i=c.align),o=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(i,o)),s&&(o=s),new ve(Math.max(r,i),Math.max(s,o))}if(e instanceof se){let a=0,i=0,o=0,c=0,u=0;for(const h of e.members){const x=this._getTypeSize(h.type);x!==null&&(a=Math.max(x.align,a),o=this._roundUp(x.align,o+c),c=x.size,u=o)}return i=this._roundUp(a,u+c),new ve(Math.max(r,a),Math.max(s,i))}return null}_isUniformVar(e){return e instanceof ee&&e.storage=="uniform"}_isStorageVar(e){return e instanceof ee&&e.storage=="storage"}_isTextureVar(e){return e instanceof ee&&e.type!==null&&Y._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ee&&e.type!==null&&Y._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){const n=e;if(!n||!n.attributes)return null;const s=n.attributes;for(let r of s)if(r.name==t)return r;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let s of e)if(s.name==t){let r=s!==null&&s.value!==null?s.value:n;return r instanceof Array&&(r=r[0]),typeof r=="number"?r:typeof r=="string"?parseInt(r):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}}Y._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}},Y._textureTypes=f.any_texture_type.map(l=>l.name),Y._samplerTypes=f.sampler_type.map(l=>l.name);let Xe=0;class Ke{constructor(e,t,n){this.id=Xe++,this.name=e,this.value=t,this.node=n}clone(){return new Ke(this.name,this.value,this.node)}}class Ze{constructor(e){this.id=Xe++,this.name=e.name,this.node=e}clone(){return new Ze(this.node)}}class Ye{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",this.id=Xe++,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 Ke(e,t,n??null))}setVariable(e,t,n){const s=this.getVariable(e);s!==null?s.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;const n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new Ye(this)}}class Ln{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}}class On{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){const n=this.exec.evalExpression(e.args[0],t);let s=!0;if(n instanceof d)return n.data.forEach(r=>{r||(s=!1)}),new p(s?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d){const s=n.data.some(r=>r);return new p(s?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){const 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 F&&(n=n.right);const s=this.exec.evalExpression(n,t);if(s instanceof B&&s.typeInfo.size===0){const r=s.typeInfo,a=s.buffer.byteLength/r.stride;return new p(a,this.getTypeInfo("u32"))}return new p(s.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.abs(r)),n.typeInfo);const s=n;return new p(Math.abs(s.value),s.typeInfo)}Acos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.acos(r)),n.typeInfo);const s=n;return new p(Math.acos(s.value),n.typeInfo)}Acosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.acosh(r)),n.typeInfo);const s=n;return new p(Math.acosh(s.value),n.typeInfo)}Asin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.asin(r)),n.typeInfo);const s=n;return new p(Math.asin(s.value),n.typeInfo)}Asinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.asinh(r)),n.typeInfo);const s=n;return new p(Math.asinh(s.value),n.typeInfo)}Atan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.atan(r)),n.typeInfo);const s=n;return new p(Math.atan(s.value),n.typeInfo)}Atanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.atanh(r)),n.typeInfo);const s=n;return new p(Math.atanh(s.value),n.typeInfo)}Atan2(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d)return new d(n.data.map((i,o)=>Math.atan2(i,s.data[o])),n.typeInfo);const r=n,a=s;return new p(Math.atan2(r.value,a.value),n.typeInfo)}Ceil(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.ceil(r)),n.typeInfo);const s=n;return new p(Math.ceil(s.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof d&&s instanceof d&&r instanceof d)return new d(n.data.map((c,u)=>this._clamp(c,s.data[u],r.data[u])),n.typeInfo);const a=n,i=s,o=r;return new p(this._clamp(a.value,i.value,o.value),n.typeInfo)}Cos(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.cos(r)),n.typeInfo);const s=n;return new p(Math.cos(s.value),n.typeInfo)}Cosh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.cosh(r)),n.typeInfo);const s=n;return new p(Math.cos(s.value),n.typeInfo)}CountLeadingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.clz32(r)),n.typeInfo);const s=n;return new p(Math.clz32(s.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>this._countOneBits(r)),n.typeInfo);const s=n;return new p(this._countOneBits(s.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>this._countTrailingZeros(r)),n.typeInfo);const s=n;return new p(this._countTrailingZeros(s.value),n.typeInfo)}Cross(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d){if(n.data.length!==3||s.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;const r=n.data,a=s.data;return new d([r[1]*a[2]-a[1]*r[2],r[2]*a[0]-a[2]*r[0],r[0]*a[1]-a[0]*r[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){const n=this.exec.evalExpression(e.args[0],t),s=180/Math.PI;return n instanceof d?new d(n.data.map(r=>r*s),n.typeInfo):new p(n.value*s,this.getTypeInfo("f32"))}Determinant(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof T){const s=n.data,r=n.typeInfo.getTypeName(),a=r.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h")return new p(s[0]*s[3]-s[1]*s[2],a);if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h")return new p(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);if(r==="mat2x4"||r==="mat2x4f"||r==="mat2x4h")console.error(`TODO: Determinant for ${r}`);else if(r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h")console.error(`TODO: Determinant for ${r}`);else{if(r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h")return new p(s[0]*(s[4]*s[8]-s[5]*s[7])-s[1]*(s[3]*s[8]-s[5]*s[6])+s[2]*(s[3]*s[7]-s[4]*s[6]),a);r==="mat3x4"||r==="mat3x4f"||r==="mat3x4h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h"?console.error(`TODO: Determinant for ${r}`):r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h"||console.error(`TODO: Determinant for ${r}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d){let i=0;for(let o=0;o<n.data.length;++o)i+=(n.data[o]-s.data[o])*(n.data[o]-s.data[o]);return new p(Math.sqrt(i),this.getTypeInfo("f32"))}const r=n,a=s;return new p(Math.abs(r.value-a.value),n.typeInfo)}_dot(e,t){let n=0;for(let s=0;s<e.length;++s)n+=t[s]*e[s];return n}Dot(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);return n instanceof d&&s instanceof d?new p(this._dot(n.data,s.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){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.exp(r)),n.typeInfo);const s=n;return new p(Math.exp(s.value),n.typeInfo)}Exp2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.pow(2,r)),n.typeInfo);const s=n;return new p(Math.pow(2,s.value),n.typeInfo)}ExtractBits(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;const a=s.value,i=r.value;if(n instanceof d)return new d(n.data.map(c=>c>>a&(1<<i)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;const o=n.value;return new p(o>>a&(1<<i)-1,this.getTypeInfo("i32"))}FaceForward(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof d&&s instanceof d&&r instanceof d){const a=this._dot(s.data,r.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){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>this._firstLeadingBit(r)),n.typeInfo);const s=n;return new p(this._firstLeadingBit(s.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>this._firstTrailingBit(r)),n.typeInfo);const s=n;return new p(this._firstTrailingBit(s.value),n.typeInfo)}Floor(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.floor(r)),n.typeInfo);const s=n;return new p(Math.floor(s.value),n.typeInfo)}Fma(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof d&&s instanceof d&&r instanceof d)return n.data.length!==s.data.length||n.data.length!==r.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new d(n.data.map((c,u)=>c*s.data[u]+r.data[u]),n.typeInfo);const a=n,i=s,o=r;return new p(a.value*i.value+o.value,a.typeInfo)}Fract(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>r-Math.floor(r)),n.typeInfo);const s=n;return new p(s.value-Math.floor(s.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t),a=this.exec.evalExpression(e.args[3],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;const i=r.value,o=(1<<a.value)-1<<i,c=~o;if(n instanceof d&&s instanceof d)return new d(n.data.map((x,v)=>x&c|s.data[v]<<i&o),n.typeInfo);const u=n.value,h=s.value;return new p(u&c|h<<i&o,n.typeInfo)}InverseSqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>1/Math.sqrt(r)),n.typeInfo);const s=n;return new p(1/Math.sqrt(s.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d){let r=0;return n.data.forEach(a=>{r+=a*a}),new p(Math.sqrt(r),this.getTypeInfo("f32"))}const s=n;return new p(Math.abs(s.value),n.typeInfo)}Log(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.log(r)),n.typeInfo);const s=n;return new p(Math.log(s.value),n.typeInfo)}Log2(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.log2(r)),n.typeInfo);const s=n;return new p(Math.log2(s.value),n.typeInfo)}Max(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d)return new d(n.data.map((i,o)=>Math.max(i,s.data[o])),n.typeInfo);const r=n,a=s;return new p(Math.max(r.value,a.value),n.typeInfo)}Min(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d)return new d(n.data.map((i,o)=>Math.min(i,s.data[o])),n.typeInfo);const r=n,a=s;return new p(Math.min(r.value,a.value),n.typeInfo)}Mix(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof d&&s instanceof d&&r instanceof d)return new d(n.data.map((o,c)=>n.data[c]*(1-r.data[c])+s.data[c]*r.data[c]),n.typeInfo);const a=s,i=r;return new p(n.value*(1-i.value)+a.value*i.value,n.typeInfo)}Modf(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d)return new d(n.data.map((a,i)=>a%s.data[i]),n.typeInfo);const r=s;return new p(n.value%r.value,n.typeInfo)}Normalize(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d){const s=this.Length(e,t).value;return new d(n.data.map(r=>r/s),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d)return new d(n.data.map((i,o)=>Math.pow(i,s.data[o])),n.typeInfo);const r=n,a=s;return new p(Math.pow(r.value,a.value),n.typeInfo)}QuantizeToF16(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof d?new d(n.data.map(s=>s),n.typeInfo):new p(n.value,n.typeInfo)}Radians(e,t){const n=this.exec.evalExpression(e.args[0],t);return n instanceof d?new d(n.data.map(s=>s*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),s=this.exec.evalExpression(e.args[1],t);if(n instanceof d&&s instanceof d){const r=this._dot(n.data,s.data);return new d(n.data.map((a,i)=>a-2*r*s.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),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(n instanceof d&&s instanceof d&&r instanceof p){const a=this._dot(s.data,n.data);return new d(n.data.map((i,o)=>{const c=1-r.value*r.value*(1-a*a);if(c<0)return 0;const u=Math.sqrt(c);return r.value*i-(r.value*a+u)*s.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){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.round(r)),n.typeInfo);const s=n;return new p(Math.round(s.value),n.typeInfo)}Saturate(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.min(Math.max(r,0),1)),n.typeInfo);const s=n;return new p(Math.min(Math.max(s.value,0),1),n.typeInfo)}Sign(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.sign(r)),n.typeInfo);const s=n;return new p(Math.sign(s.value),n.typeInfo)}Sin(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.sin(r)),n.typeInfo);const s=n;return new p(Math.sin(s.value),n.typeInfo)}Sinh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.sinh(r)),n.typeInfo);const s=n;return new p(Math.sinh(s.value),n.typeInfo)}_smoothstep(e,t,n){const s=Math.min(Math.max((n-e)/(t-e),0),1);return s*s*(3-2*s)}SmoothStep(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t),r=this.exec.evalExpression(e.args[2],t);if(r instanceof d&&n instanceof d&&s instanceof d)return new d(r.data.map((c,u)=>this._smoothstep(n.data[u],s.data[u],c)),r.typeInfo);const a=n,i=s,o=r;return new p(this._smoothstep(a.value,i.value,o.value),r.typeInfo)}Sqrt(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.sqrt(r)),n.typeInfo);const s=n;return new p(Math.sqrt(s.value),n.typeInfo)}Step(e,t){const n=this.exec.evalExpression(e.args[0],t),s=this.exec.evalExpression(e.args[1],t);if(s instanceof d&&n instanceof d)return new d(s.data.map((a,i)=>a<n.data[i]?0:1),s.typeInfo);const r=n;return new p(s.value<r.value?0:1,r.typeInfo)}Tan(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.tan(r)),n.typeInfo);const s=n;return new p(Math.tan(s.value),n.typeInfo)}Tanh(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.tanh(r)),n.typeInfo);const s=n;return new p(Math.tanh(s.value),n.typeInfo)}_getTransposeType(e){const 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){const n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof T))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;const s=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){const r=n.data;return new T([r[0],r[2],r[1],r[3]],s)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){const r=n.data;return new T([r[0],r[3],r[6],r[1],r[4],r[7]],s)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){const r=n.data;return new T([r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13]],s)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){const r=n.data;return new T([r[0],r[3],r[1],r[4],r[2],r[5]],s)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){const r=n.data;return new T([r[0],r[3],r[6],r[1],r[4],r[7],r[2],r[5],r[8]],s)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){const r=n.data;return new T([r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14]],s)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){const r=n.data;return new T([r[0],r[4],r[1],r[5],r[2],r[6]],s)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){const r=n.data;return new T([r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]],s)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){const r=n.data;return new T([r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14],r[3],r[7],r[11],r[15]],s)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){const n=this.exec.evalExpression(e.args[0],t);if(n instanceof d)return new d(n.data.map(r=>Math.trunc(r)),n.typeInfo);const s=n;return new p(Math.trunc(s.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){const n=e.args[0],s=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof H){const r=n.name,a=t.getVariableValue(r);if(a instanceof J){if(s<0||s>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;const i=a.getMipLevelSize(s),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 ${r} 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){const n=e.args[0],s=this.exec.evalExpression(e.args[1],t),r=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(s instanceof d)||s.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof H){const a=n.name,i=t.getVariableValue(a);if(i instanceof J){const o=Math.floor(s.data[0]),c=Math.floor(s.data[1]);if(o<0||o>=i.width||c<0||c>=i.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;const u=i.getPixel(o,c,0,r);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new d(u,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){const n=e.args[0];if(n instanceof H){const s=n.name,r=t.getVariableValue(s);return r instanceof J?new p(r.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){const n=e.args[0];if(n instanceof H){const s=n.name,r=t.getVariableValue(s);return r instanceof J?new p(r.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){const n=e.args[0];if(n instanceof H){const s=n.name,r=t.getVariableValue(s);return r instanceof J?new p(r.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${s} 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){const n=e.args[0],s=this.exec.evalExpression(e.args[1],t),r=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(!(s instanceof d)||s.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof H){const i=n.name,o=t.getVariableValue(i);if(o instanceof J){const c=o.getMipLevelSize(0),u=Math.floor(s.data[0]),h=Math.floor(s.data[1]);return u<0||u>=c[0]||h<0||h>=c[1]?(console.error(`Texture ${i} out of bounds. Line ${e.line}`),null):(o.setPixel(u,h,0,r,Array.from(a)),null)}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t);return t.getVariable(s).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t);return o instanceof p&&i instanceof p&&(o.value=i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value+=i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value-=i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=Math.max(o.value,i.value)),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=Math.min(o.value,i.value)),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value&i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value|i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=o.value^i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof F&&(n=n.right);const s=this.exec.getVariableName(n,t),r=t.getVariable(s);let a=e.args[1];const i=this.exec.evalExpression(a,t),o=r.value.getSubData(this.exec,n.postfix,t),c=new p(o.value,o.typeInfo);return o instanceof p&&i instanceof p&&(o.value=i.value),r.value instanceof B&&r.value.setDataValue(this.exec,o,n.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}}const Fe={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},W={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]};class U extends Ln{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new Y,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new Ye,this.builtins=new On(this),this.typeInfo={bool:this.getTypeInfo(b.bool),i32:this.getTypeInfo(b.i32),u32:this.getTypeInfo(b.u32),f32:this.getTypeInfo(b.f32),f16:this.getTypeInfo(b.f16),vec2f:this.getTypeInfo(g.vec2f),vec2u:this.getTypeInfo(g.vec2u),vec2i:this.getTypeInfo(g.vec2i),vec2h:this.getTypeInfo(g.vec2h),vec3f:this.getTypeInfo(g.vec3f),vec3u:this.getTypeInfo(g.vec3u),vec3i:this.getTypeInfo(g.vec3i),vec3h:this.getTypeInfo(g.vec3h),vec4f:this.getTypeInfo(g.vec4f),vec4u:this.getTypeInfo(g.vec4u),vec4i:this.getTypeInfo(g.vec4i),vec4h:this.getTypeInfo(g.vec4h),mat2x2f:this.getTypeInfo(g.mat2x2f),mat2x3f:this.getTypeInfo(g.mat2x3f),mat2x4f:this.getTypeInfo(g.mat2x4f),mat3x2f:this.getTypeInfo(g.mat3x2f),mat3x3f:this.getTypeInfo(g.mat3x3f),mat3x4f:this.getTypeInfo(g.mat3x4f),mat4x2f:this.getTypeInfo(g.mat4x2f),mat4x3f:this.getTypeInfo(g.mat4x3f),mat4x4f:this.getTypeInfo(g.mat4x4f)}}getVariableValue(e){var t,n;const s=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(s===null)return null;if(s instanceof p)return s.value;if(s instanceof d||s instanceof T)return Array.from(s.data);if(s instanceof B&&s.typeInfo instanceof re){if(s.typeInfo.format.name==="u32")return Array.from(new Uint32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="i32")return Array.from(new Int32Array(s.buffer,s.offset,s.typeInfo.count));if(s.typeInfo.format.name==="f32")return Array.from(new Float32Array(s.buffer,s.offset,s.typeInfo.count))}return console.error(`Unsupported return variable type ${s.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,s){const r=this.context.clone();(s=s??{}).constants&&this._setOverrides(s.constants,r),this._execStatements(this.ast,r);const a=r.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]])}const i=t[0],o=t[1],c=t[2],u=this.getTypeInfo("vec3u");r.setVariable("@num_workgroups",new d(t,u));const h=this.reflection.getFunctionInfo(e);h===null&&console.error(`Function ${e} not found in reflection data`);for(const x in n)for(const v in n[x]){const k=n[x][v];r.variables.forEach($=>{var E;const D=$.node;if(D?.attributes){let R=null,A=null;for(const I of D.attributes)I.name==="binding"?R=I.value:I.name==="group"&&(A=I.value);if(v==R&&x==A){let I=!1;for(const M of h.resources)if(M.name===$.name&&M.group===parseInt(x)&&M.binding===parseInt(v)){I=!0;break}if(I)if(k.texture!==void 0&&k.descriptor!==void 0){const M=new J(k.texture,this.getTypeInfo(D.type),k.descriptor,(E=k.texture.view)!==null&&E!==void 0?E:null);$.value=M}else k.uniform!==void 0?$.value=new B(k.uniform,this.getTypeInfo(D.type)):$.value=new B(k,this.getTypeInfo(D.type))}}})}for(let x=0;x<c;++x)for(let v=0;v<o;++v)for(let k=0;k<i;++k)r.setVariable("@workgroup_id",new d([k,v,x],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[k,v,x],r)}execStatement(e,t){if(e instanceof At)return this.evalExpression(e.value,t);if(e instanceof Et){if(e.condition){const n=this.evalExpression(e.condition,t);if(!(n instanceof p))throw new Error("Invalid break-if condition");if(!n.value)return null}return U._breakObj}if(e instanceof Lt)return U._continueObj;if(e instanceof de)this._let(e,t);else if(e instanceof ee)this._var(e,t);else if(e instanceof ke)this._const(e,t);else if(e instanceof _e)this._function(e,t);else{if(e instanceof Tt)return this._if(e,t);if(e instanceof It)return this._switch(e,t);if(e instanceof bt)return this._for(e,t);if(e instanceof xt)return this._while(e,t);if(e instanceof kt)return this._loop(e,t);if(e instanceof Me){const n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof wt)this._assign(e,t);else if(e instanceof vt)this._increment(e,t);else{if(e instanceof Q)return null;if(e instanceof He){const n=e.name;t.getVariable(n)===null&&t.setVariable(n,new p(0,this.getTypeInfo("u32")))}else if(e instanceof ze)this._call(e,t);else{if(e instanceof St||e instanceof je)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof X?this._evalBinaryOp(e,t):e instanceof P?this._evalLiteral(e,t):e instanceof H?this._evalVariable(e,t):e instanceof Ge?this._evalCall(e,t):e instanceof Z?this._evalCreate(e,t):e instanceof Ot?this._evalConst(e,t):e instanceof $t?this._evalBitcast(e,t):e instanceof F?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof b){const s=this.reflection.getTypeInfo(e);if(s!==null)return s}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(const n in e){const s=e[n],r=this.reflection.getOverrideInfo(n);r!==null?(r.type===null&&(r.type=this.getTypeInfo("u32")),r.type.name==="u32"||r.type.name==="i32"||r.type.name==="f32"||r.type.name==="f16"?t.setVariable(n,new p(s,r.type)):r.type.name==="bool"?t.setVariable(n,new p(s?1:0,r.type)):r.type.name==="vec2"||r.type.name==="vec3"||r.type.name==="vec4"||r.type.name==="vec2f"||r.type.name==="vec3f"||r.type.name==="vec4f"||r.type.name==="vec2i"||r.type.name==="vec3i"||r.type.name==="vec4i"||r.type.name==="vec2u"||r.type.name==="vec3u"||r.type.name==="vec4u"||r.type.name==="vec2h"||r.type.name==="vec3h"||r.type.name==="vec4h"?t.setVariable(n,new d(s,r.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){const s=[1,1,1];for(const u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){const h=n.getVariableValue(u.value[0]);s[0]=h instanceof p?h.value:parseInt(u.value[0])}if(u.value.length>1){const h=n.getVariableValue(u.value[1]);s[1]=h instanceof p?h.value:parseInt(u.value[1])}if(u.value.length>2){const h=n.getVariableValue(u.value[2]);s[2]=h instanceof p?h.value:parseInt(u.value[2])}}const r=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new d(s,r));const i=s[0],o=s[1],c=s[2];for(let u=0,h=0;u<c;++u)for(let x=0;x<o;++x)for(let v=0;v<i;++v,++h){const k=[v,x,u],$=[v+t[0]*s[0],x+t[1]*s[1],u+t[2]*s[2]];n.setVariable("@local_invocation_id",new d(k,r)),n.setVariable("@global_invocation_id",new d($,r)),n.setVariable("@local_invocation_index",new p(h,a)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(const n of e.node.args)for(const s of n.attributes)if(s.name==="builtin"){const r=`@${s.value}`,a=t.getVariable(r);a!==void 0&&t.variables.set(n.name,a)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof F;)e=e.right;return e instanceof H?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(const n of e){if(n instanceof Array){const r=t.clone(),a=this._execStatements(n,r);if(a)return a;continue}const s=this.execStatement(n,t);if(s)return s}return null}_call(e,t){const n=t.clone();n.currentFunctionName=e.name;const s=t.getFunction(e.name);if(s){for(let r=0;r<s.node.args.length;++r){const a=s.node.args[r],i=this.evalExpression(e.args[r],n);n.setVariable(a.name,i,a)}this._execStatements(s.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){const n=this.getVariableName(e.variable,t),s=t.getVariable(n);s?e.operator==="++"?s.value instanceof p?s.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?s.value instanceof p?s.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){const n=this.getVariableName(e,t),s=t.getVariable(n);return s===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):s.value.getSubData(this,e.postfix,t)}if(e instanceof F){if(e.operator==="*"){const n=this._getVariableData(e.right,t);return n instanceof ue?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){const n=this._getVariableData(e.right,t);return new ue(n)}}return null}_assign(e,t){let n=null,s="<var>",r=null;if(e.variable instanceof F){const o=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(o instanceof p||o instanceof d||o instanceof T){if(c instanceof p||c instanceof d||c instanceof T&&o.data.length===c.data.length)return void o.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(o instanceof B&&c instanceof B&&o.buffer.byteLength-o.offset>=c.buffer.byteLength-c.offset)return void(o.buffer.byteLength%4==0?new Uint32Array(o.buffer,o.offset,o.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(o.buffer,o.offset,o.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return o instanceof p||o instanceof d||o instanceof T?c instanceof p||c instanceof d||c instanceof T?void o.data.set(c.data.map((h,x)=>o.data[x]+h)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(o instanceof p||o instanceof d||o instanceof T)&&(c instanceof p||c instanceof d||c instanceof T)?void o.data.set(c.data.map((h,x)=>o.data[x]-h)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof F){if(e.variable.operator==="*"){s=this.getVariableName(e.variable.right,t);const o=t.getVariable(s);if(!(o&&o.value instanceof ue))return void console.error(`Variable ${s} is not a pointer. Line ${e.line}`);n=o.value.reference;let c=e.variable.postfix;if(!c){let u=e.variable.right;for(;u instanceof F;){if(u.postfix){c=u.postfix;break}u=u.right}}c&&(n=n.getSubData(this,c,t))}}else{r=e.variable.postfix,s=this.getVariableName(e.variable,t);const o=t.getVariable(s);if(o===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);n=o.value}if(n instanceof ue&&(n=n.reference),n===null)return void console.error(`Variable ${s} not found. Line ${e.line}`);const a=this.evalExpression(e.value,t),i=e.operator;if(i!=="="){const o=n.getSubData(this,r,t);if(o instanceof d&&a instanceof p){const c=o.data,u=a.value;if(i==="+=")for(let h=0;h<c.length;++h)c[h]+=u;else if(i==="-=")for(let h=0;h<c.length;++h)c[h]-=u;else if(i==="*=")for(let h=0;h<c.length;++h)c[h]*=u;else if(i==="/=")for(let h=0;h<c.length;++h)c[h]/=u;else if(i==="%=")for(let h=0;h<c.length;++h)c[h]%=u;else if(i==="&=")for(let h=0;h<c.length;++h)c[h]&=u;else if(i==="|=")for(let h=0;h<c.length;++h)c[h]|=u;else if(i==="^=")for(let h=0;h<c.length;++h)c[h]^=u;else if(i==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u;else if(i===">>=")for(let h=0;h<c.length;++h)c[h]>>=u;else console.error(`Invalid operator ${i}. Line ${e.line}`)}else if(o instanceof d&&a instanceof d){const c=o.data,u=a.data;if(c.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(i==="+=")for(let h=0;h<c.length;++h)c[h]+=u[h];else if(i==="-=")for(let h=0;h<c.length;++h)c[h]-=u[h];else if(i==="*=")for(let h=0;h<c.length;++h)c[h]*=u[h];else if(i==="/=")for(let h=0;h<c.length;++h)c[h]/=u[h];else if(i==="%=")for(let h=0;h<c.length;++h)c[h]%=u[h];else if(i==="&=")for(let h=0;h<c.length;++h)c[h]&=u[h];else if(i==="|=")for(let h=0;h<c.length;++h)c[h]|=u[h];else if(i==="^=")for(let h=0;h<c.length;++h)c[h]^=u[h];else if(i==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u[h];else if(i===">>=")for(let h=0;h<c.length;++h)c[h]>>=u[h];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 B&&n.setDataValue(this,o,r,t))}if(n instanceof B)n.setDataValue(this,a,r,t);else if(r){if(!(n instanceof d||n instanceof T))return void console.error(`Variable ${s} is not a vector or matrix. Line ${e.line}`);if(r instanceof le){const o=this.evalExpression(r.index,t).value;if(n instanceof d){if(!(a instanceof p))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[o]=a.value}else{if(!(n instanceof T))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{const c=this.evalExpression(r.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(a instanceof d))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);{const u=n.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(c<2&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(c<2&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(c<2&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(c<3&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(c<3&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(c<3&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(c<4&&a.data.length===2))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[2*c]=a.data[0],n.data[2*c+1]=a.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(c<4&&a.data.length===3))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[3*c]=a.data[0],n.data[3*c+1]=a.data[1],n.data[3*c+2]=a.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(!(c<4&&a.data.length===4))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);n.data[4*c]=a.data[0],n.data[4*c+1]=a.data[1],n.data[4*c+2]=a.data[2],n.data[4*c+3]=a.data[3]}}}}}else if(r instanceof oe){const o=r.value;if(!(n instanceof d))return void console.error(`Invalid assignment to ${o}. Variable ${s} 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 ${s}. 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 ${s}. 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 ${s}. 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 ${s}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof d))return void console.error(`Invalid assignment to ${s}. Line ${e.line}`);if(o.length!==a.data.length)return void console.error(`Invalid assignment to ${o} for variable ${s}. Line ${e.line}`);for(let c=0;c<o.length;++c){const u=o[c];if(u==="x"||u==="r")n.data[0]=a.data[c];else if(u==="y"||u==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[1]=a.data[c]}else if(u==="z"||u==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[2]=a.data[c]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${s}. Line ${e.line}`);n.data[3]=a.data[c]}}}}}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 ${s}. Line ${e.line}`)}_function(e,t){const n=new Ze(e);t.functions.set(e.name,n)}_const(e,t){let n=null;e.value!==null&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e)}_let(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof F||(n=n.clone())}else{const s=e.type.name;if(s==="f32"||s==="i32"||s==="u32"||s==="bool"||s==="f16"||s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2b"||s==="vec3b"||s==="vec4b"||s==="mat2x2"||s==="mat2x3"||s==="mat2x4"||s==="mat3x2"||s==="mat3x3"||s==="mat3x4"||s==="mat4x2"||s==="mat4x3"||s==="mat4x4"||s==="mat2x2f"||s==="mat2x3f"||s==="mat2x4f"||s==="mat3x2f"||s==="mat3x3f"||s==="mat3x4f"||s==="mat4x2f"||s==="mat4x3f"||s==="mat4x4f"||s==="mat2x2h"||s==="mat2x3h"||s==="mat2x4h"||s==="mat3x2h"||s==="mat3x3h"||s==="mat3x4h"||s==="mat4x2h"||s==="mat4x3h"||s==="mat4x4h"||s==="array"){const r=new Z(e.type,[]);n=this._evalCreate(r,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof F||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);const s=e.type.name;if(s==="f32"||s==="i32"||s==="u32"||s==="bool"||s==="f16"||s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2b"||s==="vec3b"||s==="vec4b"||s==="mat2x2"||s==="mat2x3"||s==="mat2x4"||s==="mat3x2"||s==="mat3x3"||s==="mat3x4"||s==="mat4x2"||s==="mat4x3"||s==="mat4x4"||s==="mat2x2f"||s==="mat2x3f"||s==="mat2x4f"||s==="mat3x2f"||s==="mat3x3f"||s==="mat3x4f"||s==="mat4x2f"||s==="mat4x3f"||s==="mat4x4f"||s==="mat2x2h"||s==="mat2x3h"||s==="mat2x4h"||s==="mat3x2h"||s==="mat3x3h"||s==="mat3x4h"||s==="mat4x2h"||s==="mat4x3h"||s==="mat4x4h"||e.type instanceof pe||e.type instanceof Q||e.type instanceof g){const r=new Z(e.type,[]);n=this._evalCreate(r,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();const n=this.evalExpression(e.condition,t);if(!(n instanceof p))return console.error(`Invalid if condition. Line ${e.line}`),null;let s=null;for(const r of e.cases)if(r instanceof Bt)for(const a of r.selectors){if(a instanceof Te){s=r;continue}const 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(r.body,t)}else r instanceof Ft&&(s=r);return s?this._execStatements(s.body,t):null}_if(e,t){t=t.clone();const 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(const s of e.elseif){const r=this.evalExpression(s.condition,t);if(!(r instanceof p))return console.error(`Invalid if condition. Line ${e.line}`),null;if(r.value)return this._execStatements(s.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));){const n=this._execStatements(e.body,t);if(n===U._breakObj)break;if(n!==null&&n!==U._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){const n=this._execStatements(e.body,t);if(n===U._breakObj)break;if(n===U._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===U._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){const n=this._execStatements(e.body,t);if(n===U._breakObj)break;if(n!==U._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){const n=this.evalExpression(e.value,t),s=e.type;if(n instanceof p){const r=ft(n.value,n.typeInfo.name,s.name);return new p(r,this.getTypeInfo(s))}if(n instanceof d){const r=n.typeInfo.getTypeName();let a="";if(r.endsWith("f"))a="f32";else if(r.endsWith("i"))a="i32";else if(r.endsWith("u"))a="u32";else if(r.endsWith("b"))a="bool";else{if(!r.endsWith("h"))return console.error(`Unknown vector type ${r}. Line ${e.line}`),null;a="f16"}const i=s.getTypeName();let 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"}const c=(function(u,h,x){if(h===x)return u;const v=new Array(u.length);for(let k=0;k<u.length;k++)v[k]=ft(u[k],h,x);return v})(Array.from(n.data),a,o);return new d(c,this.getTypeInfo(s))}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 Z){if(e.type===null)return We.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)}}const s=e instanceof Z?e.type.name:e.name,r=e instanceof Z?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(r===null)return console.error(`Unknown type ${s}. Line ${e.line}`),null;if(r.size===0)return null;const a=new B(new ArrayBuffer(r.size),r,0);if(r instanceof se){if(e.args)for(let i=0;i<e.args.length;++i){const o=r.members[i],c=e.args[i],u=this.evalExpression(c,t);a.setData(this,u,o.type,o.offset,t)}}else if(r instanceof re){let i=0;if(e.args)for(let o=0;o<e.args.length;++o){const c=e.args[o],u=this.evalExpression(c,t);r.format===null&&(((n=u.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?r.format=this.getTypeInfo("i32"):r.format=u.typeInfo),a.setData(this,u,r.format,i,t),i+=r.stride}}else console.error(`Unknown type "${s}". Line ${e.line}`);return e instanceof Z?a.getSubData(this,e.postfix,t):a}_evalLiteral(e,t){const n=this.getTypeInfo(e.type),s=n.name;return s==="x32"||s==="u32"||s==="f32"||s==="f16"||s==="i32"||s==="bool"?new p(e.scalarValue,n):s==="vec2"||s==="vec3"||s==="vec4"||s==="vec2f"||s==="vec3f"||s==="vec4f"||s==="vec2h"||s==="vec3h"||s==="vec4h"||s==="vec2i"||s==="vec3i"||s==="vec4i"||s==="vec2u"||s==="vec3u"||s==="vec4u"?this._callConstructorVec(e,t):s==="mat2x2"||s==="mat2x3"||s==="mat2x4"||s==="mat3x2"||s==="mat3x3"||s==="mat3x4"||s==="mat4x2"||s==="mat4x3"||s==="mat4x4"||s==="mat2x2f"||s==="mat2x3f"||s==="mat2x4f"||s==="mat3x2f"||s==="mat3x3f"||s==="mat3x4f"||s==="mat4x2f"||s==="mat4x3f"||s==="mat4x4f"||s==="mat2x2h"||s==="mat2x3h"||s==="mat2x4h"||s==="mat3x2h"||s==="mat3x3h"||s==="mat3x4h"||s==="mat4x2h"||s==="mat4x3h"||s==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){const 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){const s=U._priority.get(t.name);U._priority.get(e[n].name)<s&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){const n=this.evalExpression(e.right,t);if(e.operator==="&")return new ue(n);if(e.operator==="*")return n instanceof ue?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);const s=n instanceof p?n.value:n instanceof d?Array.from(n.data):null;switch(e.operator){case"+":{if(w(s)){const i=s.map((o,c)=>+o);return new d(i,n.typeInfo)}const r=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(+r,a)}case"-":{if(w(s)){const i=s.map((o,c)=>-o);return new d(i,n.typeInfo)}const r=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(-r,a)}case"!":{if(w(s)){const i=s.map((o,c)=>o?0:1);return new d(i,n.typeInfo)}const r=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(r?0:1,a)}case"~":{if(w(s)){const i=s.map((o,c)=>~o);return new d(i,n.typeInfo)}const r=s,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new p(~r,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){const n=this.evalExpression(e.left,t),s=this.evalExpression(e.right,t),r=n instanceof p?n.value:n instanceof d||n instanceof T?Array.from(n.data):null,a=s instanceof p?s.value:s instanceof d||s instanceof T?Array.from(s.data):null;switch(e.operator){case"+":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v+h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x+u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u+x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i+o,c)}case"-":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v-h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x-u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u-x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i-o,c)}case"*":{if(w(r)&&w(a)){const u=r,h=a;if(n instanceof T&&s instanceof T){const x=(function(E,D,R,A){if(W[D.name]===void 0||W[A.name]===void 0)return null;const I=W[D.name][0],M=W[D.name][1],q=W[A.name][0];if(I!==W[A.name][1])return null;const tt=new Array(q*M);for(let ge=0;ge<M;ge++)for(let ye=0;ye<q;ye++){let nt=0;for(let xe=0;xe<I;xe++)nt+=E[xe*M+ge]*R[ye*I+xe];tt[ge*q+ye]=nt}return tt})(u,n.typeInfo,h,s.typeInfo);if(x===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;const v=W[s.typeInfo.name][0],k=W[n.typeInfo.name][1],$=this.getTypeInfo(`mat${v}x${k}f`);return new T(x,$)}if(n instanceof T&&s instanceof d){const x=(function(v,k,$,E){if(W[k.name]===void 0||Fe[E.name]===void 0)return null;const D=W[k.name][0],R=W[k.name][1];if(D!==$.length)return null;const A=new Array(R);for(let I=0;I<R;I++){let M=0;for(let q=0;q<D;q++)M+=v[q*R+I]*$[q];A[I]=M}return A})(u,n.typeInfo,h,s.typeInfo);return x===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(x,s.typeInfo)}if(n instanceof d&&s instanceof T){const x=(function(v,k,$,E){if(Fe[k.name]===void 0||W[E.name]===void 0)return null;const D=W[E.name][0],R=W[E.name][1];if(R!==v.length)return null;const A=[];for(let I=0;I<D;I++){let M=0;for(let q=0;q<R;q++)M+=v[q]*$[q*D+I];A[I]=M}return A})(u,n.typeInfo,h,s.typeInfo);return x===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new d(x,n.typeInfo)}{if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v*h[k]);return new d(x,n.typeInfo)}}if(w(r)){const u=a,h=r.map((x,v)=>x*u);return n instanceof T?new T(h,n.typeInfo):new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u*x);return s instanceof T?new T(h,s.typeInfo):new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i*o,c)}case"%":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v%h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x%u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u%x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i%o,c)}case"/":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v/h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x/u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u/x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i/o,c)}case"&":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v&h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x&u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u&x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i&o,c)}case"|":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v|h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x|u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u|x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i|o,c)}case"^":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v^h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x^u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u^x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i^o,c)}case"<<":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v<<h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x<<u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u<<x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i<<o,c)}case">>":{if(w(r)&&w(a)){const u=r,h=a;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const x=u.map((v,k)=>v>>h[k]);return new d(x,n.typeInfo)}if(w(r)){const u=a,h=r.map((x,v)=>x>>u);return new d(h,n.typeInfo)}if(w(a)){const u=r,h=a.map((x,v)=>u>>x);return new d(h,s.typeInfo)}const i=r,o=a,c=this._maxFormatTypeInfo([n.typeInfo,s.typeInfo]);return new p(i>>o,c)}case">":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u>o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c>i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i>c?1:0);return new d(o,s.typeInfo)}return new p(r>a?1:0,this.getTypeInfo("bool"));case"<":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u<o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c<i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i<c?1:0);return new d(o,s.typeInfo)}return new p(r<a?1:0,this.getTypeInfo("bool"));case"==":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u===o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c==i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i==c?1:0);return new d(o,s.typeInfo)}return new p(r===a?1:0,this.getTypeInfo("bool"));case"!=":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u!==o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c!==i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i!==c?1:0);return new d(o,s.typeInfo)}return new p(r!==a?1:0,this.getTypeInfo("bool"));case">=":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u>=o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c>=i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i>=c?1:0);return new d(o,s.typeInfo)}return new p(r>=a?1:0,this.getTypeInfo("bool"));case"<=":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u<=o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c<=i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i<=c?1:0);return new d(o,s.typeInfo)}return new p(r<=a?1:0,this.getTypeInfo("bool"));case"&&":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u&&o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c&&i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i&&c?1:0);return new d(o,s.typeInfo)}return new p(r&&a?1:0,this.getTypeInfo("bool"));case"||":if(w(r)&&w(a)){const i=r,o=a;if(i.length!==o.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;const c=i.map((u,h)=>u||o[h]?1:0);return new d(c,n.typeInfo)}if(w(r)){const i=a,o=r.map((c,u)=>c||i?1:0);return new d(o,n.typeInfo)}if(w(a)){const i=r,o=a.map((c,u)=>i||c?1:0);return new d(o,s.typeInfo)}return new p(r||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;const n=t.clone();n.currentFunctionName=e.name;const s=t.getFunction(e.name);if(!s)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 r=0;r<s.node.args.length;++r){const a=s.node.args[r],i=this.evalExpression(e.args[r],n);n.createVariable(a.name,i,a)}return this._execStatements(s.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)}const n=t.getFunction(e.name);if(n){const s=t.clone();for(let r=0;r<n.node.args.length;++r){const a=n.node.args[r],i=this.evalExpression(e.args[r],s);s.setVariable(a.name,i,a)}return this._execStatements(n.node.body,s)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new p(0,this.getTypeInfo(e.type));const n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){const n=this.getTypeInfo(e.type),s=e.type.getTypeName(),r=Fe[s];if(r===void 0)return console.error(`Invalid vec constructor ${s}. Line ${e.line}`),null;const a=[];if(e instanceof P)if(e.isVector){const i=e.vectorValue;for(const o of i)a.push(o)}else a.push(e.scalarValue);else if(e.args)for(const i of e.args){const o=this.evalExpression(i,t);if(o instanceof d){const c=o.data;for(let u=0;u<c.length;++u){let h=c[u];a.push(h)}}else if(o instanceof p){let c=o.value;a.push(c)}}if(e.type instanceof g&&e.type.format===null&&(e.type.format=g.f32),a.length===0){const i=new Array(r).fill(0);return new d(i,n).getSubData(this,e.postfix,t)}if(a.length===1)for(;a.length<r;)a.push(a[0]);return a.length<r?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new d(a.length>r?a.slice(0,r):a,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){const n=this.getTypeInfo(e.type),s=e.type.getTypeName(),r=W[s];if(r===void 0)return console.error(`Invalid matrix constructor ${s}. Line ${e.line}`),null;const a=[];if(e instanceof P)if(e.isVector){const i=e.vectorValue;for(const o of i)a.push(o)}else a.push(e.scalarValue);else if(e.args)for(const i of e.args){const 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 ae&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){const i=new Array(r[2]).fill(0);return new T(i,n).getSubData(this,e.postfix,t)}return a.length!==r[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new T(a,n).getSubData(this,e.postfix,t)}}U._breakObj=new j(new z("BREAK",null),null),U._continueObj=new j(new z("CONTINUE",null),null),U._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);class $n{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}}class Nn{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new $n,this._exec=new U,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;const t=[];for(;!this._isAtEnd();){const n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(const n of this._deferArrayCountEval){const s=n.arrayType,r=n.countNode;if(r instanceof H){const a=r.name,i=this._context.constants.get(a);if(i)try{const o=i.constEvaluate(this._exec);s.count=o}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(const n of t)n.search(s=>{s instanceof ct||s instanceof Ie?s.type=this._forwardType(s.type):s instanceof pe?s.format=this._forwardType(s.format):s instanceof ee||s instanceof de||s instanceof ke?s.type=this._forwardType(s.type):s instanceof _e?s.returnType=this._forwardType(s.returnType):s instanceof ut&&(s.type=this._forwardType(s.type))});return t}_forwardType(e){if(e instanceof ot){const t=this._getType(e.name);if(t)return t}else e instanceof Ie?e.type=this._forwardType(e.type):e instanceof pe&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){const t=new vn(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==f.eof}_match(e){if(e instanceof _)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){const s=e[t];if(this._check(s))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;const t=this._peek();if(e instanceof Array){const n=t.type;let s=!1;for(const r of e){if(n===r)return!0;r===f.tokens.name&&(s=!0)}if(s){const r=f.tokens.name.rule.exec(t.lexeme);if(r&&r.index==0&&r[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===f.tokens.name){const n=f.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(f.tokens.semicolon)&&!this._isAtEnd(););if(this._match(f.keywords.alias)){const t=this._type_alias();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.diagnostic)){const t=this._diagnostic();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.requires)){const t=this._requires_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.enable)){const t=this._enable_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}const e=this._attribute();if(this._check(f.keywords.var)){const t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.override)){const t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.let)){const t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.const)){const t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.struct)){const t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.fn)){const t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(f.keywords.fn))return null;const e=this._currentLine,t=this._consume(f.tokens.ident,"Expected function name.").toString();this._consume(f.tokens.paren_left,"Expected '(' for function arguments.");const n=[];if(!this._check(f.tokens.paren_right))do{if(this._check(f.tokens.paren_right))break;const i=this._attribute(),o=this._consume(f.tokens.name,"Expected argument name.").toString();this._consume(f.tokens.colon,"Expected ':' for argument type.");const c=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=c,n.push(this._updateNode(new ut(o,u,i))))}while(this._match(f.tokens.comma));this._consume(f.tokens.paren_right,"Expected ')' after function arguments.");let s=null;if(this._match(f.tokens.arrow)){const i=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=i)}const r=this._compound_statement(),a=this._currentLine;return this._updateNode(new _e(t,n,s,r,e,a),e)}_compound_statement(){const e=[];for(this._consume(f.tokens.brace_left,"Expected '{' for block.");!this._check(f.tokens.brace_right);){const t=this._statement();t!==null&&e.push(t)}return this._consume(f.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(f.tokens.semicolon)&&!this._isAtEnd(););if(this._check(f.tokens.attr)&&this._attribute(),this._check(f.keywords.if))return this._if_statement();if(this._check(f.keywords.switch))return this._switch_statement();if(this._check(f.keywords.loop))return this._loop_statement();if(this._check(f.keywords.for))return this._for_statement();if(this._check(f.keywords.while))return this._while_statement();if(this._check(f.keywords.continuing))return this._continuing_statement();if(this._check(f.keywords.static_assert))return this._static_assert_statement();if(this._check(f.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(f.keywords.return))e=this._return_statement();else if(this._check([f.keywords.var,f.keywords.let,f.keywords.const]))e=this._variable_statement();else if(this._match(f.keywords.discard))e=this._updateNode(new yn);else if(this._match(f.keywords.break)){const t=this._updateNode(new Et);if(this._currentLoop.length>0){const n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t,this._check(f.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(f.keywords.continue)){const t=this._updateNode(new Lt);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{const 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(f.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(f.keywords.static_assert))return null;const e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new mn(t),e)}_while_statement(){if(!this._match(f.keywords.while))return null;const e=this._updateNode(new xt(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(f.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){const e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(f.keywords.continuing))return null;const t=this._currentLine,n=this._compound_statement();return this._updateNode(new Me(n,e),t)}_for_statement(){if(!this._match(f.keywords.for))return null;this._consume(f.tokens.paren_left,"Expected '('.");const e=this._updateNode(new bt(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(f.tokens.semicolon)?null:this._for_init(),this._consume(f.tokens.semicolon,"Expected ';'."),e.condition=this._check(f.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(f.tokens.semicolon,"Expected ';'."),e.increment=this._check(f.tokens.paren_right)?null:this._for_increment(),this._consume(f.tokens.paren_right,"Expected ')'."),this._check(f.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(f.keywords.var)){const e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(f.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new ee(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(f.keywords.let)){const e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for let.").toString();let n=null;if(this._match(f.tokens.colon)){const r=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=r)}this._consume(f.tokens.equal,"Expected '=' for let.");const s=this._short_circuit_or_expression();return this._updateNode(new de(t,n,null,null,s),e)}if(this._match(f.keywords.const)){const e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for const.").toString();let n=null;if(this._match(f.tokens.colon)){const r=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=r)}this._consume(f.tokens.equal,"Expected '=' for const.");const s=this._short_circuit_or_expression();return n===null&&s instanceof P&&(n=s.type),this._updateNode(new ke(t,n,null,null,s),e)}return null}_increment_decrement_statement(){const e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(f.increment_operators))return this._current=e,null;const n=this._consume(f.increment_operators,"Expected increment operator");return this._updateNode(new vt(n.type===f.tokens.plus_plus?ce.increment:ce.decrement,t))}_assignment_statement(){let e=null;const t=this._currentLine;if(this._check(f.tokens.brace_right))return null;let n=this._match(f.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;const s=this._consume(f.assignment_operators,"Expected assignment operator."),r=this._short_circuit_or_expression();return this._updateNode(new wt(fe.parse(s.lexeme),e,r),t)}_func_call_statement(){if(!this._check(f.tokens.ident))return null;const e=this._currentLine,t=this._current,n=this._consume(f.tokens.ident,"Expected function name."),s=this._argument_expression_list();return s===null?(this._current=t,null):this._updateNode(new ze(n.lexeme,s),e)}_loop_statement(){if(!this._match(f.keywords.loop))return null;this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Expected '{' for loop.");const e=this._updateNode(new kt([],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 Me){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(f.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(f.keywords.switch))return null;const e=this._updateNode(new It(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.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(f.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){const e=[];let t=!1;for(;this._check([f.keywords.default,f.keywords.case]);){if(this._match(f.keywords.case)){const n=this._case_selectors();for(const r of n)if(r instanceof Te){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(f.tokens.colon),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Exected '{' for switch case.");const s=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Bt(n,s)))}if(this._match(f.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(f.tokens.colon),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Exected '{' for switch default.");const n=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Ft(n)))}}return e}_case_selectors(){const e=[];for(this._match(f.keywords.default)?e.push(this._updateNode(new Te)):e.push(this._shift_expression());this._match(f.tokens.comma);)this._match(f.keywords.default)?e.push(this._updateNode(new Te)):e.push(this._shift_expression());return e}_case_body(){if(this._match(f.keywords.fallthrough))return this._consume(f.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);const t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(f.keywords.if))return null;const e=this._currentLine,t=this._optional_paren_expression();this._check(f.tokens.attr)&&this._attribute();const n=this._compound_statement();let s=[];this._match_elseif()&&(this._check(f.tokens.attr)&&this._attribute(),s=this._elseif_statement(s));let r=null;return this._match(f.keywords.else)&&(this._check(f.tokens.attr)&&this._attribute(),r=this._compound_statement()),this._updateNode(new Tt(t,n,s,r),e)}_match_elseif(){return this._tokens[this._current].type===f.keywords.else&&this._tokens[this._current+1].type===f.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){const t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new xn(t,n))),this._match_elseif()&&(this._check(f.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(f.keywords.return))return null;const e=this._short_circuit_or_expression();return this._updateNode(new At(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(f.tokens.or_or);)e=this._updateNode(new X(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(f.tokens.and_and);)e=this._updateNode(new X(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(f.tokens.or);)e=this._updateNode(new X(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(f.tokens.xor);)e=this._updateNode(new X(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(f.tokens.and);)e=this._updateNode(new X(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){const e=this._relational_expression();return this._match([f.tokens.equal_equal,f.tokens.not_equal])?this._updateNode(new X(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([f.tokens.less_than,f.tokens.greater_than,f.tokens.less_than_equal,f.tokens.greater_than_equal]);)e=this._updateNode(new X(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([f.tokens.shift_left,f.tokens.shift_right]);)e=this._updateNode(new X(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([f.tokens.plus,f.tokens.minus]);)e=this._updateNode(new X(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([f.tokens.star,f.tokens.forward_slash,f.tokens.modulo]);)e=this._updateNode(new X(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([f.tokens.minus,f.tokens.bang,f.tokens.tilde,f.tokens.star,f.tokens.and])?this._updateNode(new F(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){const e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(f.tokens.bracket_left)){const e=this._short_circuit_or_expression();this._consume(f.tokens.bracket_right,"Expected ']'.");const t=this._updateNode(new le(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(f.tokens.period)){const e=this._consume(f.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new oe(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){const t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return b.void;case"bool":return b.bool;case"i32":return b.i32;case"u32":return b.u32;case"f32":return b.f32;case"f16":return b.f16;case"vec2f":return g.vec2f;case"vec3f":return g.vec3f;case"vec4f":return g.vec4f;case"vec2i":return g.vec2i;case"vec3i":return g.vec3i;case"vec4i":return g.vec4i;case"vec2u":return g.vec2u;case"vec3u":return g.vec3u;case"vec4u":return g.vec4u;case"vec2h":return g.vec2h;case"vec3h":return g.vec3h;case"vec4h":return g.vec4h;case"mat2x2f":return g.mat2x2f;case"mat2x3f":return g.mat2x3f;case"mat2x4f":return g.mat2x4f;case"mat3x2f":return g.mat3x2f;case"mat3x3f":return g.mat3x3f;case"mat3x4f":return g.mat3x4f;case"mat4x2f":return g.mat4x2f;case"mat4x3f":return g.mat4x3f;case"mat4x4f":return g.mat4x4f;case"mat2x2h":return g.mat2x2h;case"mat2x3h":return g.mat2x3h;case"mat2x4h":return g.mat2x4h;case"mat3x2h":return g.mat3x2h;case"mat3x3h":return g.mat3x3h;case"mat3x4h":return g.mat3x4h;case"mat4x2h":return g.mat4x2h;case"mat4x3h":return g.mat4x3h;case"mat4x4h":return g.mat4x4h;case"mat2x2i":return g.mat2x2i;case"mat2x3i":return g.mat2x3i;case"mat2x4i":return g.mat2x4i;case"mat3x2i":return g.mat3x2i;case"mat3x3i":return g.mat3x3i;case"mat3x4i":return g.mat3x4i;case"mat4x2i":return g.mat4x2i;case"mat4x3i":return g.mat4x3i;case"mat4x4i":return g.mat4x4i;case"mat2x2u":return g.mat2x2u;case"mat2x3u":return g.mat2x3u;case"mat2x4u":return g.mat2x4u;case"mat3x2u":return g.mat3x2u;case"mat3x3u":return g.mat3x3u;case"mat3x4u":return g.mat3x4u;case"mat4x2u":return g.mat4x2u;case"mat4x3u":return g.mat4x3u;case"mat4x4u":return g.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(f.tokens.ident)){const n=this._previous().toString();if(this._check(f.tokens.paren_left)){const s=this._argument_expression_list(),r=this._getType(n);return r!==null?this._updateNode(new Z(r,s)):this._updateNode(new Ge(n,s))}if(this._context.constants.has(n)){const s=this._context.constants.get(n);return this._updateNode(new Ot(n,s.value))}return this._updateNode(new H(n))}if(this._match(f.tokens.int_literal)){const n=this._previous().toString();let s=n.endsWith("i")||n.endsWith("i")?b.i32:n.endsWith("u")||n.endsWith("U")?b.u32:b.x32;const r=parseInt(n);return this._validateTypeRange(r,s),this._updateNode(new P(new p(r,this._exec.getTypeInfo(s)),s))}if(this._match(f.tokens.uint_literal)){const n=parseInt(this._previous().toString());return this._validateTypeRange(n,b.u32),this._updateNode(new P(new p(n,this._exec.getTypeInfo(b.u32)),b.u32))}if(this._match([f.tokens.decimal_float_literal,f.tokens.hex_float_literal])){let n=this._previous().toString(),s=n.endsWith("h");s&&(n=n.substring(0,n.length-1));const r=parseFloat(n);this._validateTypeRange(r,s?b.f16:b.f32);const a=s?b.f16:b.f32;return this._updateNode(new P(new p(r,this._exec.getTypeInfo(a)),a))}if(this._match([f.keywords.true,f.keywords.false])){let n=this._previous().toString()===f.keywords.true.rule;return this._updateNode(new P(new p(n?1:0,this._exec.getTypeInfo(b.bool)),b.bool))}if(this._check(f.tokens.paren_left))return this._paren_expression();if(this._match(f.keywords.bitcast)){this._consume(f.tokens.less_than,"Expected '<'.");const n=this._type_decl();this._consume(f.tokens.greater_than,"Expected '>'.");const s=this._paren_expression();return this._updateNode(new $t(n,s))}const e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new Z(e,t))}_argument_expression_list(){if(!this._match(f.tokens.paren_left))return null;const e=[];do{if(this._check(f.tokens.paren_right))break;const t=this._short_circuit_or_expression();e.push(t)}while(this._match(f.tokens.comma));return this._consume(f.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(f.tokens.paren_left);const e=this._short_circuit_or_expression();return this._match(f.tokens.paren_right),e}_paren_expression(){this._consume(f.tokens.paren_left,"Expected '('.");const e=this._short_circuit_or_expression();return this._consume(f.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(f.keywords.struct))return null;const e=this._currentLine,t=this._consume(f.tokens.ident,"Expected name for struct.").toString();this._consume(f.tokens.brace_left,"Expected '{' for struct body.");const n=[];for(;!this._check(f.tokens.brace_right);){const a=this._attribute(),i=this._consume(f.tokens.name,"Expected variable name.").toString();this._consume(f.tokens.colon,"Expected ':' for struct member type.");const o=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=o),this._check(f.tokens.brace_right)?this._match(f.tokens.comma):this._consume(f.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new ct(i,c,a)))}this._consume(f.tokens.brace_right,"Expected '}' after struct body.");const s=this._currentLine,r=this._updateNode(new Q(t,n,e,s),e);return this._context.structs.set(t,r),r}_global_variable_decl(){const e=this._variable_decl();if(!e)return null;if(this._match(f.tokens.equal)){const t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof P){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 P&&(e.type=e.value.type.name==="x32"?b.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){const e=this._override_decl();return e&&this._match(f.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(f.keywords.const))return null;const t=this._consume(f.tokens.name,"Expected variable name"),n=this._currentLine;let s=null;if(this._match(f.tokens.colon)){const o=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=o)}let r=null;this._consume(f.tokens.equal,"const declarations require an assignment");const a=this._short_circuit_or_expression();try{let o=[b.f32],c=a.constEvaluate(this._exec,o);c instanceof p&&this._validateTypeRange(c.value,o[0]),o[0]instanceof g&&o[0].format===null&&c.typeInfo instanceof ae&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?o[0].format=b.f16:c.typeInfo.format.name==="f32"?o[0].format=b.f32:c.typeInfo.format.name==="i32"?o[0].format=b.i32:c.typeInfo.format.name==="u32"?o[0].format=b.u32:c.typeInfo.format.name==="bool"?o[0].format=b.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),r=this._updateNode(new P(c,o[0])),this._exec.context.setVariable(t.toString(),c)}catch{r=a}if(s!==null&&r instanceof P){if(r.type.name!=="x32"&&s.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${s.name}. Line:${this._currentLine}`);r.type=s,r.isScalar&&this._validateTypeRange(r.scalarValue,r.type)}else s===null&&r instanceof P&&(s=(e=r?.type)!==null&&e!==void 0?e:b.f32,s===b.x32&&(s=b.i32));const i=this._updateNode(new ke(t.toString(),s,"","",r),n);return this._context.constants.set(i.name,i),i}_global_let_decl(){if(!this._match(f.keywords.let))return null;const e=this._currentLine,t=this._consume(f.tokens.name,"Expected variable name");let n=null;if(this._match(f.tokens.colon)){const r=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=r)}let s=null;if(this._match(f.tokens.equal)&&(s=this._const_expression()),n!==null&&s instanceof P){if(s.type.name!=="x32"&&n.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${n.name}. Line:${this._currentLine}`);s.type=n}else n===null&&s instanceof P&&(n=s.type.name==="x32"?b.i32:s.type);return s instanceof P&&s.isScalar&&this._validateTypeRange(s.scalarValue,n),this._updateNode(new de(t.toString(),n,"","",s),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(f.keywords.var))return null;const e=this._currentLine;let t="",n="";this._match(f.tokens.less_than)&&(t=this._consume(f.storage_class,"Expected storage_class.").toString(),this._match(f.tokens.comma)&&(n=this._consume(f.access_mode,"Expected access_mode.").toString()),this._consume(f.tokens.greater_than,"Expected '>'."));const s=this._consume(f.tokens.name,"Expected variable name");let r=null;if(this._match(f.tokens.colon)){const a=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=a)}return this._updateNode(new ee(s.toString(),r,t,n,null),e)}_override_decl(){if(!this._match(f.keywords.override))return null;const e=this._consume(f.tokens.name,"Expected variable name");let t=null;if(this._match(f.tokens.colon)){const n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new He(e.toString(),t,null))}_diagnostic(){this._consume(f.tokens.paren_left,"Expected '('");const e=this._consume(f.tokens.ident,"Expected severity control name.");this._consume(f.tokens.comma,"Expected ','");let t=this._consume(f.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(f.tokens.period)&&(t+=`.${this._consume(f.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(f.tokens.paren_right,"Expected ')'"),this._updateNode(new St(e.toString(),t))}_enable_directive(){const e=this._consume(f.tokens.ident,"identity expected.");return this._updateNode(new _n(e.toString()))}_requires_directive(){const e=[this._consume(f.tokens.ident,"identity expected.").toString()];for(;this._match(f.tokens.comma);){const t=this._consume(f.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new gn(e))}_type_alias(){const e=this._consume(f.tokens.ident,"identity expected.");this._consume(f.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);const n=this._updateNode(new je(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([f.tokens.ident,...f.texel_format,f.keywords.bool,f.keywords.f32,f.keywords.i32,f.keywords.u32])){const 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)){const s=this._updateNode(new ot(n));return this._forwardTypeCount++,s}return this._updateNode(new b(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(f.template_types)){let n=this._advance().toString(),s=null,r=null;return this._match(f.tokens.less_than)&&(s=this._type_decl(),r=null,this._match(f.tokens.comma)&&(r=this._consume(f.access_mode,"Expected access_mode for pointer").toString()),this._consume(f.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new g(n,s,r))}if(this._match(f.keywords.ptr)){let n=this._previous().toString();this._consume(f.tokens.less_than,"Expected '<' for pointer.");const s=this._consume(f.storage_class,"Expected storage_class for pointer");this._consume(f.tokens.comma,"Expected ',' for pointer.");const r=this._type_decl();let a=null;return this._match(f.tokens.comma)&&(a=this._consume(f.access_mode,"Expected access_mode for pointer").toString()),this._consume(f.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Ie(n,s.toString(),r,a))}const t=this._attribute();if(this._match(f.keywords.array)){let n=null,s=-1;const r=this._previous();let a=null;if(this._match(f.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(f.tokens.comma)){a=this._shift_expression();try{o=a.constEvaluate(this._exec).toString(),a=null}catch{o="1"}}this._consume(f.tokens.greater_than,"Expected '>' for array."),s=o?parseInt(o):0}const i=this._updateNode(new pe(r.toString(),t,n,s));return a&&this._deferArrayCountEval.push({arrayType:i,countNode:a}),i}return null}_texture_sampler_types(){if(this._match(f.sampler_type))return this._updateNode(new he(this._previous().toString(),null,null));if(this._match(f.depth_texture_type))return this._updateNode(new he(this._previous().toString(),null,null));if(this._match(f.sampled_texture_type)||this._match(f.multisampled_texture_type)){const e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");const t=this._type_decl();return this._consume(f.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new he(e.toString(),t,null))}if(this._match(f.storage_texture_type)){const e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");const t=this._consume(f.texel_format,"Invalid texel format.").toString();this._consume(f.tokens.comma,"Expected ',' after texel format.");const n=this._consume(f.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(f.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new he(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(f.tokens.attr);){const t=this._consume(f.attribute_name,"Expected attribute name"),n=this._updateNode(new Pt(t.toString(),null));if(this._match(f.tokens.paren_left)){if(n.value=this._consume(f.literal_or_ident,"Expected attribute value").toString(),this._check(f.tokens.comma)){this._advance();do{const s=this._consume(f.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(s)}while(this._match(f.tokens.comma))}this._consume(f.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}}class Dn extends Y{constructor(e){super(),e&&this.update(e)}update(e){const t=new Nn().parse(e);this.updateAST(t)}}function Bn(l){const e={attributes:[],bindings:[]};let t;try{t=Fn(l)}catch(r){return S.error(r.message)(),e}for(const r of t.uniforms){const a=[];for(const i of r.type?.members||[])a.push({name:i.name,type:ht(i.type)});e.bindings.push({type:"uniform",name:r.name,group:r.group,location:r.binding,members:a})}for(const r of t.textures)e.bindings.push({type:"texture",name:r.name,group:r.group,location:r.binding});for(const r of t.samplers)e.bindings.push({type:"sampler",name:r.name,group:r.group,location:r.binding});const n=t.entry.vertex[0],s=n?.inputs.length||0;for(let r=0;r<s;r++){const a=n.inputs[r];if(a.locationType==="location"){const i=ht(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:i})}}return e}function ht(l){return l?.format?`${l.name}<${l.format.name}>`:l.name}function Fn(l){try{return new Dn(l)}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 Qe(l,e=[],t=0){const n=Math.fround(l),s=l-n;return e[t]=n,e[t+1]=s,e}function Ct(l){return l-Math.fround(l)}function Vt(l){const e=new Float32Array(32);for(let t=0;t<4;++t)for(let n=0;n<4;++n){const s=t*4+n;Qe(l[n*4+t],e,s*2)}return e}const Pn=`
6
+ uniform fp64arithmeticUniforms {
7
+ uniform float ONE;
8
+ } fp64;
9
+
10
+ /*
11
+ About LUMA_FP64_CODE_ELIMINATION_WORKAROUND
12
+
13
+ The purpose of this workaround is to prevent shader compilers from
14
+ optimizing away necessary arithmetic operations by swapping their sequences
15
+ or transform the equation to some 'equivalent' form.
16
+
17
+ The method is to multiply an artifical variable, ONE, which will be known to
18
+ the compiler to be 1 only at runtime. The whole expression is then represented
19
+ as a polynomial with respective to ONE. In the coefficients of all terms, only one a
20
+ and one b should appear
21
+
22
+ err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
23
+ */
24
+
25
+ // Divide float number to high and low floats to extend fraction bits
26
+ vec2 split(float a) {
27
+ const float SPLIT = 4097.0;
28
+ float t = a * SPLIT;
29
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
30
+ float a_hi = t * fp64.ONE - (t - a);
31
+ float a_lo = a * fp64.ONE - a_hi;
32
+ #else
33
+ float a_hi = t - (t - a);
34
+ float a_lo = a - a_hi;
35
+ #endif
36
+ return vec2(a_hi, a_lo);
37
+ }
38
+
39
+ // Divide float number again when high float uses too many fraction bits
40
+ vec2 split2(vec2 a) {
41
+ vec2 b = split(a.x);
42
+ b.y += a.y;
43
+ return b;
44
+ }
45
+
46
+ // Special sum operation when a > b
47
+ vec2 quickTwoSum(float a, float b) {
48
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
49
+ float sum = (a + b) * fp64.ONE;
50
+ float err = b - (sum - a) * fp64.ONE;
51
+ #else
52
+ float sum = a + b;
53
+ float err = b - (sum - a);
54
+ #endif
55
+ return vec2(sum, err);
56
+ }
57
+
58
+ // General sum operation
59
+ vec2 twoSum(float a, float b) {
60
+ float s = (a + b);
61
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
62
+ float v = (s * fp64.ONE - a) * fp64.ONE;
63
+ float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE + (b - v);
64
+ #else
65
+ float v = s - a;
66
+ float err = (a - (s - v)) + (b - v);
67
+ #endif
68
+ return vec2(s, err);
69
+ }
70
+
71
+ vec2 twoSub(float a, float b) {
72
+ float s = (a - b);
73
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
74
+ float v = (s * fp64.ONE - a) * fp64.ONE;
75
+ float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE - (b + v);
76
+ #else
77
+ float v = s - a;
78
+ float err = (a - (s - v)) - (b + v);
79
+ #endif
80
+ return vec2(s, err);
81
+ }
82
+
83
+ vec2 twoSqr(float a) {
84
+ float prod = a * a;
85
+ vec2 a_fp64 = split(a);
86
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
87
+ float err = ((a_fp64.x * a_fp64.x - prod) * fp64.ONE + 2.0 * a_fp64.x *
88
+ a_fp64.y * fp64.ONE * fp64.ONE) + a_fp64.y * a_fp64.y * fp64.ONE * fp64.ONE * fp64.ONE;
89
+ #else
90
+ float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;
91
+ #endif
92
+ return vec2(prod, err);
93
+ }
94
+
95
+ vec2 twoProd(float a, float b) {
96
+ float prod = a * b;
97
+ vec2 a_fp64 = split(a);
98
+ vec2 b_fp64 = split(b);
99
+ float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
100
+ a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
101
+ return vec2(prod, err);
102
+ }
103
+
104
+ vec2 sum_fp64(vec2 a, vec2 b) {
105
+ vec2 s, t;
106
+ s = twoSum(a.x, b.x);
107
+ t = twoSum(a.y, b.y);
108
+ s.y += t.x;
109
+ s = quickTwoSum(s.x, s.y);
110
+ s.y += t.y;
111
+ s = quickTwoSum(s.x, s.y);
112
+ return s;
113
+ }
114
+
115
+ vec2 sub_fp64(vec2 a, vec2 b) {
116
+ vec2 s, t;
117
+ s = twoSub(a.x, b.x);
118
+ t = twoSub(a.y, b.y);
119
+ s.y += t.x;
120
+ s = quickTwoSum(s.x, s.y);
121
+ s.y += t.y;
122
+ s = quickTwoSum(s.x, s.y);
123
+ return s;
124
+ }
125
+
126
+ vec2 mul_fp64(vec2 a, vec2 b) {
127
+ vec2 prod = twoProd(a.x, b.x);
128
+ // y component is for the error
129
+ prod.y += a.x * b.y;
130
+ #if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
131
+ prod = split2(prod);
132
+ #endif
133
+ prod = quickTwoSum(prod.x, prod.y);
134
+ prod.y += a.y * b.x;
135
+ #if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
136
+ prod = split2(prod);
137
+ #endif
138
+ prod = quickTwoSum(prod.x, prod.y);
139
+ return prod;
140
+ }
141
+
142
+ vec2 div_fp64(vec2 a, vec2 b) {
143
+ float xn = 1.0 / b.x;
144
+ #if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
145
+ vec2 yn = mul_fp64(a, vec2(xn, 0));
146
+ #else
147
+ vec2 yn = a * xn;
148
+ #endif
149
+ float diff = (sub_fp64(a, mul_fp64(b, yn))).x;
150
+ vec2 prod = twoProd(xn, diff);
151
+ return sum_fp64(yn, prod);
152
+ }
153
+
154
+ vec2 sqrt_fp64(vec2 a) {
155
+ if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);
156
+ if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
157
+
158
+ float x = 1.0 / sqrt(a.x);
159
+ float yn = a.x * x;
160
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
161
+ vec2 yn_sqr = twoSqr(yn) * fp64.ONE;
162
+ #else
163
+ vec2 yn_sqr = twoSqr(yn);
164
+ #endif
165
+ float diff = sub_fp64(a, yn_sqr).x;
166
+ vec2 prod = twoProd(x * 0.5, diff);
167
+ #if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)
168
+ return sum_fp64(split(yn), prod);
169
+ #else
170
+ return sum_fp64(vec2(yn, 0.0), prod);
171
+ #endif
172
+ }
173
+ `,Cn=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
174
+ const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
175
+ const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
176
+ const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
177
+ const vec2 PI_2_FP64 = vec2(1.5707963705062866, -4.371139006309477e-8);
178
+ const vec2 PI_4_FP64 = vec2(0.7853981852531433, -2.1855695031547384e-8);
179
+ const vec2 PI_16_FP64 = vec2(0.19634954631328583, -5.463923757886846e-9);
180
+ const vec2 PI_16_2_FP64 = vec2(0.39269909262657166, -1.0927847515773692e-8);
181
+ const vec2 PI_16_3_FP64 = vec2(0.5890486240386963, -1.4906100798128818e-9);
182
+ const vec2 PI_180_FP64 = vec2(0.01745329238474369, 1.3519960498364902e-10);
183
+
184
+ const vec2 SIN_TABLE_0_FP64 = vec2(0.19509032368659973, -1.6704714833615242e-9);
185
+ const vec2 SIN_TABLE_1_FP64 = vec2(0.3826834261417389, 6.22335089017767e-9);
186
+ const vec2 SIN_TABLE_2_FP64 = vec2(0.5555702447891235, -1.1769521357507529e-8);
187
+ const vec2 SIN_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617041793133e-8);
188
+
189
+ const vec2 COS_TABLE_0_FP64 = vec2(0.9807852506637573, 2.9739473106360492e-8);
190
+ const vec2 COS_TABLE_1_FP64 = vec2(0.9238795042037964, 2.8307490351764386e-8);
191
+ const vec2 COS_TABLE_2_FP64 = vec2(0.8314695954322815, 1.6870263741530778e-8);
192
+ const vec2 COS_TABLE_3_FP64 = vec2(0.7071067690849304, 1.2101617152815436e-8);
193
+
194
+ const vec2 INVERSE_FACTORIAL_3_FP64 = vec2(1.666666716337204e-01, -4.967053879312289e-09); // 1/3!
195
+ const vec2 INVERSE_FACTORIAL_4_FP64 = vec2(4.16666679084301e-02, -1.2417634698280722e-09); // 1/4!
196
+ const vec2 INVERSE_FACTORIAL_5_FP64 = vec2(8.333333767950535e-03, -4.34617203337595e-10); // 1/5!
197
+ const vec2 INVERSE_FACTORIAL_6_FP64 = vec2(1.3888889225199819e-03, -3.3631094437103215e-11); // 1/6!
198
+ const vec2 INVERSE_FACTORIAL_7_FP64 = vec2(1.9841270113829523e-04, -2.725596874933456e-12); // 1/7!
199
+ const vec2 INVERSE_FACTORIAL_8_FP64 = vec2(2.4801587642286904e-05, -3.406996025904184e-13); // 1/8!
200
+ const vec2 INVERSE_FACTORIAL_9_FP64 = vec2(2.75573188446287533e-06, 3.7935713937038186e-14); // 1/9!
201
+ const vec2 INVERSE_FACTORIAL_10_FP64 = vec2(2.755731998149713e-07, -7.575112367869873e-15); // 1/10!
202
+
203
+ float nint(float d) {
204
+ if (d == floor(d)) return d;
205
+ return floor(d + 0.5);
206
+ }
207
+
208
+ vec2 nint_fp64(vec2 a) {
209
+ float hi = nint(a.x);
210
+ float lo;
211
+ vec2 tmp;
212
+ if (hi == a.x) {
213
+ lo = nint(a.y);
214
+ tmp = quickTwoSum(hi, lo);
215
+ } else {
216
+ lo = 0.0;
217
+ if (abs(hi - a.x) == 0.5 && a.y < 0.0) {
218
+ hi -= 1.0;
219
+ }
220
+ tmp = vec2(hi, lo);
221
+ }
222
+ return tmp;
223
+ }
224
+
225
+ /* k_power controls how much range reduction we would like to have
226
+ Range reduction uses the following method:
227
+ assume a = k_power * r + m * log(2), k and m being integers.
228
+ Set k_power = 4 (we can choose other k to trade accuracy with performance.
229
+ we only need to calculate exp(r) and using exp(a) = 2^m * exp(r)^k_power;
230
+ */
231
+
232
+ vec2 exp_fp64(vec2 a) {
233
+ // We need to make sure these two numbers match
234
+ // as bit-wise shift is not available in GLSL 1.0
235
+ const int k_power = 4;
236
+ const float k = 16.0;
237
+
238
+ const float inv_k = 1.0 / k;
239
+
240
+ if (a.x <= -88.0) return vec2(0.0, 0.0);
241
+ if (a.x >= 88.0) return vec2(1.0 / 0.0, 1.0 / 0.0);
242
+ if (a.x == 0.0 && a.y == 0.0) return vec2(1.0, 0.0);
243
+ if (a.x == 1.0 && a.y == 0.0) return E_FP64;
244
+
245
+ float m = floor(a.x / LOG2_FP64.x + 0.5);
246
+ vec2 r = sub_fp64(a, mul_fp64(LOG2_FP64, vec2(m, 0.0))) * inv_k;
247
+ vec2 s, t, p;
248
+
249
+ p = mul_fp64(r, r);
250
+ s = sum_fp64(r, p * 0.5);
251
+ p = mul_fp64(p, r);
252
+ t = mul_fp64(p, INVERSE_FACTORIAL_3_FP64);
253
+
254
+ s = sum_fp64(s, t);
255
+ p = mul_fp64(p, r);
256
+ t = mul_fp64(p, INVERSE_FACTORIAL_4_FP64);
257
+
258
+ s = sum_fp64(s, t);
259
+ p = mul_fp64(p, r);
260
+ t = mul_fp64(p, INVERSE_FACTORIAL_5_FP64);
261
+
262
+ // s = sum_fp64(s, t);
263
+ // p = mul_fp64(p, r);
264
+ // t = mul_fp64(p, INVERSE_FACTORIAL_6_FP64);
265
+
266
+ // s = sum_fp64(s, t);
267
+ // p = mul_fp64(p, r);
268
+ // t = mul_fp64(p, INVERSE_FACTORIAL_7_FP64);
269
+
270
+ s = sum_fp64(s, t);
271
+
272
+
273
+ // At this point, s = exp(r) - 1; but after following 4 recursions, we will get exp(r) ^ 512 - 1.
274
+ for (int i = 0; i < k_power; i++) {
275
+ s = sum_fp64(s * 2.0, mul_fp64(s, s));
276
+ }
277
+
278
+ #if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
279
+ s = sum_fp64(s, vec2(fp64.ONE, 0.0));
280
+ #else
281
+ s = sum_fp64(s, vec2(1.0, 0.0));
282
+ #endif
283
+
284
+ return s * pow(2.0, m);
285
+ // return r;
286
+ }
287
+
288
+ vec2 log_fp64(vec2 a)
289
+ {
290
+ if (a.x == 1.0 && a.y == 0.0) return vec2(0.0, 0.0);
291
+ if (a.x <= 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);
292
+ vec2 x = vec2(log(a.x), 0.0);
293
+ vec2 s;
294
+ #if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
295
+ s = vec2(fp64.ONE, 0.0);
296
+ #else
297
+ s = vec2(1.0, 0.0);
298
+ #endif
299
+
300
+ x = sub_fp64(sum_fp64(x, mul_fp64(a, exp_fp64(-x))), s);
301
+ return x;
302
+ }
303
+
304
+ vec2 sin_taylor_fp64(vec2 a) {
305
+ vec2 r, s, t, x;
306
+
307
+ if (a.x == 0.0 && a.y == 0.0) {
308
+ return vec2(0.0, 0.0);
309
+ }
310
+
311
+ x = -mul_fp64(a, a);
312
+ s = a;
313
+ r = a;
314
+
315
+ r = mul_fp64(r, x);
316
+ t = mul_fp64(r, INVERSE_FACTORIAL_3_FP64);
317
+ s = sum_fp64(s, t);
318
+
319
+ r = mul_fp64(r, x);
320
+ t = mul_fp64(r, INVERSE_FACTORIAL_5_FP64);
321
+ s = sum_fp64(s, t);
322
+
323
+ /* keep the following commented code in case we need them
324
+ for extra accuracy from the Taylor expansion*/
325
+
326
+ // r = mul_fp64(r, x);
327
+ // t = mul_fp64(r, INVERSE_FACTORIAL_7_FP64);
328
+ // s = sum_fp64(s, t);
329
+
330
+ // r = mul_fp64(r, x);
331
+ // t = mul_fp64(r, INVERSE_FACTORIAL_9_FP64);
332
+ // s = sum_fp64(s, t);
333
+
334
+ return s;
335
+ }
336
+
337
+ vec2 cos_taylor_fp64(vec2 a) {
338
+ vec2 r, s, t, x;
339
+
340
+ if (a.x == 0.0 && a.y == 0.0) {
341
+ return vec2(1.0, 0.0);
342
+ }
343
+
344
+ x = -mul_fp64(a, a);
345
+ r = x;
346
+ s = sum_fp64(vec2(1.0, 0.0), r * 0.5);
347
+
348
+ r = mul_fp64(r, x);
349
+ t = mul_fp64(r, INVERSE_FACTORIAL_4_FP64);
350
+ s = sum_fp64(s, t);
351
+
352
+ r = mul_fp64(r, x);
353
+ t = mul_fp64(r, INVERSE_FACTORIAL_6_FP64);
354
+ s = sum_fp64(s, t);
355
+
356
+ /* keep the following commented code in case we need them
357
+ for extra accuracy from the Taylor expansion*/
358
+
359
+ // r = mul_fp64(r, x);
360
+ // t = mul_fp64(r, INVERSE_FACTORIAL_8_FP64);
361
+ // s = sum_fp64(s, t);
362
+
363
+ // r = mul_fp64(r, x);
364
+ // t = mul_fp64(r, INVERSE_FACTORIAL_10_FP64);
365
+ // s = sum_fp64(s, t);
366
+
367
+ return s;
368
+ }
369
+
370
+ void sincos_taylor_fp64(vec2 a, out vec2 sin_t, out vec2 cos_t) {
371
+ if (a.x == 0.0 && a.y == 0.0) {
372
+ sin_t = vec2(0.0, 0.0);
373
+ cos_t = vec2(1.0, 0.0);
374
+ }
375
+
376
+ sin_t = sin_taylor_fp64(a);
377
+ cos_t = sqrt_fp64(sub_fp64(vec2(1.0, 0.0), mul_fp64(sin_t, sin_t)));
378
+ }
379
+
380
+ vec2 sin_fp64(vec2 a) {
381
+ if (a.x == 0.0 && a.y == 0.0) {
382
+ return vec2(0.0, 0.0);
383
+ }
384
+
385
+ // 2pi range reduction
386
+ vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
387
+ vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
388
+
389
+ vec2 t;
390
+ float q = floor(r.x / PI_2_FP64.x + 0.5);
391
+ int j = int(q);
392
+
393
+ if (j < -2 || j > 2) {
394
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
395
+ }
396
+
397
+ t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
398
+
399
+ q = floor(t.x / PI_16_FP64.x + 0.5);
400
+ int k = int(q);
401
+
402
+ if (k == 0) {
403
+ if (j == 0) {
404
+ return sin_taylor_fp64(t);
405
+ } else if (j == 1) {
406
+ return cos_taylor_fp64(t);
407
+ } else if (j == -1) {
408
+ return -cos_taylor_fp64(t);
409
+ } else {
410
+ return -sin_taylor_fp64(t);
411
+ }
412
+ }
413
+
414
+ int abs_k = int(abs(float(k)));
415
+
416
+ if (abs_k > 4) {
417
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
418
+ } else {
419
+ t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
420
+ }
421
+
422
+ vec2 u = vec2(0.0, 0.0);
423
+ vec2 v = vec2(0.0, 0.0);
424
+
425
+ #if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
426
+ if (abs(float(abs_k) - 1.0) < 0.5) {
427
+ u = COS_TABLE_0_FP64;
428
+ v = SIN_TABLE_0_FP64;
429
+ } else if (abs(float(abs_k) - 2.0) < 0.5) {
430
+ u = COS_TABLE_1_FP64;
431
+ v = SIN_TABLE_1_FP64;
432
+ } else if (abs(float(abs_k) - 3.0) < 0.5) {
433
+ u = COS_TABLE_2_FP64;
434
+ v = SIN_TABLE_2_FP64;
435
+ } else if (abs(float(abs_k) - 4.0) < 0.5) {
436
+ u = COS_TABLE_3_FP64;
437
+ v = SIN_TABLE_3_FP64;
438
+ }
439
+ #else
440
+ if (abs_k == 1) {
441
+ u = COS_TABLE_0_FP64;
442
+ v = SIN_TABLE_0_FP64;
443
+ } else if (abs_k == 2) {
444
+ u = COS_TABLE_1_FP64;
445
+ v = SIN_TABLE_1_FP64;
446
+ } else if (abs_k == 3) {
447
+ u = COS_TABLE_2_FP64;
448
+ v = SIN_TABLE_2_FP64;
449
+ } else if (abs_k == 4) {
450
+ u = COS_TABLE_3_FP64;
451
+ v = SIN_TABLE_3_FP64;
452
+ }
453
+ #endif
454
+
455
+ vec2 sin_t, cos_t;
456
+ sincos_taylor_fp64(t, sin_t, cos_t);
457
+
458
+
459
+
460
+ vec2 result = vec2(0.0, 0.0);
461
+ if (j == 0) {
462
+ if (k > 0) {
463
+ result = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
464
+ } else {
465
+ result = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
466
+ }
467
+ } else if (j == 1) {
468
+ if (k > 0) {
469
+ result = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
470
+ } else {
471
+ result = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
472
+ }
473
+ } else if (j == -1) {
474
+ if (k > 0) {
475
+ result = sub_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
476
+ } else {
477
+ result = -sum_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
478
+ }
479
+ } else {
480
+ if (k > 0) {
481
+ result = -sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
482
+ } else {
483
+ result = sub_fp64(mul_fp64(v, cos_t), mul_fp64(u, sin_t));
484
+ }
485
+ }
486
+
487
+ return result;
488
+ }
489
+
490
+ vec2 cos_fp64(vec2 a) {
491
+ if (a.x == 0.0 && a.y == 0.0) {
492
+ return vec2(1.0, 0.0);
493
+ }
494
+
495
+ // 2pi range reduction
496
+ vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
497
+ vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
498
+
499
+ vec2 t;
500
+ float q = floor(r.x / PI_2_FP64.x + 0.5);
501
+ int j = int(q);
502
+
503
+ if (j < -2 || j > 2) {
504
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
505
+ }
506
+
507
+ t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
508
+
509
+ q = floor(t.x / PI_16_FP64.x + 0.5);
510
+ int k = int(q);
511
+
512
+ if (k == 0) {
513
+ if (j == 0) {
514
+ return cos_taylor_fp64(t);
515
+ } else if (j == 1) {
516
+ return -sin_taylor_fp64(t);
517
+ } else if (j == -1) {
518
+ return sin_taylor_fp64(t);
519
+ } else {
520
+ return -cos_taylor_fp64(t);
521
+ }
522
+ }
523
+
524
+ int abs_k = int(abs(float(k)));
525
+
526
+ if (abs_k > 4) {
527
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
528
+ } else {
529
+ t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
530
+ }
531
+
532
+ vec2 u = vec2(0.0, 0.0);
533
+ vec2 v = vec2(0.0, 0.0);
534
+
535
+ #if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
536
+ if (abs(float(abs_k) - 1.0) < 0.5) {
537
+ u = COS_TABLE_0_FP64;
538
+ v = SIN_TABLE_0_FP64;
539
+ } else if (abs(float(abs_k) - 2.0) < 0.5) {
540
+ u = COS_TABLE_1_FP64;
541
+ v = SIN_TABLE_1_FP64;
542
+ } else if (abs(float(abs_k) - 3.0) < 0.5) {
543
+ u = COS_TABLE_2_FP64;
544
+ v = SIN_TABLE_2_FP64;
545
+ } else if (abs(float(abs_k) - 4.0) < 0.5) {
546
+ u = COS_TABLE_3_FP64;
547
+ v = SIN_TABLE_3_FP64;
548
+ }
549
+ #else
550
+ if (abs_k == 1) {
551
+ u = COS_TABLE_0_FP64;
552
+ v = SIN_TABLE_0_FP64;
553
+ } else if (abs_k == 2) {
554
+ u = COS_TABLE_1_FP64;
555
+ v = SIN_TABLE_1_FP64;
556
+ } else if (abs_k == 3) {
557
+ u = COS_TABLE_2_FP64;
558
+ v = SIN_TABLE_2_FP64;
559
+ } else if (abs_k == 4) {
560
+ u = COS_TABLE_3_FP64;
561
+ v = SIN_TABLE_3_FP64;
562
+ }
563
+ #endif
564
+
565
+ vec2 sin_t, cos_t;
566
+ sincos_taylor_fp64(t, sin_t, cos_t);
567
+
568
+ vec2 result = vec2(0.0, 0.0);
569
+ if (j == 0) {
570
+ if (k > 0) {
571
+ result = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
572
+ } else {
573
+ result = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
574
+ }
575
+ } else if (j == 1) {
576
+ if (k > 0) {
577
+ result = -sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
578
+ } else {
579
+ result = sub_fp64(mul_fp64(v, cos_t), mul_fp64(u, sin_t));
580
+ }
581
+ } else if (j == -1) {
582
+ if (k > 0) {
583
+ result = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
584
+ } else {
585
+ result = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
586
+ }
587
+ } else {
588
+ if (k > 0) {
589
+ result = sub_fp64(mul_fp64(v, sin_t), mul_fp64(u, cos_t));
590
+ } else {
591
+ result = -sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
592
+ }
593
+ }
594
+
595
+ return result;
596
+ }
597
+
598
+ vec2 tan_fp64(vec2 a) {
599
+ vec2 sin_a;
600
+ vec2 cos_a;
601
+
602
+ if (a.x == 0.0 && a.y == 0.0) {
603
+ return vec2(0.0, 0.0);
604
+ }
605
+
606
+ // 2pi range reduction
607
+ vec2 z = nint_fp64(div_fp64(a, TWO_PI_FP64));
608
+ vec2 r = sub_fp64(a, mul_fp64(TWO_PI_FP64, z));
609
+
610
+ vec2 t;
611
+ float q = floor(r.x / PI_2_FP64.x + 0.5);
612
+ int j = int(q);
613
+
614
+
615
+ if (j < -2 || j > 2) {
616
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
617
+ }
618
+
619
+ t = sub_fp64(r, mul_fp64(PI_2_FP64, vec2(q, 0.0)));
620
+
621
+ q = floor(t.x / PI_16_FP64.x + 0.5);
622
+ int k = int(q);
623
+ int abs_k = int(abs(float(k)));
624
+
625
+ // We just can't get PI/16 * 3.0 very accurately.
626
+ // so let's just store it
627
+ if (abs_k > 4) {
628
+ return vec2(0.0 / 0.0, 0.0 / 0.0);
629
+ } else {
630
+ t = sub_fp64(t, mul_fp64(PI_16_FP64, vec2(q, 0.0)));
631
+ }
632
+
633
+
634
+ vec2 u = vec2(0.0, 0.0);
635
+ vec2 v = vec2(0.0, 0.0);
636
+
637
+ vec2 sin_t, cos_t;
638
+ vec2 s, c;
639
+ sincos_taylor_fp64(t, sin_t, cos_t);
640
+
641
+ if (k == 0) {
642
+ s = sin_t;
643
+ c = cos_t;
644
+ } else {
645
+ #if defined(NVIDIA_FP64_WORKAROUND) || defined(INTEL_FP64_WORKAROUND)
646
+ if (abs(float(abs_k) - 1.0) < 0.5) {
647
+ u = COS_TABLE_0_FP64;
648
+ v = SIN_TABLE_0_FP64;
649
+ } else if (abs(float(abs_k) - 2.0) < 0.5) {
650
+ u = COS_TABLE_1_FP64;
651
+ v = SIN_TABLE_1_FP64;
652
+ } else if (abs(float(abs_k) - 3.0) < 0.5) {
653
+ u = COS_TABLE_2_FP64;
654
+ v = SIN_TABLE_2_FP64;
655
+ } else if (abs(float(abs_k) - 4.0) < 0.5) {
656
+ u = COS_TABLE_3_FP64;
657
+ v = SIN_TABLE_3_FP64;
658
+ }
659
+ #else
660
+ if (abs_k == 1) {
661
+ u = COS_TABLE_0_FP64;
662
+ v = SIN_TABLE_0_FP64;
663
+ } else if (abs_k == 2) {
664
+ u = COS_TABLE_1_FP64;
665
+ v = SIN_TABLE_1_FP64;
666
+ } else if (abs_k == 3) {
667
+ u = COS_TABLE_2_FP64;
668
+ v = SIN_TABLE_2_FP64;
669
+ } else if (abs_k == 4) {
670
+ u = COS_TABLE_3_FP64;
671
+ v = SIN_TABLE_3_FP64;
672
+ }
673
+ #endif
674
+ if (k > 0) {
675
+ s = sum_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
676
+ c = sub_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
677
+ } else {
678
+ s = sub_fp64(mul_fp64(u, sin_t), mul_fp64(v, cos_t));
679
+ c = sum_fp64(mul_fp64(u, cos_t), mul_fp64(v, sin_t));
680
+ }
681
+ }
682
+
683
+ if (j == 0) {
684
+ sin_a = s;
685
+ cos_a = c;
686
+ } else if (j == 1) {
687
+ sin_a = c;
688
+ cos_a = -s;
689
+ } else if (j == -1) {
690
+ sin_a = -c;
691
+ cos_a = s;
692
+ } else {
693
+ sin_a = -s;
694
+ cos_a = -c;
695
+ }
696
+ return div_fp64(sin_a, cos_a);
697
+ }
698
+
699
+ vec2 radians_fp64(vec2 degree) {
700
+ return mul_fp64(degree, PI_180_FP64);
701
+ }
702
+
703
+ vec2 mix_fp64(vec2 a, vec2 b, float x) {
704
+ vec2 range = sub_fp64(b, a);
705
+ return sum_fp64(a, mul_fp64(range, vec2(x, 0.0)));
706
+ }
707
+
708
+ // Vector functions
709
+ // vec2 functions
710
+ void vec2_sum_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
711
+ out_val[0] = sum_fp64(a[0], b[0]);
712
+ out_val[1] = sum_fp64(a[1], b[1]);
713
+ }
714
+
715
+ void vec2_sub_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
716
+ out_val[0] = sub_fp64(a[0], b[0]);
717
+ out_val[1] = sub_fp64(a[1], b[1]);
718
+ }
719
+
720
+ void vec2_mul_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
721
+ out_val[0] = mul_fp64(a[0], b[0]);
722
+ out_val[1] = mul_fp64(a[1], b[1]);
723
+ }
724
+
725
+ void vec2_div_fp64(vec2 a[2], vec2 b[2], out vec2 out_val[2]) {
726
+ out_val[0] = div_fp64(a[0], b[0]);
727
+ out_val[1] = div_fp64(a[1], b[1]);
728
+ }
729
+
730
+ void vec2_mix_fp64(vec2 x[2], vec2 y[2], float a, out vec2 out_val[2]) {
731
+ vec2 range[2];
732
+ vec2_sub_fp64(y, x, range);
733
+ vec2 portion[2];
734
+ portion[0] = range[0] * a;
735
+ portion[1] = range[1] * a;
736
+ vec2_sum_fp64(x, portion, out_val);
737
+ }
738
+
739
+ vec2 vec2_length_fp64(vec2 x[2]) {
740
+ return sqrt_fp64(sum_fp64(mul_fp64(x[0], x[0]), mul_fp64(x[1], x[1])));
741
+ }
742
+
743
+ void vec2_normalize_fp64(vec2 x[2], out vec2 out_val[2]) {
744
+ vec2 length = vec2_length_fp64(x);
745
+ vec2 length_vec2[2];
746
+ length_vec2[0] = length;
747
+ length_vec2[1] = length;
748
+
749
+ vec2_div_fp64(x, length_vec2, out_val);
750
+ }
751
+
752
+ vec2 vec2_distance_fp64(vec2 x[2], vec2 y[2]) {
753
+ vec2 diff[2];
754
+ vec2_sub_fp64(x, y, diff);
755
+ return vec2_length_fp64(diff);
756
+ }
757
+
758
+ vec2 vec2_dot_fp64(vec2 a[2], vec2 b[2]) {
759
+ vec2 v[2];
760
+
761
+ v[0] = mul_fp64(a[0], b[0]);
762
+ v[1] = mul_fp64(a[1], b[1]);
763
+
764
+ return sum_fp64(v[0], v[1]);
765
+ }
766
+
767
+ // vec3 functions
768
+ void vec3_sub_fp64(vec2 a[3], vec2 b[3], out vec2 out_val[3]) {
769
+ for (int i = 0; i < 3; i++) {
770
+ out_val[i] = sum_fp64(a[i], b[i]);
771
+ }
772
+ }
773
+
774
+ void vec3_sum_fp64(vec2 a[3], vec2 b[3], out vec2 out_val[3]) {
775
+ for (int i = 0; i < 3; i++) {
776
+ out_val[i] = sum_fp64(a[i], b[i]);
777
+ }
778
+ }
779
+
780
+ vec2 vec3_length_fp64(vec2 x[3]) {
781
+ return sqrt_fp64(sum_fp64(sum_fp64(mul_fp64(x[0], x[0]), mul_fp64(x[1], x[1])),
782
+ mul_fp64(x[2], x[2])));
783
+ }
784
+
785
+ vec2 vec3_distance_fp64(vec2 x[3], vec2 y[3]) {
786
+ vec2 diff[3];
787
+ vec3_sub_fp64(x, y, diff);
788
+ return vec3_length_fp64(diff);
789
+ }
790
+
791
+ // vec4 functions
792
+ void vec4_fp64(vec4 a, out vec2 out_val[4]) {
793
+ out_val[0].x = a[0];
794
+ out_val[0].y = 0.0;
795
+
796
+ out_val[1].x = a[1];
797
+ out_val[1].y = 0.0;
798
+
799
+ out_val[2].x = a[2];
800
+ out_val[2].y = 0.0;
801
+
802
+ out_val[3].x = a[3];
803
+ out_val[3].y = 0.0;
804
+ }
805
+
806
+ void vec4_scalar_mul_fp64(vec2 a[4], vec2 b, out vec2 out_val[4]) {
807
+ out_val[0] = mul_fp64(a[0], b);
808
+ out_val[1] = mul_fp64(a[1], b);
809
+ out_val[2] = mul_fp64(a[2], b);
810
+ out_val[3] = mul_fp64(a[3], b);
811
+ }
812
+
813
+ void vec4_sum_fp64(vec2 a[4], vec2 b[4], out vec2 out_val[4]) {
814
+ for (int i = 0; i < 4; i++) {
815
+ out_val[i] = sum_fp64(a[i], b[i]);
816
+ }
817
+ }
818
+
819
+ void vec4_dot_fp64(vec2 a[4], vec2 b[4], out vec2 out_val) {
820
+ vec2 v[4];
821
+
822
+ v[0] = mul_fp64(a[0], b[0]);
823
+ v[1] = mul_fp64(a[1], b[1]);
824
+ v[2] = mul_fp64(a[2], b[2]);
825
+ v[3] = mul_fp64(a[3], b[3]);
826
+
827
+ out_val = sum_fp64(sum_fp64(v[0], v[1]), sum_fp64(v[2], v[3]));
828
+ }
829
+
830
+ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
831
+ vec2 tmp[4];
832
+
833
+ for (int i = 0; i < 4; i++)
834
+ {
835
+ for (int j = 0; j < 4; j++)
836
+ {
837
+ tmp[j] = b[j + i * 4];
838
+ }
839
+ vec4_dot_fp64(a, tmp, out_val[i]);
840
+ }
841
+ }
842
+ `,Vn={ONE:1},Un={name:"fp64arithmetic",vs:Pn,defaultUniforms:Vn,uniformTypes:{ONE:"f32"},fp64ify:Qe,fp64LowPart:Ct,fp64ifyMatrix4:Vt},cs={name:"fp64",vs:Cn,dependencies:[Un],fp64ify:Qe,fp64LowPart:Ct,fp64ifyMatrix4:Vt},Pe={};function De(l="id"){Pe[l]=Pe[l]||1;const e=Pe[l]++;return`${l}-${e}`}class dt{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(e){if(this.id=e.id||De("geometry"),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&ne.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){this.indices?.destroy();for(const e of Object.values(this.attributes))e.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}}function Mn(l,e){if(e instanceof dt)return e;const t=Wn(l,e),{attributes:n,bufferLayout:s}=Rn(l,e);return new dt({topology:e.topology||"triangle-list",bufferLayout:s,vertexCount:e.vertexCount,indices:t,attributes:n})}function Wn(l,e){if(!e.indices)return;const t=e.indices.value;return l.createBuffer({usage:ne.INDEX,data:t})}function Rn(l,e){const t=[],n={};for(const[r,a]of Object.entries(e.attributes)){let i=r;switch(r){case"POSITION":i="positions";break;case"NORMAL":i="normals";break;case"TEXCOORD_0":i="texCoords";break;case"COLOR_0":i="colors";break}if(a){n[i]=l.createBuffer({data:a.value,id:`${r}-buffer`});const{value:o,size:c,normalized:u}=a;t.push({name:i,format:Rt(o,c,u)})}}const s=e._calculateVertexCount(e.attributes,e.indices);return{attributes:n,bufferLayout:t,vertexCount:s}}class Je{static defaultProps={...we.defaultProps};static getDefaultPipelineFactory(e){return e._lumaData.defaultPipelineFactory=e._lumaData.defaultPipelineFactory||new Je(e),e._lumaData.defaultPipelineFactory}device;cachingEnabled;destroyPolicy;debug;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(e){this.device=e,this.cachingEnabled=e.props._cachePipelines,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=e.props.debugFactories}createRenderPipeline(e){if(!this.cachingEnabled)return this.device.createRenderPipeline(e);const t={...we.defaultProps,...e},n=this._renderPipelineCache,s=this._hashRenderPipeline(t);let r=n[s]?.pipeline;return r?(n[s].useCount++,this.debug&&S.warn(`${this}: ${n[s].pipeline} reused, count=${n[s].useCount}, (id=${e.id})`)()):(r=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:De("unnamed-cached")}),r.hash=s,n[s]={pipeline:r,useCount:1},this.debug&&S.warn(`${this}: ${r} created, count=${n[s].useCount}`)()),r}createComputePipeline(e){if(!this.cachingEnabled)return this.device.createComputePipeline(e);const t={...Ae.defaultProps,...e},n=this._computePipelineCache,s=this._hashComputePipeline(t);let r=n[s]?.pipeline;return r?(n[s].useCount++,this.debug&&S.warn(`${this}: ${n[s].pipeline} reused, count=${n[s].useCount}, (id=${e.id})`)()):(r=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),r.hash=s,n[s]={pipeline:r,useCount:1},this.debug&&S.warn(`${this}: ${r} created, count=${n[s].useCount}`)()),r}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._getCache(e),n=e.hash;t[n].useCount--,t[n].useCount===0?(this._destroyPipeline(e),this.debug&&S.warn(`${this}: ${e} released and destroyed`)()):t[n].useCount<0?(S.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[n].useCount=0):this.debug&&S.warn(`${this}: ${e} released, count=${t[n].useCount}`)()}_destroyPipeline(e){const t=this._getCache(e);switch(this.destroyPolicy){case"never":return!1;case"unused":return delete t[e.hash],e.destroy(),!0}}_getCache(e){let t;if(e instanceof Ae&&(t=this._computePipelineCache),e instanceof we&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){const{type:t}=this.device,n=this._getHash(e.shader.source);return`${t}/C/${n}`}_hashRenderPipeline(e){const t=e.vs?this._getHash(e.vs.source):0,n=e.fs?this._getHash(e.fs.source):0,s="-",r=this._getHash(JSON.stringify(e.bufferLayout)),{type:a}=this.device;switch(a){case"webgl":return`${a}/R/${t}/${n}V${s}BL${r}`;case"webgpu":default:const i=this._getHash(JSON.stringify(e.parameters));return`${a}/R/${t}/${n}V${s}T${e.topology}P${i}BL${r}`}}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}}class et{static defaultProps={...jt.defaultProps};static getDefaultShaderFactory(e){return e._lumaData.defaultShaderFactory||=new et(e),e._lumaData.defaultShaderFactory}device;cachingEnabled;destroyPolicy;debug;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(e){this.device=e,this.cachingEnabled=e.props._cacheShaders,this.destroyPolicy=e.props._cacheDestroyPolicy,this.debug=!0}createShader(e){if(!this.cachingEnabled)return this.device.createShader(e);const t=this._hashShader(e);let n=this._cache[t];if(n)n.useCount++,this.debug&&S.warn(`${this}: Reusing shader ${n.shader.id} count=${n.useCount}`)();else{const s=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=n={shader:s,useCount:1},this.debug&&S.warn(`${this}: Created new shader ${s.id}`)()}return n.shader}release(e){if(!this.cachingEnabled){e.destroy();return}const t=this._hashShader(e),n=this._cache[t];if(n)if(n.useCount--,n.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[t],n.shader.destroy(),this.debug&&S.warn(`${this}: Releasing shader ${e.id}, destroyed`)());else{if(n.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.debug&&S.warn(`${this}: Releasing shader ${e.id} count=${n.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}}function qn(l,e){const t={},n="Values";if(l.attributes.length===0&&!l.varyings?.length)return{"No attributes or varyings":{[n]:"N/A"}};for(const s of l.attributes)if(s){const r=`${s.location} ${s.name}: ${s.type}`;t[`in ${r}`]={[n]:s.stepMode||"vertex"}}for(const s of l.varyings||[]){const r=`${s.location} ${s.name}`;t[`out ${r}`]={[n]:JSON.stringify(s)}}return t}let C=null,Ce=null;function Hn(l,{id:e,minimap:t,opaque:n,top:s="0",left:r="0",rgbaScale:a=1}){C||(C=document.createElement("canvas"),C.id=e,C.title=e,C.style.zIndex="100",C.style.position="absolute",C.style.top=s,C.style.left=r,C.style.border="blue 5px solid",C.style.transform="scaleY(-1)",document.body.appendChild(C),Ce=C.getContext("2d")),(C.width!==l.width||C.height!==l.height)&&(C.width=l.width/2,C.height=l.height/2,C.style.width="400px",C.style.height="400px");const i=l.device.readPixelsToArrayWebGL(l),o=Ce?.createImageData(l.width,l.height);if(o){for(let u=0;u<i.length;u+=4)o.data[0+u+0]=i[u+0]*a,o.data[0+u+1]=i[u+1]*a,o.data[0+u+2]=i[u+2]*a,o.data[0+u+3]=n?255:i[u+3]*a;Ce?.putImageData(o,0,0)}}function Re(l,e,t){if(l===e)return!0;if(!t||!l||!e)return!1;if(Array.isArray(l)){if(!Array.isArray(e)||l.length!==e.length)return!1;for(let n=0;n<l.length;n++)if(!Re(l[n],e[n],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof l=="object"&&typeof e=="object"){const n=Object.keys(l),s=Object.keys(e);if(n.length!==s.length)return!1;for(const r of n)if(!e.hasOwnProperty(r)||!Re(l[r],e[r],t-1))return!1;return!0}return!1}class Ve{bufferLayouts;constructor(e){this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(t=>t.name===e)||null}getAttributeNamesForBuffer(e){return e.attributes?e.attributes?.map(t=>t.attribute):[e.name]}mergeBufferLayouts(e,t){const n=[...e];for(const s of t){const r=n.findIndex(a=>a.name===s.name);r<0?n.push(s):n[r]=s}return n}getBufferIndex(e){const t=this.bufferLayouts.findIndex(n=>n.name===e);return t===-1&&S.warn(`BufferLayout: Missing buffer for "${e}".`)(),t}}function zn(l,e){const t=Object.fromEntries(l.attributes.map(s=>[s.name,s.location])),n=e.slice();return n.sort((s,r)=>{const a=s.attributes?s.attributes.map(u=>u.attribute):[s.name],i=r.attributes?r.attributes.map(u=>u.attribute):[r.name],o=Math.min(...a.map(u=>t[u])),c=Math.min(...i.map(u=>t[u]));return o-c}),n}function jn(l){return ArrayBuffer.isView(l)&&!(l instanceof DataView)}function Gn(l){return Array.isArray(l)?l.length===0||typeof l[0]=="number":!1}function Xn(l){return jn(l)||Gn(l)}function Kn(l){return Xn(l)||typeof l=="number"||typeof l=="boolean"}function Zn(l){const e={bindings:{},uniforms:{}};return Object.keys(l).forEach(t=>{const n=l[t];Kn(n)?e.uniforms[t]=n:e.bindings[t]=n}),e}class Yn{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(e,t){Object.assign(this.options,t);const n=Kt(Object.values(e).filter(s=>s.dependencies));for(const s of n)e[s.name]=s;S.log(1,"Creating ShaderInputs with modules",Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(const[s,r]of Object.entries(e))this._addModule(r),r.name&&s!==r.name&&!this.options.disableWarnings&&S.warn(`Module name: ${s} vs ${r.name}`)()}destroy(){}setProps(e){for(const t of Object.keys(e)){const n=t,s=e[n]||{},r=this.modules[n];if(!r){this.options.disableWarnings||S.warn(`Module ${t} not found`)();continue}const a=this.moduleUniforms[n],i=this.moduleBindings[n],o=r.getUniforms?.(s,a)||s,{uniforms:c,bindings:u}=Zn(o);this.moduleUniforms[n]={...a,...c},this.moduleBindings[n]={...i,...u}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){const e={};for(const t of Object.values(this.moduleBindings))Object.assign(e,t);return e}getDebugTable(){const e={};for(const[t,n]of Object.entries(this.moduleUniforms))for(const[s,r]of Object.entries(n))e[`${t}.${s}`]={type:this.modules[t].uniformTypes?.[s],value:String(r)};return e}_addModule(e){const t=e.name;this.moduleUniforms[t]=e.defaultUniforms||{},this.moduleBindings[t]={}}}let Qn="";async function Jn(l,e){const t=new Image;return t.crossOrigin="anonymous",t.src=l.startsWith("http")?l:Qn+l,await t.decode(),e?await createImageBitmap(t,e):await createImageBitmap(t)}const es=["+X","-X","+Y","-Y","+Z","-Z"],ts=["+X","-X","+Y","-Y","+Z","-Z"];class me{device;id;props;texture;sampler;view;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}constructor(e,t){this.device=e;const n=De("async-texture");this.props={...me.defaultProps,id:n,...t},this.id=this.props.id,t={...t},typeof t?.data=="string"&&t.dimension==="2d"&&(t.data=Jn(t.data)),t.mipmaps&&(t.mipLevels="auto"),this.ready=new Promise((s,r)=>{this.resolveReady=()=>{this.isReady=!0,s()},this.rejectReady=r}),this.initAsync(t)}async initAsync(e){const t=e.data,n=await Ut(t).then(void 0,this.rejectReady);if(this.destroyed)return;const s=this.props.width&&this.props.height?{width:this.props.width,height:this.props.height}:this.getTextureDataSize(n);if(!s)throw new Error("Texture size could not be determined");const r={...s,...e,data:void 0,mipLevels:1},a=this.device.getMipLevelCount(r.width,r.height);if(r.mipLevels=this.props.mipLevels==="auto"?a:Math.min(a,this.props.mipLevels),this.texture=this.device.createTexture(r),this.sampler=this.texture.sampler,this.view=this.texture.view,e.data)switch(this.props.dimension){case"1d":this._setTexture1DData(this.texture,n);break;case"2d":this._setTexture2DData(n);break;case"3d":this._setTexture3DData(this.texture,n);break;case"2d-array":this._setTextureArrayData(this.texture,n);break;case"cube":this._setTextureCubeData(this.texture,n);break;case"cube-array":this._setTextureCubeArrayData(this.texture,n);break}this.props.mipmaps&&this.generateMipmaps(),S.info(1,`${this} loaded`),this.resolveReady()}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}generateMipmaps(){this.texture.generateMipmapsWebGL()}setSampler(e={}){this.texture.setSampler(e instanceof pt?e:this.device.createSampler(e))}resize(e){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(e.width===this.texture.width&&e.height===this.texture.height)return!1;if(this.texture){const t=this.texture;this.texture=t.clone(e),t.destroy()}return!0}isTextureLevelData(e){const t=e?.data;return ArrayBuffer.isView(t)}getTextureDataSize(e){if(!e||ArrayBuffer.isView(e))return null;if(Array.isArray(e))return this.getTextureDataSize(e[0]);if(this.device.isExternalImage(e))return this.device.getExternalImageSize(e);if(e&&typeof e=="object"&&e.constructor===Object){const n=Object.values(e)[0];return{width:n.width,height:n.height}}throw new Error("texture size deduction failed")}getCubeFaceDepth(e){switch(e){case"+X":return 0;case"-X":return 1;case"+Y":return 2;case"-Y":return 3;case"+Z":return 4;case"-Z":return 5;default:throw new Error(e)}}setTextureData(e){}_setTexture1DData(e,t){throw new Error("setTexture1DData not supported in WebGL.")}_setTexture2DData(e,t=0){if(!this.texture)throw new Error("Texture not initialized");const n=this._normalizeTextureData(e);n.length>1&&this.props.mipmaps!==!1&&S.warn(`Texture ${this.id} mipmap and multiple LODs.`)();for(let s=0;s<n.length;s++){const r=n[s];this.device.isExternalImage(r)?this.texture.copyExternalImage({image:r,depth:t,mipLevel:s,flipY:!0}):this.texture.copyImageData({data:r.data,mipLevel:s})}}_setTexture3DData(e,t){if(this.texture?.props.dimension!=="3d")throw new Error(this.id);for(let n=0;n<t.length;n++)this._setTexture2DData(t[n],n)}_setTextureCubeData(e,t){if(this.texture?.props.dimension!=="cube")throw new Error(this.id);for(const[n,s]of Object.entries(t)){const r=ts.indexOf(n);this._setTexture2DData(s,r)}}_setTextureArrayData(e,t){if(this.texture?.props.dimension!=="2d-array")throw new Error(this.id);for(let n=0;n<t.length;n++)this._setTexture2DData(t[n],n)}_setTextureCubeArrayData(e,t){throw new Error("setTextureCubeArrayData not supported in WebGL2.")}_setTextureCubeFaceData(e,t,n,s=0){Array.isArray(t)&&t.length>1&&this.props.mipmaps!==!1&&S.warn(`${this.id} has mipmap and multiple LODs.`)();const r=es.indexOf(n);this._setTexture2DData(t,r)}_normalizeTextureData(e){const t=this.texture;let n;return ArrayBuffer.isView(e)?n=[{data:e,width:t.width,height:t.height}]:Array.isArray(e)?n=e:n=[e],n}static defaultProps={...mt.defaultProps,data:null,mipmaps:!1}}async function Ut(l){if(l=await l,Array.isArray(l))return await Promise.all(l.map(Ut));if(l&&typeof l=="object"&&l.constructor===Object){const e=l,t=await Promise.all(Object.values(e)),n=Object.keys(e),s={};for(let r=0;r<n.length;r++)s[n[r]]=t[r];return s}return l}const ie=2,ns=1e4;class Mt{static defaultProps={...we.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:Zt.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0};device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(e,t){this.props={...Mt.defaultProps,...t},t=this.props,this.id=t.id||De("model"),this.device=e,Object.assign(this.userData,t.userData);const n=Object.fromEntries(this.props.modules?.map(o=>[o.name,o])||[]),s=t.shaderInputs||new Yn(n,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(s);const r=rs(e),a=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){const{source:o,getUniforms:c}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:a});this.source=o,this._getModuleUniforms=c,this.props.shaderLayout||=Bn(this.source)}else{const{vs:o,fs:c,getUniforms:u}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:r,...this.props,modules:a});this.vs=o,this.fs=c,this._getModuleUniforms=u}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,t.geometry&&this.setGeometry(t.geometry),this.pipelineFactory=t.pipelineFactory||Je.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||et.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in t&&(this.isInstanced=t.isInstanced),t.instanceCount&&this.setInstanceCount(t.instanceCount),t.vertexCount&&this.setVertexCount(t.vertexCount),t.indexBuffer&&this.setIndexBuffer(t.indexBuffer),t.attributes&&this.setAttributes(t.attributes),t.constantAttributes&&this.setConstantAttributes(t.constantAttributes),t.bindings&&this.setBindings(t.bindings),t.transformFeedback&&(this.transformFeedback=t.transformFeedback),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");const e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||=e}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(e){const t=this._areBindingsLoading();if(t)return S.info(ie,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;try{e.pushDebugGroup(`${this}.predraw(${e})`),this.predraw()}finally{e.popDebugGroup()}let n;try{e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();const s=this._getBindings();this.pipeline.setBindings(s,{disableWarnings:this.props.disableWarnings});const{indexBuffer:r}=this.vertexArray,a=r?r.byteLength/(r.indexType==="uint32"?4:2):void 0;n=this.pipeline.draw({renderPass:e,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:a,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),n?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",n}setGeometry(e){this._gpuGeometry?.destroy();const t=e&&Mn(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");const n=new Ve(this.bufferLayout);this.bufferLayout=n.mergeBufferLayouts(t.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(t)}this._gpuGeometry=t}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(e){const t=new Ve(this.bufferLayout);this.bufferLayout=this._gpuGeometry?t.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(e){Re(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw("vertexCount")}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new sn(this.shaderInputs.modules);for(const[t,n]of Object.entries(this.shaderInputs.modules))if(ss(n)){const s=this._uniformStore.getManagedUniformBuffer(this.device,t);this.bindings[`${t}Uniforms`]=s}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw("bindings")}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(e){this.vertexArray.setIndexBuffer(e),this.setNeedsRedraw("indexBuffer")}setAttributes(e,t){const n=t?.disableWarnings??this.props.disableWarnings;e.indices&&S.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=zn(this.pipeline.shaderLayout,this.bufferLayout);const s=new Ve(this.bufferLayout);for(const[r,a]of Object.entries(e)){const i=s.getBufferLayout(r);if(!i){n||S.warn(`Model(${this.id}): Missing layout for buffer "${r}".`)();continue}const o=s.getAttributeNamesForBuffer(i);let c=!1;for(const u of o){const h=this._attributeInfos[u];if(h){const x=this.device.type==="webgpu"?s.getBufferIndex(h.bufferName):h.location;this.vertexArray.setBuffer(x,a),c=!0}}!c&&!n&&S.warn(`Model(${this.id}): Ignoring buffer "${a.id}" for unknown attribute "${r}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(const[n,s]of Object.entries(e)){const r=this._attributeInfos[n];r?this.vertexArray.setConstantWebGL(r.location,s):(t?.disableWarnings??this.props.disableWarnings)||S.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(const e of Object.values(this.bindings))if(e instanceof me&&!e.isReady)return e.id;return!1}_getBindings(){const e={};for(const[t,n]of Object.entries(this.bindings))n instanceof me?n.isReady&&(e[t]=n.texture):e[t]=n;return e}_getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof Gt?e=Math.max(e,t.texture.updateTimestamp):t instanceof ne||t instanceof mt?e=Math.max(e,t.updateTimestamp):t instanceof me?e=t.texture?Math.max(e,t.texture.updateTimestamp):1/0:t instanceof pt||(e=Math.max(e,t.buffer.updateTimestamp));return e}_setGeometryAttributes(e){const t={...e.attributes};for(const[n]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(s=>s.name===n)&&n!=="positions"&&delete t[n];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(t,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||=e,this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,t=null;this.pipeline&&(S.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,t=this.pipeline.fs),this._pipelineNeedsUpdate=!1;const n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders});let s=null;this.source?s=n:this.fs&&(s=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:n,fs:s}),this._attributeInfos=Xt(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),t&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){const e=S.level>3?0:ns;S.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,S.group(ie,`>>> DRAWING MODEL ${this.id}`,{collapsed:S.level<=2})())}_logDrawCallEnd(){if(this._logOpen){const e=qn(this.pipeline.shaderLayout,this.id);S.table(ie,e)();const t=this.shaderInputs.getDebugTable();S.table(ie,t)();const n=this._getAttributeDebugTable();S.table(ie,this._attributeInfos)(),S.table(ie,n)(),S.groupEnd(ie)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(e){const t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;const n=e.props.framebuffer;n&&Hn(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){const e={};for(const[t,n]of Object.entries(this._attributeInfos)){const s=this.vertexArray.attributes[n.location];e[n.location]={name:t,type:n.shaderType,values:s?this._getBufferOrConstantValues(s,n.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){const{indexBuffer:t}=this.vertexArray,n=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:n.toString()}}return e}_getBufferOrConstantValues(e,t){const n=qt(t);return(e instanceof ne?new n(e.debugData):e).toString()}}function ss(l){return!!(l.uniformTypes&&!is(l.uniformTypes))}function rs(l){return{type:l.type,shaderLanguage:l.info.shadingLanguage,shaderLanguageVersion:l.info.shadingLanguageVersion,gpu:l.info.gpu,features:l.features}}function is(l){for(const e in l)return!1;return!0}function ls(l,e){if(!e)return l;const t={...l,...e};if("defines"in e&&(t.defines={...l.defines,...e.defines}),"modules"in e&&(t.modules=(l.modules||[]).concat(e.modules),e.modules.some(n=>n.name==="project64"))){const n=t.modules.findIndex(s=>s.name==="project32");n>=0&&t.modules.splice(n,1)}if("inject"in e)if(!l.inject)t.inject=e.inject;else{const n={...l.inject};for(const s in e.inject)n[s]=(n[s]||"")+e.inject[s];t.inject=n}return t}export{Mt as M,Un as a,cs as f,ls as m,De as u};
843
+ //# sourceMappingURL=shader-BJmsOfPx.js.map