@luma.gl/shadertools 9.1.9 → 9.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/dist.dev.js +1614 -3716
  2. package/dist/dist.min.js +278 -484
  3. package/dist/index.cjs +366 -804
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +0 -6
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -10
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/shader-assembly/assemble-shaders.d.ts +6 -4
  10. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  11. package/dist/lib/shader-assembly/assemble-shaders.js +14 -9
  12. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  13. package/dist/lib/shader-assembly/platform-info.d.ts +1 -1
  14. package/dist/lib/shader-assembly/platform-info.d.ts.map +1 -1
  15. package/dist/lib/shader-module/shader-module.d.ts +1 -1
  16. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  17. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +1 -1
  18. package/dist/lib/wgsl/get-shader-layout-wgsl.js +3 -1
  19. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +1 -1
  20. package/dist/modules/engine/project/project.d.ts.map +1 -1
  21. package/dist/modules/engine/project/project.js +4 -2
  22. package/dist/modules/engine/project/project.js.map +1 -1
  23. package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
  24. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  25. package/dist/modules/lighting/lights/{lighting-uniforms-glsl.d.ts → lighting-glsl.d.ts} +1 -1
  26. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -0
  27. package/dist/modules/lighting/lights/{lighting-uniforms-glsl.js → lighting-glsl.js} +1 -1
  28. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -0
  29. package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.d.ts → lighting-wgsl.d.ts} +1 -1
  30. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -0
  31. package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.js → lighting-wgsl.js} +1 -1
  32. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -0
  33. package/dist/modules/lighting/lights/lighting.d.ts +1 -3
  34. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  35. package/dist/modules/lighting/lights/lighting.js +4 -4
  36. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  37. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  38. package/dist/modules/lighting/no-material/dirlight.js +1 -2
  39. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  40. package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.d.ts → pbr-material-glsl.d.ts} +2 -1
  41. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -0
  42. package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.js → pbr-material-glsl.js} +36 -1
  43. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -0
  44. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +3 -0
  45. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -0
  46. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +487 -0
  47. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -0
  48. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +11 -4
  49. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  50. package/dist/modules/lighting/pbr-material/pbr-material.js +12 -12
  51. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  52. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  53. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  54. package/dist/modules/lighting/phong-material/phong-material.js +1 -1
  55. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  56. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -1
  57. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  58. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +2 -0
  59. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  60. package/dist/modules/math/random/random.d.ts +1 -0
  61. package/dist/modules/math/random/random.d.ts.map +1 -1
  62. package/dist/modules/math/random/random.js +7 -0
  63. package/dist/modules/math/random/random.js.map +1 -1
  64. package/package.json +3 -3
  65. package/src/index.ts +0 -17
  66. package/src/lib/shader-assembly/assemble-shaders.ts +12 -11
  67. package/src/lib/shader-assembly/platform-info.ts +1 -1
  68. package/src/lib/shader-module/shader-module.ts +1 -1
  69. package/src/lib/wgsl/get-shader-layout-wgsl.ts +7 -5
  70. package/src/modules/engine/project/project.ts +8 -5
  71. package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
  72. package/src/modules/lighting/lights/lighting.ts +4 -4
  73. package/src/modules/lighting/no-material/dirlight.ts +2 -3
  74. package/src/modules/lighting/pbr-material/{pbr-fragment-glsl.ts → pbr-material-glsl.ts} +36 -1
  75. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +490 -0
  76. package/src/modules/lighting/pbr-material/pbr-material.ts +12 -12
  77. package/src/modules/lighting/pbr-material/pbr-projection.ts +0 -2
  78. package/src/modules/lighting/phong-material/phong-material.ts +1 -1
  79. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -0
  80. package/src/modules/math/random/random.ts +8 -0
  81. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +0 -1
  82. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js.map +0 -1
  83. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +0 -1
  84. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js.map +0 -1
  85. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +0 -1
  86. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js.map +0 -1
  87. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
  88. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
  89. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -67
  90. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js.map +0 -1
  91. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +0 -2
  92. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +0 -1
  93. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +0 -39
  94. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js.map +0 -1
  95. package/dist/modules/module-injectors.d.ts +0 -3
  96. package/dist/modules/module-injectors.d.ts.map +0 -1
  97. package/dist/modules/module-injectors.js +0 -31
  98. package/dist/modules/module-injectors.js.map +0 -1
  99. package/dist/modules-webgl1/geometry/geometry.d.ts +0 -9
  100. package/dist/modules-webgl1/geometry/geometry.d.ts.map +0 -1
  101. package/dist/modules-webgl1/geometry/geometry.js +0 -39
  102. package/dist/modules-webgl1/geometry/geometry.js.map +0 -1
  103. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +0 -10
  104. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +0 -1
  105. package/dist/modules-webgl1/lighting/dirlight/dirlight.js +0 -38
  106. package/dist/modules-webgl1/lighting/dirlight/dirlight.js.map +0 -1
  107. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +0 -2
  108. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +0 -1
  109. package/dist/modules-webgl1/lighting/lights/lights-glsl.js +0 -40
  110. package/dist/modules-webgl1/lighting/lights/lights-glsl.js.map +0 -1
  111. package/dist/modules-webgl1/lighting/lights/lights.d.ts +0 -38
  112. package/dist/modules-webgl1/lighting/lights/lights.d.ts.map +0 -1
  113. package/dist/modules-webgl1/lighting/lights/lights.js +0 -93
  114. package/dist/modules-webgl1/lighting/lights/lights.js.map +0 -1
  115. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +0 -2
  116. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +0 -1
  117. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +0 -393
  118. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js.map +0 -1
  119. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +0 -2
  120. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +0 -1
  121. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +0 -43
  122. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js.map +0 -1
  123. package/dist/modules-webgl1/lighting/pbr/pbr.d.ts +0 -23
  124. package/dist/modules-webgl1/lighting/pbr/pbr.d.ts.map +0 -1
  125. package/dist/modules-webgl1/lighting/pbr/pbr.js +0 -21
  126. package/dist/modules-webgl1/lighting/pbr/pbr.js.map +0 -1
  127. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +0 -2
  128. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +0 -1
  129. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +0 -79
  130. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js.map +0 -1
  131. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts +0 -45
  132. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts.map +0 -1
  133. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js +0 -44
  134. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js.map +0 -1
  135. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +0 -2
  136. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +0 -1
  137. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +0 -171
  138. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js.map +0 -1
  139. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +0 -2
  140. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +0 -1
  141. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +0 -675
  142. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js.map +0 -1
  143. package/dist/modules-webgl1/math/fp64/fp64.d.ts +0 -35
  144. package/dist/modules-webgl1/math/fp64/fp64.d.ts.map +0 -1
  145. package/dist/modules-webgl1/math/fp64/fp64.js +0 -38
  146. package/dist/modules-webgl1/math/fp64/fp64.js.map +0 -1
  147. package/dist/modules-webgl1/project/project.d.ts +0 -20
  148. package/dist/modules-webgl1/project/project.d.ts.map +0 -1
  149. package/dist/modules-webgl1/project/project.js +0 -114
  150. package/dist/modules-webgl1/project/project.js.map +0 -1
  151. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -67
  152. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +0 -39
  153. package/src/modules/module-injectors.ts +0 -32
  154. package/src/modules-webgl1/geometry/geometry.ts +0 -41
  155. package/src/modules-webgl1/lighting/dirlight/dirlight.ts +0 -50
  156. package/src/modules-webgl1/lighting/lights/lights-glsl.ts +0 -40
  157. package/src/modules-webgl1/lighting/lights/lights.ts +0 -143
  158. package/src/modules-webgl1/lighting/pbr/README.md +0 -12
  159. package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +0 -396
  160. package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +0 -43
  161. package/src/modules-webgl1/lighting/pbr/pbr.ts +0 -23
  162. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +0 -79
  163. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts +0 -64
  164. package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +0 -171
  165. package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +0 -675
  166. package/src/modules-webgl1/math/fp64/fp64.ts +0 -44
  167. package/src/modules-webgl1/project/README.md +0 -52
  168. package/src/modules-webgl1/project/project.ts +0 -135
  169. /package/src/modules/lighting/lights/{lighting-uniforms-glsl.ts → lighting-glsl.ts} +0 -0
  170. /package/src/modules/lighting/lights/{lighting-uniforms-wgsl.ts → lighting-wgsl.ts} +0 -0
package/dist/dist.min.js CHANGED
@@ -4,10 +4,10 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- "use strict";var __exports__=(()=>{var Ss=Object.create;var Ve=Object.defineProperty;var As=Object.getOwnPropertyDescriptor;var Ls=Object.getOwnPropertyNames;var Ts=Object.getPrototypeOf,Es=Object.prototype.hasOwnProperty;var Ms=(i,e,t)=>e in i?Ve(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var Cs=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Ns=(i,e)=>{for(var t in e)Ve(i,t,{get:e[t],enumerable:!0})},at=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ls(e))!Es.call(i,r)&&r!==t&&Ve(i,r,{get:()=>e[r],enumerable:!(n=As(e,r))||n.enumerable});return i},ct=(i,e,t)=>(at(i,e,"default"),t&&at(t,e,"default")),Jt=(i,e,t)=>(t=i!=null?Ss(Ts(i)):{},at(e||!i||!i.__esModule?Ve(t,"default",{value:i,enumerable:!0}):t,i)),Os=i=>at(Ve({},"__esModule",{value:!0}),i);var Hn=(i,e,t)=>(Ms(i,typeof e!="symbol"?e+"":e,t),t);var lt=Cs((so,Gn)=>{Gn.exports=globalThis.luma});var ot={};Ns(ot,{ShaderAssembler:()=>Ge,_getDependencyGraph:()=>He,_resolveModules:()=>nr,assembleGLSLShaderPair:()=>ht,capitalize:()=>ve,checkShaderModuleDeprecations:()=>ze,combineInjects:()=>er,convertToVec4:()=>on,dirlight:()=>Fn,dirlight1:()=>xs,fp32:()=>ns,fp64:()=>is,fp64LowPart:()=>rt,fp64arithmetic:()=>Pn,fp64ify:()=>Fe,fp64ifyMatrix4:()=>st,fromHalfFloat:()=>Jr,generateShaderForModule:()=>_r,geometry1:()=>ds,getPassthroughFS:()=>hr,getQualifierDetails:()=>fr,getShaderInfo:()=>ft,getShaderLayoutFromWGSL:()=>Sr,getShaderModuleDependencies:()=>We,getShaderModuleSource:()=>pt,getShaderModuleUniforms:()=>tr,gouraudLighting:()=>bs,gouraudMaterial:()=>Bn,initializeShaderModule:()=>ut,initializeShaderModules:()=>le,lighting:()=>ce,lights1:()=>Ae,pbr:()=>Is,pbrMaterial:()=>ms,phongLighting:()=>ys,phongMaterial:()=>Vn,picking:()=>os,preprocess:()=>mt,project1:()=>Qt,random:()=>ts,toHalfFloat:()=>Qr,typeToChannelCount:()=>mr,typeToChannelSuffix:()=>pr});ct(ot,Jt(lt(),1));function de(i,e){if(!i)throw new Error(e||"shadertools: assertion failed.")}var en={number:{type:"number",validate(i,e){return Number.isFinite(i)&&typeof e=="object"&&(e.max===void 0||i<=e.max)&&(e.min===void 0||i>=e.min)}},array:{type:"array",validate(i,e){return Array.isArray(i)||ArrayBuffer.isView(i)}}};function jn(i){let e={};for(let[t,n]of Object.entries(i))e[t]=Ps(n);return e}function Xn(i,e,t){let n={};for(let[r,s]of Object.entries(e))i&&r in i&&!s.private?(s.validate&&de(s.validate(i[r],s),`${t}: invalid ${r}`),n[r]=i[r]):n[r]=s.value;return n}function Ps(i){let e=qn(i);if(e!=="object")return{value:i,...en[e],type:e};if(typeof i=="object")return i?i.type!==void 0?{...i,...en[i.type],type:i.type}:i.value===void 0?{type:"object",value:i}:(e=qn(i.value),{...i,...en[e],type:e}):{type:"object",value:null};throw new Error("props")}function qn(i){return Array.isArray(i)||ArrayBuffer.isView(i)?"array":typeof i}var Yn=`#ifdef MODULE_LOGDEPTH
7
+ "use strict";var __exports__=(()=>{var yr=Object.create;var Ee=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var Ir=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Ar=(a,e,t)=>e in a?Ee(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var Tr=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Lr=(a,e)=>{for(var t in e)Ee(a,t,{get:e[t],enumerable:!0})},Qe=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of kr(e))!Sr.call(a,r)&&r!==t&&Ee(a,r,{get:()=>e[r],enumerable:!(n=wr(e,r))||n.enumerable});return a},Ye=(a,e,t)=>(Qe(a,e,"default"),t&&Qe(t,e,"default")),Rt=(a,e,t)=>(t=a!=null?yr(Ir(a)):{},Qe(e||!a||!a.__esModule?Ee(t,"default",{value:a,enumerable:!0}):t,a)),Er=a=>Qe(Ee({},"__esModule",{value:!0}),a);var vn=(a,e,t)=>(Ar(a,typeof e!="symbol"?e+"":e,t),t);var Je=Tr((Es,bn)=>{bn.exports=globalThis.luma});var Ze={};Lr(Ze,{ShaderAssembler:()=>De,_getDependencyGraph:()=>Fe,_resolveModules:()=>Cn,assembleGLSLShaderPair:()=>nt,capitalize:()=>pe,checkShaderModuleDeprecations:()=>Oe,combineInjects:()=>Ln,convertToVec4:()=>Gt,dirlight:()=>mn,fp32:()=>lr,fp64:()=>fr,fp64LowPart:()=>je,fp64arithmetic:()=>hn,fp64ify:()=>Te,fp64ifyMatrix4:()=>Xe,fromHalfFloat:()=>or,generateShaderForModule:()=>zn,getPassthroughFS:()=>Un,getQualifierDetails:()=>Vn,getShaderInfo:()=>tt,getShaderLayoutFromWGSL:()=>Jn,getShaderModuleDependencies:()=>Pe,getShaderModuleSource:()=>rt,getShaderModuleUniforms:()=>En,gouraudMaterial:()=>_n,initializeShaderModule:()=>et,initializeShaderModules:()=>ne,lighting:()=>te,pbrMaterial:()=>xr,phongMaterial:()=>gn,picking:()=>hr,preprocess:()=>st,random:()=>ar,toHalfFloat:()=>sr,typeToChannelCount:()=>Hn,typeToChannelSuffix:()=>$n});Ye(Ze,Rt(Je(),1));function le(a,e){if(!a)throw new Error(e||"shadertools: assertion failed.")}var Bt={number:{type:"number",validate(a,e){return Number.isFinite(a)&&typeof e=="object"&&(e.max===void 0||a<=e.max)&&(e.min===void 0||a>=e.min)}},array:{type:"array",validate(a,e){return Array.isArray(a)||ArrayBuffer.isView(a)}}};function yn(a){let e={};for(let[t,n]of Object.entries(a))e[t]=Cr(n);return e}function wn(a,e,t){let n={};for(let[r,s]of Object.entries(e))a&&r in a&&!s.private?(s.validate&&le(s.validate(a[r],s),`${t}: invalid ${r}`),n[r]=a[r]):n[r]=s.value;return n}function Cr(a){let e=xn(a);if(e!=="object")return{value:a,...Bt[e],type:e};if(typeof a=="object")return a?a.type!==void 0?{...a,...Bt[a.type],type:a.type}:a.value===void 0?{type:"object",value:a}:(e=xn(a.value),{...a,...Bt[e],type:e}):{type:"object",value:null};throw new Error("props")}function xn(a){return Array.isArray(a)||ArrayBuffer.isView(a)?"array":typeof a}var kn=`#ifdef MODULE_LOGDEPTH
8
8
  logdepth_adjustPosition(gl_Position);
9
9
  #endif
10
- `,Kn=`#ifdef MODULE_MATERIAL
10
+ `,In=`#ifdef MODULE_MATERIAL
11
11
  fragColor = material_filterColor(fragColor);
12
12
  #endif
13
13
 
@@ -27,10 +27,10 @@
27
27
  #ifdef MODULE_LOGDEPTH
28
28
  logdepth_setFragDepth();
29
29
  #endif
30
- `;var Rs={vertex:Yn,fragment:Kn},Zn=/void\s+main\s*\([^)]*\)\s*\{\n?/,Qn=/}\n?[^{}]*$/,tn=[],$e="__LUMA_INJECT_DECLARATIONS__";function Jn(i){let e={vertex:{},fragment:{}};for(let t in i){let n=i[t],r=Ds(t);typeof n=="string"&&(n={order:0,injection:n}),e[r][t]=n}return e}function Ds(i){let e=i.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function Ue(i,e,t,n=!1){let r=e==="vertex";for(let s in t){let a=t[s];a.sort((c,l)=>c.order-l.order),tn.length=a.length;for(let c=0,l=a.length;c<l;++c)tn[c]=a[c].injection;let o=`${tn.join(`
30
+ `;var Nr={vertex:kn,fragment:In},Sn=/void\s+main\s*\([^)]*\)\s*\{\n?/,An=/}\n?[^{}]*$/,Vt=[],Ce="__LUMA_INJECT_DECLARATIONS__";function Tn(a){let e={vertex:{},fragment:{}};for(let t in a){let n=a[t],r=Or(t);typeof n=="string"&&(n={order:0,injection:n}),e[r][t]=n}return e}function Or(a){let e=a.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function Ne(a,e,t,n=!1){let r=e==="vertex";for(let s in t){let i=t[s];i.sort((l,c)=>l.order-c.order),Vt.length=i.length;for(let l=0,c=i.length;l<c;++l)Vt[l]=i[l].injection;let o=`${Vt.join(`
31
31
  `)}
32
- `;switch(s){case"vs:#decl":r&&(i=i.replace($e,o));break;case"vs:#main-start":r&&(i=i.replace(Zn,c=>c+o));break;case"vs:#main-end":r&&(i=i.replace(Qn,c=>o+c));break;case"fs:#decl":r||(i=i.replace($e,o));break;case"fs:#main-start":r||(i=i.replace(Zn,c=>c+o));break;case"fs:#main-end":r||(i=i.replace(Qn,c=>o+c));break;default:i=i.replace(s,c=>c+o)}}return i=i.replace($e,""),n&&(i=i.replace(/\}\s*$/,s=>s+Rs[e])),i}function er(i){let e={};return de(Array.isArray(i)&&i.length>1),i.forEach(t=>{for(let n in t)e[n]=e[n]?`${e[n]}
33
- ${t[n]}`:t[n]}),e}function le(i){i.map(e=>ut(e))}function ut(i){if(i.instance)return;le(i.dependencies||[]);let{propTypes:e={},deprecations:t=[],inject:n={}}=i,r={normalizedInjections:Jn(n),parsedDeprecations:Fs(t)};e&&(r.propValidators=jn(e)),i.instance=r;let s={};e&&(s=Object.entries(e).reduce((a,[o,c])=>{let l=c?.value;return l&&(a[o]=l),a},{})),i.defaultUniforms={...i.defaultUniforms,...s}}function tr(i,e,t){ut(i);let n=t||{...i.defaultUniforms};return e&&i.getUniforms?i.getUniforms(e,n):Xn(e,i.instance?.propValidators,i.name)}function ze(i,e,t){i.deprecations?.forEach(n=>{n.regex?.test(e)&&(n.deprecated?t.deprecated(n.old,n.new)():t.removed(n.old,n.new)())})}function Fs(i){return i.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),i}function We(i){le(i);let e={},t={};He({modules:i,level:0,moduleMap:e,moduleDepth:t});let n=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return le(n),n}function He(i){let{modules:e,level:t,moduleMap:n,moduleDepth:r}=i;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(let s of e)n[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(let s of e)s.dependencies&&He({modules:s.dependencies,level:t+1,moduleMap:n,moduleDepth:r})}function Bs(i){le(i);let e={},t={};return He({modules:i,level:0,moduleMap:e,moduleDepth:t}),i=Object.keys(t).sort((n,r)=>t[r]-t[n]).map(n=>e[n]),le(i),i}function nr(i){return Bs(i)}function rr(i){switch(i?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
32
+ `;switch(s){case"vs:#decl":r&&(a=a.replace(Ce,o));break;case"vs:#main-start":r&&(a=a.replace(Sn,l=>l+o));break;case"vs:#main-end":r&&(a=a.replace(An,l=>o+l));break;case"fs:#decl":r||(a=a.replace(Ce,o));break;case"fs:#main-start":r||(a=a.replace(Sn,l=>l+o));break;case"fs:#main-end":r||(a=a.replace(An,l=>o+l));break;default:a=a.replace(s,l=>l+o)}}return a=a.replace(Ce,""),n&&(a=a.replace(/\}\s*$/,s=>s+Nr[e])),a}function Ln(a){let e={};return le(Array.isArray(a)&&a.length>1),a.forEach(t=>{for(let n in t)e[n]=e[n]?`${e[n]}
33
+ ${t[n]}`:t[n]}),e}function ne(a){a.map(e=>et(e))}function et(a){if(a.instance)return;ne(a.dependencies||[]);let{propTypes:e={},deprecations:t=[],inject:n={}}=a,r={normalizedInjections:Tn(n),parsedDeprecations:Pr(t)};e&&(r.propValidators=yn(e)),a.instance=r;let s={};e&&(s=Object.entries(e).reduce((i,[o,l])=>{let c=l?.value;return c&&(i[o]=c),i},{})),a.defaultUniforms={...a.defaultUniforms,...s}}function En(a,e,t){et(a);let n=t||{...a.defaultUniforms};return e&&a.getUniforms?a.getUniforms(e,n):wn(e,a.instance?.propValidators,a.name)}function Oe(a,e,t){a.deprecations?.forEach(n=>{n.regex?.test(e)&&(n.deprecated?t.deprecated(n.old,n.new)():t.removed(n.old,n.new)())})}function Pr(a){return a.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),a}function Pe(a){ne(a);let e={},t={};Fe({modules:a,level:0,moduleMap:e,moduleDepth:t});let n=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return ne(n),n}function Fe(a){let{modules:e,level:t,moduleMap:n,moduleDepth:r}=a;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(let s of e)n[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(let s of e)s.dependencies&&Fe({modules:s.dependencies,level:t+1,moduleMap:n,moduleDepth:r})}function Fr(a){ne(a);let e={},t={};return Fe({modules:a,level:0,moduleMap:e,moduleDepth:t}),a=Object.keys(t).sort((n,r)=>t[r]-t[n]).map(n=>e[n]),ne(a),a}function Cn(a){return Fr(a)}function Nn(a){switch(a?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
34
34
  // Apple optimizes away the calculation necessary for emulated fp64
35
35
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
36
36
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
@@ -54,58 +54,60 @@ ${t[n]}`:t[n]}),e}function le(i){i.map(e=>ut(e))}function ut(i){if(i.instance)re
54
54
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
55
55
  // If the GPU doesn't have full 32 bits precision, will causes overflow
56
56
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
57
- `}}function ir(i,e){if(Number(i.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return i=sr(i,Vs),i;case"fragment":return i=sr(i,$s),i;default:throw new Error(e)}}var or=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
58
- `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Vs=[...or,[nn("attribute"),"in $1"],[nn("varying"),"out $1"]],$s=[...or,[nn("varying"),"in $1"]];function sr(i,e){for(let[t,n]of e)i=i.replace(t,n);return i}function nn(i){return new RegExp(`\\b${i}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function rn(i,e){let t="";for(let n in i){let r=i[n];if(t+=`void ${r.signature} {
59
- `,r.header&&(t+=` ${r.header}`),e[n]){let s=e[n];s.sort((a,o)=>a.order-o.order);for(let a of s)t+=` ${a.injection}
57
+ `}}function Pn(a,e){if(Number(a.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return a=On(a,Dr),a;case"fragment":return a=On(a,Mr),a;default:throw new Error(e)}}var Fn=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
58
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Dr=[...Fn,[Ut("attribute"),"in $1"],[Ut("varying"),"out $1"]],Mr=[...Fn,[Ut("varying"),"in $1"]];function On(a,e){for(let[t,n]of e)a=a.replace(t,n);return a}function Ut(a){return new RegExp(`\\b${a}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function $t(a,e){let t="";for(let n in a){let r=a[n];if(t+=`void ${r.signature} {
59
+ `,r.header&&(t+=` ${r.header}`),e[n]){let s=e[n];s.sort((i,o)=>i.order-o.order);for(let i of s)t+=` ${i.injection}
60
60
  `}r.footer&&(t+=` ${r.footer}`),t+=`}
61
- `}return t}function sn(i){let e={vertex:{},fragment:{}};for(let t of i){let n,r;typeof t!="string"?(n=t,r=n.hook):(n={},r=t),r=r.trim();let[s,a]=r.split(":"),o=r.replace(/\(.+/,""),c=Object.assign(n,{signature:a});switch(s){case"vs":e.vertex[o]=c;break;case"fs":e.fragment[o]=c;break;default:throw new Error(s)}}return e}function ft(i,e){return{name:Us(i,e),language:"glsl",version:zs(i)}}function Us(i,e="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(i);return n?n[1]:e}function zs(i){let e=100,t=i.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let n=parseInt(t[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var cr=`
61
+ `}return t}function Ht(a){let e={vertex:{},fragment:{}};for(let t of a){let n,r;typeof t!="string"?(n=t,r=n.hook):(n={},r=t),r=r.trim();let[s,i]=r.split(":"),o=r.replace(/\(.+/,""),l=Object.assign(n,{signature:i});switch(s){case"vs":e.vertex[o]=l;break;case"fs":e.fragment[o]=l;break;default:throw new Error(s)}}return e}function tt(a,e){return{name:Rr(a,e),language:"glsl",version:Br(a)}}function Rr(a,e="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(a);return n?n[1]:e}function Br(a){let e=100,t=a.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let n=parseInt(t[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var Mn=`
62
62
 
63
- ${$e}
64
- `,Ws=`precision highp float;
65
- `;function lr(i){let e=We(i.modules||[]);return{source:Hs(i.platformInfo,{...i,source:i.source,stage:"vertex",modules:e}),getUniforms:ur(e)}}function ht(i){let{vs:e,fs:t}=i,n=We(i.modules||[]);return{vs:ar(i.platformInfo,{...i,source:e,stage:"vertex",modules:n}),fs:ar(i.platformInfo,{...i,source:t,stage:"fragment",modules:n}),getUniforms:ur(n)}}function Hs(i,e){let{source:t,stage:n,modules:r,hookFunctions:s=[],inject:a={},log:o}=e;de(typeof t=="string","shader source must be a string");let c=t,l="",u=sn(s),f={},_={},b={};for(let L in a){let S=typeof a[L]=="string"?{injection:a[L],order:0}:a[L],E=/^(v|f)s:(#)?([\w-]+)$/.exec(L);if(E){let T=E[2],k=E[3];T?k==="decl"?_[L]=[S]:b[L]=[S]:f[L]=[S]}else b[L]=[S]}let w=r;for(let L of w){o&&ze(L,c,o);let S=pt(L,"wgsl");l+=S;let E=L.injections?.[n]||{};for(let T in E){let k=/^(v|f)s:#([\w-]+)$/.exec(T);if(k){let C=k[2]==="decl"?_:b;C[T]=C[T]||[],C[T].push(E[T])}else f[T]=f[T]||[],f[T].push(E[T])}}return l+=cr,l=Ue(l,n,_),l+=rn(u[n],f),l+=c,l=Ue(l,n,b),l}function ar(i,e){let{id:t,source:n,stage:r,language:s="glsl",modules:a,defines:o={},hookFunctions:c=[],inject:l={},prologue:u=!0,log:f}=e;de(typeof n=="string","shader source must be a string");let _=s==="glsl"?ft(n).version:-1,b=i.shaderLanguageVersion,w=_===100?"#version 100":"#version 300 es",S=n.split(`
63
+ ${Ce}
64
+ `,Vr=`precision highp float;
65
+ `;function Rn(a){let e=Pe(a.modules||[]);return{source:Ur(a.platformInfo,{...a,source:a.source,stage:"vertex",modules:e}),getUniforms:Bn(e)}}function nt(a){let{vs:e,fs:t}=a,n=Pe(a.modules||[]);return{vs:Dn(a.platformInfo,{...a,source:e,stage:"vertex",modules:n}),fs:Dn(a.platformInfo,{...a,source:t,stage:"fragment",modules:n}),getUniforms:Bn(n)}}function Ur(a,e){let{source:t,stage:n,modules:r,hookFunctions:s=[],inject:i={},log:o}=e;le(typeof t=="string","shader source must be a string");let l=t,c="",u=Ht(s),h={},b={},y={};for(let E in i){let T=typeof i[E]=="string"?{injection:i[E],order:0}:i[E],L=/^(v|f)s:(#)?([\w-]+)$/.exec(E);if(L){let P=L[2],k=L[3];P?k==="decl"?b[E]=[T]:y[E]=[T]:h[E]=[T]}else y[E]=[T]}let S=r;for(let E of S){o&&Oe(E,l,o);let T=rt(E,"wgsl");c+=T;let L=E.injections?.[n]||{};for(let P in L){let k=/^(v|f)s:#([\w-]+)$/.exec(P);if(k){let B=k[2]==="decl"?b:y;B[P]=B[P]||[],B[P].push(L[P])}else h[P]=h[P]||[],h[P].push(L[P])}}return c+=Mn,c=Ne(c,n,b),c+=$t(u[n],h),c+=l,c=Ne(c,n,y),c}function Dn(a,e){let{source:t,stage:n,language:r="glsl",modules:s,defines:i={},hookFunctions:o=[],inject:l={},prologue:c=!0,log:u}=e;le(typeof t=="string","shader source must be a string");let h=r==="glsl"?tt(t).version:-1,b=a.shaderLanguageVersion,y=h===100?"#version 100":"#version 300 es",E=t.split(`
66
66
  `).slice(1).join(`
67
- `),E={};a.forEach(O=>{Object.assign(E,O.defines)}),Object.assign(E,o);let T="";switch(s){case"wgsl":break;case"glsl":T=u?`${w}
67
+ `),T={};s.forEach(O=>{Object.assign(T,O.defines)}),Object.assign(T,i);let L="";switch(r){case"wgsl":break;case"glsl":L=c?`${y}
68
68
 
69
69
  // ----- PROLOGUE -------------------------
70
- ${Gs({id:t,source:n,stage:r})}
71
- ${`#define SHADER_TYPE_${r.toUpperCase()}`}
70
+ ${`#define SHADER_TYPE_${n.toUpperCase()}`}
72
71
 
73
- ${rr(i)}
74
- ${r==="fragment"?Ws:""}
72
+ ${Nn(a)}
73
+ ${n==="fragment"?Vr:""}
75
74
 
76
75
  // ----- APPLICATION DEFINES -------------------------
77
76
 
78
- ${qs(E)}
77
+ ${$r(T)}
79
78
 
80
- `:`${w}
81
- `;break}let k=sn(c),I={},C={},M={};for(let O in l){let V=typeof l[O]=="string"?{injection:l[O],order:0}:l[O],F=/^(v|f)s:(#)?([\w-]+)$/.exec(O);if(F){let D=F[2],W=F[3];D?W==="decl"?C[O]=[V]:M[O]=[V]:I[O]=[V]}else M[O]=[V]}for(let O of a){f&&ze(O,S,f);let V=pt(O,r);T+=V;let F=O.instance?.normalizedInjections[r]||{};for(let D in F){let W=/^(v|f)s:#([\w-]+)$/.exec(D);if(W){let j=W[2]==="decl"?C:M;j[D]=j[D]||[],j[D].push(F[D])}else I[D]=I[D]||[],I[D].push(F[D])}}return T+="// ----- MAIN SHADER SOURCE -------------------------",T+=cr,T=Ue(T,r,C),T+=rn(k[r],I),T+=S,T=Ue(T,r,M),s==="glsl"&&_!==b&&(T=ir(T,r)),T.trim()}function ur(i){return function(t){let n={};for(let r of i){let s=r.getUniforms?.(t,n);Object.assign(n,s)}return n}}function Gs(i){let{id:e,source:t,stage:n}=i;return e&&t.indexOf("SHADER_NAME")===-1?`
82
- #define SHADER_NAME ${e}_${n}`:""}function qs(i={}){let e="";for(let t in i){let n=i[t];(n||Number.isFinite(n))&&(e+=`#define ${t.toUpperCase()} ${i[t]}
83
- `)}return e}function pt(i,e){let t;switch(e){case"vertex":t=i.vs||"";break;case"fragment":t=i.fs||"";break;case"wgsl":t=i.source||"";break;default:de(!1)}if(!i.name)throw new Error("Shader module must have a name");let n=i.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),r=`// ----- MODULE ${i.name} ---------------
79
+ `:`${y}
80
+ `;break}let P=Ht(o),k={},A={},B={};for(let O in l){let oe=typeof l[O]=="string"?{injection:l[O],order:0}:l[O],X=/^(v|f)s:(#)?([\w-]+)$/.exec(O);if(X){let U=X[2],he=X[3];U?he==="decl"?A[O]=[oe]:B[O]=[oe]:k[O]=[oe]}else B[O]=[oe]}for(let O of s){u&&Oe(O,E,u);let oe=rt(O,n);L+=oe;let X=O.instance?.normalizedInjections[n]||{};for(let U in X){let he=/^(v|f)s:#([\w-]+)$/.exec(U);if(he){let Mt=he[2]==="decl"?A:B;Mt[U]=Mt[U]||[],Mt[U].push(X[U])}else k[U]=k[U]||[],k[U].push(X[U])}}return L+="// ----- MAIN SHADER SOURCE -------------------------",L+=Mn,L=Ne(L,n,A),L+=$t(P[n],k),L+=E,L=Ne(L,n,B),r==="glsl"&&h!==b&&(L=Pn(L,n)),L.trim()}function Bn(a){return function(t){let n={};for(let r of a){let s=r.getUniforms?.(t,n);Object.assign(n,s)}return n}}function $r(a={}){let e="";for(let t in a){let n=a[t];(n||Number.isFinite(n))&&(e+=`#define ${t.toUpperCase()} ${a[t]}
81
+ `)}return e}function rt(a,e){let t;switch(e){case"vertex":t=a.vs||"";break;case"fragment":t=a.fs||"";break;case"wgsl":t=a.source||"";break;default:le(!1)}if(!a.name)throw new Error("Shader module must have a name");let n=a.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),r=`// ----- MODULE ${a.name} ---------------
84
82
 
85
83
  `;return e!=="wgsl"&&(r+=`#define MODULE_${n}
86
84
  `),r+=`${t}
87
- `,r}var js=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Xs=/^\s*\#\s*endif\s*$/;function mt(i,e){let t=i.split(`
88
- `),n=[],r=!0,s=null;for(let a of t){let o=a.match(js),c=a.match(Xs);o?(s=o[1],r=Boolean(e?.defines?.[s])):c?r=!0:r&&n.push(a)}return n.join(`
89
- `)}var Le=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return Le.defaultShaderAssembler=Le.defaultShaderAssembler||new Le,Le.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){let t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:s}=lr({...e,source:e.source,modules:t,hookFunctions:n});return{source:e.platformInfo.shaderLanguage==="wgsl"?mt(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){let t=this._getModuleList(e.modules),n=this._hookFunctions;return{...ht({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n}),modules:t}}_getModuleList(e=[]){let t=new Array(this._defaultModules.length+e.length),n={},r=0;for(let s=0,a=this._defaultModules.length;s<a;++s){let o=this._defaultModules[s],c=o.name;t[r++]=o,n[c]=!0}for(let s=0,a=e.length;s<a;++s){let o=e[s],c=o.name;n[c]||(t[r++]=o,n[c]=!0)}return t.length=r,le(t),t}},Ge=Le;Hn(Ge,"defaultShaderAssembler");var Ys=`out vec4 transform_output;
85
+ `,r}var Hr=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Gr=/^\s*\#\s*endif\s*$/;function st(a,e){let t=a.split(`
86
+ `),n=[],r=!0,s=null;for(let i of t){let o=i.match(Hr),l=i.match(Gr);o?(s=o[1],r=Boolean(e?.defines?.[s])):l?r=!0:r&&n.push(i)}return n.join(`
87
+ `)}var be=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return be.defaultShaderAssembler=be.defaultShaderAssembler||new be,be.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){let t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:s}=Rn({...e,source:e.source,modules:t,hookFunctions:n});return{source:e.platformInfo.shaderLanguage==="wgsl"?st(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){let t=this._getModuleList(e.modules),n=this._hookFunctions;return{...nt({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n}),modules:t}}_getModuleList(e=[]){let t=new Array(this._defaultModules.length+e.length),n={},r=0;for(let s=0,i=this._defaultModules.length;s<i;++s){let o=this._defaultModules[s],l=o.name;t[r++]=o,n[l]=!0}for(let s=0,i=e.length;s<i;++s){let o=e[s],l=o.name;n[l]||(t[r++]=o,n[l]=!0)}return t.length=r,ne(t),t}},De=be;vn(De,"defaultShaderAssembler");var Wr=`out vec4 transform_output;
90
88
  void main() {
91
89
  transform_output = vec4(0);
92
- }`,Ks=`#version 300 es
93
- ${Ys}`;function fr(i,e){e=Array.isArray(e)?e:[e];let t=i.replace(/^\s+/,"").split(/\s+/),[n,r,s]=t;if(!e.includes(n)||!r||!s)return null;let a=s.split(";")[0];return{qualifier:n,type:r,name:a}}function hr(i){let{input:e,inputChannels:t,output:n}=i||{};if(!e)return Ks;if(!t)throw new Error("inputChannels");let r=Zs(t),s=on(e,t);return`#version 300 es
90
+ }`,zr=`#version 300 es
91
+ ${Wr}`;function Vn(a,e){e=Array.isArray(e)?e:[e];let t=a.replace(/^\s+/,"").split(/\s+/),[n,r,s]=t;if(!e.includes(n)||!r||!s)return null;let i=s.split(";")[0];return{qualifier:n,type:r,name:i}}function Un(a){let{input:e,inputChannels:t,output:n}=a||{};if(!e)return zr;if(!t)throw new Error("inputChannels");let r=qr(t),s=Gt(e,t);return`#version 300 es
94
92
  in ${r} ${e};
95
93
  out vec4 ${n};
96
94
  void main() {
97
95
  ${n} = ${s};
98
- }`}function pr(i){switch(i){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(i)}}function mr(i){switch(i){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(i)}}function Zs(i){switch(i){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${i}`)}}function on(i,e){switch(e){case 1:return`vec4(${i}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${i}, 0.0, 1.0)`;case 3:return`vec4(${i}, 1.0)`;case 4:return i;default:throw new Error(`invalid channels: ${e}`)}}function ve(i){return typeof i=="string"?i.charAt(0).toUpperCase()+i.slice(1):i}function dr(i,e){return Qs(i,e)}function Qs(i,e){let t=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":t.push(`uniform ${ve(i.name)} {`);break;case"uniforms":}for(let[n,r]of Object.entries(i.uniformTypes||{})){let s=Js(r);switch(e.uniforms){case"scoped-interface-blocks":t.push(` ${s} ${n};`);break;case"unscoped-interface-blocks":t.push(` ${s} ${i.name}_${n};`);break;case"uniforms":t.push(`uniform ${s} ${i.name}_${n};`)}}switch(e.uniforms){case"scoped-interface-blocks":t.push(`} ${i.name};`);break;case"unscoped-interface-blocks":t.push("};");break;case"uniforms":}return t.push(""),t.join(`
99
- `)}function Js(i){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[i]}function gr(i,e){return ei(i,e)}function ei(i,e){let t=[];t.push(`struct ${ve(i.name)} {`);for(let[n,r]of Object.entries(i?.uniformTypes||{})){let s=r;t.push(` ${n} : ${s};`)}return t.push("};"),t.push(`var<uniform> ${i.name} : ${ve(i.name)};`),t.join(`
100
- `)}function _r(i,e){switch(e.shaderLanguage){case"glsl":return dr(i,e);case"wgsl":return gr(i,e)}}var Ir=Jt(lt(),1);var Z=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}getTypeName(){return this.name}},dt=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},ue=class 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}},fe=class extends Z{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},he=class extends Z{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},ge;(i=>{i[i.Uniform=0]="Uniform",i[i.Storage=1]="Storage",i[i.Texture=2]="Texture",i[i.Sampler=3]="Sampler",i[i.StorageTexture=4]="StorageTexture"})(ge||(ge={}));var Te=class{constructor(e,t,n,r,s,a,o){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=a,this.access=o}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}},ln=class{constructor(e,t){this.name=e,this.type=t}},un=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},gt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},fn=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},hn=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},pn=class{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n}},mn=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},br=new Float32Array(1),ti=new Int32Array(br.buffer),q=new Uint16Array(1);function ni(i){br[0]=i;let e=ti[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return q[0]=t<<15|31744|(r!==0?512:0),q[0];if(n===0){if(r===0)return q[0]=t<<15,q[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),q[0]=t<<15|n<<10|r>>13,q[0]):(q[0]=t<<15,q[0])}return n=n-127+15,n>=31?(q[0]=t<<15|31744,q[0]):n<=0?n<-10?(q[0]=t<<15,q[0]):(r=(8388608|r)>>1-n,q[0]=t<<15|r>>13,q[0]):(r>>=13,q[0]=t<<15|n<<10|r,q[0])}var An=new Uint32Array(1),yr=new Float32Array(An.buffer,0,1);function xr(i){let e=112+(i>>6&31)<<23|(63&i)<<17;return An[0]=e,yr[0]}function ri(i,e,t,n,r,s,a,o,c){let l=n*(a>>=r)*(s>>=r)+t*a+e*o;switch(c){case"r8unorm":return[P(i,l,"8unorm",1)[0]];case"r8snorm":return[P(i,l,"8snorm",1)[0]];case"r8uint":return[P(i,l,"8uint",1)[0]];case"r8sint":return[P(i,l,"8sint",1)[0]];case"rg8unorm":{let u=P(i,l,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{let u=P(i,l,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{let u=P(i,l,"8uint",2);return[u[0],u[1]]}case"rg8sint":{let u=P(i,l,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let u=P(i,l,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{let u=P(i,l,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{let u=P(i,l,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{let u=P(i,l,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let u=P(i,l,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[P(i,l,"16uint",1)[0]];case"r16sint":return[P(i,l,"16sint",1)[0]];case"r16float":return[P(i,l,"16float",1)[0]];case"rg16uint":{let u=P(i,l,"16uint",2);return[u[0],u[1]]}case"rg16sint":{let u=P(i,l,"16sint",2);return[u[0],u[1]]}case"rg16float":{let u=P(i,l,"16float",2);return[u[0],u[1]]}case"rgba16uint":{let u=P(i,l,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{let u=P(i,l,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{let u=P(i,l,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[P(i,l,"32uint",1)[0]];case"r32sint":return[P(i,l,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[P(i,l,"32float",1)[0]];case"rg32uint":{let u=P(i,l,"32uint",2);return[u[0],u[1]]}case"rg32sint":{let u=P(i,l,"32sint",2);return[u[0],u[1]]}case"rg32float":{let u=P(i,l,"32float",2);return[u[0],u[1]]}case"rgba32uint":{let u=P(i,l,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{let u=P(i,l,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{let u=P(i,l,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{let u=new Uint32Array(i.buffer,l,1)[0],f=(4192256&u)>>11,_=(4290772992&u)>>22;return[xr(2047&u),xr(f),function(b){let w=112+(b>>5&31)<<23|(31&b)<<18;return An[0]=w,yr[0]}(_),1]}}return null}function P(i,e,t,n){let r=[0,0,0,0];for(let l=0;l<n;++l)switch(t){case"8unorm":r[l]=i[e]/255,e++;break;case"8snorm":r[l]=i[e]/255*2-1,e++;break;case"8uint":r[l]=i[e],e++;break;case"8sint":r[l]=i[e]-127,e++;break;case"16uint":r[l]=i[e]|i[e+1]<<8,e+=2;break;case"16sint":r[l]=(i[e]|i[e+1]<<8)-32768,e+=2;break;case"16float":r[l]=(s=i[e]|i[e+1]<<8,a=void 0,o=void 0,c=void 0,a=(32768&s)>>15,c=1023&s,(o=(31744&s)>>10)==0?(a?-1:1)*Math.pow(2,-14)*(c/Math.pow(2,10)):o==31?c?NaN:1/0*(a?-1:1):(a?-1:1)*Math.pow(2,o-15)*(1+c/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":r[l]=i[e]|i[e+1]<<8|i[e+2]<<16|i[e+3]<<24,e+=4;break;case"32float":r[l]=new Float32Array(i.buffer,e,1)[0],e+=4}var s,a,o,c;return r}function R(i,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":i[e]=255*r[s],e++;break;case"8snorm":i[e]=.5*(r[s]+1)*255,e++;break;case"8uint":i[e]=r[s],e++;break;case"8sint":i[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(i.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{let a=ni(r[s]);new Uint16Array(i.buffer,e,1)[0]=a,e+=2;break}case"32uint":new Uint32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(i.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(i.buffer,e,1)[0]=r[s],e+=4}return r}var an={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}},Q=class{constructor(){this.id=Q._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Oe.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Pe.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};Q._id=0;var Oe=class extends Q{};Oe.instance=new Oe;var Pe=class extends Q{};Pe.instance=new Pe;var wr=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),B=class extends Q{constructor(){super()}},ke=class extends B{constructor(e,t,n,r,s,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=a}get astNodeType(){return"function"}search(e){if(this.attributes)for(let t of this.attributes)e(t);e(this);for(let t of this.args)e(t);this.searchBlock(this.body,e)}},dn=class extends B{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},_t=class extends B{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)}},Xe=class extends B{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},xt=class extends B{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}},ae=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ye=class extends B{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)}},ye=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ce=class extends B{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ee,qe,v,g;(i=>{i.increment="++",i.decrement="--"})(Ee||(Ee={})),(i=>{i.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return i[t]}})(Ee||(Ee={}));var vt=class extends B{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(i=>{i.assign="=",i.addAssign="+=",i.subtractAssin="-=",i.multiplyAssign="*=",i.divideAssign="/=",i.moduloAssign="%=",i.andAssign="&=",i.orAssign="|=",i.xorAssign="^=",i.shiftLeftAssign="<<=",i.shiftRightAssign=">>="})(qe||(qe={})),(i=>{i.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(qe||(qe={}));var bt=class extends B{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)}},Ke=class extends B{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return wr.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},yt=class extends B{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},wt=class extends B{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}},kt=class extends B{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},It=class extends B{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},gn=class extends B{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},_n=class extends B{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},St=class extends B{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},Ze=class extends B{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},xn=class extends B{constructor(){super()}get astNodeType(){return"discard"}},At=class extends B{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},Lt=class extends B{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},y=class extends B{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=y._priority.get(t.name);y._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?y.i32:t}getTypeName(){return this.name}};y.x32=new y("x32"),y.f32=new y("f32"),y.i32=new y("i32"),y.u32=new y("u32"),y.f16=new y("f16"),y.bool=new y("bool"),y.void=new y("void"),y._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var Tt=class extends y{constructor(e){super(e)}},ie=class extends y{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(let t of this.members)e(t)}},x=class extends y{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};x.vec2f=new x("vec2",y.f32,null),x.vec3f=new x("vec3",y.f32,null),x.vec4f=new x("vec4",y.f32,null),x.vec2i=new x("vec2",y.i32,null),x.vec3i=new x("vec3",y.i32,null),x.vec4i=new x("vec4",y.i32,null),x.vec2u=new x("vec2",y.u32,null),x.vec3u=new x("vec3",y.u32,null),x.vec4u=new x("vec4",y.u32,null),x.vec2h=new x("vec2",y.f16,null),x.vec3h=new x("vec3",y.f16,null),x.vec4h=new x("vec4",y.f16,null),x.vec2b=new x("vec2",y.bool,null),x.vec3b=new x("vec3",y.bool,null),x.vec4b=new x("vec4",y.bool,null),x.mat2x2f=new x("mat2x2",y.f32,null),x.mat2x3f=new x("mat2x3",y.f32,null),x.mat2x4f=new x("mat2x4",y.f32,null),x.mat3x2f=new x("mat3x2",y.f32,null),x.mat3x3f=new x("mat3x3",y.f32,null),x.mat3x4f=new x("mat3x4",y.f32,null),x.mat4x2f=new x("mat4x2",y.f32,null),x.mat4x3f=new x("mat4x3",y.f32,null),x.mat4x4f=new x("mat4x4",y.f32,null),x.mat2x2h=new x("mat2x2",y.f16,null),x.mat2x3h=new x("mat2x3",y.f16,null),x.mat2x4h=new x("mat2x4",y.f16,null),x.mat3x2h=new x("mat3x2",y.f16,null),x.mat3x3h=new x("mat3x3",y.f16,null),x.mat3x4h=new x("mat3x4",y.f16,null),x.mat4x2h=new x("mat4x2",y.f16,null),x.mat4x3h=new x("mat4x3",y.f16,null),x.mat4x4h=new x("mat4x4",y.f16,null),x.mat2x2i=new x("mat2x2",y.i32,null),x.mat2x3i=new x("mat2x3",y.i32,null),x.mat2x4i=new x("mat2x4",y.i32,null),x.mat3x2i=new x("mat3x2",y.i32,null),x.mat3x3i=new x("mat3x3",y.i32,null),x.mat3x4i=new x("mat3x4",y.i32,null),x.mat4x2i=new x("mat4x2",y.i32,null),x.mat4x3i=new x("mat4x3",y.i32,null),x.mat4x4i=new x("mat4x4",y.i32,null),x.mat2x2u=new x("mat2x2",y.u32,null),x.mat2x3u=new x("mat2x3",y.u32,null),x.mat2x4u=new x("mat2x4",y.u32,null),x.mat3x2u=new x("mat3x2",y.u32,null),x.mat3x3u=new x("mat3x3",y.u32,null),x.mat3x4u=new x("mat3x4",y.u32,null),x.mat4x2u=new x("mat4x2",y.u32,null),x.mat4x3u=new x("mat4x3",y.u32,null),x.mat4x4u=new x("mat4x4",y.u32,null);var je=class extends y{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},we=class extends y{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},be=class extends y{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},se=class extends Q{constructor(){super(),this.postfix=null}},pe=class extends se{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},ne=class extends se{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}},Qe=class extends se{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return wr.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(let t of this.args)t.search(e);e(this)}},Y=class extends se{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)}},Et=class extends se{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},H=class extends se{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 m}get isVector(){return this.value instanceof p||this.value instanceof N}get scalarValue(){return this.value instanceof m?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof p||this.value instanceof N?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},Mt=class extends se{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}};var xe=class extends se{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ct=class extends se{constructor(){super()}},z=class extends Ct{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},ee=class extends Ct{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"?y.f32:e.name==="u32"||t.name==="u32"?y.u32:y.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},Nt=class extends Q{constructor(e){super(),this.body=e}},Ne=class extends se{constructor(){super()}get astNodeType(){return"default"}},Ot=class extends Nt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Pt=class extends Nt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Rt=class extends Q{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},vn=class extends Q{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)}},Dt=class extends Q{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},Ft=class extends Q{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},J=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=J._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.name}>`}};J._id=0;var Je=class extends J{constructor(){super(new Z("void",null),null)}toString(){return"void"}};Je.void=new Je;var _e=class extends J{constructor(e){super(new Z("pointer",null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}},m=class extends J{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!=0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new m(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new m(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new m(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(t instanceof m))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}};function si(i,e,t){let n=e.length;return n===2?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec2i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec2u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec3i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec3u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new p(new Float32Array(e),i.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new p(new Int32Array(e),i.getTypeInfo("vec4i")):t==="u32"?new p(new Uint32Array(e),i.getTypeInfo("vec4u")):t==="f16"?new p(new Float32Array(e),i.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var p=class extends J{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new p(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new p(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new p(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof pe?console.error("TODO: Set vector postfix"):t instanceof p?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof he)r=this.typeInfo.format||r;else{let a=this.typeInfo.name;a==="vec2f"||a==="vec3f"||a==="vec4f"?r=e.getTypeInfo("f32"):a==="vec2i"||a==="vec3i"||a==="vec4i"?r=e.getTypeInfo("i32"):a==="vec2b"||a==="vec3b"||a==="vec4b"?r=e.getTypeInfo("bool"):a==="vec2u"||a==="vec3u"||a==="vec4u"?r=e.getTypeInfo("u32"):a==="vec2h"||a==="vec3h"||a==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${a}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof xe){let a=t.index,o=-1;if(a instanceof H){if(!(a.value instanceof m))return console.error(`GetSubData: Invalid array index ${a.value}`),null;o=a.value.value}else{let c=e.evalExpression(a,n);if(!(c instanceof m))return console.error("GetSubData: Unknown index type",a),null;o=c.value}if(o<0||o>=s.data.length)return console.error("GetSubData: Index out of range",o),null;if(s.data instanceof Float32Array){let c=new Float32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}if(s.data instanceof Int32Array){let c=new Int32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}if(s.data instanceof Uint32Array){let c=new Uint32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new m(c,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof pe))return console.error("GetSubData: Unknown postfix",t),null;{let a=t.value.toLowerCase();if(a.length===1){let c=0;if(a==="x"||a==="r")c=0;else if(a==="y"||a==="g")c=1;else if(a==="z"||a==="b")c=2;else{if(a!=="w"&&a!=="a")return console.error(`GetSubData: Unknown member ${a}`),null;c=3}if(this.data instanceof Float32Array){let l=new Float32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}if(this.data instanceof Int32Array){let l=new Int32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}if(this.data instanceof Uint32Array){let l=new Uint32Array(this.data.buffer,this.data.byteOffset+4*c,1);return new m(l,r,this)}}let o=[];for(let c of a)c==="x"||c==="r"?o.push(this.data[0]):c==="y"||c==="g"?o.push(this.data[1]):c==="z"||c==="b"?o.push(this.data[2]):c==="w"||c==="a"?o.push(this.data[3]):console.error(`GetDataValue: Unknown member ${c}`);s=si(e,o,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},N=class extends J{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new N(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof pe?console.error("TODO: Set matrix postfix"):t instanceof N?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof he)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof xe){let s=t.index,a=-1;if(s instanceof H){if(!(s.value instanceof m))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;a=s.value.value}else{let l=e.evalExpression(s,n);if(!(l instanceof m))return console.error("GetDataValue: Unknown index type",s),null;a=l.value}if(a<0||a>=this.data.length)return console.error("GetDataValue: Index out of range",a),null;let o=r.endsWith("h")?"h":"f",c;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+2*a*4,2),e.getTypeInfo(`vec2${o}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+3*a*4,3),e.getTypeInfo(`vec3${o}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;c=new p(new Float32Array(this.data.buffer,this.data.byteOffset+4*a*4,4),e.getTypeInfo(`vec4${o}`))}return t.postfix?c.getSubData(e,t.postfix,n):c}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},U=class extends J{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new U(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,a=this.typeInfo;for(;n;){if(n instanceof xe)if(a instanceof fe){let o=n.index;if(o instanceof H){if(!(o.value instanceof m))return void console.error(`SetDataValue: Invalid index type ${o.value}`);s+=o.value.value*a.stride}else{let c=e.evalExpression(o,r);if(!(c instanceof m))return void console.error("SetDataValue: Unknown index type",o);s+=c.value*a.stride}a=a.format}else console.error(`SetDataValue: Type ${a.getTypeName()} is not an array`);else{if(!(n instanceof pe))return void console.error("SetDataValue: Unknown postfix type",n);{let o=n.value;if(a instanceof ue){let c=!1;for(let l of a.members)if(l.name===o){s+=l.offset,a=l.type,c=!0;break}if(!c)return void console.error(`SetDataValue: Member ${o} not found`)}else if(a instanceof Z){let c=a.getTypeName(),l=0;if(o==="x"||o==="r")l=0;else if(o==="y"||o==="g")l=1;else if(o==="z"||o==="b")l=2;else{if(o!=="w"&&o!=="a")return void console.error(`SetDataValue: Unknown member ${o}`);l=3}if(!(t instanceof m))return void console.error("SetDataValue: Invalid value",t);let u=t.value;return c==="vec2f"?void(new Float32Array(this.buffer,s,2)[l]=u):c==="vec3f"?void(new Float32Array(this.buffer,s,3)[l]=u):c==="vec4f"?void(new Float32Array(this.buffer,s,4)[l]=u):c==="vec2i"?void(new Int32Array(this.buffer,s,2)[l]=u):c==="vec3i"?void(new Int32Array(this.buffer,s,3)[l]=u):c==="vec4i"?void(new Int32Array(this.buffer,s,4)[l]=u):c==="vec2u"?void(new Uint32Array(this.buffer,s,2)[l]=u):c==="vec3u"?void(new Uint32Array(this.buffer,s,3)[l]=u):c==="vec4u"?void(new Uint32Array(this.buffer,s,4)[l]=u):void console.error(`SetDataValue: Type ${c} is not a struct`)}}}n=n.postfix}this.setData(e,t,a,s,r)}setData(e,t,n,r,s){let a=n.getTypeName();if(a!=="f32"&&a!=="f16")if(a!=="i32"&&a!=="atomic<i32>"&&a!=="x32")if(a!=="u32"&&a!=="atomic<u32>")if(a!=="bool")if(a!=="vec2f"&&a!=="vec2h")if(a!=="vec3f"&&a!=="vec3h")if(a!=="vec4f"&&a!=="vec4h")if(a!=="vec2i")if(a!=="vec3i")if(a!=="vec4i")if(a!=="vec2u")if(a!=="vec3u")if(a!=="vec4u")if(a!=="vec2b")if(a!=="vec3b")if(a!=="vec4b")if(a!=="mat2x2f"&&a!=="mat2x2h")if(a!=="mat2x3f"&&a!=="mat2x3h")if(a!=="mat2x4f"&&a!=="mat2x4h")if(a!=="mat3x2f"&&a!=="mat3x2h")if(a!=="mat3x3f"&&a!=="mat3x3h")if(a!=="mat3x4f"&&a!=="mat3x4h")if(a!=="mat4x2f"&&a!=="mat4x2h")if(a!=="mat4x3f"&&a!=="mat4x3h")if(a!=="mat4x4f"&&a!=="mat4x4h")if(t instanceof U){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",a,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${a}`);else{let o=new Float32Array(this.buffer,r,16);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11],o[12]=t.data[12],o[13]=t.data[13],o[14]=t.data[14],o[15]=t.data[15]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15])}else{let o=new Float32Array(this.buffer,r,12);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,8);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,12);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,9);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8])}else{let o=new Float32Array(this.buffer,r,6);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,8);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,6);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,4);t instanceof N?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Int32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Int32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Int32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Float32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Float32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Float32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else t instanceof m&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof m&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,s,a;if(t===null)return this;let o=this.offset,c=this.typeInfo;for(;t;){if(t instanceof xe){let u=t.index,f=e.evalExpression(u,n),_=0;if(f instanceof m?_=f.value:console.error("GetDataValue: Invalid index type",u),c instanceof fe)o+=_*c.stride,c=c.format;else{let b=c.getTypeName();b==="mat4x4"||b==="mat4x4f"||b==="mat4x4h"?(o+=16*_,c=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${c.getTypeName()} is not an array`)}}else{if(!(t instanceof pe))return console.error("GetDataValue: Unknown postfix type",t),null;{let u=t.value;if(c instanceof ue){let f=!1;for(let _ of c.members)if(_.name===u){o+=_.offset,c=_.type,f=!0;break}if(!f)return console.error(`GetDataValue: Member ${u} not found`),null}else if(c instanceof Z){let f=c.getTypeName();if(f==="vec2f"||f==="vec3f"||f==="vec4f"||f==="vec2i"||f==="vec3i"||f==="vec4i"||f==="vec2u"||f==="vec3u"||f==="vec4u"||f==="vec2b"||f==="vec3b"||f==="vec4b"||f==="vec2h"||f==="vec3h"||f==="vec4h"||f==="vec2"||f==="vec3"||f==="vec4"){if(u.length>0&&u.length<5){let _="f",b=[];for(let w=0;w<u.length;++w){let L=u[w].toLowerCase(),S=0;if(L==="x"||L==="r")S=0;else if(L==="y"||L==="g")S=1;else if(L==="z"||L==="b")S=2;else{if(L!=="w"&&L!=="a")return console.error(`Unknown member ${u}`),null;S=3}if(u.length===1){if(f.endsWith("f"))return this.buffer.byteLength<o+4*S+4?(console.log("Insufficient buffer data"),null):new m(new Float32Array(this.buffer,o+4*S,1),e.getTypeInfo("f32"),this);if(f.endsWith("h"))return new m(new Float32Array(this.buffer,o+4*S,1),e.getTypeInfo("f16"),this);if(f.endsWith("i"))return new m(new Int32Array(this.buffer,o+4*S,1),e.getTypeInfo("i32"),this);if(f.endsWith("b"))return new m(new Int32Array(this.buffer,o+4*S,1),e.getTypeInfo("bool"),this);if(f.endsWith("u"))return new m(new Uint32Array(this.buffer,o+4*S,1),e.getTypeInfo("i32"),this)}if(f==="vec2f")b.push(new Float32Array(this.buffer,o,2)[S]);else if(f==="vec3f"){if(o+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let E=new Float32Array(this.buffer,o,3);b.push(E[S])}else if(f==="vec4f")b.push(new Float32Array(this.buffer,o,4)[S]);else if(f==="vec2i")_="i",b.push(new Int32Array(this.buffer,o,2)[S]);else if(f==="vec3i")_="i",b.push(new Int32Array(this.buffer,o,3)[S]);else if(f==="vec4i")_="i",b.push(new Int32Array(this.buffer,o,4)[S]);else if(f==="vec2u"){_="u";let E=new Uint32Array(this.buffer,o,2);b.push(E[S])}else f==="vec3u"?(_="u",b.push(new Uint32Array(this.buffer,o,3)[S])):f==="vec4u"&&(_="u",b.push(new Uint32Array(this.buffer,o,4)[S]))}return b.length===2?c=e.getTypeInfo(`vec2${_}`):b.length===3?c=e.getTypeInfo(`vec3${_}`):b.length===4?c=e.getTypeInfo(`vec4${_}`):console.error(`GetDataValue: Invalid vector length ${b.length}`),new p(b,c,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${f} is not a struct`),null}}}t=t.postfix}let l=c.getTypeName();return l==="f32"?new m(new Float32Array(this.buffer,o,1),c,this):l==="i32"?new m(new Int32Array(this.buffer,o,1),c,this):l==="u32"?new m(new Uint32Array(this.buffer,o,1),c,this):l==="vec2f"?new p(new Float32Array(this.buffer,o,2),c,this):l==="vec3f"?new p(new Float32Array(this.buffer,o,3),c,this):l==="vec4f"?new p(new Float32Array(this.buffer,o,4),c,this):l==="vec2i"?new p(new Int32Array(this.buffer,o,2),c,this):l==="vec3i"?new p(new Int32Array(this.buffer,o,3),c,this):l==="vec4i"?new p(new Int32Array(this.buffer,o,4),c,this):l==="vec2u"?new p(new Uint32Array(this.buffer,o,2),c,this):l==="vec3u"?new p(new Uint32Array(this.buffer,o,3),c,this):l==="vec4u"?new p(new Uint32Array(this.buffer,o,4),c,this):c instanceof he&&c.name==="atomic"?((r=c.format)===null||r===void 0?void 0:r.name)==="u32"?new m(new Uint32Array(this.buffer,o,1)[0],c.format,this):((s=c.format)===null||s===void 0?void 0:s.name)==="i32"?new m(new Int32Array(this.buffer,o,1)[0],c.format,this):(console.error(`GetDataValue: Invalid atomic format ${(a=c.format)===null||a===void 0?void 0:a.name}`),null):new U(this.buffer,c,o,this)}toString(){let e="";if(this.typeInfo instanceof fe)if(this.typeInfo.format.name==="f32"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){let t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){let t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof ue?e+="{...}":e="[...]";return e}},oe=class extends J{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new oe(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){let e=this.format,t=an[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=an[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=an[e],n=this.width;if(!e||n<=0||!t)return-1;let r=this.height,s=this.depthOrArrayLayers,a=this.dimension;return n/t.blockWidth*(a==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,a=this.bytesPerRow,o=this.height,c=this.data[r];return ri(new Uint8Array(c),e,t,n,r,o,a,s,this.format)}setPixel(e,t,n,r,s){let a=this.texelByteSize,o=this.bytesPerRow,c=this.height,l=this.data[r];(function(u,f,_,b,w,L,S,E,T,k){let I=b*(S>>=w)*(L>>=w)+_*S+f*E;switch(T){case"r8unorm":return void R(u,I,"8unorm",1,k);case"r8snorm":return void R(u,I,"8snorm",1,k);case"r8uint":return void R(u,I,"8uint",1,k);case"r8sint":return void R(u,I,"8sint",1,k);case"rg8unorm":return void R(u,I,"8unorm",2,k);case"rg8snorm":return void R(u,I,"8snorm",2,k);case"rg8uint":return void R(u,I,"8uint",2,k);case"rg8sint":return void R(u,I,"8sint",2,k);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void R(u,I,"8unorm",4,k);case"rgba8snorm":return void R(u,I,"8snorm",4,k);case"rgba8uint":return void R(u,I,"8uint",4,k);case"rgba8sint":return void R(u,I,"8sint",4,k);case"r16uint":return void R(u,I,"16uint",1,k);case"r16sint":return void R(u,I,"16sint",1,k);case"r16float":return void R(u,I,"16float",1,k);case"rg16uint":return void R(u,I,"16uint",2,k);case"rg16sint":return void R(u,I,"16sint",2,k);case"rg16float":return void R(u,I,"16float",2,k);case"rgba16uint":return void R(u,I,"16uint",4,k);case"rgba16sint":return void R(u,I,"16sint",4,k);case"rgba16float":return void R(u,I,"16float",4,k);case"r32uint":return void R(u,I,"32uint",1,k);case"r32sint":return void R(u,I,"32sint",1,k);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void R(u,I,"32float",1,k);case"rg32uint":return void R(u,I,"32uint",2,k);case"rg32sint":return void R(u,I,"32sint",2,k);case"rg32float":return void R(u,I,"32float",2,k);case"rgba32uint":return void R(u,I,"32uint",4,k);case"rgba32sint":return void R(u,I,"32sint",4,k);case"rgba32float":return void R(u,I,"32float",4,k);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(l),e,t,n,r,c,o,a,this.format,s)}};(i=>{i[i.token=0]="token",i[i.keyword=1]="keyword",i[i.reserved=2]="reserved"})(g||(g={}));var d=class{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}},h=class{};v=h,h.none=new d("",g.reserved,""),h.eof=new d("EOF",g.token,""),h.reserved={asm:new d("asm",g.reserved,"asm"),bf16:new d("bf16",g.reserved,"bf16"),do:new d("do",g.reserved,"do"),enum:new d("enum",g.reserved,"enum"),f16:new d("f16",g.reserved,"f16"),f64:new d("f64",g.reserved,"f64"),handle:new d("handle",g.reserved,"handle"),i8:new d("i8",g.reserved,"i8"),i16:new d("i16",g.reserved,"i16"),i64:new d("i64",g.reserved,"i64"),mat:new d("mat",g.reserved,"mat"),premerge:new d("premerge",g.reserved,"premerge"),regardless:new d("regardless",g.reserved,"regardless"),typedef:new d("typedef",g.reserved,"typedef"),u8:new d("u8",g.reserved,"u8"),u16:new d("u16",g.reserved,"u16"),u64:new d("u64",g.reserved,"u64"),unless:new d("unless",g.reserved,"unless"),using:new d("using",g.reserved,"using"),vec:new d("vec",g.reserved,"vec"),void:new d("void",g.reserved,"void")},h.keywords={array:new d("array",g.keyword,"array"),atomic:new d("atomic",g.keyword,"atomic"),bool:new d("bool",g.keyword,"bool"),f32:new d("f32",g.keyword,"f32"),i32:new d("i32",g.keyword,"i32"),mat2x2:new d("mat2x2",g.keyword,"mat2x2"),mat2x3:new d("mat2x3",g.keyword,"mat2x3"),mat2x4:new d("mat2x4",g.keyword,"mat2x4"),mat3x2:new d("mat3x2",g.keyword,"mat3x2"),mat3x3:new d("mat3x3",g.keyword,"mat3x3"),mat3x4:new d("mat3x4",g.keyword,"mat3x4"),mat4x2:new d("mat4x2",g.keyword,"mat4x2"),mat4x3:new d("mat4x3",g.keyword,"mat4x3"),mat4x4:new d("mat4x4",g.keyword,"mat4x4"),ptr:new d("ptr",g.keyword,"ptr"),sampler:new d("sampler",g.keyword,"sampler"),sampler_comparison:new d("sampler_comparison",g.keyword,"sampler_comparison"),struct:new d("struct",g.keyword,"struct"),texture_1d:new d("texture_1d",g.keyword,"texture_1d"),texture_2d:new d("texture_2d",g.keyword,"texture_2d"),texture_2d_array:new d("texture_2d_array",g.keyword,"texture_2d_array"),texture_3d:new d("texture_3d",g.keyword,"texture_3d"),texture_cube:new d("texture_cube",g.keyword,"texture_cube"),texture_cube_array:new d("texture_cube_array",g.keyword,"texture_cube_array"),texture_multisampled_2d:new d("texture_multisampled_2d",g.keyword,"texture_multisampled_2d"),texture_storage_1d:new d("texture_storage_1d",g.keyword,"texture_storage_1d"),texture_storage_2d:new d("texture_storage_2d",g.keyword,"texture_storage_2d"),texture_storage_2d_array:new d("texture_storage_2d_array",g.keyword,"texture_storage_2d_array"),texture_storage_3d:new d("texture_storage_3d",g.keyword,"texture_storage_3d"),texture_depth_2d:new d("texture_depth_2d",g.keyword,"texture_depth_2d"),texture_depth_2d_array:new d("texture_depth_2d_array",g.keyword,"texture_depth_2d_array"),texture_depth_cube:new d("texture_depth_cube",g.keyword,"texture_depth_cube"),texture_depth_cube_array:new d("texture_depth_cube_array",g.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new d("texture_depth_multisampled_2d",g.keyword,"texture_depth_multisampled_2d"),texture_external:new d("texture_external",g.keyword,"texture_external"),u32:new d("u32",g.keyword,"u32"),vec2:new d("vec2",g.keyword,"vec2"),vec3:new d("vec3",g.keyword,"vec3"),vec4:new d("vec4",g.keyword,"vec4"),bitcast:new d("bitcast",g.keyword,"bitcast"),block:new d("block",g.keyword,"block"),break:new d("break",g.keyword,"break"),case:new d("case",g.keyword,"case"),continue:new d("continue",g.keyword,"continue"),continuing:new d("continuing",g.keyword,"continuing"),default:new d("default",g.keyword,"default"),diagnostic:new d("diagnostic",g.keyword,"diagnostic"),discard:new d("discard",g.keyword,"discard"),else:new d("else",g.keyword,"else"),enable:new d("enable",g.keyword,"enable"),fallthrough:new d("fallthrough",g.keyword,"fallthrough"),false:new d("false",g.keyword,"false"),fn:new d("fn",g.keyword,"fn"),for:new d("for",g.keyword,"for"),function:new d("function",g.keyword,"function"),if:new d("if",g.keyword,"if"),let:new d("let",g.keyword,"let"),const:new d("const",g.keyword,"const"),loop:new d("loop",g.keyword,"loop"),while:new d("while",g.keyword,"while"),private:new d("private",g.keyword,"private"),read:new d("read",g.keyword,"read"),read_write:new d("read_write",g.keyword,"read_write"),return:new d("return",g.keyword,"return"),requires:new d("requires",g.keyword,"requires"),storage:new d("storage",g.keyword,"storage"),switch:new d("switch",g.keyword,"switch"),true:new d("true",g.keyword,"true"),alias:new d("alias",g.keyword,"alias"),type:new d("type",g.keyword,"type"),uniform:new d("uniform",g.keyword,"uniform"),var:new d("var",g.keyword,"var"),override:new d("override",g.keyword,"override"),workgroup:new d("workgroup",g.keyword,"workgroup"),write:new d("write",g.keyword,"write"),r8unorm:new d("r8unorm",g.keyword,"r8unorm"),r8snorm:new d("r8snorm",g.keyword,"r8snorm"),r8uint:new d("r8uint",g.keyword,"r8uint"),r8sint:new d("r8sint",g.keyword,"r8sint"),r16uint:new d("r16uint",g.keyword,"r16uint"),r16sint:new d("r16sint",g.keyword,"r16sint"),r16float:new d("r16float",g.keyword,"r16float"),rg8unorm:new d("rg8unorm",g.keyword,"rg8unorm"),rg8snorm:new d("rg8snorm",g.keyword,"rg8snorm"),rg8uint:new d("rg8uint",g.keyword,"rg8uint"),rg8sint:new d("rg8sint",g.keyword,"rg8sint"),r32uint:new d("r32uint",g.keyword,"r32uint"),r32sint:new d("r32sint",g.keyword,"r32sint"),r32float:new d("r32float",g.keyword,"r32float"),rg16uint:new d("rg16uint",g.keyword,"rg16uint"),rg16sint:new d("rg16sint",g.keyword,"rg16sint"),rg16float:new d("rg16float",g.keyword,"rg16float"),rgba8unorm:new d("rgba8unorm",g.keyword,"rgba8unorm"),rgba8unorm_srgb:new d("rgba8unorm_srgb",g.keyword,"rgba8unorm_srgb"),rgba8snorm:new d("rgba8snorm",g.keyword,"rgba8snorm"),rgba8uint:new d("rgba8uint",g.keyword,"rgba8uint"),rgba8sint:new d("rgba8sint",g.keyword,"rgba8sint"),bgra8unorm:new d("bgra8unorm",g.keyword,"bgra8unorm"),bgra8unorm_srgb:new d("bgra8unorm_srgb",g.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new d("rgb10a2unorm",g.keyword,"rgb10a2unorm"),rg11b10float:new d("rg11b10float",g.keyword,"rg11b10float"),rg32uint:new d("rg32uint",g.keyword,"rg32uint"),rg32sint:new d("rg32sint",g.keyword,"rg32sint"),rg32float:new d("rg32float",g.keyword,"rg32float"),rgba16uint:new d("rgba16uint",g.keyword,"rgba16uint"),rgba16sint:new d("rgba16sint",g.keyword,"rgba16sint"),rgba16float:new d("rgba16float",g.keyword,"rgba16float"),rgba32uint:new d("rgba32uint",g.keyword,"rgba32uint"),rgba32sint:new d("rgba32sint",g.keyword,"rgba32sint"),rgba32float:new d("rgba32float",g.keyword,"rgba32float"),static_assert:new d("static_assert",g.keyword,"static_assert")},h.tokens={decimal_float_literal:new d("decimal_float_literal",g.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new d("hex_float_literal",g.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new d("int_literal",g.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new d("uint_literal",g.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new d("name",g.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new d("ident",g.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new d("and",g.token,"&"),and_and:new d("and_and",g.token,"&&"),arrow:new d("arrow ",g.token,"->"),attr:new d("attr",g.token,"@"),forward_slash:new d("forward_slash",g.token,"/"),bang:new d("bang",g.token,"!"),bracket_left:new d("bracket_left",g.token,"["),bracket_right:new d("bracket_right",g.token,"]"),brace_left:new d("brace_left",g.token,"{"),brace_right:new d("brace_right",g.token,"}"),colon:new d("colon",g.token,":"),comma:new d("comma",g.token,","),equal:new d("equal",g.token,"="),equal_equal:new d("equal_equal",g.token,"=="),not_equal:new d("not_equal",g.token,"!="),greater_than:new d("greater_than",g.token,">"),greater_than_equal:new d("greater_than_equal",g.token,">="),shift_right:new d("shift_right",g.token,">>"),less_than:new d("less_than",g.token,"<"),less_than_equal:new d("less_than_equal",g.token,"<="),shift_left:new d("shift_left",g.token,"<<"),modulo:new d("modulo",g.token,"%"),minus:new d("minus",g.token,"-"),minus_minus:new d("minus_minus",g.token,"--"),period:new d("period",g.token,"."),plus:new d("plus",g.token,"+"),plus_plus:new d("plus_plus",g.token,"++"),or:new d("or",g.token,"|"),or_or:new d("or_or",g.token,"||"),paren_left:new d("paren_left",g.token,"("),paren_right:new d("paren_right",g.token,")"),semicolon:new d("semicolon",g.token,";"),star:new d("star",g.token,"*"),tilde:new d("tilde",g.token,"~"),underscore:new d("underscore",g.token,"_"),xor:new d("xor",g.token,"^"),plus_equal:new d("plus_equal",g.token,"+="),minus_equal:new d("minus_equal",g.token,"-="),times_equal:new d("times_equal",g.token,"*="),division_equal:new d("division_equal",g.token,"/="),modulo_equal:new d("modulo_equal",g.token,"%="),and_equal:new d("and_equal",g.token,"&="),or_equal:new d("or_equal",g.token,"|="),xor_equal:new d("xor_equal",g.token,"^="),shift_right_equal:new d("shift_right_equal",g.token,">>="),shift_left_equal:new d("shift_left_equal",g.token,"<<=")},h.simpleTokens={"@":v.tokens.attr,"{":v.tokens.brace_left,"}":v.tokens.brace_right,":":v.tokens.colon,",":v.tokens.comma,"(":v.tokens.paren_left,")":v.tokens.paren_right,";":v.tokens.semicolon},h.literalTokens={"&":v.tokens.and,"&&":v.tokens.and_and,"->":v.tokens.arrow,"/":v.tokens.forward_slash,"!":v.tokens.bang,"[":v.tokens.bracket_left,"]":v.tokens.bracket_right,"=":v.tokens.equal,"==":v.tokens.equal_equal,"!=":v.tokens.not_equal,">":v.tokens.greater_than,">=":v.tokens.greater_than_equal,">>":v.tokens.shift_right,"<":v.tokens.less_than,"<=":v.tokens.less_than_equal,"<<":v.tokens.shift_left,"%":v.tokens.modulo,"-":v.tokens.minus,"--":v.tokens.minus_minus,".":v.tokens.period,"+":v.tokens.plus,"++":v.tokens.plus_plus,"|":v.tokens.or,"||":v.tokens.or_or,"*":v.tokens.star,"~":v.tokens.tilde,_:v.tokens.underscore,"^":v.tokens.xor,"+=":v.tokens.plus_equal,"-=":v.tokens.minus_equal,"*=":v.tokens.times_equal,"/=":v.tokens.division_equal,"%=":v.tokens.modulo_equal,"&=":v.tokens.and_equal,"|=":v.tokens.or_equal,"^=":v.tokens.xor_equal,">>=":v.tokens.shift_right_equal,"<<=":v.tokens.shift_left_equal},h.regexTokens={decimal_float_literal:v.tokens.decimal_float_literal,hex_float_literal:v.tokens.hex_float_literal,int_literal:v.tokens.int_literal,uint_literal:v.tokens.uint_literal,ident:v.tokens.ident},h.storage_class=[v.keywords.function,v.keywords.private,v.keywords.workgroup,v.keywords.uniform,v.keywords.storage],h.access_mode=[v.keywords.read,v.keywords.write,v.keywords.read_write],h.sampler_type=[v.keywords.sampler,v.keywords.sampler_comparison],h.sampled_texture_type=[v.keywords.texture_1d,v.keywords.texture_2d,v.keywords.texture_2d_array,v.keywords.texture_3d,v.keywords.texture_cube,v.keywords.texture_cube_array],h.multisampled_texture_type=[v.keywords.texture_multisampled_2d],h.storage_texture_type=[v.keywords.texture_storage_1d,v.keywords.texture_storage_2d,v.keywords.texture_storage_2d_array,v.keywords.texture_storage_3d],h.depth_texture_type=[v.keywords.texture_depth_2d,v.keywords.texture_depth_2d_array,v.keywords.texture_depth_cube,v.keywords.texture_depth_cube_array,v.keywords.texture_depth_multisampled_2d],h.texture_external_type=[v.keywords.texture_external],h.any_texture_type=[...v.sampled_texture_type,...v.multisampled_texture_type,...v.storage_texture_type,...v.depth_texture_type,...v.texture_external_type],h.texel_format=[v.keywords.r8unorm,v.keywords.r8snorm,v.keywords.r8uint,v.keywords.r8sint,v.keywords.r16uint,v.keywords.r16sint,v.keywords.r16float,v.keywords.rg8unorm,v.keywords.rg8snorm,v.keywords.rg8uint,v.keywords.rg8sint,v.keywords.r32uint,v.keywords.r32sint,v.keywords.r32float,v.keywords.rg16uint,v.keywords.rg16sint,v.keywords.rg16float,v.keywords.rgba8unorm,v.keywords.rgba8unorm_srgb,v.keywords.rgba8snorm,v.keywords.rgba8uint,v.keywords.rgba8sint,v.keywords.bgra8unorm,v.keywords.bgra8unorm_srgb,v.keywords.rgb10a2unorm,v.keywords.rg11b10float,v.keywords.rg32uint,v.keywords.rg32sint,v.keywords.rg32float,v.keywords.rgba16uint,v.keywords.rgba16sint,v.keywords.rgba16float,v.keywords.rgba32uint,v.keywords.rgba32sint,v.keywords.rgba32float],h.const_literal=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.keywords.true,v.keywords.false],h.literal_or_ident=[v.tokens.ident,v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.tokens.name],h.element_count_expression=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.ident],h.template_types=[v.keywords.vec2,v.keywords.vec3,v.keywords.vec4,v.keywords.mat2x2,v.keywords.mat2x3,v.keywords.mat2x4,v.keywords.mat3x2,v.keywords.mat3x3,v.keywords.mat3x4,v.keywords.mat4x2,v.keywords.mat4x3,v.keywords.mat4x4,v.keywords.atomic,v.keywords.bitcast,...v.any_texture_type],h.attribute_name=[v.tokens.ident,v.keywords.block,v.keywords.diagnostic],h.assignment_operators=[v.tokens.equal,v.tokens.plus_equal,v.tokens.minus_equal,v.tokens.times_equal,v.tokens.division_equal,v.tokens.modulo_equal,v.tokens.and_equal,v.tokens.or_equal,v.tokens.xor_equal,v.tokens.shift_right_equal,v.tokens.shift_left_equal],h.increment_operators=[v.tokens.plus_plus,v.tokens.minus_minus];var Bt=class{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return h.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==h.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},bn=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Bt(h.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
96
+ }`}function $n(a){switch(a){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(a)}}function Hn(a){switch(a){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(a)}}function qr(a){switch(a){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${a}`)}}function Gt(a,e){switch(e){case 1:return`vec4(${a}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${a}, 0.0, 1.0)`;case 3:return`vec4(${a}, 1.0)`;case 4:return a;default:throw new Error(`invalid channels: ${e}`)}}function pe(a){return typeof a=="string"?a.charAt(0).toUpperCase()+a.slice(1):a}function Gn(a,e){return jr(a,e)}function jr(a,e){let t=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":t.push(`uniform ${pe(a.name)} {`);break;case"uniforms":}for(let[n,r]of Object.entries(a.uniformTypes||{})){let s=Xr(r);switch(e.uniforms){case"scoped-interface-blocks":t.push(` ${s} ${n};`);break;case"unscoped-interface-blocks":t.push(` ${s} ${a.name}_${n};`);break;case"uniforms":t.push(`uniform ${s} ${a.name}_${n};`)}}switch(e.uniforms){case"scoped-interface-blocks":t.push(`} ${a.name};`);break;case"unscoped-interface-blocks":t.push("};");break;case"uniforms":}return t.push(""),t.join(`
97
+ `)}function Xr(a){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[a]}function Wn(a,e){return Kr(a,e)}function Kr(a,e){let t=[];t.push(`struct ${pe(a.name)} {`);for(let[n,r]of Object.entries(a?.uniformTypes||{})){let s=r;t.push(` ${n} : ${s};`)}return t.push("};"),t.push(`var<uniform> ${a.name} : ${pe(a.name)};`),t.join(`
98
+ `)}function zn(a,e){switch(e.shaderLanguage){case"glsl":return Gn(a,e);case"wgsl":return Wn(a,e)}}var Yn=Rt(Je(),1);var W=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}getTypeName(){return this.name}},ot=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},re=class extends W{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},se=class extends W{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},ie=class extends W{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},ce;(a=>{a[a.Uniform=0]="Uniform",a[a.Storage=1]="Storage",a[a.Texture=2]="Texture",a[a.Sampler=3]="Sampler",a[a.StorageTexture=4]="StorageTexture"})(ce||(ce={}));var xe=class{constructor(e,t,n,r,s,i,o){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=i,this.access=o}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}},qt=class{constructor(e,t){this.name=e,this.type=t}},jt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},it=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},Xt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},Kt=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},Zt=class{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n}},Qt=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Xn=new Float32Array(1),Zr=new Int32Array(Xn.buffer),$=new Uint16Array(1);function Qr(a){Xn[0]=a;let e=Zr[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return $[0]=t<<15|31744|(r!==0?512:0),$[0];if(n===0){if(r===0)return $[0]=t<<15,$[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),$[0]=t<<15|n<<10|r>>13,$[0]):($[0]=t<<15,$[0])}return n=n-127+15,n>=31?($[0]=t<<15|31744,$[0]):n<=0?n<-10?($[0]=t<<15,$[0]):(r=(8388608|r)>>1-n,$[0]=t<<15|r>>13,$[0]):(r>>=13,$[0]=t<<15|n<<10|r,$[0])}var un=new Uint32Array(1),Kn=new Float32Array(un.buffer,0,1);function qn(a){let e=112+(a>>6&31)<<23|(63&a)<<17;return un[0]=e,Kn[0]}function Yr(a,e,t,n,r,s,i,o,l){let c=n*(i>>=r)*(s>>=r)+t*i+e*o;switch(l){case"r8unorm":return[C(a,c,"8unorm",1)[0]];case"r8snorm":return[C(a,c,"8snorm",1)[0]];case"r8uint":return[C(a,c,"8uint",1)[0]];case"r8sint":return[C(a,c,"8sint",1)[0]];case"rg8unorm":{let u=C(a,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{let u=C(a,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{let u=C(a,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{let u=C(a,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let u=C(a,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{let u=C(a,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{let u=C(a,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{let u=C(a,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let u=C(a,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[C(a,c,"16uint",1)[0]];case"r16sint":return[C(a,c,"16sint",1)[0]];case"r16float":return[C(a,c,"16float",1)[0]];case"rg16uint":{let u=C(a,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{let u=C(a,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{let u=C(a,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{let u=C(a,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{let u=C(a,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{let u=C(a,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[C(a,c,"32uint",1)[0]];case"r32sint":return[C(a,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[C(a,c,"32float",1)[0]];case"rg32uint":{let u=C(a,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{let u=C(a,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{let u=C(a,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{let u=C(a,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{let u=C(a,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{let u=C(a,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{let u=new Uint32Array(a.buffer,c,1)[0],h=(4192256&u)>>11,b=(4290772992&u)>>22;return[qn(2047&u),qn(h),function(y){let S=112+(y>>5&31)<<23|(31&y)<<18;return un[0]=S,Kn[0]}(b),1]}}return null}function C(a,e,t,n){let r=[0,0,0,0];for(let c=0;c<n;++c)switch(t){case"8unorm":r[c]=a[e]/255,e++;break;case"8snorm":r[c]=a[e]/255*2-1,e++;break;case"8uint":r[c]=a[e],e++;break;case"8sint":r[c]=a[e]-127,e++;break;case"16uint":r[c]=a[e]|a[e+1]<<8,e+=2;break;case"16sint":r[c]=(a[e]|a[e+1]<<8)-32768,e+=2;break;case"16float":r[c]=(s=a[e]|a[e+1]<<8,i=void 0,o=void 0,l=void 0,i=(32768&s)>>15,l=1023&s,(o=(31744&s)>>10)==0?(i?-1:1)*Math.pow(2,-14)*(l/Math.pow(2,10)):o==31?l?NaN:1/0*(i?-1:1):(i?-1:1)*Math.pow(2,o-15)*(1+l/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":r[c]=a[e]|a[e+1]<<8|a[e+2]<<16|a[e+3]<<24,e+=4;break;case"32float":r[c]=new Float32Array(a.buffer,e,1)[0],e+=4}var s,i,o,l;return r}function N(a,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":a[e]=255*r[s],e++;break;case"8snorm":a[e]=.5*(r[s]+1)*255,e++;break;case"8uint":a[e]=r[s],e++;break;case"8sint":a[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(a.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(a.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{let i=Qr(r[s]);new Uint16Array(a.buffer,e,1)[0]=i,e+=2;break}case"32uint":new Uint32Array(a.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(a.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(a.buffer,e,1)[0]=r[s],e+=4}return r}var Wt={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},z=class{constructor(){this.id=z._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Se.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Ae.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};z._id=0;var Se=class extends z{};Se.instance=new Se;var Ae=class extends z{};Ae.instance=new Ae;var Zn=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"]),F=class extends z{constructor(){super()}},ge=class extends F{constructor(e,t,n,r,s,i){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=i}get astNodeType(){return"function"}search(e){if(this.attributes)for(let t of this.attributes)e(t);e(this);for(let t of this.args)e(t);this.searchBlock(this.body,e)}},Yt=class extends F{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},at=class extends F{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)}},Be=class extends F{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},lt=class extends F{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}},ee=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ve=class extends F{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)}},me=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},ke=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},ye,Me,v,_;(a=>{a.increment="++",a.decrement="--"})(ye||(ye={})),(a=>{a.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return a[t]}})(ye||(ye={}));var ct=class extends F{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(a=>{a.assign="=",a.addAssign="+=",a.subtractAssin="-=",a.multiplyAssign="*=",a.divideAssign="/=",a.moduloAssign="%=",a.andAssign="&=",a.orAssign="|=",a.xorAssign="^=",a.shiftLeftAssign="<<=",a.shiftRightAssign=">>="})(Me||(Me={})),(a=>{a.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(Me||(Me={}));var ut=class extends F{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)}},Ue=class extends F{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Zn.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},ft=class extends F{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},ht=class extends F{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}},pt=class extends F{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},dt=class extends F{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},Jt=class extends F{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},en=class extends F{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},mt=class extends F{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},$e=class extends F{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},tn=class extends F{constructor(){super()}get astNodeType(){return"discard"}},_t=class extends F{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},gt=class extends F{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},x=class extends F{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=x._priority.get(t.name);x._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?x.i32:t}getTypeName(){return this.name}};x.x32=new x("x32"),x.f32=new x("f32"),x.i32=new x("i32"),x.u32=new x("u32"),x.f16=new x("f16"),x.bool=new x("bool"),x.void=new x("void"),x._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var vt=class extends x{constructor(e){super(e)}},Y=class extends x{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(let t of this.members)e(t)}},g=class extends x{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",x.f32,null),g.vec3f=new g("vec3",x.f32,null),g.vec4f=new g("vec4",x.f32,null),g.vec2i=new g("vec2",x.i32,null),g.vec3i=new g("vec3",x.i32,null),g.vec4i=new g("vec4",x.i32,null),g.vec2u=new g("vec2",x.u32,null),g.vec3u=new g("vec3",x.u32,null),g.vec4u=new g("vec4",x.u32,null),g.vec2h=new g("vec2",x.f16,null),g.vec3h=new g("vec3",x.f16,null),g.vec4h=new g("vec4",x.f16,null),g.vec2b=new g("vec2",x.bool,null),g.vec3b=new g("vec3",x.bool,null),g.vec4b=new g("vec4",x.bool,null),g.mat2x2f=new g("mat2x2",x.f32,null),g.mat2x3f=new g("mat2x3",x.f32,null),g.mat2x4f=new g("mat2x4",x.f32,null),g.mat3x2f=new g("mat3x2",x.f32,null),g.mat3x3f=new g("mat3x3",x.f32,null),g.mat3x4f=new g("mat3x4",x.f32,null),g.mat4x2f=new g("mat4x2",x.f32,null),g.mat4x3f=new g("mat4x3",x.f32,null),g.mat4x4f=new g("mat4x4",x.f32,null),g.mat2x2h=new g("mat2x2",x.f16,null),g.mat2x3h=new g("mat2x3",x.f16,null),g.mat2x4h=new g("mat2x4",x.f16,null),g.mat3x2h=new g("mat3x2",x.f16,null),g.mat3x3h=new g("mat3x3",x.f16,null),g.mat3x4h=new g("mat3x4",x.f16,null),g.mat4x2h=new g("mat4x2",x.f16,null),g.mat4x3h=new g("mat4x3",x.f16,null),g.mat4x4h=new g("mat4x4",x.f16,null),g.mat2x2i=new g("mat2x2",x.i32,null),g.mat2x3i=new g("mat2x3",x.i32,null),g.mat2x4i=new g("mat2x4",x.i32,null),g.mat3x2i=new g("mat3x2",x.i32,null),g.mat3x3i=new g("mat3x3",x.i32,null),g.mat3x4i=new g("mat3x4",x.i32,null),g.mat4x2i=new g("mat4x2",x.i32,null),g.mat4x3i=new g("mat4x3",x.i32,null),g.mat4x4i=new g("mat4x4",x.i32,null),g.mat2x2u=new g("mat2x2",x.u32,null),g.mat2x3u=new g("mat2x3",x.u32,null),g.mat2x4u=new g("mat2x4",x.u32,null),g.mat3x2u=new g("mat3x2",x.u32,null),g.mat3x3u=new g("mat3x3",x.u32,null),g.mat3x4u=new g("mat3x4",x.u32,null),g.mat4x2u=new g("mat4x2",x.u32,null),g.mat4x3u=new g("mat4x3",x.u32,null),g.mat4x4u=new g("mat4x4",x.u32,null);var Re=class extends x{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},_e=class extends x{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},de=class extends x{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},Q=class extends z{constructor(){super(),this.postfix=null}},ae=class extends Q{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},K=class extends Q{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}},He=class extends Q{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 Zn.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(let t of this.args)t.search(e);e(this)}},G=class extends Q{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)}},bt=class extends Q{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},R=class extends Q{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof d}get isVector(){return this.value instanceof p||this.value instanceof I}get scalarValue(){return this.value instanceof d?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof p||this.value instanceof I?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},xt=class extends Q{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}};var fe=class extends Q{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},yt=class extends Q{constructor(){super()}},M=class extends yt{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},j=class extends yt{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"?x.f32:e.name==="u32"||t.name==="u32"?x.u32:x.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},wt=class extends z{constructor(e){super(),this.body=e}},Ie=class extends Q{constructor(){super()}get astNodeType(){return"default"}},kt=class extends wt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},It=class extends wt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},St=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},nn=class extends z{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},At=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},Tt=class extends z{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},q=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=q._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.name}>`}};q._id=0;var Ge=class extends q{constructor(){super(new W("void",null),null)}toString(){return"void"}};Ge.void=new Ge;var ue=class extends q{constructor(e){super(new W("pointer",null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}},d=class extends q{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!=0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new d(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new d(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new d(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}};function Jr(a,e,t){let n=e.length;return n===2?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec2i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec2u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec3i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec3u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec4i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec4u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var p=class extends q{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new p(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new p(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new p(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof ae?console.error("TODO: Set vector postfix"):t instanceof p?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof ie)r=this.typeInfo.format||r;else{let i=this.typeInfo.name;i==="vec2f"||i==="vec3f"||i==="vec4f"?r=e.getTypeInfo("f32"):i==="vec2i"||i==="vec3i"||i==="vec4i"?r=e.getTypeInfo("i32"):i==="vec2b"||i==="vec3b"||i==="vec4b"?r=e.getTypeInfo("bool"):i==="vec2u"||i==="vec3u"||i==="vec4u"?r=e.getTypeInfo("u32"):i==="vec2h"||i==="vec3h"||i==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${i}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof fe){let i=t.index,o=-1;if(i instanceof R){if(!(i.value instanceof d))return console.error(`GetSubData: Invalid array index ${i.value}`),null;o=i.value.value}else{let l=e.evalExpression(i,n);if(!(l instanceof d))return console.error("GetSubData: Unknown index type",i),null;o=l.value}if(o<0||o>=s.data.length)return console.error("GetSubData: Index out of range",o),null;if(s.data instanceof Float32Array){let l=new Float32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}if(s.data instanceof Int32Array){let l=new Int32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}if(s.data instanceof Uint32Array){let l=new Uint32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof ae))return console.error("GetSubData: Unknown postfix",t),null;{let i=t.value.toLowerCase();if(i.length===1){let l=0;if(i==="x"||i==="r")l=0;else if(i==="y"||i==="g")l=1;else if(i==="z"||i==="b")l=2;else{if(i!=="w"&&i!=="a")return console.error(`GetSubData: Unknown member ${i}`),null;l=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}}let o=[];for(let l of i)l==="x"||l==="r"?o.push(this.data[0]):l==="y"||l==="g"?o.push(this.data[1]):l==="z"||l==="b"?o.push(this.data[2]):l==="w"||l==="a"?o.push(this.data[3]):console.error(`GetDataValue: Unknown member ${l}`);s=Jr(e,o,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},I=class extends q{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new I(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof ae?console.error("TODO: Set matrix postfix"):t instanceof I?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof ie)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof fe){let s=t.index,i=-1;if(s instanceof R){if(!(s.value instanceof d))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;i=s.value.value}else{let c=e.evalExpression(s,n);if(!(c instanceof d))return console.error("GetDataValue: Unknown index type",s),null;i=c.value}if(i<0||i>=this.data.length)return console.error("GetDataValue: Index out of range",i),null;let o=r.endsWith("h")?"h":"f",l;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+2*i*4,2),e.getTypeInfo(`vec2${o}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+3*i*4,3),e.getTypeInfo(`vec3${o}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+4*i*4,4),e.getTypeInfo(`vec4${o}`))}return t.postfix?l.getSubData(e,t.postfix,n):l}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}},D=class extends q{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new D(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,i=this.typeInfo;for(;n;){if(n instanceof fe)if(i instanceof se){let o=n.index;if(o instanceof R){if(!(o.value instanceof d))return void console.error(`SetDataValue: Invalid index type ${o.value}`);s+=o.value.value*i.stride}else{let l=e.evalExpression(o,r);if(!(l instanceof d))return void console.error("SetDataValue: Unknown index type",o);s+=l.value*i.stride}i=i.format}else console.error(`SetDataValue: Type ${i.getTypeName()} is not an array`);else{if(!(n instanceof ae))return void console.error("SetDataValue: Unknown postfix type",n);{let o=n.value;if(i instanceof re){let l=!1;for(let c of i.members)if(c.name===o){s+=c.offset,i=c.type,l=!0;break}if(!l)return void console.error(`SetDataValue: Member ${o} not found`)}else if(i instanceof W){let l=i.getTypeName(),c=0;if(o==="x"||o==="r")c=0;else if(o==="y"||o==="g")c=1;else if(o==="z"||o==="b")c=2;else{if(o!=="w"&&o!=="a")return void console.error(`SetDataValue: Unknown member ${o}`);c=3}if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let u=t.value;return l==="vec2f"?void(new Float32Array(this.buffer,s,2)[c]=u):l==="vec3f"?void(new Float32Array(this.buffer,s,3)[c]=u):l==="vec4f"?void(new Float32Array(this.buffer,s,4)[c]=u):l==="vec2i"?void(new Int32Array(this.buffer,s,2)[c]=u):l==="vec3i"?void(new Int32Array(this.buffer,s,3)[c]=u):l==="vec4i"?void(new Int32Array(this.buffer,s,4)[c]=u):l==="vec2u"?void(new Uint32Array(this.buffer,s,2)[c]=u):l==="vec3u"?void(new Uint32Array(this.buffer,s,3)[c]=u):l==="vec4u"?void(new Uint32Array(this.buffer,s,4)[c]=u):void console.error(`SetDataValue: Type ${l} is not a struct`)}}}n=n.postfix}this.setData(e,t,i,s,r)}setData(e,t,n,r,s){let i=n.getTypeName();if(i!=="f32"&&i!=="f16")if(i!=="i32"&&i!=="atomic<i32>"&&i!=="x32")if(i!=="u32"&&i!=="atomic<u32>")if(i!=="bool")if(i!=="vec2f"&&i!=="vec2h")if(i!=="vec3f"&&i!=="vec3h")if(i!=="vec4f"&&i!=="vec4h")if(i!=="vec2i")if(i!=="vec3i")if(i!=="vec4i")if(i!=="vec2u")if(i!=="vec3u")if(i!=="vec4u")if(i!=="vec2b")if(i!=="vec3b")if(i!=="vec4b")if(i!=="mat2x2f"&&i!=="mat2x2h")if(i!=="mat2x3f"&&i!=="mat2x3h")if(i!=="mat2x4f"&&i!=="mat2x4h")if(i!=="mat3x2f"&&i!=="mat3x2h")if(i!=="mat3x3f"&&i!=="mat3x3h")if(i!=="mat3x4f"&&i!=="mat3x4h")if(i!=="mat4x2f"&&i!=="mat4x2h")if(i!=="mat4x3f"&&i!=="mat4x3h")if(i!=="mat4x4f"&&i!=="mat4x4h")if(t instanceof D){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",i,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${i}`);else{let o=new Float32Array(this.buffer,r,16);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11],o[12]=t.data[12],o[13]=t.data[13],o[14]=t.data[14],o[15]=t.data[15]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15])}else{let o=new Float32Array(this.buffer,r,12);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,8);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,12);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,9);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8])}else{let o=new Float32Array(this.buffer,r,6);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,8);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,6);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,4);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Int32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Int32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Int32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Float32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Float32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Float32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,s,i;if(t===null)return this;let o=this.offset,l=this.typeInfo;for(;t;){if(t instanceof fe){let u=t.index,h=e.evalExpression(u,n),b=0;if(h instanceof d?b=h.value:console.error("GetDataValue: Invalid index type",u),l instanceof se)o+=b*l.stride,l=l.format;else{let y=l.getTypeName();y==="mat4x4"||y==="mat4x4f"||y==="mat4x4h"?(o+=16*b,l=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${l.getTypeName()} is not an array`)}}else{if(!(t instanceof ae))return console.error("GetDataValue: Unknown postfix type",t),null;{let u=t.value;if(l instanceof re){let h=!1;for(let b of l.members)if(b.name===u){o+=b.offset,l=b.type,h=!0;break}if(!h)return console.error(`GetDataValue: Member ${u} not found`),null}else if(l instanceof W){let h=l.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 b="f",y=[];for(let S=0;S<u.length;++S){let E=u[S].toLowerCase(),T=0;if(E==="x"||E==="r")T=0;else if(E==="y"||E==="g")T=1;else if(E==="z"||E==="b")T=2;else{if(E!=="w"&&E!=="a")return console.error(`Unknown member ${u}`),null;T=3}if(u.length===1){if(h.endsWith("f"))return this.buffer.byteLength<o+4*T+4?(console.log("Insufficient buffer data"),null):new d(new Float32Array(this.buffer,o+4*T,1),e.getTypeInfo("f32"),this);if(h.endsWith("h"))return new d(new Float32Array(this.buffer,o+4*T,1),e.getTypeInfo("f16"),this);if(h.endsWith("i"))return new d(new Int32Array(this.buffer,o+4*T,1),e.getTypeInfo("i32"),this);if(h.endsWith("b"))return new d(new Int32Array(this.buffer,o+4*T,1),e.getTypeInfo("bool"),this);if(h.endsWith("u"))return new d(new Uint32Array(this.buffer,o+4*T,1),e.getTypeInfo("i32"),this)}if(h==="vec2f")y.push(new Float32Array(this.buffer,o,2)[T]);else if(h==="vec3f"){if(o+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let L=new Float32Array(this.buffer,o,3);y.push(L[T])}else if(h==="vec4f")y.push(new Float32Array(this.buffer,o,4)[T]);else if(h==="vec2i")b="i",y.push(new Int32Array(this.buffer,o,2)[T]);else if(h==="vec3i")b="i",y.push(new Int32Array(this.buffer,o,3)[T]);else if(h==="vec4i")b="i",y.push(new Int32Array(this.buffer,o,4)[T]);else if(h==="vec2u"){b="u";let L=new Uint32Array(this.buffer,o,2);y.push(L[T])}else h==="vec3u"?(b="u",y.push(new Uint32Array(this.buffer,o,3)[T])):h==="vec4u"&&(b="u",y.push(new Uint32Array(this.buffer,o,4)[T]))}return y.length===2?l=e.getTypeInfo(`vec2${b}`):y.length===3?l=e.getTypeInfo(`vec3${b}`):y.length===4?l=e.getTypeInfo(`vec4${b}`):console.error(`GetDataValue: Invalid vector length ${y.length}`),new p(y,l,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${h} is not a struct`),null}}}t=t.postfix}let c=l.getTypeName();return c==="f32"?new d(new Float32Array(this.buffer,o,1),l,this):c==="i32"?new d(new Int32Array(this.buffer,o,1),l,this):c==="u32"?new d(new Uint32Array(this.buffer,o,1),l,this):c==="vec2f"?new p(new Float32Array(this.buffer,o,2),l,this):c==="vec3f"?new p(new Float32Array(this.buffer,o,3),l,this):c==="vec4f"?new p(new Float32Array(this.buffer,o,4),l,this):c==="vec2i"?new p(new Int32Array(this.buffer,o,2),l,this):c==="vec3i"?new p(new Int32Array(this.buffer,o,3),l,this):c==="vec4i"?new p(new Int32Array(this.buffer,o,4),l,this):c==="vec2u"?new p(new Uint32Array(this.buffer,o,2),l,this):c==="vec3u"?new p(new Uint32Array(this.buffer,o,3),l,this):c==="vec4u"?new p(new Uint32Array(this.buffer,o,4),l,this):l instanceof ie&&l.name==="atomic"?((r=l.format)===null||r===void 0?void 0:r.name)==="u32"?new d(new Uint32Array(this.buffer,o,1)[0],l.format,this):((s=l.format)===null||s===void 0?void 0:s.name)==="i32"?new d(new Int32Array(this.buffer,o,1)[0],l.format,this):(console.error(`GetDataValue: Invalid atomic format ${(i=l.format)===null||i===void 0?void 0:i.name}`),null):new D(this.buffer,l,o,this)}toString(){let e="";if(this.typeInfo instanceof se)if(this.typeInfo.format.name==="f32"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){let t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){let t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof re?e+="{...}":e="[...]";return e}},J=class extends q{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new J(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){let e=this.format,t=Wt[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=Wt[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=Wt[e],n=this.width;if(!e||n<=0||!t)return-1;let r=this.height,s=this.depthOrArrayLayers,i=this.dimension;return n/t.blockWidth*(i==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,i=this.bytesPerRow,o=this.height,l=this.data[r];return Yr(new Uint8Array(l),e,t,n,r,o,i,s,this.format)}setPixel(e,t,n,r,s){let i=this.texelByteSize,o=this.bytesPerRow,l=this.height,c=this.data[r];(function(u,h,b,y,S,E,T,L,P,k){let A=y*(T>>=S)*(E>>=S)+b*T+h*L;switch(P){case"r8unorm":return void N(u,A,"8unorm",1,k);case"r8snorm":return void N(u,A,"8snorm",1,k);case"r8uint":return void N(u,A,"8uint",1,k);case"r8sint":return void N(u,A,"8sint",1,k);case"rg8unorm":return void N(u,A,"8unorm",2,k);case"rg8snorm":return void N(u,A,"8snorm",2,k);case"rg8uint":return void N(u,A,"8uint",2,k);case"rg8sint":return void N(u,A,"8sint",2,k);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void N(u,A,"8unorm",4,k);case"rgba8snorm":return void N(u,A,"8snorm",4,k);case"rgba8uint":return void N(u,A,"8uint",4,k);case"rgba8sint":return void N(u,A,"8sint",4,k);case"r16uint":return void N(u,A,"16uint",1,k);case"r16sint":return void N(u,A,"16sint",1,k);case"r16float":return void N(u,A,"16float",1,k);case"rg16uint":return void N(u,A,"16uint",2,k);case"rg16sint":return void N(u,A,"16sint",2,k);case"rg16float":return void N(u,A,"16float",2,k);case"rgba16uint":return void N(u,A,"16uint",4,k);case"rgba16sint":return void N(u,A,"16sint",4,k);case"rgba16float":return void N(u,A,"16float",4,k);case"r32uint":return void N(u,A,"32uint",1,k);case"r32sint":return void N(u,A,"32sint",1,k);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void N(u,A,"32float",1,k);case"rg32uint":return void N(u,A,"32uint",2,k);case"rg32sint":return void N(u,A,"32sint",2,k);case"rg32float":return void N(u,A,"32float",2,k);case"rgba32uint":return void N(u,A,"32uint",4,k);case"rgba32sint":return void N(u,A,"32sint",4,k);case"rgba32float":return void N(u,A,"32float",4,k);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,n,r,l,o,i,this.format,s)}};(a=>{a[a.token=0]="token",a[a.keyword=1]="keyword",a[a.reserved=2]="reserved"})(_||(_={}));var m=class{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}},f=class{};v=f,f.none=new m("",_.reserved,""),f.eof=new m("EOF",_.token,""),f.reserved={asm:new m("asm",_.reserved,"asm"),bf16:new m("bf16",_.reserved,"bf16"),do:new m("do",_.reserved,"do"),enum:new m("enum",_.reserved,"enum"),f16:new m("f16",_.reserved,"f16"),f64:new m("f64",_.reserved,"f64"),handle:new m("handle",_.reserved,"handle"),i8:new m("i8",_.reserved,"i8"),i16:new m("i16",_.reserved,"i16"),i64:new m("i64",_.reserved,"i64"),mat:new m("mat",_.reserved,"mat"),premerge:new m("premerge",_.reserved,"premerge"),regardless:new m("regardless",_.reserved,"regardless"),typedef:new m("typedef",_.reserved,"typedef"),u8:new m("u8",_.reserved,"u8"),u16:new m("u16",_.reserved,"u16"),u64:new m("u64",_.reserved,"u64"),unless:new m("unless",_.reserved,"unless"),using:new m("using",_.reserved,"using"),vec:new m("vec",_.reserved,"vec"),void:new m("void",_.reserved,"void")},f.keywords={array:new m("array",_.keyword,"array"),atomic:new m("atomic",_.keyword,"atomic"),bool:new m("bool",_.keyword,"bool"),f32:new m("f32",_.keyword,"f32"),i32:new m("i32",_.keyword,"i32"),mat2x2:new m("mat2x2",_.keyword,"mat2x2"),mat2x3:new m("mat2x3",_.keyword,"mat2x3"),mat2x4:new m("mat2x4",_.keyword,"mat2x4"),mat3x2:new m("mat3x2",_.keyword,"mat3x2"),mat3x3:new m("mat3x3",_.keyword,"mat3x3"),mat3x4:new m("mat3x4",_.keyword,"mat3x4"),mat4x2:new m("mat4x2",_.keyword,"mat4x2"),mat4x3:new m("mat4x3",_.keyword,"mat4x3"),mat4x4:new m("mat4x4",_.keyword,"mat4x4"),ptr:new m("ptr",_.keyword,"ptr"),sampler:new m("sampler",_.keyword,"sampler"),sampler_comparison:new m("sampler_comparison",_.keyword,"sampler_comparison"),struct:new m("struct",_.keyword,"struct"),texture_1d:new m("texture_1d",_.keyword,"texture_1d"),texture_2d:new m("texture_2d",_.keyword,"texture_2d"),texture_2d_array:new m("texture_2d_array",_.keyword,"texture_2d_array"),texture_3d:new m("texture_3d",_.keyword,"texture_3d"),texture_cube:new m("texture_cube",_.keyword,"texture_cube"),texture_cube_array:new m("texture_cube_array",_.keyword,"texture_cube_array"),texture_multisampled_2d:new m("texture_multisampled_2d",_.keyword,"texture_multisampled_2d"),texture_storage_1d:new m("texture_storage_1d",_.keyword,"texture_storage_1d"),texture_storage_2d:new m("texture_storage_2d",_.keyword,"texture_storage_2d"),texture_storage_2d_array:new m("texture_storage_2d_array",_.keyword,"texture_storage_2d_array"),texture_storage_3d:new m("texture_storage_3d",_.keyword,"texture_storage_3d"),texture_depth_2d:new m("texture_depth_2d",_.keyword,"texture_depth_2d"),texture_depth_2d_array:new m("texture_depth_2d_array",_.keyword,"texture_depth_2d_array"),texture_depth_cube:new m("texture_depth_cube",_.keyword,"texture_depth_cube"),texture_depth_cube_array:new m("texture_depth_cube_array",_.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new m("texture_depth_multisampled_2d",_.keyword,"texture_depth_multisampled_2d"),texture_external:new m("texture_external",_.keyword,"texture_external"),u32:new m("u32",_.keyword,"u32"),vec2:new m("vec2",_.keyword,"vec2"),vec3:new m("vec3",_.keyword,"vec3"),vec4:new m("vec4",_.keyword,"vec4"),bitcast:new m("bitcast",_.keyword,"bitcast"),block:new m("block",_.keyword,"block"),break:new m("break",_.keyword,"break"),case:new m("case",_.keyword,"case"),continue:new m("continue",_.keyword,"continue"),continuing:new m("continuing",_.keyword,"continuing"),default:new m("default",_.keyword,"default"),diagnostic:new m("diagnostic",_.keyword,"diagnostic"),discard:new m("discard",_.keyword,"discard"),else:new m("else",_.keyword,"else"),enable:new m("enable",_.keyword,"enable"),fallthrough:new m("fallthrough",_.keyword,"fallthrough"),false:new m("false",_.keyword,"false"),fn:new m("fn",_.keyword,"fn"),for:new m("for",_.keyword,"for"),function:new m("function",_.keyword,"function"),if:new m("if",_.keyword,"if"),let:new m("let",_.keyword,"let"),const:new m("const",_.keyword,"const"),loop:new m("loop",_.keyword,"loop"),while:new m("while",_.keyword,"while"),private:new m("private",_.keyword,"private"),read:new m("read",_.keyword,"read"),read_write:new m("read_write",_.keyword,"read_write"),return:new m("return",_.keyword,"return"),requires:new m("requires",_.keyword,"requires"),storage:new m("storage",_.keyword,"storage"),switch:new m("switch",_.keyword,"switch"),true:new m("true",_.keyword,"true"),alias:new m("alias",_.keyword,"alias"),type:new m("type",_.keyword,"type"),uniform:new m("uniform",_.keyword,"uniform"),var:new m("var",_.keyword,"var"),override:new m("override",_.keyword,"override"),workgroup:new m("workgroup",_.keyword,"workgroup"),write:new m("write",_.keyword,"write"),r8unorm:new m("r8unorm",_.keyword,"r8unorm"),r8snorm:new m("r8snorm",_.keyword,"r8snorm"),r8uint:new m("r8uint",_.keyword,"r8uint"),r8sint:new m("r8sint",_.keyword,"r8sint"),r16uint:new m("r16uint",_.keyword,"r16uint"),r16sint:new m("r16sint",_.keyword,"r16sint"),r16float:new m("r16float",_.keyword,"r16float"),rg8unorm:new m("rg8unorm",_.keyword,"rg8unorm"),rg8snorm:new m("rg8snorm",_.keyword,"rg8snorm"),rg8uint:new m("rg8uint",_.keyword,"rg8uint"),rg8sint:new m("rg8sint",_.keyword,"rg8sint"),r32uint:new m("r32uint",_.keyword,"r32uint"),r32sint:new m("r32sint",_.keyword,"r32sint"),r32float:new m("r32float",_.keyword,"r32float"),rg16uint:new m("rg16uint",_.keyword,"rg16uint"),rg16sint:new m("rg16sint",_.keyword,"rg16sint"),rg16float:new m("rg16float",_.keyword,"rg16float"),rgba8unorm:new m("rgba8unorm",_.keyword,"rgba8unorm"),rgba8unorm_srgb:new m("rgba8unorm_srgb",_.keyword,"rgba8unorm_srgb"),rgba8snorm:new m("rgba8snorm",_.keyword,"rgba8snorm"),rgba8uint:new m("rgba8uint",_.keyword,"rgba8uint"),rgba8sint:new m("rgba8sint",_.keyword,"rgba8sint"),bgra8unorm:new m("bgra8unorm",_.keyword,"bgra8unorm"),bgra8unorm_srgb:new m("bgra8unorm_srgb",_.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new m("rgb10a2unorm",_.keyword,"rgb10a2unorm"),rg11b10float:new m("rg11b10float",_.keyword,"rg11b10float"),rg32uint:new m("rg32uint",_.keyword,"rg32uint"),rg32sint:new m("rg32sint",_.keyword,"rg32sint"),rg32float:new m("rg32float",_.keyword,"rg32float"),rgba16uint:new m("rgba16uint",_.keyword,"rgba16uint"),rgba16sint:new m("rgba16sint",_.keyword,"rgba16sint"),rgba16float:new m("rgba16float",_.keyword,"rgba16float"),rgba32uint:new m("rgba32uint",_.keyword,"rgba32uint"),rgba32sint:new m("rgba32sint",_.keyword,"rgba32sint"),rgba32float:new m("rgba32float",_.keyword,"rgba32float"),static_assert:new m("static_assert",_.keyword,"static_assert")},f.tokens={decimal_float_literal:new m("decimal_float_literal",_.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new m("hex_float_literal",_.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new m("int_literal",_.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new m("uint_literal",_.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new m("name",_.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new m("ident",_.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new m("and",_.token,"&"),and_and:new m("and_and",_.token,"&&"),arrow:new m("arrow ",_.token,"->"),attr:new m("attr",_.token,"@"),forward_slash:new m("forward_slash",_.token,"/"),bang:new m("bang",_.token,"!"),bracket_left:new m("bracket_left",_.token,"["),bracket_right:new m("bracket_right",_.token,"]"),brace_left:new m("brace_left",_.token,"{"),brace_right:new m("brace_right",_.token,"}"),colon:new m("colon",_.token,":"),comma:new m("comma",_.token,","),equal:new m("equal",_.token,"="),equal_equal:new m("equal_equal",_.token,"=="),not_equal:new m("not_equal",_.token,"!="),greater_than:new m("greater_than",_.token,">"),greater_than_equal:new m("greater_than_equal",_.token,">="),shift_right:new m("shift_right",_.token,">>"),less_than:new m("less_than",_.token,"<"),less_than_equal:new m("less_than_equal",_.token,"<="),shift_left:new m("shift_left",_.token,"<<"),modulo:new m("modulo",_.token,"%"),minus:new m("minus",_.token,"-"),minus_minus:new m("minus_minus",_.token,"--"),period:new m("period",_.token,"."),plus:new m("plus",_.token,"+"),plus_plus:new m("plus_plus",_.token,"++"),or:new m("or",_.token,"|"),or_or:new m("or_or",_.token,"||"),paren_left:new m("paren_left",_.token,"("),paren_right:new m("paren_right",_.token,")"),semicolon:new m("semicolon",_.token,";"),star:new m("star",_.token,"*"),tilde:new m("tilde",_.token,"~"),underscore:new m("underscore",_.token,"_"),xor:new m("xor",_.token,"^"),plus_equal:new m("plus_equal",_.token,"+="),minus_equal:new m("minus_equal",_.token,"-="),times_equal:new m("times_equal",_.token,"*="),division_equal:new m("division_equal",_.token,"/="),modulo_equal:new m("modulo_equal",_.token,"%="),and_equal:new m("and_equal",_.token,"&="),or_equal:new m("or_equal",_.token,"|="),xor_equal:new m("xor_equal",_.token,"^="),shift_right_equal:new m("shift_right_equal",_.token,">>="),shift_left_equal:new m("shift_left_equal",_.token,"<<=")},f.simpleTokens={"@":v.tokens.attr,"{":v.tokens.brace_left,"}":v.tokens.brace_right,":":v.tokens.colon,",":v.tokens.comma,"(":v.tokens.paren_left,")":v.tokens.paren_right,";":v.tokens.semicolon},f.literalTokens={"&":v.tokens.and,"&&":v.tokens.and_and,"->":v.tokens.arrow,"/":v.tokens.forward_slash,"!":v.tokens.bang,"[":v.tokens.bracket_left,"]":v.tokens.bracket_right,"=":v.tokens.equal,"==":v.tokens.equal_equal,"!=":v.tokens.not_equal,">":v.tokens.greater_than,">=":v.tokens.greater_than_equal,">>":v.tokens.shift_right,"<":v.tokens.less_than,"<=":v.tokens.less_than_equal,"<<":v.tokens.shift_left,"%":v.tokens.modulo,"-":v.tokens.minus,"--":v.tokens.minus_minus,".":v.tokens.period,"+":v.tokens.plus,"++":v.tokens.plus_plus,"|":v.tokens.or,"||":v.tokens.or_or,"*":v.tokens.star,"~":v.tokens.tilde,_:v.tokens.underscore,"^":v.tokens.xor,"+=":v.tokens.plus_equal,"-=":v.tokens.minus_equal,"*=":v.tokens.times_equal,"/=":v.tokens.division_equal,"%=":v.tokens.modulo_equal,"&=":v.tokens.and_equal,"|=":v.tokens.or_equal,"^=":v.tokens.xor_equal,">>=":v.tokens.shift_right_equal,"<<=":v.tokens.shift_left_equal},f.regexTokens={decimal_float_literal:v.tokens.decimal_float_literal,hex_float_literal:v.tokens.hex_float_literal,int_literal:v.tokens.int_literal,uint_literal:v.tokens.uint_literal,ident:v.tokens.ident},f.storage_class=[v.keywords.function,v.keywords.private,v.keywords.workgroup,v.keywords.uniform,v.keywords.storage],f.access_mode=[v.keywords.read,v.keywords.write,v.keywords.read_write],f.sampler_type=[v.keywords.sampler,v.keywords.sampler_comparison],f.sampled_texture_type=[v.keywords.texture_1d,v.keywords.texture_2d,v.keywords.texture_2d_array,v.keywords.texture_3d,v.keywords.texture_cube,v.keywords.texture_cube_array],f.multisampled_texture_type=[v.keywords.texture_multisampled_2d],f.storage_texture_type=[v.keywords.texture_storage_1d,v.keywords.texture_storage_2d,v.keywords.texture_storage_2d_array,v.keywords.texture_storage_3d],f.depth_texture_type=[v.keywords.texture_depth_2d,v.keywords.texture_depth_2d_array,v.keywords.texture_depth_cube,v.keywords.texture_depth_cube_array,v.keywords.texture_depth_multisampled_2d],f.texture_external_type=[v.keywords.texture_external],f.any_texture_type=[...v.sampled_texture_type,...v.multisampled_texture_type,...v.storage_texture_type,...v.depth_texture_type,...v.texture_external_type],f.texel_format=[v.keywords.r8unorm,v.keywords.r8snorm,v.keywords.r8uint,v.keywords.r8sint,v.keywords.r16uint,v.keywords.r16sint,v.keywords.r16float,v.keywords.rg8unorm,v.keywords.rg8snorm,v.keywords.rg8uint,v.keywords.rg8sint,v.keywords.r32uint,v.keywords.r32sint,v.keywords.r32float,v.keywords.rg16uint,v.keywords.rg16sint,v.keywords.rg16float,v.keywords.rgba8unorm,v.keywords.rgba8unorm_srgb,v.keywords.rgba8snorm,v.keywords.rgba8uint,v.keywords.rgba8sint,v.keywords.bgra8unorm,v.keywords.bgra8unorm_srgb,v.keywords.rgb10a2unorm,v.keywords.rg11b10float,v.keywords.rg32uint,v.keywords.rg32sint,v.keywords.rg32float,v.keywords.rgba16uint,v.keywords.rgba16sint,v.keywords.rgba16float,v.keywords.rgba32uint,v.keywords.rgba32sint,v.keywords.rgba32float],f.const_literal=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.keywords.true,v.keywords.false],f.literal_or_ident=[v.tokens.ident,v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.tokens.name],f.element_count_expression=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.ident],f.template_types=[v.keywords.vec2,v.keywords.vec3,v.keywords.vec4,v.keywords.mat2x2,v.keywords.mat2x3,v.keywords.mat2x4,v.keywords.mat3x2,v.keywords.mat3x3,v.keywords.mat3x4,v.keywords.mat4x2,v.keywords.mat4x3,v.keywords.mat4x4,v.keywords.atomic,v.keywords.bitcast,...v.any_texture_type],f.attribute_name=[v.tokens.ident,v.keywords.block,v.keywords.diagnostic],f.assignment_operators=[v.tokens.equal,v.tokens.plus_equal,v.tokens.minus_equal,v.tokens.times_equal,v.tokens.division_equal,v.tokens.modulo_equal,v.tokens.and_equal,v.tokens.or_equal,v.tokens.xor_equal,v.tokens.shift_right_equal,v.tokens.shift_left_equal],f.increment_operators=[v.tokens.plus_plus,v.tokens.minus_minus];var Lt=class{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return f.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==f.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},rn=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Lt(f.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
101
99
  `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
102
- `;){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==`
103
- `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let t=h.simpleTokens[e];if(t)return this._addToken(t),!0;let n=h.none,r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(r){let a=h.keywords[e];if(a)return this._addToken(a),!0}if(r||s)return this._addToken(h.tokens.ident),!0;for(;;){let a=this._findType(e),o=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(o=="=")return this._current++,e+=o,this._addToken(h.tokens.minus_equal),!0;if(o=="-")return this._current++,e+=o,this._addToken(h.tokens.minus_minus),!0;let c=this._tokens.length-1;if((h.literal_or_ident.indexOf(this._tokens[c].type)!=-1||this._tokens[c].type==h.tokens.paren_right)&&o!=">")return this._addToken(a),!0}if(e==">"&&(o==">"||o=="=")){let c=!1,l=this._tokens.length-1;for(let u=0;u<5&&l>=0&&h.assignment_operators.indexOf(this._tokens[l].type)===-1;++u,--l)if(this._tokens[l].type===h.tokens.less_than){l>0&&this._tokens[l-1].isArrayOrTemplateType()&&(c=!0);break}if(c)return this._addToken(a),!0}if(a===h.none){let c=e,l=0,u=2;for(let f=0;f<u;++f)if(c+=this._peekAhead(f),a=this._findType(c),a!==h.none){l=f;break}if(a===h.none)return n!==h.none&&(this._current--,this._addToken(n),!0);e=c,this._current+=l+1}if(n=a,this._isAtEnd())break;e+=this._advance()}return n!==h.none&&(this._addToken(n),!0)}_findType(e){for(let n in h.regexTokens){let r=h.regexTokens[n];if(this._match(e,r.rule))return r}return h.literalTokens[e]||h.none}_match(e,t){let n=t.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
104
- `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Bt(e,t,this._line,this._start,this._current))}};function A(i){return Array.isArray(i)||i?.buffer instanceof ArrayBuffer}var Vt=new Float32Array(1),ii=new Uint32Array(Vt.buffer),oi=new Uint32Array(Vt.buffer),$t=new Int32Array(1),ai=new Float32Array($t.buffer),ci=new Uint32Array($t.buffer),Ut=new Uint32Array(1),li=new Float32Array(Ut.buffer),ui=new Int32Array(Ut.buffer);function vr(i,e,t){if(e===t)return i;if(e==="f32"){if(t==="i32"||t==="x32")return Vt[0]=i,ii[0];if(t==="u32")return Vt[0]=i,oi[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return $t[0]=i,ai[0];if(t==="u32")return $t[0]=i,ci[0]}else if(e==="u32"){if(t==="f32")return Ut[0]=i,li[0];if(t==="i32"||t==="x32")return Ut[0]=i,ui[0]}return console.error(`Unsupported cast from ${e} to ${t}`),i}var yn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},Me=class{constructor(e,t){this.align=e,this.size=t}},re=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new mn,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let t of e)t instanceof ke&&this._functions.set(t.name,new yn(t));for(let t of e)if(t instanceof ie){let n=this.getTypeInfo(t,null);n instanceof ue&&this.structs.push(n)}for(let t of e)if(t instanceof Ze)this.aliases.push(this._getAliasInfo(t));else if(t instanceof Ye){let n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new fn(n.name,s,n.attributes,r))}else if(this._isUniformVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=new Te(n.name,a,r,s,n.attributes,ge.Uniform,n.access);o.access||(o.access="read"),this.uniforms.push(o)}else if(this._isStorageVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(a),c=new Te(n.name,a,r,s,n.attributes,o?ge.StorageTexture:ge.Storage,n.access);c.access||(c.access="read"),this.storage.push(c)}else if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(a),c=new Te(n.name,a,r,s,n.attributes,o?ge.StorageTexture:ge.Texture,n.access);c.access||(c.access="read"),o?this.storage.push(c):this.textures.push(c)}else if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),a=this.getTypeInfo(n.type,n.attributes),o=new Te(n.name,a,r,s,n.attributes,ge.Sampler,n.access);this.samplers.push(o)}else if(t instanceof ke){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),a=n||r||s,o=new pn(t.name,a?.name,t.attributes);o.attributes=t.attributes,o.startLine=t.startLine,o.endLine=t.endLine,this.functions.push(o),this._functions.get(t.name).info=o,a&&(this._functions.get(t.name).inUse=!0,o.inUse=!0,o.resources=this._findResources(t,!!a),o.inputs=this._getInputs(t.args),o.outputs=this._getOutputs(t.returnType),this.entry[a.name].push(o)),o.arguments=t.args.map(c=>new hn(c.name,this.getTypeInfo(c.type,c.attributes),c.attributes)),o.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null}for(let t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(let t of this._functions.values())t.node.search(n=>{var r,s,a;if(n instanceof Ft){if(n.value)if(A(n.value))for(let o of n.value)for(let c of this.overrides)o===c.name&&((r=t.info)===null||r===void 0||r.overrides.push(c));else for(let o of this.overrides)n.value===o.name&&((s=t.info)===null||s===void 0||s.overrides.push(o))}else if(n instanceof Y)for(let o of this.overrides)n.name===o.name&&((a=t.info)===null||a===void 0||a.overrides.push(o))});for(let t of this.uniforms)this._markStructsInUse(t.type);for(let t of this.storage)this._markStructsInUse(t.type)}getStructInfo(e){for(let t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(let t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(let r of e.calls){let s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(let r of this.entry.compute)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.vertex)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.fragment)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}}for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let n=[],r=this,s=[];return e.search(a=>{if(a instanceof Oe)s.push({});else if(a instanceof Pe)s.pop();else if(a instanceof ae){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(a instanceof ne){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type)}else if(a instanceof ye){let o=a;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(a instanceof Y){let o=a;if(s.length>0&&s[s.length-1][o.name])return;let c=r._findResource(o.name);c&&n.push(c)}else if(a instanceof Qe){let o=a,c=r._functions.get(o.name);c&&(t&&(c.inUse=!0),e.calls.add(c.node),c.resources===null&&(c.resources=r._findResources(c.node,t)),n.push(...c.resources))}else if(a instanceof Ke){let o=a,c=r._functions.get(o.name);c&&(t&&(c.inUse=!0),e.calls.add(c.node),c.resources===null&&(c.resources=r._findResources(c.node,t)),n.push(...c.resources))}}),[...new Map(n.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(let n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof ie)this._getStructOutputs(e,t);else{let n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(let n of e.members)if(n.type instanceof ie)this._getStructOutputs(n.type,t);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let s=this.getTypeInfo(n.type,n.type.attributes),a=this._parseInt(r.value),o=new gt(n.name,s,r.name,a);t.push(o)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new gt("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof ie)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(let n of e.members)if(n.type instanceof ie)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),a=new un(e.name,r,t.name,s);return n!==null&&(a.interpolation=this._parseString(n.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new ln(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let t of this.structs)if(t.name==e)return t;for(let t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof we){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,a=new fe(r.name,t);return a.format=s,a.count=r.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof ie){let r=e,s=new ue(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let a of r.members){let o=this.getTypeInfo(a.type,a.attributes);s.members.push(new dt(a.name,o,a.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof be){let r=e,s=r.format instanceof y,a=r.format?s?this.getTypeInfo(r.format,null):new Z(r.format,null):null,o=new he(r.name,a,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof x){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,a=new he(r.name,s,t,r.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let n=new Z(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;let s=this._getTypeSize(e);if(e.size=(t=s?.size)!==null&&t!==void 0?t:0,e instanceof fe&&e.format){let a=this._getTypeSize(e.format);e.stride=Math.max((n=a?.size)!==null&&n!==void 0?n:0,(r=a?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof ue&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,a=0;for(let o=0,c=e.members.length;o<c;++o){let l=e.members[o],u=this._getTypeSize(l);if(!u)continue;(t=this._getAlias(l.type.name))!==null&&t!==void 0||l.type;let f=u.align,_=u.size;n=this._roundUp(f,n+r),r=_,s=n,a=Math.max(a,f),l.offset=n,l.size=_,this._updateTypeInfo(l.type)}e.size=this._roundUp(a,s+r),e.align=a}_getTypeSize(e){var t,n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof dt&&(e=e.type),e instanceof Z){let a=this._getAlias(e.name);a!==null&&(e=a)}{let a=re._typeInfo[e.name];if(a!==void 0){let o=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new Me(Math.max(s,a.align/o),Math.max(r,a.size/o))}}{let a=re._typeInfo[e.name.substring(0,e.name.length-1)];if(a){let o=e.name[e.name.length-1]==="h"?2:1;return new Me(Math.max(s,a.align/o),Math.max(r,a.size/o))}}if(e instanceof fe){let a=e,o=8,c=8,l=this._getTypeSize(a.format);return l!==null&&(c=l.size,o=l.align),c=a.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(o,c)),r&&(c=r),new Me(Math.max(s,o),Math.max(r,c))}if(e instanceof ue){let a=0,o=0,c=0,l=0,u=0;for(let f of e.members){let _=this._getTypeSize(f.type);_!==null&&(a=Math.max(_.align,a),c=this._roundUp(_.align,c+l),l=_.size,u=c)}return o=this._roundUp(a,u+l),new Me(Math.max(s,a),Math.max(r,o))}return null}_isUniformVar(e){return e instanceof ae&&e.storage=="uniform"}_isStorageVar(e){return e instanceof ae&&e.storage=="storage"}_isTextureVar(e){return e instanceof ae&&e.type!==null&&re._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ae&&e.type!==null&&re._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let n=e;if(!n||!n.attributes)return null;let r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}};re._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},re._textureTypes=h.any_texture_type.map(i=>i.name),re._samplerTypes=h.sampler_type.map(i=>i.name);var et=class{constructor(e,t,n){this.name=e,this.value=t,this.node=n}clone(){return new et(this.name,this.value,this.node)}},tt=class{constructor(e){this.name=e.name,this.node=e}clone(){return new tt(this.node)}},nt=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",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 et(e,t,n??null))}setVariable(e,t,n){let r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;let n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new nt(this)}},wn=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},kn=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){let n=this.exec.evalExpression(e.args[0],t),r=!0;if(n instanceof p)return n.data.forEach(s=>{s||(r=!1)}),new m(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=n.data.some(s=>s);return new m(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){let n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof m))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 z&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof U&&r.typeInfo.size===0){let s=r.typeInfo,a=r.buffer.byteLength/s.stride;return new m(a,this.getTypeInfo("u32"))}return new m(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new m(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new m(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new m(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new m(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new m(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new m(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new m(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.atan2(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.atan2(s.value,a.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new m(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((l,u)=>this._clamp(l,r.data[u],s.data[u])),n.typeInfo);let a=n,o=r,c=s;return new m(this._clamp(a.value,o.value,c.value),n.typeInfo)}Cos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new m(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new m(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new m(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new m(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new m(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let s=n.data,a=r.data;return new p([s[1]*a[2]-a[1]*s[2],s[2]*a[0]-a[2]*s[0],s[0]*a[1]-a[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){let n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof p?new p(n.data.map(s=>s*r),n.typeInfo):new m(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof N){let r=n.data,s=n.typeInfo.getTypeName(),a=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new m(r[0]*r[3]-r[1]*r[2],a);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new m(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new m(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),a);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let o=0;for(let c=0;c<n.data.length;++c)o+=(n.data[c]-r.data[c])*(n.data[c]-r.data[c]);return new m(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n,a=r;return new m(Math.abs(s.value-a.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof p&&r instanceof p?new m(this._dot(n.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new m(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new m(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let a=r.value,o=s.value;if(n instanceof p)return new p(n.data.map(l=>l>>a&(1<<o)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let c=n.value;return new m(c>>a&(1<<o)-1,this.getTypeInfo("i32"))}FaceForward(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p){let a=this._dot(r.data,s.data);return new p(a<0?Array.from(n.data):n.data.map(o=>-o),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new m(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new m(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new m(Math.floor(r.value),n.typeInfo)}Fma(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new p(n.data.map((l,u)=>l*r.data[u]+s.data[u]),n.typeInfo);let a=n,o=r,c=s;return new m(a.value*o.value+c.value,a.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new m(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),a=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let o=s.value,c=(1<<a.value)-1<<o,l=~c;if(n instanceof p&&r instanceof p)return new p(n.data.map((_,b)=>_&l|r.data[b]<<o&c),n.typeInfo);let u=n.value,f=r.value;return new m(u&l|f<<o&c,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new m(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let s=0;return n.data.forEach(a=>{s+=a*a}),new m(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new m(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new m(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new m(Math.log2(r.value),n.typeInfo)}Max(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.max(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.max(s.value,a.value),n.typeInfo)}Min(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.min(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.min(s.value,a.value),n.typeInfo)}Mix(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((c,l)=>n.data[l]*(1-s.data[l])+r.data[l]*s.data[l]),n.typeInfo);let a=r,o=s;return new m(n.value*(1-o.value)+a.value*o.value,n.typeInfo)}Modf(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((a,o)=>a%r.data[o]),n.typeInfo);let s=r;return new m(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=this.Length(e,t).value;return new p(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,c)=>Math.pow(o,r.data[c])),n.typeInfo);let s=n,a=r;return new m(Math.pow(s.value,a.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r),n.typeInfo):new m(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r*Math.PI/180),n.typeInfo):new m(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let s=this._dot(n.data,r.data);return new p(n.data.map((a,o)=>a-2*s*r.data[o]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof m){let a=this._dot(r.data,n.data);return new p(n.data.map((o,c)=>{let l=1-s.value*s.value*(1-a*a);if(l<0)return 0;let u=Math.sqrt(l);return s.value*o-(s.value*a+u)*r.data[c]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new m(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new m(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new m(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new m(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new m(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){let r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof p&&n instanceof p&&r instanceof p)return new p(s.data.map((l,u)=>this._smoothstep(n.data[u],r.data[u],l)),s.typeInfo);let a=n,o=r,c=s;return new m(this._smoothstep(a.value,o.value,c.value),s.typeInfo)}Sqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new m(Math.sqrt(r.value),n.typeInfo)}Step(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof p&&n instanceof p)return new p(r.data.map((a,o)=>a<n.data[o]?0:1),r.typeInfo);let s=n;return new m(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new m(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new m(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){let t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){let n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof N))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let s=n.data;return new N([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let s=n.data;return new N([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let s=n.data;return new N([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let s=n.data;return new N([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let s=n.data;return new N([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let s=n.data;return new N([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let s=n.data;return new N([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new m(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){let n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof Y){let s=n.name,a=t.getVariableValue(s);if(a instanceof oe){if(r<0||r>=a.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let o=a.getMipLevelSize(r),c=a.dimension;return c==="1d"?new m(o[0],this.getTypeInfo("u32")):c==="3d"?new p(o,this.getTypeInfo("vec3u")):c==="2d"?new p(o.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${c} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof Y){let a=n.name,o=t.getVariableValue(a);if(o instanceof oe){let c=Math.floor(r.data[0]),l=Math.floor(r.data[1]);if(c<0||c>=o.width||l<0||l>=o.height)return console.error(`Texture ${a} out of bounds. Line ${e.line}`),null;let u=o.getPixel(c,l,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new p(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){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){let n=e.args[0];if(n instanceof Y){let r=n.name,s=t.getVariableValue(r);return s instanceof oe?new m(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,a=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(a.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof Y){let o=n.name,c=t.getVariableValue(o);if(c instanceof oe){let l=c.getMipLevelSize(0),u=Math.floor(r.data[0]),f=Math.floor(r.data[1]);return u<0||u>=l[0]||f<0||f>=l[1]?(console.error(`Texture ${o} out of bounds. Line ${e.line}`),null):(c.setPixel(u,f,0,s,Array.from(a)),null)}return console.error(`Texture ${o} 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 z&&(n=n.right);let r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t);return c instanceof m&&o instanceof m&&(c.value=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value+=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicSub(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value-=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicMax(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=Math.max(c.value,o.value)),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicMin(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=Math.min(c.value,o.value)),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicAnd(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value&o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicOr(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value|o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicXor(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=c.value^o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicExchange(e,t){let n=e.args[0];n instanceof z&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),a=e.args[1],o=this.exec.evalExpression(a,t),c=s.value.getSubData(this.exec,n.postfix,t),l=new m(c.value,c.typeInfo);return c instanceof m&&o instanceof m&&(c.value=o.value),s.value instanceof U&&s.value.setDataValue(this.exec,c,n.postfix,t),l}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}},cn={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},X={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]},G=class extends wn{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new re,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new nt,this.builtins=new kn(this),this.typeInfo={bool:this.getTypeInfo(y.bool),i32:this.getTypeInfo(y.i32),u32:this.getTypeInfo(y.u32),f32:this.getTypeInfo(y.f32),f16:this.getTypeInfo(y.f16),vec2f:this.getTypeInfo(x.vec2f),vec2u:this.getTypeInfo(x.vec2u),vec2i:this.getTypeInfo(x.vec2i),vec2h:this.getTypeInfo(x.vec2h),vec3f:this.getTypeInfo(x.vec3f),vec3u:this.getTypeInfo(x.vec3u),vec3i:this.getTypeInfo(x.vec3i),vec3h:this.getTypeInfo(x.vec3h),vec4f:this.getTypeInfo(x.vec4f),vec4u:this.getTypeInfo(x.vec4u),vec4i:this.getTypeInfo(x.vec4i),vec4h:this.getTypeInfo(x.vec4h),mat2x2f:this.getTypeInfo(x.mat2x2f),mat2x3f:this.getTypeInfo(x.mat2x3f),mat2x4f:this.getTypeInfo(x.mat2x4f),mat3x2f:this.getTypeInfo(x.mat3x2f),mat3x3f:this.getTypeInfo(x.mat3x3f),mat3x4f:this.getTypeInfo(x.mat3x4f),mat4x2f:this.getTypeInfo(x.mat4x2f),mat4x3f:this.getTypeInfo(x.mat4x3f),mat4x4f:this.getTypeInfo(x.mat4x4f)}}getVariableValue(e){var t,n;let r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof m)return r.value;if(r instanceof p||r instanceof N)return Array.from(r.data);if(r instanceof U&&r.typeInfo instanceof fe){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){let s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);let a=s.getFunction(e);if(!a)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}let o=t[0],c=t[1],l=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new p(t,u));for(let f in n)for(let _ in n[f]){let b=n[f][_];s.variables.forEach(w=>{var L;let S=w.node;if(S?.attributes){let E=null,T=null;for(let k of S.attributes)k.name==="binding"?E=k.value:k.name==="group"&&(T=k.value);if(_==E&&f==T)if(b.texture!==void 0&&b.descriptor!==void 0){let k=new oe(b.texture,this.getTypeInfo(S.type),b.descriptor,(L=b.texture.view)!==null&&L!==void 0?L:null);w.value=k}else b.uniform!==void 0?w.value=new U(b.uniform,this.getTypeInfo(S.type)):w.value=new U(b,this.getTypeInfo(S.type))}})}for(let f=0;f<l;++f)for(let _=0;_<c;++_)for(let b=0;b<o;++b)s.setVariable("@workgroup_id",new p([b,_,f],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(a,[b,_,f],s)}execStatement(e,t){if(e instanceof It)return this.evalExpression(e.value,t);if(e instanceof At){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof m))throw new Error("Invalid break-if condition");if(!n.value)return null}return G._breakObj}if(e instanceof Lt)return G._continueObj;if(e instanceof ye)this._let(e,t);else if(e instanceof ae)this._var(e,t);else if(e instanceof Ce)this._const(e,t);else if(e instanceof ke)this._function(e,t);else{if(e instanceof kt)return this._if(e,t);if(e instanceof wt)return this._switch(e,t);if(e instanceof xt)return this._for(e,t);if(e instanceof _t)return this._while(e,t);if(e instanceof yt)return this._loop(e,t);if(e instanceof Xe){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof bt)this._assign(e,t);else if(e instanceof vt)this._increment(e,t);else{if(e instanceof ie)return null;if(e instanceof Ye){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new m(0,this.getTypeInfo("u32")))}else if(e instanceof Ke)this._call(e,t);else{if(e instanceof St||e instanceof Ze)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof ee?this._evalBinaryOp(e,t):e instanceof H?this._evalLiteral(e,t):e instanceof Y?this._evalVariable(e,t):e instanceof Qe?this._evalCall(e,t):e instanceof ne?this._evalCreate(e,t):e instanceof Et?this._evalConst(e,t):e instanceof Mt?this._evalBitcast(e,t):e instanceof z?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof y){let r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(let n in e){let r=e[n],s=this.reflection.getOverrideInfo(n);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(n,new m(r,s.type)):s.type.name==="bool"?t.setVariable(n,new m(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(n,new p(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){let r=[1,1,1];for(let u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){let f=n.getVariableValue(u.value[0]);r[0]=f instanceof m?f.value:parseInt(u.value[0])}if(u.value.length>1){let f=n.getVariableValue(u.value[1]);r[1]=f instanceof m?f.value:parseInt(u.value[1])}if(u.value.length>2){let f=n.getVariableValue(u.value[2]);r[2]=f instanceof m?f.value:parseInt(u.value[2])}}let s=this.getTypeInfo("vec3u"),a=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new p(r,s));let o=r[0],c=r[1],l=r[2];for(let u=0,f=0;u<l;++u)for(let _=0;_<c;++_)for(let b=0;b<o;++b,++f){let w=[b,_,u],L=[b+t[0]*r[0],_+t[1]*r[1],u+t[2]*r[2]];n.setVariable("@local_invocation_id",new p(w,s)),n.setVariable("@global_invocation_id",new p(L,s)),n.setVariable("@local_invocation_index",new m(f,a)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(let n of e.node.args)for(let r of n.attributes)if(r.name==="builtin"){let s=`@${r.value}`,a=t.getVariable(s);a!==void 0&&t.variables.set(n.name,a)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof z;)e=e.right;return e instanceof Y?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(let n of e){if(n instanceof Array){let s=t.clone(),a=this._execStatements(n,s);if(a)return a;continue}let r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],o=this.evalExpression(e.args[s],n);n.setVariable(a.name,o,a)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){let n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof m?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof m?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof Y){let n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof z){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof _e?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,t);return new _e(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof z){let c=this._getVariableData(e.variable,t),l=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(c instanceof m||c instanceof p||c instanceof N){if(l instanceof m||l instanceof p||l instanceof N&&c.data.length===l.data.length)return void c.data.set(l.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(c instanceof U&&l instanceof U&&c.buffer.byteLength-c.offset>=l.buffer.byteLength-l.offset)return void(c.buffer.byteLength%4==0?new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4).set(new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4)):new Uint8Array(c.buffer,c.offset,c.typeInfo.size).set(new Uint8Array(l.buffer,l.offset,l.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return c instanceof m||c instanceof p||c instanceof N?l instanceof m||l instanceof p||l instanceof N?void c.data.set(l.data.map((f,_)=>c.data[_]+f)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(c instanceof m||c instanceof p||c instanceof N)&&(l instanceof m||l instanceof p||l instanceof N)?void c.data.set(l.data.map((f,_)=>c.data[_]-f)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof z){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let c=t.getVariable(r);if(!(c&&c.value instanceof _e))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=c.value.reference;let l=e.variable.postfix;if(!l){let u=e.variable.right;for(;u instanceof z;){if(u.postfix){l=u.postfix;break}u=u.right}}l&&(n=n.getSubData(this,l,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);let c=t.getVariable(r);if(c===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=c.value}if(n instanceof _e&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let a=this.evalExpression(e.value,t),o=e.operator;if(o==="=")if(n instanceof U)n.setDataValue(this,a,s,t);else if(s){if(!(n instanceof p||n instanceof N))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof xe){let c=this.evalExpression(s.index,t).value;if(n instanceof p){if(!(a instanceof m))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[c]=a.value}else{if(!(n instanceof N))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let l=this.evalExpression(s.index,t).value;if(l<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let u=n.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(l<2&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(l<2&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(l<2&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(l<3&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(l<3&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(l<3&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(l<4&&a.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*l]=a.data[0],n.data[2*l+1]=a.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(l<4&&a.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*l]=a.data[0],n.data[3*l+1]=a.data[1],n.data[3*l+2]=a.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(l<4&&a.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*l]=a.data[0],n.data[4*l+1]=a.data[1],n.data[4*l+2]=a.data[2],n.data[4*l+3]=a.data[3]}}}}}else if(s instanceof pe){let c=s.value;if(!(n instanceof p))return void console.error(`Invalid assignment to ${c}. Variable ${r} is not a vector. Line ${e.line}`);if(a instanceof m){if(c.length>1)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);if(c==="x")n.data[0]=a.value;else if(c==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[1]=a.value}else if(c==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[2]=a.value}else if(c==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);n.data[3]=a.value}}else{if(!(a instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(c.length!==a.data.length)return void console.error(`Invalid assignment to ${c} for variable ${r}. Line ${e.line}`);for(let l=0;l<c.length;++l){let u=c[l];if(u==="x"||u==="r")n.data[0]=a.data[l];else if(u==="y"||u==="g"){if(a.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[1]=a.data[l]}else if(u==="z"||u==="b"){if(a.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[2]=a.data[l]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(a.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[3]=a.data[l]}}}}}else n instanceof m&&a instanceof m?n.value=a.value:n instanceof p&&a instanceof p||n instanceof N&&a instanceof N?n.data.set(a.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`);else{let c=n.getSubData(this,s,t);if(c instanceof p&&a instanceof m){let l=c.data,u=a.value;if(o==="+=")for(let f=0;f<l.length;++f)l[f]+=u;else if(o==="-=")for(let f=0;f<l.length;++f)l[f]-=u;else if(o==="*=")for(let f=0;f<l.length;++f)l[f]*=u;else if(o==="/=")for(let f=0;f<l.length;++f)l[f]/=u;else if(o==="%=")for(let f=0;f<l.length;++f)l[f]%=u;else if(o==="&=")for(let f=0;f<l.length;++f)l[f]&=u;else if(o==="|=")for(let f=0;f<l.length;++f)l[f]|=u;else if(o==="^=")for(let f=0;f<l.length;++f)l[f]^=u;else if(o==="<<=")for(let f=0;f<l.length;++f)l[f]<<=u;else if(o===">>=")for(let f=0;f<l.length;++f)l[f]>>=u;else console.error(`Invalid operator ${o}. Line ${e.line}`)}else if(c instanceof p&&a instanceof p){let l=c.data,u=a.data;if(l.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(o==="+=")for(let f=0;f<l.length;++f)l[f]+=u[f];else if(o==="-=")for(let f=0;f<l.length;++f)l[f]-=u[f];else if(o==="*=")for(let f=0;f<l.length;++f)l[f]*=u[f];else if(o==="/=")for(let f=0;f<l.length;++f)l[f]/=u[f];else if(o==="%=")for(let f=0;f<l.length;++f)l[f]%=u[f];else if(o==="&=")for(let f=0;f<l.length;++f)l[f]&=u[f];else if(o==="|=")for(let f=0;f<l.length;++f)l[f]|=u[f];else if(o==="^=")for(let f=0;f<l.length;++f)l[f]^=u[f];else if(o==="<<=")for(let f=0;f<l.length;++f)l[f]<<=u[f];else if(o===">>=")for(let f=0;f<l.length;++f)l[f]>>=u[f];else console.error(`Invalid operator ${o}. Line ${e.line}`)}else{if(!(c instanceof m&&a instanceof m))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);o==="+="?c.value+=a.value:o==="-="?c.value-=a.value:o==="*="?c.value*=a.value:o==="/="?c.value/=a.value:o==="%="?c.value%=a.value:o==="&="?c.value&=a.value:o==="|="?c.value|=a.value:o==="^="?c.value^=a.value:o==="<<="?c.value<<=a.value:o===">>="?c.value>>=a.value:console.error(`Invalid operator ${o}. Line ${e.line}`)}n instanceof U&&n.setDataValue(this,c,s,t)}}_function(e,t){let n=new tt(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 z||(n=n.clone())}else{let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){let s=new ne(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof z||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof we||e.type instanceof ie||e.type instanceof x){let s=new ne(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof Ot)for(let a of s.selectors){if(a instanceof Ne){r=s;continue}let o=this.evalExpression(a,t);if(!(o instanceof m))return console.error(`Invalid case selector. Line ${e.line}`),null;if(o.value===n.value)return this._execStatements(s.body,t)}else s instanceof Pt&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(let r of e.elseif){let s=this.evalExpression(r.condition,t);if(!(s instanceof m))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof m?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n!==null&&n!==G._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n===G._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===G._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===G._breakObj)break;if(n!==G._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof m){let s=vr(n.value,n.typeInfo.name,r.name);return new m(s,this.getTypeInfo(r))}if(n instanceof p){let s=n.typeInfo.getTypeName(),a="";if(s.endsWith("f"))a="f32";else if(s.endsWith("i"))a="i32";else if(s.endsWith("u"))a="u32";else if(s.endsWith("b"))a="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;a="f16"}let o=r.getTypeName(),c="";if(o.endsWith("f"))c="f32";else if(o.endsWith("i"))c="i32";else if(o.endsWith("u"))c="u32";else if(o.endsWith("b"))c="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${c}. Line ${e.line}`),null;c="f16"}let l=function(u,f,_){if(f===_)return u;let b=new Array(u.length);for(let w=0;w<u.length;w++)b[w]=vr(u[w],f,_);return b}(Array.from(n.data),a,c);return new p(l,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof ne){if(e.type===null)return Je.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}let r=e instanceof ne?e.type.name:e.name,s=e instanceof ne?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;let a=new U(new ArrayBuffer(s.size),s,0);if(s instanceof ue){if(e.args)for(let o=0;o<e.args.length;++o){let c=s.members[o],l=e.args[o],u=this.evalExpression(l,t);a.setData(this,u,c.type,c.offset,t)}}else if(s instanceof fe){let o=0;if(e.args)for(let c=0;c<e.args.length;++c){let l=e.args[c],u=this.evalExpression(l,t);s.format===null&&(((n=u.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),a.setData(this,u,s.format,o,t),o+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof ne?a.getSubData(this,e.postfix,t):a}_evalLiteral(e,t){let n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new m(e.scalarValue,n):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){let n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=G._priority.get(t.name);G._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){let n=this.evalExpression(e.right,t);if(e.operator==="&")return new _e(n);if(e.operator==="*")return n instanceof _e?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof m?n.value:n instanceof p?Array.from(n.data):null;switch(e.operator){case"+":{if(A(r)){let o=r.map((c,l)=>+c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(+s,a)}case"-":{if(A(r)){let o=r.map((c,l)=>-c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(-s,a)}case"!":{if(A(r)){let o=r.map((c,l)=>c?0:1);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(s?0:1,a)}case"~":{if(A(r)){let o=r.map((c,l)=>~c);return new p(o,n.typeInfo)}let s=r,a=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new m(~s,a)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){let n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof m?n.value:n instanceof p||n instanceof N?Array.from(n.data):null,a=r instanceof m?r.value:r instanceof p||r instanceof N?Array.from(r.data):null;switch(e.operator){case"+":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b+f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_+u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u+_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o+c,l)}case"-":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b-f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_-u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u-_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o-c,l)}case"*":{if(A(s)&&A(a)){let u=s,f=a;if(n instanceof N&&r instanceof N){let _=function(S,E,T,k){if(X[E.name]===void 0||X[k.name]===void 0)return null;let I=X[E.name][0],C=X[E.name][1],M=X[k.name][0];if(I!==X[k.name][1])return null;let O=new Array(M*C);for(let V=0;V<C;V++)for(let F=0;F<M;F++){let D=0;for(let W=0;W<I;W++)D+=S[W*C+V]*T[F*I+W];O[V*M+F]=D}return O}(u,n.typeInfo,f,r.typeInfo);if(_===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let b=X[r.typeInfo.name][0],w=X[n.typeInfo.name][1],L=this.getTypeInfo(`mat${b}x${w}f`);return new N(_,L)}if(n instanceof N&&r instanceof p){let _=function(b,w,L,S){if(X[w.name]===void 0||cn[S.name]===void 0)return null;let E=X[w.name][0],T=X[w.name][1];if(E!==L.length)return null;let k=new Array(T);for(let I=0;I<T;I++){let C=0;for(let M=0;M<E;M++)C+=b[M*T+I]*L[M];k[I]=C}return k}(u,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,r.typeInfo)}if(n instanceof p&&r instanceof N){let _=function(b,w,L,S){if(cn[w.name]===void 0||X[S.name]===void 0)return null;let E=X[S.name][0],T=X[S.name][1];if(T!==b.length)return null;let k=[];for(let I=0;I<E;I++){let C=0;for(let M=0;M<T;M++)C+=b[M]*L[M*E+I];k[I]=C}return k}(u,n.typeInfo,f,r.typeInfo);return _===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(_,n.typeInfo)}{if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b*f[w]);return new p(_,n.typeInfo)}}if(A(s)){let u=a,f=s.map((_,b)=>_*u);return n instanceof N?new N(f,n.typeInfo):new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u*_);return r instanceof N?new N(f,r.typeInfo):new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o*c,l)}case"%":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b%f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_%u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u%_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o%c,l)}case"/":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b/f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_/u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u/_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o/c,l)}case"&":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b&f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_&u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u&_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o&c,l)}case"|":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b|f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_|u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u|_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o|c,l)}case"^":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b^f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_^u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u^_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o^c,l)}case"<<":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b<<f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_<<u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u<<_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o<<c,l)}case">>":{if(A(s)&&A(a)){let u=s,f=a;if(u.length!==f.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let _=u.map((b,w)=>b>>f[w]);return new p(_,n.typeInfo)}if(A(s)){let u=a,f=s.map((_,b)=>_>>u);return new p(f,n.typeInfo)}if(A(a)){let u=s,f=a.map((_,b)=>u>>_);return new p(f,r.typeInfo)}let o=s,c=a,l=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new m(o>>c,l)}case">":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u>c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l>o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o>l?1:0);return new p(c,r.typeInfo)}return new m(s>a?1:0,this.getTypeInfo("bool"));case"<":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u<c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l<o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o<l?1:0);return new p(c,r.typeInfo)}return new m(s<a?1:0,this.getTypeInfo("bool"));case"==":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u===c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l==o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o==l?1:0);return new p(c,r.typeInfo)}return new m(s===a?1:0,this.getTypeInfo("bool"));case"!=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u!==c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l!==o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o!==l?1:0);return new p(c,r.typeInfo)}return new m(s!==a?1:0,this.getTypeInfo("bool"));case">=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u>=c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l>=o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o>=l?1:0);return new p(c,r.typeInfo)}return new m(s>=a?1:0,this.getTypeInfo("bool"));case"<=":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u<=c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l<=o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o<=l?1:0);return new p(c,r.typeInfo)}return new m(s<=a?1:0,this.getTypeInfo("bool"));case"&&":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u&&c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l&&o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o&&l?1:0);return new p(c,r.typeInfo)}return new m(s&&a?1:0,this.getTypeInfo("bool"));case"||":if(A(s)&&A(a)){let o=s,c=a;if(o.length!==c.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let l=o.map((u,f)=>u||c[f]?1:0);return new p(l,n.typeInfo)}if(A(s)){let o=a,c=s.map((l,u)=>l||o?1:0);return new p(c,n.typeInfo)}if(A(a)){let o=s,c=a.map((l,u)=>o||l?1:0);return new p(c,r.typeInfo)}return new m(s||a?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){let a=r.node.args[s],o=this.evalExpression(e.args[s],n);n.createVariable(a.name,o,a)}return this._execStatements(r.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothStep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}let n=t.getFunction(e.name);if(n){let r=t.clone();for(let s=0;s<n.node.args.length;++s){let a=n.node.args[s],o=this.evalExpression(e.args[s],r);r.setVariable(a.name,o,a)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new m(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=cn[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof H)if(e.isVector){let o=e.vectorValue;for(let c of o)a.push(c)}else a.push(e.scalarValue);else if(e.args)for(let o of e.args){let c=this.evalExpression(o,t);if(c instanceof p){let l=c.data;for(let u=0;u<l.length;++u){let f=l[u];a.push(f)}}else if(c instanceof m){let l=c.value;a.push(l)}}if(e.type instanceof x&&e.type.format===null&&(e.type.format=x.f32),a.length===0){let o=new Array(s).fill(0);return new p(o,n).getSubData(this,e.postfix,t)}if(a.length===1)for(;a.length<s;)a.push(a[0]);return a.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new p(a.length>s?a.slice(0,s):a,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=X[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let a=[];if(e instanceof H)if(e.isVector){let o=e.vectorValue;for(let c of o)a.push(c)}else a.push(e.scalarValue);else if(e.args)for(let o of e.args){let c=this.evalExpression(o,t);c instanceof p?a.push(...c.data):c instanceof m?a.push(c.value):c instanceof N&&a.push(...c.data)}if(n instanceof he&&n.format===null&&(n.format=this.getTypeInfo("f32")),a.length===0){let o=new Array(s[2]).fill(0);return new N(o,n).getSubData(this,e.postfix,t)}return a.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new N(a,n).getSubData(this,e.postfix,t)}};G._breakObj=new J(new Z("BREAK",null),null),G._continueObj=new J(new Z("CONTINUE",null),null),G._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var In=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Sn=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new In,this._exec=new G,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,s=n.countNode;if(s instanceof Y){let a=s.name,o=this._context.constants.get(a);if(o)try{let c=o.constEvaluate(this._exec);r.count=c}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof Dt||r instanceof je?r.type=this._forwardType(r.type):r instanceof we?r.format=this._forwardType(r.format):r instanceof ae||r instanceof ye||r instanceof Ce?r.type=this._forwardType(r.type):r instanceof ke?r.returnType=this._forwardType(r.returnType):r instanceof Rt&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof Tt){let t=this._getType(e.name);if(t)return t}else e instanceof je?e.type=this._forwardType(e.type):e instanceof we&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new bn(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==h.eof}_match(e){if(e instanceof d)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){let r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let n=t.type,r=!1;for(let s of e){if(n===s)return!0;s===h.tokens.name&&(r=!0)}if(r){let s=h.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===h.tokens.name){let n=h.tokens.name.rule.exec(t.lexeme);return n&&n.index==0&&n[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._match(h.keywords.alias)){let t=this._type_alias();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.diagnostic)){let t=this._diagnostic();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.requires)){let t=this._requires_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(h.keywords.enable)){let t=this._enable_directive();return this._consume(h.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}let e=this._attribute();if(this._check(h.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(h.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(h.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(h.keywords.fn))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected function name.").toString();this._consume(h.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(h.tokens.paren_right))do{if(this._check(h.tokens.paren_right))break;let o=this._attribute(),c=this._consume(h.tokens.name,"Expected argument name.").toString();this._consume(h.tokens.colon,"Expected ':' for argument type.");let l=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=l,n.push(this._updateNode(new Rt(c,u,o))))}while(this._match(h.tokens.comma));this._consume(h.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(h.tokens.arrow)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let s=this._compound_statement(),a=this._currentLine;return this._updateNode(new ke(t,n,r,s,e,a),e)}_compound_statement(){let e=[];for(this._consume(h.tokens.brace_left,"Expected '{' for block.");!this._check(h.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(h.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(h.tokens.semicolon)&&!this._isAtEnd(););if(this._check(h.tokens.attr)&&this._attribute(),this._check(h.keywords.if))return this._if_statement();if(this._check(h.keywords.switch))return this._switch_statement();if(this._check(h.keywords.loop))return this._loop_statement();if(this._check(h.keywords.for))return this._for_statement();if(this._check(h.keywords.while))return this._while_statement();if(this._check(h.keywords.continuing))return this._continuing_statement();if(this._check(h.keywords.static_assert))return this._static_assert_statement();if(this._check(h.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(h.keywords.return))e=this._return_statement();else if(this._check([h.keywords.var,h.keywords.let,h.keywords.const]))e=this._variable_statement();else if(this._match(h.keywords.discard))e=this._updateNode(new xn);else if(this._match(h.keywords.break)){let t=this._updateNode(new At);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t,this._check(h.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(h.keywords.continue)){let t=this._updateNode(new Lt);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(h.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(h.keywords.static_assert))return null;let e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new dn(t),e)}_while_statement(){if(!this._match(h.keywords.while))return null;let e=this._updateNode(new _t(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(h.keywords.continuing))return null;let t=this._currentLine,n=this._compound_statement();return this._updateNode(new Xe(n,e),t)}_for_statement(){if(!this._match(h.keywords.for))return null;this._consume(h.tokens.paren_left,"Expected '('.");let e=this._updateNode(new xt(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(h.tokens.semicolon)?null:this._for_init(),this._consume(h.tokens.semicolon,"Expected ';'."),e.condition=this._check(h.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(h.tokens.semicolon,"Expected ';'."),e.increment=this._check(h.tokens.paren_right)?null:this._for_increment(),this._consume(h.tokens.paren_right,"Expected ')'."),this._check(h.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(h.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(h.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new ae(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(h.keywords.let)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return this._updateNode(new ye(t,n,null,null,r),e)}if(this._match(h.keywords.const)){let e=this._currentLine,t=this._consume(h.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(h.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return n===null&&r instanceof H&&(n=r.type),this._updateNode(new Ce(t,n,null,null,r),e)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(h.increment_operators))return this._current=e,null;let n=this._consume(h.increment_operators,"Expected increment operator");return this._updateNode(new vt(n.type===h.tokens.plus_plus?Ee.increment:Ee.decrement,t))}_assignment_statement(){let e=null,t=this._currentLine;if(this._check(h.tokens.brace_right))return null;let n=this._match(h.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;let r=this._consume(h.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new bt(qe.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(h.tokens.ident))return null;let e=this._currentLine,t=this._current,n=this._consume(h.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new Ke(n.lexeme,r),e)}_loop_statement(){if(!this._match(h.keywords.loop))return null;this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new yt([],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 Xe){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(h.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(h.keywords.switch))return null;let e=this._updateNode(new wt(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(h.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],t=!1;for(;this._check([h.keywords.default,h.keywords.case]);){if(this._match(h.keywords.case)){let n=this._case_selectors();for(let s of n)if(s instanceof Ne){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new Ot(n,r)))}if(this._match(h.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(h.tokens.colon),this._check(h.tokens.attr)&&this._attribute(),this._consume(h.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(h.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new Pt(n)))}}return e}_case_selectors(){let e=[];for(this._match(h.keywords.default)?e.push(this._updateNode(new Ne)):e.push(this._shift_expression());this._match(h.tokens.comma);)this._match(h.keywords.default)?e.push(this._updateNode(new Ne)):e.push(this._shift_expression());return e}_case_body(){if(this._match(h.keywords.fallthrough))return this._consume(h.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(h.keywords.if))return null;let e=this._currentLine,t=this._optional_paren_expression();this._check(h.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(h.keywords.else)&&(this._check(h.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new kt(t,n,r,s),e)}_match_elseif(){return this._tokens[this._current].type===h.keywords.else&&this._tokens[this._current+1].type===h.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new vn(t,n))),this._match_elseif()&&(this._check(h.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(h.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new It(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(h.tokens.or_or);)e=this._updateNode(new ee(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(h.tokens.and_and);)e=this._updateNode(new ee(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(h.tokens.or);)e=this._updateNode(new ee(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(h.tokens.xor);)e=this._updateNode(new ee(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(h.tokens.and);)e=this._updateNode(new ee(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([h.tokens.equal_equal,h.tokens.not_equal])?this._updateNode(new ee(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([h.tokens.less_than,h.tokens.greater_than,h.tokens.less_than_equal,h.tokens.greater_than_equal]);)e=this._updateNode(new ee(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([h.tokens.shift_left,h.tokens.shift_right]);)e=this._updateNode(new ee(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([h.tokens.plus,h.tokens.minus]);)e=this._updateNode(new ee(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([h.tokens.star,h.tokens.forward_slash,h.tokens.modulo]);)e=this._updateNode(new ee(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([h.tokens.minus,h.tokens.bang,h.tokens.tilde,h.tokens.star,h.tokens.and])?this._updateNode(new z(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(h.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(h.tokens.bracket_right,"Expected ']'.");let t=this._updateNode(new xe(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(h.tokens.period)){let e=this._consume(h.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new pe(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return y.void;case"bool":return y.bool;case"i32":return y.i32;case"u32":return y.u32;case"f32":return y.f32;case"f16":return y.f16;case"vec2f":return x.vec2f;case"vec3f":return x.vec3f;case"vec4f":return x.vec4f;case"vec2i":return x.vec2i;case"vec3i":return x.vec3i;case"vec4i":return x.vec4i;case"vec2u":return x.vec2u;case"vec3u":return x.vec3u;case"vec4u":return x.vec4u;case"vec2h":return x.vec2h;case"vec3h":return x.vec3h;case"vec4h":return x.vec4h;case"mat2x2f":return x.mat2x2f;case"mat2x3f":return x.mat2x3f;case"mat2x4f":return x.mat2x4f;case"mat3x2f":return x.mat3x2f;case"mat3x3f":return x.mat3x3f;case"mat3x4f":return x.mat3x4f;case"mat4x2f":return x.mat4x2f;case"mat4x3f":return x.mat4x3f;case"mat4x4f":return x.mat4x4f;case"mat2x2h":return x.mat2x2h;case"mat2x3h":return x.mat2x3h;case"mat2x4h":return x.mat2x4h;case"mat3x2h":return x.mat3x2h;case"mat3x3h":return x.mat3x3h;case"mat3x4h":return x.mat3x4h;case"mat4x2h":return x.mat4x2h;case"mat4x3h":return x.mat4x3h;case"mat4x4h":return x.mat4x4h;case"mat2x2i":return x.mat2x2i;case"mat2x3i":return x.mat2x3i;case"mat2x4i":return x.mat2x4i;case"mat3x2i":return x.mat3x2i;case"mat3x3i":return x.mat3x3i;case"mat3x4i":return x.mat3x4i;case"mat4x2i":return x.mat4x2i;case"mat4x3i":return x.mat4x3i;case"mat4x4i":return x.mat4x4i;case"mat2x2u":return x.mat2x2u;case"mat2x3u":return x.mat2x3u;case"mat2x4u":return x.mat2x4u;case"mat3x2u":return x.mat3x2u;case"mat3x3u":return x.mat3x3u;case"mat3x4u":return x.mat3x4u;case"mat4x2u":return x.mat4x2u;case"mat4x3u":return x.mat4x3u;case"mat4x4u":return x.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(h.tokens.ident)){let n=this._previous().toString();if(this._check(h.tokens.paren_left)){let r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new ne(s,r)):this._updateNode(new Qe(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new Et(n,r.value))}return this._updateNode(new Y(n))}if(this._match(h.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?y.i32:n.endsWith("u")||n.endsWith("U")?y.u32:y.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new H(new m(s,this._exec.getTypeInfo(r)),r))}if(this._match(h.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,y.u32),this._updateNode(new H(new m(n,this._exec.getTypeInfo(y.u32)),y.u32))}if(this._match([h.tokens.decimal_float_literal,h.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));let s=parseFloat(n);this._validateTypeRange(s,r?y.f16:y.f32);let a=r?y.f16:y.f32;return this._updateNode(new H(new m(s,this._exec.getTypeInfo(a)),a))}if(this._match([h.keywords.true,h.keywords.false])){let n=this._previous().toString()===h.keywords.true.rule;return this._updateNode(new H(new m(n?1:0,this._exec.getTypeInfo(y.bool)),y.bool))}if(this._check(h.tokens.paren_left))return this._paren_expression();if(this._match(h.keywords.bitcast)){this._consume(h.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(h.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return this._updateNode(new Mt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new ne(e,t))}_argument_expression_list(){if(!this._match(h.tokens.paren_left))return null;let e=[];do{if(this._check(h.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(h.tokens.comma));return this._consume(h.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(h.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(h.tokens.paren_right),e}_paren_expression(){this._consume(h.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(h.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(h.keywords.struct))return null;let e=this._currentLine,t=this._consume(h.tokens.ident,"Expected name for struct.").toString();this._consume(h.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(h.tokens.brace_right);){let a=this._attribute(),o=this._consume(h.tokens.name,"Expected variable name.").toString();this._consume(h.tokens.colon,"Expected ':' for struct member type.");let c=this._attribute(),l=this._type_decl();l!=null&&(l.attributes=c),this._check(h.tokens.brace_right)?this._match(h.tokens.comma):this._consume(h.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new Dt(o,l,a)))}this._consume(h.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new ie(t,n,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(h.tokens.equal)){let t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof H){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 H&&(e.type=e.value.type.name==="x32"?y.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(h.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(h.keywords.const))return null;let t=this._consume(h.tokens.name,"Expected variable name"),n=this._currentLine,r=null;if(this._match(h.tokens.colon)){let c=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=c)}let s=null;this._consume(h.tokens.equal,"const declarations require an assignment");let a=this._short_circuit_or_expression();try{let c=[y.f32],l=a.constEvaluate(this._exec,c);l instanceof m&&this._validateTypeRange(l.value,c[0]),c[0]instanceof x&&c[0].format===null&&l.typeInfo instanceof he&&l.typeInfo.format!==null&&(l.typeInfo.format.name==="f16"?c[0].format=y.f16:l.typeInfo.format.name==="f32"?c[0].format=y.f32:l.typeInfo.format.name==="i32"?c[0].format=y.i32:l.typeInfo.format.name==="u32"?c[0].format=y.u32:l.typeInfo.format.name==="bool"?c[0].format=y.bool:console.error(`TODO: impelement template format type ${l.typeInfo.format.name}`)),s=this._updateNode(new H(l,c[0])),this._exec.context.setVariable(t.toString(),l)}catch{s=a}if(r!==null&&s instanceof H){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof H&&(r=(e=s?.type)!==null&&e!==void 0?e:y.f32,r===y.x32&&(r=y.i32));let o=this._updateNode(new Ce(t.toString(),r,"","",s),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(h.keywords.let))return null;let e=this._currentLine,t=this._consume(h.tokens.name,"Expected variable name"),n=null;if(this._match(h.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(h.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof H){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof H&&(n=r.type.name==="x32"?y.i32:r.type);return r instanceof H&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new ye(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(h.keywords.var))return null;let e=this._currentLine,t="",n="";this._match(h.tokens.less_than)&&(t=this._consume(h.storage_class,"Expected storage_class.").toString(),this._match(h.tokens.comma)&&(n=this._consume(h.access_mode,"Expected access_mode.").toString()),this._consume(h.tokens.greater_than,"Expected '>'."));let r=this._consume(h.tokens.name,"Expected variable name"),s=null;if(this._match(h.tokens.colon)){let a=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=a)}return this._updateNode(new ae(r.toString(),s,t,n,null),e)}_override_decl(){if(!this._match(h.keywords.override))return null;let e=this._consume(h.tokens.name,"Expected variable name"),t=null;if(this._match(h.tokens.colon)){let n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new Ye(e.toString(),t,null))}_diagnostic(){this._consume(h.tokens.paren_left,"Expected '('");let e=this._consume(h.tokens.ident,"Expected severity control name.");this._consume(h.tokens.comma,"Expected ','");let t=this._consume(h.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(h.tokens.period)&&(t+=`.${this._consume(h.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(h.tokens.paren_right,"Expected ')'"),this._updateNode(new St(e.toString(),t))}_enable_directive(){let e=this._consume(h.tokens.ident,"identity expected.");return this._updateNode(new gn(e.toString()))}_requires_directive(){let e=[this._consume(h.tokens.ident,"identity expected.").toString()];for(;this._match(h.tokens.comma);){let t=this._consume(h.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new _n(e))}_type_alias(){let e=this._consume(h.tokens.ident,"identity expected.");this._consume(h.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let n=this._updateNode(new Ze(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([h.tokens.ident,...h.texel_format,h.keywords.bool,h.keywords.f32,h.keywords.i32,h.keywords.u32])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let r=this._updateNode(new Tt(n));return this._forwardTypeCount++,r}return this._updateNode(new y(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(h.template_types)){let n=this._advance().toString(),r=null,s=null;return this._match(h.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(h.tokens.comma)&&(s=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new x(n,r,s))}if(this._match(h.keywords.ptr)){let n=this._previous().toString();this._consume(h.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(h.storage_class,"Expected storage_class for pointer");this._consume(h.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),a=null;return this._match(h.tokens.comma)&&(a=this._consume(h.access_mode,"Expected access_mode for pointer").toString()),this._consume(h.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new je(n,r.toString(),s,a))}let t=this._attribute();if(this._match(h.keywords.array)){let n=null,r=-1,s=this._previous(),a=null;if(this._match(h.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let c="";if(this._match(h.tokens.comma)){a=this._shift_expression();try{c=a.constEvaluate(this._exec).toString(),a=null}catch{c="1"}}this._consume(h.tokens.greater_than,"Expected '>' for array."),r=c?parseInt(c):0}let o=this._updateNode(new we(s.toString(),t,n,r));return a&&this._deferArrayCountEval.push({arrayType:o,countNode:a}),o}return null}_texture_sampler_types(){if(this._match(h.sampler_type))return this._updateNode(new be(this._previous().toString(),null,null));if(this._match(h.depth_texture_type))return this._updateNode(new be(this._previous().toString(),null,null));if(this._match(h.sampled_texture_type)||this._match(h.multisampled_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new be(e.toString(),t,null))}if(this._match(h.storage_texture_type)){let e=this._previous();this._consume(h.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(h.texel_format,"Invalid texel format.").toString();this._consume(h.tokens.comma,"Expected ',' after texel format.");let n=this._consume(h.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(h.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new be(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(h.tokens.attr);){let t=this._consume(h.attribute_name,"Expected attribute name"),n=this._updateNode(new Ft(t.toString(),null));if(this._match(h.tokens.paren_left)){if(n.value=this._consume(h.literal_or_ident,"Expected attribute value").toString(),this._check(h.tokens.comma)){this._advance();do{let r=this._consume(h.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(h.tokens.comma))}this._consume(h.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}},zt=class extends re{constructor(e){super(),e&&this.update(e)}update(e){let t=new Sn().parse(e);this.updateAST(t)}};function Sr(i){let e={attributes:[],bindings:[]},t;try{t=fi(i)}catch(s){return Ir.log.error(s.message)(),e}for(let s of t.uniforms){let a=[];for(let o of s.type?.members||[])a.push({name:o.name,type:kr(o.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:a})}for(let s of t.textures)e.bindings.push({type:"texture",name:s.name,group:s.group,location:s.binding});for(let s of t.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let n=t.entry.vertex[0],r=n?.inputs.length||0;for(let s=0;s<r;s++){let a=n.inputs[s];if(a.locationType==="location"){let o=kr(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:o})}}return e}function kr(i){return i.format?`${i.name}<${i.format.name}>`:i.name}function fi(i){try{return new zt(i)}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})}}var Yo=1/Math.PI*180,Ko=1/180*Math.PI,hi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hi}};var K=globalThis.mathgl.config;function Ln(i,{precision:e=K.precision}={}){return i=pi(i),`${parseFloat(i.toPrecision(e))}`}function Re(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Tn(i,e,t){return di(i,n=>Math.max(e,Math.min(t,n)))}function Wt(i,e,t){let n=K.EPSILON;t&&(K.EPSILON=t);try{if(i===e)return!0;if(Re(i)&&Re(e)){if(i.length!==e.length)return!1;for(let r=0;r<i.length;++r)if(!Wt(i[r],e[r]))return!1;return!0}return i&&i.equals?i.equals(e):e&&e.equals?e.equals(i):typeof i=="number"&&typeof e=="number"?Math.abs(i-e)<=K.EPSILON*Math.max(1,Math.abs(i),Math.abs(e)):!1}finally{K.EPSILON=n}}function pi(i){return Math.round(i/K.EPSILON)*K.EPSILON}function mi(i){return i.clone?i.clone():new Array(i.length)}function di(i,e,t){if(Re(i)){let n=i;t=t||mi(n);for(let r=0;r<t.length&&r<n.length;++r){let s=typeof i=="number"?i:i[r];t[r]=e(s,r,t)}return t}return e(i)}var Ht=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=e[n+t];return this.check()}toArray(e=[],t=0){for(let n=0;n<this.ELEMENTS;++n)e[t+n]=this[n];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Re(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(K)}formatString(e){let t="";for(let n=0;n<this.ELEMENTS;++n)t+=(n>0?", ":"")+Ln(this[n],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!Wt(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,n){if(n===void 0)return this.lerp(this,e,t);for(let r=0;r<this.ELEMENTS;++r){let s=e[r],a=typeof t=="number"?t:t[r];this[r]=s+n*(a-s)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e[n]),t[n]);return this.check()}add(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]+=t[n];return this.check()}subtract(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]-=t[n];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(K.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e),t);return this.check()}get elements(){return this}};function gi(i,e){if(i.length!==e)return!1;for(let t=0;t<i.length;++t)if(!Number.isFinite(i[t]))return!1;return!0}function Ar(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Gt(i,e,t=""){if(K.debug&&!gi(i,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return i}var me=typeof Float32Array<"u"?Float32Array:Array;var na=Math.PI/180;function _i(){let i=new me(2);return me!=Float32Array&&(i[0]=0,i[1]=0),i}function Er(i,e,t){let n=e[0],r=e[1];return i[0]=t[0]*n+t[4]*r+t[12],i[1]=t[1]*n+t[5]*r+t[13],i}var ra=function(){let i=_i();return function(e,t,n,r,s,a){let o,c;for(t||(t=2),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],s(i,i,a),e[o]=i[0],e[o+1]=i[1];return e}}();function Mr(i,e,t){let n=e[0],r=e[1],s=t[3]*n+t[7]*r||1;return i[0]=(t[0]*n+t[4]*r)/s,i[1]=(t[1]*n+t[5]*r)/s,i}function Cr(i,e,t){let n=e[0],r=e[1],s=e[2],a=t[3]*n+t[7]*r+t[11]*s||1;return i[0]=(t[0]*n+t[4]*r+t[8]*s)/a,i[1]=(t[1]*n+t[5]*r+t[9]*s)/a,i[2]=(t[2]*n+t[6]*r+t[10]*s)/a,i}function xi(){let i=new me(3);return me!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Nr(i,e,t){let n=e[0],r=e[1],s=e[2],a=t[3]*n+t[7]*r+t[11]*s+t[15];return a=a||1,i[0]=(t[0]*n+t[4]*r+t[8]*s+t[12])/a,i[1]=(t[1]*n+t[5]*r+t[9]*s+t[13])/a,i[2]=(t[2]*n+t[6]*r+t[10]*s+t[14])/a,i}var oa=function(){let i=xi();return function(e,t,n,r,s,a){let o,c;for(t||(t=3),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],i[2]=e[o+2],s(i,i,a),e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2];return e}}();var qt=class extends Ht{toString(){let e="[";if(K.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let n=0;n<this.RANK;++n)e+=` ${this[n*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,n){return this[t*this.RANK+e]=Ar(n),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)t[r]=this[n+r];return t}setColumn(e,t){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=t[r];return this}};function vi(i){return i[0]=1,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=1,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=1,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Or(i,e){if(i===e){let t=e[1],n=e[2],r=e[3],s=e[6],a=e[7],o=e[11];i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=t,i[6]=e[9],i[7]=e[13],i[8]=n,i[9]=s,i[11]=e[14],i[12]=r,i[13]=a,i[14]=o}else i[0]=e[0],i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=e[1],i[5]=e[5],i[6]=e[9],i[7]=e[13],i[8]=e[2],i[9]=e[6],i[10]=e[10],i[11]=e[14],i[12]=e[3],i[13]=e[7],i[14]=e[11],i[15]=e[15];return i}function Pr(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=e[9],_=e[10],b=e[11],w=e[12],L=e[13],S=e[14],E=e[15],T=t*o-n*a,k=t*c-r*a,I=t*l-s*a,C=n*c-r*o,M=n*l-s*o,O=r*l-s*c,V=u*L-f*w,F=u*S-_*w,D=u*E-b*w,W=f*S-_*L,te=f*E-b*L,j=_*E-b*S,$=T*j-k*te+I*W+C*D-M*F+O*V;return $?($=1/$,i[0]=(o*j-c*te+l*W)*$,i[1]=(r*te-n*j-s*W)*$,i[2]=(L*O-S*M+E*C)*$,i[3]=(_*M-f*O-b*C)*$,i[4]=(c*D-a*j-l*F)*$,i[5]=(t*j-r*D+s*F)*$,i[6]=(S*I-w*O-E*k)*$,i[7]=(u*O-_*I+b*k)*$,i[8]=(a*te-o*D+l*V)*$,i[9]=(n*D-t*te-s*V)*$,i[10]=(w*M-L*I+E*T)*$,i[11]=(f*I-u*M-b*T)*$,i[12]=(o*F-a*W-c*V)*$,i[13]=(t*W-n*F+r*V)*$,i[14]=(L*k-w*C-S*T)*$,i[15]=(u*C-f*k+_*T)*$,i):null}function Rr(i){let e=i[0],t=i[1],n=i[2],r=i[3],s=i[4],a=i[5],o=i[6],c=i[7],l=i[8],u=i[9],f=i[10],_=i[11],b=i[12],w=i[13],L=i[14],S=i[15],E=e*a-t*s,T=e*o-n*s,k=t*o-n*a,I=l*w-u*b,C=l*L-f*b,M=u*L-f*w,O=e*M-t*C+n*I,V=s*M-a*C+o*I,F=l*k-u*T+f*E,D=b*k-w*T+L*E;return c*O-r*V+S*F-_*D}function Mn(i,e,t){let n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],c=e[5],l=e[6],u=e[7],f=e[8],_=e[9],b=e[10],w=e[11],L=e[12],S=e[13],E=e[14],T=e[15],k=t[0],I=t[1],C=t[2],M=t[3];return i[0]=k*n+I*o+C*f+M*L,i[1]=k*r+I*c+C*_+M*S,i[2]=k*s+I*l+C*b+M*E,i[3]=k*a+I*u+C*w+M*T,k=t[4],I=t[5],C=t[6],M=t[7],i[4]=k*n+I*o+C*f+M*L,i[5]=k*r+I*c+C*_+M*S,i[6]=k*s+I*l+C*b+M*E,i[7]=k*a+I*u+C*w+M*T,k=t[8],I=t[9],C=t[10],M=t[11],i[8]=k*n+I*o+C*f+M*L,i[9]=k*r+I*c+C*_+M*S,i[10]=k*s+I*l+C*b+M*E,i[11]=k*a+I*u+C*w+M*T,k=t[12],I=t[13],C=t[14],M=t[15],i[12]=k*n+I*o+C*f+M*L,i[13]=k*r+I*c+C*_+M*S,i[14]=k*s+I*l+C*b+M*E,i[15]=k*a+I*u+C*w+M*T,i}function Dr(i,e,t){let n=t[0],r=t[1],s=t[2],a,o,c,l,u,f,_,b,w,L,S,E;return e===i?(i[12]=e[0]*n+e[4]*r+e[8]*s+e[12],i[13]=e[1]*n+e[5]*r+e[9]*s+e[13],i[14]=e[2]*n+e[6]*r+e[10]*s+e[14],i[15]=e[3]*n+e[7]*r+e[11]*s+e[15]):(a=e[0],o=e[1],c=e[2],l=e[3],u=e[4],f=e[5],_=e[6],b=e[7],w=e[8],L=e[9],S=e[10],E=e[11],i[0]=a,i[1]=o,i[2]=c,i[3]=l,i[4]=u,i[5]=f,i[6]=_,i[7]=b,i[8]=w,i[9]=L,i[10]=S,i[11]=E,i[12]=a*n+u*r+w*s+e[12],i[13]=o*n+f*r+L*s+e[13],i[14]=c*n+_*r+S*s+e[14],i[15]=l*n+b*r+E*s+e[15]),i}function Fr(i,e,t){let n=t[0],r=t[1],s=t[2];return i[0]=e[0]*n,i[1]=e[1]*n,i[2]=e[2]*n,i[3]=e[3]*n,i[4]=e[4]*r,i[5]=e[5]*r,i[6]=e[6]*r,i[7]=e[7]*r,i[8]=e[8]*s,i[9]=e[9]*s,i[10]=e[10]*s,i[11]=e[11]*s,i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15],i}function Br(i,e,t,n){let r=n[0],s=n[1],a=n[2],o=Math.sqrt(r*r+s*s+a*a),c,l,u,f,_,b,w,L,S,E,T,k,I,C,M,O,V,F,D,W,te,j,$,Be;return o<1e-6?null:(o=1/o,r*=o,s*=o,a*=o,l=Math.sin(t),c=Math.cos(t),u=1-c,f=e[0],_=e[1],b=e[2],w=e[3],L=e[4],S=e[5],E=e[6],T=e[7],k=e[8],I=e[9],C=e[10],M=e[11],O=r*r*u+c,V=s*r*u+a*l,F=a*r*u-s*l,D=r*s*u-a*l,W=s*s*u+c,te=a*s*u+r*l,j=r*a*u+s*l,$=s*a*u-r*l,Be=a*a*u+c,i[0]=f*O+L*V+k*F,i[1]=_*O+S*V+I*F,i[2]=b*O+E*V+C*F,i[3]=w*O+T*V+M*F,i[4]=f*D+L*W+k*te,i[5]=_*D+S*W+I*te,i[6]=b*D+E*W+C*te,i[7]=w*D+T*W+M*te,i[8]=f*j+L*$+k*Be,i[9]=_*j+S*$+I*Be,i[10]=b*j+E*$+C*Be,i[11]=w*j+T*$+M*Be,e!==i&&(i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i)}function Vr(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[4],a=e[5],o=e[6],c=e[7],l=e[8],u=e[9],f=e[10],_=e[11];return e!==i&&(i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[4]=s*r+l*n,i[5]=a*r+u*n,i[6]=o*r+f*n,i[7]=c*r+_*n,i[8]=l*r-s*n,i[9]=u*r-a*n,i[10]=f*r-o*n,i[11]=_*r-c*n,i}function $r(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],a=e[1],o=e[2],c=e[3],l=e[8],u=e[9],f=e[10],_=e[11];return e!==i&&(i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r-l*n,i[1]=a*r-u*n,i[2]=o*r-f*n,i[3]=c*r-_*n,i[8]=s*n+l*r,i[9]=a*n+u*r,i[10]=o*n+f*r,i[11]=c*n+_*r,i}function Ur(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],a=e[1],o=e[2],c=e[3],l=e[4],u=e[5],f=e[6],_=e[7];return e!==i&&(i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r+l*n,i[1]=a*r+u*n,i[2]=o*r+f*n,i[3]=c*r+_*n,i[4]=l*r-s*n,i[5]=u*r-a*n,i[6]=f*r-o*n,i[7]=_*r-c*n,i}function zr(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],a=t+t,o=n+n,c=r+r,l=t*a,u=n*a,f=n*o,_=r*a,b=r*o,w=r*c,L=s*a,S=s*o,E=s*c;return i[0]=1-f-w,i[1]=u+E,i[2]=_-S,i[3]=0,i[4]=u-E,i[5]=1-l-w,i[6]=b+L,i[7]=0,i[8]=_+S,i[9]=b-L,i[10]=1-l-f,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Wr(i,e,t,n,r,s,a){let o=1/(t-e),c=1/(r-n),l=1/(s-a);return i[0]=s*2*o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s*2*c,i[6]=0,i[7]=0,i[8]=(t+e)*o,i[9]=(r+n)*c,i[10]=(a+s)*l,i[11]=-1,i[12]=0,i[13]=0,i[14]=a*s*2*l,i[15]=0,i}function bi(i,e,t,n,r){let s=1/Math.tan(e/2);if(i[0]=s/t,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,r!=null&&r!==1/0){let a=1/(n-r);i[10]=(r+n)*a,i[14]=2*r*n*a}else i[10]=-1,i[14]=-2*n;return i}var Hr=bi;function yi(i,e,t,n,r,s,a){let o=1/(e-t),c=1/(n-r),l=1/(s-a);return i[0]=-2*o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=-2*c,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=2*l,i[11]=0,i[12]=(e+t)*o,i[13]=(r+n)*c,i[14]=(a+s)*l,i[15]=1,i}var Gr=yi;function qr(i,e,t,n){let r,s,a,o,c,l,u,f,_,b,w=e[0],L=e[1],S=e[2],E=n[0],T=n[1],k=n[2],I=t[0],C=t[1],M=t[2];return Math.abs(w-I)<1e-6&&Math.abs(L-C)<1e-6&&Math.abs(S-M)<1e-6?vi(i):(f=w-I,_=L-C,b=S-M,r=1/Math.sqrt(f*f+_*_+b*b),f*=r,_*=r,b*=r,s=T*b-k*_,a=k*f-E*b,o=E*_-T*f,r=Math.sqrt(s*s+a*a+o*o),r?(r=1/r,s*=r,a*=r,o*=r):(s=0,a=0,o=0),c=_*o-b*a,l=b*s-f*o,u=f*a-_*s,r=Math.sqrt(c*c+l*l+u*u),r?(r=1/r,c*=r,l*=r,u*=r):(c=0,l=0,u=0),i[0]=s,i[1]=c,i[2]=f,i[3]=0,i[4]=a,i[5]=l,i[6]=_,i[7]=0,i[8]=o,i[9]=u,i[10]=b,i[11]=0,i[12]=-(s*w+a*L+o*S),i[13]=-(c*w+l*L+u*S),i[14]=-(f*w+_*L+b*S),i[15]=1,i)}function wi(){let i=new me(4);return me!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function jr(i,e,t){let n=e[0],r=e[1],s=e[2],a=e[3];return i[0]=t[0]*n+t[4]*r+t[8]*s+t[12]*a,i[1]=t[1]*n+t[5]*r+t[9]*s+t[13]*a,i[2]=t[2]*n+t[6]*r+t[10]*s+t[14]*a,i[3]=t[3]*n+t[7]*r+t[11]*s+t[15]*a,i}var pa=function(){let i=wi();return function(e,t,n,r,s,a){let o,c;for(t||(t=4),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,o=n;o<c;o+=t)i[0]=e[o],i[1]=e[o+1],i[2]=e[o+2],i[3]=e[o+3],s(i,i,a),e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3];return e}}();var On;(function(i){i[i.COL0ROW0=0]="COL0ROW0",i[i.COL0ROW1=1]="COL0ROW1",i[i.COL0ROW2=2]="COL0ROW2",i[i.COL0ROW3=3]="COL0ROW3",i[i.COL1ROW0=4]="COL1ROW0",i[i.COL1ROW1=5]="COL1ROW1",i[i.COL1ROW2=6]="COL1ROW2",i[i.COL1ROW3=7]="COL1ROW3",i[i.COL2ROW0=8]="COL2ROW0",i[i.COL2ROW1=9]="COL2ROW1",i[i.COL2ROW2=10]="COL2ROW2",i[i.COL2ROW3=11]="COL2ROW3",i[i.COL3ROW0=12]="COL3ROW0",i[i.COL3ROW1=13]="COL3ROW1",i[i.COL3ROW2=14]="COL3ROW2",i[i.COL3ROW3=15]="COL3ROW3"})(On||(On={}));var ki=45*Math.PI/180,Ii=1,Cn=.1,Nn=500,Si=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),Ie=class extends qt{static get IDENTITY(){return Li()}static get ZERO(){return Ai()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return On}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,n,r,s,a,o,c,l,u,f,_,b,w,L,S){return this[0]=e,this[1]=t,this[2]=n,this[3]=r,this[4]=s,this[5]=a,this[6]=o,this[7]=c,this[8]=l,this[9]=u,this[10]=f,this[11]=_,this[12]=b,this[13]=w,this[14]=L,this[15]=S,this.check()}setRowMajor(e,t,n,r,s,a,o,c,l,u,f,_,b,w,L,S){return this[0]=e,this[1]=s,this[2]=l,this[3]=b,this[4]=t,this[5]=a,this[6]=u,this[7]=w,this[8]=n,this[9]=o,this[10]=f,this[11]=L,this[12]=r,this[13]=c,this[14]=_,this[15]=S,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(Si)}fromObject(e){return this.check()}fromQuaternion(e){return zr(this,e),this.check()}frustum(e){let{left:t,right:n,bottom:r,top:s,near:a=Cn,far:o=Nn}=e;return o===1/0?Ti(this,t,n,r,s,a):Wr(this,t,n,r,s,a,o),this.check()}lookAt(e){let{eye:t,center:n=[0,0,0],up:r=[0,1,0]}=e;return qr(this,t,n,r),this.check()}ortho(e){let{left:t,right:n,bottom:r,top:s,near:a=Cn,far:o=Nn}=e;return Gr(this,t,n,r,s,a,o),this.check()}orthographic(e){let{fovy:t=ki,aspect:n=Ii,focalDistance:r=1,near:s=Cn,far:a=Nn}=e;Xr(t);let o=t/2,c=r*Math.tan(o),l=c*n;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:s,far:a})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:n=1,near:r=.1,far:s=500}=e;return Xr(t),Hr(this,t,n,r,s),this.check()}determinant(){return Rr(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],a=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*r,e[5]=this[5]*s,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*r,e[9]=this[9]*s,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],a=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*a,e[3]=this[4]*r,e[4]=this[5]*s,e[5]=this[6]*a,e[6]=this[8]*r,e[7]=this[9]*s,e[8]=this[10]*a,e}transpose(){return Or(this,this),this.check()}invert(){return Pr(this,this),this.check()}multiplyLeft(e){return Mn(this,e,this),this.check()}multiplyRight(e){return Mn(this,this,e),this.check()}rotateX(e){return Vr(this,this,e),this.check()}rotateY(e){return $r(this,this,e),this.check()}rotateZ(e){return Ur(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Br(this,this,e,t),this.check()}scale(e){return Fr(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Dr(this,this,e),this.check()}transform(e,t){return e.length===4?(t=jr(t||[-0,-0,-0,-0],e,this),Gt(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:n}=e,r;switch(n){case 2:r=Er(t||[-0,-0],e,this);break;case 3:r=Nr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Gt(r,e.length),r}transformAsVector(e,t){let n;switch(e.length){case 2:n=Mr(t||[-0,-0],e,this);break;case 3:n=Cr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Gt(n,e.length),n}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,n){return this.identity().translate([e,t,n])}},jt,Xt;function Ai(){return jt||(jt=new Ie([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(jt)),jt}function Li(){return Xt||(Xt=new Ie,Object.freeze(Xt)),Xt}function Xr(i){if(i>Math.PI*2)throw Error("expected radians")}function Ti(i,e,t,n,r,s){let a=2*s/(t-e),o=2*s/(r-n),c=(t+e)/(t-e),l=(r+n)/(r-n),u=-1,f=-1,_=-2*s;return i[0]=a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=o,i[6]=0,i[7]=0,i[8]=c,i[9]=l,i[10]=u,i[11]=f,i[12]=0,i[13]=0,i[14]=_,i[15]=0,i}var Se=null,Yr=new ArrayBuffer(4),Kr=new Float32Array(Yr),Zr=new Uint32Array(Yr);function Qr(i){Se||=es(),i=Tn(i,-65504,65504),Kr[0]=i;let e=Zr[0],t=e>>23&511;return Se.baseTable[t]+((e&8388607)>>Se.shiftTable[t])}function Jr(i){Se||=es();let e=i>>10;return Zr[0]=Se.mantissaTable[Se.offsetTable[e]+(i&1023)]+Se.exponentTable[e],Kr[0]}function es(){let i=new Uint32Array(512),e=new Uint32Array(512);for(let s=0;s<256;++s){let a=s-127;a<-27?(i[s]=0,i[s|256]=32768,e[s]=24,e[s|256]=24):a<-14?(i[s]=1024>>-a-14,i[s|256]=1024>>-a-14|32768,e[s]=-a-1,e[s|256]=-a-1):a<=15?(i[s]=a+15<<10,i[s|256]=a+15<<10|32768,e[s]=13,e[s|256]=13):a<128?(i[s]=31744,i[s|256]=64512,e[s]=24,e[s|256]=24):(i[s]=31744,i[s|256]=64512,e[s]=13,e[s|256]=13)}let t=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let s=1;s<1024;++s){let a=s<<13,o=0;for(;!(a&8388608);)a<<=1,o-=8388608;a&=-8388609,o+=947912704,t[s]=a|o}for(let s=1024;s<2048;++s)t[s]=939524096+(s-1024<<13);for(let s=1;s<31;++s)n[s]=s<<23;n[31]=1199570944,n[32]=2147483648;for(let s=33;s<63;++s)n[s]=2147483648+(s-32<<23);n[63]=3347054592;for(let s=1;s<64;++s)s!==32&&(r[s]=1024);return{baseTable:i,shiftTable:e,mantissaTable:t,exponentTable:n,offsetTable:r}}function Fe(i,e=[],t=0){let n=Math.fround(i),r=i-n;return e[t]=n,e[t+1]=r,e}function rt(i){return i-Math.fround(i)}function st(i){let e=new Float32Array(32);for(let t=0;t<4;++t)for(let n=0;n<4;++n){let r=t*4+n;Fe(i[n*4+t],e,r*2)}return e}var Ei=`float random(vec3 scale, float seed) {
100
+ `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let i=1;for(;i>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
101
+ `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),i--,i==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),i++)}return!0}}let t=f.simpleTokens[e];if(t)return this._addToken(t),!0;let n=f.none,r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let i=this._peekAhead();for(;this._isAlphaNumeric(i);)e+=this._advance(),i=this._peekAhead()}if(r){let i=f.keywords[e];if(i)return this._addToken(i),!0}if(r||s)return this._addToken(f.tokens.ident),!0;for(;;){let i=this._findType(e),o=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(o=="=")return this._current++,e+=o,this._addToken(f.tokens.minus_equal),!0;if(o=="-")return this._current++,e+=o,this._addToken(f.tokens.minus_minus),!0;let l=this._tokens.length-1;if((f.literal_or_ident.indexOf(this._tokens[l].type)!=-1||this._tokens[l].type==f.tokens.paren_right)&&o!=">")return this._addToken(i),!0}if(e==">"&&(o==">"||o=="=")){let l=!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()&&(l=!0);break}if(l)return this._addToken(i),!0}if(i===f.none){let l=e,c=0,u=2;for(let h=0;h<u;++h)if(l+=this._peekAhead(h),i=this._findType(l),i!==f.none){c=h;break}if(i===f.none)return n!==f.none&&(this._current--,this._addToken(n),!0);e=l,this._current+=c+1}if(n=i,this._isAtEnd())break;e+=this._advance()}return n!==f.none&&(this._addToken(n),!0)}_findType(e){for(let n in f.regexTokens){let r=f.regexTokens[n];if(this._match(e,r.rule))return r}return f.literalTokens[e]||f.none}_match(e,t){let n=t.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
102
+ `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Lt(e,t,this._line,this._start,this._current))}};function w(a){return Array.isArray(a)||a?.buffer instanceof ArrayBuffer}var Et=new Float32Array(1),es=new Uint32Array(Et.buffer),ts=new Uint32Array(Et.buffer),Ct=new Int32Array(1),ns=new Float32Array(Ct.buffer),rs=new Uint32Array(Ct.buffer),Nt=new Uint32Array(1),ss=new Float32Array(Nt.buffer),os=new Int32Array(Nt.buffer);function jn(a,e,t){if(e===t)return a;if(e==="f32"){if(t==="i32"||t==="x32")return Et[0]=a,es[0];if(t==="u32")return Et[0]=a,ts[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return Ct[0]=a,ns[0];if(t==="u32")return Ct[0]=a,rs[0]}else if(e==="u32"){if(t==="f32")return Nt[0]=a,ss[0];if(t==="i32"||t==="x32")return Nt[0]=a,os[0]}return console.error(`Unsupported cast from ${e} to ${t}`),a}var sn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},we=class{constructor(e,t){this.align=e,this.size=t}},Z=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Qt,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let t of e)t instanceof ge&&this._functions.set(t.name,new sn(t));for(let t of e)if(t instanceof Y){let n=this.getTypeInfo(t,null);n instanceof re&&this.structs.push(n)}for(let t of e)if(t instanceof $e)this.aliases.push(this._getAliasInfo(t));else if(t instanceof Ve){let n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new Xt(n.name,s,n.attributes,r))}else if(this._isUniformVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=new xe(n.name,i,r,s,n.attributes,ce.Uniform,n.access);o.access||(o.access="read"),this.uniforms.push(o)}else if(this._isStorageVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(i),l=new xe(n.name,i,r,s,n.attributes,o?ce.StorageTexture:ce.Storage,n.access);l.access||(l.access="read"),this.storage.push(l)}else if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(i),l=new xe(n.name,i,r,s,n.attributes,o?ce.StorageTexture:ce.Texture,n.access);l.access||(l.access="read"),o?this.storage.push(l):this.textures.push(l)}else if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=new xe(n.name,i,r,s,n.attributes,ce.Sampler,n.access);this.samplers.push(o)}else if(t instanceof ge){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),i=n||r||s,o=new Zt(t.name,i?.name,t.attributes);o.attributes=t.attributes,o.startLine=t.startLine,o.endLine=t.endLine,this.functions.push(o),this._functions.get(t.name).info=o,i&&(this._functions.get(t.name).inUse=!0,o.inUse=!0,o.resources=this._findResources(t,!!i),o.inputs=this._getInputs(t.args),o.outputs=this._getOutputs(t.returnType),this.entry[i.name].push(o)),o.arguments=t.args.map(l=>new Kt(l.name,this.getTypeInfo(l.type,l.attributes),l.attributes)),o.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null}for(let t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(let t of this._functions.values())t.node.search(n=>{var r,s,i;if(n instanceof Tt){if(n.value)if(w(n.value))for(let o of n.value)for(let l of this.overrides)o===l.name&&((r=t.info)===null||r===void 0||r.overrides.push(l));else for(let o of this.overrides)n.value===o.name&&((s=t.info)===null||s===void 0||s.overrides.push(o))}else if(n instanceof G)for(let o of this.overrides)n.name===o.name&&((i=t.info)===null||i===void 0||i.overrides.push(o))});for(let t of this.uniforms)this._markStructsInUse(t.type);for(let t of this.storage)this._markStructsInUse(t.type)}getStructInfo(e){for(let t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(let t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(let r of e.calls){let s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(let r of this.entry.compute)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.vertex)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.fragment)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}}for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let n=[],r=this,s=[];return e.search(i=>{if(i instanceof Se)s.push({});else if(i instanceof Ae)s.pop();else if(i instanceof ee){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(i instanceof K){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type)}else if(i instanceof me){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(i instanceof G){let o=i;if(s.length>0&&s[s.length-1][o.name])return;let l=r._findResource(o.name);l&&n.push(l)}else if(i instanceof He){let o=i,l=r._functions.get(o.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),n.push(...l.resources))}else if(i instanceof Ue){let o=i,l=r._functions.get(o.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),n.push(...l.resources))}}),[...new Map(n.map(i=>[i.name,i])).values()]}getBindGroups(){let e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(let n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof Y)this._getStructOutputs(e,t);else{let n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(let n of e.members)if(n.type instanceof Y)this._getStructOutputs(n.type,t);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let s=this.getTypeInfo(n.type,n.type.attributes),i=this._parseInt(r.value),o=new it(n.name,s,r.name,i);t.push(o)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new it("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof Y)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(let n of e.members)if(n.type instanceof Y)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),i=new jt(e.name,r,t.name,s);return n!==null&&(i.interpolation=this._parseString(n.value)),i}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new qt(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let t of this.structs)if(t.name==e)return t;for(let t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof _e){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,i=new se(r.name,t);return i.format=s,i.count=r.count,this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof Y){let r=e,s=new re(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let i of r.members){let o=this.getTypeInfo(i.type,i.attributes);s.members.push(new ot(i.name,o,i.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof de){let r=e,s=r.format instanceof x,i=r.format?s?this.getTypeInfo(r.format,null):new W(r.format,null):null,o=new ie(r.name,i,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof g){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,i=new ie(r.name,s,t,r.access);return this._types.set(e,i),this._updateTypeInfo(i),i}let n=new W(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;let s=this._getTypeSize(e);if(e.size=(t=s?.size)!==null&&t!==void 0?t:0,e instanceof se&&e.format){let i=this._getTypeSize(e.format);e.stride=Math.max((n=i?.size)!==null&&n!==void 0?n:0,(r=i?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof re&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,i=0;for(let o=0,l=e.members.length;o<l;++o){let c=e.members[o],u=this._getTypeSize(c);if(!u)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;let h=u.align,b=u.size;n=this._roundUp(h,n+r),r=b,s=n,i=Math.max(i,h),c.offset=n,c.size=b,this._updateTypeInfo(c.type)}e.size=this._roundUp(i,s+r),e.align=i}_getTypeSize(e){var t,n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof ot&&(e=e.type),e instanceof W){let i=this._getAlias(e.name);i!==null&&(e=i)}{let i=Z._typeInfo[e.name];if(i!==void 0){let o=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new we(Math.max(s,i.align/o),Math.max(r,i.size/o))}}{let i=Z._typeInfo[e.name.substring(0,e.name.length-1)];if(i){let o=e.name[e.name.length-1]==="h"?2:1;return new we(Math.max(s,i.align/o),Math.max(r,i.size/o))}}if(e instanceof se){let i=e,o=8,l=8,c=this._getTypeSize(i.format);return c!==null&&(l=c.size,o=c.align),l=i.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(o,l)),r&&(l=r),new we(Math.max(s,o),Math.max(r,l))}if(e instanceof re){let i=0,o=0,l=0,c=0,u=0;for(let h of e.members){let b=this._getTypeSize(h.type);b!==null&&(i=Math.max(b.align,i),l=this._roundUp(b.align,l+c),c=b.size,u=l)}return o=this._roundUp(i,u+c),new we(Math.max(s,i),Math.max(r,o))}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&&Z._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ee&&e.type!==null&&Z._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let n=e;if(!n||!n.attributes)return null;let r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}};Z._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}},Z._textureTypes=f.any_texture_type.map(a=>a.name),Z._samplerTypes=f.sampler_type.map(a=>a.name);var We=class{constructor(e,t,n){this.name=e,this.value=t,this.node=n}clone(){return new We(this.name,this.value,this.node)}},ze=class{constructor(e){this.name=e.name,this.node=e}clone(){return new ze(this.node)}},qe=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",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 We(e,t,n??null))}setVariable(e,t,n){let r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;let n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new qe(this)}},on=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},an=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){let n=this.exec.evalExpression(e.args[0],t),r=!0;if(n instanceof p)return n.data.forEach(s=>{s||(r=!1)}),new d(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=n.data.some(s=>s);return new d(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){let n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof d))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof D&&r.typeInfo.size===0){let s=r.typeInfo,i=r.buffer.byteLength/s.stride;return new d(i,this.getTypeInfo("u32"))}return new d(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new d(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new d(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new d(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new d(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new d(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new d(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new d(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.atan2(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.atan2(s.value,i.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new d(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((c,u)=>this._clamp(c,r.data[u],s.data[u])),n.typeInfo);let i=n,o=r,l=s;return new d(this._clamp(i.value,o.value,l.value),n.typeInfo)}Cos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new d(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new d(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new d(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let s=n.data,i=r.data;return new p([s[1]*i[2]-i[1]*s[2],s[2]*i[0]-i[2]*s[0],s[0]*i[1]-i[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){let n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof p?new p(n.data.map(s=>s*r),n.typeInfo):new d(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof I){let r=n.data,s=n.typeInfo.getTypeName(),i=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new d(r[0]*r[3]-r[1]*r[2],i);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),i);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),i);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let o=0;for(let l=0;l<n.data.length;++l)o+=(n.data[l]-r.data[l])*(n.data[l]-r.data[l]);return new d(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n,i=r;return new d(Math.abs(s.value-i.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof p&&r instanceof p?new d(this._dot(n.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new d(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new d(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let i=r.value,o=s.value;if(n instanceof p)return new p(n.data.map(c=>c>>i&(1<<o)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let l=n.value;return new d(l>>i&(1<<o)-1,this.getTypeInfo("i32"))}FaceForward(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p){let i=this._dot(r.data,s.data);return new p(i<0?Array.from(n.data):n.data.map(o=>-o),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new d(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new d(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new d(Math.floor(r.value),n.typeInfo)}Fma(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new p(n.data.map((c,u)=>c*r.data[u]+s.data[u]),n.typeInfo);let i=n,o=r,l=s;return new d(i.value*o.value+l.value,i.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new d(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),i=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let o=s.value,l=(1<<i.value)-1<<o,c=~l;if(n instanceof p&&r instanceof p)return new p(n.data.map((b,y)=>b&c|r.data[y]<<o&l),n.typeInfo);let u=n.value,h=r.value;return new d(u&c|h<<o&l,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new d(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let s=0;return n.data.forEach(i=>{s+=i*i}),new d(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new d(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new d(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new d(Math.log2(r.value),n.typeInfo)}Max(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.max(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.max(s.value,i.value),n.typeInfo)}Min(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.min(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.min(s.value,i.value),n.typeInfo)}Mix(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((l,c)=>n.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),n.typeInfo);let i=r,o=s;return new d(n.value*(1-o.value)+i.value*o.value,n.typeInfo)}Modf(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>i%r.data[o]),n.typeInfo);let s=r;return new d(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=this.Length(e,t).value;return new p(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.pow(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.pow(s.value,i.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r),n.typeInfo):new d(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r*Math.PI/180),n.typeInfo):new d(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let s=this._dot(n.data,r.data);return new p(n.data.map((i,o)=>i-2*s*r.data[o]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof d){let i=this._dot(r.data,n.data);return new p(n.data.map((o,l)=>{let c=1-s.value*s.value*(1-i*i);if(c<0)return 0;let u=Math.sqrt(c);return s.value*o-(s.value*i+u)*r.data[l]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new d(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new d(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new d(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new d(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new d(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){let r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof p&&n instanceof p&&r instanceof p)return new p(s.data.map((c,u)=>this._smoothstep(n.data[u],r.data[u],c)),s.typeInfo);let i=n,o=r,l=s;return new d(this._smoothstep(i.value,o.value,l.value),s.typeInfo)}Sqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new d(Math.sqrt(r.value),n.typeInfo)}Step(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof p&&n instanceof p)return new p(r.data.map((i,o)=>i<n.data[o]?0:1),r.typeInfo);let s=n;return new d(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new d(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new d(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){let t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){let n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof I))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let s=n.data;return new I([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let s=n.data;return new I([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let s=n.data;return new I([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let s=n.data;return new I([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new d(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){let n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof G){let s=n.name,i=t.getVariableValue(s);if(i instanceof J){if(r<0||r>=i.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let o=i.getMipLevelSize(r),l=i.dimension;return l==="1d"?new d(o[0],this.getTypeInfo("u32")):l==="3d"?new p(o,this.getTypeInfo("vec3u")):l==="2d"?new p(o.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${l} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof G){let i=n.name,o=t.getVariableValue(i);if(o instanceof J){let l=Math.floor(r.data[0]),c=Math.floor(r.data[1]);if(l<0||l>=o.width||c<0||c>=o.height)return console.error(`Texture ${i} out of bounds. Line ${e.line}`),null;let u=o.getPixel(l,c,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new p(u,this.getTypeInfo("vec4f"))}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,i=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(i.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof G){let o=n.name,l=t.getVariableValue(o);if(l instanceof J){let c=l.getMipLevelSize(0),u=Math.floor(r.data[0]),h=Math.floor(r.data[1]);return u<0||u>=c[0]||h<0||h>=c[1]?(console.error(`Texture ${o} out of bounds. Line ${e.line}`),null):(l.setPixel(u,h,0,s,Array.from(i)),null)}return console.error(`Texture ${o} 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 M&&(n=n.right);let r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t);return l instanceof d&&o instanceof d&&(l.value=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value+=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value-=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=Math.max(l.value,o.value)),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=Math.min(l.value,o.value)),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value&o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value|o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value^o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,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}},zt={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},H={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]},V=class extends on{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new Z,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new qe,this.builtins=new an(this),this.typeInfo={bool:this.getTypeInfo(x.bool),i32:this.getTypeInfo(x.i32),u32:this.getTypeInfo(x.u32),f32:this.getTypeInfo(x.f32),f16:this.getTypeInfo(x.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;let r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof d)return r.value;if(r instanceof p||r instanceof I)return Array.from(r.data);if(r instanceof D&&r.typeInfo instanceof se){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){let s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);let i=s.getFunction(e);if(!i)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}let o=t[0],l=t[1],c=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new p(t,u));for(let h in n)for(let b in n[h]){let y=n[h][b];s.variables.forEach(S=>{var E;let T=S.node;if(T?.attributes){let L=null,P=null;for(let k of T.attributes)k.name==="binding"?L=k.value:k.name==="group"&&(P=k.value);if(b==L&&h==P)if(y.texture!==void 0&&y.descriptor!==void 0){let k=new J(y.texture,this.getTypeInfo(T.type),y.descriptor,(E=y.texture.view)!==null&&E!==void 0?E:null);S.value=k}else y.uniform!==void 0?S.value=new D(y.uniform,this.getTypeInfo(T.type)):S.value=new D(y,this.getTypeInfo(T.type))}})}for(let h=0;h<c;++h)for(let b=0;b<l;++b)for(let y=0;y<o;++y)s.setVariable("@workgroup_id",new p([y,b,h],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(i,[y,b,h],s)}execStatement(e,t){if(e instanceof dt)return this.evalExpression(e.value,t);if(e instanceof _t){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof d))throw new Error("Invalid break-if condition");if(!n.value)return null}return V._breakObj}if(e instanceof gt)return V._continueObj;if(e instanceof me)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 ge)this._function(e,t);else{if(e instanceof pt)return this._if(e,t);if(e instanceof ht)return this._switch(e,t);if(e instanceof lt)return this._for(e,t);if(e instanceof at)return this._while(e,t);if(e instanceof ft)return this._loop(e,t);if(e instanceof Be){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof ut)this._assign(e,t);else if(e instanceof ct)this._increment(e,t);else{if(e instanceof Y)return null;if(e instanceof Ve){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new d(0,this.getTypeInfo("u32")))}else if(e instanceof Ue)this._call(e,t);else{if(e instanceof mt||e instanceof $e)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof j?this._evalBinaryOp(e,t):e instanceof R?this._evalLiteral(e,t):e instanceof G?this._evalVariable(e,t):e instanceof He?this._evalCall(e,t):e instanceof K?this._evalCreate(e,t):e instanceof bt?this._evalConst(e,t):e instanceof xt?this._evalBitcast(e,t):e instanceof M?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof x){let r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(let n in e){let r=e[n],s=this.reflection.getOverrideInfo(n);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(n,new d(r,s.type)):s.type.name==="bool"?t.setVariable(n,new d(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(n,new p(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){let r=[1,1,1];for(let u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){let h=n.getVariableValue(u.value[0]);r[0]=h instanceof d?h.value:parseInt(u.value[0])}if(u.value.length>1){let h=n.getVariableValue(u.value[1]);r[1]=h instanceof d?h.value:parseInt(u.value[1])}if(u.value.length>2){let h=n.getVariableValue(u.value[2]);r[2]=h instanceof d?h.value:parseInt(u.value[2])}}let s=this.getTypeInfo("vec3u"),i=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new p(r,s));let o=r[0],l=r[1],c=r[2];for(let u=0,h=0;u<c;++u)for(let b=0;b<l;++b)for(let y=0;y<o;++y,++h){let S=[y,b,u],E=[y+t[0]*r[0],b+t[1]*r[1],u+t[2]*r[2]];n.setVariable("@local_invocation_id",new p(S,s)),n.setVariable("@global_invocation_id",new p(E,s)),n.setVariable("@local_invocation_index",new d(h,i)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(let n of e.node.args)for(let r of n.attributes)if(r.name==="builtin"){let s=`@${r.value}`,i=t.getVariable(s);i!==void 0&&t.variables.set(n.name,i)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof M;)e=e.right;return e instanceof G?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(let n of e){if(n instanceof Array){let s=t.clone(),i=this._execStatements(n,s);if(i)return i;continue}let r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){let i=r.node.args[s],o=this.evalExpression(e.args[s],n);n.setVariable(i.name,o,i)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){let n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof d?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof d?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof G){let n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof M){if(e.operator==="*"){let 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==="&"){let n=this._getVariableData(e.right,t);return new ue(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof M){let l=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(l instanceof d||l instanceof p||l instanceof I){if(c instanceof d||c instanceof p||c instanceof I&&l.data.length===c.data.length)return void l.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(l instanceof D&&c instanceof D&&l.buffer.byteLength-l.offset>=c.buffer.byteLength-c.offset)return void(l.buffer.byteLength%4==0?new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(l.buffer,l.offset,l.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return l instanceof d||l instanceof p||l instanceof I?c instanceof d||c instanceof p||c instanceof I?void l.data.set(c.data.map((h,b)=>l.data[b]+h)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(l instanceof d||l instanceof p||l instanceof I)&&(c instanceof d||c instanceof p||c instanceof I)?void l.data.set(c.data.map((h,b)=>l.data[b]-h)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof M){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let l=t.getVariable(r);if(!(l&&l.value instanceof ue))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=l.value.reference;let c=e.variable.postfix;if(!c){let u=e.variable.right;for(;u instanceof M;){if(u.postfix){c=u.postfix;break}u=u.right}}c&&(n=n.getSubData(this,c,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);let l=t.getVariable(r);if(l===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=l.value}if(n instanceof ue&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let i=this.evalExpression(e.value,t),o=e.operator;if(o==="=")if(n instanceof D)n.setDataValue(this,i,s,t);else if(s){if(!(n instanceof p||n instanceof I))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof fe){let l=this.evalExpression(s.index,t).value;if(n instanceof p){if(!(i instanceof d))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[l]=i.value}else{if(!(n instanceof I))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let c=this.evalExpression(s.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(i instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let u=n.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(c<2&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(c<2&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(c<2&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(c<3&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(c<3&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(c<3&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(c<4&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(c<4&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(c<4&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}}}}}else if(s instanceof ae){let l=s.value;if(!(n instanceof p))return void console.error(`Invalid assignment to ${l}. Variable ${r} is not a vector. Line ${e.line}`);if(i instanceof d){if(l.length>1)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);if(l==="x")n.data[0]=i.value;else if(l==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[1]=i.value}else if(l==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[2]=i.value}else if(l==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[3]=i.value}}else{if(!(i instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(l.length!==i.data.length)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);for(let c=0;c<l.length;++c){let u=l[c];if(u==="x"||u==="r")n.data[0]=i.data[c];else if(u==="y"||u==="g"){if(i.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[1]=i.data[c]}else if(u==="z"||u==="b"){if(i.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[2]=i.data[c]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(i.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[3]=i.data[c]}}}}}else n instanceof d&&i instanceof d?n.value=i.value:n instanceof p&&i instanceof p||n instanceof I&&i instanceof I?n.data.set(i.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`);else{let l=n.getSubData(this,s,t);if(l instanceof p&&i instanceof d){let c=l.data,u=i.value;if(o==="+=")for(let h=0;h<c.length;++h)c[h]+=u;else if(o==="-=")for(let h=0;h<c.length;++h)c[h]-=u;else if(o==="*=")for(let h=0;h<c.length;++h)c[h]*=u;else if(o==="/=")for(let h=0;h<c.length;++h)c[h]/=u;else if(o==="%=")for(let h=0;h<c.length;++h)c[h]%=u;else if(o==="&=")for(let h=0;h<c.length;++h)c[h]&=u;else if(o==="|=")for(let h=0;h<c.length;++h)c[h]|=u;else if(o==="^=")for(let h=0;h<c.length;++h)c[h]^=u;else if(o==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u;else if(o===">>=")for(let h=0;h<c.length;++h)c[h]>>=u;else console.error(`Invalid operator ${o}. Line ${e.line}`)}else if(l instanceof p&&i instanceof p){let c=l.data,u=i.data;if(c.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(o==="+=")for(let h=0;h<c.length;++h)c[h]+=u[h];else if(o==="-=")for(let h=0;h<c.length;++h)c[h]-=u[h];else if(o==="*=")for(let h=0;h<c.length;++h)c[h]*=u[h];else if(o==="/=")for(let h=0;h<c.length;++h)c[h]/=u[h];else if(o==="%=")for(let h=0;h<c.length;++h)c[h]%=u[h];else if(o==="&=")for(let h=0;h<c.length;++h)c[h]&=u[h];else if(o==="|=")for(let h=0;h<c.length;++h)c[h]|=u[h];else if(o==="^=")for(let h=0;h<c.length;++h)c[h]^=u[h];else if(o==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u[h];else if(o===">>=")for(let h=0;h<c.length;++h)c[h]>>=u[h];else console.error(`Invalid operator ${o}. Line ${e.line}`)}else{if(!(l instanceof d&&i instanceof d))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);o==="+="?l.value+=i.value:o==="-="?l.value-=i.value:o==="*="?l.value*=i.value:o==="/="?l.value/=i.value:o==="%="?l.value%=i.value:o==="&="?l.value&=i.value:o==="|="?l.value|=i.value:o==="^="?l.value^=i.value:o==="<<="?l.value<<=i.value:o===">>="?l.value>>=i.value:console.error(`Invalid operator ${o}. Line ${e.line}`)}n instanceof D&&n.setDataValue(this,l,s,t)}}_function(e,t){let 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 M||(n=n.clone())}else{let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){let s=new K(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof M||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof _e||e.type instanceof Y||e.type instanceof g){let s=new K(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof kt)for(let i of s.selectors){if(i instanceof Ie){r=s;continue}let o=this.evalExpression(i,t);if(!(o instanceof d))return console.error(`Invalid case selector. Line ${e.line}`),null;if(o.value===n.value)return this._execStatements(s.body,t)}else s instanceof It&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(let r of e.elseif){let s=this.evalExpression(r.condition,t);if(!(s instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof d?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n!==null&&n!==V._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n===V._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===V._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n!==V._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof d){let s=jn(n.value,n.typeInfo.name,r.name);return new d(s,this.getTypeInfo(r))}if(n instanceof p){let s=n.typeInfo.getTypeName(),i="";if(s.endsWith("f"))i="f32";else if(s.endsWith("i"))i="i32";else if(s.endsWith("u"))i="u32";else if(s.endsWith("b"))i="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;i="f16"}let o=r.getTypeName(),l="";if(o.endsWith("f"))l="f32";else if(o.endsWith("i"))l="i32";else if(o.endsWith("u"))l="u32";else if(o.endsWith("b"))l="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${l}. Line ${e.line}`),null;l="f16"}let c=function(u,h,b){if(h===b)return u;let y=new Array(u.length);for(let S=0;S<u.length;S++)y[S]=jn(u[S],h,b);return y}(Array.from(n.data),i,l);return new p(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof K){if(e.type===null)return Ge.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}let r=e instanceof K?e.type.name:e.name,s=e instanceof K?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;let i=new D(new ArrayBuffer(s.size),s,0);if(s instanceof re){if(e.args)for(let o=0;o<e.args.length;++o){let l=s.members[o],c=e.args[o],u=this.evalExpression(c,t);i.setData(this,u,l.type,l.offset,t)}}else if(s instanceof se){let o=0;if(e.args)for(let l=0;l<e.args.length;++l){let c=e.args[l],u=this.evalExpression(c,t);s.format===null&&(((n=u.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),i.setData(this,u,s.format,o,t),o+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof K?i.getSubData(this,e.postfix,t):i}_evalLiteral(e,t){let n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new d(e.scalarValue,n):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){let n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=V._priority.get(t.name);V._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){let n=this.evalExpression(e.right,t);if(e.operator==="&")return new ue(n);if(e.operator==="*")return n instanceof ue?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof d?n.value:n instanceof p?Array.from(n.data):null;switch(e.operator){case"+":{if(w(r)){let o=r.map((l,c)=>+l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(+s,i)}case"-":{if(w(r)){let o=r.map((l,c)=>-l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(-s,i)}case"!":{if(w(r)){let o=r.map((l,c)=>l?0:1);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(s?0:1,i)}case"~":{if(w(r)){let o=r.map((l,c)=>~l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(~s,i)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){let n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof d?n.value:n instanceof p||n instanceof I?Array.from(n.data):null,i=r instanceof d?r.value:r instanceof p||r instanceof I?Array.from(r.data):null;switch(e.operator){case"+":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y+h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b+u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u+b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o+l,c)}case"-":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y-h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b-u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u-b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o-l,c)}case"*":{if(w(s)&&w(i)){let u=s,h=i;if(n instanceof I&&r instanceof I){let b=function(T,L,P,k){if(H[L.name]===void 0||H[k.name]===void 0)return null;let A=H[L.name][0],B=H[L.name][1],O=H[k.name][0];if(A!==H[k.name][1])return null;let oe=new Array(O*B);for(let X=0;X<B;X++)for(let U=0;U<O;U++){let he=0;for(let Le=0;Le<A;Le++)he+=T[Le*B+X]*P[U*A+Le];oe[X*O+U]=he}return oe}(u,n.typeInfo,h,r.typeInfo);if(b===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let y=H[r.typeInfo.name][0],S=H[n.typeInfo.name][1],E=this.getTypeInfo(`mat${y}x${S}f`);return new I(b,E)}if(n instanceof I&&r instanceof p){let b=function(y,S,E,T){if(H[S.name]===void 0||zt[T.name]===void 0)return null;let L=H[S.name][0],P=H[S.name][1];if(L!==E.length)return null;let k=new Array(P);for(let A=0;A<P;A++){let B=0;for(let O=0;O<L;O++)B+=y[O*P+A]*E[O];k[A]=B}return k}(u,n.typeInfo,h,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(b,r.typeInfo)}if(n instanceof p&&r instanceof I){let b=function(y,S,E,T){if(zt[S.name]===void 0||H[T.name]===void 0)return null;let L=H[T.name][0],P=H[T.name][1];if(P!==y.length)return null;let k=[];for(let A=0;A<L;A++){let B=0;for(let O=0;O<P;O++)B+=y[O]*E[O*L+A];k[A]=B}return k}(u,n.typeInfo,h,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(b,n.typeInfo)}{if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y*h[S]);return new p(b,n.typeInfo)}}if(w(s)){let u=i,h=s.map((b,y)=>b*u);return n instanceof I?new I(h,n.typeInfo):new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u*b);return r instanceof I?new I(h,r.typeInfo):new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o*l,c)}case"%":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y%h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b%u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u%b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o%l,c)}case"/":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y/h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b/u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u/b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o/l,c)}case"&":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y&h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b&u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u&b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o&l,c)}case"|":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y|h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b|u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u|b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o|l,c)}case"^":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y^h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b^u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u^b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o^l,c)}case"<<":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y<<h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b<<u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u<<b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o<<l,c)}case">>":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y>>h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b>>u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u>>b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o>>l,c)}case">":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u>l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c>o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o>c?1:0);return new p(l,r.typeInfo)}return new d(s>i?1:0,this.getTypeInfo("bool"));case"<":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u<l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c<o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o<c?1:0);return new p(l,r.typeInfo)}return new d(s<i?1:0,this.getTypeInfo("bool"));case"==":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u===l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c==o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o==c?1:0);return new p(l,r.typeInfo)}return new d(s===i?1:0,this.getTypeInfo("bool"));case"!=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u!==l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c!==o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o!==c?1:0);return new p(l,r.typeInfo)}return new d(s!==i?1:0,this.getTypeInfo("bool"));case">=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u>=l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c>=o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o>=c?1:0);return new p(l,r.typeInfo)}return new d(s>=i?1:0,this.getTypeInfo("bool"));case"<=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u<=l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c<=o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o<=c?1:0);return new p(l,r.typeInfo)}return new d(s<=i?1:0,this.getTypeInfo("bool"));case"&&":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u&&l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c&&o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o&&c?1:0);return new p(l,r.typeInfo)}return new d(s&&i?1:0,this.getTypeInfo("bool"));case"||":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u||l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c||o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o||c?1:0);return new p(l,r.typeInfo)}return new d(s||i?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){let i=r.node.args[s],o=this.evalExpression(e.args[s],n);n.createVariable(i.name,o,i)}return this._execStatements(r.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothStep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}let n=t.getFunction(e.name);if(n){let r=t.clone();for(let s=0;s<n.node.args.length;++s){let i=n.node.args[s],o=this.evalExpression(e.args[s],r);r.setVariable(i.name,o,i)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new d(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=zt[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let i=[];if(e instanceof R)if(e.isVector){let o=e.vectorValue;for(let l of o)i.push(l)}else i.push(e.scalarValue);else if(e.args)for(let o of e.args){let l=this.evalExpression(o,t);if(l instanceof p){let c=l.data;for(let u=0;u<c.length;++u){let h=c[u];i.push(h)}}else if(l instanceof d){let c=l.value;i.push(c)}}if(e.type instanceof g&&e.type.format===null&&(e.type.format=g.f32),i.length===0){let o=new Array(s).fill(0);return new p(o,n).getSubData(this,e.postfix,t)}if(i.length===1)for(;i.length<s;)i.push(i[0]);return i.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new p(i.length>s?i.slice(0,s):i,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=H[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let i=[];if(e instanceof R)if(e.isVector){let o=e.vectorValue;for(let l of o)i.push(l)}else i.push(e.scalarValue);else if(e.args)for(let o of e.args){let l=this.evalExpression(o,t);l instanceof p?i.push(...l.data):l instanceof d?i.push(l.value):l instanceof I&&i.push(...l.data)}if(n instanceof ie&&n.format===null&&(n.format=this.getTypeInfo("f32")),i.length===0){let o=new Array(s[2]).fill(0);return new I(o,n).getSubData(this,e.postfix,t)}return i.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new I(i,n).getSubData(this,e.postfix,t)}};V._breakObj=new q(new W("BREAK",null),null),V._continueObj=new q(new W("CONTINUE",null),null),V._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var ln=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},cn=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new ln,this._exec=new V,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,s=n.countNode;if(s instanceof G){let i=s.name,o=this._context.constants.get(i);if(o)try{let l=o.constEvaluate(this._exec);r.count=l}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof At||r instanceof Re?r.type=this._forwardType(r.type):r instanceof _e?r.format=this._forwardType(r.format):r instanceof ee||r instanceof me||r instanceof ke?r.type=this._forwardType(r.type):r instanceof ge?r.returnType=this._forwardType(r.returnType):r instanceof St&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof vt){let t=this._getType(e.name);if(t)return t}else e instanceof Re?e.type=this._forwardType(e.type):e instanceof _e&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new rn(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 m)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){let r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let n=t.type,r=!1;for(let s of e){if(n===s)return!0;s===f.tokens.name&&(r=!0)}if(r){let s=f.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===f.tokens.name){let 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)){let t=this._type_alias();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.diagnostic)){let t=this._diagnostic();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.requires)){let t=this._requires_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.enable)){let t=this._enable_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}let e=this._attribute();if(this._check(f.keywords.var)){let 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)){let 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)){let 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)){let 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)){let t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(f.keywords.fn))return null;let e=this._currentLine,t=this._consume(f.tokens.ident,"Expected function name.").toString();this._consume(f.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(f.tokens.paren_right))do{if(this._check(f.tokens.paren_right))break;let o=this._attribute(),l=this._consume(f.tokens.name,"Expected argument name.").toString();this._consume(f.tokens.colon,"Expected ':' for argument type.");let c=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=c,n.push(this._updateNode(new St(l,u,o))))}while(this._match(f.tokens.comma));this._consume(f.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(f.tokens.arrow)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let s=this._compound_statement(),i=this._currentLine;return this._updateNode(new ge(t,n,r,s,e,i),e)}_compound_statement(){let e=[];for(this._consume(f.tokens.brace_left,"Expected '{' for block.");!this._check(f.tokens.brace_right);){let 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 tn);else if(this._match(f.keywords.break)){let t=this._updateNode(new _t);if(this._currentLoop.length>0){let 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)){let t=this._updateNode(new gt);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(f.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(f.keywords.static_assert))return null;let e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new Yt(t),e)}_while_statement(){if(!this._match(f.keywords.while))return null;let e=this._updateNode(new at(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(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(f.keywords.continuing))return null;let t=this._currentLine,n=this._compound_statement();return this._updateNode(new Be(n,e),t)}_for_statement(){if(!this._match(f.keywords.for))return null;this._consume(f.tokens.paren_left,"Expected '('.");let e=this._updateNode(new lt(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)){let 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)){let e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(f.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return this._updateNode(new me(t,n,null,null,r),e)}if(this._match(f.keywords.const)){let e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(f.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return n===null&&r instanceof R&&(n=r.type),this._updateNode(new ke(t,n,null,null,r),e)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(f.increment_operators))return this._current=e,null;let n=this._consume(f.increment_operators,"Expected increment operator");return this._updateNode(new ct(n.type===f.tokens.plus_plus?ye.increment:ye.decrement,t))}_assignment_statement(){let e=null,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;let r=this._consume(f.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new ut(Me.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(f.tokens.ident))return null;let e=this._currentLine,t=this._current,n=this._consume(f.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new Ue(n.lexeme,r),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.");let e=this._updateNode(new ft([],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 Be){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;let e=this._updateNode(new ht(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(){let e=[],t=!1;for(;this._check([f.keywords.default,f.keywords.case]);){if(this._match(f.keywords.case)){let n=this._case_selectors();for(let s of n)if(s instanceof Ie){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.");let r=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new kt(n,r)))}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.");let n=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new It(n)))}}return e}_case_selectors(){let e=[];for(this._match(f.keywords.default)?e.push(this._updateNode(new Ie)):e.push(this._shift_expression());this._match(f.tokens.comma);)this._match(f.keywords.default)?e.push(this._updateNode(new Ie)):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]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(f.keywords.if))return null;let e=this._currentLine,t=this._optional_paren_expression();this._check(f.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(f.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(f.keywords.else)&&(this._check(f.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new pt(t,n,r,s),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=[]){let t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new nn(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;let e=this._short_circuit_or_expression();return this._updateNode(new dt(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(f.tokens.or_or);)e=this._updateNode(new j(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(f.tokens.and_and);)e=this._updateNode(new j(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(f.tokens.or);)e=this._updateNode(new j(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(f.tokens.xor);)e=this._updateNode(new j(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(f.tokens.and);)e=this._updateNode(new j(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([f.tokens.equal_equal,f.tokens.not_equal])?this._updateNode(new j(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([f.tokens.less_than,f.tokens.greater_than,f.tokens.less_than_equal,f.tokens.greater_than_equal]);)e=this._updateNode(new j(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([f.tokens.shift_left,f.tokens.shift_right]);)e=this._updateNode(new j(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([f.tokens.plus,f.tokens.minus]);)e=this._updateNode(new j(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([f.tokens.star,f.tokens.forward_slash,f.tokens.modulo]);)e=this._updateNode(new j(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 M(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(f.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(f.tokens.bracket_right,"Expected ']'.");let t=this._updateNode(new fe(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(f.tokens.period)){let e=this._consume(f.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new ae(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return x.void;case"bool":return x.bool;case"i32":return x.i32;case"u32":return x.u32;case"f32":return x.f32;case"f16":return x.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)){let n=this._previous().toString();if(this._check(f.tokens.paren_left)){let r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new K(s,r)):this._updateNode(new He(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new bt(n,r.value))}return this._updateNode(new G(n))}if(this._match(f.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?x.i32:n.endsWith("u")||n.endsWith("U")?x.u32:x.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new R(new d(s,this._exec.getTypeInfo(r)),r))}if(this._match(f.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,x.u32),this._updateNode(new R(new d(n,this._exec.getTypeInfo(x.u32)),x.u32))}if(this._match([f.tokens.decimal_float_literal,f.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));let s=parseFloat(n);this._validateTypeRange(s,r?x.f16:x.f32);let i=r?x.f16:x.f32;return this._updateNode(new R(new d(s,this._exec.getTypeInfo(i)),i))}if(this._match([f.keywords.true,f.keywords.false])){let n=this._previous().toString()===f.keywords.true.rule;return this._updateNode(new R(new d(n?1:0,this._exec.getTypeInfo(x.bool)),x.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 '<'.");let n=this._type_decl();this._consume(f.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return this._updateNode(new xt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new K(e,t))}_argument_expression_list(){if(!this._match(f.tokens.paren_left))return null;let e=[];do{if(this._check(f.tokens.paren_right))break;let 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);let e=this._short_circuit_or_expression();return this._match(f.tokens.paren_right),e}_paren_expression(){this._consume(f.tokens.paren_left,"Expected '('.");let 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;let e=this._currentLine,t=this._consume(f.tokens.ident,"Expected name for struct.").toString();this._consume(f.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(f.tokens.brace_right);){let i=this._attribute(),o=this._consume(f.tokens.name,"Expected variable name.").toString();this._consume(f.tokens.colon,"Expected ':' for struct member type.");let l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l),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 At(o,c,i)))}this._consume(f.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new Y(t,n,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(f.tokens.equal)){let t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof R){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof R&&(e.type=e.value.type.name==="x32"?x.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(f.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(f.keywords.const))return null;let t=this._consume(f.tokens.name,"Expected variable name"),n=this._currentLine,r=null;if(this._match(f.tokens.colon)){let l=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=l)}let s=null;this._consume(f.tokens.equal,"const declarations require an assignment");let i=this._short_circuit_or_expression();try{let l=[x.f32],c=i.constEvaluate(this._exec,l);c instanceof d&&this._validateTypeRange(c.value,l[0]),l[0]instanceof g&&l[0].format===null&&c.typeInfo instanceof ie&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?l[0].format=x.f16:c.typeInfo.format.name==="f32"?l[0].format=x.f32:c.typeInfo.format.name==="i32"?l[0].format=x.i32:c.typeInfo.format.name==="u32"?l[0].format=x.u32:c.typeInfo.format.name==="bool"?l[0].format=x.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new R(c,l[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=i}if(r!==null&&s instanceof R){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof R&&(r=(e=s?.type)!==null&&e!==void 0?e:x.f32,r===x.x32&&(r=x.i32));let o=this._updateNode(new ke(t.toString(),r,"","",s),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(f.keywords.let))return null;let e=this._currentLine,t=this._consume(f.tokens.name,"Expected variable name"),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(f.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof R){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof R&&(n=r.type.name==="x32"?x.i32:r.type);return r instanceof R&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new me(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(f.keywords.var))return null;let e=this._currentLine,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 '>'."));let r=this._consume(f.tokens.name,"Expected variable name"),s=null;if(this._match(f.tokens.colon)){let i=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=i)}return this._updateNode(new ee(r.toString(),s,t,n,null),e)}_override_decl(){if(!this._match(f.keywords.override))return null;let e=this._consume(f.tokens.name,"Expected variable name"),t=null;if(this._match(f.tokens.colon)){let n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new Ve(e.toString(),t,null))}_diagnostic(){this._consume(f.tokens.paren_left,"Expected '('");let 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 mt(e.toString(),t))}_enable_directive(){let e=this._consume(f.tokens.ident,"identity expected.");return this._updateNode(new Jt(e.toString()))}_requires_directive(){let e=[this._consume(f.tokens.ident,"identity expected.").toString()];for(;this._match(f.tokens.comma);){let t=this._consume(f.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new en(e))}_type_alias(){let 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);let n=this._updateNode(new $e(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])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let r=this._updateNode(new vt(n));return this._forwardTypeCount++,r}return this._updateNode(new x(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(f.template_types)){let n=this._advance().toString(),r=null,s=null;return this._match(f.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(f.tokens.comma)&&(s=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,r,s))}if(this._match(f.keywords.ptr)){let n=this._previous().toString();this._consume(f.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(f.storage_class,"Expected storage_class for pointer");this._consume(f.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),i=null;return this._match(f.tokens.comma)&&(i=this._consume(f.access_mode,"Expected access_mode for pointer").toString()),this._consume(f.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Re(n,r.toString(),s,i))}let t=this._attribute();if(this._match(f.keywords.array)){let n=null,r=-1,s=this._previous(),i=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 l="";if(this._match(f.tokens.comma)){i=this._shift_expression();try{l=i.constEvaluate(this._exec).toString(),i=null}catch{l="1"}}this._consume(f.tokens.greater_than,"Expected '>' for array."),r=l?parseInt(l):0}let o=this._updateNode(new _e(s.toString(),t,n,r));return i&&this._deferArrayCountEval.push({arrayType:o,countNode:i}),o}return null}_texture_sampler_types(){if(this._match(f.sampler_type))return this._updateNode(new de(this._previous().toString(),null,null));if(this._match(f.depth_texture_type))return this._updateNode(new de(this._previous().toString(),null,null));if(this._match(f.sampled_texture_type)||this._match(f.multisampled_texture_type)){let e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(f.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new de(e.toString(),t,null))}if(this._match(f.storage_texture_type)){let e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(f.texel_format,"Invalid texel format.").toString();this._consume(f.tokens.comma,"Expected ',' after texel format.");let 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 de(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(f.tokens.attr);){let t=this._consume(f.attribute_name,"Expected attribute name"),n=this._updateNode(new Tt(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{let r=this._consume(f.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(f.tokens.comma))}this._consume(f.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}},Ot=class extends Z{constructor(e){super(),e&&this.update(e)}update(e){let t=new cn().parse(e);this.updateAST(t)}};function Jn(a){let e={attributes:[],bindings:[]},t;try{t=is(a)}catch(s){return Yn.log.error(s.message)(),e}for(let s of t.uniforms){let i=[];for(let o of s.type?.members||[])i.push({name:o.name,type:Qn(o.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:i})}for(let s of t.textures)e.bindings.push({type:"texture",name:s.name,group:s.group,location:s.binding});for(let s of t.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let n=t.entry.vertex[0],r=n?.inputs.length||0;for(let s=0;s<r;s++){let i=n.inputs[s];if(i.locationType==="location"){let o=Qn(i.type);e.attributes.push({name:i.name,location:Number(i.location),type:o})}}return e}function Qn(a){return a?.format?`${a.name}<${a.format.name}>`:a.name}function is(a){try{return new Ot(a)}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})}}var xo=1/Math.PI*180,yo=1/180*Math.PI,as={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...as}};var ls=globalThis.mathgl.config;function er(a){return Array.isArray(a)||ArrayBuffer.isView(a)&&!(a instanceof DataView)}function fn(a,e,t){return us(a,n=>Math.max(e,Math.min(t,n)))}function cs(a){return a.clone?a.clone():new Array(a.length)}function us(a,e,t){if(er(a)){let n=a;t=t||cs(n);for(let r=0;r<t.length&&r<n.length;++r){let s=typeof a=="number"?a:a[r];t[r]=e(s,r,t)}return t}return e(a)}var ve=null,tr=new ArrayBuffer(4),nr=new Float32Array(tr),rr=new Uint32Array(tr);function sr(a){ve||=ir(),a=fn(a,-65504,65504),nr[0]=a;let e=rr[0],t=e>>23&511;return ve.baseTable[t]+((e&8388607)>>ve.shiftTable[t])}function or(a){ve||=ir();let e=a>>10;return rr[0]=ve.mantissaTable[ve.offsetTable[e]+(a&1023)]+ve.exponentTable[e],nr[0]}function ir(){let a=new Uint32Array(512),e=new Uint32Array(512);for(let s=0;s<256;++s){let i=s-127;i<-27?(a[s]=0,a[s|256]=32768,e[s]=24,e[s|256]=24):i<-14?(a[s]=1024>>-i-14,a[s|256]=1024>>-i-14|32768,e[s]=-i-1,e[s|256]=-i-1):i<=15?(a[s]=i+15<<10,a[s|256]=i+15<<10|32768,e[s]=13,e[s|256]=13):i<128?(a[s]=31744,a[s|256]=64512,e[s]=24,e[s|256]=24):(a[s]=31744,a[s|256]=64512,e[s]=13,e[s|256]=13)}let t=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let s=1;s<1024;++s){let i=s<<13,o=0;for(;!(i&8388608);)i<<=1,o-=8388608;i&=-8388609,o+=947912704,t[s]=i|o}for(let s=1024;s<2048;++s)t[s]=939524096+(s-1024<<13);for(let s=1;s<31;++s)n[s]=s<<23;n[31]=1199570944,n[32]=2147483648;for(let s=33;s<63;++s)n[s]=2147483648+(s-32<<23);n[63]=3347054592;for(let s=1;s<64;++s)s!==32&&(r[s]=1024);return{baseTable:a,shiftTable:e,mantissaTable:t,exponentTable:n,offsetTable:r}}function Te(a,e=[],t=0){let n=Math.fround(a),r=a-n;return e[t]=n,e[t+1]=r,e}function je(a){return a-Math.fround(a)}function Xe(a){let e=new Float32Array(32);for(let t=0;t<4;++t)for(let n=0;n<4;++n){let r=t*4+n;Te(a[n*4+t],e,r*2)}return e}var fs=`fn random(scale: vec3f, seed: float) -> f32 {
105
103
  /* use the fragment position for a different seed per-pixel */
106
104
  return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
107
105
  }
108
- `,ts={name:"random",fs:Ei};var Mi=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
106
+ `,hs=`float random(vec3 scale, float seed) {
107
+ /* use the fragment position for a different seed per-pixel */
108
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
109
+ }
110
+ `,ar={name:"random",source:fs,fs:hs};var ps=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
109
111
 
110
112
  // All these functions are for substituting tan() function from Intel GPU only
111
113
  const float TWO_PI = 6.2831854820251465;
@@ -255,7 +257,7 @@ float tan_fp32(float a) {
255
257
  return tan(a);
256
258
  #endif
257
259
  }
258
- `,ns={name:"fp32",vs:Mi};var rs=`
260
+ `,lr={name:"fp32",vs:ps};var cr=`
259
261
  uniform fp64arithmeticUniforms {
260
262
  uniform float ONE;
261
263
  } fp64;
@@ -423,7 +425,7 @@ vec2 sqrt_fp64(vec2 a) {
423
425
  return sum_fp64(vec2(yn, 0.0), prod);
424
426
  #endif
425
427
  }
426
- `;var ss=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
428
+ `;var ur=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
427
429
  const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
428
430
  const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
429
431
  const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
@@ -1092,7 +1094,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
1092
1094
  vec4_dot_fp64(a, tmp, out_val[i]);
1093
1095
  }
1094
1096
  }
1095
- `;var Ci={ONE:1},Pn={name:"fp64arithmetic",vs:rs,defaultUniforms:Ci,uniformTypes:{ONE:"f32"},fp64ify:Fe,fp64LowPart:rt,fp64ifyMatrix4:st},is={name:"fp64",vs:ss,dependencies:[Pn],fp64ify:Fe,fp64LowPart:rt,fp64ifyMatrix4:st};var Ni=[0,1,1,1],Oi=`uniform pickingUniforms {
1097
+ `;var ds={ONE:1},hn={name:"fp64arithmetic",vs:cr,defaultUniforms:ds,uniformTypes:{ONE:"f32"},fp64ify:Te,fp64LowPart:je,fp64ifyMatrix4:Xe},fr={name:"fp64",vs:ur,dependencies:[hn],fp64ify:Te,fp64LowPart:je,fp64ifyMatrix4:Xe};var ms=[0,1,1,1],_s=`uniform pickingUniforms {
1096
1098
  float isActive;
1097
1099
  float isAttribute;
1098
1100
  float isHighlightActive;
@@ -1163,7 +1165,7 @@ void picking_setPickingAttribute(vec3 value) {
1163
1165
  picking_vRGBcolor_Avalid.rgb = value;
1164
1166
  }
1165
1167
  }
1166
- `,Pi=`uniform pickingUniforms {
1168
+ `,gs=`uniform pickingUniforms {
1167
1169
  float isActive;
1168
1170
  float isAttribute;
1169
1171
  float isHighlightActive;
@@ -1219,7 +1221,7 @@ vec4 picking_filterColor(vec4 color) {
1219
1221
  vec4 highlightColor = picking_filterHighlightColor(color);
1220
1222
  return picking_filterPickingColor(highlightColor);
1221
1223
  }
1222
- `,os={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ni},vs:Oi,fs:Pi,getUniforms:Ri};function Ri(i={},e){let t={};if(i.highlightedObjectColor!==void 0)if(i.highlightedObjectColor===null)t.isHighlightActive=!1;else{t.isHighlightActive=!0;let n=i.highlightedObjectColor.slice(0,3);t.highlightedObjectColor=n}if(i.highlightColor){let n=Array.from(i.highlightColor,r=>r/255);Number.isFinite(n[3])||(n[3]=1),t.highlightColor=n}return i.isActive!==void 0&&(t.isActive=Boolean(i.isActive),t.isAttribute=Boolean(i.isAttribute)),i.useFloatColors!==void 0&&(t.useFloatColors=Boolean(i.useFloatColors)),t}var cs=Jt(lt(),1);var Rn=`precision highp int;
1224
+ `,hr={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:ms},vs:_s,fs:gs,getUniforms:vs};function vs(a={},e){let t={};if(a.highlightedObjectColor!==void 0)if(a.highlightedObjectColor===null)t.isHighlightActive=!1;else{t.isHighlightActive=!0;let n=a.highlightedObjectColor.slice(0,3);t.highlightedObjectColor=n}if(a.highlightColor){let n=Array.from(a.highlightColor,r=>r/255);Number.isFinite(n[3])||(n[3]=1),t.highlightColor=n}return a.isActive!==void 0&&(t.isActive=Boolean(a.isActive),t.isAttribute=Boolean(a.isAttribute)),a.useFloatColors!==void 0&&(t.useFloatColors=Boolean(a.useFloatColors)),t}var dr=Rt(Je(),1);var pn=`precision highp int;
1223
1225
 
1224
1226
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1225
1227
  struct AmbientLight {
@@ -1293,7 +1295,7 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
1293
1295
  }
1294
1296
 
1295
1297
  // #endif
1296
- `;var as=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1298
+ `;var pr=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1297
1299
  struct AmbientLight {
1298
1300
  color: vec3<f32>,
1299
1301
  };
@@ -1344,7 +1346,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
1344
1346
  + pointLight.attenuation.y * distance
1345
1347
  + pointLight.attenuation.z * distance * distance;
1346
1348
  }
1347
- `;var ls=3,Di=255,it;(function(i){i[i.POINT=0]="POINT",i[i.DIRECTIONAL=1]="DIRECTIONAL"})(it||(it={}));var ce={props:{},uniforms:{},name:"lighting",defines:{MAX_LIGHTS:ls},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:it.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]},source:as,vs:Rn,fs:Rn,getUniforms:Fi};function Fi(i,e={}){if(i=i&&{...i},!i)return{...ce.defaultUniforms};i.lights&&(i={...i,...Vi(i.lights),lights:void 0});let{ambientLight:t,pointLights:n,directionalLights:r}=i||{};if(!(t||n&&n.length>0||r&&r.length>0))return{...ce.defaultUniforms,enabled:0};let a={...ce.defaultUniforms,...e,...Bi({ambientLight:t,pointLights:n,directionalLights:r})};return i.enabled!==void 0&&(a.enabled=i.enabled?1:0),a}function Bi({ambientLight:i,pointLights:e=[],directionalLights:t=[]}){let n={};n.ambientLightColor=Dn(i);let r=0;for(let s of e){n.lightType=it.POINT;let a=r;n[`lightColor${a}`]=Dn(s),n[`lightPosition${a}`]=s.position,n[`lightAttenuation${a}`]=s.attenuation||[1,0,0],r++}for(let s of t){n.lightType=it.DIRECTIONAL;let a=r;n[`lightColor${a}`]=Dn(s),n[`lightDirection${a}`]=s.direction,r++}return r>ls&&cs.log.warn("MAX_LIGHTS exceeded")(),n.directionalLightCount=t.length,n.pointLightCount=e.length,n}function Vi(i){let e={pointLights:[],directionalLights:[]};for(let t of i||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function Dn(i={}){let{color:e=[0,0,0],intensity:t=1}=i;return e.map(n=>n*t/Di)}var $i=`
1349
+ `;var bs=5,xs=255,Ke;(function(a){a[a.POINT=0]="POINT",a[a.DIRECTIONAL=1]="DIRECTIONAL"})(Ke||(Ke={}));var te={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:Ke.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]},source:pr,vs:pn,fs:pn,getUniforms:ys};function ys(a,e={}){if(a=a&&{...a},!a)return{...te.defaultUniforms};a.lights&&(a={...a,...ks(a.lights),lights:void 0});let{ambientLight:t,pointLights:n,directionalLights:r}=a||{};if(!(t||n&&n.length>0||r&&r.length>0))return{...te.defaultUniforms,enabled:0};let i={...te.defaultUniforms,...e,...ws({ambientLight:t,pointLights:n,directionalLights:r})};return a.enabled!==void 0&&(i.enabled=a.enabled?1:0),i}function ws({ambientLight:a,pointLights:e=[],directionalLights:t=[]}){let n={};n.ambientLightColor=dn(a);let r=0;for(let s of e){n.lightType=Ke.POINT;let i=r;n[`lightColor${i}`]=dn(s),n[`lightPosition${i}`]=s.position,n[`lightAttenuation${i}`]=s.attenuation||[1,0,0],r++}for(let s of t){n.lightType=Ke.DIRECTIONAL;let i=r;n[`lightColor${i}`]=dn(s),n[`lightDirection${i}`]=s.direction,r++}return r>bs&&dr.log.warn("MAX_LIGHTS exceeded")(),n.directionalLightCount=t.length,n.pointLightCount=e.length,n}function ks(a){let e={pointLights:[],directionalLights:[]};for(let t of a||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function dn(a={}){let{color:e=[0,0,0],intensity:t=1}=a;return e.map(n=>n*t/xs)}var Is=`
1348
1350
  struct dirlightUniforms {
1349
1351
  lightDirection: vec3<f32>,
1350
1352
  };
@@ -1370,12 +1372,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
1370
1372
  let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
1371
1373
  return vec4<f32>(color.rgb * d, color.a);
1372
1374
  }
1373
- `,Ui=`out vec3 dirlight_vNormal;
1375
+ `,Ss=`out vec3 dirlight_vNormal;
1374
1376
 
1375
1377
  void dirlight_setNormal(vec3 normal) {
1376
1378
  dirlight_vNormal = normalize(normal);
1377
1379
  }
1378
- `,zi=`uniform dirlightUniforms {
1380
+ `,As=`uniform dirlightUniforms {
1379
1381
  vec3 lightDirection;
1380
1382
  } dirlight;
1381
1383
 
@@ -1386,13 +1388,15 @@ vec4 dirlight_filterColor(vec4 color) {
1386
1388
  float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
1387
1389
  return vec4(color.rgb * d, color.a);
1388
1390
  }
1389
- `,Fn={props:{},uniforms:{},name:"dirlight",dependencies:[],source:$i,vs:Ui,fs:zi,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Wi};function Wi(i=Fn.defaultUniforms){let e={};return i.lightDirection&&(e.dirlight_uLightDirection=i.lightDirection),e}var Yt=`uniform phongMaterialUniforms {
1391
+ `,mn={props:{},uniforms:{},name:"dirlight",dependencies:[],source:Is,vs:Ss,fs:As,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Ts};function Ts(a=mn.defaultUniforms){let e={};return a.lightDirection&&(e.lightDirection=a.lightDirection),e}var Pt=`uniform phongMaterialUniforms {
1390
1392
  uniform float ambient;
1391
1393
  uniform float diffuse;
1392
1394
  uniform float shininess;
1393
1395
  uniform vec3 specularColor;
1394
1396
  } material;
1395
- `,Kt=`uniform phongMaterialUniforms {
1397
+ `,Ft=`#define MAX_LIGHTS 1
1398
+
1399
+ uniform phongMaterialUniforms {
1396
1400
  uniform float ambient;
1397
1401
  uniform float diffuse;
1398
1402
  uniform float shininess;
@@ -1437,7 +1441,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
1437
1441
 
1438
1442
  return lightColor;
1439
1443
  }
1440
- `;var Zt=`struct phongMaterialUniforms {
1444
+ `;var Dt=`struct phongMaterialUniforms {
1441
1445
  ambient: f32,
1442
1446
  diffuse: f32,
1443
1447
  shininess: f32,
@@ -1522,7 +1526,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
1522
1526
  }
1523
1527
  return lightColor;
1524
1528
  }
1525
- `;var Bn={props:{},name:"gouraudMaterial",vs:Kt.replace("phongMaterial","gouraudMaterial"),fs:Yt.replace("phongMaterial","gouraudMaterial"),source:Zt.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:1},dependencies:[ce],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(i){let e={...i};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Bn.defaultUniforms,...e}}};var Vn={name:"phongMaterial",dependencies:[ce],source:Zt,vs:Yt,fs:Kt,defines:{LIGHTING_FRAGMENT:1},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(i){let e={...i};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Vn.defaultUniforms,...e}}};var us=`out vec3 pbr_vPosition;
1529
+ `;var _n={props:{},name:"gouraudMaterial",vs:Ft.replace("phongMaterial","gouraudMaterial"),fs:Pt.replace("phongMaterial","gouraudMaterial"),source:Dt.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[te],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(a){let e={...a};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{..._n.defaultUniforms,...e}}};var gn={name:"phongMaterial",dependencies:[te],source:Dt,vs:Pt,fs:Ft,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(a){let e={...a};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...gn.defaultUniforms,...e}}};var mr=`out vec3 pbr_vPosition;
1526
1530
  out vec2 pbr_vUV;
1527
1531
 
1528
1532
  #ifdef HAS_NORMALS
@@ -1555,7 +1559,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
1555
1559
  pbr_vUV = vec2(0.,0.);
1556
1560
  #endif
1557
1561
  }
1558
- `;var fs=`precision highp float;
1562
+ `,_r=`precision highp float;
1559
1563
 
1560
1564
  uniform pbrMaterialUniforms {
1561
1565
  // Material is unlit
@@ -1956,245 +1960,28 @@ vec4 pbr_filterColor(vec4 colorUnused)
1956
1960
 
1957
1961
  return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
1958
1962
  }
1959
- `;var hs=`uniform pbrProjectionUniforms {
1960
- mat4 modelViewProjectionMatrix;
1961
- mat4 modelMatrix;
1962
- mat4 normalMatrix;
1963
- vec3 camera;
1964
- } pbrProjection;
1965
- `,ps={name:"pbrProjection",vs:hs,fs:hs,getUniforms:i=>i,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<i32>"}};var ms={props:{},uniforms:{},name:"pbrMaterial",dependencies:[ce,ps],vs:us,fs,defines:{LIGHTING_FRAGMENT:1},getUniforms:i=>i,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"}};var Hi=`varying vec4 geometry_vPosition;
1966
- varying vec3 geometry_vNormal;
1967
-
1968
- void geometry_setNormal(vec3 normal) {
1969
- geometry_vNormal = normal;
1970
- }
1971
-
1972
- void geometry_setPosition(vec4 position) {
1973
- geometry_vPosition = position;
1974
- }
1975
-
1976
- void geometry_setPosition(vec3 position) {
1977
- geometry_vPosition = vec4(position, 1.);
1978
- }
1979
- `,Gi=`varying vec4 geometry_vPosition;
1980
- varying vec3 geometry_vNormal;
1981
-
1982
- vec4 geometry_getPosition() {
1983
- return geometry_vPosition;
1984
- }
1985
-
1986
- vec3 geometry_getNormal() {
1987
- return geometry_vNormal;
1988
- }
1989
- `,ds={name:"geometry",vs:Hi,fs:Gi};var $n=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],qi={modelMatrix:$n,viewMatrix:$n,projectionMatrix:$n,cameraPositionWorld:[0,0,0]};function ji(i=qi,e={}){let t={};return i.modelMatrix!==void 0&&(t.modelMatrix=i.modelMatrix),i.viewMatrix!==void 0&&(t.viewMatrix=i.viewMatrix),i.projectionMatrix!==void 0&&(t.projectionMatrix=i.projectionMatrix),i.cameraPositionWorld!==void 0&&(t.cameraPositionWorld=i.cameraPositionWorld),i.projectionMatrix!==void 0&&i.viewMatrix!==void 0&&(t.viewProjectionMatrix=new Ie(i.projectionMatrix).multiplyRight(i.viewMatrix)),t}var gs=`varying vec4 project_vPositionWorld;
1990
- varying vec3 project_vNormalWorld;
1991
-
1992
- vec4 project_getPosition_World() {
1993
- return project_vPositionWorld;
1994
- }
1995
-
1996
- vec3 project_getNormal_World() {
1997
- return project_vNormalWorld;
1998
- }
1999
- `,Xi=`${gs}
2000
-
2001
- // Unprefixed uniforms
2002
- uniform mat4 modelMatrix;
2003
- uniform mat4 viewMatrix;
2004
- uniform mat4 projectionMatrix;
2005
- uniform mat4 viewProjectionMatrix;
2006
- uniform vec3 cameraPositionWorld;
2007
-
2008
- struct World {
2009
- vec3 position;
2010
- vec3 normal;
2011
- };
2012
-
2013
- World world;
2014
-
2015
- void project_setPosition(vec4 position) {
2016
- project_vPositionWorld = position;
2017
- }
2018
-
2019
- void project_setNormal(vec3 normal) {
2020
- project_vNormalWorld = normal;
2021
- }
2022
-
2023
- void project_setPositionAndNormal_World(vec3 position, vec3 normal) {
2024
- world.position = position;
2025
- world.normal = normal;
2026
- }
2027
-
2028
- void project_setPositionAndNormal_Model(vec3 position, vec3 normal) {
2029
- world.position = (modelMatrix * vec4(position, 1.)).xyz;
2030
- world.normal = mat3(modelMatrix) * normal;
2031
- }
2032
-
2033
- vec4 project_model_to_clipspace(vec4 position) {
2034
- return viewProjectionMatrix * modelMatrix * position;
2035
- }
2036
-
2037
- vec4 project_model_to_clipspace(vec3 position) {
2038
- return viewProjectionMatrix * modelMatrix * vec4(position, 1.);
2039
- }
2040
-
2041
- vec4 project_world_to_clipspace(vec3 position) {
2042
- return viewProjectionMatrix * vec4(position, 1.);
2043
- }
2044
-
2045
- vec4 project_view_to_clipspace(vec3 position) {
2046
- return projectionMatrix * vec4(position, 1.);
2047
- }
2048
-
2049
- vec4 project_to_clipspace(vec3 position) {
2050
- return viewProjectionMatrix * vec4(position, 1.);
2051
- }
2052
- `,Yi=`
2053
- ${gs}`,Qt={name:"project",getUniforms:ji,vs:Xi,fs:Yi};var Un=`#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
2054
-
2055
- struct AmbientLight {
2056
- vec3 color;
2057
- };
2058
-
2059
- struct PointLight {
2060
- vec3 color;
2061
- vec3 position;
2062
-
2063
- // Constant-Linear-Exponential
2064
- vec3 attenuation;
2065
- };
2066
-
2067
- struct DirectionalLight {
2068
- vec3 color;
2069
- vec3 direction;
1963
+ `;var gr=`struct PBRFragmentInputs {
1964
+ pbr_vPosition: vec3f,
1965
+ pbr_vUV: vec2f,
1966
+ pbr_vTBN: mat3f,
1967
+ pbr_vNormal: vec3f
2070
1968
  };
2071
1969
 
2072
- uniform AmbientLight lighting_uAmbientLight;
2073
- uniform PointLight lighting_uPointLight[MAX_LIGHTS];
2074
- uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
2075
- uniform int lighting_uPointLightCount;
2076
- uniform int lighting_uDirectionalLightCount;
2077
-
2078
- uniform bool lighting_uEnabled;
2079
-
2080
- float getPointLightAttenuation(PointLight pointLight, float distance) {
2081
- return pointLight.attenuation.x
2082
- + pointLight.attenuation.y * distance
2083
- + pointLight.attenuation.z * distance * distance;
2084
- }
2085
-
2086
- #endif
2087
- `;var Ki={lightSources:{}};function zn(i={}){let{color:e=[0,0,0],intensity:t=1}=i;return e.map(n=>n*t/255)}function Zi({ambientLight:i,pointLights:e=[],directionalLights:t=[]}){let n={};return i?n["lighting_uAmbientLight.color"]=zn(i):n["lighting_uAmbientLight.color"]=[0,0,0],e.forEach((r,s)=>{n[`lighting_uPointLight[${s}].color`]=zn(r),n[`lighting_uPointLight[${s}].position`]=r.position,n[`lighting_uPointLight[${s}].attenuation`]=r.attenuation||[1,0,0]}),n.lighting_uPointLightCount=e.length,t.forEach((r,s)=>{n[`lighting_uDirectionalLight[${s}].color`]=zn(r),n[`lighting_uDirectionalLight[${s}].direction`]=r.direction}),n.lighting_uDirectionalLightCount=t.length,n}function _s(i=Ki){if("lightSources"in i){let{ambientLight:e,pointLights:t,directionalLights:n}=i.lightSources||{};return e||t&&t.length>0||n&&n.length>0?Object.assign({},Zi({ambientLight:e,pointLights:t,directionalLights:n}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in i){let e={pointLights:[],directionalLights:[]};for(let t of i.lights||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return _s({lightSources:e})}return{}}var Ae={name:"lights",vs:Un,fs:Un,getUniforms:_s,defines:{MAX_LIGHTS:3}};var Qi={lightDirection:new Float32Array([1,1,2])};function Ji(i=Qi){let e={};return i.lightDirection&&(e.dirlight_uLightDirection=i.lightDirection),e}var eo=`uniform vec3 dirlight_uLightDirection;
2088
-
2089
- /*
2090
- * Returns color attenuated by angle from light source
2091
- */
2092
- vec4 dirlight_filterColor(vec4 color) {
2093
- vec3 normal = project_getNormal_World();
2094
- float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
2095
- return vec4(color.rgb * d, color.a);
2096
- }
2097
- `,xs={name:"dirlight",fs:eo,getUniforms:Ji,dependencies:[Qt]};var Wn=`
2098
- uniform float lighting_uAmbient;
2099
- uniform float lighting_uDiffuse;
2100
- uniform float lighting_uShininess;
2101
- uniform vec3 lighting_uSpecularColor;
1970
+ var fragmentInputs: PBRFragmentInputs;
2102
1971
 
2103
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
2104
- vec3 halfway_direction = normalize(light_direction + view_direction);
2105
- float lambertian = dot(light_direction, normal_worldspace);
2106
- float specular = 0.0;
2107
- if (lambertian > 0.0) {
2108
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
2109
- specular = pow(specular_angle, lighting_uShininess);
2110
- }
2111
- lambertian = max(lambertian, 0.0);
2112
- return (lambertian * lighting_uDiffuse * surfaceColor + specular * lighting_uSpecularColor) * color;
2113
- }
2114
-
2115
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2116
- vec3 lightColor = surfaceColor;
2117
-
2118
- if (lighting_uEnabled) {
2119
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2120
- lightColor = lighting_uAmbient * surfaceColor * lighting_uAmbientLight.color;
2121
-
2122
- for (int i = 0; i < MAX_LIGHTS; i++) {
2123
- if (i >= lighting_uPointLightCount) {
2124
- break;
2125
- }
2126
- PointLight pointLight = lighting_uPointLight[i];
2127
- vec3 light_position_worldspace = pointLight.position;
2128
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2129
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2130
- }
2131
-
2132
- for (int i = 0; i < MAX_LIGHTS; i++) {
2133
- if (i >= lighting_uDirectionalLightCount) {
2134
- break;
2135
- }
2136
- DirectionalLight directionalLight = lighting_uDirectionalLight[i];
2137
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2138
- }
2139
- }
2140
- return lightColor;
2141
- }
2142
-
2143
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2144
- vec3 lightColor = vec3(0, 0, 0);
2145
- vec3 surfaceColor = vec3(0, 0, 0);
2146
-
2147
- if (lighting_uEnabled) {
2148
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2149
-
2150
- for (int i = 0; i < MAX_LIGHTS; i++) {
2151
- if (i >= lighting_uPointLightCount) {
2152
- break;
2153
- }
2154
- PointLight pointLight = lighting_uPointLight[i];
2155
- vec3 light_position_worldspace = pointLight.position;
2156
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2157
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2158
- }
2159
-
2160
- for (int i = 0; i < MAX_LIGHTS; i++) {
2161
- if (i >= lighting_uDirectionalLightCount) {
2162
- break;
2163
- }
2164
- DirectionalLight directionalLight = lighting_uDirectionalLight[i];
2165
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2166
- }
2167
- }
2168
- return lightColor;
2169
- }
2170
- `;var to={};function no(i){let{ambient:e=.35,diffuse:t=.6,shininess:n=32,specularColor:r=[30,30,30]}=i;return{lighting_uAmbient:e,lighting_uDiffuse:t,lighting_uShininess:n,lighting_uSpecularColor:r.map(s=>s/255)}}function vs(i=to){if(!("material"in i))return{};let{material:e}=i;return e?no(e):{lighting_uEnabled:!1}}var bs={name:"gouraud-lighting",dependencies:[Ae],vs:Wn,defines:{LIGHTING_VERTEX:1},getUniforms:vs},ys={name:"phong-lighting",dependencies:[Ae],fs:Wn,defines:{LIGHTING_FRAGMENT:1},getUniforms:vs};var ws=`uniform mat4 u_MVPMatrix;
2171
- uniform mat4 u_ModelMatrix;
2172
- uniform mat4 u_NormalMatrix;
2173
-
2174
- out vec3 pbr_vPosition;
2175
- out vec2 pbr_vUV;
2176
-
2177
- #ifdef HAS_NORMALS
2178
- # ifdef HAS_TANGENTS
2179
- out mat3 pbr_vTBN;
2180
- # else
2181
- out vec3 pbr_vNormal;
2182
- # endif
2183
- #endif
2184
-
2185
- void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
1972
+ fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
2186
1973
  {
2187
- vec4 pos = u_ModelMatrix * position;
1974
+ var pos: vec4f = pbrProjection.modelMatrix * position;
2188
1975
  pbr_vPosition = vec3(pos.xyz) / pos.w;
2189
1976
 
2190
1977
  #ifdef HAS_NORMALS
2191
1978
  #ifdef HAS_TANGENTS
2192
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
2193
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
2194
- vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
2195
- pbr_vTBN = mat3(tangentW, bitangentW, normalW);
1979
+ let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
1980
+ let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
1981
+ let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
1982
+ fragmentInputs,pbr_vTBN = mat3(tangentW, bitangentW, normalW);
2196
1983
  #else // HAS_TANGENTS != 1
2197
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
1984
+ fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
2198
1985
  #endif
2199
1986
  #endif
2200
1987
 
@@ -2204,97 +1991,98 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
2204
1991
  pbr_vUV = vec2(0.,0.);
2205
1992
  #endif
2206
1993
  }
2207
- `;var ks=`precision highp float;
2208
1994
 
2209
- uniform bool pbr_uUnlit;
1995
+ struct pbrMaterialUniforms {
1996
+ // Material is unlit
1997
+ unlit: uint32,
2210
1998
 
2211
- #ifdef USE_IBL
2212
- uniform samplerCube u_DiffuseEnvSampler;
2213
- uniform samplerCube u_SpecularEnvSampler;
2214
- uniform sampler2D u_brdfLUT;
2215
- uniform vec2 u_ScaleIBLAmbient;
2216
- #endif
1999
+ // Base color map
2000
+ baseColorMapEnabled: uint32,
2001
+ baseColorFactor: vec4f,
2217
2002
 
2003
+ normalMapEnabled : uint32,
2004
+ normalScale: f32, // #ifdef HAS_NORMALMAP
2005
+
2006
+ emissiveMapEnabled: uint32,
2007
+ emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
2008
+
2009
+ metallicRoughnessValues: vec2f,
2010
+ metallicRoughnessMapEnabled: uint32,
2011
+
2012
+ occlusionMapEnabled: i32,
2013
+ occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
2014
+
2015
+ alphaCutoffEnabled: i32,
2016
+ alphaCutoff: f32, // #ifdef ALPHA_CUTOFF
2017
+
2018
+ // IBL
2019
+ IBLenabled: i32,
2020
+ scaleIBLAmbient: vec2f, // #ifdef USE_IBL
2021
+
2022
+ // debugging flags used for shader output of intermediate PBR variables
2023
+ // #ifdef PBR_DEBUG
2024
+ scaleDiffBaseMR: vec4f,
2025
+ scaleFGDSpec: vec4f
2026
+ // #endif
2027
+ }
2028
+
2029
+ @binding(2) @group(0) var<uniform> material : pbrMaterialUniforms;
2030
+
2031
+ // Samplers
2218
2032
  #ifdef HAS_BASECOLORMAP
2219
- uniform sampler2D u_BaseColorSampler;
2033
+ uniform sampler2D pbr_baseColorSampler;
2220
2034
  #endif
2221
2035
  #ifdef HAS_NORMALMAP
2222
- uniform sampler2D u_NormalSampler;
2223
- uniform float u_NormalScale;
2036
+ uniform sampler2D pbr_normalSampler;
2224
2037
  #endif
2225
2038
  #ifdef HAS_EMISSIVEMAP
2226
- uniform sampler2D u_EmissiveSampler;
2227
- uniform vec3 u_EmissiveFactor;
2039
+ uniform sampler2D pbr_emissiveSampler;
2228
2040
  #endif
2229
2041
  #ifdef HAS_METALROUGHNESSMAP
2230
- uniform sampler2D u_MetallicRoughnessSampler;
2042
+ uniform sampler2D pbr_metallicRoughnessSampler;
2231
2043
  #endif
2232
2044
  #ifdef HAS_OCCLUSIONMAP
2233
- uniform sampler2D u_OcclusionSampler;
2234
- uniform float u_OcclusionStrength;
2235
- #endif
2236
-
2237
- #ifdef ALPHA_CUTOFF
2238
- uniform float u_AlphaCutoff;
2239
- #endif
2240
-
2241
- uniform vec2 u_MetallicRoughnessValues;
2242
- uniform vec4 u_BaseColorFactor;
2243
-
2244
- uniform vec3 u_Camera;
2245
-
2246
- // debugging flags used for shader output of intermediate PBR variables
2247
- #ifdef PBR_DEBUG
2248
- uniform vec4 u_ScaleDiffBaseMR;
2249
- uniform vec4 u_ScaleFGDSpec;
2250
- #endif
2251
-
2252
- in vec3 pbr_vPosition;
2253
-
2254
- in vec2 pbr_vUV;
2255
-
2256
- #ifdef HAS_NORMALS
2257
- #ifdef HAS_TANGENTS
2258
- in mat3 pbr_vTBN;
2259
- #else
2260
- in vec3 pbr_vNormal;
2045
+ uniform sampler2D pbr_occlusionSampler;
2261
2046
  #endif
2047
+ #ifdef USE_IBL
2048
+ uniform samplerCube pbr_diffuseEnvSampler;
2049
+ uniform samplerCube pbr_specularEnvSampler;
2050
+ uniform sampler2D pbr_brdfLUT;
2262
2051
  #endif
2263
2052
 
2264
2053
  // Encapsulate the various inputs used by the various functions in the shading equation
2265
2054
  // We store values in this struct to simplify the integration of alternative implementations
2266
2055
  // of the shading terms, outlined in the Readme.MD Appendix.
2267
- struct PBRInfo
2268
- {
2269
- float NdotL; // cos angle between normal and light direction
2270
- float NdotV; // cos angle between normal and view direction
2271
- float NdotH; // cos angle between normal and half vector
2272
- float LdotH; // cos angle between light direction and half vector
2273
- float VdotH; // cos angle between view direction and half vector
2274
- float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
2275
- float metalness; // metallic value at the surface
2276
- vec3 reflectance0; // full reflectance color (normal incidence angle)
2277
- vec3 reflectance90; // reflectance color at grazing angle
2278
- float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
2279
- vec3 diffuseColor; // color contribution from diffuse lighting
2280
- vec3 specularColor; // color contribution from specular lighting
2281
- vec3 n; // normal at surface point
2282
- vec3 v; // vector from surface point to camera
2056
+ struct PBRInfo {
2057
+ NdotL: f32, // cos angle between normal and light direction
2058
+ NdotV: f32, // cos angle between normal and view direction
2059
+ NdotH: f32, // cos angle between normal and half vector
2060
+ LdotH: f32, // cos angle between light direction and half vector
2061
+ VdotH: f32, // cos angle between view direction and half vector
2062
+ perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)
2063
+ metalness: f32, // metallic value at the surface
2064
+ reflectance0: vec3f, // full reflectance color (normal incidence angle)
2065
+ reflectance90: vec3f, // reflectance color at grazing angle
2066
+ alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])
2067
+ diffuseColor: vec3f, // color contribution from diffuse lighting
2068
+ specularColor: vec3f, // color contribution from specular lighting
2069
+ n: vec3f, // normal at surface point
2070
+ v: vec3f, // vector from surface point to camera
2283
2071
  };
2284
2072
 
2285
- const float M_PI = 3.141592653589793;
2286
- const float c_MinRoughness = 0.04;
2073
+ const M_PI = 3.141592653589793;
2074
+ const c_MinRoughness = 0.04;
2287
2075
 
2288
- vec4 SRGBtoLINEAR(vec4 srgbIn)
2076
+ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
2289
2077
  {
2290
2078
  #ifdef MANUAL_SRGB
2291
2079
  #ifdef SRGB_FAST_APPROXIMATION
2292
- vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
2293
- #else //SRGB_FAST_APPROXIMATION
2294
- vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
2295
- vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
2080
+ var linOut: vec3f = pow(srgbIn.xyz,vec3(2.2));
2081
+ #else // SRGB_FAST_APPROXIMATION
2082
+ var bLess: vec3f = step(vec3(0.04045),srgbIn.xyz);
2083
+ var linOut: vec3f = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
2296
2084
  #endif //SRGB_FAST_APPROXIMATION
2297
- return vec4(linOut,srgbIn.w);;
2085
+ return vec4f(linOut,srgbIn.w);;
2298
2086
  #else //MANUAL_SRGB
2299
2087
  return srgbIn;
2300
2088
  #endif //MANUAL_SRGB
@@ -2302,32 +2090,32 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
2302
2090
 
2303
2091
  // Find the normal for this fragment, pulling either from a predefined normal map
2304
2092
  // or from the interpolated mesh normal and tangent attributes.
2305
- vec3 getNormal()
2093
+ fn getNormal() -> vec3f
2306
2094
  {
2307
2095
  // Retrieve the tangent space matrix
2308
2096
  #ifndef HAS_TANGENTS
2309
- vec3 pos_dx = dFdx(pbr_vPosition);
2310
- vec3 pos_dy = dFdy(pbr_vPosition);
2311
- vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
2312
- vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
2313
- vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
2097
+ var pos_dx: vec3f = dFdx(pbr_vPosition);
2098
+ var pos_dy: vec3f = dFdy(pbr_vPosition);
2099
+ var tex_dx: vec3f = dFdx(vec3(pbr_vUV, 0.0));
2100
+ var tex_dy: vec3f = dFdy(vec3(pbr_vUV, 0.0));
2101
+ var t: vec3f = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
2314
2102
 
2315
2103
  #ifdef HAS_NORMALS
2316
- vec3 ng = normalize(pbr_vNormal);
2104
+ var ng: vec3f = normalize(pbr_vNormal);
2317
2105
  #else
2318
- vec3 ng = cross(pos_dx, pos_dy);
2106
+ var ng: vec3f = cross(pos_dx, pos_dy);
2319
2107
  #endif
2320
2108
 
2321
2109
  t = normalize(t - ng * dot(ng, t));
2322
- vec3 b = normalize(cross(ng, t));
2323
- mat3 tbn = mat3(t, b, ng);
2110
+ var b: vec3f = normalize(cross(ng, t));
2111
+ var tbn: mat3f = mat3f(t, b, ng);
2324
2112
  #else // HAS_TANGENTS
2325
- mat3 tbn = pbr_vTBN;
2113
+ var tbn: mat3f = pbr_vTBN;
2326
2114
  #endif
2327
2115
 
2328
2116
  #ifdef HAS_NORMALMAP
2329
- vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
2330
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
2117
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
2118
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2331
2119
  #else
2332
2120
  // The tbn matrix is linearly interpolated, so we need to re-normalize
2333
2121
  vec3 n = normalize(tbn[2].xyz);
@@ -2340,27 +2128,27 @@ vec3 getNormal()
2340
2128
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
2341
2129
  // See our README.md on Environment Maps [3] for additional discussion.
2342
2130
  #ifdef USE_IBL
2343
- vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
2131
+ fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
2344
2132
  {
2345
2133
  float mipCount = 9.0; // resolution of 512x512
2346
- float lod = (pbrInputs.perceptualRoughness * mipCount);
2134
+ float lod = (pbrInfo.perceptualRoughness * mipCount);
2347
2135
  // retrieve a scale and bias to F0. See [1], Figure 3
2348
- vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
2349
- vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
2350
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
2136
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
2137
+ vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
2138
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
2351
2139
 
2352
2140
  #ifdef USE_TEX_LOD
2353
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
2141
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
2354
2142
  #else
2355
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
2143
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
2356
2144
  #endif
2357
2145
 
2358
- vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
2359
- vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
2146
+ vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
2147
+ vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
2360
2148
 
2361
2149
  // For presentation, this allows us to disable IBL terms
2362
- diffuse *= u_ScaleIBLAmbient.x;
2363
- specular *= u_ScaleIBLAmbient.y;
2150
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
2151
+ specular *= pbrMaterial.scaleIBLAmbient.y;
2364
2152
 
2365
2153
  return diffuse + specular;
2366
2154
  }
@@ -2369,32 +2157,29 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
2369
2157
  // Basic Lambertian diffuse
2370
2158
  // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
2371
2159
  // See also [1], Equation 1
2372
- vec3 diffuse(PBRInfo pbrInputs)
2373
- {
2374
- return pbrInputs.diffuseColor / M_PI;
2160
+ fn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {
2161
+ return pbrInfo.diffuseColor / PI;
2375
2162
  }
2376
2163
 
2377
2164
  // The following equation models the Fresnel reflectance term of the spec equation (aka F())
2378
2165
  // Implementation of fresnel from [4], Equation 15
2379
- vec3 specularReflection(PBRInfo pbrInputs)
2380
- {
2381
- return pbrInputs.reflectance0 +
2382
- (pbrInputs.reflectance90 - pbrInputs.reflectance0) *
2383
- pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
2166
+ fn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {
2167
+ return pbrInfo.reflectance0 +
2168
+ (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
2169
+ pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
2384
2170
  }
2385
2171
 
2386
2172
  // This calculates the specular geometric attenuation (aka G()),
2387
2173
  // where rougher material will reflect less light back to the viewer.
2388
2174
  // This implementation is based on [1] Equation 4, and we adopt their modifications to
2389
2175
  // alphaRoughness as input as originally proposed in [2].
2390
- float geometricOcclusion(PBRInfo pbrInputs)
2391
- {
2392
- float NdotL = pbrInputs.NdotL;
2393
- float NdotV = pbrInputs.NdotV;
2394
- float r = pbrInputs.alphaRoughness;
2176
+ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
2177
+ let NdotL: f32 = pbrInfo.NdotL;
2178
+ let NdotV: f32 = pbrInfo.NdotV;
2179
+ let r: f32 = pbrInfo.alphaRoughness;
2395
2180
 
2396
- float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
2397
- float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
2181
+ let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
2182
+ let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
2398
2183
  return attenuationL * attenuationV;
2399
2184
  }
2400
2185
 
@@ -2404,112 +2189,110 @@ float geometricOcclusion(PBRInfo pbrInputs)
2404
2189
  // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
2405
2190
  // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
2406
2191
  // from EPIC Games [1], Equation 3.
2407
- float microfacetDistribution(PBRInfo pbrInputs)
2408
- {
2409
- float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
2410
- float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
2411
- return roughnessSq / (M_PI * f * f);
2192
+ fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
2193
+ let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
2194
+ let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
2195
+ return roughnessSq / (PI * f * f);
2412
2196
  }
2413
2197
 
2414
- void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
2415
- pbrInputs.NdotL = 1.0;
2416
- pbrInputs.NdotH = 0.0;
2417
- pbrInputs.LdotH = 0.0;
2418
- pbrInputs.VdotH = 1.0;
2198
+ fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
2199
+ (*pbrInfo).NdotL = 1.0;
2200
+ (*pbrInfo).NdotH = 0.0;
2201
+ (*pbrInfo).LdotH = 0.0;
2202
+ (*pbrInfo).VdotH = 1.0;
2419
2203
  }
2420
2204
 
2421
- void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
2422
- vec3 n = pbrInputs.n;
2423
- vec3 v = pbrInputs.v;
2424
- vec3 l = normalize(lightDirection); // Vector from surface point to light
2425
- vec3 h = normalize(l+v); // Half vector between both l and v
2205
+ fn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {
2206
+ let n = (*pbrInfo).n;
2207
+ let v = (*pbrInfo).v;
2208
+ let l = normalize(lightDirection); // Vector from surface point to light
2209
+ let h = normalize(l + v); // Half vector between both l and v
2426
2210
 
2427
- pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
2428
- pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
2429
- pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
2430
- pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
2211
+ (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);
2212
+ (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);
2213
+ (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);
2214
+ (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);
2431
2215
  }
2432
2216
 
2433
- void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
2434
- vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
2435
- PBRInfo_setDirectionalLight(pbrInputs, light_direction);
2217
+ fn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {
2218
+ let light_direction = normalize(pointLight.position - pbr_vPosition);
2219
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
2436
2220
  }
2437
2221
 
2438
- vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
2222
+ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
2439
2223
  // Calculate the shading terms for the microfacet specular shading model
2440
- vec3 F = specularReflection(pbrInputs);
2441
- float G = geometricOcclusion(pbrInputs);
2442
- float D = microfacetDistribution(pbrInputs);
2224
+ let F = specularReflection(pbrInfo);
2225
+ let G = geometricOcclusion(pbrInfo);
2226
+ let D = microfacetDistribution(pbrInfo);
2443
2227
 
2444
2228
  // Calculation of analytical lighting contribution
2445
- vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
2446
- vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
2229
+ let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
2230
+ let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
2447
2231
  // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
2448
- return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
2232
+ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
2449
2233
  }
2450
2234
 
2451
- vec4 pbr_filterColor(vec4 colorUnused)
2452
- {
2235
+ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2453
2236
  // The albedo may be defined from a base texture or a flat color
2454
- #ifdef HAS_BASECOLORMAP
2455
- vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
2456
- #else
2457
- vec4 baseColor = u_BaseColorFactor;
2458
- #endif
2459
-
2460
- #ifdef ALPHA_CUTOFF
2461
- if (baseColor.a < u_AlphaCutoff) {
2237
+ var baseColor: vec4<f32>;
2238
+ #ifdef HAS_BASECOLORMAP
2239
+ baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
2240
+ #else
2241
+ baseColor = pbrMaterial.baseColorFactor;
2242
+ #endif
2243
+
2244
+ #ifdef ALPHA_CUTOFF
2245
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
2462
2246
  discard;
2463
2247
  }
2464
- #endif
2248
+ #endif
2465
2249
 
2466
- vec3 color = vec3(0, 0, 0);
2250
+ var color = vec3<f32>(0.0, 0.0, 0.0);
2467
2251
 
2468
- if(pbr_uUnlit){
2469
- color.rgb = baseColor.rgb;
2470
- }
2471
- else{
2252
+ if (pbrMaterial.unlit) {
2253
+ color = baseColor.rgb;
2254
+ } else {
2472
2255
  // Metallic and Roughness material properties are packed together
2473
2256
  // In glTF, these factors can be specified by fixed scalar values
2474
2257
  // or from a metallic-roughness map
2475
- float perceptualRoughness = u_MetallicRoughnessValues.y;
2476
- float metallic = u_MetallicRoughnessValues.x;
2477
- #ifdef HAS_METALROUGHNESSMAP
2258
+ var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
2259
+ var metallic = pbrMaterial.metallicRoughnessValues.x;
2260
+ #ifdef HAS_METALROUGHNESSMAP
2478
2261
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
2479
2262
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
2480
- vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
2263
+ let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, pbr_vUV);
2481
2264
  perceptualRoughness = mrSample.g * perceptualRoughness;
2482
2265
  metallic = mrSample.b * metallic;
2483
- #endif
2266
+ #endif
2484
2267
  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
2485
2268
  metallic = clamp(metallic, 0.0, 1.0);
2486
2269
  // Roughness is authored as perceptual roughness; as is convention,
2487
2270
  // convert to material roughness by squaring the perceptual roughness [2].
2488
- float alphaRoughness = perceptualRoughness * perceptualRoughness;
2271
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
2489
2272
 
2490
- vec3 f0 = vec3(0.04);
2491
- vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
2273
+ let f0 = vec3<f32>(0.04);
2274
+ var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);
2492
2275
  diffuseColor *= 1.0 - metallic;
2493
- vec3 specularColor = mix(f0, baseColor.rgb, metallic);
2276
+ let specularColor = mix(f0, baseColor.rgb, metallic);
2494
2277
 
2495
2278
  // Compute reflectance.
2496
- float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
2279
+ let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
2497
2280
 
2498
2281
  // For typical incident reflectance range (between 4% to 100%) set the grazing
2499
2282
  // reflectance to 100% for typical fresnel effect.
2500
2283
  // For very low reflectance range on highly diffuse objects (below 4%),
2501
- // incrementally reduce grazing reflecance to 0%.
2502
- float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2503
- vec3 specularEnvironmentR0 = specularColor.rgb;
2504
- vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
2284
+ // incrementally reduce grazing reflectance to 0%.
2285
+ let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2286
+ let specularEnvironmentR0 = specularColor;
2287
+ let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
2505
2288
 
2506
- vec3 n = getNormal(); // normal at surface point
2507
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
2289
+ let n = getNormal(); // normal at surface point
2290
+ let v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
2508
2291
 
2509
- float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2510
- vec3 reflection = -normalize(reflect(v, n));
2292
+ let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2293
+ let reflection = -normalize(reflect(v, n));
2511
2294
 
2512
- PBRInfo pbrInputs = PBRInfo(
2295
+ var pbrInfo = PBRInfo(
2513
2296
  0.0, // NdotL
2514
2297
  NdotV,
2515
2298
  0.0, // NdotH
@@ -2526,65 +2309,76 @@ vec4 pbr_filterColor(vec4 colorUnused)
2526
2309
  v
2527
2310
  );
2528
2311
 
2529
- #ifdef USE_LIGHTS
2312
+ #ifdef USE_LIGHTS
2530
2313
  // Apply ambient light
2531
- PBRInfo_setAmbientLight(pbrInputs);
2532
- color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
2314
+ PBRInfo_setAmbientLight(&pbrInfo);
2315
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2533
2316
 
2534
2317
  // Apply directional light
2535
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
2536
- if (i < lighting_uDirectionalLightCount) {
2537
- PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
2538
- color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
2318
+ for (var i = 0; i < lighting.directionalLightCount; i++) {
2319
+ if (i < lighting.directionalLightCount) {
2320
+ PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
2321
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2539
2322
  }
2540
2323
  }
2541
2324
 
2542
2325
  // Apply point light
2543
- for(int i = 0; i < lighting_uPointLightCount; i++) {
2544
- if (i < lighting_uPointLightCount) {
2545
- PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
2546
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
2547
- color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
2326
+ for (var i = 0; i < lighting.pointLightCount; i++) {
2327
+ if (i < lighting.pointLightCount) {
2328
+ PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
2329
+ let attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
2330
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
2548
2331
  }
2549
2332
  }
2550
- #endif
2333
+ #endif
2551
2334
 
2552
2335
  // Calculate lighting contribution from image based lighting source (IBL)
2553
- #ifdef USE_IBL
2554
- color += getIBLContribution(pbrInputs, n, reflection);
2555
- #endif
2336
+ #ifdef USE_IBL
2337
+ if (pbrMaterial.IBLenabled) {
2338
+ color += getIBLContribution(pbrInfo, n, reflection);
2339
+ }
2340
+ #endif
2556
2341
 
2557
2342
  // Apply optional PBR terms for additional (optional) shading
2558
- #ifdef HAS_OCCLUSIONMAP
2559
- float ao = texture(u_OcclusionSampler, pbr_vUV).r;
2560
- color = mix(color, color * ao, u_OcclusionStrength);
2561
- #endif
2343
+ #ifdef HAS_OCCLUSIONMAP
2344
+ if (pbrMaterial.occlusionMapEnabled) {
2345
+ let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, pbr_vUV).r;
2346
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2347
+ }
2348
+ #endif
2562
2349
 
2563
- #ifdef HAS_EMISSIVEMAP
2564
- vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
2565
- color += emissive;
2566
- #endif
2350
+ #ifdef HAS_EMISSIVEMAP
2351
+ if (pbrMaterial.emissiveMapEnabled) {
2352
+ let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
2353
+ color += emissive;
2354
+ }
2355
+ #endif
2567
2356
 
2568
2357
  // This section uses mix to override final color for reference app visualization
2569
2358
  // of various parameters in the lighting equation.
2570
- #ifdef PBR_DEBUG
2359
+ #ifdef PBR_DEBUG
2571
2360
  // TODO: Figure out how to debug multiple lights
2572
2361
 
2573
- // color = mix(color, F, u_ScaleFGDSpec.x);
2574
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
2575
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
2576
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
2577
-
2578
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
2579
- color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
2580
- color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
2581
- color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
2582
- #endif
2362
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
2363
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
2364
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
2365
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
2583
2366
 
2367
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
2368
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
2369
+ color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);
2370
+ color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
2371
+ #endif
2584
2372
  }
2585
2373
 
2586
- return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
2374
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
2587
2375
  }
2588
- `;var Is={name:"pbr",vs:ws,fs:ks,defines:{LIGHTING_FRAGMENT:1},dependencies:[Ae],getUniforms:i=>i};return Os(ot);})();
2376
+ `;var vr=`uniform pbrProjectionUniforms {
2377
+ mat4 modelViewProjectionMatrix;
2378
+ mat4 modelMatrix;
2379
+ mat4 normalMatrix;
2380
+ vec3 camera;
2381
+ } pbrProjection;
2382
+ `,br={name:"pbrProjection",vs:vr,fs:vr,getUniforms:a=>a,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<i32>"}};var xr={props:{},uniforms:{},name:"pbrMaterial",dependencies:[te,br],source:gr,vs:mr,fs:_r,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:a=>a,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"}};return Er(Ze);})();
2589
2383
  return __exports__;
2590
2384
  });