@genai-fi/nanogpt 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Generator.js +11 -11
- package/dist/NanoGPTModel.d.ts +2 -2
- package/dist/NanoGPTModel.js +104 -136
- package/dist/{RealDiv-BYViZwhN.js → RealDiv-C4hOvYOZ.js} +26 -25
- package/dist/{Reshape-t7Kcikjk.js → Reshape-BLijOA8h.js} +5 -5
- package/dist/TeachableLLM.d.ts +3 -0
- package/dist/TeachableLLM.js +50 -47
- package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-BLltddza.js} +4 -4
- package/dist/{axis_util-Bu4h7XWV.js → axis_util-DaAl5MER.js} +3 -3
- package/dist/backend.d.ts +1 -0
- package/dist/backend.js +7 -0
- package/dist/backend_util-DWiwsi2N.js +749 -0
- package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-C4v-j9yA.js} +2 -2
- package/dist/{concat-5aPGqw3Z.js → concat-CsHeR4zV.js} +8 -8
- package/dist/{dataset-pgqp-YfL.js → dataset-JDyjG3QR.js} +3 -3
- package/dist/{dropout-Bciw46HT.js → dropout-hpDwECTe.js} +7 -7
- package/dist/{gather-DjyCjmOD.js → gather-D0_gPiBz.js} +4 -4
- package/dist/gelu-uyHP1x1f.js +26 -0
- package/dist/gpgpu_math-DJm3ZTAf.js +2371 -0
- package/dist/index-BPPzKVdR.js +12099 -0
- package/dist/{index-BAzbokzv.js → index-C0dhsYom.js} +405 -389
- package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CwRTFqrc.js} +31 -30
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +5 -5
- package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-D086OgZJ.js} +15 -15
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -5
- package/dist/{mat_mul-7121rsJk.js → mat_mul-1nwdPkQ_.js} +4 -4
- package/dist/{max-DtlIuVeW.js → max-BQc2Aj-I.js} +4 -4
- package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-Gzf3I9UV.js} +1 -1
- package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
- package/dist/{ones-BBlSRqn1.js → ones-D63HpSF_.js} +2 -2
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +8 -8
- package/dist/ops/cpu/attentionMask.js +9 -9
- package/dist/ops/cpu/fusedSoftmax.js +17 -11
- package/dist/ops/cpu/gatherSub.js +7 -7
- package/dist/ops/cpu/gelu.js +13 -13
- package/dist/ops/cpu/matMulGelu.js +36 -24
- package/dist/ops/cpu/matMulMul.js +14 -8
- package/dist/ops/cpu/mulDropout.js +9 -3
- package/dist/ops/cpu/normRMS.js +5 -5
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +11 -11
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +3 -24
- package/dist/ops/grads/matMulGelu.js +5 -5
- package/dist/ops/grads/normRMS.js +6 -6
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +3 -3
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +4 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +4 -4
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +5 -5
- package/dist/ops/webgl/matMulGelu.js +17 -17
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +4 -4
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/ops/webgpu/appendCache.js +56 -0
- package/dist/ops/webgpu/attentionMask.d.ts +1 -0
- package/dist/ops/webgpu/attentionMask.js +64 -0
- package/dist/ops/webgpu/gatherSub.d.ts +1 -0
- package/dist/ops/webgpu/gatherSub.js +37 -0
- package/dist/ops/webgpu/gelu.d.ts +14 -0
- package/dist/ops/webgpu/gelu.js +86 -0
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +8 -0
- package/dist/ops/webgpu/normRMS.d.ts +1 -0
- package/dist/ops/webgpu/normRMS.js +115 -0
- package/dist/ops/webgpu/qkv.d.ts +1 -0
- package/dist/ops/webgpu/qkv.js +56 -0
- package/dist/ops/webgpu/rope.d.ts +1 -0
- package/dist/ops/webgpu/rope.js +68 -0
- package/dist/ops/webgpu/scatterSub.d.ts +1 -0
- package/dist/ops/webgpu/scatterSub.js +37 -0
- package/dist/{ops-C0sQEcPw.js → ops-CIQLNshk.js} +452 -503
- package/dist/{random_width-DWzaOgrn.js → random_width-DkYP8W8N.js} +143 -144
- package/dist/{range-DYsrnfiy.js → range-CYzpQY53.js} +1 -1
- package/dist/{reciprocal-CJQeasVa.js → reciprocal-_A9yv27J.js} +1 -1
- package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-guvSxp7M.js} +202 -200
- package/dist/{reshape-krWGKraP.js → reshape-BMUzc1UY.js} +3 -3
- package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-IRBqKz_b.js} +3 -3
- package/dist/{selu_util-sntGesxr.js → selu_util-Dt_iuXaq.js} +6 -6
- package/dist/shared-BNa2q6jD.js +69 -0
- package/dist/{shared-Ca6iDobD.js → shared-CDu9S76h.js} +541 -606
- package/dist/{sin-D_h-qCSx.js → sin-Cocju-BY.js} +6 -6
- package/dist/{softmax-fsdtf6JC.js → softmax-GPNK3o-U.js} +3 -3
- package/dist/{split-eiktj-6L.js → split-CHzJjxDv.js} +4 -4
- package/dist/{stack-dfEEz2OY.js → stack-Dpgg_1W1.js} +2 -2
- package/dist/{sum-BE_Irnim.js → sum-B8wEpKsg.js} +5 -5
- package/dist/{tensor-Xyi595sG.js → tensor-RvZVNmg0.js} +1 -1
- package/dist/{tensor2d-CPEkynbH.js → tensor2d-B_kyod7_.js} +1 -1
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/Evaluator.js +1 -1
- package/dist/training/FullTrainer.js +20 -20
- package/dist/training/Trainer.d.ts +5 -6
- package/dist/training/Trainer.js +59 -60
- package/dist/training/sparseCrossEntropy.js +19 -26
- package/dist/utilities/dummy.js +19 -19
- package/dist/utilities/generate.js +15 -16
- package/dist/utilities/multinomialCPU.d.ts +2 -0
- package/dist/utilities/multinomialCPU.js +13 -0
- package/dist/utilities/performance.d.ts +2 -0
- package/dist/utilities/performance.js +16 -0
- package/dist/utilities/profile.d.ts +1 -0
- package/dist/utilities/profile.js +9 -6
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-wSS22xj5.js → variable-DXEUOwew.js} +1 -1
- package/dist/webgpu_util-g13LvDIv.js +625 -0
- package/dist/{zeros-YJDE7oRb.js → zeros-DCPCdFGq.js} +8 -8
- package/package.json +2 -1
- package/dist/gpgpu_math-CNslybmD.js +0 -3115
- package/dist/norm-CzltS9Fz.js +0 -86
- package/dist/ops/node/sparseCrossEntropy.js +0 -11
- /package/dist/ops/{node/sparseCrossEntropy.d.ts → webgpu/appendCache.d.ts} +0 -0
|
@@ -0,0 +1,2371 @@
|
|
|
1
|
+
import { ay as z, ac as v, az as oe, aA as ie, aB as ae, l as F, aC as me, aD as J, Z as B, aE as I, ab as T, j as E, aF as H, aG as $e, aH as Y, aa as Te } from "./index-C0dhsYom.js";
|
|
2
|
+
import "./index-Tf7vU29b.js";
|
|
3
|
+
import { b as Se } from "./backend_util-DWiwsi2N.js";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
* =============================================================================
|
|
19
|
+
*/
|
|
20
|
+
const Re = "model", Ee = ".json", Ce = ".weights.bin";
|
|
21
|
+
function K(e) {
|
|
22
|
+
return new Promise((t) => setTimeout(t)).then(e);
|
|
23
|
+
}
|
|
24
|
+
class N {
|
|
25
|
+
constructor(t) {
|
|
26
|
+
if (!v().getBool("IS_BROWSER"))
|
|
27
|
+
throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
|
|
28
|
+
t.startsWith(N.URL_SCHEME) && (t = t.slice(N.URL_SCHEME.length)), (t == null || t.length === 0) && (t = Re), this.modelJsonFileName = t + Ee, this.weightDataFileName = t + Ce;
|
|
29
|
+
}
|
|
30
|
+
async save(t) {
|
|
31
|
+
if (typeof document > "u")
|
|
32
|
+
throw new Error("Browser downloads are not supported in this environment since `document` is not present");
|
|
33
|
+
const n = oe.join(t.weightData), r = window.URL.createObjectURL(new Blob([n], { type: "application/octet-stream" }));
|
|
34
|
+
if (t.modelTopology instanceof ArrayBuffer)
|
|
35
|
+
throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");
|
|
36
|
+
{
|
|
37
|
+
const o = [{
|
|
38
|
+
paths: ["./" + this.weightDataFileName],
|
|
39
|
+
weights: t.weightSpecs
|
|
40
|
+
}], i = ie(t, o), a = window.URL.createObjectURL(new Blob([JSON.stringify(i)], { type: "application/json" })), s = this.modelJsonAnchor == null ? document.createElement("a") : this.modelJsonAnchor;
|
|
41
|
+
if (s.download = this.modelJsonFileName, s.href = a, await K(() => s.dispatchEvent(new MouseEvent("click"))), t.weightData != null) {
|
|
42
|
+
const c = this.weightDataAnchor == null ? document.createElement("a") : this.weightDataAnchor;
|
|
43
|
+
c.download = this.weightDataFileName, c.href = r, await K(() => c.dispatchEvent(new MouseEvent("click")));
|
|
44
|
+
}
|
|
45
|
+
return { modelArtifactsInfo: ae(t) };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
N.URL_SCHEME = "downloads://";
|
|
50
|
+
const we = (e) => v().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(N.URL_SCHEME) ? Fe(e.slice(N.URL_SCHEME.length)) : null;
|
|
51
|
+
z.registerSaveRouter(we);
|
|
52
|
+
function Fe(e = "model") {
|
|
53
|
+
return new N(e);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @license
|
|
57
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
58
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
59
|
+
* you may not use this file except in compliance with the License.
|
|
60
|
+
* You may obtain a copy of the License at
|
|
61
|
+
*
|
|
62
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
63
|
+
*
|
|
64
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
65
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
66
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
67
|
+
* See the License for the specific language governing permissions and
|
|
68
|
+
* limitations under the License.
|
|
69
|
+
* =============================================================================
|
|
70
|
+
*/
|
|
71
|
+
function Z(e, t, n, r) {
|
|
72
|
+
a(e), n = n ?? 0, r = r ?? 1, s(n, r);
|
|
73
|
+
let o = 0;
|
|
74
|
+
const i = (c) => (c.then((u) => {
|
|
75
|
+
const l = n + ++o / e.length * (r - n);
|
|
76
|
+
return t(l), u;
|
|
77
|
+
}), c);
|
|
78
|
+
function a(c) {
|
|
79
|
+
F(c != null && Array.isArray(c) && c.length > 0, () => "promises must be a none empty array");
|
|
80
|
+
}
|
|
81
|
+
function s(c, u) {
|
|
82
|
+
F(c >= 0 && c <= 1, () => `Progress fraction must be in range [0, 1], but got startFraction ${c}`), F(u >= 0 && u <= 1, () => `Progress fraction must be in range [0, 1], but got endFraction ${u}`), F(u >= c, () => `startFraction must be no more than endFraction, but got startFraction ${c} and endFraction ${u}`);
|
|
83
|
+
}
|
|
84
|
+
return Promise.all(e.map(i));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @license
|
|
88
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
89
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
90
|
+
* you may not use this file except in compliance with the License.
|
|
91
|
+
* You may obtain a copy of the License at
|
|
92
|
+
*
|
|
93
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
94
|
+
*
|
|
95
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
96
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
97
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
98
|
+
* See the License for the specific language governing permissions and
|
|
99
|
+
* limitations under the License.
|
|
100
|
+
* =============================================================================
|
|
101
|
+
*/
|
|
102
|
+
async function ge(e, t) {
|
|
103
|
+
t == null && (t = {});
|
|
104
|
+
const n = t.fetchFunc == null ? v().platform.fetch : t.fetchFunc, r = e.map((f) => n(f, t.requestInit, { isBinary: !0 })), s = (t.onProgress == null ? await Promise.all(r) : await Z(r, t.onProgress, 0, 0.5)).map((f) => f.arrayBuffer());
|
|
105
|
+
return t.onProgress == null ? await Promise.all(s) : await Z(s, t.onProgress, 0.5, 1);
|
|
106
|
+
}
|
|
107
|
+
function Ae(e, t) {
|
|
108
|
+
var n;
|
|
109
|
+
const r = t.fetchFunc == null ? v().platform.fetch : t.fetchFunc;
|
|
110
|
+
let o = 0, i;
|
|
111
|
+
return (n = t.onProgress) === null || n === void 0 || n.call(t, 0), new ReadableStream({
|
|
112
|
+
pull: async (a) => {
|
|
113
|
+
for (var s; o < e.length; ) {
|
|
114
|
+
i || (i = (await r(e[o], t.requestInit, { isBinary: !0 })).body.getReader());
|
|
115
|
+
const { done: c, value: u } = await i.read();
|
|
116
|
+
if (c) {
|
|
117
|
+
o++, i = void 0, (s = t.onProgress) === null || s === void 0 || s.call(t, o / e.length);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
a.enqueue(u);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
a.close();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @license
|
|
129
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
130
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
131
|
+
* you may not use this file except in compliance with the License.
|
|
132
|
+
* You may obtain a copy of the License at
|
|
133
|
+
*
|
|
134
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
135
|
+
*
|
|
136
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
137
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
138
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
139
|
+
* See the License for the specific language governing permissions and
|
|
140
|
+
* limitations under the License.
|
|
141
|
+
* =============================================================================
|
|
142
|
+
*/
|
|
143
|
+
const _e = "application/octet-stream", Ne = "application/json";
|
|
144
|
+
class q {
|
|
145
|
+
constructor(t, n) {
|
|
146
|
+
if (this.DEFAULT_METHOD = "POST", n == null && (n = {}), this.weightPathPrefix = n.weightPathPrefix, this.weightUrlConverter = n.weightUrlConverter, n.fetchFunc != null ? (F(typeof n.fetchFunc == "function", () => "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"), this.fetch = n.fetchFunc) : this.fetch = v().platform.fetch, F(t != null && t.length > 0, () => "URL path for http must not be null, undefined or empty."), Array.isArray(t) && F(t.length === 2, () => `URL paths for http must have a length of 2, (actual length is ${t.length}).`), this.path = t, n.requestInit != null && n.requestInit.body != null)
|
|
147
|
+
throw new Error("requestInit is expected to have no pre-existing body, but has one.");
|
|
148
|
+
this.requestInit = n.requestInit || {}, this.loadOptions = n;
|
|
149
|
+
}
|
|
150
|
+
async save(t) {
|
|
151
|
+
if (t.modelTopology instanceof ArrayBuffer)
|
|
152
|
+
throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
|
|
153
|
+
const n = Object.assign({ method: this.DEFAULT_METHOD }, this.requestInit);
|
|
154
|
+
n.body = new FormData();
|
|
155
|
+
const r = [{
|
|
156
|
+
paths: ["./model.weights.bin"],
|
|
157
|
+
weights: t.weightSpecs
|
|
158
|
+
}], o = ie(t, r);
|
|
159
|
+
if (n.body.append("model.json", new Blob([JSON.stringify(o)], { type: Ne }), "model.json"), t.weightData != null) {
|
|
160
|
+
const a = oe.join(t.weightData);
|
|
161
|
+
n.body.append("model.weights.bin", new Blob([a], { type: _e }), "model.weights.bin");
|
|
162
|
+
}
|
|
163
|
+
const i = await this.fetch(this.path, n);
|
|
164
|
+
if (i.ok)
|
|
165
|
+
return {
|
|
166
|
+
modelArtifactsInfo: ae(t),
|
|
167
|
+
responses: [i]
|
|
168
|
+
};
|
|
169
|
+
throw new Error(`BrowserHTTPRequest.save() failed due to HTTP response status ${i.status}.`);
|
|
170
|
+
}
|
|
171
|
+
async loadModelJSON() {
|
|
172
|
+
const t = await this.fetch(this.path, this.requestInit);
|
|
173
|
+
if (!t.ok)
|
|
174
|
+
throw new Error(`Request to ${this.path} failed with status code ${t.status}. Please verify this URL points to the model JSON of the model to load.`);
|
|
175
|
+
let n;
|
|
176
|
+
try {
|
|
177
|
+
n = await t.json();
|
|
178
|
+
} catch {
|
|
179
|
+
let a = `Failed to parse model JSON of response from ${this.path}.`;
|
|
180
|
+
throw this.path.endsWith(".pb") ? a += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : a += " Please make sure the server is serving valid JSON for this request.", new Error(a);
|
|
181
|
+
}
|
|
182
|
+
const r = n.modelTopology, o = n.weightsManifest;
|
|
183
|
+
if (r == null && o == null)
|
|
184
|
+
throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);
|
|
185
|
+
return n;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Load model artifacts via HTTP request(s).
|
|
189
|
+
*
|
|
190
|
+
* See the documentation to `tf.io.http` for details on the saved
|
|
191
|
+
* artifacts.
|
|
192
|
+
*
|
|
193
|
+
* @returns The loaded model artifacts (if loading succeeds).
|
|
194
|
+
*/
|
|
195
|
+
async load() {
|
|
196
|
+
if (this.loadOptions.streamWeights)
|
|
197
|
+
return this.loadStream();
|
|
198
|
+
const t = await this.loadModelJSON();
|
|
199
|
+
return me(t, (n) => this.loadWeights(n));
|
|
200
|
+
}
|
|
201
|
+
async loadStream() {
|
|
202
|
+
const t = await this.loadModelJSON(), n = await this.getWeightUrls(t.weightsManifest), r = J(t.weightsManifest), o = () => Ae(n, this.loadOptions);
|
|
203
|
+
return Object.assign(Object.assign({}, t), { weightSpecs: r, getWeightStream: o });
|
|
204
|
+
}
|
|
205
|
+
async getWeightUrls(t) {
|
|
206
|
+
const n = Array.isArray(this.path) ? this.path[1] : this.path, [r, o] = Ie(n), i = this.weightPathPrefix || r, a = [], s = [];
|
|
207
|
+
for (const c of t)
|
|
208
|
+
for (const u of c.paths)
|
|
209
|
+
this.weightUrlConverter != null ? s.push(this.weightUrlConverter(u)) : a.push(i + u + o);
|
|
210
|
+
return this.weightUrlConverter && a.push(...await Promise.all(s)), a;
|
|
211
|
+
}
|
|
212
|
+
async loadWeights(t) {
|
|
213
|
+
const n = await this.getWeightUrls(t), r = J(t), o = await ge(n, this.loadOptions);
|
|
214
|
+
return [r, o];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
q.URL_SCHEME_REGEX = /^https?:\/\//;
|
|
218
|
+
function Ie(e) {
|
|
219
|
+
const t = e.lastIndexOf("/"), n = e.lastIndexOf("?"), r = e.substring(0, t), o = n > t ? e.substring(n) : "";
|
|
220
|
+
return [r + "/", o];
|
|
221
|
+
}
|
|
222
|
+
function Q(e) {
|
|
223
|
+
return e.match(q.URL_SCHEME_REGEX) != null;
|
|
224
|
+
}
|
|
225
|
+
const ce = (e, t) => {
|
|
226
|
+
if (typeof fetch > "u" && (t == null || t.fetchFunc == null))
|
|
227
|
+
return null;
|
|
228
|
+
{
|
|
229
|
+
let n = !0;
|
|
230
|
+
if (Array.isArray(e) ? n = e.every((r) => Q(r)) : n = Q(e), n)
|
|
231
|
+
return Ue(e, t);
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
z.registerSaveRouter(ce);
|
|
236
|
+
z.registerLoadRouter(ce);
|
|
237
|
+
function Ue(e, t) {
|
|
238
|
+
return new q(e, t);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @license
|
|
242
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
243
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
244
|
+
* you may not use this file except in compliance with the License.
|
|
245
|
+
* You may obtain a copy of the License at
|
|
246
|
+
*
|
|
247
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
248
|
+
*
|
|
249
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
250
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
251
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
252
|
+
* See the License for the specific language governing permissions and
|
|
253
|
+
* limitations under the License.
|
|
254
|
+
* =============================================================================
|
|
255
|
+
*/
|
|
256
|
+
function L() {
|
|
257
|
+
let e, t, n, r, o, i, a, s, c, u;
|
|
258
|
+
return v().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", o = "texture", i = "outputColor", a = "out vec4 outputColor;", s = v().getBool("WEBGL2_ISNAN_CUSTOM") ? `
|
|
259
|
+
bool isnan_custom(float val) {
|
|
260
|
+
uint floatToUint = floatBitsToUint(val);
|
|
261
|
+
return (floatToUint & 0x7fffffffu) > 0x7f800000u;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
bvec4 isnan_custom(vec4 val) {
|
|
265
|
+
return bvec4(isnan_custom(val.x),
|
|
266
|
+
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#define isnan(value) isnan_custom(value)
|
|
270
|
+
` : "", c = "", u = `
|
|
271
|
+
#define round(value) newRound(value)
|
|
272
|
+
int newRound(float value) {
|
|
273
|
+
return int(floor(value + 0.5));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
ivec4 newRound(vec4 value) {
|
|
277
|
+
return ivec4(floor(value + vec4(0.5)));
|
|
278
|
+
}
|
|
279
|
+
`) : (e = "", t = "attribute", n = "varying", r = "varying", o = "texture2D", i = "gl_FragColor", a = "", s = `
|
|
280
|
+
#define isnan(value) isnan_custom(value)
|
|
281
|
+
bool isnan_custom(float val) {
|
|
282
|
+
return (val > 0. || val < 1. || val == 0.) ? false : true;
|
|
283
|
+
}
|
|
284
|
+
bvec4 isnan_custom(vec4 val) {
|
|
285
|
+
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
|
|
286
|
+
}
|
|
287
|
+
`, c = `
|
|
288
|
+
uniform float INFINITY;
|
|
289
|
+
|
|
290
|
+
bool isinf(float val) {
|
|
291
|
+
return abs(val) == INFINITY;
|
|
292
|
+
}
|
|
293
|
+
bvec4 isinf(vec4 val) {
|
|
294
|
+
return equal(abs(val), vec4(INFINITY));
|
|
295
|
+
}
|
|
296
|
+
`, u = `
|
|
297
|
+
int round(float value) {
|
|
298
|
+
return int(floor(value + 0.5));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
ivec4 round(vec4 value) {
|
|
302
|
+
return ivec4(floor(value + vec4(0.5)));
|
|
303
|
+
}
|
|
304
|
+
`), {
|
|
305
|
+
version: e,
|
|
306
|
+
attribute: t,
|
|
307
|
+
varyingVs: n,
|
|
308
|
+
varyingFs: r,
|
|
309
|
+
texture2D: o,
|
|
310
|
+
output: i,
|
|
311
|
+
defineOutput: a,
|
|
312
|
+
defineSpecialNaN: s,
|
|
313
|
+
defineSpecialInf: c,
|
|
314
|
+
defineRound: u
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @license
|
|
319
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
320
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
321
|
+
* you may not use this file except in compliance with the License.
|
|
322
|
+
* You may obtain a copy of the License at
|
|
323
|
+
*
|
|
324
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
325
|
+
*
|
|
326
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
327
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
328
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
329
|
+
* See the License for the specific language governing permissions and
|
|
330
|
+
* limitations under the License.
|
|
331
|
+
* =============================================================================
|
|
332
|
+
*/
|
|
333
|
+
function V(e, t, n = "index") {
|
|
334
|
+
const r = B(t);
|
|
335
|
+
return r.map((o, i) => {
|
|
336
|
+
const a = `int ${e[i]} = ${n} / ${o}`, s = i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${o}` : `index -= ${e[i]} * ${o}`;
|
|
337
|
+
return `${a}; ${s};`;
|
|
338
|
+
}).join("");
|
|
339
|
+
}
|
|
340
|
+
function se(e, t, n = "index") {
|
|
341
|
+
const r = B(t);
|
|
342
|
+
return r.map((o, i) => {
|
|
343
|
+
const a = `int ${e[i]} = ${n} / outShapeStrides[${i}]`, s = i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * outShapeStrides[${i}]` : `index -= ${e[i]} * outShapeStrides[${i}]`;
|
|
344
|
+
return `${a}; ${s};`;
|
|
345
|
+
}).join("");
|
|
346
|
+
}
|
|
347
|
+
function Oe(e, t) {
|
|
348
|
+
const n = e.length, r = e.map((i) => `${t}[${i}]`), o = new Array(n - 1);
|
|
349
|
+
o[n - 2] = r[n - 1];
|
|
350
|
+
for (let i = n - 3; i >= 0; --i)
|
|
351
|
+
o[i] = `(${o[i + 1]} * ${r[i + 1]})`;
|
|
352
|
+
return o;
|
|
353
|
+
}
|
|
354
|
+
function Lt(e, t, n = "index") {
|
|
355
|
+
const r = e.map((i, a) => a), o = Oe(r, t);
|
|
356
|
+
return o.map((i, a) => {
|
|
357
|
+
const s = `int ${e[a]} = ${n} / ${o[a]}`, c = a === o.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * ${o[a]}` : `index -= ${e[a]} * ${o[a]}`;
|
|
358
|
+
return `${s}; ${c};`;
|
|
359
|
+
}).join("");
|
|
360
|
+
}
|
|
361
|
+
function bt(e) {
|
|
362
|
+
const t = B(e).map((n) => n.toString());
|
|
363
|
+
return `
|
|
364
|
+
int getFlatIndex(ivec3 coords) {
|
|
365
|
+
return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
368
|
+
}
|
|
369
|
+
function Dt() {
|
|
370
|
+
return `
|
|
371
|
+
int getFlatIndex(ivec3 coords) {
|
|
372
|
+
return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
}
|
|
376
|
+
const yt = `
|
|
377
|
+
const float FLOAT_MAX = 1.70141184e38;
|
|
378
|
+
const float FLOAT_MIN = 1.17549435e-38;
|
|
379
|
+
|
|
380
|
+
lowp vec4 encode_float(highp float v) {
|
|
381
|
+
if (isnan(v)) {
|
|
382
|
+
return vec4(255, 255, 255, 255);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
highp float av = abs(v);
|
|
386
|
+
|
|
387
|
+
if(av < FLOAT_MIN) {
|
|
388
|
+
return vec4(0.0, 0.0, 0.0, 0.0);
|
|
389
|
+
} else if(v > FLOAT_MAX) {
|
|
390
|
+
return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
|
|
391
|
+
} else if(v < -FLOAT_MAX) {
|
|
392
|
+
return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
highp vec4 c = vec4(0,0,0,0);
|
|
396
|
+
|
|
397
|
+
highp float e = floor(log2(av));
|
|
398
|
+
highp float m = exp2(fract(log2(av))) - 1.0;
|
|
399
|
+
|
|
400
|
+
c[2] = floor(128.0 * m);
|
|
401
|
+
m -= c[2] / 128.0;
|
|
402
|
+
c[1] = floor(32768.0 * m);
|
|
403
|
+
m -= c[1] / 32768.0;
|
|
404
|
+
c[0] = floor(8388608.0 * m);
|
|
405
|
+
|
|
406
|
+
highp float ebias = e + 127.0;
|
|
407
|
+
c[3] = floor(ebias / 2.0);
|
|
408
|
+
ebias -= c[3] * 2.0;
|
|
409
|
+
c[2] += floor(ebias) * 128.0;
|
|
410
|
+
|
|
411
|
+
c[3] += 128.0 * step(0.0, -v);
|
|
412
|
+
|
|
413
|
+
return c / 255.0;
|
|
414
|
+
}
|
|
415
|
+
`;
|
|
416
|
+
/**
|
|
417
|
+
* @license
|
|
418
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
419
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
420
|
+
* you may not use this file except in compliance with the License.
|
|
421
|
+
* You may obtain a copy of the License at
|
|
422
|
+
*
|
|
423
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
424
|
+
*
|
|
425
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
426
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
427
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
428
|
+
* See the License for the specific language governing permissions and
|
|
429
|
+
* limitations under the License.
|
|
430
|
+
* =============================================================================
|
|
431
|
+
*/
|
|
432
|
+
const { getBroadcastDims: ue } = Se;
|
|
433
|
+
function Le(e, t, n) {
|
|
434
|
+
const r = [];
|
|
435
|
+
if (e.forEach((h) => {
|
|
436
|
+
const x = E(h.shapeInfo.logicalShape);
|
|
437
|
+
if (h.shapeInfo.isUniform ? r.push(`uniform float ${h.name}${x > 1 ? `[${x}]` : ""};`) : (r.push(`uniform sampler2D ${h.name};`), r.push(`uniform int offset${h.name};`)), n.enableShapeUniforms) {
|
|
438
|
+
const { uniformShape: p } = j(n.packedInputs, h.shapeInfo.logicalShape, h.shapeInfo.texShape);
|
|
439
|
+
switch (p.length) {
|
|
440
|
+
case 1:
|
|
441
|
+
r.push(`uniform int ${h.name}Shape;`);
|
|
442
|
+
break;
|
|
443
|
+
case 2:
|
|
444
|
+
r.push(`uniform ivec2 ${h.name}Shape;`);
|
|
445
|
+
break;
|
|
446
|
+
case 3:
|
|
447
|
+
r.push(`uniform ivec3 ${h.name}Shape;`);
|
|
448
|
+
break;
|
|
449
|
+
case 4:
|
|
450
|
+
r.push(`uniform ivec4 ${h.name}Shape;`);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
r.push(`uniform ivec2 ${h.name}TexShape;`);
|
|
454
|
+
}
|
|
455
|
+
}), n.enableShapeUniforms) {
|
|
456
|
+
switch (t.logicalShape.length) {
|
|
457
|
+
case 1:
|
|
458
|
+
r.push("uniform int outShape;");
|
|
459
|
+
break;
|
|
460
|
+
case 2:
|
|
461
|
+
r.push("uniform ivec2 outShape;"), r.push("uniform int outShapeStrides;");
|
|
462
|
+
break;
|
|
463
|
+
case 3:
|
|
464
|
+
r.push("uniform ivec3 outShape;"), r.push("uniform ivec2 outShapeStrides;");
|
|
465
|
+
break;
|
|
466
|
+
case 4:
|
|
467
|
+
r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
r.push("uniform ivec2 outTexShape;");
|
|
471
|
+
}
|
|
472
|
+
n.customUniforms && n.customUniforms.forEach((h) => {
|
|
473
|
+
r.push(`uniform ${h.type} ${h.name}${h.arrayIndex ? `[${h.arrayIndex}]` : ""};`);
|
|
474
|
+
});
|
|
475
|
+
const o = r.join(`
|
|
476
|
+
`), i = e.map((h) => be(h, t, n.packedInputs, n.enableShapeUniforms)).join(`
|
|
477
|
+
`), a = t.texShape, s = L(), c = Me(s);
|
|
478
|
+
let u, l, f = Pe(s);
|
|
479
|
+
return t.isPacked ? (u = De(t.logicalShape, a, n.enableShapeUniforms), l = ke(s)) : (u = ye(t.logicalShape, a, n.enableShapeUniforms), l = Be(s)), n.packedInputs && (f += He), [
|
|
480
|
+
f,
|
|
481
|
+
c,
|
|
482
|
+
l,
|
|
483
|
+
o,
|
|
484
|
+
u,
|
|
485
|
+
i,
|
|
486
|
+
n.userCode
|
|
487
|
+
].join(`
|
|
488
|
+
`);
|
|
489
|
+
}
|
|
490
|
+
function b(e, t = !1) {
|
|
491
|
+
const n = e.shapeInfo.logicalShape;
|
|
492
|
+
switch (n.length) {
|
|
493
|
+
case 0:
|
|
494
|
+
return nt(e, t);
|
|
495
|
+
case 1:
|
|
496
|
+
return ot(e, t);
|
|
497
|
+
case 2:
|
|
498
|
+
return at(e, t);
|
|
499
|
+
case 3:
|
|
500
|
+
return st(e, t);
|
|
501
|
+
case 4:
|
|
502
|
+
return lt(e, t);
|
|
503
|
+
case 5:
|
|
504
|
+
return ft(e);
|
|
505
|
+
case 6:
|
|
506
|
+
return ht(e);
|
|
507
|
+
default:
|
|
508
|
+
throw new Error(`${n.length}-D input sampling is not yet supported`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function le(e, t) {
|
|
512
|
+
switch (e.shapeInfo.logicalShape.length) {
|
|
513
|
+
case 0:
|
|
514
|
+
return tt(e);
|
|
515
|
+
case 1:
|
|
516
|
+
return rt(e, t);
|
|
517
|
+
case 2:
|
|
518
|
+
return it(e, t);
|
|
519
|
+
case 3:
|
|
520
|
+
return ct(e, t);
|
|
521
|
+
default:
|
|
522
|
+
return ut(e, t);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function be(e, t, n = !1, r) {
|
|
526
|
+
let o = "";
|
|
527
|
+
n ? o += le(e, r) : o += b(e, r);
|
|
528
|
+
const i = e.shapeInfo.logicalShape, a = t.logicalShape;
|
|
529
|
+
return i.length <= a.length && (n ? o += dt(e, t) : o += xt(e, t)), o;
|
|
530
|
+
}
|
|
531
|
+
function De(e, t, n) {
|
|
532
|
+
switch (e.length) {
|
|
533
|
+
case 0:
|
|
534
|
+
return fe();
|
|
535
|
+
case 1:
|
|
536
|
+
return Ge(e, t, n);
|
|
537
|
+
case 2:
|
|
538
|
+
return Qe(e, t, n);
|
|
539
|
+
case 3:
|
|
540
|
+
return qe(e, t, n);
|
|
541
|
+
default:
|
|
542
|
+
return Je(e, t, n);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
function ye(e, t, n) {
|
|
546
|
+
switch (e.length) {
|
|
547
|
+
case 0:
|
|
548
|
+
return fe();
|
|
549
|
+
case 1:
|
|
550
|
+
return ze(e, t, n);
|
|
551
|
+
case 2:
|
|
552
|
+
return et(e, t, n);
|
|
553
|
+
case 3:
|
|
554
|
+
return je(e, t, n);
|
|
555
|
+
case 4:
|
|
556
|
+
return Ye(e, t, n);
|
|
557
|
+
case 5:
|
|
558
|
+
return Ke(e, t);
|
|
559
|
+
case 6:
|
|
560
|
+
return Ze(e, t);
|
|
561
|
+
default:
|
|
562
|
+
throw new Error(`${e.length}-D output sampling is not yet supported`);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function Me(e) {
|
|
566
|
+
return `
|
|
567
|
+
float sampleTexture(sampler2D textureSampler, vec2 uv) {
|
|
568
|
+
return ${e.texture2D}(textureSampler, uv).r;
|
|
569
|
+
}
|
|
570
|
+
`;
|
|
571
|
+
}
|
|
572
|
+
function Be(e) {
|
|
573
|
+
return `
|
|
574
|
+
void setOutput(float val) {
|
|
575
|
+
${e.output} = vec4(val, 0, 0, 0);
|
|
576
|
+
}
|
|
577
|
+
`;
|
|
578
|
+
}
|
|
579
|
+
function ke(e) {
|
|
580
|
+
return `
|
|
581
|
+
void setOutput(vec4 val) {
|
|
582
|
+
${e.output} = val;
|
|
583
|
+
}
|
|
584
|
+
`;
|
|
585
|
+
}
|
|
586
|
+
function Pe(e) {
|
|
587
|
+
return `${e.version}
|
|
588
|
+
precision highp float;
|
|
589
|
+
precision highp int;
|
|
590
|
+
precision highp sampler2D;
|
|
591
|
+
${e.varyingFs} vec2 resultUV;
|
|
592
|
+
${e.defineOutput}
|
|
593
|
+
const vec2 halfCR = vec2(0.5, 0.5);
|
|
594
|
+
|
|
595
|
+
struct ivec5
|
|
596
|
+
{
|
|
597
|
+
int x;
|
|
598
|
+
int y;
|
|
599
|
+
int z;
|
|
600
|
+
int w;
|
|
601
|
+
int u;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
struct ivec6
|
|
605
|
+
{
|
|
606
|
+
int x;
|
|
607
|
+
int y;
|
|
608
|
+
int z;
|
|
609
|
+
int w;
|
|
610
|
+
int u;
|
|
611
|
+
int v;
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
uniform float NAN;
|
|
615
|
+
${e.defineSpecialNaN}
|
|
616
|
+
${e.defineSpecialInf}
|
|
617
|
+
${e.defineRound}
|
|
618
|
+
|
|
619
|
+
int imod(int x, int y) {
|
|
620
|
+
return x - y * (x / y);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
int idiv(int a, int b, float sign) {
|
|
624
|
+
int res = a / b;
|
|
625
|
+
int mod = imod(a, b);
|
|
626
|
+
if (sign < 0. && mod != 0) {
|
|
627
|
+
res -= 1;
|
|
628
|
+
}
|
|
629
|
+
return res;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
//Based on the work of Dave Hoskins
|
|
633
|
+
//https://www.shadertoy.com/view/4djSRW
|
|
634
|
+
#define HASHSCALE1 443.8975
|
|
635
|
+
float random(float seed){
|
|
636
|
+
vec2 p = resultUV * seed;
|
|
637
|
+
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
|
|
638
|
+
p3 += dot(p3, p3.yzx + 19.19);
|
|
639
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
${Ve}
|
|
643
|
+
${We}
|
|
644
|
+
${Xe}
|
|
645
|
+
`;
|
|
646
|
+
}
|
|
647
|
+
const Ve = `
|
|
648
|
+
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
|
|
649
|
+
int texR = index / texNumC;
|
|
650
|
+
int texC = index - texR * texNumC;
|
|
651
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
652
|
+
}
|
|
653
|
+
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
|
|
654
|
+
int texelIndex = index / 2;
|
|
655
|
+
int texR = texelIndex / texNumC;
|
|
656
|
+
int texC = texelIndex - texR * texNumC;
|
|
657
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
658
|
+
}
|
|
659
|
+
`, We = `
|
|
660
|
+
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
|
|
661
|
+
int texNumC, int row, int col) {
|
|
662
|
+
int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
|
|
663
|
+
int texR = texelIndex / texNumC;
|
|
664
|
+
int texC = texelIndex - texR * texNumC;
|
|
665
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
666
|
+
}
|
|
667
|
+
`, Xe = `
|
|
668
|
+
vec2 packedUVfrom3D(int texNumR, int texNumC,
|
|
669
|
+
int texelsInBatch, int texelsInLogicalRow, int b,
|
|
670
|
+
int row, int col) {
|
|
671
|
+
int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
|
|
672
|
+
int texR = index / texNumC;
|
|
673
|
+
int texC = index - texR * texNumC;
|
|
674
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
675
|
+
}
|
|
676
|
+
`, He = `
|
|
677
|
+
float getChannel(vec4 frag, vec2 innerDims) {
|
|
678
|
+
vec2 modCoord = mod(innerDims, 2.);
|
|
679
|
+
return modCoord.x == 0. ?
|
|
680
|
+
(modCoord.y == 0. ? frag.r : frag.g) :
|
|
681
|
+
(modCoord.y == 0. ? frag.b : frag.a);
|
|
682
|
+
}
|
|
683
|
+
float getChannel(vec4 frag, int dim) {
|
|
684
|
+
float modCoord = mod(float(dim), 2.);
|
|
685
|
+
return modCoord == 0. ? frag.r : frag.g;
|
|
686
|
+
}
|
|
687
|
+
`;
|
|
688
|
+
function fe() {
|
|
689
|
+
return `
|
|
690
|
+
int getOutputCoords() {
|
|
691
|
+
return 0;
|
|
692
|
+
}
|
|
693
|
+
`;
|
|
694
|
+
}
|
|
695
|
+
function Ge(e, t, n) {
|
|
696
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
697
|
+
return r[0] === 1 ? n ? `
|
|
698
|
+
int getOutputCoords() {
|
|
699
|
+
return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));
|
|
700
|
+
}
|
|
701
|
+
` : `
|
|
702
|
+
int getOutputCoords() {
|
|
703
|
+
return 2 * int(resultUV.x * ${r[1]}.0);
|
|
704
|
+
}
|
|
705
|
+
` : r[1] === 1 ? n ? `
|
|
706
|
+
int getOutputCoords() {
|
|
707
|
+
return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));
|
|
708
|
+
}
|
|
709
|
+
` : `
|
|
710
|
+
int getOutputCoords() {
|
|
711
|
+
return 2 * int(resultUV.y * ${r[0]}.0);
|
|
712
|
+
}
|
|
713
|
+
` : n ? `
|
|
714
|
+
int getOutputCoords() {
|
|
715
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
716
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
717
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
718
|
+
return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);
|
|
719
|
+
}
|
|
720
|
+
` : `
|
|
721
|
+
int getOutputCoords() {
|
|
722
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
723
|
+
vec2(${r[0]}, ${r[1]}));
|
|
724
|
+
return 2 * (resTexRC.x * ${r[1]} + resTexRC.y);
|
|
725
|
+
}
|
|
726
|
+
`;
|
|
727
|
+
}
|
|
728
|
+
function ze(e, t, n) {
|
|
729
|
+
return t[0] === 1 ? n ? `
|
|
730
|
+
int getOutputCoords() {
|
|
731
|
+
return int(resultUV.x * float(outTexShape[1]));
|
|
732
|
+
}
|
|
733
|
+
` : `
|
|
734
|
+
int getOutputCoords() {
|
|
735
|
+
return int(resultUV.x * ${t[1]}.0);
|
|
736
|
+
}
|
|
737
|
+
` : t[1] === 1 ? n ? `
|
|
738
|
+
int getOutputCoords() {
|
|
739
|
+
return int(resultUV.y * float(outTexShape[0]));
|
|
740
|
+
}
|
|
741
|
+
` : `
|
|
742
|
+
int getOutputCoords() {
|
|
743
|
+
return int(resultUV.y * ${t[0]}.0);
|
|
744
|
+
}
|
|
745
|
+
` : n ? `
|
|
746
|
+
int getOutputCoords() {
|
|
747
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
748
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
749
|
+
return resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
750
|
+
}
|
|
751
|
+
` : `
|
|
752
|
+
int getOutputCoords() {
|
|
753
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
754
|
+
vec2(${t[0]}, ${t[1]}));
|
|
755
|
+
return resTexRC.x * ${t[1]} + resTexRC.y;
|
|
756
|
+
}
|
|
757
|
+
`;
|
|
758
|
+
}
|
|
759
|
+
function qe(e, t, n) {
|
|
760
|
+
if (n)
|
|
761
|
+
return `
|
|
762
|
+
ivec3 getOutputCoords() {
|
|
763
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
764
|
+
int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));
|
|
765
|
+
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));
|
|
766
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
767
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
768
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
769
|
+
|
|
770
|
+
int b = index / texelsInBatch;
|
|
771
|
+
index -= b * texelsInBatch;
|
|
772
|
+
|
|
773
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
774
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
775
|
+
|
|
776
|
+
return ivec3(b, r, c);
|
|
777
|
+
}
|
|
778
|
+
`;
|
|
779
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[2] / 2), i = o * Math.ceil(e[1] / 2);
|
|
780
|
+
return `
|
|
781
|
+
ivec3 getOutputCoords() {
|
|
782
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
783
|
+
vec2(${r[0]}, ${r[1]}));
|
|
784
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
785
|
+
|
|
786
|
+
int b = index / ${i};
|
|
787
|
+
index -= b * ${i};
|
|
788
|
+
|
|
789
|
+
int r = 2 * (index / ${o});
|
|
790
|
+
int c = imod(index, ${o}) * 2;
|
|
791
|
+
|
|
792
|
+
return ivec3(b, r, c);
|
|
793
|
+
}
|
|
794
|
+
`;
|
|
795
|
+
}
|
|
796
|
+
function je(e, t, n) {
|
|
797
|
+
if (n)
|
|
798
|
+
return `
|
|
799
|
+
ivec3 getOutputCoords() {
|
|
800
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
801
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
802
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
803
|
+
${se(["r", "c", "d"], e)}
|
|
804
|
+
return ivec3(r, c, d);
|
|
805
|
+
}
|
|
806
|
+
`;
|
|
807
|
+
const r = V(["r", "c", "d"], e);
|
|
808
|
+
return `
|
|
809
|
+
ivec3 getOutputCoords() {
|
|
810
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
811
|
+
vec2(${t[0]}, ${t[1]}));
|
|
812
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
813
|
+
${r}
|
|
814
|
+
return ivec3(r, c, d);
|
|
815
|
+
}
|
|
816
|
+
`;
|
|
817
|
+
}
|
|
818
|
+
function Je(e, t, n) {
|
|
819
|
+
if (n)
|
|
820
|
+
return `
|
|
821
|
+
ivec4 getOutputCoords() {
|
|
822
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
823
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
824
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
825
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
826
|
+
|
|
827
|
+
int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));
|
|
828
|
+
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));
|
|
829
|
+
int texelsInBatchN = texelsInBatch * outShape[1];
|
|
830
|
+
|
|
831
|
+
int b2 = index / texelsInBatchN;
|
|
832
|
+
index -= b2 * texelsInBatchN;
|
|
833
|
+
|
|
834
|
+
int b = index / texelsInBatch;
|
|
835
|
+
index -= b * texelsInBatch;
|
|
836
|
+
|
|
837
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
838
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
839
|
+
|
|
840
|
+
return ivec4(b2, b, r, c);
|
|
841
|
+
}
|
|
842
|
+
`;
|
|
843
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[e.length - 1] / 2), i = o * Math.ceil(e[e.length - 2] / 2);
|
|
844
|
+
let a = i, s = "", c = "b, r, c";
|
|
845
|
+
for (let u = 2; u < e.length - 1; u++)
|
|
846
|
+
a *= e[e.length - u - 1], s = `
|
|
847
|
+
int b${u} = index / ${a};
|
|
848
|
+
index -= b${u} * ${a};
|
|
849
|
+
` + s, c = `b${u}, ` + c;
|
|
850
|
+
return `
|
|
851
|
+
ivec${e.length} getOutputCoords() {
|
|
852
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
853
|
+
vec2(${r[0]}, ${r[1]}));
|
|
854
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
855
|
+
|
|
856
|
+
${s}
|
|
857
|
+
|
|
858
|
+
int b = index / ${i};
|
|
859
|
+
index -= b * ${i};
|
|
860
|
+
|
|
861
|
+
int r = 2 * (index / ${o});
|
|
862
|
+
int c = imod(index, ${o}) * 2;
|
|
863
|
+
|
|
864
|
+
return ivec${e.length}(${c});
|
|
865
|
+
}
|
|
866
|
+
`;
|
|
867
|
+
}
|
|
868
|
+
function Ye(e, t, n) {
|
|
869
|
+
if (n)
|
|
870
|
+
return `
|
|
871
|
+
ivec4 getOutputCoords() {
|
|
872
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
873
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
874
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
875
|
+
${se(["r", "c", "d", "d2"], e)}
|
|
876
|
+
return ivec4(r, c, d, d2);
|
|
877
|
+
}
|
|
878
|
+
`;
|
|
879
|
+
const r = V(["r", "c", "d", "d2"], e);
|
|
880
|
+
return `
|
|
881
|
+
ivec4 getOutputCoords() {
|
|
882
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
883
|
+
vec2(${t[0]}, ${t[1]}));
|
|
884
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
885
|
+
${r}
|
|
886
|
+
return ivec4(r, c, d, d2);
|
|
887
|
+
}
|
|
888
|
+
`;
|
|
889
|
+
}
|
|
890
|
+
function Ke(e, t) {
|
|
891
|
+
const n = V(["r", "c", "d", "d2", "d3"], e);
|
|
892
|
+
return `
|
|
893
|
+
ivec5 getOutputCoords() {
|
|
894
|
+
ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
|
|
895
|
+
${t[1]}));
|
|
896
|
+
|
|
897
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
898
|
+
|
|
899
|
+
${n}
|
|
900
|
+
|
|
901
|
+
ivec5 outShape = ivec5(r, c, d, d2, d3);
|
|
902
|
+
return outShape;
|
|
903
|
+
}
|
|
904
|
+
`;
|
|
905
|
+
}
|
|
906
|
+
function Ze(e, t) {
|
|
907
|
+
const n = V(["r", "c", "d", "d2", "d3", "d4"], e);
|
|
908
|
+
return `
|
|
909
|
+
ivec6 getOutputCoords() {
|
|
910
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
911
|
+
vec2(${t[0]}, ${t[1]}));
|
|
912
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
913
|
+
|
|
914
|
+
${n}
|
|
915
|
+
|
|
916
|
+
ivec6 result = ivec6(r, c, d, d2, d3, d4);
|
|
917
|
+
return result;
|
|
918
|
+
}
|
|
919
|
+
`;
|
|
920
|
+
}
|
|
921
|
+
function Qe(e, t, n) {
|
|
922
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
923
|
+
if (T(e, t))
|
|
924
|
+
return n ? `
|
|
925
|
+
ivec2 getOutputCoords() {
|
|
926
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
927
|
+
return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));
|
|
928
|
+
}
|
|
929
|
+
` : `
|
|
930
|
+
ivec2 getOutputCoords() {
|
|
931
|
+
return 2 * ivec2(resultUV.yx * vec2(${r[0]}, ${r[1]}));
|
|
932
|
+
}
|
|
933
|
+
`;
|
|
934
|
+
const o = Math.ceil(e[1] / 2);
|
|
935
|
+
return n ? `
|
|
936
|
+
ivec2 getOutputCoords() {
|
|
937
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
938
|
+
int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));
|
|
939
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
940
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
941
|
+
|
|
942
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
943
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
944
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
945
|
+
|
|
946
|
+
return ivec2(r, c);
|
|
947
|
+
}
|
|
948
|
+
` : `
|
|
949
|
+
ivec2 getOutputCoords() {
|
|
950
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
951
|
+
vec2(${r[0]}, ${r[1]}));
|
|
952
|
+
|
|
953
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
954
|
+
int r = 2 * (index / ${o});
|
|
955
|
+
int c = imod(index, ${o}) * 2;
|
|
956
|
+
|
|
957
|
+
return ivec2(r, c);
|
|
958
|
+
}
|
|
959
|
+
`;
|
|
960
|
+
}
|
|
961
|
+
function et(e, t, n) {
|
|
962
|
+
return T(e, t) ? n ? `
|
|
963
|
+
ivec2 getOutputCoords() {
|
|
964
|
+
return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
|
|
965
|
+
}
|
|
966
|
+
` : `
|
|
967
|
+
ivec2 getOutputCoords() {
|
|
968
|
+
return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
|
|
969
|
+
}
|
|
970
|
+
` : e[1] === 1 ? n ? `
|
|
971
|
+
ivec2 getOutputCoords() {
|
|
972
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
973
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
974
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
975
|
+
return ivec2(index, 0);
|
|
976
|
+
}
|
|
977
|
+
` : `
|
|
978
|
+
ivec2 getOutputCoords() {
|
|
979
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
980
|
+
vec2(${t[0]}, ${t[1]}));
|
|
981
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
982
|
+
return ivec2(index, 0);
|
|
983
|
+
}
|
|
984
|
+
` : e[0] === 1 ? n ? `
|
|
985
|
+
ivec2 getOutputCoords() {
|
|
986
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
987
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
988
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
989
|
+
return ivec2(0, index);
|
|
990
|
+
}
|
|
991
|
+
` : `
|
|
992
|
+
ivec2 getOutputCoords() {
|
|
993
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
994
|
+
vec2(${t[0]}, ${t[1]}));
|
|
995
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
996
|
+
return ivec2(0, index);
|
|
997
|
+
}
|
|
998
|
+
` : n ? `
|
|
999
|
+
ivec2 getOutputCoords() {
|
|
1000
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1001
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1002
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1003
|
+
int r = index / outShape[1];
|
|
1004
|
+
int c = index - r * outShape[1];
|
|
1005
|
+
return ivec2(r, c);
|
|
1006
|
+
}
|
|
1007
|
+
` : `
|
|
1008
|
+
ivec2 getOutputCoords() {
|
|
1009
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1010
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1011
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1012
|
+
int r = index / ${e[1]};
|
|
1013
|
+
int c = index - r * ${e[1]};
|
|
1014
|
+
return ivec2(r, c);
|
|
1015
|
+
}
|
|
1016
|
+
`;
|
|
1017
|
+
}
|
|
1018
|
+
function U(e) {
|
|
1019
|
+
return `offset${e}`;
|
|
1020
|
+
}
|
|
1021
|
+
function tt(e) {
|
|
1022
|
+
const t = e.name, n = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = L();
|
|
1023
|
+
return `
|
|
1024
|
+
vec4 ${n}() {
|
|
1025
|
+
return ${r.texture2D}(${t}, halfCR);
|
|
1026
|
+
}
|
|
1027
|
+
`;
|
|
1028
|
+
}
|
|
1029
|
+
function nt(e, t) {
|
|
1030
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1031
|
+
if (e.shapeInfo.isUniform)
|
|
1032
|
+
return `float ${r}() {return ${n};}`;
|
|
1033
|
+
const [o, i] = e.shapeInfo.texShape;
|
|
1034
|
+
if (o === 1 && i === 1)
|
|
1035
|
+
return `
|
|
1036
|
+
float ${r}() {
|
|
1037
|
+
return sampleTexture(${n}, halfCR);
|
|
1038
|
+
}
|
|
1039
|
+
`;
|
|
1040
|
+
const a = U(n);
|
|
1041
|
+
if (t)
|
|
1042
|
+
return `
|
|
1043
|
+
float ${r}() {
|
|
1044
|
+
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${a});
|
|
1045
|
+
return sampleTexture(${n}, uv);
|
|
1046
|
+
}
|
|
1047
|
+
`;
|
|
1048
|
+
const [s, c] = e.shapeInfo.texShape;
|
|
1049
|
+
return `
|
|
1050
|
+
float ${r}() {
|
|
1051
|
+
vec2 uv = uvFromFlat(${s}, ${c}, ${a});
|
|
1052
|
+
return sampleTexture(${n}, uv);
|
|
1053
|
+
}
|
|
1054
|
+
`;
|
|
1055
|
+
}
|
|
1056
|
+
function rt(e, t) {
|
|
1057
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = e.shapeInfo.texShape, i = L();
|
|
1058
|
+
if (t)
|
|
1059
|
+
return `
|
|
1060
|
+
vec4 ${r}(int index) {
|
|
1061
|
+
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
1062
|
+
vec2 uv = packedUVfrom1D(
|
|
1063
|
+
packedTexShape[0], packedTexShape[1], index);
|
|
1064
|
+
return ${i.texture2D}(${n}, uv);
|
|
1065
|
+
}
|
|
1066
|
+
`;
|
|
1067
|
+
const a = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
|
|
1068
|
+
return `
|
|
1069
|
+
vec4 ${r}(int index) {
|
|
1070
|
+
vec2 uv = packedUVfrom1D(
|
|
1071
|
+
${a[0]}, ${a[1]}, index);
|
|
1072
|
+
return ${i.texture2D}(${n}, uv);
|
|
1073
|
+
}
|
|
1074
|
+
`;
|
|
1075
|
+
}
|
|
1076
|
+
function ot(e, t) {
|
|
1077
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1078
|
+
if (e.shapeInfo.isUniform)
|
|
1079
|
+
return `
|
|
1080
|
+
float ${r}(int index) {
|
|
1081
|
+
${D(e)}
|
|
1082
|
+
}
|
|
1083
|
+
`;
|
|
1084
|
+
const o = e.shapeInfo.texShape, i = o[0], a = o[1];
|
|
1085
|
+
if (a === 1 && i === 1)
|
|
1086
|
+
return `
|
|
1087
|
+
float ${r}(int index) {
|
|
1088
|
+
return sampleTexture(${n}, halfCR);
|
|
1089
|
+
}
|
|
1090
|
+
`;
|
|
1091
|
+
const s = U(n);
|
|
1092
|
+
return a === 1 ? t ? `
|
|
1093
|
+
float ${r}(int index) {
|
|
1094
|
+
vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / float(${n}TexShape[0]));
|
|
1095
|
+
return sampleTexture(${n}, uv);
|
|
1096
|
+
}
|
|
1097
|
+
` : `
|
|
1098
|
+
float ${r}(int index) {
|
|
1099
|
+
vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / ${i}.0);
|
|
1100
|
+
return sampleTexture(${n}, uv);
|
|
1101
|
+
}
|
|
1102
|
+
` : i === 1 ? t ? `
|
|
1103
|
+
float ${r}(int index) {
|
|
1104
|
+
vec2 uv = vec2((float(index + ${s}) + 0.5) / float(${n}TexShape[1]), 0.5);
|
|
1105
|
+
return sampleTexture(${n}, uv);
|
|
1106
|
+
}
|
|
1107
|
+
` : `
|
|
1108
|
+
float ${r}(int index) {
|
|
1109
|
+
vec2 uv = vec2((float(index + ${s}) + 0.5) / ${a}.0, 0.5);
|
|
1110
|
+
return sampleTexture(${n}, uv);
|
|
1111
|
+
}
|
|
1112
|
+
` : t ? `
|
|
1113
|
+
float ${r}(int index) {
|
|
1114
|
+
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${s});
|
|
1115
|
+
return sampleTexture(${n}, uv);
|
|
1116
|
+
}
|
|
1117
|
+
` : `
|
|
1118
|
+
float ${r}(int index) {
|
|
1119
|
+
vec2 uv = uvFromFlat(${i}, ${a}, index + ${s});
|
|
1120
|
+
return sampleTexture(${n}, uv);
|
|
1121
|
+
}
|
|
1122
|
+
`;
|
|
1123
|
+
}
|
|
1124
|
+
function it(e, t) {
|
|
1125
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape, a = i[0], s = i[1], c = L();
|
|
1126
|
+
if (i != null && T(n, i))
|
|
1127
|
+
return t ? `
|
|
1128
|
+
vec4 ${o}(int row, int col) {
|
|
1129
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1130
|
+
|
|
1131
|
+
return ${c.texture2D}(${r}, uv);
|
|
1132
|
+
}
|
|
1133
|
+
` : `
|
|
1134
|
+
vec4 ${o}(int row, int col) {
|
|
1135
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${s}.0, ${a}.0);
|
|
1136
|
+
|
|
1137
|
+
return ${c.texture2D}(${r}, uv);
|
|
1138
|
+
}
|
|
1139
|
+
`;
|
|
1140
|
+
if (t)
|
|
1141
|
+
return `
|
|
1142
|
+
vec4 ${o}(int row, int col) {
|
|
1143
|
+
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1144
|
+
int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1145
|
+
vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
|
|
1146
|
+
return ${c.texture2D}(${r}, uv);
|
|
1147
|
+
}
|
|
1148
|
+
`;
|
|
1149
|
+
const u = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)], l = Math.ceil(n[1] / 2);
|
|
1150
|
+
return `
|
|
1151
|
+
vec4 ${o}(int row, int col) {
|
|
1152
|
+
vec2 uv = packedUVfrom2D(${l}, ${u[0]}, ${u[1]}, row, col);
|
|
1153
|
+
return ${c.texture2D}(${r}, uv);
|
|
1154
|
+
}
|
|
1155
|
+
`;
|
|
1156
|
+
}
|
|
1157
|
+
function at(e, t) {
|
|
1158
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape;
|
|
1159
|
+
if (i != null && T(n, i)) {
|
|
1160
|
+
if (t)
|
|
1161
|
+
return `
|
|
1162
|
+
float ${o}(int row, int col) {
|
|
1163
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1164
|
+
return sampleTexture(${r}, uv);
|
|
1165
|
+
}
|
|
1166
|
+
`;
|
|
1167
|
+
const d = i[0], h = i[1];
|
|
1168
|
+
return `
|
|
1169
|
+
float ${o}(int row, int col) {
|
|
1170
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${h}.0, ${d}.0);
|
|
1171
|
+
return sampleTexture(${r}, uv);
|
|
1172
|
+
}
|
|
1173
|
+
`;
|
|
1174
|
+
}
|
|
1175
|
+
const { newShape: a, keptDims: s } = I(n), c = a;
|
|
1176
|
+
if (c.length < n.length) {
|
|
1177
|
+
const d = y(e, c), h = ["row", "col"];
|
|
1178
|
+
return `
|
|
1179
|
+
${b(d, t)}
|
|
1180
|
+
float ${o}(int row, int col) {
|
|
1181
|
+
return ${o}(${M(h, s)});
|
|
1182
|
+
}
|
|
1183
|
+
`;
|
|
1184
|
+
}
|
|
1185
|
+
if (e.shapeInfo.isUniform)
|
|
1186
|
+
return `
|
|
1187
|
+
float ${o}(int row, int col) {
|
|
1188
|
+
int index = round(dot(vec2(row, col), vec2(${n[1]}, 1)));
|
|
1189
|
+
${D(e)}
|
|
1190
|
+
}
|
|
1191
|
+
`;
|
|
1192
|
+
const u = i[0], l = i[1], f = U(r);
|
|
1193
|
+
return l === 1 ? t ? `
|
|
1194
|
+
float ${o}(int row, int col) {
|
|
1195
|
+
float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
|
|
1196
|
+
vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
|
|
1197
|
+
return sampleTexture(${r}, uv);
|
|
1198
|
+
}
|
|
1199
|
+
` : `
|
|
1200
|
+
float ${o}(int row, int col) {
|
|
1201
|
+
float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
|
|
1202
|
+
vec2 uv = vec2(0.5, (index + 0.5) / ${u}.0);
|
|
1203
|
+
return sampleTexture(${r}, uv);
|
|
1204
|
+
}
|
|
1205
|
+
` : u === 1 ? t ? `
|
|
1206
|
+
float ${o}(int row, int col) {
|
|
1207
|
+
float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
|
|
1208
|
+
vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
|
|
1209
|
+
return sampleTexture(${r}, uv);
|
|
1210
|
+
}
|
|
1211
|
+
` : `
|
|
1212
|
+
float ${o}(int row, int col) {
|
|
1213
|
+
float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
|
|
1214
|
+
vec2 uv = vec2((index + 0.5) / ${l}.0, 0.5);
|
|
1215
|
+
return sampleTexture(${r}, uv);
|
|
1216
|
+
}
|
|
1217
|
+
` : t ? `
|
|
1218
|
+
float ${o}(int row, int col) {
|
|
1219
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1220
|
+
int index = row * ${r}Shape[1] + col + ${f};
|
|
1221
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
1222
|
+
return sampleTexture(${r}, uv);
|
|
1223
|
+
}
|
|
1224
|
+
` : `
|
|
1225
|
+
float ${o}(int row, int col) {
|
|
1226
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1227
|
+
int index = row * ${n[1]} + col + ${f};
|
|
1228
|
+
vec2 uv = uvFromFlat(${u}, ${l}, index);
|
|
1229
|
+
return sampleTexture(${r}, uv);
|
|
1230
|
+
}
|
|
1231
|
+
`;
|
|
1232
|
+
}
|
|
1233
|
+
function ct(e, t) {
|
|
1234
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape, a = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)];
|
|
1235
|
+
if (n[0] === 1) {
|
|
1236
|
+
const d = n.slice(1), h = [1, 2], x = y(e, d), p = ["b", "row", "col"];
|
|
1237
|
+
return `
|
|
1238
|
+
${le(x, t)}
|
|
1239
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1240
|
+
return ${o}(${M(p, h)});
|
|
1241
|
+
}
|
|
1242
|
+
`;
|
|
1243
|
+
}
|
|
1244
|
+
const s = L();
|
|
1245
|
+
if (t)
|
|
1246
|
+
return `
|
|
1247
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1248
|
+
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1249
|
+
int valuesPerRow = int(ceil(float(${r}Shape[2]) / 2.0));
|
|
1250
|
+
int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1251
|
+
vec2 uv = packedUVfrom3D(
|
|
1252
|
+
packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
|
|
1253
|
+
return ${s.texture2D}(${r}, uv);
|
|
1254
|
+
}
|
|
1255
|
+
`;
|
|
1256
|
+
const c = a[0], u = a[1], l = Math.ceil(n[2] / 2), f = l * Math.ceil(n[1] / 2);
|
|
1257
|
+
return `
|
|
1258
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1259
|
+
vec2 uv = packedUVfrom3D(
|
|
1260
|
+
${c}, ${u}, ${f}, ${l}, b, row, col);
|
|
1261
|
+
return ${s.texture2D}(${r}, uv);
|
|
1262
|
+
}
|
|
1263
|
+
`;
|
|
1264
|
+
}
|
|
1265
|
+
function st(e, t) {
|
|
1266
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = n[1] * n[2], a = n[2], { newShape: s, keptDims: c } = I(n), u = s;
|
|
1267
|
+
if (u.length < n.length) {
|
|
1268
|
+
const p = y(e, u), $ = ["row", "col", "depth"];
|
|
1269
|
+
return `
|
|
1270
|
+
${b(p, t)}
|
|
1271
|
+
float ${o}(int row, int col, int depth) {
|
|
1272
|
+
return ${o}(${M($, c)});
|
|
1273
|
+
}
|
|
1274
|
+
`;
|
|
1275
|
+
}
|
|
1276
|
+
if (e.shapeInfo.isUniform)
|
|
1277
|
+
return `
|
|
1278
|
+
float ${o}(int row, int col, int depth) {
|
|
1279
|
+
int index = round(dot(vec3(row, col, depth),
|
|
1280
|
+
vec3(${i}, ${a}, 1)));
|
|
1281
|
+
${D(e)}
|
|
1282
|
+
}
|
|
1283
|
+
`;
|
|
1284
|
+
const l = e.shapeInfo.texShape, f = l[0], d = l[1], h = e.shapeInfo.flatOffset;
|
|
1285
|
+
if (d === i && h == null)
|
|
1286
|
+
return t ? `
|
|
1287
|
+
float ${o}(int row, int col, int depth) {
|
|
1288
|
+
int stride1 = ${r}Shape[2];
|
|
1289
|
+
float texR = float(row);
|
|
1290
|
+
float texC = dot(vec2(col, depth), vec2(stride1, 1));
|
|
1291
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1292
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1293
|
+
return sampleTexture(${r}, uv);
|
|
1294
|
+
}
|
|
1295
|
+
` : `
|
|
1296
|
+
float ${o}(int row, int col, int depth) {
|
|
1297
|
+
float texR = float(row);
|
|
1298
|
+
float texC = dot(vec2(col, depth), vec2(${a}, 1));
|
|
1299
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1300
|
+
vec2(${d}.0, ${f}.0);
|
|
1301
|
+
return sampleTexture(${r}, uv);
|
|
1302
|
+
}
|
|
1303
|
+
`;
|
|
1304
|
+
if (d === a && h == null)
|
|
1305
|
+
return t ? `
|
|
1306
|
+
float ${o}(int row, int col, int depth) {
|
|
1307
|
+
float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
|
|
1308
|
+
float texC = float(depth);
|
|
1309
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1310
|
+
return sampleTexture(${r}, uv);
|
|
1311
|
+
}
|
|
1312
|
+
` : `
|
|
1313
|
+
float ${o}(int row, int col, int depth) {
|
|
1314
|
+
float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
|
|
1315
|
+
float texC = float(depth);
|
|
1316
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${d}.0, ${f}.0);
|
|
1317
|
+
return sampleTexture(${r}, uv);
|
|
1318
|
+
}
|
|
1319
|
+
`;
|
|
1320
|
+
const x = U(r);
|
|
1321
|
+
return t ? `
|
|
1322
|
+
float ${o}(int row, int col, int depth) {
|
|
1323
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1324
|
+
int stride0 = ${r}Shape[1] * ${r}Shape[2];
|
|
1325
|
+
int stride1 = ${r}Shape[2];
|
|
1326
|
+
int index = row * stride0 + col * stride1 + depth + ${x};
|
|
1327
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
1328
|
+
return sampleTexture(${r}, uv);
|
|
1329
|
+
}
|
|
1330
|
+
` : `
|
|
1331
|
+
float ${o}(int row, int col, int depth) {
|
|
1332
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1333
|
+
int index = row * ${i} + col * ${a} + depth + ${x};
|
|
1334
|
+
vec2 uv = uvFromFlat(${f}, ${d}, index);
|
|
1335
|
+
return sampleTexture(${r}, uv);
|
|
1336
|
+
}
|
|
1337
|
+
`;
|
|
1338
|
+
}
|
|
1339
|
+
function ut(e, t) {
|
|
1340
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = L();
|
|
1341
|
+
if (t)
|
|
1342
|
+
return `
|
|
1343
|
+
vec4 ${r}(int b2, int b, int row, int col) {
|
|
1344
|
+
int valuesPerRow = int(ceil(float(${n}Shape[3]) / 2.0));
|
|
1345
|
+
int texelsInBatch = valuesPerRow * int(ceil(float(${n}Shape[2]) / 2.0));
|
|
1346
|
+
int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
|
|
1347
|
+
texelsInBatch *= ${n}Shape[1];
|
|
1348
|
+
index = b2 * texelsInBatch + index;
|
|
1349
|
+
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
1350
|
+
int texR = index / packedTexShape[1];
|
|
1351
|
+
int texC = index - texR * packedTexShape[1];
|
|
1352
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${o.texture2D}(${n}, uv);
|
|
1353
|
+
}
|
|
1354
|
+
`;
|
|
1355
|
+
const i = e.shapeInfo.logicalShape, a = i.length, s = e.shapeInfo.texShape, c = [Math.ceil(s[0] / 2), Math.ceil(s[1] / 2)], u = c[0], l = c[1], f = Math.ceil(i[a - 1] / 2);
|
|
1356
|
+
let d = f * Math.ceil(i[a - 2] / 2), h = "int b, int row, int col", x = `b * ${d} + (row / 2) * ${f} + (col / 2)`;
|
|
1357
|
+
for (let p = 2; p < a - 1; p++)
|
|
1358
|
+
h = `int b${p}, ` + h, d *= i[a - p - 1], x = `b${p} * ${d} + ` + x;
|
|
1359
|
+
return `
|
|
1360
|
+
vec4 ${r}(${h}) {
|
|
1361
|
+
int index = ${x};
|
|
1362
|
+
int texR = index / ${l};
|
|
1363
|
+
int texC = index - texR * ${l};
|
|
1364
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${l}, ${u});
|
|
1365
|
+
return ${o.texture2D}(${n}, uv);
|
|
1366
|
+
}
|
|
1367
|
+
`;
|
|
1368
|
+
}
|
|
1369
|
+
function lt(e, t) {
|
|
1370
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = n[3], a = n[2] * i, s = n[1] * a, { newShape: c, keptDims: u } = I(n);
|
|
1371
|
+
if (c.length < n.length) {
|
|
1372
|
+
const R = y(e, c), w = ["row", "col", "depth", "depth2"];
|
|
1373
|
+
return `
|
|
1374
|
+
${b(R, t)}
|
|
1375
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1376
|
+
return ${o}(${M(w, u)});
|
|
1377
|
+
}
|
|
1378
|
+
`;
|
|
1379
|
+
}
|
|
1380
|
+
if (e.shapeInfo.isUniform)
|
|
1381
|
+
return `
|
|
1382
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1383
|
+
int index = round(dot(vec4(row, col, depth, depth2),
|
|
1384
|
+
vec4(${s}, ${a}, ${i}, 1)));
|
|
1385
|
+
${D(e)}
|
|
1386
|
+
}
|
|
1387
|
+
`;
|
|
1388
|
+
const l = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], h = f[1], x = `int stride2 = ${r}Shape[3];`, p = `int stride1 = ${r}Shape[2] * stride2;`, $ = `int stride0 = ${r}Shape[1] * stride1;`;
|
|
1389
|
+
if (h === s && l == null)
|
|
1390
|
+
return t ? `
|
|
1391
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1392
|
+
${x}
|
|
1393
|
+
${p}
|
|
1394
|
+
float texR = float(row);
|
|
1395
|
+
float texC =
|
|
1396
|
+
dot(vec3(col, depth, depth2),
|
|
1397
|
+
vec3(stride1, stride2, 1));
|
|
1398
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1399
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1400
|
+
return sampleTexture(${r}, uv);
|
|
1401
|
+
}
|
|
1402
|
+
` : `
|
|
1403
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1404
|
+
float texR = float(row);
|
|
1405
|
+
float texC =
|
|
1406
|
+
dot(vec3(col, depth, depth2),
|
|
1407
|
+
vec3(${a}, ${i}, 1));
|
|
1408
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1409
|
+
vec2(${h}.0, ${d}.0);
|
|
1410
|
+
return sampleTexture(${r}, uv);
|
|
1411
|
+
}
|
|
1412
|
+
`;
|
|
1413
|
+
if (h === i && l == null)
|
|
1414
|
+
return t ? `
|
|
1415
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1416
|
+
float texR = dot(vec3(row, col, depth),
|
|
1417
|
+
vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
|
|
1418
|
+
float texC = float(depth2);
|
|
1419
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1420
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1421
|
+
return sampleTexture(${r}, uv);
|
|
1422
|
+
}
|
|
1423
|
+
` : `
|
|
1424
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1425
|
+
float texR = dot(vec3(row, col, depth),
|
|
1426
|
+
vec3(${n[1] * n[2]}, ${n[2]}, 1));
|
|
1427
|
+
float texC = float(depth2);
|
|
1428
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1429
|
+
vec2(${h}.0, ${d}.0);
|
|
1430
|
+
return sampleTexture(${r}, uv);
|
|
1431
|
+
}
|
|
1432
|
+
`;
|
|
1433
|
+
const S = U(r);
|
|
1434
|
+
return t ? `
|
|
1435
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1436
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1437
|
+
${x}
|
|
1438
|
+
${p}
|
|
1439
|
+
${$}
|
|
1440
|
+
int index = row * stride0 + col * stride1 +
|
|
1441
|
+
depth * stride2 + depth2;
|
|
1442
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${S});
|
|
1443
|
+
return sampleTexture(${r}, uv);
|
|
1444
|
+
}
|
|
1445
|
+
` : `
|
|
1446
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
1447
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1448
|
+
int index = row * ${s} + col * ${a} +
|
|
1449
|
+
depth * ${i} + depth2;
|
|
1450
|
+
vec2 uv = uvFromFlat(${d}, ${h}, index + ${S});
|
|
1451
|
+
return sampleTexture(${r}, uv);
|
|
1452
|
+
}
|
|
1453
|
+
`;
|
|
1454
|
+
}
|
|
1455
|
+
function ft(e) {
|
|
1456
|
+
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = t[4], i = t[3] * o, a = t[2] * i, s = t[1] * a, { newShape: c, keptDims: u } = I(t);
|
|
1457
|
+
if (c.length < t.length) {
|
|
1458
|
+
const p = y(e, c), $ = ["row", "col", "depth", "depth2", "depth3"];
|
|
1459
|
+
return `
|
|
1460
|
+
${b(p)}
|
|
1461
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1462
|
+
return ${r}(${M($, u)});
|
|
1463
|
+
}
|
|
1464
|
+
`;
|
|
1465
|
+
}
|
|
1466
|
+
if (e.shapeInfo.isUniform)
|
|
1467
|
+
return `
|
|
1468
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1469
|
+
float index = dot(
|
|
1470
|
+
vec4(row, col, depth, depth2),
|
|
1471
|
+
vec4(${s}, ${a}, ${i}, ${o})) +
|
|
1472
|
+
depth3;
|
|
1473
|
+
${D(e)}
|
|
1474
|
+
}
|
|
1475
|
+
`;
|
|
1476
|
+
const l = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], h = f[1];
|
|
1477
|
+
if (h === s && l == null)
|
|
1478
|
+
return `
|
|
1479
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1480
|
+
int texR = row;
|
|
1481
|
+
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
1482
|
+
vec4(${a}, ${i}, ${o}, 1));
|
|
1483
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1484
|
+
vec2(${h}.0, ${d}.0);
|
|
1485
|
+
return sampleTexture(${n}, uv);
|
|
1486
|
+
}
|
|
1487
|
+
`;
|
|
1488
|
+
if (h === o && l == null)
|
|
1489
|
+
return `
|
|
1490
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1491
|
+
float texR = dot(
|
|
1492
|
+
vec4(row, col, depth, depth2),
|
|
1493
|
+
vec4(${t[1] * t[2] * t[3]},
|
|
1494
|
+
${t[2] * t[3]}, ${t[3]}, 1));
|
|
1495
|
+
int texC = depth3;
|
|
1496
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1497
|
+
vec2(${h}.0, ${d}.0);
|
|
1498
|
+
return sampleTexture(${n}, uv);
|
|
1499
|
+
}
|
|
1500
|
+
`;
|
|
1501
|
+
const x = U(n);
|
|
1502
|
+
return `
|
|
1503
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1504
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1505
|
+
int index = row * ${s} + col * ${a} + depth * ${i} +
|
|
1506
|
+
depth2 * ${o} + depth3 + ${x};
|
|
1507
|
+
vec2 uv = uvFromFlat(${d}, ${h}, index);
|
|
1508
|
+
return sampleTexture(${n}, uv);
|
|
1509
|
+
}
|
|
1510
|
+
`;
|
|
1511
|
+
}
|
|
1512
|
+
function ht(e) {
|
|
1513
|
+
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: o, keptDims: i } = I(t);
|
|
1514
|
+
if (o.length < t.length) {
|
|
1515
|
+
const $ = y(e, o), S = ["row", "col", "depth", "depth2", "depth3", "depth4"];
|
|
1516
|
+
return `
|
|
1517
|
+
${b($)}
|
|
1518
|
+
float ${r}(int row, int col, int depth,
|
|
1519
|
+
int depth2, int depth3, int depth4) {
|
|
1520
|
+
return ${r}(${M(S, i)});
|
|
1521
|
+
}
|
|
1522
|
+
`;
|
|
1523
|
+
}
|
|
1524
|
+
const a = t[5], s = t[4] * a, c = t[3] * s, u = t[2] * c, l = t[1] * u;
|
|
1525
|
+
if (e.shapeInfo.isUniform)
|
|
1526
|
+
return `
|
|
1527
|
+
float ${r}(int row, int col, int depth,
|
|
1528
|
+
int depth2, int depth3, int depth4) {
|
|
1529
|
+
int index = round(dot(
|
|
1530
|
+
vec4(row, col, depth, depth2),
|
|
1531
|
+
vec4(${l}, ${u}, ${c}, ${s})) +
|
|
1532
|
+
dot(
|
|
1533
|
+
vec2(depth3, depth4),
|
|
1534
|
+
vec2(${a}, 1)));
|
|
1535
|
+
${D(e)}
|
|
1536
|
+
}
|
|
1537
|
+
`;
|
|
1538
|
+
const f = e.shapeInfo.flatOffset, d = e.shapeInfo.texShape, h = d[0], x = d[1];
|
|
1539
|
+
if (x === l && f == null)
|
|
1540
|
+
return `
|
|
1541
|
+
float ${r}(int row, int col, int depth,
|
|
1542
|
+
int depth2, int depth3, int depth4) {
|
|
1543
|
+
int texR = row;
|
|
1544
|
+
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
1545
|
+
vec4(${u}, ${c}, ${s}, ${a})) +
|
|
1546
|
+
float(depth4);
|
|
1547
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1548
|
+
vec2(${x}.0, ${h}.0);
|
|
1549
|
+
return sampleTexture(${n}, uv);
|
|
1550
|
+
}
|
|
1551
|
+
`;
|
|
1552
|
+
if (x === a && f == null)
|
|
1553
|
+
return `
|
|
1554
|
+
float ${r}(int row, int col, int depth,
|
|
1555
|
+
int depth2, int depth3, int depth4) {
|
|
1556
|
+
float texR = dot(vec4(row, col, depth, depth2),
|
|
1557
|
+
vec4(${t[1] * t[2] * t[3] * t[4]},
|
|
1558
|
+
${t[2] * t[3] * t[4]},
|
|
1559
|
+
${t[3] * t[4]},
|
|
1560
|
+
${t[4]})) + float(depth3);
|
|
1561
|
+
int texC = depth4;
|
|
1562
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1563
|
+
vec2(${x}.0, ${h}.0);
|
|
1564
|
+
return sampleTexture(${n}, uv);
|
|
1565
|
+
}
|
|
1566
|
+
`;
|
|
1567
|
+
const p = U(n);
|
|
1568
|
+
return `
|
|
1569
|
+
float ${r}(int row, int col, int depth,
|
|
1570
|
+
int depth2, int depth3, int depth4) {
|
|
1571
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1572
|
+
int index = row * ${l} + col * ${u} + depth * ${c} +
|
|
1573
|
+
depth2 * ${s} + depth3 * ${a} + depth4 + ${p};
|
|
1574
|
+
vec2 uv = uvFromFlat(${h}, ${x}, index);
|
|
1575
|
+
return sampleTexture(${n}, uv);
|
|
1576
|
+
}
|
|
1577
|
+
`;
|
|
1578
|
+
}
|
|
1579
|
+
function D(e) {
|
|
1580
|
+
const t = e.name, n = E(e.shapeInfo.logicalShape);
|
|
1581
|
+
return n < 2 ? `return ${t};` : `
|
|
1582
|
+
for (int i = 0; i < ${n}; i++) {
|
|
1583
|
+
if (i == index) {
|
|
1584
|
+
return ${t}[i];
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
`;
|
|
1588
|
+
}
|
|
1589
|
+
function dt(e, t) {
|
|
1590
|
+
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", i = e.shapeInfo.logicalShape.length, a = t.logicalShape.length, s = ue(e.shapeInfo.logicalShape, t.logicalShape), c = he(a), u = a - i;
|
|
1591
|
+
let l;
|
|
1592
|
+
const f = ["x", "y", "z", "w", "u", "v"];
|
|
1593
|
+
i === 0 ? l = "" : a < 2 && s.length >= 1 ? l = "coords = 0;" : l = s.map((R) => `coords.${f[R + u]} = 0;`).join(`
|
|
1594
|
+
`);
|
|
1595
|
+
let d = "";
|
|
1596
|
+
a < 2 && i > 0 ? d = "coords" : d = e.shapeInfo.logicalShape.map((R, w) => `coords.${f[w + u]}`).join(", ");
|
|
1597
|
+
let h = "return outputValue;";
|
|
1598
|
+
const p = E(e.shapeInfo.logicalShape) === 1, S = E(t.logicalShape) === 1;
|
|
1599
|
+
if (i === 1 && !p && !S)
|
|
1600
|
+
h = `
|
|
1601
|
+
return vec4(outputValue.xy, outputValue.xy);
|
|
1602
|
+
`;
|
|
1603
|
+
else if (p && !S)
|
|
1604
|
+
a === 1 ? h = `
|
|
1605
|
+
return vec4(outputValue.x, outputValue.x, 0., 0.);
|
|
1606
|
+
` : h = `
|
|
1607
|
+
return vec4(outputValue.x);
|
|
1608
|
+
`;
|
|
1609
|
+
else if (s.length) {
|
|
1610
|
+
const R = i - 2, w = i - 1;
|
|
1611
|
+
s.indexOf(R) > -1 && s.indexOf(w) > -1 ? h = "return vec4(outputValue.x);" : s.indexOf(R) > -1 ? h = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : s.indexOf(w) > -1 && (h = "return vec4(outputValue.xx, outputValue.zz);");
|
|
1612
|
+
}
|
|
1613
|
+
return `
|
|
1614
|
+
vec4 ${o}() {
|
|
1615
|
+
${c} coords = getOutputCoords();
|
|
1616
|
+
${l}
|
|
1617
|
+
vec4 outputValue = get${r}(${d});
|
|
1618
|
+
${h}
|
|
1619
|
+
}
|
|
1620
|
+
`;
|
|
1621
|
+
}
|
|
1622
|
+
function xt(e, t) {
|
|
1623
|
+
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", i = t.texShape, a = e.shapeInfo.texShape, s = e.shapeInfo.logicalShape.length, c = t.logicalShape.length;
|
|
1624
|
+
if (!e.shapeInfo.isUniform && s === c && e.shapeInfo.flatOffset == null && T(a, i))
|
|
1625
|
+
return `
|
|
1626
|
+
float ${o}() {
|
|
1627
|
+
return sampleTexture(${n}, resultUV);
|
|
1628
|
+
}
|
|
1629
|
+
`;
|
|
1630
|
+
const u = he(c), l = ue(e.shapeInfo.logicalShape, t.logicalShape), f = c - s;
|
|
1631
|
+
let d;
|
|
1632
|
+
const h = ["x", "y", "z", "w", "u", "v"];
|
|
1633
|
+
s === 0 ? d = "" : c < 2 && l.length >= 1 ? d = "coords = 0;" : d = l.map((p) => `coords.${h[p + f]} = 0;`).join(`
|
|
1634
|
+
`);
|
|
1635
|
+
let x = "";
|
|
1636
|
+
return c < 2 && s > 0 ? x = "coords" : x = e.shapeInfo.logicalShape.map((p, $) => `coords.${h[$ + f]}`).join(", "), `
|
|
1637
|
+
float ${o}() {
|
|
1638
|
+
${u} coords = getOutputCoords();
|
|
1639
|
+
${d}
|
|
1640
|
+
return get${r}(${x});
|
|
1641
|
+
}
|
|
1642
|
+
`;
|
|
1643
|
+
}
|
|
1644
|
+
function he(e) {
|
|
1645
|
+
if (e <= 1)
|
|
1646
|
+
return "int";
|
|
1647
|
+
if (e === 2)
|
|
1648
|
+
return "ivec2";
|
|
1649
|
+
if (e === 3)
|
|
1650
|
+
return "ivec3";
|
|
1651
|
+
if (e === 4)
|
|
1652
|
+
return "ivec4";
|
|
1653
|
+
if (e === 5)
|
|
1654
|
+
return "ivec5";
|
|
1655
|
+
if (e === 6)
|
|
1656
|
+
return "ivec6";
|
|
1657
|
+
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
1658
|
+
}
|
|
1659
|
+
function j(e, t, n) {
|
|
1660
|
+
const { newShape: r, keptDims: o } = I(t), i = t.length, a = e && i === 3 && t[0] === 1, s = a ? t.slice(1) : r, c = !e && i > 1 && !T(t, n) && r.length < i || a;
|
|
1661
|
+
return { useSqueezeShape: c, uniformShape: c ? s : t, keptDims: o };
|
|
1662
|
+
}
|
|
1663
|
+
function y(e, t) {
|
|
1664
|
+
const n = JSON.parse(JSON.stringify(e));
|
|
1665
|
+
return n.shapeInfo.logicalShape = t, n;
|
|
1666
|
+
}
|
|
1667
|
+
function M(e, t) {
|
|
1668
|
+
return t.map((n) => e[n]).join(", ");
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* @license
|
|
1672
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
1673
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1674
|
+
* you may not use this file except in compliance with the License.
|
|
1675
|
+
* You may obtain a copy of the License at
|
|
1676
|
+
*
|
|
1677
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1678
|
+
*
|
|
1679
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1680
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1681
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1682
|
+
* See the License for the specific language governing permissions and
|
|
1683
|
+
* limitations under the License.
|
|
1684
|
+
* =============================================================================
|
|
1685
|
+
*/
|
|
1686
|
+
const _ = {}, k = {
|
|
1687
|
+
alpha: !1,
|
|
1688
|
+
antialias: !1,
|
|
1689
|
+
premultipliedAlpha: !1,
|
|
1690
|
+
preserveDrawingBuffer: !1,
|
|
1691
|
+
depth: !1,
|
|
1692
|
+
stencil: !1,
|
|
1693
|
+
failIfMajorPerformanceCaveat: !0
|
|
1694
|
+
};
|
|
1695
|
+
function Mt(e, t) {
|
|
1696
|
+
_[e] = t;
|
|
1697
|
+
}
|
|
1698
|
+
function A(e, t) {
|
|
1699
|
+
if (!(e in _) || t != null) {
|
|
1700
|
+
const r = vt(e, t);
|
|
1701
|
+
if (r !== null)
|
|
1702
|
+
_[e] = r;
|
|
1703
|
+
else
|
|
1704
|
+
return console.log("Could not get context for WebGL version", e), null;
|
|
1705
|
+
}
|
|
1706
|
+
const n = _[e];
|
|
1707
|
+
return n == null || n.isContextLost() ? (delete _[e], A(e)) : (n.disable(n.DEPTH_TEST), n.disable(n.STENCIL_TEST), n.disable(n.BLEND), n.disable(n.DITHER), n.disable(n.POLYGON_OFFSET_FILL), n.disable(n.SAMPLE_COVERAGE), n.enable(n.SCISSOR_TEST), n.enable(n.CULL_FACE), n.cullFace(n.BACK), _[e]);
|
|
1708
|
+
}
|
|
1709
|
+
function pt(e) {
|
|
1710
|
+
if (!v().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2)
|
|
1711
|
+
return new OffscreenCanvas(300, 150);
|
|
1712
|
+
if (typeof document < "u")
|
|
1713
|
+
return document.createElement("canvas");
|
|
1714
|
+
throw new Error("Cannot create a canvas in this context");
|
|
1715
|
+
}
|
|
1716
|
+
function vt(e, t) {
|
|
1717
|
+
if (e !== 1 && e !== 2)
|
|
1718
|
+
throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
|
|
1719
|
+
const n = t ?? pt(e);
|
|
1720
|
+
return n.addEventListener("webglcontextlost", (r) => {
|
|
1721
|
+
r.preventDefault(), delete _[e];
|
|
1722
|
+
}, !1), v().getBool("SOFTWARE_WEBGL_ENABLED") && (k.failIfMajorPerformanceCaveat = !1), e === 1 ? (
|
|
1723
|
+
// tslint:disable-next-line
|
|
1724
|
+
n.getContext("webgl", k) || n.getContext("experimental-webgl", k)
|
|
1725
|
+
) : n.getContext("webgl2", k);
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* @license
|
|
1729
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
1730
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1731
|
+
* you may not use this file except in compliance with the License.
|
|
1732
|
+
* You may obtain a copy of the License at
|
|
1733
|
+
*
|
|
1734
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1735
|
+
*
|
|
1736
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1737
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1738
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1739
|
+
* See the License for the specific language governing permissions and
|
|
1740
|
+
* limitations under the License.
|
|
1741
|
+
* =============================================================================
|
|
1742
|
+
*/
|
|
1743
|
+
var ee;
|
|
1744
|
+
(function(e) {
|
|
1745
|
+
e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
|
|
1746
|
+
})(ee || (ee = {}));
|
|
1747
|
+
var te;
|
|
1748
|
+
(function(e) {
|
|
1749
|
+
e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
|
|
1750
|
+
})(te || (te = {}));
|
|
1751
|
+
var ne;
|
|
1752
|
+
(function(e) {
|
|
1753
|
+
e[e.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", e[e.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", e[e.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", e[e.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", e[e.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
|
|
1754
|
+
})(ne || (ne = {}));
|
|
1755
|
+
function Bt(e, t) {
|
|
1756
|
+
return [t, e];
|
|
1757
|
+
}
|
|
1758
|
+
function kt(e, t) {
|
|
1759
|
+
return e * t;
|
|
1760
|
+
}
|
|
1761
|
+
function Pt(e) {
|
|
1762
|
+
const t = E(e), n = Math.ceil(t / 4);
|
|
1763
|
+
return H(n);
|
|
1764
|
+
}
|
|
1765
|
+
function mt(e, t) {
|
|
1766
|
+
return [
|
|
1767
|
+
Math.max(1, Math.ceil(t / 2)),
|
|
1768
|
+
Math.max(1, Math.ceil(e / 2))
|
|
1769
|
+
];
|
|
1770
|
+
}
|
|
1771
|
+
function Vt(e, t) {
|
|
1772
|
+
const [n, r] = mt(e, t);
|
|
1773
|
+
return n * r * 4;
|
|
1774
|
+
}
|
|
1775
|
+
function de(e, t) {
|
|
1776
|
+
const n = e;
|
|
1777
|
+
let r, o, i, a, s, c, u, l, f, d;
|
|
1778
|
+
return v().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, o = n.R16F, i = n.RGBA16F, a = n.RGBA32F, s = n.RED, u = 4, l = 1, f = n.HALF_FLOAT, d = n.FLOAT, c = n.RGBA8) : (r = e.RGBA, o = e.RGBA, i = e.RGBA, a = n.RGBA, s = e.RGBA, u = 4, l = 4, f = t != null ? t.HALF_FLOAT_OES : null, d = e.FLOAT, c = e.RGBA), {
|
|
1779
|
+
internalFormatFloat: r,
|
|
1780
|
+
internalFormatHalfFloat: o,
|
|
1781
|
+
internalFormatPackedHalfFloat: i,
|
|
1782
|
+
internalFormatPackedFloat: a,
|
|
1783
|
+
textureFormatFloat: s,
|
|
1784
|
+
downloadTextureFormat: c,
|
|
1785
|
+
downloadUnpackNumChannels: u,
|
|
1786
|
+
defaultNumChannels: l,
|
|
1787
|
+
textureTypeHalfFloat: f,
|
|
1788
|
+
textureTypeFloat: d
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* @license
|
|
1793
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
1794
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1795
|
+
* you may not use this file except in compliance with the License.
|
|
1796
|
+
* You may obtain a copy of the License at
|
|
1797
|
+
*
|
|
1798
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1799
|
+
*
|
|
1800
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1801
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1802
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1803
|
+
* See the License for the specific language governing permissions and
|
|
1804
|
+
* limitations under the License.
|
|
1805
|
+
* =============================================================================
|
|
1806
|
+
*/
|
|
1807
|
+
function m(e, t) {
|
|
1808
|
+
const n = t();
|
|
1809
|
+
return v().getBool("DEBUG") && $t(e), n;
|
|
1810
|
+
}
|
|
1811
|
+
function $t(e) {
|
|
1812
|
+
const t = e.getError();
|
|
1813
|
+
if (t !== e.NO_ERROR)
|
|
1814
|
+
throw new Error("WebGL Error: " + Rt(e, t));
|
|
1815
|
+
}
|
|
1816
|
+
const Tt = 596e-10, St = 65504;
|
|
1817
|
+
function Wt(e) {
|
|
1818
|
+
return !!(v().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || Tt < Math.abs(e) && Math.abs(e) < St);
|
|
1819
|
+
}
|
|
1820
|
+
function Rt(e, t) {
|
|
1821
|
+
switch (t) {
|
|
1822
|
+
case e.NO_ERROR:
|
|
1823
|
+
return "NO_ERROR";
|
|
1824
|
+
case e.INVALID_ENUM:
|
|
1825
|
+
return "INVALID_ENUM";
|
|
1826
|
+
case e.INVALID_VALUE:
|
|
1827
|
+
return "INVALID_VALUE";
|
|
1828
|
+
case e.INVALID_OPERATION:
|
|
1829
|
+
return "INVALID_OPERATION";
|
|
1830
|
+
case e.INVALID_FRAMEBUFFER_OPERATION:
|
|
1831
|
+
return "INVALID_FRAMEBUFFER_OPERATION";
|
|
1832
|
+
case e.OUT_OF_MEMORY:
|
|
1833
|
+
return "OUT_OF_MEMORY";
|
|
1834
|
+
case e.CONTEXT_LOST_WEBGL:
|
|
1835
|
+
return "CONTEXT_LOST_WEBGL";
|
|
1836
|
+
default:
|
|
1837
|
+
return `Unknown error code ${t}`;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
function Xt(e, t) {
|
|
1841
|
+
return C(e, () => e.getExtension(t), 'Extension "' + t + '" not supported on this browser.');
|
|
1842
|
+
}
|
|
1843
|
+
function Ht(e, t) {
|
|
1844
|
+
const n = C(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
|
|
1845
|
+
if (m(e, () => e.shaderSource(n, t)), m(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
1846
|
+
throw console.log(e.getShaderInfoLog(n)), new Error("Failed to compile vertex shader.");
|
|
1847
|
+
return n;
|
|
1848
|
+
}
|
|
1849
|
+
function Et(e, t) {
|
|
1850
|
+
const n = C(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
|
|
1851
|
+
if (m(e, () => e.shaderSource(n, t)), m(e, () => e.compileShader(n)), v().get("ENGINE_COMPILE_ONLY"))
|
|
1852
|
+
return n;
|
|
1853
|
+
if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
1854
|
+
throw wt(t, e.getShaderInfoLog(n)), new Error("Failed to compile fragment shader.");
|
|
1855
|
+
return n;
|
|
1856
|
+
}
|
|
1857
|
+
const Ct = /ERROR: [0-9]+:([0-9]+):/g;
|
|
1858
|
+
function wt(e, t) {
|
|
1859
|
+
const n = Ct.exec(t);
|
|
1860
|
+
if (n == null) {
|
|
1861
|
+
console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
const r = +n[1], o = e.split(`
|
|
1865
|
+
`), i = o.length.toString().length + 2, a = o.map((f, d) => Y((d + 1).toString(), i) + f);
|
|
1866
|
+
let s = 0;
|
|
1867
|
+
for (let f = 0; f < a.length; f++)
|
|
1868
|
+
s = Math.max(a[f].length, s);
|
|
1869
|
+
const c = a.slice(0, r - 1), u = a.slice(r - 1, r), l = a.slice(r);
|
|
1870
|
+
console.log(c.join(`
|
|
1871
|
+
`)), console.log(t.split(`
|
|
1872
|
+
`)[0]), console.log(`%c ${Y(u[0], s)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(l.join(`
|
|
1873
|
+
`));
|
|
1874
|
+
}
|
|
1875
|
+
function Gt(e) {
|
|
1876
|
+
return C(e, () => e.createProgram(), "Unable to create WebGLProgram.");
|
|
1877
|
+
}
|
|
1878
|
+
function zt(e, t) {
|
|
1879
|
+
if (m(e, () => e.linkProgram(t)), !v().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1)
|
|
1880
|
+
throw console.log(e.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
|
|
1881
|
+
}
|
|
1882
|
+
function qt(e, t) {
|
|
1883
|
+
if (m(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1)
|
|
1884
|
+
throw console.log(e.getProgramInfoLog(t)), new Error("Shader program validation failed.");
|
|
1885
|
+
}
|
|
1886
|
+
function jt(e, t) {
|
|
1887
|
+
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
1888
|
+
return m(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), m(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
1889
|
+
}
|
|
1890
|
+
function Jt(e, t) {
|
|
1891
|
+
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
1892
|
+
return m(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), m(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
1893
|
+
}
|
|
1894
|
+
function Yt(e) {
|
|
1895
|
+
return C(e, () => e.createTexture(), "Unable to create WebGLTexture.");
|
|
1896
|
+
}
|
|
1897
|
+
function Kt(e, t) {
|
|
1898
|
+
const n = v().getNumber("WEBGL_MAX_TEXTURE_SIZE");
|
|
1899
|
+
if (e <= 0 || t <= 0) {
|
|
1900
|
+
const r = `[${e}x${t}]`;
|
|
1901
|
+
throw new Error("Requested texture size " + r + " is invalid.");
|
|
1902
|
+
}
|
|
1903
|
+
if (e > n || t > n) {
|
|
1904
|
+
const r = `[${e}x${t}]`, o = `[${n}x${n}]`;
|
|
1905
|
+
throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + o + ".");
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
function Zt(e) {
|
|
1909
|
+
return C(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
|
|
1910
|
+
}
|
|
1911
|
+
function Qt(e, t, n, r, o, i, a) {
|
|
1912
|
+
const s = e.getAttribLocation(t, n);
|
|
1913
|
+
return s === -1 ? !1 : (m(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), m(e, () => e.vertexAttribPointer(s, o, e.FLOAT, !1, i, a)), m(e, () => e.enableVertexAttribArray(s)), !0);
|
|
1914
|
+
}
|
|
1915
|
+
function Ft(e, t, n) {
|
|
1916
|
+
At(e, n), m(e, () => e.activeTexture(e.TEXTURE0 + n)), m(e, () => e.bindTexture(e.TEXTURE_2D, t));
|
|
1917
|
+
}
|
|
1918
|
+
function en(e, t, n) {
|
|
1919
|
+
return C(e, () => e.getUniformLocation(t, n), 'uniform "' + n + '" not present in program.');
|
|
1920
|
+
}
|
|
1921
|
+
function tn(e, t, n) {
|
|
1922
|
+
return e.getUniformLocation(t, n);
|
|
1923
|
+
}
|
|
1924
|
+
function nn(e, t, n, r) {
|
|
1925
|
+
m(e, () => Ft(e, t, r)), m(e, () => e.uniform1i(n, r));
|
|
1926
|
+
}
|
|
1927
|
+
function rn(e, t, n) {
|
|
1928
|
+
m(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), m(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
|
|
1929
|
+
}
|
|
1930
|
+
function on(e, t) {
|
|
1931
|
+
m(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), m(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
|
|
1932
|
+
}
|
|
1933
|
+
function an(e) {
|
|
1934
|
+
const t = e.checkFramebufferStatus(e.FRAMEBUFFER);
|
|
1935
|
+
if (t !== e.FRAMEBUFFER_COMPLETE)
|
|
1936
|
+
throw new Error("Error binding framebuffer: " + gt(e, t));
|
|
1937
|
+
}
|
|
1938
|
+
function gt(e, t) {
|
|
1939
|
+
switch (t) {
|
|
1940
|
+
case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
|
1941
|
+
return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
|
1942
|
+
case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
|
1943
|
+
return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
|
1944
|
+
case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
|
1945
|
+
return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
|
|
1946
|
+
case e.FRAMEBUFFER_UNSUPPORTED:
|
|
1947
|
+
return "FRAMEBUFFER_UNSUPPORTED";
|
|
1948
|
+
default:
|
|
1949
|
+
return `unknown error ${t}`;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function C(e, t, n) {
|
|
1953
|
+
const r = m(e, () => t());
|
|
1954
|
+
if (r == null)
|
|
1955
|
+
throw new Error(n);
|
|
1956
|
+
return r;
|
|
1957
|
+
}
|
|
1958
|
+
function At(e, t) {
|
|
1959
|
+
const n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
|
|
1960
|
+
if (r < e.TEXTURE0 || r > n) {
|
|
1961
|
+
const o = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
|
|
1962
|
+
throw new Error(`textureUnit must be in ${o}.`);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
function xe(e, t = 2) {
|
|
1966
|
+
return E(e.slice(0, e.length - t));
|
|
1967
|
+
}
|
|
1968
|
+
function pe(e) {
|
|
1969
|
+
if (e.length === 0)
|
|
1970
|
+
throw Error("Cannot get rows and columns of an empty shape array.");
|
|
1971
|
+
return [
|
|
1972
|
+
e.length > 1 ? e[e.length - 2] : 1,
|
|
1973
|
+
e[e.length - 1]
|
|
1974
|
+
];
|
|
1975
|
+
}
|
|
1976
|
+
function cn(e) {
|
|
1977
|
+
let t = [1, 1, 1];
|
|
1978
|
+
return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [xe(e), ...pe(e)]), t;
|
|
1979
|
+
}
|
|
1980
|
+
function sn(e, t = !1) {
|
|
1981
|
+
let n = v().getNumber("WEBGL_MAX_TEXTURE_SIZE"), r = v().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
|
|
1982
|
+
r === 1 / 0 && v().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (r = n / 2), t && (n = n * 2, r = r * 2, e = e.map((s, c) => c >= e.length - 2 ? $e(e[c]) : e[c]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = I(e).newShape);
|
|
1983
|
+
let o = E(e), i = null;
|
|
1984
|
+
e.length <= 1 && o <= n ? i = [1, o] : e.length === 2 && e[0] <= n && e[1] <= n ? i = e : e.length === 3 && e[0] * e[1] <= n && e[2] <= n ? i = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= n && e[1] * e[2] <= n ? i = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= n && e[3] <= n ? i = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= n && e[1] * e[2] * e[3] <= n && (i = [e[0], e[1] * e[2] * e[3]]);
|
|
1985
|
+
const a = i != null && Math.max(...i) > r && Math.min(...i) <= (t ? 2 : 1) && Math.min(...i) > 0;
|
|
1986
|
+
if (i == null || a)
|
|
1987
|
+
if (t) {
|
|
1988
|
+
const s = xe(e);
|
|
1989
|
+
let c = 2, u = 2;
|
|
1990
|
+
e.length && ([c, u] = pe(e)), o = s * (c / 2) * (u / 2), i = H(o).map((l) => l * 2);
|
|
1991
|
+
} else
|
|
1992
|
+
i = H(o);
|
|
1993
|
+
return i;
|
|
1994
|
+
}
|
|
1995
|
+
function P(e) {
|
|
1996
|
+
return e % 2 === 0;
|
|
1997
|
+
}
|
|
1998
|
+
function un(e, t) {
|
|
1999
|
+
if (e = e.slice(-2), t = t.slice(-2), T(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0)
|
|
2000
|
+
return !0;
|
|
2001
|
+
if (e.length !== t.length) {
|
|
2002
|
+
const n = e[e.length - 1], r = t[t.length - 1];
|
|
2003
|
+
if (n === r || P(n) && P(r) && (e[0] === 1 || t[0] === 1))
|
|
2004
|
+
return !0;
|
|
2005
|
+
}
|
|
2006
|
+
return e[1] === t[1] && P(e[0]) && P(t[0]);
|
|
2007
|
+
}
|
|
2008
|
+
let W, X;
|
|
2009
|
+
function ln(e) {
|
|
2010
|
+
if (W == null) {
|
|
2011
|
+
const t = A(e);
|
|
2012
|
+
W = t.getParameter(t.MAX_TEXTURE_SIZE);
|
|
2013
|
+
}
|
|
2014
|
+
return W;
|
|
2015
|
+
}
|
|
2016
|
+
function fn(e) {
|
|
2017
|
+
if (X == null) {
|
|
2018
|
+
const t = A(e);
|
|
2019
|
+
X = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
|
|
2020
|
+
}
|
|
2021
|
+
return Math.min(16, X);
|
|
2022
|
+
}
|
|
2023
|
+
function hn(e) {
|
|
2024
|
+
if (e === 0)
|
|
2025
|
+
return 0;
|
|
2026
|
+
let t;
|
|
2027
|
+
const n = A(e);
|
|
2028
|
+
return g(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? t = 2 : g(n, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
|
|
2029
|
+
}
|
|
2030
|
+
function g(e, t) {
|
|
2031
|
+
return e.getExtension(t) != null;
|
|
2032
|
+
}
|
|
2033
|
+
function dn(e) {
|
|
2034
|
+
try {
|
|
2035
|
+
if (A(e) != null)
|
|
2036
|
+
return !0;
|
|
2037
|
+
} catch (t) {
|
|
2038
|
+
return console.log("Error when getting WebGL context: ", t), !1;
|
|
2039
|
+
}
|
|
2040
|
+
return !1;
|
|
2041
|
+
}
|
|
2042
|
+
function xn(e) {
|
|
2043
|
+
if (e === 0)
|
|
2044
|
+
return !1;
|
|
2045
|
+
const t = A(e);
|
|
2046
|
+
if (e === 1) {
|
|
2047
|
+
if (!g(t, "OES_texture_float"))
|
|
2048
|
+
return !1;
|
|
2049
|
+
} else if (!g(t, "EXT_color_buffer_float"))
|
|
2050
|
+
return !1;
|
|
2051
|
+
return G(t);
|
|
2052
|
+
}
|
|
2053
|
+
function pn(e) {
|
|
2054
|
+
if (e === 0)
|
|
2055
|
+
return !1;
|
|
2056
|
+
const t = A(e);
|
|
2057
|
+
if (e === 1) {
|
|
2058
|
+
if (!g(t, "OES_texture_float") || !g(t, "WEBGL_color_buffer_float"))
|
|
2059
|
+
return !1;
|
|
2060
|
+
} else {
|
|
2061
|
+
if (g(t, "EXT_color_buffer_float"))
|
|
2062
|
+
return G(t);
|
|
2063
|
+
const r = "EXT_color_buffer_half_float";
|
|
2064
|
+
if (g(t, r)) {
|
|
2065
|
+
const o = t.getExtension(r);
|
|
2066
|
+
return _t(t, o);
|
|
2067
|
+
}
|
|
2068
|
+
return !1;
|
|
2069
|
+
}
|
|
2070
|
+
return G(t);
|
|
2071
|
+
}
|
|
2072
|
+
function G(e) {
|
|
2073
|
+
const t = de(e), n = e.createTexture();
|
|
2074
|
+
e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
|
|
2075
|
+
const i = e.createFramebuffer();
|
|
2076
|
+
e.bindFramebuffer(e.FRAMEBUFFER, i), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
|
|
2077
|
+
const a = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
2078
|
+
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(i), a;
|
|
2079
|
+
}
|
|
2080
|
+
function _t(e, t) {
|
|
2081
|
+
const n = de(e, t), r = e.createTexture();
|
|
2082
|
+
e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
|
|
2083
|
+
const a = e.createFramebuffer();
|
|
2084
|
+
e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
|
|
2085
|
+
const s = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
2086
|
+
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(a), s;
|
|
2087
|
+
}
|
|
2088
|
+
function vn(e) {
|
|
2089
|
+
return e !== 2 ? !1 : A(e).fenceSync != null;
|
|
2090
|
+
}
|
|
2091
|
+
function mn(e, t) {
|
|
2092
|
+
Array.isArray(e) || (e = [e]), e.forEach((n) => {
|
|
2093
|
+
n != null && F(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* @license
|
|
2098
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
2099
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2100
|
+
* you may not use this file except in compliance with the License.
|
|
2101
|
+
* You may obtain a copy of the License at
|
|
2102
|
+
*
|
|
2103
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2104
|
+
*
|
|
2105
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2106
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2107
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2108
|
+
* See the License for the specific language governing permissions and
|
|
2109
|
+
* limitations under the License.
|
|
2110
|
+
* =============================================================================
|
|
2111
|
+
*/
|
|
2112
|
+
function $n(e, t, n, r) {
|
|
2113
|
+
const o = n.map((l, f) => {
|
|
2114
|
+
const d = {
|
|
2115
|
+
logicalShape: l.shape,
|
|
2116
|
+
texShape: l.isUniform ? null : l.texData.texShape,
|
|
2117
|
+
isUniform: l.isUniform,
|
|
2118
|
+
isPacked: l.isUniform ? !1 : l.texData.isPacked,
|
|
2119
|
+
flatOffset: null
|
|
2120
|
+
};
|
|
2121
|
+
return l.texData != null && l.texData.slice != null && l.texData.slice.flatOffset > 0 && (d.flatOffset = l.texData.slice.flatOffset), { name: t.variableNames[f], shapeInfo: d };
|
|
2122
|
+
}), i = o.map((l) => l.shapeInfo), a = {
|
|
2123
|
+
logicalShape: r.shape,
|
|
2124
|
+
texShape: r.texData.texShape,
|
|
2125
|
+
isUniform: !1,
|
|
2126
|
+
isPacked: r.texData.isPacked,
|
|
2127
|
+
flatOffset: null
|
|
2128
|
+
}, s = Le(o, a, t), c = Et(e.gl, s), u = e.createProgram(c);
|
|
2129
|
+
return v().get("ENGINE_COMPILE_ONLY") ? {
|
|
2130
|
+
program: t,
|
|
2131
|
+
fragmentShader: c,
|
|
2132
|
+
source: s,
|
|
2133
|
+
webGLProgram: u,
|
|
2134
|
+
inShapeInfos: i,
|
|
2135
|
+
outShapeInfo: a,
|
|
2136
|
+
variablesLocations: null,
|
|
2137
|
+
customUniformLocations: null,
|
|
2138
|
+
infLoc: null,
|
|
2139
|
+
nanLoc: null,
|
|
2140
|
+
outShapeLocation: null,
|
|
2141
|
+
outShapeStridesLocation: null,
|
|
2142
|
+
outTexShapeLocation: null
|
|
2143
|
+
} : (e.buildVao(u), Object.assign({
|
|
2144
|
+
program: t,
|
|
2145
|
+
fragmentShader: c,
|
|
2146
|
+
source: s,
|
|
2147
|
+
webGLProgram: u,
|
|
2148
|
+
inShapeInfos: i,
|
|
2149
|
+
outShapeInfo: a
|
|
2150
|
+
}, Nt(e, t, u)));
|
|
2151
|
+
}
|
|
2152
|
+
function Nt(e, t, n) {
|
|
2153
|
+
const r = [], o = [];
|
|
2154
|
+
let i, a, s, c = null, u = null;
|
|
2155
|
+
u = e.getUniformLocation(n, "NAN", !1), v().getNumber("WEBGL_VERSION") === 1 && (c = e.getUniformLocation(n, "INFINITY", !1));
|
|
2156
|
+
const l = !1;
|
|
2157
|
+
for (const f of t.variableNames) {
|
|
2158
|
+
const d = {
|
|
2159
|
+
name: f,
|
|
2160
|
+
uniform: e.getUniformLocation(n, f, l),
|
|
2161
|
+
offset: e.getUniformLocation(n, `offset${f}`, l)
|
|
2162
|
+
};
|
|
2163
|
+
t.enableShapeUniforms && (d.shape = e.getUniformLocation(n, `${f}Shape`, l), d.texShape = e.getUniformLocation(n, `${f}TexShape`, l)), r.push(d);
|
|
2164
|
+
}
|
|
2165
|
+
if (t.enableShapeUniforms && (i = e.getUniformLocation(n, "outShape", l), s = e.getUniformLocation(n, "outShapeStrides", l), a = e.getUniformLocation(n, "outTexShape", l)), t.customUniforms)
|
|
2166
|
+
for (const f of t.customUniforms)
|
|
2167
|
+
o.push(e.getUniformLocation(n, f.name, l));
|
|
2168
|
+
return {
|
|
2169
|
+
variablesLocations: r,
|
|
2170
|
+
customUniformLocations: o,
|
|
2171
|
+
infLoc: c,
|
|
2172
|
+
nanLoc: u,
|
|
2173
|
+
outShapeLocation: i,
|
|
2174
|
+
outShapeStridesLocation: s,
|
|
2175
|
+
outTexShapeLocation: a
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
function re(e, t) {
|
|
2179
|
+
if (e.length !== t.length)
|
|
2180
|
+
throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
|
|
2181
|
+
e.forEach((n, r) => {
|
|
2182
|
+
const o = n.logicalShape, i = t[r], a = i.shape;
|
|
2183
|
+
if (!T(o, a))
|
|
2184
|
+
throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${a} must match`);
|
|
2185
|
+
if (n.isUniform && i.isUniform)
|
|
2186
|
+
return;
|
|
2187
|
+
const s = n.texShape, c = i.isUniform ? null : i.texData.texShape;
|
|
2188
|
+
if (!T(s, c))
|
|
2189
|
+
throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${s} and ${c} must match`);
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
function Tn(e, t, n, r, o) {
|
|
2193
|
+
t.program.enableShapeUniforms || (re(t.inShapeInfos, n), re([t.outShapeInfo], [r]));
|
|
2194
|
+
const i = r.texData.texture, a = r.texData.texShape;
|
|
2195
|
+
r.texData.isPacked ? e.setOutputPackedMatrixTexture(i.texture, a[0], a[1]) : e.setOutputMatrixTexture(i.texture, a[0], a[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), v().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
|
|
2196
|
+
for (let c = 0; c < n.length; ++c) {
|
|
2197
|
+
const u = n[c], { uniform: l, offset: f, shape: d, texShape: h } = t.variablesLocations[c];
|
|
2198
|
+
if (d) {
|
|
2199
|
+
const { uniformShape: x } = j(t.program.packedInputs, u.shape, u.texData.texShape);
|
|
2200
|
+
switch (x.length) {
|
|
2201
|
+
case 1:
|
|
2202
|
+
e.gl.uniform1iv(d, new Int32Array(x));
|
|
2203
|
+
break;
|
|
2204
|
+
case 2:
|
|
2205
|
+
e.gl.uniform2iv(d, new Int32Array(x));
|
|
2206
|
+
break;
|
|
2207
|
+
case 3:
|
|
2208
|
+
e.gl.uniform3iv(d, new Int32Array(x));
|
|
2209
|
+
break;
|
|
2210
|
+
case 4:
|
|
2211
|
+
e.gl.uniform4iv(d, new Int32Array(x));
|
|
2212
|
+
break;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
if (h && e.gl.uniform2i(h, u.texData.texShape[0], u.texData.texShape[1]), l != null) {
|
|
2216
|
+
if (u.isUniform) {
|
|
2217
|
+
if (E(u.shape) < 2)
|
|
2218
|
+
e.gl.uniform1f(l, u.uniformValues[0]);
|
|
2219
|
+
else {
|
|
2220
|
+
let x = u.uniformValues;
|
|
2221
|
+
x instanceof Float32Array || (x = new Float32Array(x)), e.gl.uniform1fv(l, x);
|
|
2222
|
+
}
|
|
2223
|
+
continue;
|
|
2224
|
+
}
|
|
2225
|
+
u.texData.slice != null && f != null && e.gl.uniform1i(f, u.texData.slice.flatOffset), e.setInputMatrixTexture(u.texData.texture.texture, l, c);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
const s = t.outShapeLocation;
|
|
2229
|
+
if (s)
|
|
2230
|
+
switch (r.shape.length) {
|
|
2231
|
+
case 1:
|
|
2232
|
+
e.gl.uniform1iv(s, new Int32Array(r.shape));
|
|
2233
|
+
break;
|
|
2234
|
+
case 2:
|
|
2235
|
+
e.gl.uniform2iv(s, new Int32Array(r.shape));
|
|
2236
|
+
break;
|
|
2237
|
+
case 3:
|
|
2238
|
+
e.gl.uniform3iv(s, new Int32Array(r.shape));
|
|
2239
|
+
break;
|
|
2240
|
+
case 4:
|
|
2241
|
+
e.gl.uniform4iv(s, new Int32Array(r.shape));
|
|
2242
|
+
break;
|
|
2243
|
+
}
|
|
2244
|
+
if (t.outShapeStridesLocation) {
|
|
2245
|
+
const c = B(r.shape);
|
|
2246
|
+
switch (r.shape.length) {
|
|
2247
|
+
case 2:
|
|
2248
|
+
e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2249
|
+
break;
|
|
2250
|
+
case 3:
|
|
2251
|
+
e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2252
|
+
break;
|
|
2253
|
+
case 4:
|
|
2254
|
+
e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2255
|
+
break;
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
if (t.outTexShapeLocation && e.gl.uniform2i(t.outTexShapeLocation, r.texData.texShape[0], r.texData.texShape[1]), t.program.customUniforms && o)
|
|
2259
|
+
for (let c = 0; c < t.program.customUniforms.length; ++c) {
|
|
2260
|
+
const u = t.program.customUniforms[c], l = t.customUniformLocations[c], f = o[c];
|
|
2261
|
+
if (u.type === "float")
|
|
2262
|
+
e.gl.uniform1fv(l, f);
|
|
2263
|
+
else if (u.type === "vec2")
|
|
2264
|
+
e.gl.uniform2fv(l, f);
|
|
2265
|
+
else if (u.type === "vec3")
|
|
2266
|
+
e.gl.uniform3fv(l, f);
|
|
2267
|
+
else if (u.type === "vec4")
|
|
2268
|
+
e.gl.uniform4fv(l, f);
|
|
2269
|
+
else if (u.type === "int")
|
|
2270
|
+
e.gl.uniform1iv(l, f);
|
|
2271
|
+
else if (u.type === "ivec2")
|
|
2272
|
+
e.gl.uniform2iv(l, f);
|
|
2273
|
+
else if (u.type === "ivec3")
|
|
2274
|
+
e.gl.uniform3iv(l, f);
|
|
2275
|
+
else if (u.type === "ivec4")
|
|
2276
|
+
e.gl.uniform4iv(l, f);
|
|
2277
|
+
else
|
|
2278
|
+
throw Error(`uniform type ${u.type} is not supported yet.`);
|
|
2279
|
+
}
|
|
2280
|
+
e.executeProgram();
|
|
2281
|
+
}
|
|
2282
|
+
function Sn(e, t, n) {
|
|
2283
|
+
let r = "";
|
|
2284
|
+
t.concat(n).forEach((a) => {
|
|
2285
|
+
const s = a.texData != null && a.texData.slice != null && a.texData.slice.flatOffset > 0;
|
|
2286
|
+
if (e.enableShapeUniforms && !a.isUniform) {
|
|
2287
|
+
const c = a.texData.texShape, { useSqueezeShape: u, uniformShape: l, keptDims: f } = j(e.packedInputs, a.shape, c);
|
|
2288
|
+
let d = "", h = "", x = "";
|
|
2289
|
+
if (l.length === 1 && e.packedInputs) {
|
|
2290
|
+
const O = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)];
|
|
2291
|
+
d = `${O[0] > 1}_${O[1] > 1}`;
|
|
2292
|
+
} else if (l.length === 2 && !e.packedInputs)
|
|
2293
|
+
h = `${l[0] > 1}_${l[1] > 1}`;
|
|
2294
|
+
else if (l.length > 2 && !e.packedInputs) {
|
|
2295
|
+
const O = B(l);
|
|
2296
|
+
x = `${O[0] === c[1]}_${O[O.length - 1] === c[1]}`;
|
|
2297
|
+
}
|
|
2298
|
+
const p = a.shape.length, $ = l.length === 2 && T(a.shape, c), S = E(a.shape) === 1, R = Te(a.shape, n.shape), w = !e.packedInputs && p === n.shape.length && T(c, n.texData.texShape), ve = e.packedInputs || l.length > 2 ? "" : `${c[0] > 1}_${c[1] > 1}`;
|
|
2299
|
+
r += `${p}_${w}_${u ? f : ""}_${l.length}_${S}_${R}_${$}_${d}_${h}_${x}_${ve}_${s}`;
|
|
2300
|
+
} else {
|
|
2301
|
+
const c = a.isUniform ? "uniform" : a.texData.texShape;
|
|
2302
|
+
r += `${a.shape}_${c}_${s}`;
|
|
2303
|
+
}
|
|
2304
|
+
});
|
|
2305
|
+
const o = e.userCode;
|
|
2306
|
+
let i = e.constructor.name;
|
|
2307
|
+
return i += "_" + r + "_" + o + `${v().getNumber("WEBGL_VERSION")}`, i;
|
|
2308
|
+
}
|
|
2309
|
+
function Rn(e) {
|
|
2310
|
+
return v().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
|
|
2311
|
+
}
|
|
2312
|
+
export {
|
|
2313
|
+
Tn as $,
|
|
2314
|
+
mt as A,
|
|
2315
|
+
kt as B,
|
|
2316
|
+
Vt as C,
|
|
2317
|
+
A as D,
|
|
2318
|
+
yt as E,
|
|
2319
|
+
Xt as F,
|
|
2320
|
+
g as G,
|
|
2321
|
+
Zt as H,
|
|
2322
|
+
de as I,
|
|
2323
|
+
on as J,
|
|
2324
|
+
Gt as K,
|
|
2325
|
+
zt as L,
|
|
2326
|
+
qt as M,
|
|
2327
|
+
en as N,
|
|
2328
|
+
tn as O,
|
|
2329
|
+
ee as P,
|
|
2330
|
+
nn as Q,
|
|
2331
|
+
an as R,
|
|
2332
|
+
rn as S,
|
|
2333
|
+
te as T,
|
|
2334
|
+
Mt as U,
|
|
2335
|
+
ne as V,
|
|
2336
|
+
cn as W,
|
|
2337
|
+
Pt as X,
|
|
2338
|
+
Wt as Y,
|
|
2339
|
+
Sn as Z,
|
|
2340
|
+
$n as _,
|
|
2341
|
+
bt as a,
|
|
2342
|
+
sn as a0,
|
|
2343
|
+
wt as a1,
|
|
2344
|
+
Nt as a2,
|
|
2345
|
+
mn as a3,
|
|
2346
|
+
Lt as b,
|
|
2347
|
+
V as c,
|
|
2348
|
+
xe as d,
|
|
2349
|
+
pe as e,
|
|
2350
|
+
he as f,
|
|
2351
|
+
Dt as g,
|
|
2352
|
+
dn as h,
|
|
2353
|
+
un as i,
|
|
2354
|
+
ln as j,
|
|
2355
|
+
fn as k,
|
|
2356
|
+
hn as l,
|
|
2357
|
+
xn as m,
|
|
2358
|
+
pn as n,
|
|
2359
|
+
vn as o,
|
|
2360
|
+
L as p,
|
|
2361
|
+
se as q,
|
|
2362
|
+
jt as r,
|
|
2363
|
+
Jt as s,
|
|
2364
|
+
m as t,
|
|
2365
|
+
Rn as u,
|
|
2366
|
+
Bt as v,
|
|
2367
|
+
Ht as w,
|
|
2368
|
+
Qt as x,
|
|
2369
|
+
Kt as y,
|
|
2370
|
+
Yt as z
|
|
2371
|
+
};
|