@luma.gl/core 9.0.0-beta.3 → 9.0.0-beta.5

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 (152) hide show
  1. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +140 -109
  2. package/dist/adapter/canvas-context.js +305 -233
  3. package/dist/adapter/device.d.ts +9 -11
  4. package/dist/adapter/device.d.ts.map +1 -1
  5. package/dist/adapter/device.js +114 -95
  6. package/dist/adapter/resources/buffer.d.ts +1 -1
  7. package/dist/adapter/resources/buffer.d.ts.map +1 -1
  8. package/dist/adapter/resources/buffer.js +65 -57
  9. package/dist/adapter/resources/command-buffer.js +13 -13
  10. package/dist/adapter/resources/command-encoder.js +17 -17
  11. package/dist/adapter/resources/compute-pass.js +10 -13
  12. package/dist/adapter/resources/compute-pipeline.js +19 -18
  13. package/dist/adapter/resources/external-texture.js +10 -15
  14. package/dist/adapter/resources/framebuffer.js +155 -94
  15. package/dist/adapter/resources/render-pass.js +28 -21
  16. package/dist/adapter/resources/render-pipeline.d.ts +3 -1
  17. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  18. package/dist/adapter/resources/render-pipeline.js +37 -34
  19. package/dist/adapter/resources/resource.js +131 -93
  20. package/dist/adapter/resources/sampler.js +24 -24
  21. package/dist/adapter/resources/shader.d.ts +2 -2
  22. package/dist/adapter/resources/shader.d.ts.map +1 -1
  23. package/dist/adapter/resources/shader.js +90 -78
  24. package/dist/adapter/resources/texture.js +49 -43
  25. package/dist/adapter/resources/transform-feedback.d.ts +2 -2
  26. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
  27. package/dist/adapter/resources/transform-feedback.js +13 -15
  28. package/dist/adapter/resources/vertex-array.js +30 -22
  29. package/dist/adapter/type-utils/decode-attribute-type.js +56 -52
  30. package/dist/adapter/type-utils/decode-data-type.js +36 -35
  31. package/dist/adapter/type-utils/decode-shader-types.js +36 -97
  32. package/dist/adapter/type-utils/decode-texture-format.js +160 -93
  33. package/dist/adapter/type-utils/decode-vertex-format.js +28 -23
  34. package/dist/adapter/type-utils/vertex-format-from-attribute.js +69 -65
  35. package/dist/adapter/type-utils/wgsl-utils.js +14 -13
  36. package/dist/adapter/types/accessor.js +0 -1
  37. package/dist/adapter/types/buffer-layout.js +0 -1
  38. package/dist/adapter/types/parameters.js +31 -26
  39. package/dist/adapter/types/shader-layout.js +0 -1
  40. package/dist/adapter/types/shader-types.js +2 -1
  41. package/dist/adapter/types/texture-formats.d.ts +1 -1
  42. package/dist/adapter/types/texture-formats.d.ts.map +1 -1
  43. package/dist/adapter/types/texture-formats.js +2 -1
  44. package/dist/adapter/types/types.js +0 -1
  45. package/dist/adapter/types/vertex-formats.js +2 -1
  46. package/dist/dist.dev.js +453 -270
  47. package/dist/index.cjs +66 -168
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +57 -46
  52. package/dist/init.js +29 -19
  53. package/dist/lib/compiler-log/compiler-message.js +2 -1
  54. package/dist/lib/compiler-log/format-compiler-log.js +66 -48
  55. package/dist/lib/compiler-log/get-shader-info.js +22 -19
  56. package/dist/lib/luma.d.ts.map +1 -1
  57. package/dist/lib/luma.js +60 -55
  58. package/dist/lib/uniforms/uniform-block.d.ts +0 -1
  59. package/dist/lib/uniforms/uniform-block.d.ts.map +1 -1
  60. package/dist/lib/uniforms/uniform-block.js +50 -43
  61. package/dist/lib/uniforms/uniform-buffer-layout.js +87 -70
  62. package/dist/lib/uniforms/uniform-store.js +112 -79
  63. package/dist/lib/uniforms/uniform.js +13 -16
  64. package/dist/types.js +1 -3
  65. package/dist/utils/array-equal.js +25 -23
  66. package/dist/utils/array-utils-flat.js +28 -28
  67. package/dist/utils/assert.js +5 -4
  68. package/dist/utils/cast.js +2 -2
  69. package/dist/utils/check-props.js +28 -27
  70. package/dist/utils/deep-equal.js +39 -32
  71. package/dist/utils/format-value.js +33 -39
  72. package/dist/utils/is-array.js +17 -6
  73. package/dist/utils/load-file.js +62 -37
  74. package/dist/utils/log.js +2 -4
  75. package/dist/utils/random.js +10 -9
  76. package/dist/utils/request-animation-frame.js +9 -3
  77. package/dist/utils/stats-manager.js +13 -14
  78. package/dist/utils/stub-methods.js +13 -13
  79. package/dist/utils/utils.d.ts +0 -6
  80. package/dist/utils/utils.d.ts.map +1 -1
  81. package/dist/utils/utils.js +20 -15
  82. package/dist.min.js +8 -23
  83. package/package.json +6 -6
  84. package/src/adapter/device.ts +38 -59
  85. package/src/adapter/resources/buffer.ts +1 -1
  86. package/src/adapter/resources/render-pipeline.ts +3 -1
  87. package/src/adapter/resources/shader.ts +2 -2
  88. package/src/adapter/resources/transform-feedback.ts +2 -2
  89. package/src/adapter/types/texture-formats.ts +1 -1
  90. package/src/index.ts +1 -1
  91. package/src/lib/luma.ts +0 -2
  92. package/src/lib/uniforms/uniform-block.ts +0 -1
  93. package/src/utils/utils.ts +0 -9
  94. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +0 -1
  95. package/dist/adapter/canvas-context.js.map +0 -1
  96. package/dist/adapter/device.js.map +0 -1
  97. package/dist/adapter/resources/buffer.js.map +0 -1
  98. package/dist/adapter/resources/command-buffer.js.map +0 -1
  99. package/dist/adapter/resources/command-encoder.js.map +0 -1
  100. package/dist/adapter/resources/compute-pass.js.map +0 -1
  101. package/dist/adapter/resources/compute-pipeline.js.map +0 -1
  102. package/dist/adapter/resources/external-texture.js.map +0 -1
  103. package/dist/adapter/resources/framebuffer.js.map +0 -1
  104. package/dist/adapter/resources/render-pass.js.map +0 -1
  105. package/dist/adapter/resources/render-pipeline.js.map +0 -1
  106. package/dist/adapter/resources/resource.js.map +0 -1
  107. package/dist/adapter/resources/sampler.js.map +0 -1
  108. package/dist/adapter/resources/shader.js.map +0 -1
  109. package/dist/adapter/resources/texture.js.map +0 -1
  110. package/dist/adapter/resources/transform-feedback.js.map +0 -1
  111. package/dist/adapter/resources/vertex-array.js.map +0 -1
  112. package/dist/adapter/type-utils/decode-attribute-type.js.map +0 -1
  113. package/dist/adapter/type-utils/decode-data-type.js.map +0 -1
  114. package/dist/adapter/type-utils/decode-shader-types.js.map +0 -1
  115. package/dist/adapter/type-utils/decode-texture-format.js.map +0 -1
  116. package/dist/adapter/type-utils/decode-vertex-format.js.map +0 -1
  117. package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +0 -1
  118. package/dist/adapter/type-utils/wgsl-utils.js.map +0 -1
  119. package/dist/adapter/types/accessor.js.map +0 -1
  120. package/dist/adapter/types/buffer-layout.js.map +0 -1
  121. package/dist/adapter/types/parameters.js.map +0 -1
  122. package/dist/adapter/types/shader-layout.js.map +0 -1
  123. package/dist/adapter/types/shader-types.js.map +0 -1
  124. package/dist/adapter/types/texture-formats.js.map +0 -1
  125. package/dist/adapter/types/types.js.map +0 -1
  126. package/dist/adapter/types/vertex-formats.js.map +0 -1
  127. package/dist/index.js.map +0 -1
  128. package/dist/init.js.map +0 -1
  129. package/dist/lib/compiler-log/compiler-message.js.map +0 -1
  130. package/dist/lib/compiler-log/format-compiler-log.js.map +0 -1
  131. package/dist/lib/compiler-log/get-shader-info.js.map +0 -1
  132. package/dist/lib/luma.js.map +0 -1
  133. package/dist/lib/uniforms/uniform-block.js.map +0 -1
  134. package/dist/lib/uniforms/uniform-buffer-layout.js.map +0 -1
  135. package/dist/lib/uniforms/uniform-store.js.map +0 -1
  136. package/dist/lib/uniforms/uniform.js.map +0 -1
  137. package/dist/types.js.map +0 -1
  138. package/dist/utils/array-equal.js.map +0 -1
  139. package/dist/utils/array-utils-flat.js.map +0 -1
  140. package/dist/utils/assert.js.map +0 -1
  141. package/dist/utils/cast.js.map +0 -1
  142. package/dist/utils/check-props.js.map +0 -1
  143. package/dist/utils/deep-equal.js.map +0 -1
  144. package/dist/utils/format-value.js.map +0 -1
  145. package/dist/utils/is-array.js.map +0 -1
  146. package/dist/utils/load-file.js.map +0 -1
  147. package/dist/utils/log.js.map +0 -1
  148. package/dist/utils/random.js.map +0 -1
  149. package/dist/utils/request-animation-frame.js.map +0 -1
  150. package/dist/utils/stats-manager.js.map +0 -1
  151. package/dist/utils/stub-methods.js.map +0 -1
  152. package/dist/utils/utils.js.map +0 -1
@@ -1,64 +1,82 @@
1
+ /** @returns annotated errors or warnings */
1
2
  export function formatCompilerLog(shaderLog, source, options) {
2
- let formattedLog = '';
3
- const lines = source.split(/\r?\n/);
4
- const log = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
5
- switch ((options === null || options === void 0 ? void 0 : options.showSourceCode) || 'no') {
6
- case 'all':
7
- let currentMessage = 0;
8
- for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
9
- formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
10
- while (log.length > currentMessage && log[currentMessage].lineNum === lineNum) {
11
- const message = log[currentMessage++];
12
- formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
13
- ...options,
14
- inlineSource: false
15
- });
16
- }
17
- }
18
- return formattedLog;
19
- case 'issues':
20
- case 'no':
21
- for (const message of shaderLog) {
22
- formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
23
- inlineSource: (options === null || options === void 0 ? void 0 : options.showSourceCode) !== 'no'
24
- });
25
- }
26
- return formattedLog;
27
- }
3
+ let formattedLog = '';
4
+ const lines = source.split(/\r?\n/);
5
+ const log = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
6
+ switch (options?.showSourceCode || 'no') {
7
+ case 'all':
8
+ // Parse the error - note: browser and driver dependent
9
+ let currentMessage = 0;
10
+ for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
11
+ formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
12
+ while (log.length > currentMessage && log[currentMessage].lineNum === lineNum) {
13
+ const message = log[currentMessage++];
14
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
15
+ ...options,
16
+ inlineSource: false
17
+ });
18
+ }
19
+ }
20
+ return formattedLog;
21
+ case 'issues':
22
+ case 'no':
23
+ // Parse the error - note: browser and driver dependent
24
+ for (const message of shaderLog) {
25
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
26
+ inlineSource: options?.showSourceCode !== 'no'
27
+ });
28
+ }
29
+ return formattedLog;
30
+ }
28
31
  }
32
+ // Helpers
33
+ /** Format one message */
29
34
  function formatCompilerMessage(message, lines, lineNum, options) {
30
- if (options !== null && options !== void 0 && options.inlineSource) {
31
- const numberedLines = getNumberedLines(lines, lineNum);
32
- const positionIndicator = message.linePos > 0 ? `${' '.repeat(message.linePos + 5)}^^^\n` : '';
33
- return `
35
+ if (options?.inlineSource) {
36
+ const numberedLines = getNumberedLines(lines, lineNum);
37
+ // If we got error position on line add a `^^^` indicator on next line
38
+ const positionIndicator = message.linePos > 0 ? `${' '.repeat(message.linePos + 5)}^^^\n` : '';
39
+ return `
34
40
  ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.message}
35
41
 
36
42
  `;
37
- }
38
- return options !== null && options !== void 0 && options.html ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message.type.toUpperCase()}: ${message.message}</b></div>` : `${message.type.toUpperCase()}: ${message.message}`;
43
+ }
44
+ return options?.html
45
+ ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message.type.toUpperCase()}: ${message.message}</b></div>`
46
+ : `${message.type.toUpperCase()}: ${message.message}`;
39
47
  }
40
48
  function getNumberedLines(lines, lineNum, options) {
41
- let numberedLines = '';
42
- for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
43
- const sourceLine = lines[lineIndex - 1];
44
- if (sourceLine !== undefined) {
45
- numberedLines += getNumberedLine(sourceLine, lineNum, options);
49
+ let numberedLines = '';
50
+ for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
51
+ const sourceLine = lines[lineIndex - 1];
52
+ if (sourceLine !== undefined) {
53
+ numberedLines += getNumberedLine(sourceLine, lineNum, options);
54
+ }
46
55
  }
47
- }
48
- return numberedLines;
56
+ return numberedLines;
49
57
  }
50
58
  function getNumberedLine(line, lineNum, options) {
51
- const escapedLine = options !== null && options !== void 0 && options.html ? escapeHTML(line) : line;
52
- return `${padLeft(String(lineNum), 4)}: ${escapedLine}${options !== null && options !== void 0 && options.html ? '<br/>' : '\n'}`;
59
+ const escapedLine = options?.html ? escapeHTML(line) : line;
60
+ return `${padLeft(String(lineNum), 4)}: ${escapedLine}${options?.html ? '<br/>' : '\n'}`;
53
61
  }
62
+ /**
63
+ * Pads a string with a number of spaces (space characters) to the left
64
+ * @param {String} string - string to pad
65
+ * @param {Number} digits - number of spaces to add
66
+ * @return {String} string - The padded string
67
+ */
54
68
  function padLeft(string, paddedLength) {
55
- let result = '';
56
- for (let i = string.length; i < paddedLength; ++i) {
57
- result += ' ';
58
- }
59
- return result + string;
69
+ let result = '';
70
+ for (let i = string.length; i < paddedLength; ++i) {
71
+ result += ' ';
72
+ }
73
+ return result + string;
60
74
  }
61
75
  function escapeHTML(unsafe) {
62
- return unsafe.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll('\'', '&#039;');
76
+ return unsafe
77
+ .replaceAll('&', '&amp;')
78
+ .replaceAll('<', '&lt;')
79
+ .replaceAll('>', '&gt;')
80
+ .replaceAll('"', '&quot;')
81
+ .replaceAll('\'', '&#039;');
63
82
  }
64
- //# sourceMappingURL=format-compiler-log.js.map
@@ -1,25 +1,28 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ /** Extracts information from shader source code */
1
4
  export function getShaderInfo(source, defaultName) {
2
- return {
3
- name: getShaderName(source, defaultName),
4
- language: 'glsl',
5
- version: getShaderVersion(source)
6
- };
5
+ return {
6
+ name: getShaderName(source, defaultName),
7
+ language: 'glsl',
8
+ version: getShaderVersion(source)
9
+ };
7
10
  }
8
- function getShaderName(shader) {
9
- let defaultName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unnamed';
10
- const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
11
- const match = SHADER_NAME_REGEXP.exec(shader);
12
- return match ? match[1] : defaultName;
11
+ /** Extracts GLSLIFY style naming of shaders: `#define SHADER_NAME ...` */
12
+ function getShaderName(shader, defaultName = 'unnamed') {
13
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
14
+ const match = SHADER_NAME_REGEXP.exec(shader);
15
+ return match ? match[1] : defaultName;
13
16
  }
17
+ /** returns GLSL shader version of given shader string */
14
18
  function getShaderVersion(source) {
15
- let version = 100;
16
- const words = source.match(/[^\s]+/g);
17
- if (words && words.length >= 2 && words[0] === '#version') {
18
- const v = parseInt(words[1], 10);
19
- if (Number.isFinite(v)) {
20
- version = v;
19
+ let version = 100;
20
+ const words = source.match(/[^\s]+/g);
21
+ if (words && words.length >= 2 && words[0] === '#version') {
22
+ const v = parseInt(words[1], 10);
23
+ if (Number.isFinite(v)) {
24
+ version = v;
25
+ }
21
26
  }
22
- }
23
- return version;
27
+ return version;
24
28
  }
25
- //# sourceMappingURL=get-shader-info.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"luma.d.ts","sourceRoot":"","sources":["../../src/lib/luma.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAQpD;;;;GAIG;AACH,qBAAa,IAAI;IACf,mCAAmC;IACnC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAa;IAEvC,iBAAiB;IACjB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAO;IAEtB,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,GAAyB,IAAI;IAOxE,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAItD,wCAAwC;WAC3B,YAAY,CAAC,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;CAmCpE"}
1
+ {"version":3,"file":"luma.d.ts","sourceRoot":"","sources":["../../src/lib/luma.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAQpD;;;;GAIG;AACH,qBAAa,IAAI;IACf,mCAAmC;IACnC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAa;IAEvC,iBAAiB;IACjB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAO;IAEtB,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,GAAyB,IAAI;IAOxE,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAItD,wCAAwC;WAC3B,YAAY,CAAC,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;CAiCpE"}
package/dist/lib/luma.js CHANGED
@@ -1,63 +1,68 @@
1
- import { Device } from "../adapter/device.js";
2
- import { lumaStats } from "../utils/stats-manager.js";
3
- import { log } from "../utils/log.js";
4
- import { assert } from "../utils/assert.js";
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ import { Device } from '../adapter/device';
4
+ import { lumaStats } from '../utils/stats-manager';
5
+ import { log } from '../utils/log';
6
+ import { assert } from '../utils/assert';
5
7
  const deviceList = new Map();
8
+ /**
9
+ * Entry point to the luma.gl GPU abstraction
10
+ * Register WebGPU and/or WebGL devices (controls application bundle size)
11
+ * Run-time selection of the first available Device
12
+ */
6
13
  export class luma {
7
- static registerDevices(deviceClasses) {
8
- for (const deviceClass of deviceClasses) {
9
- assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
10
- deviceList.set(deviceClass.type, deviceClass);
14
+ /** Global stats for all devices */
15
+ static stats = lumaStats;
16
+ /** Global log */
17
+ static log = log;
18
+ static registerDevices(deviceClasses /* : typeof Device */) {
19
+ for (const deviceClass of deviceClasses) {
20
+ assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
21
+ deviceList.set(deviceClass.type, deviceClass);
22
+ }
11
23
  }
12
- }
13
- static getAvailableDevices() {
14
- return Array.from(deviceList).map(Device => Device.type);
15
- }
16
- static getSupportedDevices() {
17
- return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type);
18
- }
19
- static setDefaultDeviceProps(props) {
20
- Object.assign(Device.defaultProps, props);
21
- }
22
- static async createDevice() {
23
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
- props = {
25
- ...Device.defaultProps,
26
- ...props
27
- };
28
- if (props.gl) {
29
- props.type = 'webgl';
24
+ static getAvailableDevices() {
25
+ // @ts-expect-error
26
+ return Array.from(deviceList).map(Device => Device.type);
30
27
  }
31
- let DeviceClass;
32
- switch (props.type) {
33
- case 'webgpu':
34
- DeviceClass = deviceList.get('webgpu');
35
- if (DeviceClass) {
36
- return await DeviceClass.create(props);
37
- }
38
- break;
39
- case 'webgl':
40
- case 'webgl1':
41
- case 'webgl2':
42
- DeviceClass = deviceList.get('webgl');
43
- if (DeviceClass) {
44
- return await DeviceClass.create(props);
45
- }
46
- break;
47
- case 'best-available':
48
- DeviceClass = deviceList.get('webgpu');
49
- if (DeviceClass && DeviceClass.isSupported()) {
50
- return await DeviceClass.create(props);
28
+ static getSupportedDevices() {
29
+ // @ts-expect-error
30
+ return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type);
31
+ }
32
+ static setDefaultDeviceProps(props) {
33
+ Object.assign(Device.defaultProps, props);
34
+ }
35
+ /** Creates a device. Asynchronously. */
36
+ static async createDevice(props = {}) {
37
+ props = { ...Device.defaultProps, ...props };
38
+ if (props.gl) {
39
+ props.type = 'webgl';
51
40
  }
52
- DeviceClass = deviceList.get('webgl');
53
- if (DeviceClass && DeviceClass.isSupported()) {
54
- return await DeviceClass.create(props);
41
+ let DeviceClass;
42
+ switch (props.type) {
43
+ case 'webgpu':
44
+ DeviceClass = deviceList.get('webgpu');
45
+ if (DeviceClass) {
46
+ return await DeviceClass.create(props);
47
+ }
48
+ break;
49
+ case 'webgl':
50
+ DeviceClass = deviceList.get('webgl');
51
+ if (DeviceClass) {
52
+ return await DeviceClass.create(props);
53
+ }
54
+ break;
55
+ case 'best-available':
56
+ DeviceClass = deviceList.get('webgpu');
57
+ if (DeviceClass && DeviceClass.isSupported()) {
58
+ return await DeviceClass.create(props);
59
+ }
60
+ DeviceClass = deviceList.get('webgl');
61
+ if (DeviceClass && DeviceClass.isSupported()) {
62
+ return await DeviceClass.create(props);
63
+ }
64
+ break;
55
65
  }
56
- break;
66
+ throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
57
67
  }
58
- throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
59
- }
60
68
  }
61
- luma.stats = lumaStats;
62
- luma.log = log;
63
- //# sourceMappingURL=luma.js.map
@@ -4,7 +4,6 @@ import { ShaderLayout, UniformInfo } from '../../adapter/types/shader-layout';
4
4
  /**
5
5
  * A uniform block holds values of the of uniform values for one uniform block / buffer.
6
6
  * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
7
- * @todo - Track changes to individual uniforms (for WebGL1)
8
7
  */
9
8
  export declare class UniformBlock<TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>> {
10
9
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"uniform-block.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform-block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,WAAW,EAEZ,MAAM,mCAAmC,CAAC;AAG3C;;;;GAIG;AACH,qBAAa,YAAY,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IACrG,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,YAAY,CAAC,CAA+C;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,OAAO,CAAC,CAA0C;IAC5F,QAAQ,EAAE,OAAO,CAAQ;IAEzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAM;IACzD,WAAW,EAAE,MAAM,GAAG,KAAK,CAAiB;gBAEhC,KAAK,CAAC,EAAE;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;KAC3E;IAmBD,4BAA4B;IAC5B,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAS/C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,2BAA2B;IAC3B,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAO9C,2BAA2B;IAC3B,OAAO,CAAC,WAAW;CAQpB"}
1
+ {"version":3,"file":"uniform-block.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform-block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,WAAW,EAEZ,MAAM,mCAAmC,CAAC;AAG3C;;;GAGG;AACH,qBAAa,YAAY,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IACrG,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,YAAY,CAAC,CAA+C;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,OAAO,CAAC,CAA0C;IAC5F,QAAQ,EAAE,OAAO,CAAQ;IAEzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAM;IACzD,WAAW,EAAE,MAAM,GAAG,KAAK,CAAiB;gBAEhC,KAAK,CAAC,EAAE;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;KAC3E;IAmBD,4BAA4B;IAC5B,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAS/C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,2BAA2B;IAC3B,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAO9C,2BAA2B;IAC3B,OAAO,CAAC,WAAW;CAQpB"}
@@ -1,48 +1,55 @@
1
- import { arrayEqual, arrayCopy } from "../../utils/array-equal.js";
1
+ import { arrayEqual, arrayCopy } from '../../utils/array-equal';
2
+ /**
3
+ * A uniform block holds values of the of uniform values for one uniform block / buffer.
4
+ * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
5
+ */
2
6
  export class UniformBlock {
3
- constructor(props) {
4
- this.name = void 0;
5
- this.uniforms = {};
6
- this.modifiedUniforms = {};
7
- this.modified = true;
8
- this.bindingLayout = {};
9
- this.needsRedraw = 'initialized';
10
- this.name = props === null || props === void 0 ? void 0 : props.name;
11
- if (props !== null && props !== void 0 && props.name && props !== null && props !== void 0 && props.shaderLayout) {
12
- var _props$shaderLayout$b;
13
- const binding = props === null || props === void 0 || (_props$shaderLayout$b = props.shaderLayout.bindings) === null || _props$shaderLayout$b === void 0 ? void 0 : _props$shaderLayout$b.find(binding => binding.type === 'uniform' && binding.name === (props === null || props === void 0 ? void 0 : props.name));
14
- if (!binding) {
15
- throw new Error(props === null || props === void 0 ? void 0 : props.name);
16
- }
17
- const uniformBlock = binding;
18
- for (const uniform of uniformBlock.uniforms || []) {
19
- this.bindingLayout[uniform.name] = uniform;
20
- }
7
+ name;
8
+ uniforms = {};
9
+ modifiedUniforms = {};
10
+ modified = true;
11
+ bindingLayout = {};
12
+ needsRedraw = 'initialized';
13
+ constructor(props) {
14
+ this.name = props?.name;
15
+ // TODO - Extract uniform layout from the shaderLayout object
16
+ if (props?.name && props?.shaderLayout) {
17
+ const binding = props?.shaderLayout.bindings?.find(binding => binding.type === 'uniform' && binding.name === props?.name);
18
+ if (!binding) {
19
+ throw new Error(props?.name);
20
+ }
21
+ const uniformBlock = binding;
22
+ for (const uniform of uniformBlock.uniforms || []) {
23
+ this.bindingLayout[uniform.name] = uniform;
24
+ }
25
+ }
21
26
  }
22
- }
23
- setUniforms(uniforms) {
24
- for (const [key, value] of Object.entries(uniforms)) {
25
- this._setUniform(key, value);
26
- if (!this.needsRedraw) {
27
- this.setNeedsRedraw(`${this.name}.${key}=${value}`);
28
- }
27
+ /** Set a map of uniforms */
28
+ setUniforms(uniforms) {
29
+ for (const [key, value] of Object.entries(uniforms)) {
30
+ this._setUniform(key, value);
31
+ if (!this.needsRedraw) {
32
+ this.setNeedsRedraw(`${this.name}.${key}=${value}`);
33
+ }
34
+ }
29
35
  }
30
- }
31
- setNeedsRedraw(reason) {
32
- this.needsRedraw = this.needsRedraw || reason;
33
- }
34
- getAllUniforms() {
35
- this.modifiedUniforms = {};
36
- this.needsRedraw = false;
37
- return this.uniforms || {};
38
- }
39
- _setUniform(key, value) {
40
- if (arrayEqual(this.uniforms[key], value)) {
41
- return;
36
+ setNeedsRedraw(reason) {
37
+ this.needsRedraw = this.needsRedraw || reason;
38
+ }
39
+ /** Returns all uniforms */
40
+ getAllUniforms() {
41
+ // @ts-expect-error
42
+ this.modifiedUniforms = {};
43
+ this.needsRedraw = false;
44
+ return (this.uniforms || {});
45
+ }
46
+ /** Set a single uniform */
47
+ _setUniform(key, value) {
48
+ if (arrayEqual(this.uniforms[key], value)) {
49
+ return;
50
+ }
51
+ this.uniforms[key] = arrayCopy(value);
52
+ this.modifiedUniforms[key] = true;
53
+ this.modified = true;
42
54
  }
43
- this.uniforms[key] = arrayCopy(value);
44
- this.modifiedUniforms[key] = true;
45
- this.modified = true;
46
- }
47
55
  }
48
- //# sourceMappingURL=uniform-block.js.map
@@ -1,76 +1,93 @@
1
- import { decodeShaderUniformType, alignTo } from "../../adapter/type-utils/decode-shader-types.js";
2
- import { getScratchArrayBuffer } from "../../utils/array-utils-flat.js";
3
- import { isNumberArray } from "../../utils/is-array.js";
4
- import { log } from "../../utils/log.js";
1
+ import { decodeShaderUniformType, alignTo } from '../../adapter/type-utils/decode-shader-types';
2
+ import { getScratchArrayBuffer } from '../../utils/array-utils-flat';
3
+ import { isNumberArray } from '../../utils/is-array';
4
+ import { log } from '../../utils/log';
5
+ /**
6
+ * Smallest buffer size that can be used for uniform buffers.
7
+ * TODO - does this depend on device?
8
+ */
5
9
  const minBufferSize = 1024;
10
+ /**
11
+ * Std140 layout for uniform buffers
12
+ * Supports manual listing of uniforms
13
+ */
6
14
  export class UniformBufferLayout {
7
- constructor(uniformTypes) {
8
- this.layout = {};
9
- this.byteLength = void 0;
10
- let size = 0;
11
- for (const [key, uniformType] of Object.entries(uniformTypes)) {
12
- const typeAndComponents = decodeShaderUniformType(uniformType);
13
- const {
14
- type,
15
- components: count
16
- } = typeAndComponents;
17
- size = alignTo(size, count);
18
- const offset = size;
19
- size += count;
20
- this.layout[key] = {
21
- type,
22
- size: count,
23
- offset
24
- };
25
- }
26
- size += (4 - size % 4) % 4;
27
- const actualByteLength = size * 4;
28
- this.byteLength = Math.max(actualByteLength, minBufferSize);
29
- }
30
- getData(uniformValues) {
31
- const bufferSize = Math.max(this.byteLength, minBufferSize);
32
- const arrayBuffer = getScratchArrayBuffer(bufferSize);
33
- const typedArrays = {
34
- i32: new Int32Array(arrayBuffer),
35
- u32: new Uint32Array(arrayBuffer),
36
- f32: new Float32Array(arrayBuffer),
37
- f16: new Uint16Array(arrayBuffer)
38
- };
39
- for (const [name, value] of Object.entries(uniformValues)) {
40
- const uniformLayout = this.layout[name];
41
- if (!uniformLayout) {
42
- log.warn(`Supplied uniform value ${name} not present in uniform block layout`)();
43
- continue;
44
- }
45
- const {
46
- type,
47
- size,
48
- offset
49
- } = uniformLayout;
50
- const typedArray = typedArrays[type];
51
- if (size === 1) {
52
- if (typeof value !== 'number' && typeof value !== 'boolean') {
53
- log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)();
54
- continue;
15
+ layout = {};
16
+ /** number of bytes needed for buffer allocation */
17
+ byteLength;
18
+ /** Create a new UniformBufferLayout given a map of attributes. */
19
+ constructor(uniformTypes) {
20
+ /** number of 4 byte slots taken */
21
+ let size = 0;
22
+ // Add layout (type, size and offset) definitions for each uniform in the layout
23
+ for (const [key, uniformType] of Object.entries(uniformTypes)) {
24
+ const typeAndComponents = decodeShaderUniformType(uniformType);
25
+ const { type, components: count } = typeAndComponents;
26
+ // First, align (bump) current offset to an even multiple of current object (1, 2, 4)
27
+ size = alignTo(size, count);
28
+ // Use the aligned size as the offset of the current uniform.
29
+ const offset = size;
30
+ // Then, add our object's padded size ((1, 2, multiple of 4) to the current offset
31
+ size += count;
32
+ this.layout[key] = { type, size: count, offset };
55
33
  }
56
- typedArray[offset] = Number(value);
57
- } else {
58
- const numericArray = isNumberArray(value);
59
- if (!numericArray) {
60
- log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)();
61
- continue;
34
+ size += (4 - (size % 4)) % 4;
35
+ const actualByteLength = size * 4;
36
+ this.byteLength = Math.max(actualByteLength, minBufferSize);
37
+ }
38
+ /** Get the data for the complete buffer */
39
+ getData(uniformValues) {
40
+ const bufferSize = Math.max(this.byteLength, minBufferSize);
41
+ // Allocate three typed arrays pointing at same memory
42
+ const arrayBuffer = getScratchArrayBuffer(bufferSize);
43
+ const typedArrays = {
44
+ i32: new Int32Array(arrayBuffer),
45
+ u32: new Uint32Array(arrayBuffer),
46
+ f32: new Float32Array(arrayBuffer),
47
+ // TODO not implemented
48
+ f16: new Uint16Array(arrayBuffer)
49
+ };
50
+ // TODO is this needed?
51
+ // typedArrays.i32.fill(0);
52
+ for (const [name, value] of Object.entries(uniformValues)) {
53
+ const uniformLayout = this.layout[name];
54
+ if (!uniformLayout) {
55
+ log.warn(`Supplied uniform value ${name} not present in uniform block layout`)();
56
+ // eslint-disable-next-line no-continue
57
+ continue;
58
+ }
59
+ const { type, size, offset } = uniformLayout;
60
+ const typedArray = typedArrays[type];
61
+ if (size === 1) {
62
+ if (typeof value !== 'number' && typeof value !== 'boolean') {
63
+ log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)();
64
+ // eslint-disable-next-line no-continue
65
+ continue;
66
+ }
67
+ // single value -> just set it
68
+ typedArray[offset] = Number(value);
69
+ }
70
+ else {
71
+ const numericArray = isNumberArray(value);
72
+ if (!numericArray) {
73
+ log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)();
74
+ // eslint-disable-next-line no-continue
75
+ continue;
76
+ }
77
+ // vector/matrix -> copy the supplied (typed) array, starting from offset
78
+ // TODO: we should limit or check size in case the supplied data overflows
79
+ typedArray.set(numericArray, offset);
80
+ }
62
81
  }
63
- typedArray.set(numericArray, offset);
64
- }
82
+ return new Uint8Array(arrayBuffer);
83
+ }
84
+ /** Does this layout have a field with specified name */
85
+ has(name) {
86
+ return Boolean(this.layout[name]);
87
+ }
88
+ /** Get offset and size for a field with specified name */
89
+ get(name) {
90
+ const layout = this.layout[name];
91
+ return layout;
65
92
  }
66
- return new Uint8Array(arrayBuffer);
67
- }
68
- has(name) {
69
- return Boolean(this.layout[name]);
70
- }
71
- get(name) {
72
- const layout = this.layout[name];
73
- return layout;
74
- }
75
93
  }
76
- //# sourceMappingURL=uniform-buffer-layout.js.map