@luma.gl/webgpu 9.0.0-alpha.5 → 9.0.0-alpha.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
  4. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  5. package/dist/adapter/helpers/convert-texture-format.js +0 -1
  6. package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
  7. package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
  8. package/dist/adapter/helpers/generate-mipmaps.js +20 -15
  9. package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
  10. package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
  11. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  12. package/dist/adapter/helpers/get-bind-group.js +8 -17
  13. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  14. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
  15. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  16. package/dist/adapter/helpers/get-vertex-buffer-layout.js +32 -40
  17. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  18. package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
  19. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  20. package/dist/adapter/helpers/webgpu-parameters.js +51 -48
  21. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  22. package/dist/adapter/resources/webgpu-buffer.d.ts +5 -6
  23. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-buffer.js +19 -33
  25. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  26. package/dist/adapter/resources/webgpu-command-encoder.d.ts +6 -15
  27. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  28. package/dist/adapter/resources/webgpu-command-encoder.js +11 -29
  29. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  30. package/dist/adapter/resources/webgpu-compute-pass.d.ts +6 -6
  31. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgpu-compute-pass.js +14 -27
  33. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  34. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +4 -4
  35. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgpu-compute-pipeline.js +6 -11
  37. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  38. package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
  39. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgpu-external-texture.js +6 -14
  41. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
  42. package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
  43. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-framebuffer.js +4 -105
  45. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  46. package/dist/adapter/resources/webgpu-query.js.map +1 -1
  47. package/dist/adapter/resources/webgpu-render-pass.d.ts +12 -7
  48. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgpu-render-pass.js +59 -36
  50. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  51. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +14 -10
  52. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-render-pipeline.js +50 -67
  54. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  55. package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
  56. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgpu-sampler.js +11 -11
  58. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  59. package/dist/adapter/resources/webgpu-shader.d.ts +7 -7
  60. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgpu-shader.js +11 -25
  62. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  63. package/dist/adapter/resources/webgpu-texture.d.ts +15 -8
  64. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  65. package/dist/adapter/resources/webgpu-texture.js +17 -27
  66. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  67. package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
  68. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  69. package/dist/adapter/resources/webgpu-vertex-array.js +39 -0
  70. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -0
  71. package/dist/adapter/webgpu-canvas-context.d.ts +16 -12
  72. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  73. package/dist/adapter/webgpu-canvas-context.js +26 -47
  74. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  75. package/dist/adapter/webgpu-device.d.ts +39 -22
  76. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  77. package/dist/adapter/webgpu-device.js +94 -95
  78. package/dist/adapter/webgpu-device.js.map +1 -1
  79. package/dist/adapter/webgpu-types.js.map +1 -1
  80. package/dist/dist.dev.js +2988 -0
  81. package/dist/glsl/glsllang.js +0 -1
  82. package/dist/glsl/glsllang.js.map +1 -1
  83. package/dist/index.cjs +1518 -0
  84. package/dist/index.d.ts +5 -7
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +5 -7
  87. package/dist/index.js.map +1 -1
  88. package/dist.min.js +20 -0
  89. package/package.json +18 -9
  90. package/src/adapter/helpers/accessor-to-format.ts +1 -2
  91. package/src/adapter/helpers/convert-texture-format.ts +1 -1
  92. package/src/adapter/helpers/generate-mipmaps.ts +2 -2
  93. package/src/adapter/helpers/get-bind-group.ts +22 -12
  94. package/src/adapter/helpers/get-vertex-buffer-layout.ts +55 -34
  95. package/src/adapter/helpers/webgpu-parameters.ts +56 -47
  96. package/src/adapter/resources/webgpu-buffer.ts +11 -12
  97. package/src/adapter/resources/webgpu-command-encoder.ts +62 -41
  98. package/src/adapter/resources/webgpu-compute-pass.ts +13 -13
  99. package/src/adapter/resources/webgpu-compute-pipeline.ts +6 -5
  100. package/src/adapter/resources/webgpu-external-texture.ts +5 -5
  101. package/src/adapter/resources/webgpu-framebuffer.ts +8 -109
  102. package/src/adapter/resources/webgpu-query.ts +3 -3
  103. package/src/adapter/resources/webgpu-render-pass.ts +74 -18
  104. package/src/adapter/resources/webgpu-render-pipeline.ts +64 -39
  105. package/src/adapter/resources/webgpu-sampler.ts +12 -5
  106. package/src/adapter/resources/webgpu-shader.ts +13 -10
  107. package/src/adapter/resources/webgpu-texture.ts +22 -8
  108. package/src/adapter/resources/webgpu-vertex-array.ts +74 -0
  109. package/src/adapter/webgpu-canvas-context.ts +52 -27
  110. package/src/adapter/webgpu-device.ts +158 -64
  111. package/src/index.ts +7 -9
  112. package/dist/bundle.d.ts +0 -2
  113. package/dist/bundle.d.ts.map +0 -1
  114. package/dist/bundle.js +0 -5
  115. package/dist/bundle.js.map +0 -1
  116. package/dist/init.d.ts +0 -2
  117. package/dist/init.d.ts.map +0 -1
  118. package/dist/init.js +0 -4
  119. package/dist/init.js.map +0 -1
  120. package/src/bundle.ts +0 -4
  121. package/src/init.ts +0 -4
@@ -0,0 +1,2988 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['luma'] = factory();
6
+ else root['luma'] = factory();})(globalThis, function () {
7
+ var __exports__ = (() => {
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __export = (target, all) => {
14
+ for (var name2 in all)
15
+ __defProp(target, name2, { get: all[name2], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var __publicField = (obj, key, value) => {
27
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+ return value;
29
+ };
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ WebGPUBuffer: () => WebGPUBuffer,
35
+ WebGPUDevice: () => WebGPUDevice,
36
+ WebGPUSampler: () => WebGPUSampler,
37
+ WebGPUShader: () => WebGPUShader,
38
+ WebGPUTexture: () => WebGPUTexture
39
+ });
40
+
41
+ // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
42
+ function isElectron(mockUserAgent) {
43
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
44
+ return true;
45
+ }
46
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
47
+ return true;
48
+ }
49
+ const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
50
+ const userAgent = mockUserAgent || realUserAgent;
51
+ if (userAgent && userAgent.indexOf("Electron") >= 0) {
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+
57
+ // ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
58
+ function isBrowser() {
59
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
60
+ return !isNode || isElectron();
61
+ }
62
+
63
+ // ../../node_modules/@probe.gl/env/dist/lib/globals.js
64
+ var self_ = globalThis.self || globalThis.window || globalThis.global;
65
+ var window_ = globalThis.window || globalThis.self || globalThis.global;
66
+ var document_ = globalThis.document || {};
67
+ var process_ = globalThis.process || {};
68
+ var console_ = globalThis.console;
69
+ var navigator_ = globalThis.navigator || {};
70
+
71
+ // ../../node_modules/@probe.gl/env/dist/utils/globals.js
72
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
73
+ var isBrowser2 = isBrowser();
74
+
75
+ // ../../node_modules/@probe.gl/env/dist/lib/get-browser.js
76
+ var window2 = globalThis;
77
+ function getBrowser(mockUserAgent) {
78
+ if (!mockUserAgent && !isBrowser()) {
79
+ return "Node";
80
+ }
81
+ if (isElectron(mockUserAgent)) {
82
+ return "Electron";
83
+ }
84
+ const userAgent = mockUserAgent || navigator_.userAgent || "";
85
+ if (userAgent.indexOf("Edge") > -1) {
86
+ return "Edge";
87
+ }
88
+ const isMSIE = userAgent.indexOf("MSIE ") !== -1;
89
+ const isTrident = userAgent.indexOf("Trident/") !== -1;
90
+ if (isMSIE || isTrident) {
91
+ return "IE";
92
+ }
93
+ if (window2.chrome) {
94
+ return "Chrome";
95
+ }
96
+ if (window2.safari) {
97
+ return "Safari";
98
+ }
99
+ if (window2.mozInnerScreenX) {
100
+ return "Firefox";
101
+ }
102
+ return "Unknown";
103
+ }
104
+
105
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
106
+ function getStorage(type) {
107
+ try {
108
+ const storage = window[type];
109
+ const x = "__storage_test__";
110
+ storage.setItem(x, x);
111
+ storage.removeItem(x);
112
+ return storage;
113
+ } catch (e) {
114
+ return null;
115
+ }
116
+ }
117
+ var LocalStorage = class {
118
+ constructor(id, defaultConfig) {
119
+ let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
120
+ this.storage = void 0;
121
+ this.id = void 0;
122
+ this.config = void 0;
123
+ this.storage = getStorage(type);
124
+ this.id = id;
125
+ this.config = defaultConfig;
126
+ this._loadConfiguration();
127
+ }
128
+ getConfiguration() {
129
+ return this.config;
130
+ }
131
+ setConfiguration(configuration) {
132
+ Object.assign(this.config, configuration);
133
+ if (this.storage) {
134
+ const serialized = JSON.stringify(this.config);
135
+ this.storage.setItem(this.id, serialized);
136
+ }
137
+ }
138
+ _loadConfiguration() {
139
+ let configuration = {};
140
+ if (this.storage) {
141
+ const serializedConfiguration = this.storage.getItem(this.id);
142
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
143
+ }
144
+ Object.assign(this.config, configuration);
145
+ return this;
146
+ }
147
+ };
148
+
149
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
150
+ function formatTime(ms) {
151
+ let formatted;
152
+ if (ms < 10) {
153
+ formatted = "".concat(ms.toFixed(2), "ms");
154
+ } else if (ms < 100) {
155
+ formatted = "".concat(ms.toFixed(1), "ms");
156
+ } else if (ms < 1e3) {
157
+ formatted = "".concat(ms.toFixed(0), "ms");
158
+ } else {
159
+ formatted = "".concat((ms / 1e3).toFixed(2), "s");
160
+ }
161
+ return formatted;
162
+ }
163
+ function leftPad(string) {
164
+ let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
165
+ const padLength = Math.max(length - string.length, 0);
166
+ return "".concat(" ".repeat(padLength)).concat(string);
167
+ }
168
+ function formatImage(image, message, scale) {
169
+ let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
170
+ const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
171
+ if (image.width > maxWidth) {
172
+ scale = Math.min(scale, maxWidth / image.width);
173
+ }
174
+ const width = image.width * scale;
175
+ const height = image.height * scale;
176
+ const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
177
+ return ["".concat(message, " %c+"), style];
178
+ }
179
+
180
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
181
+ var COLOR;
182
+ (function(COLOR2) {
183
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
184
+ COLOR2[COLOR2["RED"] = 31] = "RED";
185
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
186
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
187
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
188
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
189
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
190
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
191
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
192
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
193
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
194
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
195
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
196
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
197
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
198
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
199
+ })(COLOR || (COLOR = {}));
200
+ var BACKGROUND_INCREMENT = 10;
201
+ function getColor(color) {
202
+ if (typeof color !== "string") {
203
+ return color;
204
+ }
205
+ color = color.toUpperCase();
206
+ return COLOR[color] || COLOR.WHITE;
207
+ }
208
+ function addColor(string, color, background) {
209
+ if (!isBrowser && typeof string === "string") {
210
+ if (color) {
211
+ const colorCode = getColor(color);
212
+ string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
213
+ }
214
+ if (background) {
215
+ const colorCode = getColor(background);
216
+ string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
217
+ }
218
+ }
219
+ return string;
220
+ }
221
+
222
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
223
+ function autobind(obj) {
224
+ let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
225
+ const proto = Object.getPrototypeOf(obj);
226
+ const propNames = Object.getOwnPropertyNames(proto);
227
+ const object = obj;
228
+ for (const key of propNames) {
229
+ const value = object[key];
230
+ if (typeof value === "function") {
231
+ if (!predefined.find((name2) => key === name2)) {
232
+ object[key] = value.bind(obj);
233
+ }
234
+ }
235
+ }
236
+ }
237
+
238
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
239
+ function assert(condition, message) {
240
+ if (!condition) {
241
+ throw new Error(message || "Assertion failed");
242
+ }
243
+ }
244
+
245
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
246
+ function getHiResTimestamp() {
247
+ let timestamp;
248
+ if (isBrowser() && window_.performance) {
249
+ var _window$performance, _window$performance$n;
250
+ timestamp = window_ === null || window_ === void 0 ? void 0 : (_window$performance = window_.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
251
+ } else if ("hrtime" in process_) {
252
+ var _process$hrtime;
253
+ const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
254
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
255
+ } else {
256
+ timestamp = Date.now();
257
+ }
258
+ return timestamp;
259
+ }
260
+
261
+ // ../../node_modules/@probe.gl/log/dist/log.js
262
+ var originalConsole = {
263
+ debug: isBrowser() ? console.debug || console.log : console.log,
264
+ log: console.log,
265
+ info: console.info,
266
+ warn: console.warn,
267
+ error: console.error
268
+ };
269
+ var DEFAULT_LOG_CONFIGURATION = {
270
+ enabled: true,
271
+ level: 0
272
+ };
273
+ function noop() {
274
+ }
275
+ var cache = {};
276
+ var ONCE = {
277
+ once: true
278
+ };
279
+ var Log = class {
280
+ constructor() {
281
+ let {
282
+ id
283
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
284
+ id: ""
285
+ };
286
+ this.id = void 0;
287
+ this.VERSION = VERSION;
288
+ this._startTs = getHiResTimestamp();
289
+ this._deltaTs = getHiResTimestamp();
290
+ this._storage = void 0;
291
+ this.userData = {};
292
+ this.LOG_THROTTLE_TIMEOUT = 0;
293
+ this.id = id;
294
+ this.userData = {};
295
+ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
296
+ this.timeStamp("".concat(this.id, " started"));
297
+ autobind(this);
298
+ Object.seal(this);
299
+ }
300
+ set level(newLevel) {
301
+ this.setLevel(newLevel);
302
+ }
303
+ get level() {
304
+ return this.getLevel();
305
+ }
306
+ isEnabled() {
307
+ return this._storage.config.enabled;
308
+ }
309
+ getLevel() {
310
+ return this._storage.config.level;
311
+ }
312
+ getTotal() {
313
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
314
+ }
315
+ getDelta() {
316
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
317
+ }
318
+ set priority(newPriority) {
319
+ this.level = newPriority;
320
+ }
321
+ get priority() {
322
+ return this.level;
323
+ }
324
+ getPriority() {
325
+ return this.level;
326
+ }
327
+ enable() {
328
+ let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
329
+ this._storage.setConfiguration({
330
+ enabled
331
+ });
332
+ return this;
333
+ }
334
+ setLevel(level) {
335
+ this._storage.setConfiguration({
336
+ level
337
+ });
338
+ return this;
339
+ }
340
+ get(setting) {
341
+ return this._storage.config[setting];
342
+ }
343
+ set(setting, value) {
344
+ this._storage.setConfiguration({
345
+ [setting]: value
346
+ });
347
+ }
348
+ settings() {
349
+ if (console.table) {
350
+ console.table(this._storage.config);
351
+ } else {
352
+ console.log(this._storage.config);
353
+ }
354
+ }
355
+ assert(condition, message) {
356
+ assert(condition, message);
357
+ }
358
+ warn(message) {
359
+ return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
360
+ }
361
+ error(message) {
362
+ return this._getLogFunction(0, message, originalConsole.error, arguments);
363
+ }
364
+ deprecated(oldUsage, newUsage) {
365
+ return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
366
+ }
367
+ removed(oldUsage, newUsage) {
368
+ return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
369
+ }
370
+ probe(logLevel, message) {
371
+ return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
372
+ time: true,
373
+ once: true
374
+ });
375
+ }
376
+ log(logLevel, message) {
377
+ return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
378
+ }
379
+ info(logLevel, message) {
380
+ return this._getLogFunction(logLevel, message, console.info, arguments);
381
+ }
382
+ once(logLevel, message) {
383
+ return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
384
+ }
385
+ table(logLevel, table, columns) {
386
+ if (table) {
387
+ return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
388
+ tag: getTableHeader(table)
389
+ });
390
+ }
391
+ return noop;
392
+ }
393
+ image(_ref) {
394
+ let {
395
+ logLevel,
396
+ priority,
397
+ image,
398
+ message = "",
399
+ scale = 1
400
+ } = _ref;
401
+ if (!this._shouldLog(logLevel || priority)) {
402
+ return noop;
403
+ }
404
+ return isBrowser() ? logImageInBrowser({
405
+ image,
406
+ message,
407
+ scale
408
+ }) : logImageInNode({
409
+ image,
410
+ message,
411
+ scale
412
+ });
413
+ }
414
+ time(logLevel, message) {
415
+ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
416
+ }
417
+ timeEnd(logLevel, message) {
418
+ return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
419
+ }
420
+ timeStamp(logLevel, message) {
421
+ return this._getLogFunction(logLevel, message, console.timeStamp || noop);
422
+ }
423
+ group(logLevel, message) {
424
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
425
+ collapsed: false
426
+ };
427
+ const options = normalizeArguments({
428
+ logLevel,
429
+ message,
430
+ opts
431
+ });
432
+ const {
433
+ collapsed
434
+ } = opts;
435
+ options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
436
+ return this._getLogFunction(options);
437
+ }
438
+ groupCollapsed(logLevel, message) {
439
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
440
+ return this.group(logLevel, message, Object.assign({}, opts, {
441
+ collapsed: true
442
+ }));
443
+ }
444
+ groupEnd(logLevel) {
445
+ return this._getLogFunction(logLevel, "", console.groupEnd || noop);
446
+ }
447
+ withGroup(logLevel, message, func) {
448
+ this.group(logLevel, message)();
449
+ try {
450
+ func();
451
+ } finally {
452
+ this.groupEnd(logLevel)();
453
+ }
454
+ }
455
+ trace() {
456
+ if (console.trace) {
457
+ console.trace();
458
+ }
459
+ }
460
+ _shouldLog(logLevel) {
461
+ return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
462
+ }
463
+ _getLogFunction(logLevel, message, method, args, opts) {
464
+ if (this._shouldLog(logLevel)) {
465
+ opts = normalizeArguments({
466
+ logLevel,
467
+ message,
468
+ args,
469
+ opts
470
+ });
471
+ method = method || opts.method;
472
+ assert(method);
473
+ opts.total = this.getTotal();
474
+ opts.delta = this.getDelta();
475
+ this._deltaTs = getHiResTimestamp();
476
+ const tag = opts.tag || opts.message;
477
+ if (opts.once && tag) {
478
+ if (!cache[tag]) {
479
+ cache[tag] = getHiResTimestamp();
480
+ } else {
481
+ return noop;
482
+ }
483
+ }
484
+ message = decorateMessage(this.id, opts.message, opts);
485
+ return method.bind(console, message, ...opts.args);
486
+ }
487
+ return noop;
488
+ }
489
+ };
490
+ Log.VERSION = VERSION;
491
+ function normalizeLogLevel(logLevel) {
492
+ if (!logLevel) {
493
+ return 0;
494
+ }
495
+ let resolvedLevel;
496
+ switch (typeof logLevel) {
497
+ case "number":
498
+ resolvedLevel = logLevel;
499
+ break;
500
+ case "object":
501
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
502
+ break;
503
+ default:
504
+ return 0;
505
+ }
506
+ assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
507
+ return resolvedLevel;
508
+ }
509
+ function normalizeArguments(opts) {
510
+ const {
511
+ logLevel,
512
+ message
513
+ } = opts;
514
+ opts.logLevel = normalizeLogLevel(logLevel);
515
+ const args = opts.args ? Array.from(opts.args) : [];
516
+ while (args.length && args.shift() !== message) {
517
+ }
518
+ switch (typeof logLevel) {
519
+ case "string":
520
+ case "function":
521
+ if (message !== void 0) {
522
+ args.unshift(message);
523
+ }
524
+ opts.message = logLevel;
525
+ break;
526
+ case "object":
527
+ Object.assign(opts, logLevel);
528
+ break;
529
+ default:
530
+ }
531
+ if (typeof opts.message === "function") {
532
+ opts.message = opts.message();
533
+ }
534
+ const messageType = typeof opts.message;
535
+ assert(messageType === "string" || messageType === "object");
536
+ return Object.assign(opts, {
537
+ args
538
+ }, opts.opts);
539
+ }
540
+ function decorateMessage(id, message, opts) {
541
+ if (typeof message === "string") {
542
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
543
+ message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
544
+ message = addColor(message, opts.color, opts.background);
545
+ }
546
+ return message;
547
+ }
548
+ function logImageInNode(_ref2) {
549
+ let {
550
+ image,
551
+ message = "",
552
+ scale = 1
553
+ } = _ref2;
554
+ console.warn("removed");
555
+ return noop;
556
+ }
557
+ function logImageInBrowser(_ref3) {
558
+ let {
559
+ image,
560
+ message = "",
561
+ scale = 1
562
+ } = _ref3;
563
+ if (typeof image === "string") {
564
+ const img = new Image();
565
+ img.onload = () => {
566
+ const args = formatImage(img, message, scale);
567
+ console.log(...args);
568
+ };
569
+ img.src = image;
570
+ return noop;
571
+ }
572
+ const element = image.nodeName || "";
573
+ if (element.toLowerCase() === "img") {
574
+ console.log(...formatImage(image, message, scale));
575
+ return noop;
576
+ }
577
+ if (element.toLowerCase() === "canvas") {
578
+ const img = new Image();
579
+ img.onload = () => console.log(...formatImage(img, message, scale));
580
+ img.src = image.toDataURL();
581
+ return noop;
582
+ }
583
+ return noop;
584
+ }
585
+ function getTableHeader(table) {
586
+ for (const key in table) {
587
+ for (const title in table[key]) {
588
+ return title || "untitled";
589
+ }
590
+ }
591
+ return "empty";
592
+ }
593
+
594
+ // ../../node_modules/@probe.gl/log/dist/index.js
595
+ var dist_default = new Log({
596
+ id: "@probe.gl/log"
597
+ });
598
+
599
+ // ../core/src/lib/utils/log.ts
600
+ var log = new Log({
601
+ id: "luma.gl"
602
+ });
603
+
604
+ // ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
605
+ function getHiResTimestamp2() {
606
+ let timestamp;
607
+ if (typeof window !== "undefined" && window.performance) {
608
+ timestamp = window.performance.now();
609
+ } else if (typeof process !== "undefined" && process.hrtime) {
610
+ const timeParts = process.hrtime();
611
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
612
+ } else {
613
+ timestamp = Date.now();
614
+ }
615
+ return timestamp;
616
+ }
617
+
618
+ // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
619
+ var Stat = class {
620
+ constructor(name2, type) {
621
+ this.name = void 0;
622
+ this.type = void 0;
623
+ this.sampleSize = 1;
624
+ this.time = 0;
625
+ this.count = 0;
626
+ this.samples = 0;
627
+ this.lastTiming = 0;
628
+ this.lastSampleTime = 0;
629
+ this.lastSampleCount = 0;
630
+ this._count = 0;
631
+ this._time = 0;
632
+ this._samples = 0;
633
+ this._startTime = 0;
634
+ this._timerPending = false;
635
+ this.name = name2;
636
+ this.type = type;
637
+ this.reset();
638
+ }
639
+ reset() {
640
+ this.time = 0;
641
+ this.count = 0;
642
+ this.samples = 0;
643
+ this.lastTiming = 0;
644
+ this.lastSampleTime = 0;
645
+ this.lastSampleCount = 0;
646
+ this._count = 0;
647
+ this._time = 0;
648
+ this._samples = 0;
649
+ this._startTime = 0;
650
+ this._timerPending = false;
651
+ return this;
652
+ }
653
+ setSampleSize(samples) {
654
+ this.sampleSize = samples;
655
+ return this;
656
+ }
657
+ incrementCount() {
658
+ this.addCount(1);
659
+ return this;
660
+ }
661
+ decrementCount() {
662
+ this.subtractCount(1);
663
+ return this;
664
+ }
665
+ addCount(value) {
666
+ this._count += value;
667
+ this._samples++;
668
+ this._checkSampling();
669
+ return this;
670
+ }
671
+ subtractCount(value) {
672
+ this._count -= value;
673
+ this._samples++;
674
+ this._checkSampling();
675
+ return this;
676
+ }
677
+ addTime(time) {
678
+ this._time += time;
679
+ this.lastTiming = time;
680
+ this._samples++;
681
+ this._checkSampling();
682
+ return this;
683
+ }
684
+ timeStart() {
685
+ this._startTime = getHiResTimestamp2();
686
+ this._timerPending = true;
687
+ return this;
688
+ }
689
+ timeEnd() {
690
+ if (!this._timerPending) {
691
+ return this;
692
+ }
693
+ this.addTime(getHiResTimestamp2() - this._startTime);
694
+ this._timerPending = false;
695
+ this._checkSampling();
696
+ return this;
697
+ }
698
+ getSampleAverageCount() {
699
+ return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
700
+ }
701
+ getSampleAverageTime() {
702
+ return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
703
+ }
704
+ getSampleHz() {
705
+ return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
706
+ }
707
+ getAverageCount() {
708
+ return this.samples > 0 ? this.count / this.samples : 0;
709
+ }
710
+ getAverageTime() {
711
+ return this.samples > 0 ? this.time / this.samples : 0;
712
+ }
713
+ getHz() {
714
+ return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
715
+ }
716
+ _checkSampling() {
717
+ if (this._samples === this.sampleSize) {
718
+ this.lastSampleTime = this._time;
719
+ this.lastSampleCount = this._count;
720
+ this.count += this._count;
721
+ this.time += this._time;
722
+ this.samples += this._samples;
723
+ this._time = 0;
724
+ this._count = 0;
725
+ this._samples = 0;
726
+ }
727
+ }
728
+ };
729
+
730
+ // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
731
+ var Stats = class {
732
+ constructor(options) {
733
+ this.id = void 0;
734
+ this.stats = {};
735
+ this.id = options.id;
736
+ this.stats = {};
737
+ this._initializeStats(options.stats);
738
+ Object.seal(this);
739
+ }
740
+ get(name2) {
741
+ let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
742
+ return this._getOrCreate({
743
+ name: name2,
744
+ type
745
+ });
746
+ }
747
+ get size() {
748
+ return Object.keys(this.stats).length;
749
+ }
750
+ reset() {
751
+ for (const stat of Object.values(this.stats)) {
752
+ stat.reset();
753
+ }
754
+ return this;
755
+ }
756
+ forEach(fn) {
757
+ for (const stat of Object.values(this.stats)) {
758
+ fn(stat);
759
+ }
760
+ }
761
+ getTable() {
762
+ const table = {};
763
+ this.forEach((stat) => {
764
+ table[stat.name] = {
765
+ time: stat.time || 0,
766
+ count: stat.count || 0,
767
+ average: stat.getAverageTime() || 0,
768
+ hz: stat.getHz() || 0
769
+ };
770
+ });
771
+ return table;
772
+ }
773
+ _initializeStats() {
774
+ let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
775
+ stats.forEach((stat) => this._getOrCreate(stat));
776
+ }
777
+ _getOrCreate(stat) {
778
+ const {
779
+ name: name2,
780
+ type
781
+ } = stat;
782
+ let result = this.stats[name2];
783
+ if (!result) {
784
+ if (stat instanceof Stat) {
785
+ result = stat;
786
+ } else {
787
+ result = new Stat(name2, type);
788
+ }
789
+ this.stats[name2] = result;
790
+ }
791
+ return result;
792
+ }
793
+ };
794
+
795
+ // ../core/src/lib/utils/stats-manager.ts
796
+ var StatsManager = class {
797
+ stats = /* @__PURE__ */ new Map();
798
+ getStats(name2) {
799
+ return this.get(name2);
800
+ }
801
+ get(name2) {
802
+ if (!this.stats.has(name2)) {
803
+ this.stats.set(name2, new Stats({
804
+ id: name2
805
+ }));
806
+ }
807
+ return this.stats.get(name2);
808
+ }
809
+ };
810
+ var lumaStats = new StatsManager();
811
+
812
+ // ../core/src/init.ts
813
+ function initializeLuma() {
814
+ const VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
815
+ const STARTUP_MESSAGE = "set luma.log.level=1 (or higher) to trace rendering";
816
+ if (globalThis.luma && globalThis.luma.VERSION !== VERSION3) {
817
+ throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION3}`);
818
+ }
819
+ if (!globalThis.luma) {
820
+ if (isBrowser()) {
821
+ log.log(1, `luma.gl ${VERSION3} - ${STARTUP_MESSAGE}`)();
822
+ }
823
+ globalThis.luma = globalThis.luma || {
824
+ VERSION: VERSION3,
825
+ version: VERSION3,
826
+ log,
827
+ stats: lumaStats
828
+ };
829
+ }
830
+ return VERSION3;
831
+ }
832
+ var VERSION2 = initializeLuma();
833
+
834
+ // ../core/src/lib/utils/utils.ts
835
+ var uidCounters = {};
836
+ function uid(id = "id") {
837
+ uidCounters[id] = uidCounters[id] || 1;
838
+ const count = uidCounters[id]++;
839
+ return `${id}-${count}`;
840
+ }
841
+ function isObjectEmpty(obj) {
842
+ let isEmpty = true;
843
+ for (const key in obj) {
844
+ isEmpty = false;
845
+ break;
846
+ }
847
+ return isEmpty;
848
+ }
849
+
850
+ // ../core/src/adapter/resources/resource.ts
851
+ var Resource = class {
852
+ userData = {};
853
+ destroyed = false;
854
+ allocatedBytes = 0;
855
+ _attachedResources = /* @__PURE__ */ new Set();
856
+ constructor(device, props, defaultProps) {
857
+ if (!device) {
858
+ throw new Error("no device");
859
+ }
860
+ this._device = device;
861
+ this.props = selectivelyMerge(props, defaultProps);
862
+ const id = this.props.id !== "undefined" ? this.props.id : uid(this[Symbol.toStringTag]);
863
+ this.props.id = id;
864
+ this.id = id;
865
+ this.userData = this.props.userData || {};
866
+ this.addStats();
867
+ }
868
+ destroy() {
869
+ this.destroyResource();
870
+ }
871
+ delete() {
872
+ this.destroy();
873
+ return this;
874
+ }
875
+ toString() {
876
+ return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
877
+ }
878
+ getProps() {
879
+ return this.props;
880
+ }
881
+ attachResource(resource) {
882
+ this._attachedResources.add(resource);
883
+ }
884
+ detachResource(resource) {
885
+ this._attachedResources.delete(resource);
886
+ }
887
+ destroyAttachedResource(resource) {
888
+ if (this._attachedResources.delete(resource)) {
889
+ resource.destroy();
890
+ }
891
+ }
892
+ destroyAttachedResources() {
893
+ for (const resource of Object.values(this._attachedResources)) {
894
+ resource.destroy();
895
+ }
896
+ this._attachedResources = /* @__PURE__ */ new Set();
897
+ }
898
+ destroyResource() {
899
+ this.destroyAttachedResources();
900
+ this.removeStats();
901
+ this.destroyed = true;
902
+ }
903
+ removeStats() {
904
+ const stats = this._device.statsManager.getStats("Resource Counts");
905
+ const name2 = this[Symbol.toStringTag];
906
+ stats.get(`${name2}s Active`).decrementCount();
907
+ }
908
+ trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
909
+ const stats = this._device.statsManager.getStats("Resource Counts");
910
+ stats.get("GPU Memory").addCount(bytes);
911
+ stats.get(`${name2} Memory`).addCount(bytes);
912
+ this.allocatedBytes = bytes;
913
+ }
914
+ trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
915
+ const stats = this._device.statsManager.getStats("Resource Counts");
916
+ stats.get("GPU Memory").subtractCount(this.allocatedBytes);
917
+ stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
918
+ this.allocatedBytes = 0;
919
+ }
920
+ addStats() {
921
+ const stats = this._device.statsManager.getStats("Resource Counts");
922
+ const name2 = this[Symbol.toStringTag];
923
+ stats.get("Resources Created").incrementCount();
924
+ stats.get(`${name2}s Created`).incrementCount();
925
+ stats.get(`${name2}s Active`).incrementCount();
926
+ }
927
+ };
928
+ __publicField(Resource, "defaultProps", {
929
+ id: "undefined",
930
+ handle: void 0,
931
+ userData: void 0
932
+ });
933
+ function selectivelyMerge(props, defaultProps) {
934
+ const mergedProps = {
935
+ ...defaultProps
936
+ };
937
+ for (const key in props) {
938
+ if (props[key] !== void 0) {
939
+ mergedProps[key] = props[key];
940
+ }
941
+ }
942
+ return mergedProps;
943
+ }
944
+
945
+ // ../core/src/adapter/resources/buffer.ts
946
+ var _Buffer = class extends Resource {
947
+ get [Symbol.toStringTag]() {
948
+ return "Buffer";
949
+ }
950
+ constructor(device, props) {
951
+ const deducedProps = {
952
+ ...props
953
+ };
954
+ if ((props.usage || 0) & _Buffer.INDEX && !props.indexType) {
955
+ if (props.data instanceof Uint32Array) {
956
+ deducedProps.indexType = "uint32";
957
+ } else if (props.data instanceof Uint16Array) {
958
+ deducedProps.indexType = "uint16";
959
+ }
960
+ }
961
+ super(device, deducedProps, _Buffer.defaultProps);
962
+ this.usage = props.usage || 0;
963
+ this.indexType = deducedProps.indexType;
964
+ }
965
+ write(data, byteOffset) {
966
+ throw new Error("not implemented");
967
+ }
968
+ readAsync(byteOffset, byteLength) {
969
+ throw new Error("not implemented");
970
+ }
971
+ getData() {
972
+ throw new Error("not implemented");
973
+ }
974
+ };
975
+ var Buffer2 = _Buffer;
976
+ __publicField(Buffer2, "defaultProps", {
977
+ ...Resource.defaultProps,
978
+ usage: 0,
979
+ byteLength: 0,
980
+ byteOffset: 0,
981
+ data: null,
982
+ indexType: "uint16",
983
+ mappedAtCreation: false
984
+ });
985
+ __publicField(Buffer2, "MAP_READ", 1);
986
+ __publicField(Buffer2, "MAP_WRITE", 2);
987
+ __publicField(Buffer2, "COPY_SRC", 4);
988
+ __publicField(Buffer2, "COPY_DST", 8);
989
+ __publicField(Buffer2, "INDEX", 16);
990
+ __publicField(Buffer2, "VERTEX", 32);
991
+ __publicField(Buffer2, "UNIFORM", 64);
992
+ __publicField(Buffer2, "STORAGE", 128);
993
+ __publicField(Buffer2, "INDIRECT", 256);
994
+ __publicField(Buffer2, "QUERY_RESOLVE", 512);
995
+
996
+ // ../core/src/adapter/device.ts
997
+ var _Device = class {
998
+ get [Symbol.toStringTag]() {
999
+ return "Device";
1000
+ }
1001
+ constructor(props) {
1002
+ this.props = {
1003
+ ..._Device.defaultProps,
1004
+ ...props
1005
+ };
1006
+ this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
1007
+ }
1008
+ statsManager = lumaStats;
1009
+ userData = {};
1010
+ _lumaData = {};
1011
+ loseDevice() {
1012
+ return false;
1013
+ }
1014
+ getCanvasContext() {
1015
+ if (!this.canvasContext) {
1016
+ throw new Error("Device has no CanvasContext");
1017
+ }
1018
+ return this.canvasContext;
1019
+ }
1020
+ createTexture(props) {
1021
+ if (props instanceof Promise || typeof props === "string") {
1022
+ props = {
1023
+ data: props
1024
+ };
1025
+ }
1026
+ return this._createTexture(props);
1027
+ }
1028
+ createCommandEncoder(props = {}) {
1029
+ throw new Error("not implemented");
1030
+ }
1031
+ _getBufferProps(props) {
1032
+ if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
1033
+ props = {
1034
+ data: props
1035
+ };
1036
+ }
1037
+ const newProps = {
1038
+ ...props
1039
+ };
1040
+ if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
1041
+ if (props.data instanceof Uint32Array) {
1042
+ newProps.indexType = "uint32";
1043
+ } else if (props.data instanceof Uint16Array) {
1044
+ newProps.indexType = "uint16";
1045
+ } else {
1046
+ log.warn("indices buffer content must be of integer type")();
1047
+ }
1048
+ }
1049
+ return newProps;
1050
+ }
1051
+ };
1052
+ var Device = _Device;
1053
+ __publicField(Device, "defaultProps", {
1054
+ id: null,
1055
+ type: "best-available",
1056
+ canvas: null,
1057
+ container: null,
1058
+ webgl2: true,
1059
+ webgl1: true,
1060
+ manageState: true,
1061
+ width: 800,
1062
+ height: 600,
1063
+ debug: Boolean(log.get("debug")),
1064
+ break: [],
1065
+ gl: null
1066
+ });
1067
+ __publicField(Device, "VERSION", VERSION2);
1068
+
1069
+ // ../core/src/adapter/canvas-context.ts
1070
+ var isPage = isBrowser() && typeof document !== "undefined";
1071
+ var isPageLoaded = () => isPage && document.readyState === "complete";
1072
+ var DEFAULT_CANVAS_CONTEXT_PROPS = {
1073
+ canvas: null,
1074
+ width: 800,
1075
+ height: 600,
1076
+ useDevicePixels: true,
1077
+ autoResize: true,
1078
+ container: null,
1079
+ visible: true,
1080
+ colorSpace: "srgb",
1081
+ alphaMode: "opaque"
1082
+ };
1083
+ var CanvasContext = class {
1084
+ width = 1;
1085
+ height = 1;
1086
+ _canvasSizeInfo = {
1087
+ clientWidth: 0,
1088
+ clientHeight: 0,
1089
+ devicePixelRatio: 1
1090
+ };
1091
+ static get isPageLoaded() {
1092
+ return isPageLoaded();
1093
+ }
1094
+ constructor(props) {
1095
+ this.props = {
1096
+ ...DEFAULT_CANVAS_CONTEXT_PROPS,
1097
+ ...props
1098
+ };
1099
+ props = this.props;
1100
+ if (!isBrowser()) {
1101
+ this.id = "node-canvas-context";
1102
+ this.type = "node";
1103
+ this.width = this.props.width;
1104
+ this.height = this.props.height;
1105
+ this.canvas = null;
1106
+ return;
1107
+ }
1108
+ if (!props.canvas) {
1109
+ const canvas = createCanvas(props);
1110
+ const container = getContainer(props?.container || null);
1111
+ container.insertBefore(canvas, container.firstChild);
1112
+ this.canvas = canvas;
1113
+ if (!props?.visible) {
1114
+ this.canvas.style.visibility = "hidden";
1115
+ }
1116
+ } else if (typeof props.canvas === "string") {
1117
+ this.canvas = getCanvasFromDOM(props.canvas);
1118
+ } else {
1119
+ this.canvas = props.canvas;
1120
+ }
1121
+ if (this.canvas instanceof HTMLCanvasElement) {
1122
+ this.id = this.canvas.id;
1123
+ this.type = "html-canvas";
1124
+ this.htmlCanvas = this.canvas;
1125
+ } else {
1126
+ this.id = "offscreen-canvas";
1127
+ this.type = "offscreen-canvas";
1128
+ this.offscreenCanvas = this.canvas;
1129
+ }
1130
+ if (this.canvas instanceof HTMLCanvasElement && props.autoResize) {
1131
+ this.resizeObserver = new ResizeObserver((entries) => {
1132
+ for (const entry of entries) {
1133
+ if (entry.target === this.canvas) {
1134
+ this.update();
1135
+ }
1136
+ }
1137
+ });
1138
+ this.resizeObserver.observe(this.canvas);
1139
+ }
1140
+ }
1141
+ getDevicePixelRatio(useDevicePixels) {
1142
+ if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
1143
+ return 1;
1144
+ }
1145
+ useDevicePixels = useDevicePixels === void 0 ? this.props.useDevicePixels : useDevicePixels;
1146
+ if (!useDevicePixels || useDevicePixels <= 0) {
1147
+ return 1;
1148
+ }
1149
+ if (useDevicePixels === true) {
1150
+ const dpr = typeof window !== "undefined" && window.devicePixelRatio;
1151
+ return dpr || 1;
1152
+ }
1153
+ return useDevicePixels;
1154
+ }
1155
+ getPixelSize() {
1156
+ switch (this.type) {
1157
+ case "node":
1158
+ return [this.width, this.height];
1159
+ case "offscreen-canvas":
1160
+ return [this.canvas.width, this.canvas.height];
1161
+ case "html-canvas":
1162
+ const dpr = this.getDevicePixelRatio();
1163
+ const canvas = this.canvas;
1164
+ return canvas.parentElement ? [canvas.clientWidth * dpr, canvas.clientHeight * dpr] : [this.canvas.width, this.canvas.height];
1165
+ default:
1166
+ throw new Error(this.type);
1167
+ }
1168
+ }
1169
+ getAspect() {
1170
+ const [width, height] = this.getPixelSize();
1171
+ return width / height;
1172
+ }
1173
+ cssToDeviceRatio() {
1174
+ try {
1175
+ const [drawingBufferWidth] = this.getDrawingBufferSize();
1176
+ const {
1177
+ clientWidth
1178
+ } = this._canvasSizeInfo;
1179
+ return clientWidth ? drawingBufferWidth / clientWidth : 1;
1180
+ } catch {
1181
+ return 1;
1182
+ }
1183
+ }
1184
+ cssToDevicePixels(cssPixel, yInvert = true) {
1185
+ const ratio = this.cssToDeviceRatio();
1186
+ const [width, height] = this.getDrawingBufferSize();
1187
+ return scalePixels(cssPixel, ratio, width, height, yInvert);
1188
+ }
1189
+ setDevicePixelRatio(devicePixelRatio, options = {}) {
1190
+ if (!this.htmlCanvas) {
1191
+ return;
1192
+ }
1193
+ let clientWidth = "width" in options ? options.width : this.htmlCanvas.clientWidth;
1194
+ let clientHeight = "height" in options ? options.height : this.htmlCanvas.clientHeight;
1195
+ if (!clientWidth || !clientHeight) {
1196
+ log.log(1, "Canvas clientWidth/clientHeight is 0")();
1197
+ devicePixelRatio = 1;
1198
+ clientWidth = this.htmlCanvas.width || 1;
1199
+ clientHeight = this.htmlCanvas.height || 1;
1200
+ }
1201
+ const cachedSize = this._canvasSizeInfo;
1202
+ if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio) {
1203
+ let clampedPixelRatio = devicePixelRatio;
1204
+ const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
1205
+ const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
1206
+ this.htmlCanvas.width = canvasWidth;
1207
+ this.htmlCanvas.height = canvasHeight;
1208
+ const [drawingBufferWidth, drawingBufferHeight] = this.getDrawingBufferSize();
1209
+ if (drawingBufferWidth !== canvasWidth || drawingBufferHeight !== canvasHeight) {
1210
+ clampedPixelRatio = Math.min(drawingBufferWidth / clientWidth, drawingBufferHeight / clientHeight);
1211
+ this.htmlCanvas.width = Math.floor(clientWidth * clampedPixelRatio);
1212
+ this.htmlCanvas.height = Math.floor(clientHeight * clampedPixelRatio);
1213
+ log.warn("Device pixel ratio clamped")();
1214
+ }
1215
+ this._canvasSizeInfo.clientWidth = clientWidth;
1216
+ this._canvasSizeInfo.clientHeight = clientHeight;
1217
+ this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
1218
+ }
1219
+ }
1220
+ getDrawingBufferSize() {
1221
+ const gl = this.device.gl;
1222
+ if (!gl) {
1223
+ throw new Error("canvas size");
1224
+ }
1225
+ return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1226
+ }
1227
+ _setAutoCreatedCanvasId(id) {
1228
+ if (this.htmlCanvas?.id === "lumagl-auto-created-canvas") {
1229
+ this.htmlCanvas.id = id;
1230
+ }
1231
+ }
1232
+ };
1233
+ __publicField(CanvasContext, "pageLoaded", getPageLoadPromise());
1234
+ function getPageLoadPromise() {
1235
+ if (isPageLoaded() || typeof window === "undefined") {
1236
+ return Promise.resolve();
1237
+ }
1238
+ return new Promise((resolve) => {
1239
+ window.addEventListener("load", () => resolve());
1240
+ });
1241
+ }
1242
+ function getContainer(container) {
1243
+ if (typeof container === "string") {
1244
+ const element = document.getElementById(container);
1245
+ if (!element && !isPageLoaded()) {
1246
+ throw new Error(`Accessing '${container}' before page was loaded`);
1247
+ }
1248
+ if (!element) {
1249
+ throw new Error(`${container} is not an HTML element`);
1250
+ }
1251
+ return element;
1252
+ } else if (container) {
1253
+ return container;
1254
+ }
1255
+ return document.body;
1256
+ }
1257
+ function getCanvasFromDOM(canvasId) {
1258
+ const canvas = document.getElementById(canvasId);
1259
+ if (!canvas && !isPageLoaded()) {
1260
+ throw new Error(`Accessing '${canvasId}' before page was loaded`);
1261
+ }
1262
+ if (!(canvas instanceof HTMLCanvasElement)) {
1263
+ throw new Error("Object is not a canvas element");
1264
+ }
1265
+ return canvas;
1266
+ }
1267
+ function createCanvas(props) {
1268
+ const {
1269
+ width,
1270
+ height
1271
+ } = props;
1272
+ const targetCanvas = document.createElement("canvas");
1273
+ targetCanvas.id = "lumagl-auto-created-canvas";
1274
+ targetCanvas.width = width || 1;
1275
+ targetCanvas.height = height || 1;
1276
+ targetCanvas.style.width = Number.isFinite(width) ? `${width}px` : "100%";
1277
+ targetCanvas.style.height = Number.isFinite(height) ? `${height}px` : "100%";
1278
+ return targetCanvas;
1279
+ }
1280
+ function scalePixels(pixel, ratio, width, height, yInvert) {
1281
+ const point = pixel;
1282
+ const x = scaleX(point[0], ratio, width);
1283
+ let y = scaleY(point[1], ratio, height, yInvert);
1284
+ let t = scaleX(point[0] + 1, ratio, width);
1285
+ const xHigh = t === width - 1 ? t : t - 1;
1286
+ t = scaleY(point[1] + 1, ratio, height, yInvert);
1287
+ let yHigh;
1288
+ if (yInvert) {
1289
+ t = t === 0 ? t : t + 1;
1290
+ yHigh = y;
1291
+ y = t;
1292
+ } else {
1293
+ yHigh = t === height - 1 ? t : t - 1;
1294
+ }
1295
+ return {
1296
+ x,
1297
+ y,
1298
+ width: Math.max(xHigh - x + 1, 1),
1299
+ height: Math.max(yHigh - y + 1, 1)
1300
+ };
1301
+ }
1302
+ function scaleX(x, ratio, width) {
1303
+ const r = Math.min(Math.round(x * ratio), width - 1);
1304
+ return r;
1305
+ }
1306
+ function scaleY(y, ratio, height, yInvert) {
1307
+ return yInvert ? Math.max(0, height - 1 - Math.round(y * ratio)) : Math.min(Math.round(y * ratio), height - 1);
1308
+ }
1309
+
1310
+ // ../core/src/adapter/resources/texture.ts
1311
+ var _Texture = class extends Resource {
1312
+ get [Symbol.toStringTag]() {
1313
+ return "Texture";
1314
+ }
1315
+ constructor(device, props, defaultProps = _Texture.defaultProps) {
1316
+ super(device, props, defaultProps);
1317
+ this.dimension = this.props.dimension;
1318
+ this.format = this.props.format;
1319
+ this.width = this.props.width;
1320
+ this.height = this.props.height;
1321
+ this.depth = this.props.depth;
1322
+ }
1323
+ };
1324
+ var Texture = _Texture;
1325
+ __publicField(Texture, "defaultProps", {
1326
+ ...Resource.defaultProps,
1327
+ data: null,
1328
+ dimension: "2d",
1329
+ format: "rgba8unorm",
1330
+ width: void 0,
1331
+ height: void 0,
1332
+ depth: 1,
1333
+ mipmaps: true,
1334
+ sampler: {},
1335
+ compressed: false,
1336
+ usage: 0,
1337
+ mipLevels: void 0,
1338
+ samples: void 0,
1339
+ type: void 0
1340
+ });
1341
+ __publicField(Texture, "COPY_SRC", 1);
1342
+ __publicField(Texture, "COPY_DST", 2);
1343
+ __publicField(Texture, "TEXTURE_BINDING", 4);
1344
+ __publicField(Texture, "STORAGE_BINDING", 8);
1345
+ __publicField(Texture, "RENDER_ATTACHMENT", 16);
1346
+
1347
+ // ../core/src/adapter/resources/external-texture.ts
1348
+ var _ExternalTexture = class extends Resource {
1349
+ get [Symbol.toStringTag]() {
1350
+ return "ExternalTexture";
1351
+ }
1352
+ constructor(device, props) {
1353
+ super(device, props, _ExternalTexture.defaultProps);
1354
+ }
1355
+ };
1356
+ var ExternalTexture = _ExternalTexture;
1357
+ __publicField(ExternalTexture, "defaultProps", {
1358
+ ...Resource.defaultProps,
1359
+ source: null,
1360
+ colorSpace: "srgb"
1361
+ });
1362
+
1363
+ // ../core/src/adapter/resources/shader.ts
1364
+ var _Shader = class extends Resource {
1365
+ get [Symbol.toStringTag]() {
1366
+ return "Shader";
1367
+ }
1368
+ constructor(device, props) {
1369
+ super(device, props, _Shader.defaultProps);
1370
+ this.stage = this.props.stage;
1371
+ this.source = this.props.source;
1372
+ }
1373
+ };
1374
+ var Shader = _Shader;
1375
+ __publicField(Shader, "defaultProps", {
1376
+ ...Resource.defaultProps,
1377
+ stage: "vertex",
1378
+ source: "",
1379
+ sourceMap: null,
1380
+ language: "auto",
1381
+ shaderType: 0
1382
+ });
1383
+
1384
+ // ../core/src/adapter/resources/sampler.ts
1385
+ var _Sampler = class extends Resource {
1386
+ get [Symbol.toStringTag]() {
1387
+ return "Sampler";
1388
+ }
1389
+ constructor(device, props) {
1390
+ super(device, props, _Sampler.defaultProps);
1391
+ }
1392
+ };
1393
+ var Sampler = _Sampler;
1394
+ __publicField(Sampler, "defaultProps", {
1395
+ ...Resource.defaultProps,
1396
+ type: "color-sampler",
1397
+ addressModeU: "clamp-to-edge",
1398
+ addressModeV: "clamp-to-edge",
1399
+ addressModeW: "clamp-to-edge",
1400
+ magFilter: "nearest",
1401
+ minFilter: "nearest",
1402
+ mipmapFilter: "nearest",
1403
+ lodMinClamp: 0,
1404
+ lodMaxClamp: 32,
1405
+ compare: "less-equal",
1406
+ maxAnisotropy: 1
1407
+ });
1408
+
1409
+ // ../core/src/adapter/resources/framebuffer.ts
1410
+ var _Framebuffer = class extends Resource {
1411
+ get [Symbol.toStringTag]() {
1412
+ return "Framebuffer";
1413
+ }
1414
+ colorAttachments = [];
1415
+ depthStencilAttachment = null;
1416
+ constructor(device, props = {}) {
1417
+ super(device, props, _Framebuffer.defaultProps);
1418
+ this.width = this.props.width;
1419
+ this.height = this.props.height;
1420
+ }
1421
+ resize(size) {
1422
+ let updateSize = !size;
1423
+ if (size) {
1424
+ const [width, height] = Array.isArray(size) ? size : [size.width, size.height];
1425
+ updateSize = updateSize || height !== this.height || width !== this.width;
1426
+ this.width = width;
1427
+ this.height = height;
1428
+ }
1429
+ if (updateSize) {
1430
+ log.log(2, `Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)();
1431
+ this.resizeAttachments(this.width, this.height);
1432
+ }
1433
+ }
1434
+ autoCreateAttachmentTextures() {
1435
+ this.colorAttachments = this.props.colorAttachments.map((attachment) => {
1436
+ if (typeof attachment === "string") {
1437
+ const texture = this.createColorTexture(attachment);
1438
+ this.attachResource(texture);
1439
+ return texture;
1440
+ }
1441
+ return attachment;
1442
+ });
1443
+ if (this.props.depthStencilAttachment) {
1444
+ if (typeof this.props.depthStencilAttachment === "string") {
1445
+ const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);
1446
+ this.attachResource(texture);
1447
+ this.depthStencilAttachment = texture;
1448
+ } else {
1449
+ this.depthStencilAttachment = this.props.depthStencilAttachment;
1450
+ }
1451
+ }
1452
+ }
1453
+ createColorTexture(format) {
1454
+ return this.device.createTexture({
1455
+ id: "color-attachment",
1456
+ usage: Texture.RENDER_ATTACHMENT,
1457
+ format,
1458
+ width: this.width,
1459
+ height: this.height
1460
+ });
1461
+ }
1462
+ createDepthStencilTexture(format) {
1463
+ return this.device.createTexture({
1464
+ id: "depth-stencil-attachment",
1465
+ usage: Texture.RENDER_ATTACHMENT,
1466
+ format,
1467
+ width: this.width,
1468
+ height: this.height
1469
+ });
1470
+ }
1471
+ resizeAttachments(width, height) {
1472
+ for (let i = 0; i < this.colorAttachments.length; ++i) {
1473
+ if (this.colorAttachments[i]) {
1474
+ const resizedTexture = this.device._createTexture({
1475
+ ...this.colorAttachments[i].props,
1476
+ width,
1477
+ height
1478
+ });
1479
+ this.destroyAttachedResource(this.colorAttachments[i]);
1480
+ this.colorAttachments[i] = resizedTexture;
1481
+ this.attachResource(resizedTexture);
1482
+ }
1483
+ }
1484
+ if (this.depthStencilAttachment) {
1485
+ const resizedTexture = this.device._createTexture({
1486
+ ...this.depthStencilAttachment.props,
1487
+ width,
1488
+ height
1489
+ });
1490
+ this.destroyAttachedResource(this.depthStencilAttachment);
1491
+ this.depthStencilAttachment = resizedTexture;
1492
+ this.attachResource(resizedTexture);
1493
+ }
1494
+ }
1495
+ };
1496
+ var Framebuffer = _Framebuffer;
1497
+ __publicField(Framebuffer, "defaultProps", {
1498
+ ...Resource.defaultProps,
1499
+ width: 1,
1500
+ height: 1,
1501
+ colorAttachments: [],
1502
+ depthStencilAttachment: null
1503
+ });
1504
+
1505
+ // ../core/src/adapter/resources/render-pipeline.ts
1506
+ var _RenderPipeline = class extends Resource {
1507
+ get [Symbol.toStringTag]() {
1508
+ return "RenderPipeline";
1509
+ }
1510
+ hash = "";
1511
+ constructor(device, props) {
1512
+ super(device, props, _RenderPipeline.defaultProps);
1513
+ this.shaderLayout = this.props.shaderLayout;
1514
+ this.bufferLayout = this.props.bufferLayout || [];
1515
+ }
1516
+ };
1517
+ var RenderPipeline = _RenderPipeline;
1518
+ __publicField(RenderPipeline, "defaultProps", {
1519
+ ...Resource.defaultProps,
1520
+ vs: null,
1521
+ vsEntryPoint: "",
1522
+ vsConstants: {},
1523
+ fs: null,
1524
+ fsEntryPoint: "",
1525
+ fsConstants: {},
1526
+ shaderLayout: null,
1527
+ bufferLayout: [],
1528
+ topology: "triangle-list",
1529
+ parameters: {},
1530
+ vertexCount: 0,
1531
+ instanceCount: 0,
1532
+ bindings: {},
1533
+ uniforms: {}
1534
+ });
1535
+
1536
+ // ../core/src/adapter/resources/compute-pipeline.ts
1537
+ var _ComputePipeline = class extends Resource {
1538
+ get [Symbol.toStringTag]() {
1539
+ return "ComputePipeline";
1540
+ }
1541
+ hash = "";
1542
+ constructor(device, props) {
1543
+ super(device, props, _ComputePipeline.defaultProps);
1544
+ }
1545
+ };
1546
+ var ComputePipeline = _ComputePipeline;
1547
+ __publicField(ComputePipeline, "defaultProps", {
1548
+ ...Resource.defaultProps,
1549
+ cs: void 0,
1550
+ csEntryPoint: void 0,
1551
+ csConstants: {},
1552
+ shaderLayout: []
1553
+ });
1554
+
1555
+ // ../core/src/adapter/resources/render-pass.ts
1556
+ var _RenderPass = class extends Resource {
1557
+ get [Symbol.toStringTag]() {
1558
+ return "RenderPass";
1559
+ }
1560
+ constructor(device, props) {
1561
+ super(device, props, _RenderPass.defaultProps);
1562
+ }
1563
+ };
1564
+ var RenderPass = _RenderPass;
1565
+ __publicField(RenderPass, "defaultProps", {
1566
+ ...Resource.defaultProps,
1567
+ framebuffer: null,
1568
+ parameters: void 0,
1569
+ clearColor: [0, 0, 0, 0],
1570
+ clearDepth: 1,
1571
+ clearStencil: 0,
1572
+ depthReadOnly: false,
1573
+ stencilReadOnly: false,
1574
+ discard: false
1575
+ });
1576
+
1577
+ // ../core/src/adapter/resources/compute-pass.ts
1578
+ var ComputePass = class extends Resource {
1579
+ get [Symbol.toStringTag]() {
1580
+ return "ComputePass";
1581
+ }
1582
+ constructor(device, props) {
1583
+ super(device, props, Resource.defaultProps);
1584
+ }
1585
+ };
1586
+ __publicField(ComputePass, "defaultProps", {
1587
+ ...Resource.defaultProps
1588
+ });
1589
+
1590
+ // ../core/src/adapter/type-utils/decode-attribute-type.ts
1591
+ function decodeShaderAttributeType(attributeType) {
1592
+ const [dataType, components] = TYPE_INFO[attributeType];
1593
+ const integer = dataType === "i32" || dataType === "u32";
1594
+ const signed = dataType !== "u32";
1595
+ const byteLength = TYPE_SIZES[dataType] * components;
1596
+ const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
1597
+ return {
1598
+ dataType,
1599
+ components,
1600
+ defaultVertexFormat,
1601
+ byteLength,
1602
+ integer,
1603
+ signed
1604
+ };
1605
+ }
1606
+ function getCompatibleVertexFormat(dataType, components) {
1607
+ let vertexType;
1608
+ switch (dataType) {
1609
+ case "f32":
1610
+ vertexType = "float32";
1611
+ break;
1612
+ case "i32":
1613
+ vertexType = "sint32";
1614
+ break;
1615
+ case "u32":
1616
+ vertexType = "uint32";
1617
+ break;
1618
+ case "f16":
1619
+ return components <= 2 ? "float16x2" : "float16x4";
1620
+ }
1621
+ if (components === 1) {
1622
+ return vertexType;
1623
+ }
1624
+ return `${vertexType}x${components}`;
1625
+ }
1626
+ var TYPE_INFO = {
1627
+ f32: ["f32", 1],
1628
+ "vec2<f32>": ["f32", 2],
1629
+ "vec3<f32>": ["f32", 3],
1630
+ "vec4<f32>": ["f32", 4],
1631
+ f16: ["f16", 1],
1632
+ "vec2<f16>": ["f16", 2],
1633
+ "vec3<f16>": ["f16", 3],
1634
+ "vec4<f16>": ["f16", 4],
1635
+ i32: ["i32", 1],
1636
+ "vec2<i32>": ["i32", 2],
1637
+ "vec3<i32>": ["i32", 3],
1638
+ "vec4<i32>": ["i32", 4],
1639
+ u32: ["u32", 1],
1640
+ "vec2<u32>": ["u32", 2],
1641
+ "vec3<u32>": ["u32", 3],
1642
+ "vec4<u32>": ["u32", 4]
1643
+ };
1644
+ var TYPE_SIZES = {
1645
+ f32: 4,
1646
+ f16: 2,
1647
+ i32: 4,
1648
+ u32: 4
1649
+ };
1650
+
1651
+ // ../core/src/adapter/type-utils/decode-data-type.ts
1652
+ function decodeVertexType(type) {
1653
+ const dataType = TYPE_MAP[type];
1654
+ const bytes = getDataTypeBytes(dataType);
1655
+ const normalized = type.includes("norm");
1656
+ const integer = !normalized && !type.startsWith("float");
1657
+ const signed = type.startsWith("s");
1658
+ return {
1659
+ dataType: TYPE_MAP[type],
1660
+ byteLength: bytes,
1661
+ integer,
1662
+ signed,
1663
+ normalized
1664
+ };
1665
+ }
1666
+ function getDataTypeBytes(type) {
1667
+ const bytes = TYPE_SIZES2[type];
1668
+ return bytes;
1669
+ }
1670
+ var TYPE_MAP = {
1671
+ uint8: "uint8",
1672
+ sint8: "sint8",
1673
+ unorm8: "uint8",
1674
+ snorm8: "sint8",
1675
+ uint16: "uint16",
1676
+ sint16: "sint16",
1677
+ unorm16: "uint16",
1678
+ snorm16: "sint16",
1679
+ float16: "float16",
1680
+ float32: "float32",
1681
+ uint32: "uint32",
1682
+ sint32: "sint32"
1683
+ };
1684
+ var TYPE_SIZES2 = {
1685
+ uint8: 1,
1686
+ sint8: 1,
1687
+ uint16: 2,
1688
+ sint16: 2,
1689
+ float16: 2,
1690
+ float32: 4,
1691
+ uint32: 4,
1692
+ sint32: 4
1693
+ };
1694
+
1695
+ // ../core/src/adapter/type-utils/decode-vertex-format.ts
1696
+ function decodeVertexFormat(format) {
1697
+ let webglOnly;
1698
+ if (format.endsWith("-webgl")) {
1699
+ format.replace("-webgl", "");
1700
+ webglOnly = true;
1701
+ }
1702
+ const [type_, count] = format.split("x");
1703
+ const type = type_;
1704
+ const components = count ? parseInt(count) : 1;
1705
+ const decodedType = decodeVertexType(type);
1706
+ const result = {
1707
+ type,
1708
+ components,
1709
+ byteLength: decodedType.byteLength * components,
1710
+ integer: decodedType.integer,
1711
+ signed: decodedType.signed,
1712
+ normalized: decodedType.normalized
1713
+ };
1714
+ if (webglOnly) {
1715
+ result.webglOnly = true;
1716
+ }
1717
+ return result;
1718
+ }
1719
+
1720
+ // ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
1721
+ function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
1722
+ const attributeInfos = {};
1723
+ for (const attribute of shaderLayout.attributes) {
1724
+ attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
1725
+ }
1726
+ return attributeInfos;
1727
+ }
1728
+ function getAttributeInfosByLocation(shaderLayout, bufferLayout, maxVertexAttributes = 16) {
1729
+ const attributeInfos = getAttributeInfosFromLayouts(shaderLayout, bufferLayout);
1730
+ const locationInfos = new Array(maxVertexAttributes).fill(null);
1731
+ for (const attributeInfo of Object.values(attributeInfos)) {
1732
+ locationInfos[attributeInfo.location] = attributeInfo;
1733
+ }
1734
+ return locationInfos;
1735
+ }
1736
+ function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
1737
+ const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
1738
+ const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
1739
+ if (!shaderDeclaration) {
1740
+ return null;
1741
+ }
1742
+ const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
1743
+ const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
1744
+ const vertexFormatInfo = decodeVertexFormat(vertexFormat);
1745
+ return {
1746
+ attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
1747
+ bufferName: bufferMapping?.bufferName || shaderDeclaration.name,
1748
+ location: shaderDeclaration.location,
1749
+ shaderType: shaderDeclaration.type,
1750
+ shaderDataType: attributeTypeInfo.dataType,
1751
+ shaderComponents: attributeTypeInfo.components,
1752
+ vertexFormat,
1753
+ bufferDataType: vertexFormatInfo.type,
1754
+ bufferComponents: vertexFormatInfo.components,
1755
+ normalized: vertexFormatInfo.normalized,
1756
+ integer: attributeTypeInfo.integer,
1757
+ stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
1758
+ byteOffset: bufferMapping?.byteOffset || 0,
1759
+ byteStride: bufferMapping?.byteStride || 0
1760
+ };
1761
+ }
1762
+ function getAttributeFromShaderLayout(shaderLayout, name2) {
1763
+ const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
1764
+ if (!attribute) {
1765
+ log.warn(`shader layout attribute "${name2}" not present in shader`);
1766
+ }
1767
+ return attribute || null;
1768
+ }
1769
+ function getAttributeFromBufferLayout(bufferLayouts, name2) {
1770
+ checkBufferLayouts(bufferLayouts);
1771
+ let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name2);
1772
+ if (bufferLayoutInfo) {
1773
+ return bufferLayoutInfo;
1774
+ }
1775
+ bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name2);
1776
+ if (bufferLayoutInfo) {
1777
+ return bufferLayoutInfo;
1778
+ }
1779
+ log.warn(`layout for attribute "${name2}" not present in buffer layout`);
1780
+ return null;
1781
+ }
1782
+ function checkBufferLayouts(bufferLayouts) {
1783
+ for (const bufferLayout of bufferLayouts) {
1784
+ if (bufferLayout.attributes && bufferLayout.format || !bufferLayout.attributes && !bufferLayout.format) {
1785
+ log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);
1786
+ }
1787
+ }
1788
+ }
1789
+ function getAttributeFromShortHand(bufferLayouts, name2) {
1790
+ for (const bufferLayout of bufferLayouts) {
1791
+ if (bufferLayout.format && bufferLayout.name === name2) {
1792
+ return {
1793
+ attributeName: bufferLayout.name,
1794
+ bufferName: name2,
1795
+ stepMode: bufferLayout.stepMode,
1796
+ vertexFormat: bufferLayout.format,
1797
+ byteOffset: 0,
1798
+ byteStride: bufferLayout.byteStride || 0
1799
+ };
1800
+ }
1801
+ }
1802
+ return null;
1803
+ }
1804
+ function getAttributeFromAttributesList(bufferLayouts, name2) {
1805
+ for (const bufferLayout of bufferLayouts) {
1806
+ let byteStride = bufferLayout.byteStride;
1807
+ if (typeof bufferLayout.byteStride !== "number") {
1808
+ for (const attributeMapping2 of bufferLayout.attributes || []) {
1809
+ const info = decodeVertexFormat(attributeMapping2.format);
1810
+ byteStride += info.byteLength;
1811
+ }
1812
+ }
1813
+ const attributeMapping = bufferLayout.attributes?.find((mapping) => mapping.attribute === name2);
1814
+ if (attributeMapping) {
1815
+ return {
1816
+ attributeName: attributeMapping.attribute,
1817
+ bufferName: bufferLayout.name,
1818
+ stepMode: bufferLayout.stepMode,
1819
+ vertexFormat: attributeMapping.format,
1820
+ byteOffset: attributeMapping.byteOffset,
1821
+ byteStride
1822
+ };
1823
+ }
1824
+ }
1825
+ return null;
1826
+ }
1827
+
1828
+ // ../core/src/adapter/resources/vertex-array.ts
1829
+ var _VertexArray = class extends Resource {
1830
+ get [Symbol.toStringTag]() {
1831
+ return "VertexArray";
1832
+ }
1833
+ indexBuffer = null;
1834
+ constructor(device, props) {
1835
+ super(device, props, _VertexArray.defaultProps);
1836
+ this.maxVertexAttributes = device.limits.maxVertexAttributes;
1837
+ this.attributes = new Array(this.maxVertexAttributes).fill(null);
1838
+ this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
1839
+ }
1840
+ };
1841
+ var VertexArray = _VertexArray;
1842
+ __publicField(VertexArray, "defaultProps", {
1843
+ ...Resource.defaultProps,
1844
+ renderPipeline: null
1845
+ });
1846
+
1847
+ // ../core/src/lib/utils/cast.ts
1848
+ function cast(value) {
1849
+ return value;
1850
+ }
1851
+
1852
+ // src/adapter/resources/webgpu-buffer.ts
1853
+ function getByteLength(props) {
1854
+ return props.byteLength || props.data?.byteLength || 0;
1855
+ }
1856
+ var WebGPUBuffer = class extends Buffer2 {
1857
+ constructor(device, props) {
1858
+ super(device, props);
1859
+ this.device = device;
1860
+ this.byteLength = getByteLength(props);
1861
+ const mapBuffer = Boolean(props.data);
1862
+ const size = Math.ceil(this.byteLength / 4) * 4;
1863
+ this.handle = this.props.handle || this.device.handle.createBuffer({
1864
+ size,
1865
+ usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
1866
+ mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
1867
+ label: this.props.id
1868
+ });
1869
+ if (props.data) {
1870
+ this._writeMapped(props.data);
1871
+ }
1872
+ if (mapBuffer && !props.mappedAtCreation) {
1873
+ this.handle.unmap();
1874
+ }
1875
+ }
1876
+ destroy() {
1877
+ this.handle.destroy();
1878
+ }
1879
+ write(data, byteOffset = 0) {
1880
+ this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
1881
+ }
1882
+ async readAsync(byteOffset = 0, byteLength = this.byteLength) {
1883
+ const tempBuffer = new WebGPUBuffer(this.device, {
1884
+ usage: Buffer2.MAP_READ | Buffer2.COPY_DST,
1885
+ byteLength
1886
+ });
1887
+ const commandEncoder = this.device.handle.createCommandEncoder();
1888
+ commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
1889
+ this.device.handle.queue.submit([commandEncoder.finish()]);
1890
+ await tempBuffer.handle.mapAsync(GPUMapMode.READ, byteOffset, byteLength);
1891
+ const arrayBuffer = tempBuffer.handle.getMappedRange().slice(0);
1892
+ tempBuffer.handle.unmap();
1893
+ tempBuffer.destroy();
1894
+ return new Uint8Array(arrayBuffer);
1895
+ }
1896
+ _writeMapped(typedArray) {
1897
+ const arrayBuffer = this.handle.getMappedRange();
1898
+ new typedArray.constructor(arrayBuffer).set(typedArray);
1899
+ }
1900
+ mapAsync(mode, offset = 0, size) {
1901
+ return this.handle.mapAsync(mode, offset, size);
1902
+ }
1903
+ getMappedRange(offset = 0, size) {
1904
+ return this.handle.getMappedRange(offset, size);
1905
+ }
1906
+ unmap() {
1907
+ this.handle.unmap();
1908
+ }
1909
+ };
1910
+
1911
+ // src/adapter/helpers/convert-texture-format.ts
1912
+ function getWebGPUTextureFormat(format) {
1913
+ if (format.includes("webgl")) {
1914
+ throw new Error("webgl-only format");
1915
+ }
1916
+ return format;
1917
+ }
1918
+
1919
+ // src/adapter/resources/webgpu-sampler.ts
1920
+ var WebGPUSampler = class extends Sampler {
1921
+ constructor(device, props) {
1922
+ super(device, props);
1923
+ this.device = device;
1924
+ const samplerProps = {
1925
+ ...this.props
1926
+ };
1927
+ if (samplerProps.type !== "comparison-sampler") {
1928
+ delete samplerProps.compare;
1929
+ }
1930
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
1931
+ this.handle.label = this.props.id;
1932
+ }
1933
+ destroy() {
1934
+ }
1935
+ };
1936
+
1937
+ // src/adapter/resources/webgpu-texture.ts
1938
+ var BASE_DIMENSIONS = {
1939
+ "1d": "1d",
1940
+ "2d": "2d",
1941
+ "2d-array": "2d",
1942
+ "cube": "2d",
1943
+ "cube-array": "2d",
1944
+ "3d": "3d"
1945
+ };
1946
+ var WebGPUTexture = class extends Texture {
1947
+ height = 1;
1948
+ width = 1;
1949
+ constructor(device, props) {
1950
+ super(device, props);
1951
+ if (typeof this.props.format === "number") {
1952
+ throw new Error("number format");
1953
+ }
1954
+ this.device = device;
1955
+ this.handle = this.props.handle || this.createHandle();
1956
+ if (this.props.data) {
1957
+ this.setData({
1958
+ data: this.props.data
1959
+ });
1960
+ }
1961
+ this.width = this.handle.width;
1962
+ this.height = this.handle.height;
1963
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
1964
+ this.view = this.handle.createView({});
1965
+ }
1966
+ createHandle() {
1967
+ if (typeof this.props.format === "number") {
1968
+ throw new Error("number format");
1969
+ }
1970
+ const width = this.props.width || this.props.data?.width || 1;
1971
+ const height = this.props.height || this.props.data?.height || 1;
1972
+ return this.device.handle.createTexture({
1973
+ size: {
1974
+ width,
1975
+ height,
1976
+ depthOrArrayLayers: this.props.depth
1977
+ },
1978
+ dimension: BASE_DIMENSIONS[this.props.dimension],
1979
+ format: getWebGPUTextureFormat(this.props.format),
1980
+ usage: this.props.usage,
1981
+ mipLevelCount: this.props.mipLevels,
1982
+ sampleCount: this.props.samples
1983
+ });
1984
+ }
1985
+ destroy() {
1986
+ this.handle.destroy();
1987
+ }
1988
+ setSampler(sampler) {
1989
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
1990
+ return this;
1991
+ }
1992
+ setData(options) {
1993
+ return this.setImage({
1994
+ source: options.data
1995
+ });
1996
+ }
1997
+ setImage(options) {
1998
+ const {
1999
+ source,
2000
+ width = options.source.width,
2001
+ height = options.source.height,
2002
+ depth = 1,
2003
+ sourceX = 0,
2004
+ sourceY = 0,
2005
+ mipLevel = 0,
2006
+ x = 0,
2007
+ y = 0,
2008
+ z = 0,
2009
+ aspect = "all",
2010
+ colorSpace = "srgb",
2011
+ premultipliedAlpha = false
2012
+ } = options;
2013
+ this.device.handle.queue.copyExternalImageToTexture({
2014
+ source,
2015
+ origin: [sourceX, sourceY]
2016
+ }, {
2017
+ texture: this.handle,
2018
+ origin: [x, y, z],
2019
+ mipLevel,
2020
+ aspect,
2021
+ colorSpace,
2022
+ premultipliedAlpha
2023
+ }, [width, height, depth]);
2024
+ return {
2025
+ width,
2026
+ height
2027
+ };
2028
+ }
2029
+ };
2030
+
2031
+ // src/adapter/resources/webgpu-external-texture.ts
2032
+ var WebGPUExternalTexture = class extends ExternalTexture {
2033
+ constructor(device, props) {
2034
+ super(device, props);
2035
+ this.device = device;
2036
+ this.handle = this.props.handle || this.device.handle.importExternalTexture({
2037
+ source: props.source,
2038
+ colorSpace: props.colorSpace
2039
+ });
2040
+ this.sampler = null;
2041
+ }
2042
+ destroy() {
2043
+ }
2044
+ setSampler(sampler) {
2045
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
2046
+ return this;
2047
+ }
2048
+ };
2049
+
2050
+ // src/adapter/resources/webgpu-shader.ts
2051
+ var WebGPUShader = class extends Shader {
2052
+ constructor(device, props) {
2053
+ super(device, props);
2054
+ this.device = device;
2055
+ this.device.handle.pushErrorScope("validation");
2056
+ this.handle = this.props.handle || this.createHandle();
2057
+ this.handle.label = this.props.id;
2058
+ this._checkCompilationError(this.device.handle.popErrorScope());
2059
+ }
2060
+ async _checkCompilationError(errorScope) {
2061
+ const error = await errorScope;
2062
+ if (error) {
2063
+ const shaderLog = await this.compilationInfo();
2064
+ log.error(`Shader compilation error: ${error.message}`, shaderLog)();
2065
+ throw new Error(`Shader compilation error: ${error.message}`);
2066
+ }
2067
+ }
2068
+ destroy() {
2069
+ }
2070
+ createHandle() {
2071
+ const {
2072
+ source,
2073
+ stage
2074
+ } = this.props;
2075
+ let language = this.props.language;
2076
+ if (language === "auto") {
2077
+ language = source.includes("->") ? "wgsl" : "glsl";
2078
+ }
2079
+ switch (language) {
2080
+ case "wgsl":
2081
+ return this.device.handle.createShaderModule({
2082
+ code: source
2083
+ });
2084
+ case "glsl":
2085
+ return this.device.handle.createShaderModule({
2086
+ code: source,
2087
+ transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
2088
+ });
2089
+ default:
2090
+ throw new Error(language);
2091
+ }
2092
+ }
2093
+ async compilationInfo() {
2094
+ const compilationInfo = await this.handle.getCompilationInfo();
2095
+ return compilationInfo.messages;
2096
+ }
2097
+ };
2098
+
2099
+ // src/adapter/helpers/webgpu-parameters.ts
2100
+ function addDepthStencil(descriptor) {
2101
+ descriptor.depthStencil = descriptor.depthStencil || {
2102
+ format: "depth24plus",
2103
+ stencilFront: {},
2104
+ stencilBack: {},
2105
+ depthWriteEnabled: false,
2106
+ depthCompare: "less-equal"
2107
+ };
2108
+ return descriptor.depthStencil;
2109
+ }
2110
+ var PARAMETER_TABLE = {
2111
+ cullMode: (parameter, value, descriptor) => {
2112
+ descriptor.primitive = descriptor.primitive || {};
2113
+ descriptor.primitive.cullMode = value;
2114
+ },
2115
+ frontFace: (parameter, value, descriptor) => {
2116
+ descriptor.primitive = descriptor.primitive || {};
2117
+ descriptor.primitive.frontFace = value;
2118
+ },
2119
+ depthWriteEnabled: (parameter, value, descriptor) => {
2120
+ const depthStencil = addDepthStencil(descriptor);
2121
+ depthStencil.depthWriteEnabled = value;
2122
+ },
2123
+ depthCompare: (parameter, value, descriptor) => {
2124
+ const depthStencil = addDepthStencil(descriptor);
2125
+ depthStencil.depthCompare = value;
2126
+ },
2127
+ depthFormat: (parameter, value, descriptor) => {
2128
+ const depthStencil = addDepthStencil(descriptor);
2129
+ depthStencil.format = value;
2130
+ },
2131
+ depthBias: (parameter, value, descriptor) => {
2132
+ const depthStencil = addDepthStencil(descriptor);
2133
+ depthStencil.depthBias = value;
2134
+ },
2135
+ depthBiasSlopeScale: (parameter, value, descriptor) => {
2136
+ const depthStencil = addDepthStencil(descriptor);
2137
+ depthStencil.depthBiasSlopeScale = value;
2138
+ },
2139
+ depthBiasClamp: (parameter, value, descriptor) => {
2140
+ const depthStencil = addDepthStencil(descriptor);
2141
+ depthStencil.depthBiasClamp = value;
2142
+ },
2143
+ stencilReadMask: (parameter, value, descriptor) => {
2144
+ const depthStencil = addDepthStencil(descriptor);
2145
+ depthStencil.stencilReadMask = value;
2146
+ },
2147
+ stencilWriteMask: (parameter, value, descriptor) => {
2148
+ const depthStencil = addDepthStencil(descriptor);
2149
+ depthStencil.stencilWriteMask = value;
2150
+ },
2151
+ stencilCompare: (parameter, value, descriptor) => {
2152
+ const depthStencil = addDepthStencil(descriptor);
2153
+ depthStencil.stencilFront.compare = value;
2154
+ depthStencil.stencilBack.compare = value;
2155
+ },
2156
+ stencilPassOperation: (parameter, value, descriptor) => {
2157
+ const depthStencil = addDepthStencil(descriptor);
2158
+ depthStencil.stencilFront.passOp = value;
2159
+ depthStencil.stencilBack.passOp = value;
2160
+ },
2161
+ stencilFailOperation: (parameter, value, descriptor) => {
2162
+ const depthStencil = addDepthStencil(descriptor);
2163
+ depthStencil.stencilFront.failOp = value;
2164
+ depthStencil.stencilBack.failOp = value;
2165
+ },
2166
+ stencilDepthFailOperation: (parameter, value, descriptor) => {
2167
+ const depthStencil = addDepthStencil(descriptor);
2168
+ depthStencil.stencilFront.depthFailOp = value;
2169
+ depthStencil.stencilBack.depthFailOp = value;
2170
+ },
2171
+ sampleCount: (parameter, value, descriptor) => {
2172
+ descriptor.multisample = descriptor.multisample || {};
2173
+ descriptor.multisample.count = value;
2174
+ },
2175
+ sampleMask: (parameter, value, descriptor) => {
2176
+ descriptor.multisample = descriptor.multisample || {};
2177
+ descriptor.multisample.mask = value;
2178
+ },
2179
+ sampleAlphaToCoverageEnabled: (parameter, value, descriptor) => {
2180
+ descriptor.multisample = descriptor.multisample || {};
2181
+ descriptor.multisample.alphaToCoverageEnabled = value;
2182
+ },
2183
+ colorMask: (parameter, value, descriptor) => {
2184
+ const targets = addColorState(descriptor);
2185
+ targets[0].writeMask = value;
2186
+ },
2187
+ blendColorOperation: (parameter, value, descriptor) => {
2188
+ addColorState(descriptor);
2189
+ }
2190
+ };
2191
+ var DEFAULT_PIPELINE_DESCRIPTOR = {
2192
+ primitive: {
2193
+ cullMode: "back",
2194
+ topology: "triangle-list"
2195
+ },
2196
+ vertex: {
2197
+ module: void 0,
2198
+ entryPoint: "main"
2199
+ },
2200
+ fragment: {
2201
+ module: void 0,
2202
+ entryPoint: "main",
2203
+ targets: []
2204
+ },
2205
+ layout: "auto"
2206
+ };
2207
+ function applyParametersToRenderPipelineDescriptor(pipelineDescriptor, parameters = {}) {
2208
+ Object.assign(pipelineDescriptor, {
2209
+ ...DEFAULT_PIPELINE_DESCRIPTOR,
2210
+ ...pipelineDescriptor
2211
+ });
2212
+ setParameters(pipelineDescriptor, parameters);
2213
+ }
2214
+ function setParameters(pipelineDescriptor, parameters) {
2215
+ for (const [key, value] of Object.entries(parameters)) {
2216
+ const setterFunction = PARAMETER_TABLE[key];
2217
+ if (!setterFunction) {
2218
+ throw new Error(`Illegal parameter ${key}`);
2219
+ }
2220
+ setterFunction(key, value, pipelineDescriptor);
2221
+ }
2222
+ }
2223
+ function addColorState(descriptor) {
2224
+ descriptor.fragment.targets = descriptor.fragment?.targets || [];
2225
+ if (!Array.isArray(descriptor.fragment?.targets)) {
2226
+ throw new Error("colorstate");
2227
+ }
2228
+ if (descriptor.fragment?.targets?.length === 0) {
2229
+ descriptor.fragment.targets?.push({});
2230
+ }
2231
+ return descriptor.fragment?.targets;
2232
+ }
2233
+
2234
+ // src/adapter/helpers/get-bind-group.ts
2235
+ function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
2236
+ const entries = getBindGroupEntries(bindings, shaderLayout);
2237
+ return device.createBindGroup({
2238
+ layout: bindGroupLayout,
2239
+ entries
2240
+ });
2241
+ }
2242
+ function getShaderLayoutBinding(shaderLayout, bindingName) {
2243
+ const bindingLayout = shaderLayout.bindings.find((binding) => binding.name === bindingName);
2244
+ if (!bindingLayout) {
2245
+ log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
2246
+ }
2247
+ return bindingLayout;
2248
+ }
2249
+ function getBindGroupEntries(bindings, shaderLayout) {
2250
+ const entries = [];
2251
+ for (const [bindingName, value] of Object.entries(bindings)) {
2252
+ const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
2253
+ if (bindingLayout) {
2254
+ entries.push(getBindGroupEntry(value, bindingLayout.location));
2255
+ }
2256
+ }
2257
+ return entries;
2258
+ }
2259
+ function getBindGroupEntry(binding, index) {
2260
+ if (binding instanceof Buffer2) {
2261
+ return {
2262
+ binding: index,
2263
+ resource: {
2264
+ buffer: cast(binding).handle
2265
+ }
2266
+ };
2267
+ }
2268
+ if (binding instanceof Sampler) {
2269
+ return {
2270
+ binding: index,
2271
+ resource: cast(binding).handle
2272
+ };
2273
+ } else if (binding instanceof Texture) {
2274
+ return {
2275
+ binding: index,
2276
+ resource: cast(binding).handle.createView()
2277
+ };
2278
+ }
2279
+ throw new Error("invalid binding");
2280
+ }
2281
+
2282
+ // src/adapter/helpers/get-vertex-buffer-layout.ts
2283
+ function getWebGPUVertexFormat(format) {
2284
+ if (format.endsWith("-webgl")) {
2285
+ throw new Error(`WebGPU does not support vertex format ${format}`);
2286
+ }
2287
+ return format;
2288
+ }
2289
+ function getVertexBufferLayout(shaderLayout, bufferLayout) {
2290
+ const vertexBufferLayouts = [];
2291
+ const usedAttributes = /* @__PURE__ */ new Set();
2292
+ for (const mapping of bufferLayout) {
2293
+ const vertexAttributes = [];
2294
+ let stepMode = "vertex";
2295
+ let byteStride = 0;
2296
+ if (mapping.attributes) {
2297
+ for (const attributeMapping of mapping.attributes) {
2298
+ const attributeName = attributeMapping.attribute;
2299
+ const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
2300
+ stepMode = attributeLayout.stepMode || "vertex";
2301
+ vertexAttributes.push({
2302
+ format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
2303
+ offset: attributeMapping.byteOffset,
2304
+ shaderLocation: attributeLayout.location
2305
+ });
2306
+ byteStride += decodeVertexFormat(mapping.format).byteLength;
2307
+ }
2308
+ } else {
2309
+ const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
2310
+ byteStride = decodeVertexFormat(mapping.format).byteLength;
2311
+ stepMode = attributeLayout.stepMode || "vertex";
2312
+ vertexAttributes.push({
2313
+ format: getWebGPUVertexFormat(mapping.format),
2314
+ offset: 0,
2315
+ shaderLocation: attributeLayout.location
2316
+ });
2317
+ }
2318
+ vertexBufferLayouts.push({
2319
+ arrayStride: mapping.byteStride || byteStride,
2320
+ stepMode: stepMode || "vertex",
2321
+ attributes: vertexAttributes
2322
+ });
2323
+ }
2324
+ for (const attribute of shaderLayout.attributes) {
2325
+ if (!usedAttributes.has(attribute.name)) {
2326
+ vertexBufferLayouts.push({
2327
+ arrayStride: decodeVertexFormat("float32x3").byteLength,
2328
+ stepMode: attribute.stepMode || "vertex",
2329
+ attributes: [{
2330
+ format: getWebGPUVertexFormat("float32x3"),
2331
+ offset: 0,
2332
+ shaderLocation: attribute.location
2333
+ }]
2334
+ });
2335
+ }
2336
+ }
2337
+ return vertexBufferLayouts;
2338
+ }
2339
+ function getBufferSlots(shaderLayout, bufferLayout) {
2340
+ const usedAttributes = /* @__PURE__ */ new Set();
2341
+ let bufferSlot = 0;
2342
+ const bufferSlots = {};
2343
+ for (const mapping of bufferLayout) {
2344
+ if ("attributes" in mapping) {
2345
+ for (const interleaved of mapping.attributes) {
2346
+ usedAttributes.add(interleaved.attribute);
2347
+ }
2348
+ } else {
2349
+ usedAttributes.add(mapping.name);
2350
+ }
2351
+ bufferSlots[mapping.name] = bufferSlot++;
2352
+ }
2353
+ for (const attribute of shaderLayout.attributes) {
2354
+ if (!usedAttributes.has(attribute.name)) {
2355
+ bufferSlots[attribute.name] = bufferSlot++;
2356
+ }
2357
+ }
2358
+ return bufferSlots;
2359
+ }
2360
+ function findAttributeLayout(shaderLayout, name2, attributeNames) {
2361
+ const attribute = shaderLayout.attributes.find((attribute2) => attribute2.name === name2);
2362
+ if (!attribute) {
2363
+ throw new Error(`Unknown attribute ${name2}`);
2364
+ }
2365
+ if (attributeNames.has(name2)) {
2366
+ throw new Error(`Duplicate attribute ${name2}`);
2367
+ }
2368
+ attributeNames.add(name2);
2369
+ return attribute;
2370
+ }
2371
+
2372
+ // src/adapter/resources/webgpu-render-pipeline.ts
2373
+ var WebGPURenderPipeline = class extends RenderPipeline {
2374
+ fs = null;
2375
+ _indexBuffer = null;
2376
+ _bindGroupLayout = null;
2377
+ _bindGroup = null;
2378
+ constructor(device, props) {
2379
+ super(device, props);
2380
+ this.device = device;
2381
+ this.handle = this.props.handle;
2382
+ if (!this.handle) {
2383
+ const descriptor = this._getRenderPipelineDescriptor();
2384
+ log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
2385
+ log.probe(1, JSON.stringify(descriptor, null, 2))();
2386
+ log.groupEnd(1)();
2387
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
2388
+ }
2389
+ this.handle.label = this.props.id;
2390
+ this.vs = cast(props.vs);
2391
+ this.fs = cast(props.fs);
2392
+ this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
2393
+ this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);
2394
+ }
2395
+ destroy() {
2396
+ }
2397
+ setIndexBuffer(indexBuffer) {
2398
+ this._indexBuffer = cast(indexBuffer);
2399
+ }
2400
+ setAttributes(attributes) {
2401
+ for (const [name2, buffer] of Object.entries(attributes)) {
2402
+ const bufferIndex = this._bufferSlots[name2];
2403
+ if (bufferIndex >= 0) {
2404
+ this._buffers[bufferIndex] = buffer;
2405
+ } else {
2406
+ throw new Error(`Setting attribute '${name2}' not listed in shader layout for program ${this.id}`);
2407
+ }
2408
+ }
2409
+ }
2410
+ setConstantAttributes(attributes) {
2411
+ throw new Error("not implemented");
2412
+ }
2413
+ setBindings(bindings) {
2414
+ if (!isObjectEmpty(this.props.bindings)) {
2415
+ Object.assign(this.props.bindings, bindings);
2416
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
2417
+ this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this.props.bindings);
2418
+ }
2419
+ }
2420
+ setUniforms(uniforms) {
2421
+ if (!isObjectEmpty(uniforms)) {
2422
+ throw new Error("WebGPU does not support uniforms");
2423
+ }
2424
+ }
2425
+ _getBuffers() {
2426
+ return this._buffers;
2427
+ }
2428
+ _getBindGroup() {
2429
+ return this._bindGroup;
2430
+ }
2431
+ _getRenderPipelineDescriptor() {
2432
+ const vertex = {
2433
+ module: cast(this.props.vs).handle,
2434
+ entryPoint: this.props.vsEntryPoint || "main",
2435
+ buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
2436
+ };
2437
+ let fragment;
2438
+ if (this.props.fs) {
2439
+ fragment = {
2440
+ module: cast(this.props.fs).handle,
2441
+ entryPoint: this.props.fsEntryPoint || "main",
2442
+ targets: [{
2443
+ format: getWebGPUTextureFormat(this.device?.canvasContext?.format)
2444
+ }]
2445
+ };
2446
+ }
2447
+ switch (this.props.topology) {
2448
+ case "triangle-fan-webgl":
2449
+ case "line-loop-webgl":
2450
+ throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
2451
+ default:
2452
+ }
2453
+ const descriptor = {
2454
+ vertex,
2455
+ fragment,
2456
+ primitive: {
2457
+ topology: this.props.topology
2458
+ },
2459
+ layout: "auto"
2460
+ };
2461
+ applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
2462
+ return descriptor;
2463
+ }
2464
+ draw(options) {
2465
+ const webgpuRenderPass = cast(options.renderPass) || this.device.getDefaultRenderPass();
2466
+ webgpuRenderPass.handle.setPipeline(this.handle);
2467
+ const bindGroup = this._getBindGroup();
2468
+ if (bindGroup) {
2469
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
2470
+ }
2471
+ this._setAttributeBuffers(webgpuRenderPass);
2472
+ if (options.indexCount) {
2473
+ webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
2474
+ } else {
2475
+ webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstInstance);
2476
+ }
2477
+ }
2478
+ _setAttributeBuffers(webgpuRenderPass) {
2479
+ if (this._indexBuffer) {
2480
+ webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);
2481
+ }
2482
+ const buffers = this._getBuffers();
2483
+ for (let i = 0; i < buffers.length; ++i) {
2484
+ const buffer = cast(buffers[i]);
2485
+ if (!buffer) {
2486
+ const attribute = this.props.shaderLayout.attributes.find((attribute2) => attribute2.location === i);
2487
+ throw new Error(`No buffer provided for attribute '${attribute?.name || ""}' in Model '${this.props.id}'`);
2488
+ }
2489
+ webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);
2490
+ }
2491
+ }
2492
+ };
2493
+
2494
+ // src/adapter/resources/webgpu-compute-pipeline.ts
2495
+ var WebGPUComputePipeline = class extends ComputePipeline {
2496
+ constructor(device, props) {
2497
+ super(device, props);
2498
+ this.device = device;
2499
+ const module = cast(this.props.cs).handle;
2500
+ this.handle = this.props.handle || this.device.handle.createComputePipeline({
2501
+ label: this.props.id,
2502
+ compute: {
2503
+ module,
2504
+ entryPoint: this.props.csEntryPoint
2505
+ },
2506
+ layout: "auto"
2507
+ });
2508
+ }
2509
+ _getBindGroupLayout() {
2510
+ return this.handle.getBindGroupLayout(0);
2511
+ }
2512
+ };
2513
+
2514
+ // src/adapter/resources/webgpu-render-pass.ts
2515
+ var WebGPURenderPass = class extends RenderPass {
2516
+ pipeline = null;
2517
+ constructor(device, props = {}) {
2518
+ super(device, props);
2519
+ this.device = device;
2520
+ const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
2521
+ const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
2522
+ log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)();
2523
+ log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))();
2524
+ log.groupEnd(1)();
2525
+ this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
2526
+ this.handle.label = this.props.id;
2527
+ }
2528
+ destroy() {
2529
+ }
2530
+ end() {
2531
+ this.handle.end();
2532
+ }
2533
+ setPipeline(pipeline) {
2534
+ this.pipeline = cast(pipeline);
2535
+ this.handle.setPipeline(this.pipeline.handle);
2536
+ }
2537
+ setBindings(bindings) {
2538
+ this.pipeline?.setBindings(bindings);
2539
+ const bindGroup = this.pipeline?._getBindGroup();
2540
+ if (bindGroup) {
2541
+ this.handle.setBindGroup(0, bindGroup);
2542
+ }
2543
+ }
2544
+ setIndexBuffer(buffer, indexFormat, offset = 0, size) {
2545
+ this.handle.setIndexBuffer(cast(buffer).handle, indexFormat, offset, size);
2546
+ }
2547
+ setVertexBuffer(slot, buffer, offset = 0) {
2548
+ this.handle.setVertexBuffer(slot, cast(buffer).handle, offset);
2549
+ }
2550
+ draw(options) {
2551
+ if (options.indexCount) {
2552
+ this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
2553
+ } else {
2554
+ this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
2555
+ }
2556
+ }
2557
+ drawIndirect() {
2558
+ }
2559
+ setParameters(parameters) {
2560
+ const {
2561
+ blendConstant,
2562
+ stencilReference,
2563
+ scissorRect,
2564
+ viewport
2565
+ } = parameters;
2566
+ if (blendConstant) {
2567
+ this.handle.setBlendConstant(blendConstant);
2568
+ }
2569
+ if (stencilReference) {
2570
+ this.handle.setStencilReference(stencilReference);
2571
+ }
2572
+ if (scissorRect) {
2573
+ this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);
2574
+ }
2575
+ if (viewport) {
2576
+ this.handle.setViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
2577
+ }
2578
+ }
2579
+ pushDebugGroup(groupLabel) {
2580
+ this.handle.pushDebugGroup(groupLabel);
2581
+ }
2582
+ popDebugGroup() {
2583
+ this.handle.popDebugGroup();
2584
+ }
2585
+ insertDebugMarker(markerLabel) {
2586
+ this.handle.insertDebugMarker(markerLabel);
2587
+ }
2588
+ getRenderPassDescriptor(framebuffer) {
2589
+ const renderPassDescriptor = {
2590
+ colorAttachments: []
2591
+ };
2592
+ renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
2593
+ loadOp: this.props.clearColor !== false ? "clear" : "load",
2594
+ colorClearValue: this.props.clearColor || [0, 0, 0, 0],
2595
+ storeOp: this.props.discard ? "discard" : "store",
2596
+ view: colorAttachment.handle.createView()
2597
+ }));
2598
+ if (framebuffer.depthStencilAttachment) {
2599
+ renderPassDescriptor.depthStencilAttachment = {
2600
+ view: framebuffer.depthStencilAttachment.handle.createView()
2601
+ };
2602
+ const {
2603
+ depthStencilAttachment
2604
+ } = renderPassDescriptor;
2605
+ if (this.props.depthReadOnly) {
2606
+ depthStencilAttachment.depthReadOnly = true;
2607
+ }
2608
+ depthStencilAttachment.depthClearValue = this.props.clearDepth || 0;
2609
+ const hasDepthAspect = true;
2610
+ if (hasDepthAspect) {
2611
+ depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
2612
+ depthStencilAttachment.depthStoreOp = "store";
2613
+ }
2614
+ const hasStencilAspect = false;
2615
+ if (hasStencilAspect) {
2616
+ depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
2617
+ depthStencilAttachment.stencilStoreOp = "store";
2618
+ }
2619
+ }
2620
+ return renderPassDescriptor;
2621
+ }
2622
+ };
2623
+
2624
+ // src/adapter/resources/webgpu-compute-pass.ts
2625
+ var WebGPUComputePass = class extends ComputePass {
2626
+ _bindGroupLayout = null;
2627
+ constructor(device, props) {
2628
+ super(device, props);
2629
+ this.device = device;
2630
+ this.handle = this.props.handle || device.commandEncoder?.beginComputePass({
2631
+ label: this.props.id
2632
+ });
2633
+ }
2634
+ destroy() {
2635
+ }
2636
+ end() {
2637
+ this.handle.end();
2638
+ }
2639
+ setPipeline(pipeline) {
2640
+ const wgpuPipeline = cast(pipeline);
2641
+ this.handle.setPipeline(wgpuPipeline.handle);
2642
+ this._bindGroupLayout = wgpuPipeline._getBindGroupLayout();
2643
+ }
2644
+ setBindings(bindings) {
2645
+ throw new Error("fix me");
2646
+ }
2647
+ dispatch(x, y, z) {
2648
+ this.handle.dispatchWorkgroups(x, y, z);
2649
+ }
2650
+ dispatchIndirect(indirectBuffer, indirectOffset = 0) {
2651
+ this.handle.dispatchWorkgroupsIndirect(cast(indirectBuffer).handle, indirectOffset);
2652
+ }
2653
+ pushDebugGroup(groupLabel) {
2654
+ this.handle.pushDebugGroup(groupLabel);
2655
+ }
2656
+ popDebugGroup() {
2657
+ this.handle.popDebugGroup();
2658
+ }
2659
+ insertDebugMarker(markerLabel) {
2660
+ this.handle.insertDebugMarker(markerLabel);
2661
+ }
2662
+ };
2663
+
2664
+ // src/adapter/resources/webgpu-vertex-array.ts
2665
+ var WebGPUVertexArray = class extends VertexArray {
2666
+ get [Symbol.toStringTag]() {
2667
+ return "WebGPUVertexArray";
2668
+ }
2669
+ static isConstantAttributeZeroSupported(device) {
2670
+ return device.info.type === "webgl2" || getBrowser() === "Chrome";
2671
+ }
2672
+ constructor(device, props) {
2673
+ super(device, props);
2674
+ this.device = device;
2675
+ }
2676
+ destroy() {
2677
+ }
2678
+ setIndexBuffer(buffer) {
2679
+ this.indexBuffer = buffer;
2680
+ }
2681
+ setBuffer(location, buffer) {
2682
+ this.attributes[location] = buffer;
2683
+ }
2684
+ setConstant(location, value) {
2685
+ log.warn(`${this.id} constant attributes not supported on WebGPU`);
2686
+ }
2687
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
2688
+ const webgpuRenderPass = renderPass;
2689
+ const webgpuIndexBuffer = this.indexBuffer;
2690
+ webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);
2691
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
2692
+ const webgpuBuffer = this.attributes[location];
2693
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle);
2694
+ }
2695
+ }
2696
+ unbindAfterRender(renderPass) {
2697
+ }
2698
+ };
2699
+
2700
+ // src/adapter/resources/webgpu-framebuffer.ts
2701
+ var WebGPUFramebuffer = class extends Framebuffer {
2702
+ constructor(device, props) {
2703
+ super(device, props);
2704
+ this.device = device;
2705
+ this.autoCreateAttachmentTextures();
2706
+ }
2707
+ };
2708
+
2709
+ // src/adapter/webgpu-canvas-context.ts
2710
+ var WebGPUCanvasContext = class extends CanvasContext {
2711
+ format = navigator.gpu.getPreferredCanvasFormat();
2712
+ depthStencilFormat = "depth24plus";
2713
+ depthStencilAttachment = null;
2714
+ constructor(device, adapter, props) {
2715
+ super(props);
2716
+ this.device = device;
2717
+ this.width = -1;
2718
+ this.height = -1;
2719
+ this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
2720
+ this.gpuCanvasContext = this.canvas.getContext("webgpu");
2721
+ this.format = "bgra8unorm";
2722
+ }
2723
+ destroy() {
2724
+ this.gpuCanvasContext.unconfigure();
2725
+ }
2726
+ getCurrentTexture() {
2727
+ return this.device._createTexture({
2728
+ id: "default-render-target",
2729
+ handle: this.gpuCanvasContext.getCurrentTexture()
2730
+ });
2731
+ }
2732
+ getCurrentFramebuffer() {
2733
+ this.update();
2734
+ const currentColorAttachment = this.getCurrentTexture();
2735
+ this.width = currentColorAttachment.width;
2736
+ this.height = currentColorAttachment.height;
2737
+ this._createDepthStencilAttachment();
2738
+ return new WebGPUFramebuffer(this.device, {
2739
+ colorAttachments: [currentColorAttachment],
2740
+ depthStencilAttachment: this.depthStencilAttachment
2741
+ });
2742
+ }
2743
+ update() {
2744
+ const [width, height] = this.getPixelSize();
2745
+ const sizeChanged = width !== this.width || height !== this.height;
2746
+ if (sizeChanged) {
2747
+ this.width = width;
2748
+ this.height = height;
2749
+ if (this.depthStencilAttachment) {
2750
+ this.depthStencilAttachment.destroy();
2751
+ this.depthStencilAttachment = null;
2752
+ }
2753
+ this.gpuCanvasContext.configure({
2754
+ device: this.device.handle,
2755
+ format: getWebGPUTextureFormat(this.format),
2756
+ colorSpace: this.props.colorSpace,
2757
+ alphaMode: this.props.alphaMode
2758
+ });
2759
+ log.log(1, `Resized to ${this.width}x${this.height}px`)();
2760
+ }
2761
+ }
2762
+ resize(options) {
2763
+ this.update();
2764
+ }
2765
+ _createDepthStencilAttachment() {
2766
+ if (!this.depthStencilAttachment) {
2767
+ this.depthStencilAttachment = this.device.createTexture({
2768
+ id: "depth-stencil-target",
2769
+ format: this.depthStencilFormat,
2770
+ width: this.width,
2771
+ height: this.height,
2772
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
2773
+ });
2774
+ }
2775
+ return this.depthStencilAttachment;
2776
+ }
2777
+ };
2778
+
2779
+ // src/adapter/webgpu-device.ts
2780
+ var _WebGPUDevice = class extends Device {
2781
+ canvasContext = null;
2782
+ commandEncoder = null;
2783
+ renderPass = null;
2784
+ _isLost = false;
2785
+ static isSupported() {
2786
+ return Boolean(typeof navigator !== "undefined" && navigator.gpu);
2787
+ }
2788
+ static async create(props) {
2789
+ if (!navigator.gpu) {
2790
+ throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
2791
+ }
2792
+ log.groupCollapsed(1, "WebGPUDevice created")();
2793
+ const adapter = await navigator.gpu.requestAdapter({
2794
+ powerPreference: "high-performance"
2795
+ });
2796
+ if (!adapter) {
2797
+ throw new Error("Failed to request WebGPU adapter");
2798
+ }
2799
+ const adapterInfo = await adapter.requestAdapterInfo();
2800
+ log.probe(1, "Adapter available", adapterInfo)();
2801
+ const gpuDevice = await adapter.requestDevice({
2802
+ requiredFeatures: adapter.features
2803
+ });
2804
+ log.probe(1, "GPUDevice available")();
2805
+ if (typeof props.canvas === "string") {
2806
+ await CanvasContext.pageLoaded;
2807
+ log.probe(1, "DOM is loaded")();
2808
+ }
2809
+ const device = new _WebGPUDevice(gpuDevice, adapter, props);
2810
+ log.probe(1, "Device created", device.info)();
2811
+ log.table(1, device.info)();
2812
+ log.groupEnd(1)();
2813
+ return device;
2814
+ }
2815
+ constructor(device, adapter, props) {
2816
+ super({
2817
+ ...props,
2818
+ id: props.id || uid("webgpu-device")
2819
+ });
2820
+ this.handle = device;
2821
+ this.adapter = adapter;
2822
+ this._info = {
2823
+ type: "webgpu",
2824
+ vendor: this.adapter.__brand,
2825
+ renderer: "",
2826
+ version: "",
2827
+ gpu: "unknown",
2828
+ shadingLanguage: "wgsl",
2829
+ shadingLanguageVersion: 100,
2830
+ vendorMasked: "",
2831
+ rendererMasked: ""
2832
+ };
2833
+ this.lost = new Promise(async (resolve) => {
2834
+ const lostInfo = await this.handle.lost;
2835
+ this._isLost = true;
2836
+ resolve({
2837
+ reason: "destroyed",
2838
+ message: lostInfo.message
2839
+ });
2840
+ });
2841
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
2842
+ canvas: props.canvas,
2843
+ height: props.height,
2844
+ width: props.width,
2845
+ container: props.container
2846
+ });
2847
+ this.features = this._getFeatures();
2848
+ }
2849
+ destroy() {
2850
+ this.handle.destroy();
2851
+ }
2852
+ get info() {
2853
+ return this._info;
2854
+ }
2855
+ get limits() {
2856
+ return this.handle.limits;
2857
+ }
2858
+ isTextureFormatSupported(format) {
2859
+ return !format.includes("webgl");
2860
+ }
2861
+ isTextureFormatFilterable(format) {
2862
+ return this.isTextureFormatSupported(format);
2863
+ }
2864
+ isTextureFormatRenderable(format) {
2865
+ return this.isTextureFormatSupported(format);
2866
+ }
2867
+ get isLost() {
2868
+ return this._isLost;
2869
+ }
2870
+ createBuffer(props) {
2871
+ const newProps = this._getBufferProps(props);
2872
+ return new WebGPUBuffer(this, newProps);
2873
+ }
2874
+ _createTexture(props) {
2875
+ return new WebGPUTexture(this, props);
2876
+ }
2877
+ createExternalTexture(props) {
2878
+ return new WebGPUExternalTexture(this, props);
2879
+ }
2880
+ createShader(props) {
2881
+ return new WebGPUShader(this, props);
2882
+ }
2883
+ createSampler(props) {
2884
+ return new WebGPUSampler(this, props);
2885
+ }
2886
+ createRenderPipeline(props) {
2887
+ return new WebGPURenderPipeline(this, props);
2888
+ }
2889
+ createFramebuffer(props) {
2890
+ throw new Error("Not implemented");
2891
+ }
2892
+ createComputePipeline(props) {
2893
+ return new WebGPUComputePipeline(this, props);
2894
+ }
2895
+ createVertexArray(props) {
2896
+ return new WebGPUVertexArray(this, props);
2897
+ }
2898
+ beginRenderPass(props) {
2899
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
2900
+ return new WebGPURenderPass(this, props);
2901
+ }
2902
+ beginComputePass(props) {
2903
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
2904
+ return new WebGPUComputePass(this, props);
2905
+ }
2906
+ createTransformFeedback(props) {
2907
+ throw new Error("Transform feedback not supported in WebGPU");
2908
+ }
2909
+ createCanvasContext(props) {
2910
+ return new WebGPUCanvasContext(this, this.adapter, props);
2911
+ }
2912
+ getDefaultRenderPass() {
2913
+ throw new Error("a");
2914
+ }
2915
+ submit() {
2916
+ const commandBuffer = this.commandEncoder?.finish();
2917
+ if (commandBuffer) {
2918
+ this.handle.queue.submit([commandBuffer]);
2919
+ }
2920
+ this.commandEncoder = null;
2921
+ }
2922
+ _getFeatures() {
2923
+ const features = new Set(this.handle.features);
2924
+ if (features.has("depth-clamping")) {
2925
+ features.delete("depth-clamping");
2926
+ features.add("depth-clip-control");
2927
+ }
2928
+ if (features.has("texture-compression-bc")) {
2929
+ features.add("texture-compression-bc5-webgl");
2930
+ }
2931
+ features.add("webgpu");
2932
+ features.add("timer-query-webgl");
2933
+ features.add("vertex-array-object-webgl1");
2934
+ features.add("instanced-rendering-webgl1");
2935
+ features.add("multiple-render-targets-webgl1");
2936
+ features.add("index-uint32-webgl1");
2937
+ features.add("blend-minmax-webgl1");
2938
+ features.add("texture-blend-float-webgl1");
2939
+ features.add("texture-formats-srgb-webgl1");
2940
+ features.add("texture-formats-depth-webgl1");
2941
+ features.add("texture-formats-float32-webgl1");
2942
+ features.add("texture-formats-float16-webgl1");
2943
+ features.add("texture-filter-linear-float32-webgl");
2944
+ features.add("texture-filter-linear-float16-webgl");
2945
+ features.add("texture-filter-anisotropic-webgl");
2946
+ features.add("texture-renderable-rgba32float-webgl");
2947
+ features.add("texture-renderable-float32-webgl");
2948
+ features.add("texture-renderable-float16-webgl");
2949
+ features.add("glsl-frag-data");
2950
+ features.add("glsl-frag-depth");
2951
+ features.add("glsl-derivatives");
2952
+ features.add("glsl-texture-lod");
2953
+ return features;
2954
+ }
2955
+ copyExternalImageToTexture(options) {
2956
+ const {
2957
+ source,
2958
+ sourceX = 0,
2959
+ sourceY = 0,
2960
+ texture,
2961
+ mipLevel = 0,
2962
+ aspect = "all",
2963
+ colorSpace = "display-p3",
2964
+ premultipliedAlpha = false,
2965
+ width = texture.width,
2966
+ height = texture.height,
2967
+ depth = 1
2968
+ } = options;
2969
+ const webGpuTexture = texture;
2970
+ this.handle?.queue.copyExternalImageToTexture({
2971
+ source,
2972
+ origin: [sourceX, sourceY]
2973
+ }, {
2974
+ texture: webGpuTexture.handle,
2975
+ origin: [0, 0, 0],
2976
+ mipLevel,
2977
+ aspect,
2978
+ colorSpace,
2979
+ premultipliedAlpha
2980
+ }, [width, height, depth]);
2981
+ }
2982
+ };
2983
+ var WebGPUDevice = _WebGPUDevice;
2984
+ __publicField(WebGPUDevice, "type", "webgpu");
2985
+ return __toCommonJS(src_exports);
2986
+ })();
2987
+ return __exports__;
2988
+ });