@luma.gl/core 9.0.17 → 9.1.0-alpha.10

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 (248) hide show
  1. package/dist/adapter/adapter.d.ts +11 -0
  2. package/dist/adapter/adapter.d.ts.map +1 -0
  3. package/dist/adapter/adapter.js +8 -0
  4. package/dist/adapter/canvas-context.d.ts +5 -0
  5. package/dist/adapter/canvas-context.d.ts.map +1 -1
  6. package/dist/adapter/device.d.ts +23 -11
  7. package/dist/adapter/device.d.ts.map +1 -1
  8. package/dist/adapter/device.js +22 -20
  9. package/dist/adapter/luma.d.ts +70 -0
  10. package/dist/adapter/luma.d.ts.map +1 -0
  11. package/dist/adapter/luma.js +159 -0
  12. package/dist/adapter/resources/buffer.js +5 -5
  13. package/dist/adapter/resources/compute-pipeline.d.ts +2 -0
  14. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
  15. package/dist/adapter/resources/compute-pipeline.js +3 -0
  16. package/dist/adapter/resources/external-texture.d.ts +1 -1
  17. package/dist/adapter/resources/external-texture.d.ts.map +1 -1
  18. package/dist/adapter/resources/external-texture.js +1 -1
  19. package/dist/adapter/resources/framebuffer.d.ts +3 -3
  20. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  21. package/dist/adapter/resources/framebuffer.js +2 -83
  22. package/dist/adapter/resources/render-pass.d.ts +2 -2
  23. package/dist/adapter/resources/render-pass.d.ts.map +1 -1
  24. package/dist/adapter/resources/render-pipeline.d.ts +2 -5
  25. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  26. package/dist/adapter/resources/resource.d.ts +3 -3
  27. package/dist/adapter/resources/resource.d.ts.map +1 -1
  28. package/dist/adapter/resources/resource.js +1 -1
  29. package/dist/adapter/resources/shader.d.ts +5 -2
  30. package/dist/adapter/resources/shader.d.ts.map +1 -1
  31. package/dist/adapter/resources/shader.js +15 -9
  32. package/dist/adapter/resources/texture-view.d.ts +1 -1
  33. package/dist/adapter/resources/texture-view.d.ts.map +1 -1
  34. package/dist/adapter/resources/texture.d.ts +144 -47
  35. package/dist/adapter/resources/texture.d.ts.map +1 -1
  36. package/dist/adapter/resources/texture.js +120 -12
  37. package/dist/adapter/resources/transform-feedback.d.ts +1 -1
  38. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
  39. package/dist/adapter/resources/vertex-array.d.ts +1 -1
  40. package/dist/adapter/resources/vertex-array.d.ts.map +1 -1
  41. package/dist/adapter/resources/vertex-array.js +6 -2
  42. package/dist/adapter/types/{types.d.ts → attachments.d.ts} +7 -17
  43. package/dist/adapter/types/attachments.d.ts.map +1 -0
  44. package/dist/adapter/types/buffer-layout.d.ts +1 -1
  45. package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
  46. package/dist/adapter/types/compiler-message.d.ts.map +1 -0
  47. package/dist/adapter/types/parameters.d.ts +4 -6
  48. package/dist/adapter/types/parameters.d.ts.map +1 -1
  49. package/dist/adapter/types/parameters.js +1 -0
  50. package/dist/adapter/types/shader-layout.d.ts +23 -3
  51. package/dist/adapter/types/shader-layout.d.ts.map +1 -1
  52. package/dist/adapter/types/uniforms.d.ts +4 -0
  53. package/dist/adapter/types/uniforms.d.ts.map +1 -0
  54. package/dist/{lib/compiler-log → adapter-utils}/format-compiler-log.d.ts +1 -1
  55. package/dist/adapter-utils/format-compiler-log.d.ts.map +1 -0
  56. package/dist/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.d.ts +4 -11
  57. package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -0
  58. package/dist/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.js +10 -30
  59. package/dist/adapter-utils/is-uniform-value.d.ts +3 -0
  60. package/dist/adapter-utils/is-uniform-value.d.ts.map +1 -0
  61. package/dist/adapter-utils/is-uniform-value.js +7 -0
  62. package/dist/dist.dev.js +635 -821
  63. package/dist/dist.min.js +6 -6
  64. package/dist/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.d.ts +3 -3
  65. package/dist/gpu-type-utils/decode-attribute-type.d.ts.map +1 -0
  66. package/dist/{adapter/type-utils → gpu-type-utils}/decode-data-type.d.ts +1 -1
  67. package/dist/gpu-type-utils/decode-data-type.d.ts.map +1 -0
  68. package/dist/{adapter/type-utils → gpu-type-utils}/decode-shader-types.d.ts +1 -1
  69. package/dist/gpu-type-utils/decode-shader-types.d.ts.map +1 -0
  70. package/dist/{adapter/type-utils → gpu-type-utils}/decode-shader-types.js +0 -2
  71. package/dist/gpu-type-utils/decode-texture-format.d.ts +43 -0
  72. package/dist/gpu-type-utils/decode-texture-format.d.ts.map +1 -0
  73. package/dist/{adapter/type-utils → gpu-type-utils}/decode-texture-format.js +67 -31
  74. package/dist/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.d.ts +1 -1
  75. package/dist/gpu-type-utils/decode-vertex-format.d.ts.map +1 -0
  76. package/dist/gpu-type-utils/shader-types.d.ts.map +1 -0
  77. package/dist/{adapter/types → gpu-type-utils}/texture-formats.d.ts +3 -5
  78. package/dist/gpu-type-utils/texture-formats.d.ts.map +1 -0
  79. package/dist/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.d.ts +2 -2
  80. package/dist/gpu-type-utils/vertex-format-from-attribute.d.ts.map +1 -0
  81. package/dist/gpu-type-utils/vertex-formats.d.ts.map +1 -0
  82. package/dist/{adapter/type-utils → gpu-type-utils}/wgsl-utils.d.ts +1 -1
  83. package/dist/gpu-type-utils/wgsl-utils.d.ts.map +1 -0
  84. package/dist/index.cjs +396 -567
  85. package/dist/index.cjs.map +4 -4
  86. package/dist/index.d.ts +28 -44
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +19 -37
  89. package/dist/{lib/uniforms → portable}/uniform-block.d.ts +3 -3
  90. package/dist/portable/uniform-block.d.ts.map +1 -0
  91. package/dist/{lib/uniforms → portable}/uniform-block.js +2 -2
  92. package/dist/{lib/uniforms → portable}/uniform-buffer-layout.d.ts +2 -2
  93. package/dist/portable/uniform-buffer-layout.d.ts.map +1 -0
  94. package/dist/{lib/uniforms → portable}/uniform-buffer-layout.js +6 -7
  95. package/dist/{lib/uniforms → portable}/uniform-store.d.ts +9 -4
  96. package/dist/portable/uniform-store.d.ts.map +1 -0
  97. package/dist/{lib/uniforms → portable}/uniform-store.js +11 -9
  98. package/dist/types.d.ts +0 -10
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/utils/array-equal.d.ts.map +1 -1
  101. package/dist/utils/array-equal.js +6 -7
  102. package/dist/utils/array-utils-flat.d.ts +1 -7
  103. package/dist/utils/array-utils-flat.d.ts.map +1 -1
  104. package/dist/utils/array-utils-flat.js +0 -23
  105. package/dist/utils/is-array.d.ts +3 -3
  106. package/dist/utils/is-array.d.ts.map +1 -1
  107. package/dist/utils/is-array.js +2 -2
  108. package/dist/utils/uid.d.ts +7 -0
  109. package/dist/utils/uid.d.ts.map +1 -0
  110. package/dist/utils/{utils.js → uid.js} +0 -11
  111. package/package.json +5 -5
  112. package/src/adapter/adapter.ts +16 -0
  113. package/src/adapter/canvas-context.ts +6 -0
  114. package/src/adapter/device.ts +52 -36
  115. package/src/adapter/luma.ts +219 -0
  116. package/src/adapter/resources/buffer.ts +5 -5
  117. package/src/adapter/resources/command-encoder.ts +1 -1
  118. package/src/adapter/resources/compute-pass.ts +3 -3
  119. package/src/adapter/resources/compute-pipeline.ts +6 -3
  120. package/src/adapter/resources/external-texture.ts +2 -2
  121. package/src/adapter/resources/framebuffer.ts +5 -92
  122. package/src/adapter/resources/query-set.ts +2 -2
  123. package/src/adapter/resources/render-pass.ts +11 -7
  124. package/src/adapter/resources/render-pipeline.ts +3 -6
  125. package/src/adapter/resources/resource.ts +7 -7
  126. package/src/adapter/resources/shader.ts +18 -11
  127. package/src/adapter/resources/texture-view.ts +5 -5
  128. package/src/adapter/resources/texture.ts +285 -76
  129. package/src/adapter/resources/transform-feedback.ts +1 -1
  130. package/src/adapter/resources/vertex-array.ts +7 -3
  131. package/src/adapter/types/{types.ts → attachments.ts} +10 -18
  132. package/src/adapter/types/buffer-layout.ts +1 -1
  133. package/src/adapter/types/parameters.ts +14 -14
  134. package/src/adapter/types/shader-layout.ts +31 -29
  135. package/src/adapter/types/uniforms.ts +10 -0
  136. package/src/{lib/compiler-log → adapter-utils}/format-compiler-log.ts +1 -1
  137. package/src/{adapter/attribute-utils → adapter-utils}/get-attribute-from-layouts.ts +18 -42
  138. package/src/adapter-utils/is-uniform-value.ts +10 -0
  139. package/src/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.ts +3 -3
  140. package/src/{adapter/type-utils → gpu-type-utils}/decode-data-type.ts +1 -1
  141. package/src/{adapter/type-utils → gpu-type-utils}/decode-shader-types.ts +1 -3
  142. package/src/{adapter/type-utils → gpu-type-utils}/decode-texture-format.ts +99 -39
  143. package/src/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.ts +1 -1
  144. package/src/{adapter/types → gpu-type-utils}/texture-formats.ts +3 -14
  145. package/src/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.ts +2 -2
  146. package/src/{adapter/type-utils → gpu-type-utils}/wgsl-utils.ts +1 -1
  147. package/src/index.ts +67 -83
  148. package/src/{lib/uniforms → portable}/uniform-block.ts +5 -5
  149. package/src/{lib/uniforms → portable}/uniform-buffer-layout.ts +9 -9
  150. package/src/{lib/uniforms → portable}/uniform-store.ts +20 -12
  151. package/src/types.ts +0 -12
  152. package/src/utils/array-equal.ts +6 -7
  153. package/src/utils/array-utils-flat.ts +1 -31
  154. package/src/utils/is-array.ts +5 -5
  155. package/src/utils/{utils.ts → uid.ts} +0 -12
  156. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +0 -1
  157. package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +0 -1
  158. package/dist/adapter/type-utils/decode-data-type.d.ts.map +0 -1
  159. package/dist/adapter/type-utils/decode-shader-types.d.ts.map +0 -1
  160. package/dist/adapter/type-utils/decode-texture-format.d.ts +0 -23
  161. package/dist/adapter/type-utils/decode-texture-format.d.ts.map +0 -1
  162. package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +0 -1
  163. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +0 -1
  164. package/dist/adapter/type-utils/wgsl-utils.d.ts.map +0 -1
  165. package/dist/adapter/types/accessor.d.ts +0 -23
  166. package/dist/adapter/types/accessor.d.ts.map +0 -1
  167. package/dist/adapter/types/shader-types.d.ts.map +0 -1
  168. package/dist/adapter/types/texture-formats.d.ts.map +0 -1
  169. package/dist/adapter/types/types.d.ts.map +0 -1
  170. package/dist/adapter/types/vertex-formats.d.ts.map +0 -1
  171. package/dist/init.d.ts +0 -5
  172. package/dist/init.d.ts.map +0 -1
  173. package/dist/init.js +0 -37
  174. package/dist/lib/compiler-log/compiler-message.d.ts.map +0 -1
  175. package/dist/lib/compiler-log/format-compiler-log.d.ts.map +0 -1
  176. package/dist/lib/compiler-log/get-shader-info.d.ts +0 -9
  177. package/dist/lib/compiler-log/get-shader-info.d.ts.map +0 -1
  178. package/dist/lib/compiler-log/get-shader-info.js +0 -29
  179. package/dist/lib/luma.d.ts +0 -38
  180. package/dist/lib/luma.d.ts.map +0 -1
  181. package/dist/lib/luma.js +0 -141
  182. package/dist/lib/uniforms/uniform-block.d.ts.map +0 -1
  183. package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +0 -1
  184. package/dist/lib/uniforms/uniform-store.d.ts.map +0 -1
  185. package/dist/lib/uniforms/uniform.d.ts +0 -10
  186. package/dist/lib/uniforms/uniform.d.ts.map +0 -1
  187. package/dist/lib/uniforms/uniform.js +0 -20
  188. package/dist/utils/assert.d.ts +0 -2
  189. package/dist/utils/assert.d.ts.map +0 -1
  190. package/dist/utils/assert.js +0 -10
  191. package/dist/utils/cast.d.ts +0 -3
  192. package/dist/utils/cast.d.ts.map +0 -1
  193. package/dist/utils/cast.js +0 -7
  194. package/dist/utils/check-props.d.ts +0 -7
  195. package/dist/utils/check-props.d.ts.map +0 -1
  196. package/dist/utils/check-props.js +0 -36
  197. package/dist/utils/deep-equal.d.ts +0 -9
  198. package/dist/utils/deep-equal.d.ts.map +0 -1
  199. package/dist/utils/deep-equal.js +0 -50
  200. package/dist/utils/format-value.d.ts +0 -7
  201. package/dist/utils/format-value.d.ts.map +0 -1
  202. package/dist/utils/format-value.js +0 -39
  203. package/dist/utils/load-file.d.ts +0 -35
  204. package/dist/utils/load-file.d.ts.map +0 -1
  205. package/dist/utils/load-file.js +0 -74
  206. package/dist/utils/random.d.ts +0 -5
  207. package/dist/utils/random.d.ts.map +0 -1
  208. package/dist/utils/random.js +0 -18
  209. package/dist/utils/request-animation-frame.d.ts +0 -3
  210. package/dist/utils/request-animation-frame.d.ts.map +0 -1
  211. package/dist/utils/request-animation-frame.js +0 -16
  212. package/dist/utils/stub-methods.d.ts +0 -2
  213. package/dist/utils/stub-methods.d.ts.map +0 -1
  214. package/dist/utils/stub-methods.js +0 -19
  215. package/dist/utils/utils.d.ts +0 -9
  216. package/dist/utils/utils.d.ts.map +0 -1
  217. package/src/adapter/types/accessor.ts +0 -37
  218. package/src/init.ts +0 -53
  219. package/src/lib/compiler-log/get-shader-info.ts +0 -42
  220. package/src/lib/luma.ts +0 -190
  221. package/src/lib/uniforms/uniform.ts +0 -31
  222. package/src/utils/assert.ts +0 -11
  223. package/src/utils/cast.ts +0 -8
  224. package/src/utils/check-props.ts +0 -82
  225. package/src/utils/deep-equal.ts +0 -51
  226. package/src/utils/format-value.ts +0 -47
  227. package/src/utils/load-file.ts +0 -91
  228. package/src/utils/random.ts +0 -21
  229. package/src/utils/request-animation-frame.ts +0 -19
  230. package/src/utils/stub-methods.ts +0 -29
  231. /package/dist/adapter/types/{accessor.js → attachments.js} +0 -0
  232. /package/dist/{lib/compiler-log → adapter/types}/compiler-message.d.ts +0 -0
  233. /package/dist/{lib/compiler-log → adapter/types}/compiler-message.js +0 -0
  234. /package/dist/adapter/types/{shader-types.js → uniforms.js} +0 -0
  235. /package/dist/{lib/compiler-log → adapter-utils}/format-compiler-log.js +0 -0
  236. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-attribute-type.js +0 -0
  237. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-data-type.js +0 -0
  238. /package/dist/{adapter/type-utils → gpu-type-utils}/decode-vertex-format.js +0 -0
  239. /package/dist/{adapter/types → gpu-type-utils}/shader-types.d.ts +0 -0
  240. /package/dist/{adapter/types/texture-formats.js → gpu-type-utils/shader-types.js} +0 -0
  241. /package/dist/{adapter/types/types.js → gpu-type-utils/texture-formats.js} +0 -0
  242. /package/dist/{adapter/type-utils → gpu-type-utils}/vertex-format-from-attribute.js +0 -0
  243. /package/dist/{adapter/types → gpu-type-utils}/vertex-formats.d.ts +0 -0
  244. /package/dist/{adapter/types → gpu-type-utils}/vertex-formats.js +0 -0
  245. /package/dist/{adapter/type-utils → gpu-type-utils}/wgsl-utils.js +0 -0
  246. /package/src/{lib/compiler-log → adapter/types}/compiler-message.ts +0 -0
  247. /package/src/{adapter/types → gpu-type-utils}/shader-types.ts +0 -0
  248. /package/src/{adapter/types → gpu-type-utils}/vertex-formats.ts +0 -0
@@ -2,11 +2,10 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {VERSION} from '../init';
6
5
  import {StatsManager, lumaStats} from '../utils/stats-manager';
7
6
  import {log} from '../utils/log';
8
- import {uid} from '../utils/utils';
9
- import type {TextureFormat} from './types/texture-formats';
7
+ import {uid} from '../utils/uid';
8
+ import type {TextureFormat} from '../gpu-type-utils//texture-formats';
10
9
  import type {CanvasContext, CanvasContextProps} from './canvas-context';
11
10
  import type {BufferProps} from './resources/buffer';
12
11
  import {Buffer} from './resources/buffer';
@@ -14,7 +13,7 @@ import type {RenderPipeline, RenderPipelineProps} from './resources/render-pipel
14
13
  import type {ComputePipeline, ComputePipelineProps} from './resources/compute-pipeline';
15
14
  import type {Sampler, SamplerProps} from './resources/sampler';
16
15
  import type {Shader, ShaderProps} from './resources/shader';
17
- import type {Texture, TextureProps, TextureData} from './resources/texture';
16
+ import type {Texture, TextureProps} from './resources/texture';
18
17
  import type {ExternalTexture, ExternalTextureProps} from './resources/external-texture';
19
18
  import type {Framebuffer, FramebufferProps} from './resources/framebuffer';
20
19
  import type {RenderPass, RenderPassProps} from './resources/render-pass';
@@ -24,7 +23,7 @@ import type {VertexArray, VertexArrayProps} from './resources/vertex-array';
24
23
  import type {TransformFeedback, TransformFeedbackProps} from './resources/transform-feedback';
25
24
  import type {QuerySet, QuerySetProps} from './resources/query-set';
26
25
 
27
- import {isTextureFormatCompressed} from './type-utils/decode-texture-format';
26
+ import {isTextureFormatCompressed} from '../gpu-type-utils/decode-texture-format';
28
27
 
29
28
  /**
30
29
  * Identifies the GPU vendor and driver.
@@ -131,7 +130,7 @@ export class DeviceFeatures {
131
130
  }
132
131
 
133
132
  has(feature: DeviceFeature): boolean {
134
- return !this.disabledFeatures[feature] && this.features.has(feature);
133
+ return !this.disabledFeatures?.[feature] && this.features.has(feature);
135
134
  }
136
135
  }
137
136
 
@@ -146,7 +145,6 @@ export type WebGPUDeviceFeature =
146
145
  | 'indirect-first-instance'
147
146
  | 'timestamp-query'
148
147
  | 'shader-f16'
149
- | 'depth24unorm-stencil8'
150
148
  | 'depth32float-stencil8'
151
149
  | 'rg11b10ufloat-renderable' // Is the rg11b10ufloat texture format renderable?
152
150
  | 'float32-filterable' // Is the float32 format filterable?
@@ -219,26 +217,42 @@ export type DeviceProps = {
219
217
  /** Error handling */
220
218
  onError?: (error: Error) => unknown;
221
219
 
222
- // DEBUG SETTINGS
220
+ // @deprecated Attach to existing context. Rename to handle? Use Device.attach?
221
+ gl?: WebGL2RenderingContext | null;
223
222
 
223
+ // DEBUG SETTINGS
224
224
  /** WebGL: Instrument WebGL2RenderingContext (at the expense of performance) */
225
225
  debug?: boolean;
226
226
  /** Break on WebGL functions matching these strings */
227
227
  break?: string[];
228
+
228
229
  /** WebGL: Initialize the SpectorJS WebGL debugger */
229
- spector?: boolean;
230
+ debugWithSpectorJS?: boolean;
231
+ /** SpectorJS URL. Override if CDN is down or different SpectorJS version is desired */
232
+ spectorUrl?: string;
233
+
234
+ // EXPERIMENTAL SETTINGS
235
+ /** Set to false to disable WebGL state management instrumentation: TODO- Unclear if still supported / useful */
236
+ manageState?: boolean;
230
237
  /** Initialize all features on startup */
231
238
  initalizeFeatures?: boolean;
232
239
  /** Disable specific features */
233
240
  disabledFeatures?: Partial<Record<DeviceFeature, boolean>>;
234
-
235
- /** TODO- Unclear if still supported: Set to false to disable WebGL state management instrumentation */
236
- manageState?: boolean;
237
-
238
- // @deprecated Attach to existing context. Rename to handle? Use Device.attach?
239
- gl?: WebGL2RenderingContext | null;
241
+ /** Never destroy cached shaders and pipelines */
242
+ _factoryDestroyPolicy?: 'unused' | 'never';
240
243
  };
241
244
 
245
+ /**
246
+ * Create and attach devices for a specific backend. Currently static methods on each device
247
+ */
248
+ export interface DeviceFactory {
249
+ // new (props: DeviceProps): Device; Constructor isn't used
250
+ type: string;
251
+ isSupported(): boolean;
252
+ create(props: DeviceProps): Promise<Device>;
253
+ attach?(handle: unknown): Device;
254
+ }
255
+
242
256
  /**
243
257
  * WebGPU Device/WebGL context abstraction
244
258
  */
@@ -250,17 +264,12 @@ export abstract class Device {
250
264
  manageState: true,
251
265
  width: 800, // width are height are only used by headless gl
252
266
  height: 600,
253
-
254
267
  requestMaxLimits: true,
255
- debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)
256
- spector: Boolean(log.get('spector') || log.get('spectorjs')), // Initialize the SpectorJS WebGL debugger
257
- break: [],
258
268
 
259
- // TODO - Change these after confirming things work as expected
260
- initalizeFeatures: true,
261
- disabledFeatures: {
262
- 'compilation-status-async-webgl': true
263
- },
269
+ // Callbacks
270
+ onError: (error: Error) => log.error(error.message),
271
+
272
+ gl: null,
264
273
 
265
274
  // alpha: undefined,
266
275
  // depth: undefined,
@@ -270,18 +279,25 @@ export abstract class Device {
270
279
  // preserveDrawingBuffer: undefined,
271
280
  // failIfMajorPerformanceCaveat: undefined
272
281
 
273
- gl: null,
282
+ debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)
283
+ break: (log.get('break') as string[]) || [],
274
284
 
275
- // Callbacks
276
- onError: (error: Error) => log.error(error.message)
285
+ // WebGL specific debugging
286
+ debugWithSpectorJS: undefined!,
287
+ spectorUrl: undefined!,
288
+
289
+ // TODO - Change these after confirming things work as expected
290
+ initalizeFeatures: true,
291
+ disabledFeatures: {
292
+ 'compilation-status-async-webgl': true
293
+ },
294
+ _factoryDestroyPolicy: 'unused'
277
295
  };
278
296
 
279
297
  get [Symbol.toStringTag](): string {
280
298
  return 'Device';
281
299
  }
282
300
 
283
- static VERSION = VERSION;
284
-
285
301
  constructor(props: DeviceProps) {
286
302
  this.props = {...Device.defaultProps, ...props};
287
303
  this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
@@ -343,6 +359,11 @@ export abstract class Device {
343
359
  return false;
344
360
  }
345
361
 
362
+ /** Report error (normally for unhandled device errors) */
363
+ error(error: Error): void {
364
+ this.props.onError(error);
365
+ }
366
+
346
367
  // Canvas context
347
368
 
348
369
  /** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
@@ -370,14 +391,9 @@ export abstract class Device {
370
391
  /** Create a texture */
371
392
  abstract _createTexture(props: TextureProps): Texture;
372
393
  createTexture(props: TextureProps): Texture;
373
- createTexture(data: Promise<TextureData>): Texture;
374
- createTexture(url: string): Texture;
394
+ // createTexture(data: Promise<TextureData>): Texture;
375
395
 
376
- createTexture(props: TextureProps | Promise<TextureData> | string): Texture {
377
- // Signature: new Texture2D(gl, url | Promise)
378
- if (props instanceof Promise || typeof props === 'string') {
379
- props = {data: props};
380
- }
396
+ createTexture(props: TextureProps): Texture {
381
397
  return this._createTexture(props);
382
398
  }
383
399
 
@@ -0,0 +1,219 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Log} from '@probe.gl/log';
6
+ import type {DeviceProps} from './device';
7
+ import {Device} from './device';
8
+ import {Adapter} from './adapter';
9
+ import {StatsManager} from '../utils/stats-manager';
10
+ import {lumaStats} from '../utils/stats-manager';
11
+ import {log} from '../utils/log';
12
+
13
+ declare global {
14
+ // eslint-disable-next-line no-var
15
+ var luma: Luma;
16
+ }
17
+
18
+ const STARTUP_MESSAGE = 'set luma.log.level=1 (or higher) to trace rendering';
19
+
20
+ const ERROR_MESSAGE =
21
+ 'No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.';
22
+
23
+ /** Properties for creating a new device */
24
+ export type CreateDeviceProps = DeviceProps & {
25
+ /** Selects the type of device. `best-available` uses webgpu if available, then webgl. */
26
+ type?: 'webgl' | 'webgpu' | 'unknown' | 'best-available';
27
+ adapters?: Adapter[];
28
+ };
29
+
30
+ /** Properties for attaching an existing WebGL context or WebGPU device to a new luma Device */
31
+ export type AttachDeviceProps = DeviceProps & {
32
+ /** Externally created WebGL context or WebGPU device */
33
+ handle: unknown; // WebGL2RenderingContext | GPUDevice | null;
34
+ /** List of adapters. Will also search any pre-registered adapterss */
35
+ adapters?: Adapter[];
36
+ };
37
+
38
+ /**
39
+ * Entry point to the luma.gl GPU abstraction
40
+ * Register WebGPU and/or WebGL adapters (controls application bundle size)
41
+ * Run-time selection of the first available Device
42
+ */
43
+ export class Luma {
44
+ static defaultProps: Required<CreateDeviceProps> = {
45
+ ...Device.defaultProps,
46
+ type: 'best-available',
47
+ adapters: undefined!
48
+ };
49
+
50
+ /** Global stats for all devices */
51
+ readonly stats: StatsManager = lumaStats;
52
+
53
+ /**
54
+ * Global log
55
+ *
56
+ * Assign luma.log.level in console to control logging: \
57
+ * 0: none, 1: minimal, 2: verbose, 3: attribute/uniforms, 4: gl logs
58
+ * luma.log.break[], set to gl funcs, luma.log.profile[] set to model names`;
59
+ */
60
+ readonly log: Log = log;
61
+
62
+ /** Version of luma.gl */
63
+ readonly VERSION: string =
64
+ // Version detection using build plugin
65
+ // @ts-expect-error no-undef
66
+ typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'running from source';
67
+
68
+ spector: unknown;
69
+
70
+ protected preregisteredAdapters = new Map<string, Adapter>();
71
+
72
+ constructor() {
73
+ if (globalThis.luma) {
74
+ if (globalThis.luma.VERSION !== this.VERSION) {
75
+ log.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)();
76
+ log.error(`'yarn why @luma.gl/core' can help identify the source of the conflict`)();
77
+ throw new Error(`luma.gl - multiple versions detected: see console log`);
78
+ }
79
+
80
+ log.error('This version of luma.gl has already been initialized')();
81
+ }
82
+
83
+ log.log(1, `${this.VERSION} - ${STARTUP_MESSAGE}`)();
84
+
85
+ globalThis.luma = this;
86
+ }
87
+
88
+ registerAdapters(adapters: Adapter[]): void {
89
+ for (const deviceClass of adapters) {
90
+ this.preregisteredAdapters.set(deviceClass.type, deviceClass);
91
+ }
92
+ }
93
+
94
+ /** Get type strings for supported Devices */
95
+ getSupportedAdapters(adapters: Adapter[] = []): string[] {
96
+ const adapterMap = this.getAdapterMap(adapters);
97
+ return Array.from(adapterMap)
98
+ .map(([, adapter]) => adapter)
99
+ .filter(adapter => adapter.isSupported?.())
100
+ .map(adapter => adapter.type);
101
+ }
102
+
103
+ /** Get type strings for best available Device */
104
+ getBestAvailableAdapter(adapters: Adapter[] = []): 'webgpu' | 'webgl' | null {
105
+ const adapterMap = this.getAdapterMap(adapters);
106
+ if (adapterMap.get('webgpu')?.isSupported?.()) {
107
+ return 'webgpu';
108
+ }
109
+ if (adapterMap.get('webgl')?.isSupported?.()) {
110
+ return 'webgl';
111
+ }
112
+ return null;
113
+ }
114
+
115
+ setDefaultDeviceProps(props: CreateDeviceProps): void {
116
+ Object.assign(Luma.defaultProps, props);
117
+ }
118
+
119
+ /** Creates a device. Asynchronously. */
120
+ async createDevice(props: CreateDeviceProps = {}): Promise<Device> {
121
+ props = {...Luma.defaultProps, ...props};
122
+
123
+ // Should be handled by attach device
124
+ // if (props.gl) {
125
+ // props.type = 'webgl';
126
+ // }
127
+
128
+ const adapterMap = this.getAdapterMap(props.adapters);
129
+
130
+ let type: string = props.type || '';
131
+ if (type === 'best-available') {
132
+ type = this.getBestAvailableAdapter(props.adapters) || type;
133
+ }
134
+
135
+ const adapters = this.getAdapterMap(props.adapters) || adapterMap;
136
+
137
+ const adapter = adapters.get(type);
138
+ const device = await adapter?.create?.(props);
139
+ if (device) {
140
+ return device;
141
+ }
142
+
143
+ throw new Error(ERROR_MESSAGE);
144
+ }
145
+
146
+ /** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
147
+ async attachDevice(props: AttachDeviceProps): Promise<Device> {
148
+ const adapters = this.getAdapterMap(props.adapters);
149
+
150
+ // WebGL
151
+ let type = '';
152
+ if (props.handle instanceof WebGL2RenderingContext) {
153
+ type = 'webgl';
154
+ }
155
+
156
+ // TODO - WebGPU does not yet have a stable API
157
+ // if (props.handle instanceof GPUDevice) {
158
+ // const WebGPUDevice = adapters.get('webgpu') as any;
159
+ // if (WebGPUDevice) {
160
+ // return (await WebGPUDevice.attach(props.handle)) as Device;
161
+ // }
162
+ // }
163
+
164
+ // null
165
+ if (props.handle === null) {
166
+ type = 'unknown';
167
+ }
168
+
169
+ const adapter = adapters.get(type);
170
+ const device = await adapter?.attach?.(null);
171
+ if (device) {
172
+ return device;
173
+ }
174
+
175
+ throw new Error(ERROR_MESSAGE);
176
+ }
177
+
178
+ /**
179
+ * Override `HTMLCanvasContext.getCanvas()` to always create WebGL2 contexts with additional WebGL1 compatibility.
180
+ * Useful when attaching luma to a context from an external library does not support creating WebGL2 contexts.
181
+ */
182
+ enforceWebGL2(enforce: boolean = true, adapters: Adapter[] = []): void {
183
+ const adapterMap = this.getAdapterMap(adapters);
184
+ const webgl2Adapter = adapterMap.get('webgl');
185
+ if (!webgl2Adapter) {
186
+ log.warn('enforceWebGL2: webgl adapter not found')();
187
+ }
188
+ (webgl2Adapter as any)?.enforceWebGL2?.(enforce);
189
+ }
190
+
191
+ /** Convert a list of adapters to a map */
192
+ protected getAdapterMap(adapters: Adapter[] = []): Map<string, Adapter> {
193
+ const map = new Map(this.preregisteredAdapters);
194
+ for (const adapter of adapters) {
195
+ map.set(adapter.type, adapter);
196
+ }
197
+ return map;
198
+ }
199
+
200
+ // DEPRECATED
201
+
202
+ /** @deprecated Use registerAdapters */
203
+ registerDevices(deviceClasses: any[]): void {
204
+ log.warn('luma.registerDevices() is deprecated, use luma.registerAdapters() instead');
205
+ for (const deviceClass of deviceClasses) {
206
+ const adapter = deviceClass.adapter as Adapter;
207
+ if (adapter) {
208
+ this.preregisteredAdapters.set(adapter.type, adapter);
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Entry point to the luma.gl GPU abstraction
216
+ * Register WebGPU and/or WebGL adapters (controls application bundle size)
217
+ * Run-time selection of the first available Device
218
+ */
219
+ export const luma = new Luma();
@@ -107,17 +107,17 @@ export abstract class Buffer extends Resource<BufferProps> {
107
107
  byteOffset: number,
108
108
  byteLength: number
109
109
  ): void {
110
- const buffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data;
110
+ const arrayBuffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data;
111
111
  const debugDataLength = Math.min(
112
112
  data ? data.byteLength : byteLength,
113
113
  Buffer.DEBUG_DATA_MAX_LENGTH
114
114
  );
115
- if (data === null) {
115
+ if (arrayBuffer === null) {
116
116
  this.debugData = new ArrayBuffer(debugDataLength);
117
- } else if (byteOffset === 0 && byteLength === data.byteLength) {
118
- this.debugData = buffer.slice(0, debugDataLength);
117
+ } else if (byteOffset === 0 && byteLength === arrayBuffer.byteLength) {
118
+ this.debugData = arrayBuffer.slice(0, debugDataLength);
119
119
  } else {
120
- this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
120
+ this.debugData = arrayBuffer.slice(byteOffset, byteOffset + debugDataLength);
121
121
  }
122
122
  }
123
123
  }
@@ -133,7 +133,7 @@ export type CommandEncoderProps = ResourceProps & {
133
133
  export abstract class CommandEncoder extends Resource<CommandEncoderProps> {
134
134
  static override defaultProps: Required<CommandEncoderProps> = {
135
135
  ...Resource.defaultProps,
136
- measureExecutionTime: undefined
136
+ measureExecutionTime: undefined!
137
137
  };
138
138
 
139
139
  override get [Symbol.toStringTag](): string {
@@ -20,9 +20,9 @@ export type ComputePassProps = ResourceProps & {
20
20
  export abstract class ComputePass extends Resource<ComputePassProps> {
21
21
  static override defaultProps: Required<ComputePassProps> = {
22
22
  ...Resource.defaultProps,
23
- timestampQuerySet: undefined,
24
- beginTimestampIndex: undefined,
25
- endTimestampIndex: undefined
23
+ timestampQuerySet: undefined!,
24
+ beginTimestampIndex: undefined!,
25
+ endTimestampIndex: undefined!
26
26
  };
27
27
 
28
28
  override get [Symbol.toStringTag](): string {
@@ -28,10 +28,10 @@ export type ComputePipelineProps = ResourceProps & {
28
28
  export abstract class ComputePipeline extends Resource<ComputePipelineProps> {
29
29
  static override defaultProps: Required<ComputePipelineProps> = {
30
30
  ...Resource.defaultProps,
31
- shader: undefined,
32
- entryPoint: undefined,
31
+ shader: undefined!,
32
+ entryPoint: undefined!,
33
33
  constants: {},
34
- shaderLayout: undefined
34
+ shaderLayout: undefined!
35
35
  };
36
36
 
37
37
  override get [Symbol.toStringTag](): string {
@@ -39,9 +39,12 @@ export abstract class ComputePipeline extends Resource<ComputePipelineProps> {
39
39
  }
40
40
 
41
41
  hash: string = '';
42
+ /** The merged shader layout */
43
+ shaderLayout: ComputeShaderLayout;
42
44
 
43
45
  constructor(device: Device, props: ComputePipelineProps) {
44
46
  super(device, props, ComputePipeline.defaultProps);
47
+ this.shaderLayout = props.shaderLayout!;
45
48
  }
46
49
 
47
50
  /**
@@ -6,13 +6,13 @@ import type {Device} from '../device';
6
6
  import {Resource, ResourceProps} from './resource';
7
7
 
8
8
  export type ExternalTextureProps = ResourceProps & {
9
- source: HTMLVideoElement | null;
9
+ source: HTMLVideoElement; // | null;
10
10
  colorSpace?: 'srgb';
11
11
  };
12
12
  export abstract class ExternalTexture extends Resource<ExternalTextureProps> {
13
13
  static override defaultProps: Required<ExternalTextureProps> = {
14
14
  ...Resource.defaultProps,
15
- source: null,
15
+ source: undefined!,
16
16
  colorSpace: 'srgb'
17
17
  };
18
18
 
@@ -6,7 +6,7 @@ import type {
6
6
  ColorTextureFormat,
7
7
  DepthStencilTextureFormat,
8
8
  TextureFormat
9
- } from '../types/texture-formats';
9
+ } from '../../gpu-type-utils/texture-formats';
10
10
  import type {Device} from '../device';
11
11
  import {Resource, ResourceProps} from './resource';
12
12
  import {Texture} from './texture';
@@ -42,17 +42,14 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
42
42
  /** Height of all attachments in this framebuffer */
43
43
  height: number;
44
44
  /** Color attachments */
45
- colorAttachments: TextureView[] = [];
45
+ abstract colorAttachments: TextureView[];
46
46
  /** Depth-stencil attachment, if provided */
47
- depthStencilAttachment: TextureView | null = null;
47
+ abstract depthStencilAttachment: TextureView | null;
48
48
 
49
49
  constructor(device: Device, props: FramebufferProps = {}) {
50
50
  super(device, props, Framebuffer.defaultProps);
51
51
  this.width = this.props.width;
52
52
  this.height = this.props.height;
53
-
54
- // NOTE: call from subclass constructor as we cannot call overridden methods here (subclass not yet constructed)
55
- // this.autoCreateAttachmentTextures();
56
53
  }
57
54
 
58
55
  /**
@@ -139,7 +136,7 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
139
136
  for (let i = 0; i < this.colorAttachments.length; ++i) {
140
137
  if (this.colorAttachments[i]) {
141
138
  const resizedTexture = this.device._createTexture({
142
- ...this.colorAttachments[i].props,
139
+ ...this.colorAttachments[i].texture.props,
143
140
  width,
144
141
  height
145
142
  });
@@ -151,7 +148,7 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
151
148
 
152
149
  if (this.depthStencilAttachment) {
153
150
  const resizedTexture = this.device._createTexture({
154
- ...this.depthStencilAttachment.props,
151
+ ...this.depthStencilAttachment.texture.props,
155
152
  width,
156
153
  height
157
154
  });
@@ -161,87 +158,3 @@ export abstract class Framebuffer extends Resource<FramebufferProps> {
161
158
  }
162
159
  }
163
160
  }
164
-
165
- // TODO - remove if not needed
166
-
167
- // Create a color attachment for WebGL *
168
- // protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
169
- // return this.device._createTexture({
170
- // id: `${this.id}-color`,
171
- // data: null, // reserves texture memory, but texels are undefined
172
- // format,
173
- // // type: GL.UNSIGNED_BYTE,
174
- // width: this.width,
175
- // height: this.height,
176
- // // Note: Mipmapping can be disabled by texture resource when we resize the texture
177
- // // to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
178
- // // behavior we always disable mipmaps.
179
- // mipmaps: false,
180
- // // Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
181
- // // Use LINEAR so subpixel algos like fxaa work.
182
- // // Set WRAP modes that support NPOT textures too.
183
- // sampler: {
184
- // minFilter: 'linear',
185
- // magFilter: 'linear',
186
- // addressModeU: 'clamp-to-edge',
187
- // addressModeV: 'clamp-to-edge'
188
- // }
189
- // // parameters: {
190
- // // [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
191
- // // [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
192
- // // [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
193
- // // [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
194
- // // }
195
- // });
196
- // }
197
-
198
- // /** Returns fully populated attachment object. */
199
- // protected normalizeColorAttachment(
200
- // attachment: Texture | ColorTextureFormat
201
- // ): Required<ColorAttachment> {
202
-
203
- // const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
204
- // texture: undefined!,
205
- // format: undefined!,
206
- // clearValue: [0.0, 0.0, 0.0, 0.0],
207
- // loadOp: 'clear',
208
- // storeOp: 'store'
209
- // };
210
-
211
- // if (attachment instanceof Texture) {
212
- // return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
213
- // }
214
- // if (typeof attachment === 'string') {
215
- // return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
216
- // }
217
- // return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
218
- // }
219
-
220
- // /** Wraps texture inside fully populated attachment object. */
221
- // protected normalizeDepthStencilAttachment(
222
- // attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
223
- // ): Required<DepthStencilAttachment> {
224
- // const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
225
- // texture: undefined!,
226
- // format: undefined!,
227
-
228
- // depthClearValue: 1.0,
229
- // depthLoadOp: 'clear',
230
- // depthStoreOp: 'store',
231
- // depthReadOnly: false,
232
-
233
- // stencilClearValue: 0,
234
- // stencilLoadOp: 'clear',
235
- // stencilStoreOp: 'store',
236
- // stencilReadOnly: false
237
- // };
238
-
239
- // if (typeof attachment === 'string') {
240
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
241
- // }
242
- // // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
243
- // if (attachment.handle || attachment instanceof Texture) {
244
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
245
- // }
246
- // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
247
- // }
@@ -27,8 +27,8 @@ export type QuerySetProps = ResourceProps & {
27
27
  export abstract class QuerySet extends Resource<QuerySetProps> {
28
28
  static override defaultProps: Required<QuerySetProps> = {
29
29
  ...Resource.defaultProps,
30
- type: undefined,
31
- count: undefined
30
+ type: undefined!,
31
+ count: undefined!
32
32
  };
33
33
 
34
34
  get [Symbol.toStringTag](): string {
@@ -18,8 +18,14 @@ export type RenderPassProps = ResourceProps & {
18
18
  framebuffer?: Framebuffer | null;
19
19
  /** Control viewport, scissor rect, blend constant and stencil ref */
20
20
  parameters?: RenderPassParameters;
21
+
22
+ // TODO - API needs to be able to control multiple render targets
23
+
21
24
  /** Clear value for color attachment, or `load` to preserve the previous value */
22
25
  clearColor?: NumberArray | false;
26
+ /** Whether to disable / discard the output of the rasterizer */
27
+ discard?: boolean;
28
+
23
29
  /** Clear value for depth attachment, or `load` to preserve the previous value */
24
30
  clearDepth?: number | false;
25
31
  /** Clear value for stencil attachment, or `load` to preserve the previous value */
@@ -28,8 +34,6 @@ export type RenderPassProps = ResourceProps & {
28
34
  depthReadOnly?: boolean;
29
35
  /** Indicates that the stencil component is read only. */
30
36
  stencilReadOnly?: boolean;
31
- /** Whether to disable / discard the output of the rasterizer */
32
- discard?: boolean;
33
37
 
34
38
  /** QuerySet to write begin/end timestamps to */
35
39
  occlusionQuerySet?: QuerySet;
@@ -54,7 +58,7 @@ export abstract class RenderPass extends Resource<RenderPassProps> {
54
58
  static override defaultProps: Required<RenderPassProps> = {
55
59
  ...Resource.defaultProps,
56
60
  framebuffer: null,
57
- parameters: undefined,
61
+ parameters: undefined!,
58
62
  clearColor: [0, 0, 0, 0],
59
63
  clearDepth: 1,
60
64
  clearStencil: 0,
@@ -62,10 +66,10 @@ export abstract class RenderPass extends Resource<RenderPassProps> {
62
66
  stencilReadOnly: false,
63
67
  discard: false,
64
68
 
65
- occlusionQuerySet: undefined,
66
- timestampQuerySet: undefined,
67
- beginTimestampIndex: undefined,
68
- endTimestampIndex: undefined
69
+ occlusionQuerySet: undefined!,
70
+ timestampQuerySet: undefined!,
71
+ beginTimestampIndex: undefined!,
72
+ endTimestampIndex: undefined!
69
73
  };
70
74
 
71
75
  override get [Symbol.toStringTag](): string {