@luma.gl/shadertools
Version:
Shader module system for luma.gl
100 lines (89 loc) • 314 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if (typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if (typeof define === 'function' && define.amd) define([], factory);
else if (typeof exports === 'object') exports['luma'] = factory();
else root['luma'] = factory();})(globalThis, function () {
"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
logdepth_adjustPosition(gl_Position);
#endif
`,Kn=`#ifdef MODULE_MATERIAL
fragColor = material_filterColor(fragColor);
#endif
#ifdef MODULE_LIGHTING
fragColor = lighting_filterColor(fragColor);
#endif
#ifdef MODULE_FOG
fragColor = fog_filterColor(fragColor);
#endif
#ifdef MODULE_PICKING
fragColor = picking_filterHighlightColor(fragColor);
fragColor = picking_filterPickingColor(fragColor);
#endif
#ifdef MODULE_LOGDEPTH
logdepth_setFragDepth();
#endif
`;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(`
`)}
`;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]}
${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
// Apple optimizes away the calculation necessary for emulated fp64
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
`;case"nvidia":return`#define NVIDIA_GPU
// Nvidia optimizes away the calculation necessary for emulated fp64
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
`;case"intel":return`#define INTEL_GPU
// Intel optimizes away the calculation necessary for emulated fp64
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
// Intel's built-in 'tan' function doesn't have acceptable precision
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
`;case"amd":return`#define AMD_GPU
`;default:return`#define DEFAULT_GPU
// Prevent driver from optimizing away the calculation necessary for emulated fp64
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
// Headless Chrome's software shader 'tan' function doesn't have acceptable precision
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
// If the GPU doesn't have full 32 bits precision, will causes overflow
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
`}}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
`],[/\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} {
`,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}
`}r.footer&&(t+=` ${r.footer}`),t+=`}
`}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=`
${$e}
`,Ws=`precision highp float;
`;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(`
`).slice(1).join(`
`),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}
// ----- PROLOGUE -------------------------
${Gs({id:t,source:n,stage:r})}
${`#define SHADER_TYPE_${r.toUpperCase()}`}
${rr(i)}
${r==="fragment"?Ws:""}
// ----- APPLICATION DEFINES -------------------------
${qs(E)}
`:`${w}
`;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?`
#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]}
`)}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} ---------------
`;return e!=="wgsl"&&(r+=`#define MODULE_${n}
`),r+=`${t}
`,r}var js=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Xs=/^\s*\#\s*endif\s*$/;function mt(i,e){let t=i.split(`
`),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(`
`)}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;
void main() {
transform_output = vec4(0);
}`,Ks=`#version 300 es
${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
in ${r} ${e};
out vec4 ${n};
void main() {
${n} = ${s};
}`}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(`
`)}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(`
`)}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