@luma.gl/core 9.0.0-alpha.9 → 9.0.0-beta.2

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 (306) hide show
  1. package/LICENSE +3 -1
  2. package/README.md +4 -4
  3. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts +52 -0
  4. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -0
  5. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +130 -0
  6. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +1 -0
  7. package/dist/adapter/canvas-context.d.ts +109 -0
  8. package/dist/adapter/canvas-context.d.ts.map +1 -0
  9. package/dist/adapter/canvas-context.js +254 -0
  10. package/dist/adapter/canvas-context.js.map +1 -0
  11. package/dist/adapter/device.d.ts +219 -0
  12. package/dist/adapter/device.d.ts.map +1 -0
  13. package/dist/adapter/device.js +99 -0
  14. package/dist/adapter/device.js.map +1 -0
  15. package/dist/adapter/resources/buffer.d.ts +56 -0
  16. package/dist/adapter/resources/buffer.d.ts.map +1 -0
  17. package/dist/adapter/resources/buffer.js +62 -0
  18. package/dist/adapter/resources/buffer.js.map +1 -0
  19. package/dist/adapter/resources/command-buffer.d.ts +12 -0
  20. package/dist/adapter/resources/command-buffer.d.ts.map +1 -0
  21. package/dist/adapter/resources/command-buffer.js +15 -0
  22. package/dist/adapter/resources/command-buffer.js.map +1 -0
  23. package/dist/adapter/resources/command-encoder.d.ts +113 -0
  24. package/dist/adapter/resources/command-encoder.d.ts.map +1 -0
  25. package/dist/adapter/resources/command-encoder.js +19 -0
  26. package/dist/adapter/resources/command-encoder.js.map +1 -0
  27. package/dist/adapter/resources/compute-pass.d.ts +31 -0
  28. package/dist/adapter/resources/compute-pass.d.ts.map +1 -0
  29. package/dist/adapter/resources/compute-pass.js +15 -0
  30. package/dist/adapter/resources/compute-pass.js.map +1 -0
  31. package/dist/adapter/resources/compute-pipeline.d.ts +24 -0
  32. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -0
  33. package/dist/adapter/resources/compute-pipeline.js +20 -0
  34. package/dist/adapter/resources/compute-pipeline.js.map +1 -0
  35. package/dist/adapter/resources/external-texture.d.ts +12 -0
  36. package/dist/adapter/resources/external-texture.d.ts.map +1 -0
  37. package/dist/adapter/resources/external-texture.js +17 -0
  38. package/dist/adapter/resources/external-texture.js.map +1 -0
  39. package/dist/adapter/resources/framebuffer.d.ts +50 -0
  40. package/dist/adapter/resources/framebuffer.d.ts.map +1 -0
  41. package/dist/adapter/resources/framebuffer.js +102 -0
  42. package/dist/adapter/resources/framebuffer.js.map +1 -0
  43. package/dist/adapter/resources/render-pass.d.ts +51 -0
  44. package/dist/adapter/resources/render-pass.d.ts.map +1 -0
  45. package/dist/adapter/resources/render-pass.js +23 -0
  46. package/dist/adapter/resources/render-pass.js.map +1 -0
  47. package/dist/adapter/resources/render-pipeline.d.ts +89 -0
  48. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -0
  49. package/dist/adapter/resources/render-pipeline.js +36 -0
  50. package/dist/adapter/resources/render-pipeline.js.map +1 -0
  51. package/dist/adapter/resources/resource.d.ts +73 -0
  52. package/dist/adapter/resources/resource.d.ts.map +1 -0
  53. package/dist/adapter/resources/resource.js +101 -0
  54. package/dist/adapter/resources/resource.js.map +1 -0
  55. package/dist/adapter/resources/sampler.d.ts +42 -0
  56. package/dist/adapter/resources/sampler.d.ts.map +1 -0
  57. package/dist/adapter/resources/sampler.js +26 -0
  58. package/dist/adapter/resources/sampler.js.map +1 -0
  59. package/dist/adapter/resources/shader.d.ts +45 -0
  60. package/dist/adapter/resources/shader.d.ts.map +1 -0
  61. package/dist/adapter/resources/shader.js +90 -0
  62. package/dist/adapter/resources/shader.js.map +1 -0
  63. package/dist/adapter/resources/texture.d.ts +90 -0
  64. package/dist/adapter/resources/texture.d.ts.map +1 -0
  65. package/dist/adapter/resources/texture.js +45 -0
  66. package/dist/adapter/resources/texture.js.map +1 -0
  67. package/dist/adapter/resources/transform-feedback.d.ts +30 -0
  68. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -0
  69. package/dist/adapter/resources/transform-feedback.js +17 -0
  70. package/dist/adapter/resources/transform-feedback.js.map +1 -0
  71. package/dist/adapter/resources/vertex-array.d.ts +40 -0
  72. package/dist/adapter/resources/vertex-array.d.ts.map +1 -0
  73. package/dist/adapter/resources/vertex-array.js +24 -0
  74. package/dist/adapter/resources/vertex-array.js.map +1 -0
  75. package/dist/adapter/type-utils/decode-attribute-type.d.ts +20 -0
  76. package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -0
  77. package/dist/adapter/type-utils/decode-attribute-type.js +60 -0
  78. package/dist/adapter/type-utils/decode-attribute-type.js.map +1 -0
  79. package/dist/adapter/type-utils/decode-data-type.d.ts +16 -0
  80. package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -0
  81. package/dist/adapter/type-utils/decode-data-type.js +43 -0
  82. package/dist/adapter/type-utils/decode-data-type.js.map +1 -0
  83. package/dist/adapter/type-utils/decode-shader-types.d.ts +9 -0
  84. package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -0
  85. package/dist/adapter/type-utils/decode-shader-types.js +103 -0
  86. package/dist/adapter/type-utils/decode-shader-types.js.map +1 -0
  87. package/dist/adapter/type-utils/decode-texture-format.d.ts +19 -0
  88. package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -0
  89. package/dist/adapter/type-utils/decode-texture-format.js +101 -0
  90. package/dist/adapter/type-utils/decode-texture-format.js.map +1 -0
  91. package/dist/adapter/type-utils/decode-vertex-format.d.ts +22 -0
  92. package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -0
  93. package/dist/adapter/type-utils/decode-vertex-format.js +25 -0
  94. package/dist/adapter/type-utils/decode-vertex-format.js.map +1 -0
  95. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +10 -0
  96. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -0
  97. package/dist/adapter/type-utils/vertex-format-from-attribute.js +76 -0
  98. package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +1 -0
  99. package/dist/adapter/type-utils/wgsl-utils.d.ts +4 -0
  100. package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -0
  101. package/dist/adapter/type-utils/wgsl-utils.js +15 -0
  102. package/dist/adapter/type-utils/wgsl-utils.js.map +1 -0
  103. package/dist/adapter/types/accessor.d.ts +23 -0
  104. package/dist/adapter/types/accessor.d.ts.map +1 -0
  105. package/dist/adapter/types/accessor.js +2 -0
  106. package/dist/adapter/types/accessor.js.map +1 -0
  107. package/dist/adapter/types/buffer-layout.d.ts +59 -0
  108. package/dist/adapter/types/buffer-layout.d.ts.map +1 -0
  109. package/dist/adapter/types/buffer-layout.js +2 -0
  110. package/dist/adapter/types/buffer-layout.js.map +1 -0
  111. package/dist/adapter/types/parameters.d.ts +97 -0
  112. package/dist/adapter/types/parameters.d.ts.map +1 -0
  113. package/dist/adapter/types/parameters.js +28 -0
  114. package/dist/adapter/types/parameters.js.map +1 -0
  115. package/dist/adapter/types/shader-layout.d.ts +145 -0
  116. package/dist/adapter/types/shader-layout.d.ts.map +1 -0
  117. package/dist/adapter/types/shader-layout.js +2 -0
  118. package/dist/adapter/types/shader-layout.js.map +1 -0
  119. package/dist/adapter/types/shader-types.d.ts +21 -0
  120. package/dist/adapter/types/shader-types.d.ts.map +1 -0
  121. package/dist/adapter/types/shader-types.js +2 -0
  122. package/dist/adapter/types/shader-types.js.map +1 -0
  123. package/dist/adapter/types/texture-formats.d.ts +12 -0
  124. package/dist/adapter/types/texture-formats.d.ts.map +1 -0
  125. package/dist/adapter/types/texture-formats.js +2 -0
  126. package/dist/adapter/types/texture-formats.js.map +1 -0
  127. package/dist/adapter/types/types.d.ts +90 -0
  128. package/dist/adapter/types/types.d.ts.map +1 -0
  129. package/dist/adapter/types/types.js +2 -0
  130. package/dist/adapter/types/types.js.map +1 -0
  131. package/dist/adapter/types/vertex-formats.d.ts +14 -0
  132. package/dist/adapter/types/vertex-formats.d.ts.map +1 -0
  133. package/dist/adapter/types/vertex-formats.js +2 -0
  134. package/dist/adapter/types/vertex-formats.js.map +1 -0
  135. package/dist/dist.dev.js +2976 -0
  136. package/dist/index.cjs +2445 -0
  137. package/dist/index.d.ts +81 -128
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +45 -18
  140. package/dist/index.js.map +1 -1
  141. package/dist/init.d.ts +5 -0
  142. package/dist/init.d.ts.map +1 -0
  143. package/dist/init.js +24 -0
  144. package/dist/init.js.map +1 -0
  145. package/dist/lib/compiler-log/compiler-message.d.ts +8 -0
  146. package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -0
  147. package/dist/lib/compiler-log/compiler-message.js +2 -0
  148. package/dist/lib/compiler-log/compiler-message.js.map +1 -0
  149. package/dist/lib/compiler-log/format-compiler-log.d.ts +8 -0
  150. package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -0
  151. package/dist/lib/compiler-log/format-compiler-log.js +64 -0
  152. package/dist/lib/compiler-log/format-compiler-log.js.map +1 -0
  153. package/dist/lib/compiler-log/get-shader-info.d.ts +9 -0
  154. package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -0
  155. package/dist/lib/compiler-log/get-shader-info.js +25 -0
  156. package/dist/lib/compiler-log/get-shader-info.js.map +1 -0
  157. package/dist/lib/luma.d.ts +22 -0
  158. package/dist/lib/luma.d.ts.map +1 -0
  159. package/dist/lib/luma.js +63 -0
  160. package/dist/lib/luma.js.map +1 -0
  161. package/dist/lib/uniforms/uniform-block.d.ts +29 -0
  162. package/dist/lib/uniforms/uniform-block.d.ts.map +1 -0
  163. package/dist/lib/uniforms/uniform-block.js +48 -0
  164. package/dist/lib/uniforms/uniform-block.js.map +1 -0
  165. package/dist/lib/uniforms/uniform-buffer-layout.d.ts +27 -0
  166. package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -0
  167. package/dist/lib/uniforms/uniform-buffer-layout.js +76 -0
  168. package/dist/lib/uniforms/uniform-buffer-layout.js.map +1 -0
  169. package/dist/lib/uniforms/uniform-store.d.ts +62 -0
  170. package/dist/lib/uniforms/uniform-store.d.ts.map +1 -0
  171. package/dist/lib/uniforms/uniform-store.js +89 -0
  172. package/dist/lib/uniforms/uniform-store.js.map +1 -0
  173. package/dist/lib/uniforms/uniform.d.ts +10 -0
  174. package/dist/lib/uniforms/uniform.d.ts.map +1 -0
  175. package/dist/lib/uniforms/uniform.js +20 -0
  176. package/dist/lib/uniforms/uniform.js.map +1 -0
  177. package/dist/types.d.ts +19 -0
  178. package/dist/types.d.ts.map +1 -0
  179. package/dist/types.js +3 -0
  180. package/dist/types.js.map +1 -0
  181. package/dist/utils/array-equal.d.ts +5 -0
  182. package/dist/utils/array-equal.d.ts.map +1 -0
  183. package/dist/utils/array-equal.js +28 -0
  184. package/dist/utils/array-equal.js.map +1 -0
  185. package/dist/utils/array-utils-flat.d.ts +10 -0
  186. package/dist/utils/array-utils-flat.d.ts.map +1 -0
  187. package/dist/utils/array-utils-flat.js +36 -0
  188. package/dist/utils/array-utils-flat.js.map +1 -0
  189. package/dist/utils/assert.d.ts +2 -0
  190. package/dist/utils/assert.d.ts.map +1 -0
  191. package/dist/utils/assert.js +6 -0
  192. package/dist/utils/assert.js.map +1 -0
  193. package/dist/utils/cast.d.ts +3 -0
  194. package/dist/utils/cast.d.ts.map +1 -0
  195. package/dist/utils/cast.js +4 -0
  196. package/dist/utils/cast.js.map +1 -0
  197. package/dist/utils/check-props.d.ts +7 -0
  198. package/dist/utils/check-props.d.ts.map +1 -0
  199. package/dist/utils/check-props.js +32 -0
  200. package/dist/utils/check-props.js.map +1 -0
  201. package/dist/utils/deep-equal.d.ts +9 -0
  202. package/dist/utils/deep-equal.d.ts.map +1 -0
  203. package/dist/utils/deep-equal.js +40 -0
  204. package/dist/utils/deep-equal.js.map +1 -0
  205. package/dist/utils/format-value.d.ts +7 -0
  206. package/dist/utils/format-value.d.ts.map +1 -0
  207. package/dist/utils/format-value.js +42 -0
  208. package/dist/utils/format-value.js.map +1 -0
  209. package/dist/utils/is-array.d.ts +16 -0
  210. package/dist/utils/is-array.d.ts.map +1 -0
  211. package/dist/utils/is-array.js +10 -0
  212. package/dist/utils/is-array.js.map +1 -0
  213. package/dist/utils/load-file.d.ts +35 -0
  214. package/dist/utils/load-file.d.ts.map +1 -0
  215. package/dist/utils/load-file.js +48 -0
  216. package/dist/utils/load-file.js.map +1 -0
  217. package/dist/utils/log.d.ts +4 -0
  218. package/dist/utils/log.d.ts.map +1 -0
  219. package/dist/utils/log.js +5 -0
  220. package/dist/utils/log.js.map +1 -0
  221. package/dist/utils/random.d.ts +5 -0
  222. package/dist/utils/random.d.ts.map +1 -0
  223. package/dist/utils/random.js +14 -0
  224. package/dist/utils/random.js.map +1 -0
  225. package/dist/utils/request-animation-frame.d.ts +3 -0
  226. package/dist/utils/request-animation-frame.d.ts.map +1 -0
  227. package/dist/utils/request-animation-frame.js +7 -0
  228. package/dist/utils/request-animation-frame.js.map +1 -0
  229. package/dist/utils/stats-manager.d.ts +12 -0
  230. package/dist/utils/stats-manager.d.ts.map +1 -0
  231. package/dist/utils/stats-manager.js +19 -0
  232. package/dist/utils/stats-manager.js.map +1 -0
  233. package/dist/utils/stub-methods.d.ts +2 -0
  234. package/dist/utils/stub-methods.d.ts.map +1 -0
  235. package/dist/utils/stub-methods.js +16 -0
  236. package/dist/utils/stub-methods.js.map +1 -0
  237. package/dist/utils/utils.d.ts +15 -0
  238. package/dist/utils/utils.d.ts.map +1 -0
  239. package/dist/utils/utils.js +19 -0
  240. package/dist/utils/utils.js.map +1 -0
  241. package/dist.min.js +33 -0
  242. package/package.json +17 -12
  243. package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +259 -0
  244. package/src/adapter/canvas-context.ts +433 -0
  245. package/src/adapter/device.ts +435 -0
  246. package/src/adapter/resources/buffer.ts +106 -0
  247. package/src/adapter/resources/command-buffer.ts +38 -0
  248. package/src/adapter/resources/command-encoder.ts +172 -0
  249. package/src/adapter/resources/compute-pass.ts +52 -0
  250. package/src/adapter/resources/compute-pipeline.ts +39 -0
  251. package/src/adapter/resources/external-texture.ts +20 -0
  252. package/src/adapter/resources/framebuffer.ts +230 -0
  253. package/src/adapter/resources/render-pass.ts +117 -0
  254. package/src/adapter/resources/render-pipeline.ts +133 -0
  255. package/src/adapter/resources/resource.ts +176 -0
  256. package/src/adapter/resources/sampler.ts +69 -0
  257. package/src/adapter/resources/shader.ts +143 -0
  258. package/src/adapter/resources/texture.ts +140 -0
  259. package/src/adapter/resources/transform-feedback.ts +45 -0
  260. package/src/adapter/resources/vertex-array.ts +65 -0
  261. package/src/adapter/type-utils/decode-attribute-type.ts +82 -0
  262. package/src/adapter/type-utils/decode-data-type.ts +62 -0
  263. package/src/adapter/type-utils/decode-shader-types.ts +48 -0
  264. package/src/adapter/type-utils/decode-texture-format.ts +190 -0
  265. package/src/adapter/type-utils/decode-vertex-format.ts +49 -0
  266. package/src/adapter/type-utils/vertex-format-from-attribute.ts +103 -0
  267. package/src/adapter/type-utils/wgsl-utils.ts +18 -0
  268. package/src/adapter/types/accessor.ts +34 -0
  269. package/src/adapter/types/buffer-layout.ts +62 -0
  270. package/src/adapter/types/parameters.ts +250 -0
  271. package/src/adapter/types/shader-layout.ts +193 -0
  272. package/src/adapter/types/shader-types.ts +77 -0
  273. package/src/adapter/types/texture-formats.ts +168 -0
  274. package/src/adapter/types/types.ts +109 -0
  275. package/src/adapter/types/vertex-formats.ts +91 -0
  276. package/src/index.ts +160 -92
  277. package/src/init.ts +47 -0
  278. package/src/lib/compiler-log/compiler-message.ts +10 -0
  279. package/src/lib/compiler-log/format-compiler-log.ts +113 -0
  280. package/src/lib/compiler-log/get-shader-info.ts +41 -0
  281. package/src/lib/luma.ts +84 -0
  282. package/src/lib/uniforms/uniform-block.ts +80 -0
  283. package/src/lib/uniforms/uniform-buffer-layout.ts +109 -0
  284. package/src/lib/uniforms/uniform-store.ts +173 -0
  285. package/src/lib/uniforms/uniform.ts +25 -0
  286. package/src/types.ts +33 -0
  287. package/src/utils/array-equal.ts +33 -0
  288. package/src/utils/array-utils-flat.ts +43 -0
  289. package/src/utils/assert.ts +7 -0
  290. package/src/utils/cast.ts +4 -0
  291. package/src/utils/check-props.ts +74 -0
  292. package/src/utils/deep-equal.ts +47 -0
  293. package/src/utils/format-value.ts +40 -0
  294. package/src/utils/is-array.ts +24 -0
  295. package/src/utils/load-file.ts +89 -0
  296. package/src/utils/log.ts +4 -0
  297. package/src/utils/random.ts +17 -0
  298. package/src/utils/request-animation-frame.ts +15 -0
  299. package/src/utils/stats-manager.ts +23 -0
  300. package/src/utils/stub-methods.ts +20 -0
  301. package/src/utils/utils.ts +36 -0
  302. package/dist/bundle.d.ts +0 -2
  303. package/dist/bundle.d.ts.map +0 -1
  304. package/dist/bundle.js +0 -5
  305. package/dist/bundle.js.map +0 -1
  306. package/src/bundle.ts +0 -4
@@ -0,0 +1,10 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ /** WebGPU style compiler message */
5
+ export type CompilerMessage = {
6
+ type: 'error' | 'warning' | 'info';
7
+ message: string;
8
+ lineNum: number;
9
+ linePos: number;
10
+ }
@@ -0,0 +1,113 @@
1
+ // luma.gl, MIT license
2
+ import type {CompilerMessage} from './compiler-message';
3
+
4
+ /** @returns annotated errors or warnings */
5
+ export function formatCompilerLog(
6
+ shaderLog: readonly CompilerMessage[],
7
+ source: string,
8
+ options?: {
9
+ /** Include source code in the log. Either just the lines before issues or all source code */
10
+ showSourceCode?: 'no' | 'issues' | 'all';
11
+ html?: boolean;
12
+ }
13
+ ): string {
14
+ let formattedLog = '';
15
+ const lines = source.split(/\r?\n/);
16
+ const log = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
17
+
18
+ switch (options?.showSourceCode || 'no') {
19
+ case 'all':
20
+ // Parse the error - note: browser and driver dependent
21
+ let currentMessage = 0;
22
+ for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
23
+ formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
24
+ while (log.length > currentMessage && log[currentMessage].lineNum === lineNum) {
25
+ const message = log[currentMessage++];
26
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
27
+ ...options,
28
+ inlineSource: false
29
+ });
30
+ }
31
+ }
32
+ return formattedLog;
33
+
34
+ case 'issues':
35
+ case 'no':
36
+ // Parse the error - note: browser and driver dependent
37
+ for (const message of shaderLog) {
38
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
39
+ inlineSource: options?.showSourceCode !== 'no'
40
+ });
41
+ }
42
+ return formattedLog;
43
+ }
44
+ }
45
+
46
+ // Helpers
47
+
48
+ /** Format one message */
49
+ function formatCompilerMessage(
50
+ message: CompilerMessage,
51
+ lines: readonly string[],
52
+ lineNum: number,
53
+ options: {
54
+ inlineSource?: boolean;
55
+ html?: boolean;
56
+ }
57
+ ): string {
58
+ if (options?.inlineSource) {
59
+ const numberedLines = getNumberedLines(lines, lineNum);
60
+ // If we got error position on line add a `^^^` indicator on next line
61
+ const positionIndicator = message.linePos > 0 ? `${' '.repeat(message.linePos + 5)}^^^\n` : '';
62
+ return `
63
+ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.message}
64
+
65
+ `;
66
+ }
67
+ return options?.html
68
+ ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message.type.toUpperCase()}: ${message.message}</b></div>`
69
+ : `${message.type.toUpperCase()}: ${message.message}`;
70
+ }
71
+
72
+ function getNumberedLines(
73
+ lines: readonly string[],
74
+ lineNum: number,
75
+ options?: {html?: boolean}
76
+ ): string {
77
+ let numberedLines = '';
78
+ for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
79
+ const sourceLine = lines[lineIndex - 1];
80
+ if (sourceLine !== undefined) {
81
+ numberedLines += getNumberedLine(sourceLine, lineNum, options);
82
+ }
83
+ }
84
+ return numberedLines;
85
+ }
86
+
87
+ function getNumberedLine(line: string, lineNum: number, options?: {html?: boolean}): string {
88
+ const escapedLine = options?.html ? escapeHTML(line) : line;
89
+ return `${padLeft(String(lineNum), 4)}: ${escapedLine}${options?.html ? '<br/>' : '\n'}`;
90
+ }
91
+
92
+ /**
93
+ * Pads a string with a number of spaces (space characters) to the left
94
+ * @param {String} string - string to pad
95
+ * @param {Number} digits - number of spaces to add
96
+ * @return {String} string - The padded string
97
+ */
98
+ function padLeft(string: string, paddedLength: number): string {
99
+ let result = '';
100
+ for (let i = string.length; i < paddedLength; ++i) {
101
+ result += ' ';
102
+ }
103
+ return result + string;
104
+ }
105
+
106
+ function escapeHTML(unsafe: string): string {
107
+ return unsafe
108
+ .replaceAll('&', '&amp;')
109
+ .replaceAll('<', '&lt;')
110
+ .replaceAll('>', '&gt;')
111
+ .replaceAll('"', '&quot;')
112
+ .replaceAll('\'', '&#039;');
113
+ }
@@ -0,0 +1,41 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ // Note: This was the only dependency that made @luma.gl/webgl depend on @luma.gl/shadertools
5
+ // This file was coped from shadertools to avoid the dependency
6
+
7
+ /** Information extracted from shader source code */
8
+ export type ShaderInfo = {
9
+ name: string;
10
+ language: 'glsl' | 'wgsl';
11
+ version: number;
12
+ };
13
+
14
+ /** Extracts information from shader source code */
15
+ export function getShaderInfo(source: string, defaultName?: string): ShaderInfo {
16
+ return {
17
+ name: getShaderName(source, defaultName),
18
+ language: 'glsl',
19
+ version: getShaderVersion(source)
20
+ };
21
+ }
22
+
23
+ /** Extracts GLSLIFY style naming of shaders: `#define SHADER_NAME ...` */
24
+ function getShaderName(shader: string, defaultName: string = 'unnamed'): string {
25
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
26
+ const match = SHADER_NAME_REGEXP.exec(shader);
27
+ return match ? match[1] : defaultName;
28
+ }
29
+
30
+ /** returns GLSL shader version of given shader string */
31
+ function getShaderVersion(source: string): number {
32
+ let version = 100;
33
+ const words = source.match(/[^\s]+/g);
34
+ if (words && words.length >= 2 && words[0] === '#version') {
35
+ const v = parseInt(words[1], 10);
36
+ if (Number.isFinite(v)) {
37
+ version = v;
38
+ }
39
+ }
40
+ return version;
41
+ }
@@ -0,0 +1,84 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import type {Log} from '@probe.gl/log';
5
+ import type {DeviceProps} from '../adapter/device';
6
+ import {Device} from '../adapter/device';
7
+ import {StatsManager} from '../utils/stats-manager';
8
+ import {lumaStats} from '../utils/stats-manager';
9
+ import {log} from '../utils/log';
10
+ import {assert} from '../utils/assert';
11
+
12
+
13
+ const deviceList = new Map<string, typeof Device>();
14
+
15
+ /**
16
+ * Entry point to the luma.gl GPU abstraction
17
+ * Register WebGPU and/or WebGL devices (controls application bundle size)
18
+ * Run-time selection of the first available Device
19
+ */
20
+ export class luma {
21
+ /** Global stats for all devices */
22
+ static stats: StatsManager = lumaStats;
23
+
24
+ /** Global log */
25
+ static log: Log = log;
26
+
27
+ static registerDevices(deviceClasses: any[] /* : typeof Device */): void {
28
+ for (const deviceClass of deviceClasses) {
29
+ assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
30
+ deviceList.set(deviceClass.type, deviceClass);
31
+ }
32
+ }
33
+
34
+ static getAvailableDevices(): string[] {
35
+ // @ts-expect-error
36
+ return Array.from(deviceList).map(Device => Device.type);
37
+ }
38
+
39
+ static getSupportedDevices(): string[] {
40
+ // @ts-expect-error
41
+ return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type);
42
+ }
43
+
44
+ static setDefaultDeviceProps(props: DeviceProps): void {
45
+ Object.assign(Device.defaultProps, props);
46
+ }
47
+
48
+ /** Creates a device. Asynchronously. */
49
+ static async createDevice(props: DeviceProps = {}): Promise<Device> {
50
+ props = {...Device.defaultProps, ...props}
51
+ if (props.gl) {
52
+ props.type = 'webgl';
53
+ }
54
+
55
+ let DeviceClass: any;
56
+ switch (props.type) {
57
+ case 'webgpu':
58
+ DeviceClass = deviceList.get('webgpu');
59
+ if (DeviceClass) {
60
+ return await DeviceClass.create(props);
61
+ }
62
+ break;
63
+ case 'webgl':
64
+ case 'webgl1':
65
+ case 'webgl2':
66
+ DeviceClass = deviceList.get('webgl');
67
+ if (DeviceClass) {
68
+ return await DeviceClass.create(props);
69
+ }
70
+ break;
71
+ case 'best-available':
72
+ DeviceClass = deviceList.get('webgpu');
73
+ if (DeviceClass && DeviceClass.isSupported()) {
74
+ return await DeviceClass.create(props);
75
+ }
76
+ DeviceClass = deviceList.get('webgl');
77
+ if (DeviceClass && DeviceClass.isSupported()) {
78
+ return await DeviceClass.create(props);
79
+ }
80
+ break;
81
+ }
82
+ throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
83
+ }
84
+ }
@@ -0,0 +1,80 @@
1
+ // luma.gl, MIT license
2
+ import type {ShaderUniformType} from '../../adapter/types/shader-types';
3
+ import type {UniformValue} from '../../adapter/types/types';
4
+ import {
5
+ ShaderLayout,
6
+ UniformInfo,
7
+ UniformBufferBindingLayout
8
+ } from '../../adapter/types/shader-layout';
9
+ import {arrayEqual, arrayCopy} from '../../utils/array-equal';
10
+
11
+ /**
12
+ * A uniform block holds values of the of uniform values for one uniform block / buffer.
13
+ * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
14
+ * @todo - Track changes to individual uniforms (for WebGL1)
15
+ */
16
+ export class UniformBlock<TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>> {
17
+ name: string;
18
+
19
+ uniforms: Record<keyof TUniforms, UniformValue> = {} as Record<keyof TUniforms, UniformValue>;
20
+ modifiedUniforms: Record<keyof TUniforms, boolean> = {} as Record<keyof TUniforms, boolean>;
21
+ modified: boolean = true;
22
+
23
+ readonly bindingLayout: Record<string, UniformInfo> = {};
24
+ needsRedraw: string | false = 'initialized';
25
+
26
+ constructor(props?: {
27
+ name?: string;
28
+ shaderLayout?: ShaderLayout;
29
+ uniformTypes?: Record<keyof TUniforms, Record<string, ShaderUniformType>>;
30
+ }) {
31
+ this.name = props?.name;
32
+
33
+ // TODO - Extract uniform layout from the shaderLayout object
34
+ if (props?.name && props?.shaderLayout) {
35
+ const binding = props?.shaderLayout.bindings?.find(
36
+ binding => binding.type === 'uniform' && binding.name === props?.name
37
+ );
38
+ if (!binding) {
39
+ throw new Error(props?.name);
40
+ }
41
+
42
+ const uniformBlock = binding as UniformBufferBindingLayout;
43
+ for (const uniform of uniformBlock.uniforms || []) {
44
+ this.bindingLayout[uniform.name] = uniform;
45
+ }
46
+ }
47
+ }
48
+
49
+ /** Set a map of uniforms */
50
+ setUniforms(uniforms: Partial<TUniforms>): void {
51
+ for (const [key, value] of Object.entries(uniforms)) {
52
+ this._setUniform(key, value);
53
+ if (!this.needsRedraw) {
54
+ this.setNeedsRedraw(`${this.name}.${key}=${value}`);
55
+ }
56
+ }
57
+ }
58
+
59
+ setNeedsRedraw(reason: string): void {
60
+ this.needsRedraw = this.needsRedraw || reason;
61
+ }
62
+
63
+ /** Returns all uniforms */
64
+ getAllUniforms(): Record<string, UniformValue> {
65
+ // @ts-expect-error
66
+ this.modifiedUniforms = {};
67
+ this.needsRedraw = false;
68
+ return (this.uniforms || {}) as Record<string, UniformValue>;
69
+ }
70
+
71
+ /** Set a single uniform */
72
+ private _setUniform(key: keyof TUniforms, value: UniformValue) {
73
+ if (arrayEqual(this.uniforms[key], value)) {
74
+ return;
75
+ }
76
+ this.uniforms[key] = arrayCopy(value);
77
+ this.modifiedUniforms[key] = true;
78
+ this.modified = true;
79
+ }
80
+ }
@@ -0,0 +1,109 @@
1
+ // luma.gl, MIT license
2
+ import type {ShaderUniformType, ShaderDataType} from '../../adapter/types/shader-types';
3
+ import type {UniformValue} from '../../adapter/types/types';
4
+ import {decodeShaderUniformType, alignTo} from '../../adapter/type-utils/decode-shader-types';
5
+ import {getScratchArrayBuffer} from '../../utils/array-utils-flat';
6
+ import {isNumberArray} from '../../utils/is-array';
7
+ import { log } from '../../utils/log';
8
+
9
+ /**
10
+ * Smallest buffer size that can be used for uniform buffers.
11
+ * TODO - does this depend on device?
12
+ */
13
+ const minBufferSize: number = 1024;
14
+
15
+ /**
16
+ * Std140 layout for uniform buffers
17
+ * Supports manual listing of uniforms
18
+ */
19
+ export class UniformBufferLayout {
20
+ readonly layout: Record<string, {offset: number, size: number, type: ShaderDataType}> = {};
21
+
22
+ /** number of bytes needed for buffer allocation */
23
+ readonly byteLength: number;
24
+
25
+
26
+ /** Create a new UniformBufferLayout given a map of attributes. */
27
+ constructor(uniformTypes: Record<string, ShaderUniformType>) {
28
+ /** number of 4 byte slots taken */
29
+ let size: number = 0;
30
+
31
+ // Add layout (type, size and offset) definitions for each uniform in the layout
32
+ for (const [key, uniformType] of Object.entries(uniformTypes)) {
33
+ const typeAndComponents = decodeShaderUniformType(uniformType);
34
+ const {type, components: count} = typeAndComponents;
35
+ // First, align (bump) current offset to an even multiple of current object (1, 2, 4)
36
+ size = alignTo(size, count);
37
+ // Use the aligned size as the offset of the current uniform.
38
+ const offset = size;
39
+ // Then, add our object's padded size ((1, 2, multiple of 4) to the current offset
40
+ size += count;
41
+ this.layout[key] = {type, size: count, offset};
42
+ }
43
+ size += (4 - (size % 4)) % 4;
44
+
45
+ const actualByteLength = size * 4;
46
+ this.byteLength = Math.max(actualByteLength, minBufferSize);
47
+ }
48
+
49
+ /** Get the data for the complete buffer */
50
+ getData(uniformValues: Record<string, UniformValue>): Uint8Array {
51
+ const bufferSize = Math.max(this.byteLength, minBufferSize);
52
+
53
+ // Allocate three typed arrays pointing at same memory
54
+ const arrayBuffer = getScratchArrayBuffer(bufferSize);
55
+ const typedArrays = {
56
+ i32: new Int32Array(arrayBuffer),
57
+ u32: new Uint32Array(arrayBuffer),
58
+ f32: new Float32Array(arrayBuffer),
59
+ // TODO not implemented
60
+ f16: new Uint16Array(arrayBuffer)
61
+ };
62
+ // TODO is this needed?
63
+ // typedArrays.i32.fill(0);
64
+
65
+ for (const [name, value] of Object.entries(uniformValues)) {
66
+ const uniformLayout = this.layout[name];
67
+ if (!uniformLayout) {
68
+ log.warn(`Supplied uniform value ${name} not present in uniform block layout`)();
69
+ // eslint-disable-next-line no-continue
70
+ continue;
71
+ }
72
+
73
+ const {type, size, offset} = uniformLayout;
74
+ const typedArray = typedArrays[type];
75
+ if (size === 1) {
76
+ if (typeof value !== 'number' && typeof value !== 'boolean') {
77
+ log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)();
78
+ // eslint-disable-next-line no-continue
79
+ continue;
80
+ }
81
+ // single value -> just set it
82
+ typedArray[offset] = Number(value);
83
+ } else {
84
+ const numericArray = isNumberArray(value);
85
+ if (!numericArray) {
86
+ log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)();
87
+ // eslint-disable-next-line no-continue
88
+ continue;
89
+ }
90
+ // vector/matrix -> copy the supplied (typed) array, starting from offset
91
+ // TODO: we should limit or check size in case the supplied data overflows
92
+ typedArray.set(numericArray, offset);
93
+ }
94
+ }
95
+
96
+ return new Uint8Array(arrayBuffer);
97
+ }
98
+
99
+ /** Does this layout have a field with specified name */
100
+ has(name: string) {
101
+ return Boolean(this.layout[name]);
102
+ }
103
+
104
+ /** Get offset and size for a field with specified name */
105
+ get(name: string): {offset: number, size: number} | undefined {
106
+ const layout = this.layout[name];
107
+ return layout;
108
+ }
109
+ }
@@ -0,0 +1,173 @@
1
+ // luma.gl, MIT license
2
+ import type {ShaderUniformType} from '../../adapter/types/shader-types';
3
+ import type {UniformValue} from '../../adapter/types/types';
4
+ import type {Device} from '../../adapter/device';
5
+ import {Buffer} from '../../adapter/resources/buffer';
6
+ import {UniformBlock} from './uniform-block';
7
+ import {UniformBufferLayout} from './uniform-buffer-layout';
8
+ import {log} from '../../utils/log';
9
+
10
+ export type ShaderModuleInputs = {
11
+ uniformTypes?: Record<string, ShaderUniformType>;
12
+ defaultProps?: Record<string, unknown>;
13
+ defaultUniforms?: Record<string, UniformValue>;
14
+ };
15
+
16
+ /**
17
+ * A uniform store holds a uniform values for one or more uniform blocks,
18
+ * - It can generate binary data for any uniform buffer
19
+ * - It can manage a uniform buffer for each block
20
+ * - It can update managed uniform buffers with a single call
21
+ * - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
22
+ */
23
+ export class UniformStore<
24
+ TPropGroups extends Record<string, Record<string, unknown>> = Record<
25
+ string,
26
+ Record<string, unknown>
27
+ >
28
+ > {
29
+ /** Stores the uniform values for each uniform block */
30
+ uniformBlocks = new Map<keyof TPropGroups, UniformBlock>();
31
+ /** Can generate data for a uniform buffer for each block from data */
32
+ uniformBufferLayouts = new Map<keyof TPropGroups, UniformBufferLayout>();
33
+ /** Actual buffer for the blocks */
34
+ uniformBuffers = new Map<keyof TPropGroups, Buffer>();
35
+
36
+ /**
37
+ * Create a new UniformStore instance
38
+ * @param blocks
39
+ */
40
+ constructor(
41
+ blocks: Record<
42
+ keyof TPropGroups,
43
+ {
44
+ uniformTypes?: Record<string, ShaderUniformType>;
45
+ defaultProps?: Record<string, unknown>;
46
+ defaultUniforms?: Record<string, UniformValue>;
47
+ }
48
+ >
49
+ ) {
50
+ for (const [bufferName, block] of Object.entries(blocks)) {
51
+ const uniformBufferName = bufferName as keyof TPropGroups;
52
+
53
+ // Create a layout object to help us generate correctly formatted binary uniform buffers
54
+ const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});
55
+ this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
56
+
57
+ // Create a Uniform block to store the uniforms for each buffer.
58
+ const uniformBlock = new UniformBlock({name: bufferName});
59
+ uniformBlock.setUniforms(block.defaultUniforms || {});
60
+ this.uniformBlocks.set(uniformBufferName, uniformBlock);
61
+ }
62
+ }
63
+
64
+ /** Destroy any managed uniform buffers */
65
+ destroy(): void {
66
+ for (const uniformBuffer of Object.values(this.uniformBuffers)) {
67
+ uniformBuffer.destroy();
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Set uniforms
73
+ * Makes all properties partial
74
+ */
75
+ setUniforms(
76
+ uniforms: Partial<{[group in keyof TPropGroups]: Partial<TPropGroups[group]>}>
77
+ ): void {
78
+ for (const [blockName, uniformValues] of Object.entries(uniforms)) {
79
+ this.uniformBlocks.get(blockName).setUniforms(uniformValues);
80
+ // We leverage logging in updateUniformBuffers(), even though slightly less efficient
81
+ // this.updateUniformBuffer(blockName);
82
+ }
83
+
84
+ this.updateUniformBuffers();
85
+ }
86
+
87
+ /** Get the required minimum length of the uniform buffer */
88
+ getUniformBufferByteLength(uniformBufferName: keyof TPropGroups): number {
89
+ return this.uniformBufferLayouts.get(uniformBufferName).byteLength;
90
+ }
91
+
92
+ /** Get formatted binary memory that can be uploaded to a buffer */
93
+ getUniformBufferData(uniformBufferName: keyof TPropGroups): Uint8Array {
94
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
95
+ return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);
96
+ }
97
+
98
+ /**
99
+ * Creates an unmanaged uniform buffer (umnanaged means that application is responsible for destroying it)
100
+ * The new buffer is initialized with current / supplied values
101
+ */
102
+ createUniformBuffer(
103
+ device: Device,
104
+ uniformBufferName: keyof TPropGroups,
105
+ uniforms?: Partial<{[group in keyof TPropGroups]: Partial<TPropGroups[group]>}>
106
+ ): Buffer {
107
+ if (uniforms) {
108
+ this.setUniforms(uniforms);
109
+ }
110
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
111
+ const uniformBuffer = device.createBuffer({
112
+ usage: Buffer.UNIFORM | Buffer.COPY_DST,
113
+ byteLength
114
+ });
115
+ // Note that this clears the needs redraw flag
116
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
117
+ uniformBuffer.write(uniformBufferData);
118
+ return uniformBuffer;
119
+ }
120
+
121
+ /** Get the managed uniform buffer. "managed" resources are destroyed when the uniformStore is destroyed. */
122
+ getManagedUniformBuffer(device: Device, uniformBufferName: keyof TPropGroups): Buffer {
123
+ if (!this.uniformBuffers.get(uniformBufferName)) {
124
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
125
+ const uniformBuffer = device.createBuffer({
126
+ usage: Buffer.UNIFORM | Buffer.COPY_DST,
127
+ byteLength
128
+ });
129
+ this.uniformBuffers.set(uniformBufferName, uniformBuffer);
130
+ }
131
+ // this.updateUniformBuffers();
132
+ return this.uniformBuffers.get(uniformBufferName);
133
+ }
134
+
135
+ /** Updates all uniform buffers where values have changed */
136
+ updateUniformBuffers(): false | string {
137
+ let reason: false | string = false;
138
+ for (const uniformBufferName of this.uniformBlocks.keys()) {
139
+ const bufferReason = this.updateUniformBuffer(uniformBufferName);
140
+ reason ||= bufferReason;
141
+ }
142
+ if (reason) {
143
+ log.log(3, `UniformStore.updateUniformBuffers(): ${reason}`)();
144
+ }
145
+ return reason;
146
+ }
147
+
148
+ /** Update one uniform buffer. Only updates if values have changed */
149
+ updateUniformBuffer(uniformBufferName: keyof TPropGroups): false | string {
150
+ const uniformBlock = this.uniformBlocks.get(uniformBufferName);
151
+ const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
152
+
153
+ let reason: false | string = false;
154
+ if (uniformBuffer && uniformBlock.needsRedraw) {
155
+ reason ||= uniformBlock.needsRedraw;
156
+ // This clears the needs redraw flag
157
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
158
+
159
+ const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
160
+ uniformBuffer.write(uniformBufferData);
161
+
162
+ // logging - TODO - don't query the values unnecessarily
163
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
164
+ log.log(
165
+ 4,
166
+ `Writing to uniform buffer ${String(uniformBufferName)}`,
167
+ uniformBufferData,
168
+ uniformValues
169
+ )();
170
+ }
171
+ return reason;
172
+ }
173
+ }
@@ -0,0 +1,25 @@
1
+ import type {UniformValue} from '../../adapter/types/types';
2
+ import type {Binding} from '../../adapter/types/shader-layout';
3
+ import {isNumberArray} from '../../utils/is-array';
4
+
5
+ export function isUniformValue(value: unknown): boolean {
6
+ return isNumberArray(value) !== null || (typeof value === 'number') || (typeof value === 'boolean');
7
+ }
8
+
9
+ type UniformsAndBindings = {
10
+ bindings: Record<string, Binding>,
11
+ uniforms: Record<string, UniformValue>
12
+ };
13
+ export function splitUniformsAndBindings(uniforms: Record<string, Binding | UniformValue>): UniformsAndBindings {
14
+ const result: UniformsAndBindings = { bindings: {}, uniforms: {} }
15
+ Object.keys(uniforms).forEach(name => {
16
+ const uniform = uniforms[name];
17
+ if(isUniformValue(uniform)) {
18
+ result.uniforms[name] = uniform as UniformValue;
19
+ } else {
20
+ result.bindings[name] = uniform as Binding;
21
+ }
22
+ });
23
+
24
+ return result;
25
+ }
package/src/types.ts ADDED
@@ -0,0 +1,33 @@
1
+ /** TypeScript type covering all typed arrays */
2
+ import {TypedArray, NumberArray} from '@math.gl/types';
3
+
4
+ export {TypedArray, NumberArray};
5
+
6
+ /** TypeScript type covering constructors of any of the typed arrays */
7
+ export type TypedArrayConstructor =
8
+ | Int8ArrayConstructor
9
+ | Uint8ArrayConstructor
10
+ | Int16ArrayConstructor
11
+ | Uint16ArrayConstructor
12
+ | Int32ArrayConstructor
13
+ | Uint32ArrayConstructor
14
+ | Uint8ClampedArrayConstructor
15
+ | Float32ArrayConstructor
16
+ | Float64ArrayConstructor;
17
+
18
+ /** Keep big int arrays separate as they are still problematic, can't be indexed and don't work well on Safari */
19
+ export type BigIntTypedArray = BigInt64Array | BigUint64Array;
20
+
21
+ export type BigIntOrNumberArray = NumberArray | BigIntTypedArray;
22
+
23
+ /** Get the constructor type of a type */
24
+ export interface ConstructorOf<T> {
25
+ new (...args: unknown[]): T;
26
+ }
27
+
28
+ /**
29
+ * Make specific fields in a type optional. Granular version of `Partial<T>`
30
+ * @example
31
+ * type PartialProps = PartialBy<Required<DeviceProps>, 'device' | 'canvas'>
32
+ */
33
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;