@luma.gl/core 9.3.0-alpha.6 → 9.3.0-alpha.8

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 (202) hide show
  1. package/dist/adapter/canvas-surface.d.ts +1 -1
  2. package/dist/adapter/canvas-surface.d.ts.map +1 -1
  3. package/dist/adapter/device.d.ts +13 -3
  4. package/dist/adapter/device.d.ts.map +1 -1
  5. package/dist/adapter/device.js +73 -6
  6. package/dist/adapter/device.js.map +1 -1
  7. package/dist/adapter/luma.js +1 -1
  8. package/dist/adapter/resources/command-buffer.d.ts +3 -1
  9. package/dist/adapter/resources/command-buffer.d.ts.map +1 -1
  10. package/dist/adapter/resources/command-buffer.js +3 -1
  11. package/dist/adapter/resources/command-buffer.js.map +1 -1
  12. package/dist/adapter/resources/command-encoder.d.ts +3 -1
  13. package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
  14. package/dist/adapter/resources/command-encoder.js +3 -1
  15. package/dist/adapter/resources/command-encoder.js.map +1 -1
  16. package/dist/adapter/resources/compute-pipeline.d.ts +2 -2
  17. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
  18. package/dist/adapter/resources/framebuffer.d.ts +1 -1
  19. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  20. package/dist/adapter/resources/render-pipeline.d.ts +10 -4
  21. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  22. package/dist/adapter/resources/render-pipeline.js +2 -1
  23. package/dist/adapter/resources/render-pipeline.js.map +1 -1
  24. package/dist/adapter/resources/texture-view.d.ts +1 -1
  25. package/dist/adapter/resources/texture-view.d.ts.map +1 -1
  26. package/dist/adapter/resources/texture.d.ts +5 -4
  27. package/dist/adapter/resources/texture.d.ts.map +1 -1
  28. package/dist/adapter/resources/texture.js +4 -3
  29. package/dist/adapter/resources/texture.js.map +1 -1
  30. package/dist/adapter/types/attachments.d.ts +1 -1
  31. package/dist/adapter/types/attachments.d.ts.map +1 -1
  32. package/dist/adapter/types/buffer-layout.d.ts +1 -1
  33. package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
  34. package/dist/adapter/types/parameters.d.ts +3 -1
  35. package/dist/adapter/types/parameters.d.ts.map +1 -1
  36. package/dist/adapter/types/parameters.js +1 -0
  37. package/dist/adapter/types/parameters.js.map +1 -1
  38. package/dist/adapter/types/shader-layout.d.ts +10 -6
  39. package/dist/adapter/types/shader-layout.d.ts.map +1 -1
  40. package/dist/adapter/types/uniforms.d.ts +6 -0
  41. package/dist/adapter/types/uniforms.d.ts.map +1 -1
  42. package/dist/adapter-utils/bind-groups.d.ts +9 -0
  43. package/dist/adapter-utils/bind-groups.d.ts.map +1 -0
  44. package/dist/adapter-utils/bind-groups.js +41 -0
  45. package/dist/adapter-utils/bind-groups.js.map +1 -0
  46. package/dist/adapter-utils/get-attribute-from-layouts.d.ts +2 -2
  47. package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -1
  48. package/dist/adapter-utils/get-attribute-from-layouts.js +6 -6
  49. package/dist/adapter-utils/get-attribute-from-layouts.js.map +1 -1
  50. package/dist/dist.dev.js +983 -223
  51. package/dist/dist.min.js +5 -5
  52. package/dist/factories/bind-group-factory.d.ts +20 -0
  53. package/dist/factories/bind-group-factory.d.ts.map +1 -0
  54. package/dist/factories/bind-group-factory.js +79 -0
  55. package/dist/factories/bind-group-factory.js.map +1 -0
  56. package/dist/factories/core-module-state.d.ts +7 -0
  57. package/dist/factories/core-module-state.d.ts.map +1 -0
  58. package/dist/{shadertypes/data-types/shader-types.js → factories/core-module-state.js} +1 -1
  59. package/dist/factories/core-module-state.js.map +1 -0
  60. package/dist/factories/pipeline-factory.d.ts +54 -0
  61. package/dist/factories/pipeline-factory.d.ts.map +1 -0
  62. package/dist/factories/pipeline-factory.js +270 -0
  63. package/dist/factories/pipeline-factory.js.map +1 -0
  64. package/dist/factories/shader-factory.d.ts +20 -0
  65. package/dist/factories/shader-factory.d.ts.map +1 -0
  66. package/dist/factories/shader-factory.js +84 -0
  67. package/dist/factories/shader-factory.js.map +1 -0
  68. package/dist/index.cjs +942 -221
  69. package/dist/index.cjs.map +4 -4
  70. package/dist/index.d.ts +22 -14
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +13 -9
  73. package/dist/index.js.map +1 -1
  74. package/dist/portable/uniform-block.d.ts +1 -1
  75. package/dist/portable/uniform-block.d.ts.map +1 -1
  76. package/dist/portable/uniform-buffer-layout.d.ts +20 -15
  77. package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
  78. package/dist/portable/uniform-buffer-layout.js +188 -43
  79. package/dist/portable/uniform-buffer-layout.js.map +1 -1
  80. package/dist/portable/uniform-store.d.ts +5 -6
  81. package/dist/portable/uniform-store.d.ts.map +1 -1
  82. package/dist/portable/uniform-store.js +6 -3
  83. package/dist/portable/uniform-store.js.map +1 -1
  84. package/dist/shadertypes/data-types/data-type-decoder.d.ts +20 -0
  85. package/dist/shadertypes/data-types/data-type-decoder.d.ts.map +1 -0
  86. package/dist/shadertypes/data-types/data-type-decoder.js +79 -0
  87. package/dist/shadertypes/data-types/data-type-decoder.js.map +1 -0
  88. package/dist/shadertypes/data-types/data-types.d.ts +31 -12
  89. package/dist/shadertypes/data-types/data-types.d.ts.map +1 -1
  90. package/dist/{image-utils → shadertypes/image-types}/image-types.d.ts +0 -6
  91. package/dist/shadertypes/image-types/image-types.d.ts.map +1 -0
  92. package/dist/shadertypes/image-types/image-types.js.map +1 -0
  93. package/dist/shadertypes/shader-types/shader-type-decoder.d.ts +41 -0
  94. package/dist/shadertypes/shader-types/shader-type-decoder.d.ts.map +1 -0
  95. package/dist/shadertypes/{data-types/decode-shader-types.js → shader-types/shader-type-decoder.js} +32 -2
  96. package/dist/shadertypes/shader-types/shader-type-decoder.js.map +1 -0
  97. package/dist/shadertypes/shader-types/shader-types.d.ts +101 -0
  98. package/dist/shadertypes/shader-types/shader-types.d.ts.map +1 -0
  99. package/dist/shadertypes/shader-types/shader-types.js +30 -0
  100. package/dist/shadertypes/shader-types/shader-types.js.map +1 -0
  101. package/dist/shadertypes/texture-types/pixel-utils.d.ts.map +1 -0
  102. package/dist/shadertypes/texture-types/pixel-utils.js.map +1 -0
  103. package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.d.ts +1 -0
  104. package/dist/shadertypes/texture-types/texture-format-decoder.d.ts.map +1 -0
  105. package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.js +4 -3
  106. package/dist/shadertypes/texture-types/texture-format-decoder.js.map +1 -0
  107. package/dist/shadertypes/texture-types/texture-format-generics.d.ts +34 -0
  108. package/dist/shadertypes/texture-types/texture-format-generics.d.ts.map +1 -0
  109. package/dist/shadertypes/texture-types/texture-format-generics.js.map +1 -0
  110. package/dist/shadertypes/texture-types/texture-format-table.d.ts.map +1 -0
  111. package/dist/shadertypes/texture-types/texture-format-table.js.map +1 -0
  112. package/dist/shadertypes/{textures → texture-types}/texture-formats.d.ts +5 -1
  113. package/dist/shadertypes/texture-types/texture-formats.d.ts.map +1 -0
  114. package/dist/shadertypes/{textures → texture-types}/texture-formats.js +1 -0
  115. package/dist/shadertypes/texture-types/texture-formats.js.map +1 -0
  116. package/dist/shadertypes/{textures → texture-types}/texture-layout.d.ts +1 -1
  117. package/dist/shadertypes/texture-types/texture-layout.d.ts.map +1 -0
  118. package/dist/shadertypes/texture-types/texture-layout.js.map +1 -0
  119. package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts +24 -0
  120. package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts.map +1 -0
  121. package/dist/shadertypes/vertex-types/vertex-format-decoder.js +106 -0
  122. package/dist/shadertypes/vertex-types/vertex-format-decoder.js.map +1 -0
  123. package/dist/shadertypes/vertex-types/vertex-formats.d.ts +50 -0
  124. package/dist/shadertypes/vertex-types/vertex-formats.d.ts.map +1 -0
  125. package/dist/shadertypes/vertex-types/vertex-formats.js.map +1 -0
  126. package/package.json +2 -2
  127. package/src/adapter/canvas-surface.ts +1 -1
  128. package/src/adapter/device.ts +115 -10
  129. package/src/adapter/resources/command-buffer.ts +3 -1
  130. package/src/adapter/resources/command-encoder.ts +3 -1
  131. package/src/adapter/resources/compute-pipeline.ts +2 -2
  132. package/src/adapter/resources/framebuffer.ts +1 -1
  133. package/src/adapter/resources/render-pipeline.ts +12 -5
  134. package/src/adapter/resources/texture-view.ts +1 -1
  135. package/src/adapter/resources/texture.ts +6 -5
  136. package/src/adapter/types/attachments.ts +1 -1
  137. package/src/adapter/types/buffer-layout.ts +1 -1
  138. package/src/adapter/types/parameters.ts +4 -1
  139. package/src/adapter/types/shader-layout.ts +15 -9
  140. package/src/adapter/types/uniforms.ts +12 -0
  141. package/src/adapter-utils/bind-groups.ts +71 -0
  142. package/src/adapter-utils/get-attribute-from-layouts.ts +8 -11
  143. package/src/factories/bind-group-factory.ts +139 -0
  144. package/src/factories/core-module-state.ts +11 -0
  145. package/src/factories/pipeline-factory.ts +328 -0
  146. package/src/factories/shader-factory.ts +103 -0
  147. package/src/index.ts +47 -26
  148. package/src/portable/uniform-block.ts +1 -1
  149. package/src/portable/uniform-buffer-layout.ts +269 -62
  150. package/src/portable/uniform-store.ts +14 -11
  151. package/src/shadertypes/data-types/data-type-decoder.ts +105 -0
  152. package/src/shadertypes/data-types/data-types.ts +100 -48
  153. package/src/{image-utils → shadertypes/image-types}/image-types.ts +0 -7
  154. package/src/shadertypes/{data-types/decode-shader-types.ts → shader-types/shader-type-decoder.ts} +76 -11
  155. package/src/shadertypes/shader-types/shader-types.ts +207 -0
  156. package/src/shadertypes/{textures → texture-types}/texture-format-decoder.ts +4 -3
  157. package/src/shadertypes/{textures → texture-types}/texture-format-generics.ts +42 -48
  158. package/src/shadertypes/{textures → texture-types}/texture-formats.ts +14 -2
  159. package/src/shadertypes/vertex-types/vertex-format-decoder.ts +131 -0
  160. package/src/shadertypes/vertex-types/vertex-formats.ts +183 -0
  161. package/dist/image-utils/image-types.d.ts.map +0 -1
  162. package/dist/image-utils/image-types.js.map +0 -1
  163. package/dist/shadertypes/data-types/decode-shader-types.d.ts +0 -17
  164. package/dist/shadertypes/data-types/decode-shader-types.d.ts.map +0 -1
  165. package/dist/shadertypes/data-types/decode-shader-types.js.map +0 -1
  166. package/dist/shadertypes/data-types/shader-types.d.ts +0 -43
  167. package/dist/shadertypes/data-types/shader-types.d.ts.map +0 -1
  168. package/dist/shadertypes/data-types/shader-types.js.map +0 -1
  169. package/dist/shadertypes/textures/pixel-utils.d.ts.map +0 -1
  170. package/dist/shadertypes/textures/pixel-utils.js.map +0 -1
  171. package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +0 -1
  172. package/dist/shadertypes/textures/texture-format-decoder.js.map +0 -1
  173. package/dist/shadertypes/textures/texture-format-generics.d.ts +0 -33
  174. package/dist/shadertypes/textures/texture-format-generics.d.ts.map +0 -1
  175. package/dist/shadertypes/textures/texture-format-generics.js.map +0 -1
  176. package/dist/shadertypes/textures/texture-format-table.d.ts.map +0 -1
  177. package/dist/shadertypes/textures/texture-format-table.js.map +0 -1
  178. package/dist/shadertypes/textures/texture-formats.d.ts.map +0 -1
  179. package/dist/shadertypes/textures/texture-formats.js.map +0 -1
  180. package/dist/shadertypes/textures/texture-layout.d.ts.map +0 -1
  181. package/dist/shadertypes/textures/texture-layout.js.map +0 -1
  182. package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts +0 -18
  183. package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts.map +0 -1
  184. package/dist/shadertypes/vertex-arrays/decode-vertex-format.js +0 -100
  185. package/dist/shadertypes/vertex-arrays/decode-vertex-format.js.map +0 -1
  186. package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts +0 -27
  187. package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts.map +0 -1
  188. package/dist/shadertypes/vertex-arrays/vertex-formats.js.map +0 -1
  189. package/src/shadertypes/data-types/shader-types.ts +0 -94
  190. package/src/shadertypes/vertex-arrays/decode-vertex-format.ts +0 -124
  191. package/src/shadertypes/vertex-arrays/vertex-formats.ts +0 -91
  192. /package/dist/{image-utils → shadertypes/image-types}/image-types.js +0 -0
  193. /package/dist/shadertypes/{textures → texture-types}/pixel-utils.d.ts +0 -0
  194. /package/dist/shadertypes/{textures → texture-types}/pixel-utils.js +0 -0
  195. /package/dist/shadertypes/{textures → texture-types}/texture-format-generics.js +0 -0
  196. /package/dist/shadertypes/{textures → texture-types}/texture-format-table.d.ts +0 -0
  197. /package/dist/shadertypes/{textures → texture-types}/texture-format-table.js +0 -0
  198. /package/dist/shadertypes/{textures → texture-types}/texture-layout.js +0 -0
  199. /package/dist/shadertypes/{vertex-arrays → vertex-types}/vertex-formats.js +0 -0
  200. /package/src/shadertypes/{textures → texture-types}/pixel-utils.ts +0 -0
  201. /package/src/shadertypes/{textures → texture-types}/texture-format-table.ts +0 -0
  202. /package/src/shadertypes/{textures → texture-types}/texture-layout.ts +0 -0
@@ -23,7 +23,9 @@ import {Resource, ResourceProps} from './resource';
23
23
  export type CommandBufferProps = ResourceProps & {};
24
24
 
25
25
  /**
26
- * Encodes commands to queue that can be executed later
26
+ * Represents the finished contents of exactly one CommandEncoder. Backends may store native
27
+ * command buffers or replayable command lists internally, but submission must preserve the same
28
+ * recorded command ordering.
27
29
  */
28
30
  export abstract class CommandBuffer extends Resource<CommandBufferProps> {
29
31
  override get [Symbol.toStringTag](): string {
@@ -138,7 +138,9 @@ type PassWithTimestamps = {
138
138
  };
139
139
 
140
140
  /**
141
- * Encodes commands to queue that can be executed later
141
+ * Records commands onto a single backend command encoder and can finish them into one command
142
+ * buffer. Resource helpers invoked through a CommandEncoder must record onto that encoder rather
143
+ * than allocating hidden encoders or submitting work eagerly.
142
144
  */
143
145
  export abstract class CommandEncoder extends Resource<CommandEncoderProps> {
144
146
  override get [Symbol.toStringTag](): string {
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Resource, ResourceProps} from './resource';
6
- import type {ComputeShaderLayout, Binding} from '../types/shader-layout';
6
+ import type {ComputeShaderLayout, Bindings, BindingsByGroup} from '../types/shader-layout';
7
7
  import type {Device} from '../device';
8
8
  import type {Shader} from './shader';
9
9
 
@@ -43,7 +43,7 @@ export abstract class ComputePipeline extends Resource<ComputePipelineProps> {
43
43
  * @todo Use renderpass.setBindings() ?
44
44
  * @todo Do we want to expose BindGroups in the API and remove this?
45
45
  */
46
- abstract setBindings(bindings: Record<string, Binding>): void;
46
+ abstract setBindings(bindings: Bindings | BindingsByGroup): void;
47
47
 
48
48
  static override defaultProps: Required<ComputePipelineProps> = {
49
49
  ...Resource.defaultProps,
@@ -6,7 +6,7 @@ import type {
6
6
  TextureFormatColor,
7
7
  TextureFormatDepthStencil,
8
8
  TextureFormat
9
- } from '../../shadertypes/textures/texture-formats';
9
+ } from '../../shadertypes/texture-types/texture-formats';
10
10
  import type {Device} from '../device';
11
11
  import {Resource, ResourceProps} from './resource';
12
12
  import {Texture} from './texture';
@@ -4,12 +4,12 @@
4
4
 
5
5
  import type {Device} from '../device';
6
6
  import type {PrimitiveTopology, RenderPipelineParameters} from '../types/parameters';
7
- import type {ShaderLayout, Binding} from '../types/shader-layout';
7
+ import type {ShaderLayout, Bindings, BindingsByGroup} from '../types/shader-layout';
8
8
  import type {BufferLayout} from '../types/buffer-layout';
9
9
  import type {
10
10
  TextureFormatColor,
11
11
  TextureFormatDepthStencil
12
- } from '@luma.gl/core/shadertypes/textures/texture-formats';
12
+ } from '@luma.gl/core/shadertypes/texture-types/texture-formats';
13
13
  import type {Shader} from './shader';
14
14
  import type {SharedRenderPipeline} from './shared-render-pipeline';
15
15
  import type {RenderPass} from './render-pass';
@@ -64,7 +64,9 @@ export type RenderPipelineProps = ResourceProps & {
64
64
 
65
65
  // Dynamic bindings (TODO - pipelines should be immutable, move to RenderPass)
66
66
  /** Buffers, Textures, Samplers for the shader bindings */
67
- bindings?: Record<string, Binding>;
67
+ bindings?: Bindings;
68
+ /** Bindings grouped by bind-group index */
69
+ bindGroups?: BindingsByGroup;
68
70
  };
69
71
 
70
72
  /**
@@ -142,7 +144,11 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
142
144
  /** Transform feedback. WebGL only. */
143
145
  transformFeedback?: TransformFeedback;
144
146
  /** Bindings applied for this draw (textures, samplers, uniform buffers) */
145
- bindings?: Record<string, Binding>;
147
+ bindings?: Bindings;
148
+ /** Bindings grouped by bind-group index */
149
+ bindGroups?: BindingsByGroup;
150
+ /** Optional stable cache keys for backend bind-group reuse */
151
+ _bindGroupCacheKeys?: Partial<Record<number, object>>;
146
152
  /** WebGL-only uniforms */
147
153
  uniforms?: Record<string, unknown>;
148
154
  }): boolean;
@@ -170,6 +176,7 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
170
176
  bufferMode: undefined!,
171
177
  disableWarnings: false,
172
178
  _sharedRenderPipeline: undefined!,
173
- bindings: undefined!
179
+ bindings: undefined!,
180
+ bindGroups: undefined!
174
181
  };
175
182
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type {Device} from '../device';
6
6
  import type {Texture} from './texture';
7
- import type {TextureFormat} from '../../shadertypes/textures/texture-formats';
7
+ import type {TextureFormat} from '../../shadertypes/texture-types/texture-formats';
8
8
  import {Resource, ResourceProps} from './resource';
9
9
 
10
10
  /** Properties for initializing a texture view */
@@ -8,14 +8,14 @@ import {
8
8
  type TextureFormat,
9
9
  type TextureMemoryLayout,
10
10
  type TextureFormatInfo
11
- } from '../../shadertypes/textures/texture-formats';
12
- import {type ExternalImage} from '../../image-utils/image-types';
11
+ } from '../../shadertypes/texture-types/texture-formats';
12
+ import {type ExternalImage} from '../../shadertypes/image-types/image-types';
13
13
  import {type TextureView, type TextureViewProps} from './texture-view';
14
14
  import {Resource, type ResourceProps} from './resource';
15
15
  import {Sampler, type SamplerProps} from './sampler';
16
16
  import {Buffer} from './buffer';
17
17
  import {log} from '../../utils/log';
18
- import {textureFormatDecoder} from '../../shadertypes/textures/texture-format-decoder';
18
+ import {textureFormatDecoder} from '../../shadertypes/texture-types/texture-format-decoder';
19
19
 
20
20
  /** Options for Texture.copyExternalImage */
21
21
  export type CopyExternalImageOptions = {
@@ -325,8 +325,8 @@ export abstract class Texture extends Resource<TextureProps> {
325
325
  *
326
326
  * @note The memory layout of the texture data is determined by the texture format and dimensions.
327
327
  * @note The application can call Texture.computeMemoryLayout() to compute the backend-aligned layout.
328
- * @note The application can call Buffer.readAsync()
329
- * @note If not supplied a buffer will be created and the application needs to call Buffer.destroy
328
+ * @note The application can call Buffer.readAsync() to read the returned buffer on the CPU.
329
+ * @note The destination buffer must be supplied by the caller and must be large enough for the requested region.
330
330
  * @note On WebGPU this corresponds to a texture-to-buffer copy and uses buffer-copy alignment rules.
331
331
  * @note On WebGL, luma.gl emulates the same logical readback behavior.
332
332
  */
@@ -340,6 +340,7 @@ export abstract class Texture extends Resource<TextureProps> {
340
340
  *
341
341
  * @note The memory layout of the texture data is determined by the texture format and dimensions.
342
342
  * @note The application can call Texture.computeMemoryLayout() to compute the layout.
343
+ * @deprecated Use Texture.readBuffer() with an explicit destination buffer, or DynamicTexture.readAsync() for convenience readback.
343
344
  */
344
345
  readDataAsync(options?: TextureReadOptions): Promise<ArrayBuffer> {
345
346
  throw new Error('readBuffer not implemented');
@@ -6,7 +6,7 @@ import type {
6
6
  TextureFormatColor,
7
7
  TextureFormatDepthStencil,
8
8
  TextureFormat
9
- } from '../../shadertypes/textures/texture-formats';
9
+ } from '../../shadertypes/texture-types/texture-formats';
10
10
  import type {Texture} from '../resources/texture'; // TextureView...
11
11
  import type {TextureView} from '../resources/texture-view'; // TextureView...
12
12
 
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {VertexFormat} from '../../shadertypes/vertex-arrays/vertex-formats';
5
+ import type {VertexFormat} from '../../shadertypes/vertex-types/vertex-formats';
6
6
 
7
7
  /**
8
8
  * Provides specific details about the memory layout of the actual buffers
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {NumberArray4, NumberArray6} from '@math.gl/types';
6
- import {TextureFormatDepthStencil} from '../../shadertypes/textures/texture-formats';
6
+ import {TextureFormatDepthStencil} from '../../shadertypes/texture-types/texture-formats';
7
7
 
8
8
  export type CompareFunction =
9
9
  | 'never'
@@ -102,6 +102,8 @@ export type DepthStencilParameters = {
102
102
  depthCompare?: CompareFunction;
103
103
  /** The format of depthStencilAttachment this GPURenderPipeline will be compatible with. */
104
104
  depthFormat?: TextureFormatDepthStencil;
105
+ /** Depth value used when clearing depth buffers. */
106
+ clearDepth?: number;
105
107
 
106
108
  /** Bitmask controlling which depthStencilAttachment stencil value bits are read when performing stencil comparison tests. */
107
109
  stencilReadMask?: number;
@@ -217,6 +219,7 @@ export const DEFAULT_PARAMETERS: Required<Parameters> = {
217
219
  depthWriteEnabled: false,
218
220
  depthCompare: 'always',
219
221
  depthFormat: 'depth24plus',
222
+ clearDepth: 1,
220
223
 
221
224
  depthBias: 0,
222
225
  depthBiasSlopeScale: 0,
@@ -2,15 +2,15 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {TextureFormat} from '../../shadertypes/textures/texture-formats';
6
- import type {
7
- VariableShaderType,
8
- AttributeShaderType
9
- } from '../../shadertypes/data-types/shader-types';
10
- import type {Buffer} from '../resources/buffer';
11
- import type {Sampler} from '../resources/sampler';
12
- import type {Texture} from '../resources/texture';
13
- import type {TextureView} from '../resources/texture-view';
5
+ import {type TextureFormat} from '../../shadertypes/texture-types/texture-formats';
6
+ import {
7
+ type VariableShaderType,
8
+ type AttributeShaderType
9
+ } from '../../shadertypes/shader-types/shader-types';
10
+ import {type Buffer} from '../resources/buffer';
11
+ import {type Sampler} from '../resources/sampler';
12
+ import {type Texture} from '../resources/texture';
13
+ import {type TextureView} from '../resources/texture-view';
14
14
 
15
15
  /**
16
16
  * Describes all shader binding points for a `RenderPipeline` or `ComputePipeline`
@@ -166,6 +166,12 @@ export type Binding =
166
166
  | Buffer
167
167
  | {buffer: Buffer; offset?: number; size?: number};
168
168
 
169
+ /** Named binding map */
170
+ export type Bindings = Record<string, Binding>;
171
+
172
+ /** Bindings partitioned by bind-group index */
173
+ export type BindingsByGroup = Partial<Record<number, Bindings>>;
174
+
169
175
  // SHADER LAYOUTS
170
176
 
171
177
  /**
@@ -8,3 +8,15 @@ import {NumericArray} from '@math.gl/types';
8
8
 
9
9
  /** Valid values for uniforms. @note boolean values get converted to 0 or 1 before setting */
10
10
  export type UniformValue = number | boolean | Readonly<NumericArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
11
+
12
+ /** Recursive uniform value tree used by uniform-buffer packing utilities. */
13
+ export type CompositeUniformValue =
14
+ | UniformValue
15
+ | CompositeUniformValueStruct
16
+ | CompositeUniformValueArray;
17
+
18
+ export type CompositeUniformValueStruct = {
19
+ [name: string]: CompositeUniformValue | undefined;
20
+ };
21
+
22
+ export type CompositeUniformValueArray = ReadonlyArray<CompositeUniformValue | undefined>;
@@ -0,0 +1,71 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ BindingDeclaration,
7
+ Bindings,
8
+ BindingsByGroup,
9
+ ComputeShaderLayout,
10
+ ShaderLayout
11
+ } from '../adapter/types/shader-layout';
12
+ import {log} from '../utils/log';
13
+
14
+ type AnyShaderLayout = Pick<ShaderLayout | ComputeShaderLayout, 'bindings'>;
15
+
16
+ export function getShaderLayoutBinding(
17
+ shaderLayout: AnyShaderLayout,
18
+ bindingName: string,
19
+ options?: {ignoreWarnings?: boolean}
20
+ ): BindingDeclaration | null {
21
+ const bindingLayout = shaderLayout.bindings.find(
22
+ binding =>
23
+ binding.name === bindingName ||
24
+ `${binding.name.toLocaleLowerCase()}uniforms` === bindingName.toLocaleLowerCase()
25
+ );
26
+
27
+ if (!bindingLayout && !options?.ignoreWarnings) {
28
+ log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
29
+ }
30
+
31
+ return bindingLayout || null;
32
+ }
33
+
34
+ export function normalizeBindingsByGroup(
35
+ shaderLayout: AnyShaderLayout,
36
+ bindingsOrBindGroups?: Bindings | BindingsByGroup
37
+ ): BindingsByGroup {
38
+ if (!bindingsOrBindGroups) {
39
+ return {};
40
+ }
41
+
42
+ if (areBindingsGrouped(bindingsOrBindGroups)) {
43
+ const bindGroups = bindingsOrBindGroups as BindingsByGroup;
44
+ return Object.fromEntries(
45
+ Object.entries(bindGroups).map(([group, bindings]) => [Number(group), {...bindings}])
46
+ ) as BindingsByGroup;
47
+ }
48
+
49
+ const bindGroups: BindingsByGroup = {};
50
+ for (const [bindingName, binding] of Object.entries(bindingsOrBindGroups as Bindings)) {
51
+ const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
52
+ const group = bindingLayout?.group ?? 0;
53
+ bindGroups[group] ||= {};
54
+ bindGroups[group][bindingName] = binding;
55
+ }
56
+
57
+ return bindGroups;
58
+ }
59
+
60
+ export function flattenBindingsByGroup(bindGroups: BindingsByGroup): Bindings {
61
+ const bindings: Bindings = {};
62
+ for (const groupBindings of Object.values(bindGroups)) {
63
+ Object.assign(bindings, groupBindings);
64
+ }
65
+ return bindings;
66
+ }
67
+
68
+ function areBindingsGrouped(bindingsOrBindGroups: Bindings | BindingsByGroup): boolean {
69
+ const keys = Object.keys(bindingsOrBindGroups);
70
+ return keys.length > 0 && keys.every(key => /^\d+$/.test(key));
71
+ }
@@ -4,13 +4,10 @@
4
4
 
5
5
  import {log} from '../utils/log';
6
6
  import type {PrimitiveDataType, NormalizedDataType} from '../shadertypes/data-types/data-types';
7
- import type {AttributeShaderType} from '../shadertypes/data-types/shader-types';
8
- import type {VertexFormat} from '../shadertypes/vertex-arrays/vertex-formats';
9
- import {getAttributeShaderTypeInfo} from '../shadertypes/data-types/decode-shader-types';
10
- import {
11
- getVertexFormatInfo,
12
- getCompatibleVertexFormat
13
- } from '../shadertypes/vertex-arrays/decode-vertex-format';
7
+ import type {AttributeShaderType} from '../shadertypes/shader-types/shader-types';
8
+ import type {VertexFormat} from '../shadertypes/vertex-types/vertex-formats';
9
+ import {shaderTypeDecoder} from '../shadertypes/shader-types/shader-type-decoder';
10
+ import {vertexFormatDecoder} from '../shadertypes/vertex-types/vertex-format-decoder';
14
11
  import type {ShaderLayout, AttributeDeclaration} from '../adapter/types/shader-layout';
15
12
  import type {BufferLayout} from '../adapter/types/buffer-layout';
16
13
 
@@ -112,10 +109,10 @@ function getAttributeInfoFromLayouts(
112
109
  return null;
113
110
  }
114
111
 
115
- const attributeTypeInfo = getAttributeShaderTypeInfo(shaderDeclaration.type);
116
- const defaultVertexFormat = getCompatibleVertexFormat(attributeTypeInfo);
112
+ const attributeTypeInfo = shaderTypeDecoder.getAttributeShaderTypeInfo(shaderDeclaration.type);
113
+ const defaultVertexFormat = vertexFormatDecoder.getCompatibleVertexFormat(attributeTypeInfo);
117
114
  const vertexFormat = bufferMapping?.vertexFormat || defaultVertexFormat;
118
- const vertexFormatInfo = getVertexFormatInfo(vertexFormat);
115
+ const vertexFormatInfo = vertexFormatDecoder.getVertexFormatInfo(vertexFormat);
119
116
 
120
117
  return {
121
118
  attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
@@ -217,7 +214,7 @@ function getAttributeFromAttributesList(
217
214
  // Calculate a default byte stride if not provided
218
215
  if (typeof bufferLayout.byteStride !== 'number') {
219
216
  for (const attributeMapping of bufferLayout.attributes || []) {
220
- const info = getVertexFormatInfo(attributeMapping.format);
217
+ const info = vertexFormatDecoder.getVertexFormatInfo(attributeMapping.format);
221
218
  // @ts-ignore
222
219
  byteStride += info.byteLength;
223
220
  }
@@ -0,0 +1,139 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ Bindings,
7
+ BindingsByGroup,
8
+ ComputeShaderLayout,
9
+ ShaderLayout
10
+ } from '../adapter/types/shader-layout';
11
+ import type {Device} from '../adapter/device';
12
+ import type {ComputePipeline} from '../adapter/resources/compute-pipeline';
13
+ import type {RenderPipeline} from '../adapter/resources/render-pipeline';
14
+ import {normalizeBindingsByGroup} from '../adapter-utils/bind-groups';
15
+
16
+ type AnyPipeline = RenderPipeline | ComputePipeline;
17
+ type AnyShaderLayout = ShaderLayout | ComputeShaderLayout;
18
+ type BindGroupCacheKeys = Partial<Record<number, object>>;
19
+ type BindGroupMap = Partial<Record<number, unknown>>;
20
+ type LayoutCache = Partial<Record<number, object>>;
21
+ type LayoutBindGroupCache = {
22
+ bindGroupsBySource: WeakMap<object, unknown | null>;
23
+ emptyBindGroup?: unknown;
24
+ };
25
+
26
+ export class BindGroupFactory {
27
+ readonly device: Device;
28
+
29
+ private readonly _layoutCacheByPipeline: WeakMap<AnyPipeline, LayoutCache> = new WeakMap();
30
+ private readonly _bindGroupCacheByLayout: WeakMap<object, LayoutBindGroupCache> = new WeakMap();
31
+
32
+ constructor(device: Device) {
33
+ this.device = device;
34
+ }
35
+
36
+ getBindGroups(
37
+ pipeline: AnyPipeline,
38
+ bindings?: Bindings | BindingsByGroup,
39
+ bindGroupCacheKeys?: BindGroupCacheKeys
40
+ ): BindGroupMap {
41
+ if (this.device.type !== 'webgpu' || pipeline.shaderLayout.bindings.length === 0) {
42
+ return {};
43
+ }
44
+
45
+ const bindingsByGroup = normalizeBindingsByGroup(pipeline.shaderLayout, bindings);
46
+ const resolvedBindGroups: BindGroupMap = {};
47
+
48
+ for (const group of getBindGroupIndicesUpToMax(pipeline.shaderLayout.bindings)) {
49
+ const groupBindings = bindingsByGroup[group];
50
+ const bindGroupLayout = this._getBindGroupLayout(pipeline, group);
51
+
52
+ if (!groupBindings || Object.keys(groupBindings).length === 0) {
53
+ if (!hasBindingsInGroup(pipeline.shaderLayout.bindings, group)) {
54
+ resolvedBindGroups[group] = this._getEmptyBindGroup(
55
+ bindGroupLayout,
56
+ pipeline.shaderLayout,
57
+ group
58
+ );
59
+ }
60
+ continue;
61
+ }
62
+
63
+ const bindGroupCacheKey = bindGroupCacheKeys?.[group];
64
+ if (bindGroupCacheKey) {
65
+ const layoutCache = this._getLayoutBindGroupCache(bindGroupLayout);
66
+ if (layoutCache.bindGroupsBySource.has(bindGroupCacheKey)) {
67
+ resolvedBindGroups[group] = layoutCache.bindGroupsBySource.get(bindGroupCacheKey) || null;
68
+ continue;
69
+ }
70
+
71
+ const bindGroup = this.device._createBindGroupWebGPU(
72
+ bindGroupLayout,
73
+ pipeline.shaderLayout,
74
+ groupBindings,
75
+ group
76
+ );
77
+ layoutCache.bindGroupsBySource.set(bindGroupCacheKey, bindGroup);
78
+ resolvedBindGroups[group] = bindGroup;
79
+ } else {
80
+ resolvedBindGroups[group] = this.device._createBindGroupWebGPU(
81
+ bindGroupLayout,
82
+ pipeline.shaderLayout,
83
+ groupBindings,
84
+ group
85
+ );
86
+ }
87
+ }
88
+
89
+ return resolvedBindGroups;
90
+ }
91
+
92
+ private _getBindGroupLayout(pipeline: AnyPipeline, group: number): object {
93
+ let layoutCache = this._layoutCacheByPipeline.get(pipeline);
94
+ if (!layoutCache) {
95
+ layoutCache = {};
96
+ this._layoutCacheByPipeline.set(pipeline, layoutCache);
97
+ }
98
+
99
+ layoutCache[group] ||= this.device._createBindGroupLayoutWebGPU(pipeline, group) as object;
100
+ return layoutCache[group];
101
+ }
102
+
103
+ private _getEmptyBindGroup(
104
+ bindGroupLayout: object,
105
+ shaderLayout: AnyShaderLayout,
106
+ group: number
107
+ ): unknown {
108
+ const layoutCache = this._getLayoutBindGroupCache(bindGroupLayout);
109
+ layoutCache.emptyBindGroup ||=
110
+ this.device._createBindGroupWebGPU(bindGroupLayout, shaderLayout, {}, group) || null;
111
+ return layoutCache.emptyBindGroup;
112
+ }
113
+
114
+ private _getLayoutBindGroupCache(bindGroupLayout: object): LayoutBindGroupCache {
115
+ let layoutCache = this._bindGroupCacheByLayout.get(bindGroupLayout);
116
+ if (!layoutCache) {
117
+ layoutCache = {bindGroupsBySource: new WeakMap()};
118
+ this._bindGroupCacheByLayout.set(bindGroupLayout, layoutCache);
119
+ }
120
+ return layoutCache;
121
+ }
122
+ }
123
+
124
+ export function _getDefaultBindGroupFactory(device: Device): BindGroupFactory {
125
+ device._factories.bindGroupFactory ||= new BindGroupFactory(device);
126
+ return device._factories.bindGroupFactory as BindGroupFactory;
127
+ }
128
+
129
+ function getBindGroupIndicesUpToMax(bindings: AnyShaderLayout['bindings']): number[] {
130
+ const maxGroup = bindings.reduce(
131
+ (highestGroup, binding) => Math.max(highestGroup, binding.group),
132
+ -1
133
+ );
134
+ return Array.from({length: maxGroup + 1}, (_, group) => group);
135
+ }
136
+
137
+ function hasBindingsInGroup(bindings: AnyShaderLayout['bindings'], group: number): boolean {
138
+ return bindings.some(binding => binding.group === group);
139
+ }
@@ -0,0 +1,11 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {PipelineFactory} from './pipeline-factory';
6
+ import type {ShaderFactory} from './shader-factory';
7
+
8
+ export type CoreModuleState = {
9
+ defaultPipelineFactory?: PipelineFactory;
10
+ defaultShaderFactory?: ShaderFactory;
11
+ };