@aislamov/onnxruntime-web64
Version:
A Javascript library for running ONNX models on browsers
6 lines • 719 kB
JavaScript
/*!
* ONNX Runtime Web v1.16.0
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
(()=>{var __webpack_modules__={5716:(e,t,r)=>{"use strict";t.R=void 0;const n=r(6027),o=r(1723);t.R=new class{async init(){}async createSessionHandler(e,t){const r=new n.Session(t);return await r.loadModel(e),new o.OnnxjsSessionHandler(r)}}},2818:(e,t,r)=>{"use strict";t.c8=t.rX=void 0;const n=r(6207),o=r(9719),i=r(9544),s=r(6640);t.rX=()=>{if(("number"!=typeof n.env.wasm.initTimeout||n.env.wasm.initTimeout<0)&&(n.env.wasm.initTimeout=0),"boolean"!=typeof n.env.wasm.simd&&(n.env.wasm.simd=!0),"boolean"!=typeof n.env.wasm.proxy&&(n.env.wasm.proxy=!1),"number"!=typeof n.env.wasm.numThreads||!Number.isInteger(n.env.wasm.numThreads)||n.env.wasm.numThreads<=0){const e="undefined"==typeof navigator?(0,o.cpus)().length:navigator.hardwareConcurrency;n.env.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},t.c8=new class{async init(){(0,t.rX)(),await(0,i.initializeWebAssemblyInstance)()}async createSessionHandler(e,t){const r=new s.OnnxruntimeWebAssemblySessionHandler;return await r.loadModel(e,t),Promise.resolve(r)}}},1057:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(6207),t);const i=r(6207);{const e=r(5716).R;(0,i.registerBackend)("webgl",e,-10)}{const e=r(2818).c8;(0,i.registerBackend)("webgpu",e,1),(0,i.registerBackend)("wasm",e,1),(0,i.registerBackend)("xnnpack",e,9),(0,i.registerBackend)("webnn",e,9)}},4910:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createAttributeWithCacheKey=void 0;class r{constructor(e){Object.assign(this,e)}get cacheKey(){return this._cacheKey||(this._cacheKey=Object.getOwnPropertyNames(this).sort().map((e=>`${this[e]}`)).join(";")),this._cacheKey}}t.createAttributeWithCacheKey=e=>new r(e)},6874:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Attribute=void 0;const n=r(5127),o=r(2446),i=r(9240),s=r(7273);var a=n.onnxruntime.experimental.fbs;class u{constructor(e){if(this._attributes=new Map,null!=e){for(const t of e)t instanceof o.onnx.AttributeProto?this._attributes.set(t.name,[u.getValue(t),u.getType(t)]):t instanceof a.Attribute&&this._attributes.set(t.name(),[u.getValue(t),u.getType(t)]);if(this._attributes.size<e.length)throw new Error("duplicated attribute names")}}set(e,t,r){this._attributes.set(e,[r,t])}delete(e){this._attributes.delete(e)}getFloat(e,t){return this.get(e,"float",t)}getInt(e,t){return this.get(e,"int",t)}getString(e,t){return this.get(e,"string",t)}getTensor(e,t){return this.get(e,"tensor",t)}getFloats(e,t){return this.get(e,"floats",t)}getInts(e,t){return this.get(e,"ints",t)}getStrings(e,t){return this.get(e,"strings",t)}getTensors(e,t){return this.get(e,"tensors",t)}get(e,t,r){const n=this._attributes.get(e);if(void 0===n){if(void 0!==r)return r;throw new Error(`required attribute not found: ${e}`)}if(n[1]!==t)throw new Error(`type mismatch: expected ${t} but got ${n[1]}`);return n[0]}static getType(e){const t=e instanceof o.onnx.AttributeProto?e.type:e.type();switch(t){case o.onnx.AttributeProto.AttributeType.FLOAT:return"float";case o.onnx.AttributeProto.AttributeType.INT:return"int";case o.onnx.AttributeProto.AttributeType.STRING:return"string";case o.onnx.AttributeProto.AttributeType.TENSOR:return"tensor";case o.onnx.AttributeProto.AttributeType.FLOATS:return"floats";case o.onnx.AttributeProto.AttributeType.INTS:return"ints";case o.onnx.AttributeProto.AttributeType.STRINGS:return"strings";case o.onnx.AttributeProto.AttributeType.TENSORS:return"tensors";default:throw new Error(`attribute type is not supported yet: ${o.onnx.AttributeProto.AttributeType[t]}`)}}static getValue(e){const t=e instanceof o.onnx.AttributeProto?e.type:e.type();if(t===o.onnx.AttributeProto.AttributeType.GRAPH||t===o.onnx.AttributeProto.AttributeType.GRAPHS)throw new Error("graph attribute is not supported yet");const r=this.getValueNoCheck(e);if(t===o.onnx.AttributeProto.AttributeType.INT&&s.LongUtil.isLong(r))return s.LongUtil.longToNumber(r);if(t===o.onnx.AttributeProto.AttributeType.INTS){const e=r,t=new Array(e.length);for(let r=0;r<e.length;r++){const n=e[r];t[r]=s.LongUtil.longToNumber(n)}return t}if(t===o.onnx.AttributeProto.AttributeType.TENSOR)return e instanceof o.onnx.AttributeProto?i.Tensor.fromProto(r):i.Tensor.fromOrtTensor(r);if(t===o.onnx.AttributeProto.AttributeType.TENSORS){if(e instanceof o.onnx.AttributeProto)return r.map((e=>i.Tensor.fromProto(e)));if(e instanceof a.Attribute)return r.map((e=>i.Tensor.fromOrtTensor(e)))}if(t===o.onnx.AttributeProto.AttributeType.STRING&&e instanceof o.onnx.AttributeProto){const e=r;return(0,s.decodeUtf8String)(e)}return t===o.onnx.AttributeProto.AttributeType.STRINGS&&e instanceof o.onnx.AttributeProto?r.map(s.decodeUtf8String):r}static getValueNoCheck(e){return e instanceof o.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(e):this.getValueNoCheckFromOrtFormat(e)}static getValueNoCheckFromOnnxFormat(e){switch(e.type){case o.onnx.AttributeProto.AttributeType.FLOAT:return e.f;case o.onnx.AttributeProto.AttributeType.INT:return e.i;case o.onnx.AttributeProto.AttributeType.STRING:return e.s;case o.onnx.AttributeProto.AttributeType.TENSOR:return e.t;case o.onnx.AttributeProto.AttributeType.GRAPH:return e.g;case o.onnx.AttributeProto.AttributeType.FLOATS:return e.floats;case o.onnx.AttributeProto.AttributeType.INTS:return e.ints;case o.onnx.AttributeProto.AttributeType.STRINGS:return e.strings;case o.onnx.AttributeProto.AttributeType.TENSORS:return e.tensors;case o.onnx.AttributeProto.AttributeType.GRAPHS:return e.graphs;default:throw new Error(`unsupported attribute type: ${o.onnx.AttributeProto.AttributeType[e.type]}`)}}static getValueNoCheckFromOrtFormat(e){switch(e.type()){case a.AttributeType.FLOAT:return e.f();case a.AttributeType.INT:return e.i();case a.AttributeType.STRING:return e.s();case a.AttributeType.TENSOR:return e.t();case a.AttributeType.GRAPH:return e.g();case a.AttributeType.FLOATS:return e.floatsArray();case a.AttributeType.INTS:{const t=[];for(let r=0;r<e.intsLength();r++)t.push(e.ints(r));return t}case a.AttributeType.STRINGS:{const t=[];for(let r=0;r<e.stringsLength();r++)t.push(e.strings(r));return t}case a.AttributeType.TENSORS:{const t=[];for(let r=0;r<e.tensorsLength();r++)t.push(e.tensors(r));return t}default:throw new Error(`unsupported attribute type: ${a.AttributeType[e.type()]}`)}}}t.Attribute=u},1975:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.resolveBackend=t.backend=void 0;const n=r(4418),o=new Map;async function i(e){const r=t.backend;if(void 0!==r[e]&&function(e){const t=e;return"initialize"in t&&"function"==typeof t.initialize&&"createSessionHandler"in t&&"function"==typeof t.createSessionHandler&&"dispose"in t&&"function"==typeof t.dispose}(r[e])){const t=r[e];let n=t.initialize();if("object"==typeof n&&"then"in n&&(n=await n),n)return o.set(e,t),t}}t.backend={webgl:new n.WebGLBackend},t.resolveBackend=async function e(t){if(!t)return e(["webgl"]);{const e="string"==typeof t?[t]:t;for(const t of e){const e=o.get(t);if(e)return e;const r=await i(t);if(r)return r}}throw new Error("no available backend to use")}},4418:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebGLBackend=void 0;const n=r(6207),o=r(1315),i=r(2171),s=r(3389);t.WebGLBackend=class{get contextId(){return n.env.webgl.contextId}set contextId(e){n.env.webgl.contextId=e}get matmulMaxBatchSize(){return n.env.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(e){n.env.webgl.matmulMaxBatchSize=e}get textureCacheMode(){return n.env.webgl.textureCacheMode}set textureCacheMode(e){n.env.webgl.textureCacheMode=e}get pack(){return n.env.webgl.pack}set pack(e){n.env.webgl.pack=e}get async(){return n.env.webgl.async}set async(e){n.env.webgl.async=e}initialize(){try{return this.glContext=(0,s.createWebGLContext)(this.contextId),"number"!=typeof this.matmulMaxBatchSize&&(this.matmulMaxBatchSize=16),"string"!=typeof this.textureCacheMode&&(this.textureCacheMode="full"),"boolean"!=typeof this.pack&&(this.pack=!1),"boolean"!=typeof this.async&&(this.async=!1),o.Logger.setWithEnv(n.env),Object.defineProperty(n.env.webgl,"context",{value:this.glContext.gl}),o.Logger.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(e){return o.Logger.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${e}`),!1}}createSessionHandler(e){return new i.WebGLSessionHandler(this,e)}dispose(){this.glContext.dispose()}}},6859:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CoordsGlslLib=void 0;const n=r(7273),o=r(1997),i=r(6757),s=r(7618),a=r(432);class u extends o.GlslLib{constructor(e){super(e)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.offsetToCoords()),this.coordsToOffset()),this.toVec()),this.valueFrom()),this.getCommonUtilFuncs()),this.getInputsSamplingSnippets()),this.getOutputSamplingSnippet())}getCustomTypes(){return{}}offsetToCoords(){return{offsetToCoords:new o.GlslLibRoutine("\n vec2 offsetToCoords(int offset, int width, int height) {\n int t = offset / width;\n int s = offset - t*width;\n vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height);\n return coords;\n }\n ")}}coordsToOffset(){return{coordsToOffset:new o.GlslLibRoutine("\n int coordsToOffset(vec2 coords, int width, int height) {\n float s = coords.s * float(width);\n float t = coords.t * float(height);\n int offset = int(t) * width + int(s);\n return offset;\n }\n ")}}getOutputSamplingSnippet(){const e=this.context.outputTextureLayout;return e.isPacked?this.getPackedOutputSamplingSnippet(e):this.getUnpackedOutputSamplingSnippet(e)}getPackedOutputSamplingSnippet(e){const t=e.unpackedShape,r=[e.width,e.height],n={},s="getOutputCoords";switch(t.length){case 0:n[s]=this.getOutputScalarCoords();break;case 1:n[s]=this.getOutputPacked1DCoords(t,r);break;case 2:n[s]=this.getOutputPacked2DCoords(t,r);break;case 3:n[s]=this.getOutputPacked3DCoords(t,r);break;default:n[s]=this.getOutputPackedNDCoords(t,r)}const a=`\n void setOutput(vec4 val) {\n ${(0,i.getGlsl)(this.context.glContext.version).output} = val;\n }\n `;return n.floatTextureSetRGBA=new o.GlslLibRoutine(a),n}getUnpackedOutputSamplingSnippet(e){const t=e.unpackedShape,r=[e.width,e.height],n={},s="getOutputCoords";switch(t.length){case 0:n[s]=this.getOutputScalarCoords();break;case 1:n[s]=this.getOutputUnpacked1DCoords(t,r);break;case 2:n[s]=this.getOutputUnpacked2DCoords(t,r);break;case 3:n[s]=this.getOutputUnpacked3DCoords(t,r);break;case 4:n[s]=this.getOutputUnpacked4DCoords(t,r);break;case 5:n[s]=this.getOutputUnpacked5DCoords(t,r);break;case 6:n[s]=this.getOutputUnpacked6DCoords(t,r);break;default:throw new Error(`Unsupported output dimensionality: ${t.length}`)}const a=`\n void setOutput(float val) {\n ${(0,i.getGlsl)(this.context.glContext.version).output} = vec4(val, 0, 0, 0);\n }\n `;return n.floatTextureSetR=new o.GlslLibRoutine(a),n}getOutputScalarCoords(){return new o.GlslLibRoutine("\n int getOutputCoords() {\n return 0;\n }\n ")}getOutputPacked1DCoords(e,t){const r=t;let n="";return 1===r[0]?(n=`\n int getOutputCoords() {\n return 2 * int(TexCoords.y * ${r[1]}.0);\n }\n `,new o.GlslLibRoutine(n)):1===r[1]?(n=`\n int getOutputCoords() {\n return 2 * int(TexCoords.x * ${r[0]}.0);\n }\n `,new o.GlslLibRoutine(n)):(n=`\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${r[0]}, ${r[1]}));\n return 2 * (resTexRC.y * ${r[0]} + resTexRC.x);\n }\n `,new o.GlslLibRoutine(n))}getOutputPacked2DCoords(e,t){let r="";if(n.ArrayUtil.arraysEqual(e,t))return r=`\n ivec2 getOutputCoords() {\n return 2 * ivec2(TexCoords.xy * vec2(${t[0]}, ${t[1]}));\n }\n `,new o.GlslLibRoutine(r);const i=t,s=Math.ceil(e[1]/2);return r=`\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${i[0]}, ${i[1]}));\n\n int index = resTexRC.y * ${i[0]} + resTexRC.x;\n\n // reverse r and c order for packed texture\n int r = imod(index, ${s}) * 2;\n int c = 2 * (index / ${s});\n\n return ivec2(r, c);\n }\n `,new o.GlslLibRoutine(r)}getOutputPacked3DCoords(e,t){const r=[t[0],t[1]],n=Math.ceil(e[2]/2),i=n*Math.ceil(e[1]/2),s=`\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${r[0]}, ${r[1]}));\n int index = resTexRC.y * ${r[0]} + resTexRC.x;\n\n int b = index / ${i};\n index -= b * ${i};\n\n // reverse r and c order for packed texture\n int r = imod(index, ${n}) * 2;\n int c = 2 * (index / ${n});\n\n return ivec3(b, r, c);\n }\n `;return new o.GlslLibRoutine(s)}getOutputPackedNDCoords(e,t){const r=[t[0],t[1]],n=Math.ceil(e[e.length-1]/2),i=n*Math.ceil(e[e.length-2]/2);let s=i,a="",u="b, r, c";for(let t=2;t<e.length-1;t++)s*=e[e.length-t-1],a=`\n int b${t} = index / ${s};\n index -= b${t} * ${s};\n `+a,u=`b${t}, `+u;const l=`\n ivec${e.length} getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${r[0]}, ${r[1]}));\n int index = resTexRC.y * ${r[0]} + resTexRC.x;\n\n ${a}\n\n int b = index / ${i};\n index -= b * ${i};\n\n // reverse r and c order for packed texture\n int r = imod(index, ${n}) * 2;\n int c = 2 * (index / ${n});\n\n return ivec${e.length}(${u});\n }\n `;return new o.GlslLibRoutine(l)}getOutputUnpacked1DCoords(e,t){const r=`\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n return resTexRC.y * ${t[0]} + resTexRC.x;\n }\n `;return new o.GlslLibRoutine(r)}getOutputUnpacked2DCoords(e,t){const r=`\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n int index = resTexRC.y * ${t[0]} + resTexRC.x;\n int r = index / ${e[1]};\n int c = index - r * ${e[1]};\n return ivec2(r, c);\n }\n `;return new o.GlslLibRoutine(r)}getOutputUnpacked3DCoords(e,t){let r="";const n=e.length;let i=null;n<2&&(i=[]),i=new Array(n-1),i[n-2]=e[n-1];for(let t=n-3;t>=0;--t)i[t]=i[t+1]*e[t+1];const s=["r","c","d"],a=i.map(((e,t)=>`int ${s[t]} = index / ${e}; ${t===i.length-1?`int ${s[t+1]} = index - ${s[t]} * ${e}`:`index -= ${s[t]} * ${e}`};`)).join("");return r=`\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n int index = resTexRC.y * ${t[0]} + resTexRC.x;\n ${a}\n return ivec3(r, c, d);\n }\n `,new o.GlslLibRoutine(r)}getOutputUnpacked4DCoords(e,t){let r="";const n=e.length;let i=null;n<2&&(i=[]),i=new Array(n-1),i[n-2]=e[n-1];for(let t=n-3;t>=0;--t)i[t]=i[t+1]*e[t+1];const s=["r","c","d","d2"],a=i.map(((e,t)=>`int ${s[t]} = index / ${e}; ${t===i.length-1?`int ${s[t+1]} = index - ${s[t]} * ${e}`:`index -= ${s[t]} * ${e}`};`)).join("");return r=`\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n int index = resTexRC.y * ${t[0]} + resTexRC.x;\n ${a}\n return ivec4(r, c, d, d2);\n }\n `,new o.GlslLibRoutine(r)}getOutputUnpacked5DCoords(e,t){let r="";const n=e.length;let i=null;n<2&&(i=[]),i=new Array(n-1),i[n-2]=e[n-1];for(let t=n-3;t>=0;--t)i[t]=i[t+1]*e[t+1];const s=["r","c","d","d2","d3"],a=i.map(((e,t)=>`int ${s[t]} = index / ${e}; ${t===i.length-1?`int ${s[t+1]} = index - ${s[t]} * ${e}`:`index -= ${s[t]} * ${e}`};`)).join("");return r=`\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n int index = resTexRC.y * ${t[0]} + resTexRC.x;\n ${a}\n return ivec5(r, c, d, d2, d3);\n }\n `,new o.GlslLibRoutine(r)}getOutputUnpacked6DCoords(e,t){let r="";const n=e.length;let i=null;n<2&&(i=[]),i=new Array(n-1),i[n-2]=e[n-1];for(let t=n-3;t>=0;--t)i[t]=i[t+1]*e[t+1];const s=["r","c","d","d2","d3","d4"],a=i.map(((e,t)=>`int ${s[t]} = index / ${e}; ${t===i.length-1?`int ${s[t+1]} = index - ${s[t]} * ${e}`:`index -= ${s[t]} * ${e}`};`)).join("");return r=`\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(TexCoords.xy *\n vec2(${t[0]}, ${t[1]}));\n int index = resTexRC.y * ${t[0]} + resTexRC.x;\n ${a}\n return ivec6(r, c, d, d2, d3, d4);\n }\n `,new o.GlslLibRoutine(r)}getCommonUtilFuncs(){const e={};let t="uvFromFlat";e[t]=new o.GlslLibRoutine("\n vec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texC = index / texNumR;\n int texR = index - texC * texNumR;\n // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to\n // v.\n return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC);\n }\n "),t="packedUVfrom1D",e[t]=new o.GlslLibRoutine("\n vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),t="packedUVfrom2D",e[t]=new o.GlslLibRoutine("\n vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),t="packedUVfrom3D",e[t]=new o.GlslLibRoutine("\n vec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n }\n "),t="sampleTexture";const r=(0,i.getGlsl)(this.context.glContext.version);return e[t]=new o.GlslLibRoutine(`\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return ${r.texture2D}(textureSampler, uv).r;\n }`),e}getInputsSamplingSnippets(){const e={},t=this.context.outputTextureLayout;return this.context.programInfo.inputNames.forEach(((r,n)=>{const o=this.context.inputTextureLayouts[n],i=(0,a.generateShaderFuncNameFromInputSamplerName)(r);o.isPacked?e[i]=this.getPackedSamplerFromInput(i,r,o):e[i]=this.getUnpackedSamplerFromInput(i,r,o);const s=(0,a.generateShaderFuncNameFromInputSamplerNameAtOutCoords)(r);o.unpackedShape.length<=t.unpackedShape.length&&(o.isPacked?e[s]=this.getPackedSamplerAtOutputCoords(s,o,t,r):e[s]=this.getUnpackedSamplerAtOutputCoords(s,o,t,r))})),e}getPackedSamplerAtOutputCoords(e,t,r,i){const s=t.unpackedShape,u=r.unpackedShape,l=i,c=(0,a.generateShaderFuncNameFromInputSamplerName)(l),p=s.length,d=u.length,f=n.BroadcastUtil.getBroadcastDims(s,u),h=(0,a.getCoordsDataType)(d),g=d-p;let y;const m=(0,a.getGlChannels)();y=0===p?"":d<2&&f.length>=1?"coords = 0;":f.map((e=>`coords.${m[e+g]} = 0;`)).join("\n");let b="";b=d<2&&p>0?"coords":s.map(((e,t)=>`coords.${m[t+g]}`)).join(", ");let _="return outputValue;";const v=1===n.ShapeUtil.size(s),w=1===n.ShapeUtil.size(u);if(1!==p||v||w){if(v&&!w)_=1===d?"\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n ":"\n return vec4(outputValue.x);\n ";else if(f.length){const e=p-2,t=p-1;f.indexOf(e)>-1&&f.indexOf(t)>-1?_="return vec4(outputValue.x);":f.indexOf(e)>-1?_="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":f.indexOf(t)>-1&&(_="return vec4(outputValue.xx, outputValue.zz);")}}else _="\n return vec4(outputValue.xy, outputValue.xy);\n ";const T=`\n vec4 ${e}() {\n ${h} coords = getOutputCoords();\n \n int lastDim = coords.${m[d-1]};\n coords.${m[d-1]} = coords.${m[d-2]};\n coords.${m[d-2]} = lastDim;\n \n ${y}\n vec4 outputValue = ${c}(${b});\n ${_}\n }\n `;return new o.GlslLibRoutine(T,["coordinates.getOutputCoords"])}getUnpackedSamplerAtOutputCoords(e,t,r,i){const s=[r.width,r.height],u=[t.width,t.height],l=t.unpackedShape.length,c=r.unpackedShape.length,p=t.unpackedShape,d=r.unpackedShape,f=(0,a.generateShaderFuncNameFromInputSamplerName)(i);if(l===c&&n.ArrayUtil.arraysEqual(u,s)){const t=`\n float ${e}() {\n return sampleTexture(${i}, TexCoords);\n }\n `;return new o.GlslLibRoutine(t,["coordinates.sampleTexture"])}const h=(0,a.getCoordsDataType)(c),g=n.BroadcastUtil.getBroadcastDims(p,d),y=c-l;let m;const b=(0,a.getGlChannels)();m=0===l?"":c<2&&g.length>=1?"coords = 0;":g.map((e=>`coords.${b[e+y]} = 0;`)).join("\n");let _="";_=c<2&&l>0?"coords":t.unpackedShape.map(((e,t)=>`coords.${b[t+y]}`)).join(", ");const v=`\n float ${e}() {\n ${h} coords = getOutputCoords();\n ${m}\n return ${f}(${_});\n }\n `;return new o.GlslLibRoutine(v,["coordinates.getOutputCoords"])}getPackedSamplerFromInput(e,t,r){switch(r.unpackedShape.length){case 0:return this.getPackedSamplerScalar(e,t);case 1:return this.getPackedSampler1D(e,t,r);case 2:return this.getPackedSampler2D(e,t,r);case 3:return this.getPackedSampler3D(e,t,r);default:return this.getPackedSamplerND(e,t,r)}}getUnpackedSamplerFromInput(e,t,r){const n=r.unpackedShape;switch(n.length){case 0:return this.getUnpackedSamplerScalar(e,t,r);case 1:return this.getUnpackedSampler1D(e,t,r);case 2:return this.getUnpackedSampler2D(e,t,r);case 3:return this.getUnpackedSampler3D(e,t,r);case 4:return this.getUnpackedSampler4D(e,t,r);case 5:return this.getUnpackedSampler5D(e,t,r);case 6:return this.getUnpackedSampler6D(e,t,r);default:throw new Error(`Unsupported dimension ${n.length}-D`)}}getPackedSamplerScalar(e,t){const r=`\n vec4 ${e}() {\n return ${(0,i.getGlsl)(this.context.glContext.version).texture2D}(${t}, halfCR);\n }\n `;return new o.GlslLibRoutine(r)}getPackedSampler1D(e,t,r){const n=[r.width,r.height],s=[n[1],n[0]],a=(0,i.getGlsl)(this.context.glContext.version),u=`vec4 ${e}(int index) {\n vec2 uv = packedUVfrom1D(\n ${s[0]}, ${s[1]}, index);\n return ${a.texture2D}(${t}, uv);\n }`;return new o.GlslLibRoutine(u,["coordinates.packedUVfrom1D"])}getPackedSampler2D(e,t,r){const s=r.unpackedShape,a=[r.width,r.height],u=(0,i.getGlsl)(this.context.glContext.version),l=a[0],c=a[1];if(null!=a&&n.ArrayUtil.arraysEqual(s,a)){const r=`vec4 ${e}(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${l}.0);\n return ${u.texture2D}(${t}, uv);\n }`;return new o.GlslLibRoutine(r)}const p=a,d=Math.ceil(s[1]/2),f=`vec4 ${e}(int row, int col) {\n vec2 uv = packedUVfrom2D(${p[1]}, ${p[0]}, ${d}, row, col);\n return ${u.texture2D}(${t}, uv);\n }`;return new o.GlslLibRoutine(f,["coordinates.packedUVfrom2D"])}getPackedSampler3D(e,t,r){const n=r.unpackedShape,s=[r.width,r.height],u=[s[0],s[1]],l=(0,i.getGlsl)(this.context.glContext.version);if(1===n[0]){const i=n.slice(1),s=[1,2],u=(0,a.squeezeInputShape)(n,i),l=["b","row","col"],c=JSON.parse(JSON.stringify(r));c.unpackedShape=u;const p=this.getPackedSamplerFromInput(e,t,c),d=`${p.routineBody}\n vec4 ${e}(int b, int row, int col) {\n return ${e}(${(0,a.getSqueezedParams)(l,s)});\n } `;return new o.GlslLibRoutine(d,p.dependencies)}const c=u[0],p=u[1],d=Math.ceil(n[2]/2),f=`vec4 ${e}(int b, int row, int col) {\n vec2 uv = packedUVfrom3D(\n ${p}, ${c}, ${d*Math.ceil(n[1]/2)}, ${d}, b, row, col);\n return ${l.texture2D}(${t}, uv);}`;return new o.GlslLibRoutine(f,["coordinates.packedUVfrom3D"])}getPackedSamplerND(e,t,r){const n=r.unpackedShape,s=n.length,a=[r.width,r.height],u=(0,i.getGlsl)(this.context.glContext.version),l=[a[0],a[1]],c=l[1],p=l[0],d=Math.ceil(n[s-1]/2);let f=d*Math.ceil(n[s-2]/2),h="int b, int row, int col",g=`b * ${f} + (row / 2) * ${d} + (col / 2)`;for(let e=2;e<s-1;e++)h=`int b${e}, `+h,f*=n[s-e-1],g=`b${e} * ${f} + `+g;const y=`vec4 ${e}(${h}) {\n int index = ${g};\n int texR = index / ${p};\n int texC = index - texR * ${p};\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${p}, ${c});\n return ${u.texture2D}(${t}, uv);\n }`;return new o.GlslLibRoutine(y)}getUnpackedSamplerScalar(e,t,r){const[n,i]=[r.width,r.height];if(1===n&&1===i){const r=`\n float ${e}() {\n return sampleTexture(${t}, halfCR);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture"])}const s=`\n float ${e}() {\n int offset_${t} = coordsToOffset(TexCoords, ${n}, ${i});\n vec2 uv = uvFromFlat(${n}, ${i}, offset_${t});\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(s,["coordinates.uvFromFlat","coordinates.sampleTexture","coordinates.coordsToOffset"])}getUnpackedSampler1D(e,t,r){const n=r.width,i=r.height;if(1===i&&1===n){const r=`\n float ${e}(int index) {\n return sampleTexture(${t}, halfCR);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture"])}if(1===i){const r=`\n float ${e}(int index) {\n vec2 uv = vec2((float(index) + 0.5) / ${n}.0, 0.5);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture"])}if(1===n){const r=`\n float ${e}(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / ${i}.0);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture"])}const s=`\n float ${e}(int index) {\n vec2 uv = uvFromFlat(${n}, ${i}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(s,["coordinates.uvFromFlat","coordinates.sampleTexture"])}getUnpackedSampler2D(e,t,r){const i=r.unpackedShape,u=[r.height,r.width];if(null!=u&&n.ArrayUtil.arraysEqual(i,u)){const r=`\n float ${e}(int row, int col) {\n vec2 uv = (vec2(row, col) + halfCR) / vec2(${u[1]}.0, ${u[0]}.0);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture"])}const{newShape:l,keptDims:c}=(0,s.squeezeShape)(i),p=l;if(p.length<i.length){const n=(0,a.squeezeInputShape)(i,p),s=JSON.parse(JSON.stringify(r));s.unpackedShape=n;const u=["col","row"],l=`\n ${this.getUnpackedSamplerFromInput(e,t,s).routineBody}\n float ${e}(int row, int col) {\n return ${e}(${(0,a.getSqueezedParams)(u,c)});\n }\n `;return new o.GlslLibRoutine(l,["coordinates.sampleTexture"])}const d=u[1],f=u[0];if(1===f){const r=`\n float ${e}(int row, int col) {\n int offset_${t} = coordsToOffset(TexCoords, ${d}, ${f});\n float index = dot(vec3(row, col, offset_${t}), vec3(${i[1]}, 1, 1));\n vec2 uv = vec2(0.5, (index + 0.5) / ${d}.0);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture","coordinates.coordsToOffset"])}if(1===d){const r=`\n float ${e}(int row, int col) {\n int offset_${t} = coordsToOffset(TexCoords, ${d}, ${f});\n float index = dot(vec3(row, col, offset_${t}), vec3(${i[1]}, 1, 1));\n vec2 uv = vec2((index + 0.5) / ${f}.0, 0.5);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(r,["coordinates.sampleTexture","coordinates.coordsToOffset"])}const h=`\n float ${e}(int row, int col) {\n int index = col * ${i[1]} + row;\n vec2 uv = uvFromFlat(${d}, ${f}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(h,["coordinates.uvFromFlat","coordinates.sampleTexture","coordinates.coordsToOffset"])}getUnpackedSampler3D(e,t,r){const n=r.unpackedShape,i=n[1]*n[2],u=n[2],{newShape:l,keptDims:c}=(0,s.squeezeShape)(n),p=l;if(p.length<n.length){const i=(0,a.squeezeInputShape)(n,p),s=["batch","col","row"],u=JSON.parse(JSON.stringify(r));u.unpackedShape=i;const l=this.getUnpackedSamplerFromInput(e,t,u),d=c.reverse(),f=`\n ${l.routineBody}\n float ${e}(int batch, int row, int col) {\n return ${e}(${(0,a.getSqueezedParams)(s,d)});\n }\n `;return new o.GlslLibRoutine(f,l.dependencies)}const d=`\n float ${e}(int depth, int row, int col) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = depth * ${i} + col * ${u} + row;\n vec2 uv = uvFromFlat(${r.width}, ${r.height}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(d,["coordinates.uvFromFlat","coordinates.sampleTexture","coordinates.coordsToOffset"])}getUnpackedSampler4D(e,t,r){const n=r.unpackedShape,i=n[3],s=n[2]*i,a=`\n float ${e}(int row, int col, int depth, int depth2) {\n int index = row * ${n[1]*s} + col * ${s} +\n depth2 * ${i} + depth;\n vec2 uv = uvFromFlat(${r.width}, ${r.height}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(a,["coordinates.uvFromFlat","coordinates.sampleTexture"])}getUnpackedSampler5D(e,t,r){const n=r.unpackedShape,i=n[4],u=n[3]*i,l=n[2]*u,c=n[1]*l,{newShape:p,keptDims:d}=(0,s.squeezeShape)(n);if(p.length<n.length){const i=(0,a.squeezeInputShape)(n,p),s=["row","col","depth","depth2","depth3"],u=JSON.parse(JSON.stringify(r));u.unpackedShape=i;const l=`\n ${this.getUnpackedSamplerFromInput(e,t,u).routineBody}\n float ${e}(int row, int col, int depth, int depth2, int depth3) {\n return ${e}(${(0,a.getSqueezedParams)(s,d)});\n }\n `;return new o.GlslLibRoutine(l,["coordinates.sampleTexture","coordinates.uvFromFlat"])}const f=`\n float ${e}(int row, int col, int depth, int depth2, int depth3) {\n int index = row * ${c} + col * ${l} + depth * ${u} +\n depth3 * ${i} + depth2;\n vec2 uv = uvFromFlat(${r.width}, ${r.height}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(f,["coordinates.sampleTexture","coordinates.uvFromFlat"])}getUnpackedSampler6D(e,t,r){const n=r.unpackedShape,i=n[5],u=n[4]*i,l=n[3]*u,c=n[2]*l,p=n[1]*c,{newShape:d,keptDims:f}=(0,s.squeezeShape)(n);if(d.length<n.length){const i=(0,a.squeezeInputShape)(n,d),s=["row","col","depth","depth2","depth3","depth4"],u=JSON.parse(JSON.stringify(r));u.unpackedShape=i;const l=`\n ${this.getUnpackedSamplerFromInput(e,t,u).routineBody}\n float ${e}(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n return ${e}(${(0,a.getSqueezedParams)(s,f)});\n }\n `;return new o.GlslLibRoutine(l,["coordinates.sampleTexture","coordinates.uvFromFlat"])}const h=`\n float ${e}(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int index = row * ${p} + col * ${c} + depth * ${l} +\n depth2 * ${u} + depth3 * ${i} + depth4;\n vec2 uv = uvFromFlat(${r.width}, ${r.height}, index);\n return sampleTexture(${t}, uv);\n }\n `;return new o.GlslLibRoutine(h,["coordinates.uvFromFlat","coordinates.sampleTexture","coordinates.coordsToOffset"])}toVec(){const e=this.context.outputTextureLayout,t=e.shape.length,r=e.strides,n=e.width,i=e.height,s=[];for(let e=0;e<t-1;++e)s.push(`\n c[${e}] = offset / ${r[e]};`),s.push(`\n offset -= c[${e}] * ${r[e]};`);s.push(`\n c[${t-1}] = offset;`);const a=`\n void toVec(vec2 texCoords, out int c[${t}]) {\n int offset = coordsToOffset(texCoords, ${n}, ${i});\n ${s.join("")}\n }\n void toVec(int offset, out int c[${t}]) {\n ${s.join("")}\n }\n `;return{toVec:new o.GlslLibRoutine(a,["coordinates.coordsToOffset"])}}valueFrom(){const e={};return this.context.programInfo.inputNames.forEach(((t,r)=>{const n=this.context.inputTextureLayouts[r],i=(n.unpackedShape.length>0?n.unpackedShape:n.shape).length;let s=`_${t}`;e[s]=new o.GlslLibRoutine(this.getValueFromSingle(t,i,n.width,n.height,!1),[`shapeUtils.indicesToOffset${s}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"]),s+="_T",e[s]=new o.GlslLibRoutine(this.getValueFromSingle(t,i,n.width,n.height,!0),[`shapeUtils.indicesToOffset${s}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"])})),e}getValueFromSingle(e,t,r,n,o){let s=`_${e}`;return o&&(s+="_T"),`\n float ${s}(int m[${t}]) {\n int offset = indicesToOffset${s}(m);\n vec2 coords = offsetToCoords(offset, ${r}, ${n});\n float value = getColorAsFloat(${(0,i.getGlsl)(this.context.glContext.version).texture2D}(${e}, coords));\n return value;\n }\n `}getPackedValueFrom(e,t,r,n,o){let s=`_${e}_Pack`;return o&&(s+="_T"),`\n vec4 ${s}(int m[${t}]) {\n int offset = indicesToOffset_${e}(m);\n vec2 coords = offsetToCoords(offset, ${r}, ${n});\n return ${(0,i.getGlsl)(this.context.glContext.version).texture2D}(${e}, coords);\n }\n `}}t.CoordsGlslLib=u},1997:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.TopologicalSortGlslRoutines=t.GlslLibRoutineNode=t.GlslLibRoutine=t.GlslLib=t.GlslContext=t.FunctionType=void 0,(r=t.FunctionType||(t.FunctionType={}))[r.ValueBased=0]="ValueBased",r[r.Positional=1]="Positional",t.GlslContext=class{constructor(e,t,r,n){this.glContext=e,this.programInfo=t,this.inputTextureLayouts=r,this.outputTextureLayout=n}},t.GlslLib=class{constructor(e){this.context=e}},t.GlslLibRoutine=class{constructor(e,t){this.routineBody=e,this.dependencies=t}},t.GlslLibRoutineNode=class{constructor(e,t,r){this.name=e,this.dependencies=r||[],t&&(this.routineBody=t)}addDependency(e){e&&this.dependencies.push(e)}},t.TopologicalSortGlslRoutines=class{static returnOrderedNodes(e){if(!e||0===e.length)return[];if(1===e.length)return e;const t=new Set,r=new Set,n=new Array;return this.createOrderedNodes(e,t,r,n),n}static createOrderedNodes(e,t,r,n){for(let o=0;o<e.length;++o)this.dfsTraverse(e[o],t,r,n)}static dfsTraverse(e,t,r,n){if(!e||r.has(e.name))return;if(t.has(e.name))throw new Error("Cyclic dependency detected. Can't topologically sort routines needed for shader.");t.add(e.name);const o=e.dependencies;if(o&&o.length>0)for(let e=0;e<o.length;++e)this.dfsTraverse(o[e],t,r,n);n.push(e),r.add(e.name),t.delete(e.name)}}},1371:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EncodingGlslLib=void 0;const n=r(1997);class o extends n.GlslLib{constructor(e){super(e)}getFunctions(){return Object.assign(Object.assign({},this.encodeFloat32()),this.decodeFloat32())}getCustomTypes(){return{}}encodeFloat32(){return{encode:new n.GlslLibRoutine("highp vec4 encode(highp float f) {\n return vec4(f, 0.0, 0.0, 0.0);\n }\n ")}}decodeFloat32(){return{decode:new n.GlslLibRoutine("highp float decode(highp vec4 rgba) {\n return rgba.r;\n }\n ")}}encodeUint8(){const e=o.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{encode:new n.GlslLibRoutine(`\n highp vec4 encode(highp float f) {\n highp float F = abs(f);\n highp float Sign = step(0.0,-f);\n highp float Exponent = floor(log2(F));\n highp float Mantissa = (exp2(- Exponent) * F);\n Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa));\n highp vec4 rgba;\n rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0));\n rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0);\n rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0)));\n rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0)));\n ${e}\n rgba = rgba / 255.0; // values need to be normalized to [0,1]\n return rgba;\n }\n `)}}decodeUint8(){const e=o.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{decode:new n.GlslLibRoutine(`\n highp float decode(highp vec4 rgba) {\n rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255]\n ${e}\n highp float Sign = 1.0 - step(128.0,rgba[0])*2.0;\n highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0;\n highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000);\n highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));\n return Result;\n }\n `)}}static isLittleEndian(){const e=new ArrayBuffer(4),t=new Uint32Array(e),r=new Uint8Array(e);if(t[0]=3735928559,239===r[0])return!0;if(222===r[0])return!1;throw new Error("unknown endianness")}}t.EncodingGlslLib=o},2691:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FragColorGlslLib=void 0;const n=r(1997),o=r(6757);class i extends n.GlslLib{constructor(e){super(e)}getFunctions(){return Object.assign(Object.assign({},this.setFragColor()),this.getColorAsFloat())}getCustomTypes(){return{}}setFragColor(){const e=(0,o.getGlsl)(this.context.glContext.version);return{setFragColor:new n.GlslLibRoutine(`\n void setFragColor(float value) {\n ${e.output} = encode(value);\n }\n `,["encoding.encode"])}}getColorAsFloat(){return{getColorAsFloat:new n.GlslLibRoutine("\n float getColorAsFloat(vec4 color) {\n return decode(color);\n }\n ",["encoding.decode"])}}}t.FragColorGlslLib=i},3878:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.replaceInlines=void 0;const r=/@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm;t.replaceInlines=function(e){const t={};let n;for(;null!==(n=r.exec(e));){const e=n[3].split(",").map((e=>{const t=e.trim().split(" ");return t&&2===t.length?{type:t[0],name:t[1]}:null})).filter((e=>null!==e));t[n[2]]={params:e,body:n[4]}}for(const r in t){const o="(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;".replace("__FUNC__",r),i=new RegExp(o,"gm");for(;null!==(n=i.exec(e));){const o=n[1],i=n[2],s=n[3].split(","),a=o?`${o} ${i};`:"";let u=t[r].body,l="";t[r].params.forEach(((e,t)=>{e&&(l+=`${e.type} ${e.name} = ${s[t]};\n`)})),u=`${l}\n ${u}`,u=u.replace("return",`${i} = `);const c=`\n ${a}\n {\n ${u}\n }\n `;e=e.replace(n[0],c)}}return e.replace(r,"")}},8897:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.GlslPreprocessor=void 0;const n=r(1997),o=r(3878),i=r(1248),s=r(6757);t.GlslPreprocessor=class{constructor(e,t,r,o){this.libs={},this.glslLibRoutineDependencyGraph={},this.context=new n.GlslContext(e,t,r,o),Object.keys(i.glslRegistry).forEach((e=>{const t=new i.glslRegistry[e](this.context);this.libs[e]=t}));const s=this.glslLibRoutineDependencyGraph;for(const e in this.libs){const t=this.libs[e].getFunctions();for(const r in t){const o=e+"."+r;let i;s[o]?(i=s[o],i.routineBody=t[r].routineBody):(i=new n.GlslLibRoutineNode(o,t[r].routineBody),s[o]=i);const a=t[r].dependencies;if(a)for(let e=0;e<a.length;++e)if(s[a[e]])i.addDependency(s[a[e]]);else{const t=new n.GlslLibRoutineNode(a[e]);s[a[e]]=t,i.addDependency(t)}}}}preprocess(){const e=this.context.programInfo;let t=e.shaderSource;return this.context.programInfo.hasMain||(t=`${t}\n ${(0,s.getDefaultFragShaderMain)(this.context.glContext.version,this.context.outputTextureLayout.shape.length)}`),t=(0,o.replaceInlines)(t),`${(0,s.getFragShaderPreamble)(this.context.glContext.version)}\n ${this.getUniforms(e.inputNames,e.variables)}\n ${this.getImports(t)}\n ${t}`}getImports(e){const t=this.selectGlslLibRoutinesToBeIncluded(e);if(0===t.length)return"";let r="";for(let e=0;e<t.length;++e){if(!t[e].routineBody)throw new Error(`Missing body for the Glsl Library routine: ${t[e].name}`);r+=t[e].routineBody+"\n"}return r}selectGlslLibRoutinesToBeIncluded(e){const t=[];return Object.keys(this.glslLibRoutineDependencyGraph).forEach((r=>{const n=r.split(".")[1];-1!==e.indexOf(n)&&t.push(this.glslLibRoutineDependencyGraph[r])})),n.TopologicalSortGlslRoutines.returnOrderedNodes(t)}getUniforms(e,t){const r=[];if(e)for(const t of e)r.push(`uniform sampler2D ${t};`);if(t)for(const e of t)r.push(`uniform ${e.type} ${e.name}${e.arrayLength?`[${e.arrayLength}]`:""};`);return r.join("\n")}}},1248:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.glslRegistry=void 0;const n=r(6859),o=r(1371),i=r(2691),s=r(9183),a=r(9314);t.glslRegistry={encoding:o.EncodingGlslLib,fragcolor:i.FragColorGlslLib,vec:a.VecGlslLib,shapeUtils:s.ShapeUtilsGlslLib,coordinates:n.CoordsGlslLib}},9183:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ShapeUtilsGlslLib=void 0;const n=r(1997);class o extends n.GlslLib{constructor(e){super(e)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.bcastIndex()),this.bcastMatmulIndex()),this.offsetToIndices()),this.indicesToOffset()),this.incrementIndices())}getCustomTypes(){return{}}bcastIndex(){const e=this.context.outputTextureLayout.shape.length,t={};return this.context.programInfo.inputNames.forEach(((r,o)=>{const i=this.context.inputTextureLayouts[o].unpackedShape;if(i.length<=e){const o=i.length,s=e-o,a=`bcastIndices_${r}`;let u="";for(let e=0;e<o;++e)u+=`\n realIndices[${e}] = int( mod(float(bcastedIndices[${s+e}]), ${i[e]}.0) );\n `;const l=`\n void ${a} (int bcastedIndices[${e}], out int realIndices[${o}]) {\n ${u}\n }\n `;t[a]=new n.GlslLibRoutine(l)}})),t}bcastMatmulIndex(){const e=this.context.outputTextureLayout.shape.length,t={};return this.context.programInfo.inputNames.forEach(((r,o)=>{const i=this.context.inputTextureLayouts[o].shape;if(!(i.length<2||i.length>e)){const o=i.length,s=e-o,a=`bcastMatmulIndices_${r}`;let u="";for(let e=0;e<o-2;++e)u+=`\n realIndices[${e}] = int( mod(float(bcastedIndices[${s+e}]), ${i[e]}.0) );\n `;const l=`\n void ${a}(int bcastedIndices[${e}], out int realIndices[${o}]) {\n ${u}\n realIndices[${o-1}] = bcastedIndices[${e-1}];\n realIndices[${o-2}] = bcastedIndices[${e-2}];\n }\n `;t[a]=new n.GlslLibRoutine(l)}})),t}indicesToOffset(){const e={};return this.context.programInfo.inputNames.forEach(((t,r)=>{const i=this.context.inputTextureLayouts[r].shape,s=this.context.inputTextureLayouts[r].strides,a=i.length;let u=`indicesToOffset_${t}`;e[u]=new n.GlslLibRoutine(o.indexToOffsetSingle(u,a,s)),u=`indicesToOffset_${t}_T`,e[u]=new n.GlslLibRoutine(o.indexToOffsetSingle(u,a,s.slice().reverse()))})),e}static indexToOffsetSingle(e,t,r){let n="";for(let e=t-1;e>=0;--e)n+=`\n offset += indices[${e}] * ${r[e]};\n `;return`\n int ${e}(int indices[${t}]) {\n int offset = 0;\n ${n}\n return offset;\n }\n `}offsetToIndices(){const e={};return this.context.programInfo.inputNames.forEach(((t,r)=>{const i=this.context.inputTextureLayouts[r].shape,s=this.context.inputTextureLayouts[r].strides,a=i.length;let u=`offsetToIndices_${t}`;e[u]=new n.GlslLibRoutine(o.offsetToIndicesSingle(u,a,s)),u=`offsetToIndices_${t}_T`,e[u]=new n.GlslLibRoutine(o.offsetToIndicesSingle(u,a,s.slice().reverse()))})),e}static offsetToIndicesSingle(e,t,r){const n=[];for(let e=0;e<t-1;++e)n.push(`\n indices[${e}] = offset / ${r[e]};`),n.push(`\n offset -= indices[${e}] * ${r[e]};`);return n.push(`\n indices[${t-1}] = offset;`),`\n void ${e}(int offset, out int indices[${t}]) {\n ${n.join("")}\n }\n `}incrementIndices(){const e={};return this.context.programInfo.inputNames.forEach(((t,r)=>{const o=this.context.inputTextureLayouts[r].shape,i=o.length,s=`incrementIndices_${t}`;let a="";for(let e=0;e<i;++e)a+=`\n shape[${e}] = ${o[e]};`;const u=`\n void ${s}(int axis, out int indices[${i}]) {\n int shape[${i}];\n ${a};\n for(int i = ${i} -1 ; i >= 0; --i) {\n if(i > axis) continue;\n indices[i] += 1;\n if(indices[i] < shape[i]) {\n break;\n }\n indices[i] = 0;\n }\n }\n `;e[s]=new n.GlslLibRoutine(u)})),e}}t.ShapeUtilsGlslLib=o},6757:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getDefaultFragShaderMain=t.getFragShaderPreamble=t.getVertexShaderSource=t.getGlsl=void 0;const r={version:"",attribute:"attribute",varyingVertex:"varying",varyingFrag:"varying",texture2D:"texture2D",output:"gl_FragColor",outputDeclaration:""},n={version:"#version 300 es",attribute:"in",varyingVertex:"out",varyingFrag:"in",texture2D:"texture",output:"outputColor",outputDeclaration:"out vec4 outputColor;"};function o(e){return 1===e?r:n}t.getGlsl=o,t.getVertexShaderSource=function(e){const t=o(e);return`${t.version}\n precision highp float;\n ${t.attribute} vec3 position;\n ${t.attribute} vec2 textureCoord;\n\n ${t.varyingVertex} vec2 TexCoords;\n\n void main()\n {\n gl_Position = vec4(position, 1.0);\n TexCoords = textureCoord;\n }`},t.getFragShaderPreamble=function(e){const t=o(e);return`${t.version}\n precision highp float;\n precision highp int;\n precision highp sampler2D;\n ${t.varyingFrag} vec2 TexCoords;\n ${t.outputDeclaration}\n const vec2 halfCR = vec2(0.5, 0.5);\n\n // Custom vector types to handle higher dimenalities.\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n `},t.getDefaultFragShaderMain=function(e,t){return`\n void main() {\n int indices[${t}];\n toVec(TexCoords, indices);\n vec4 result = vec4(process(indices));\n ${o(e).output} = result;\n }\n `}},9314:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.VecGlslLib=void 0;const n=r(1997);class o extends n.GlslLib{constructor(e){super(e)}getCustomTypes(){return{}}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign({},this.binaryVecFunctions()),this.copyVec()),this.setVecItem()),this.getVecItem())}binaryVecFunctions(){const e=this.context.outputTextureLayout.shape.length,t={add:"+=",sub:"-=",mul:"*=",div:"/="},r={};for(const o in t){const i=`${o}Vec`;let s="";for(let r=0;r<e;++r)s+=`\n dest[${r}] ${t[o]} src[${r}];\n `;const a=`\n void ${i}(int src[${e}], out int dest[${e}]) {\n ${s}\n }\n `;r[i]=new n.GlslLibRoutine(a)}return r}copyVec(){const e=this.context.outputTextureLayout.shape.length;let t="";for(let r=0;r<e;++r)t+=`\n dest[${r}] = src[${r}];\n `;const r=`\n void copyVec(int src[${e}], out int dest[${e}]) {\n ${t}\n }\n `;return{copyVec:new n.GlslLibRoutine(r)}}setVecItem(){const e=this.context.outputTextureLayout.shape.length;let t=`\n if(index < 0)\n index =${e} + index;\n if (index == 0)\n m[0] = value;\n `;for(let r=1;r<e-1;++r)t+=`\n else if (index == ${r})\n m[${r}] = value;\n `;t+=`\n else\n m[${e-1}] = value;\n `;const r=`\n void setVecItem(out int m[${e}], int index, int value) {\n ${t}\n }\n `;return{setVecItem:new n.GlslLibRoutine(r)}}getVecItem(){const e=this.context.outputTextureLayout.shape.length;let t=`\n if(index < 0)\n index = ${e} + index;\n if (index == 0)\n return m[0];\n `;for(let r=1;r<e-1;++r)t+=`\n else if (index == ${r})\n return m[${r}];\n `;t+=`\n else\n return m[${e-1}];\n `;const r=`\n int getVecItem(int m[${e}], int index) {\n ${t}\n }\n `;return{getVecItem:new n.GlslLibRoutine(r)}}}t.VecGlslLib=o},7860:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebGLInferenceHandler=void 0;const n=r(1315),o=r(9240),i=r(7273),s=r(9),a=r(7379),u=r(2488),l=r(540),c=r(3314),p=r(5639);t.WebGLInferenceHandler=class{constructor(e){this.session=e,this.packedTextureDataCache=new Map,this.unpackedTextureDataCach