@luma.gl/engine 9.3.5 → 9.4.0-alpha.1

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 (181) hide show
  1. package/dist/animation/animator.d.ts +42 -0
  2. package/dist/animation/animator.d.ts.map +1 -0
  3. package/dist/animation/animator.js +53 -0
  4. package/dist/animation/animator.js.map +1 -0
  5. package/dist/animation-loop/animation-loop.d.ts +14 -2
  6. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  7. package/dist/animation-loop/animation-loop.js +40 -22
  8. package/dist/animation-loop/animation-loop.js.map +1 -1
  9. package/dist/animation-loop/animation-props.d.ts +2 -0
  10. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  11. package/dist/animation-loop/make-animation-loop.d.ts +1 -0
  12. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  13. package/dist/animation-loop/make-animation-loop.js +3 -0
  14. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  15. package/dist/application-utils/load-file.d.ts +2 -0
  16. package/dist/application-utils/load-file.d.ts.map +1 -1
  17. package/dist/application-utils/load-file.js +31 -5
  18. package/dist/application-utils/load-file.js.map +1 -1
  19. package/dist/compute/buffer-transform.d.ts +5 -1
  20. package/dist/compute/buffer-transform.d.ts.map +1 -1
  21. package/dist/compute/buffer-transform.js +7 -3
  22. package/dist/compute/buffer-transform.js.map +1 -1
  23. package/dist/compute/computation.d.ts +20 -8
  24. package/dist/compute/computation.d.ts.map +1 -1
  25. package/dist/compute/computation.js +34 -13
  26. package/dist/compute/computation.js.map +1 -1
  27. package/dist/compute/swap.d.ts.map +1 -1
  28. package/dist/compute/swap.js +17 -0
  29. package/dist/compute/swap.js.map +1 -1
  30. package/dist/dist.dev.js +4100 -1979
  31. package/dist/dist.min.js +288 -42
  32. package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
  33. package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
  34. package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
  35. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
  36. package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
  37. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  38. package/dist/dynamic-texture/dynamic-texture.js +31 -2
  39. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  40. package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
  41. package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
  42. package/dist/dynamic-texture/texture-binding-source.js +55 -0
  43. package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
  44. package/dist/dynamic-texture/texture-data.d.ts +5 -3
  45. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  46. package/dist/dynamic-texture/texture-data.js +5 -0
  47. package/dist/dynamic-texture/texture-data.js.map +1 -1
  48. package/dist/dynamic-texture/video-texture.d.ts +101 -0
  49. package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
  50. package/dist/dynamic-texture/video-texture.js +272 -0
  51. package/dist/dynamic-texture/video-texture.js.map +1 -0
  52. package/dist/geometries/cube-geometry.d.ts +1 -0
  53. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  54. package/dist/geometries/cube-geometry.js +22 -2
  55. package/dist/geometries/cube-geometry.js.map +1 -1
  56. package/dist/geometries/plane-geometry.d.ts +10 -0
  57. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  58. package/dist/geometries/plane-geometry.js.map +1 -1
  59. package/dist/geometry/geometry-utils.d.ts +36 -1
  60. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  61. package/dist/geometry/geometry-utils.js +137 -2
  62. package/dist/geometry/geometry-utils.js.map +1 -1
  63. package/dist/geometry/geometry.d.ts +52 -33
  64. package/dist/geometry/geometry.d.ts.map +1 -1
  65. package/dist/geometry/geometry.js +70 -19
  66. package/dist/geometry/geometry.js.map +1 -1
  67. package/dist/geometry/gpu-geometry.d.ts +37 -4
  68. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  69. package/dist/geometry/gpu-geometry.js +44 -36
  70. package/dist/geometry/gpu-geometry.js.map +1 -1
  71. package/dist/index.cjs +3990 -1961
  72. package/dist/index.cjs.map +4 -4
  73. package/dist/index.d.ts +20 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +8 -5
  76. package/dist/index.js.map +1 -1
  77. package/dist/material/material-factory.d.ts +2 -1
  78. package/dist/material/material-factory.d.ts.map +1 -1
  79. package/dist/material/material-factory.js.map +1 -1
  80. package/dist/material/material.d.ts +29 -10
  81. package/dist/material/material.d.ts.map +1 -1
  82. package/dist/material/material.js +84 -21
  83. package/dist/material/material.js.map +1 -1
  84. package/dist/model/model.d.ts +81 -23
  85. package/dist/model/model.d.ts.map +1 -1
  86. package/dist/model/model.js +312 -78
  87. package/dist/model/model.js.map +1 -1
  88. package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
  89. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  90. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  91. package/dist/models/billboard-texture-model.d.ts +5 -2
  92. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  93. package/dist/models/billboard-texture-model.js +28 -10
  94. package/dist/models/billboard-texture-model.js.map +1 -1
  95. package/dist/modules/picking/index-color-picking.d.ts +24 -0
  96. package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
  97. package/dist/modules/picking/index-color-picking.js +205 -0
  98. package/dist/modules/picking/index-color-picking.js.map +1 -0
  99. package/dist/modules/picking/index-picking.d.ts +3 -3
  100. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  101. package/dist/modules/picking/index-picking.js +23 -6
  102. package/dist/modules/picking/index-picking.js.map +1 -1
  103. package/dist/modules/picking/picking-manager.d.ts +21 -0
  104. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  105. package/dist/modules/picking/picking-manager.js +100 -0
  106. package/dist/modules/picking/picking-manager.js.map +1 -1
  107. package/dist/modules/picking/picking-uniforms.d.ts +4 -4
  108. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  109. package/dist/modules/picking/picking-uniforms.js +3 -0
  110. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  111. package/dist/modules/picking/picking.d.ts +5 -1
  112. package/dist/modules/picking/picking.d.ts.map +1 -1
  113. package/dist/modules/picking/picking.js +6 -0
  114. package/dist/modules/picking/picking.js.map +1 -1
  115. package/dist/passes/get-fragment-shader.js +4 -4
  116. package/dist/passes/shader-pass-renderer.d.ts +92 -25
  117. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  118. package/dist/passes/shader-pass-renderer.js +466 -72
  119. package/dist/passes/shader-pass-renderer.js.map +1 -1
  120. package/dist/passes/texture-transform-module.d.ts +10 -0
  121. package/dist/passes/texture-transform-module.d.ts.map +1 -0
  122. package/dist/passes/texture-transform-module.js +50 -0
  123. package/dist/passes/texture-transform-module.js.map +1 -0
  124. package/dist/shader-inputs.d.ts +33 -16
  125. package/dist/shader-inputs.d.ts.map +1 -1
  126. package/dist/shader-inputs.js +42 -12
  127. package/dist/shader-inputs.js.map +1 -1
  128. package/dist/utils/buffer-layout-helper.d.ts +0 -1
  129. package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
  130. package/dist/utils/buffer-layout-helper.js +2 -11
  131. package/dist/utils/buffer-layout-helper.js.map +1 -1
  132. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  133. package/dist/utils/buffer-layout-order.js +4 -15
  134. package/dist/utils/buffer-layout-order.js.map +1 -1
  135. package/dist/utils/shader-module-utils.d.ts +2 -0
  136. package/dist/utils/shader-module-utils.d.ts.map +1 -1
  137. package/dist/utils/shader-module-utils.js +64 -3
  138. package/dist/utils/shader-module-utils.js.map +1 -1
  139. package/package.json +2 -2
  140. package/src/animation/animator.ts +79 -0
  141. package/src/animation-loop/animation-loop.ts +56 -22
  142. package/src/animation-loop/animation-props.ts +2 -0
  143. package/src/animation-loop/make-animation-loop.ts +4 -0
  144. package/src/application-utils/load-file.ts +38 -5
  145. package/src/compute/buffer-transform.ts +14 -5
  146. package/src/compute/computation.ts +53 -21
  147. package/src/compute/swap.ts +19 -0
  148. package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
  149. package/src/dynamic-texture/dynamic-texture.ts +36 -3
  150. package/src/dynamic-texture/texture-binding-source.ts +94 -0
  151. package/src/dynamic-texture/texture-data.ts +12 -4
  152. package/src/dynamic-texture/video-texture.ts +334 -0
  153. package/src/geometries/cube-geometry.ts +24 -2
  154. package/src/geometries/plane-geometry.ts +10 -0
  155. package/src/geometry/geometry-utils.ts +209 -4
  156. package/src/geometry/geometry.ts +113 -36
  157. package/src/geometry/gpu-geometry.ts +61 -41
  158. package/src/index.ts +50 -14
  159. package/src/material/material-factory.ts +5 -1
  160. package/src/material/material.ts +123 -27
  161. package/src/model/model.ts +441 -102
  162. package/src/model/split-uniforms-and-bindings.ts +7 -3
  163. package/src/models/billboard-texture-model.ts +33 -12
  164. package/src/modules/picking/index-color-picking.ts +212 -0
  165. package/src/modules/picking/index-picking.ts +23 -6
  166. package/src/modules/picking/picking-manager.ts +141 -0
  167. package/src/modules/picking/picking-uniforms.ts +7 -4
  168. package/src/modules/picking/picking.ts +8 -0
  169. package/src/passes/get-fragment-shader.ts +4 -4
  170. package/src/passes/shader-pass-renderer.ts +691 -89
  171. package/src/passes/texture-transform-module.ts +52 -0
  172. package/src/shader-inputs.ts +65 -17
  173. package/src/utils/buffer-layout-helper.ts +2 -14
  174. package/src/utils/buffer-layout-order.ts +14 -24
  175. package/src/utils/shader-module-utils.ts +109 -3
  176. package/dist/geometry/gpu-table.d.ts +0 -1
  177. package/dist/geometry/gpu-table.d.ts.map +0 -1
  178. package/dist/geometry/gpu-table.js +0 -46
  179. package/dist/geometry/gpu-table.js.map +0 -1
  180. package/src/dynamic-texture/texture-data.ts.disabled +0 -296
  181. package/src/geometry/gpu-table.ts +0 -45
@@ -8,19 +8,25 @@ import {
8
8
  type RenderPipelineProps,
9
9
  type RenderPipelineParameters,
10
10
  type BufferLayout,
11
+ type TextureFormatColor,
12
+ type TextureFormatDepthStencil,
11
13
  type Shader,
12
14
  type VertexArray,
13
15
  type TransformFeedback,
16
+ type CommandEncoder,
14
17
  type AttributeInfo,
15
18
  type Binding,
16
19
  type BindingsByGroup,
20
+ type ComputeShaderLayout,
17
21
  type PrimitiveTopology,
22
+ type ShaderLayout,
23
+ type AttributeShaderType,
18
24
  Device,
19
25
  DeviceFeature,
20
26
  Buffer,
27
+ ExternalTexture,
21
28
  Texture,
22
29
  TextureView,
23
- Sampler,
24
30
  RenderPipeline,
25
31
  RenderPass,
26
32
  PipelineFactory,
@@ -32,8 +38,17 @@ import {
32
38
  normalizeBindingsByGroup
33
39
  } from '@luma.gl/core';
34
40
 
35
- import type {ShaderBindingDebugRow, ShaderModule, PlatformInfo} from '@luma.gl/shadertools';
36
- import {ShaderAssembler} from '@luma.gl/shadertools';
41
+ import type {
42
+ ShaderBindingDebugRow,
43
+ ShaderModule,
44
+ ShaderPlugin,
45
+ PlatformInfo
46
+ } from '@luma.gl/shadertools';
47
+ import {
48
+ mergeShaderPluginModules,
49
+ resolveShaderPlugins,
50
+ ShaderAssembler
51
+ } from '@luma.gl/shadertools';
37
52
 
38
53
  import type {Geometry} from '../geometry/geometry';
39
54
  import {GPUGeometry, makeGPUGeometry} from '../geometry/gpu-geometry';
@@ -43,35 +58,61 @@ import {deepEqual} from '../utils/deep-equal';
43
58
  import {BufferLayoutHelper} from '../utils/buffer-layout-helper';
44
59
  import {sortedBufferLayoutByShaderSourceLocations} from '../utils/buffer-layout-order';
45
60
  import {
61
+ mergeInferredShaderLayout,
62
+ mergeShaderModules,
46
63
  mergeShaderModuleBindingsIntoLayout,
47
64
  shaderModuleHasUniforms
48
65
  } from '../utils/shader-module-utils';
49
66
  import {uid} from '../utils/uid';
50
67
  import {ShaderInputs} from '../shader-inputs';
51
- import {DynamicTexture} from '../dynamic-texture/dynamic-texture';
68
+ import {
69
+ DynamicBuffer,
70
+ type DynamicBufferRange,
71
+ isBufferRangeBinding,
72
+ resolveBufferRangeBinding
73
+ } from '../dynamic-buffer/dynamic-buffer';
74
+ import {
75
+ getTextureBindingLayout,
76
+ isTextureBindingSource,
77
+ type TextureBindingSource
78
+ } from '../dynamic-texture/texture-binding-source';
52
79
  import {Material} from '../material/material';
53
80
 
54
81
  const LOG_DRAW_PRIORITY = 2;
55
82
  const LOG_DRAW_TIMEOUT = 10000;
56
83
  const PIPELINE_INITIALIZATION_FAILED = 'render pipeline initialization failed';
84
+ const DEPTH_STENCIL_ATTACHMENT_FORMATS: TextureFormatDepthStencil[] = [
85
+ 'stencil8',
86
+ 'depth16unorm',
87
+ 'depth24plus',
88
+ 'depth24plus-stencil8',
89
+ 'depth32float',
90
+ 'depth32float-stencil8'
91
+ ];
92
+ /** Resource accepted by one model binding slot. */
93
+ type ModelBinding = Binding | TextureBindingSource | DynamicBuffer | DynamicBufferRange;
94
+ type ModelBuffer = Buffer | DynamicBuffer;
95
+ /** Shader layout subset needed while resolving texture binding sources. */
96
+ type AnyShaderLayout = Pick<ShaderLayout | ComputeShaderLayout, 'bindings'>;
57
97
 
58
98
  export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
59
99
  source?: string;
60
100
  vs?: string | null;
61
101
  fs?: string | null;
62
102
 
63
- /** shadertool shader modules (added to shader code) */
103
+ /** Shadertools shader modules added to shader code. */
64
104
  modules?: ShaderModule[];
65
- /** Shadertool module defines (configures shader code)*/
66
- defines?: Record<string, boolean>;
67
- // TODO - injections, hooks etc?
105
+ /** Shadertools boolean or numeric preprocessor defines that configure shader code. */
106
+ defines?: Record<string, boolean | number>;
107
+ /** Reusable shader assembly plugins resolved for the active GLSL or WGSL backend. */
108
+ plugins?: ShaderPlugin[];
68
109
 
69
- /** Shader inputs, used to generated uniform buffers and bindings */
110
+ /** Shader inputs, used to generate uniform buffers and bindings. */
70
111
  shaderInputs?: ShaderInputs;
71
112
  /** Material-owned group-3 bindings */
72
113
  material?: Material;
73
- /** Bindings */
74
- bindings?: Record<string, Binding | DynamicTexture>;
114
+ /** Shader resource bindings, including dynamic buffers and dynamic textures. */
115
+ bindings?: Record<string, ModelBinding>;
75
116
  /** WebGL-only uniforms */
76
117
  uniforms?: Record<string, unknown>;
77
118
  /** Parameters that are built into the pipeline */
@@ -87,9 +128,16 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
87
128
  /** Vertex count */
88
129
  vertexCount?: number;
89
130
 
90
- indexBuffer?: Buffer | null;
91
- /** @note this is really a map of buffers, not a map of attributes */
92
- attributes?: Record<string, Buffer>;
131
+ /** Optional index buffer. Dynamic buffers are rebound when resized. */
132
+ indexBuffer?: ModelBuffer | null;
133
+ /** Optional indexed draw count. Defaults to the full bound index buffer length. */
134
+ indexCount?: number;
135
+ /** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
136
+ firstVertex?: number;
137
+ /** First index element for WebGPU indexed draws. */
138
+ firstIndex?: number;
139
+ /** Buffer-valued attributes. Dynamic buffers are rebound when resized. */
140
+ attributes?: Record<string, ModelBuffer>;
93
141
  /** */
94
142
  constantAttributes?: Record<string, TypedArray>;
95
143
 
@@ -124,7 +172,7 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
124
172
  * - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
125
173
  * - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
126
174
  * - Manages geometry attributes and buffer bindings.
127
- * - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
175
+ * - Accepts textures, samplers and uniform buffers as bindings, including texture binding sources.
128
176
  * - Provides detailed debug logging and optional shader source inspection.
129
177
  */
130
178
  export class Model {
@@ -138,8 +186,12 @@ export class Model {
138
186
  userData: {},
139
187
  defines: {},
140
188
  modules: [],
189
+ plugins: [],
141
190
  geometry: null,
142
191
  indexBuffer: null,
192
+ indexCount: undefined!,
193
+ firstVertex: 0,
194
+ firstIndex: 0,
143
195
  attributes: {},
144
196
  constantAttributes: {},
145
197
  bindings: {},
@@ -199,6 +251,12 @@ export class Model {
199
251
  instanceCount: number = 0;
200
252
  /** Vertex count */
201
253
  vertexCount: number;
254
+ /** Indexed draw count override. Undefined draws the full bound index buffer. */
255
+ indexCount: number | undefined;
256
+ /** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
257
+ firstVertex: number;
258
+ /** First index element for WebGPU indexed draws. */
259
+ firstIndex: number;
202
260
 
203
261
  /** Index buffer */
204
262
  indexBuffer: Buffer | null = null;
@@ -207,7 +265,7 @@ export class Model {
207
265
  /** Constant-valued attributes */
208
266
  constantAttributes: Record<string, TypedArray> = {};
209
267
  /** Bindings (textures, samplers, uniform buffers) */
210
- bindings: Record<string, Binding | DynamicTexture> = {};
268
+ bindings: Record<string, ModelBinding> = {};
211
269
 
212
270
  /**
213
271
  * VertexArray
@@ -232,9 +290,17 @@ export class Model {
232
290
  _attributeInfos: Record<string, AttributeInfo> = {};
233
291
  _gpuGeometry: GPUGeometry | null = null;
234
292
  private props: Required<ModelProps>;
293
+ private _dynamicIndexBufferSource: {source: DynamicBuffer; generation: number} | null = null;
294
+ private _dynamicAttributeBufferSources: Record<
295
+ number,
296
+ {source: DynamicBuffer; generation: number}
297
+ > = {};
298
+ private _colorAttachmentFormats: (TextureFormatColor | null)[] | undefined;
299
+ private _depthStencilAttachmentFormat: TextureFormatDepthStencil | undefined;
235
300
 
236
301
  _pipelineNeedsUpdate: string | false = 'newly created';
237
302
  private _needsRedraw: string | false = 'initializing';
303
+ private _drawBlockedReason: string | false = false;
238
304
  private _destroyed = false;
239
305
 
240
306
  /** "Time" of last draw. Monotonically increasing timestamp */
@@ -259,24 +325,28 @@ export class Model {
259
325
 
260
326
  this.material = props.material || null;
261
327
 
328
+ const platformInfo = getPlatformInfo(device);
329
+ const resolvedPlugins = resolveShaderPlugins(this.props.plugins, platformInfo.shaderLanguage);
330
+
262
331
  // Setup shader module inputs
263
- const moduleMap = Object.fromEntries(
264
- this.props.modules?.map(module => [module.name, module]) || []
332
+ const shaderInputModules = mergeShaderPluginModules(
333
+ this.props.modules,
334
+ resolvedPlugins.modules
265
335
  );
336
+ const moduleMap = Object.fromEntries(shaderInputModules.map(module => [module.name, module]));
266
337
 
267
338
  const shaderInputs =
268
339
  props.shaderInputs ||
269
340
  new ShaderInputs(moduleMap, {disableWarnings: this.props.disableWarnings});
341
+ if (props.shaderInputs && resolvedPlugins.modules.length > 0) {
342
+ shaderInputs.addModules(resolvedPlugins.modules);
343
+ }
270
344
  // @ts-ignore
271
345
  this.setShaderInputs(shaderInputs);
272
346
 
273
347
  // Setup shader assembler
274
- const platformInfo = getPlatformInfo(device);
275
-
276
- // Extract modules from shader inputs if not supplied
277
- const modules =
278
- // @ts-ignore shaderInputs is assigned in setShaderInputs above.
279
- (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
348
+ const modules = mergeShaderModules(this.props.modules, shaderInputs.getModules());
349
+ const defines = {...resolvedPlugins.defines, ...this.props.defines};
280
350
 
281
351
  this.props.shaderLayout =
282
352
  mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
@@ -291,27 +361,41 @@ export class Model {
291
361
  const {source, getUniforms, bindingTable} = this.props.shaderAssembler.assembleWGSLShader({
292
362
  platformInfo,
293
363
  ...this.props,
294
- modules
364
+ modules,
365
+ defines,
366
+ pluginInjections: resolvedPlugins.injections,
367
+ pluginVertexInputs: resolvedPlugins.vertexInputs,
368
+ pluginVaryings: resolvedPlugins.varyings
295
369
  });
296
370
  this.source = source;
297
371
  // @ts-expect-error
298
372
  this._getModuleUniforms = getUniforms;
299
373
  this._bindingTable = bindingTable;
300
374
  // Extract shader layout after modules have been added to WGSL source, to include any bindings added by modules
301
- const inferredShaderLayout = (
375
+ const reflectedShaderLayout = (
302
376
  device as Device & {getShaderLayout?: (source: string) => any}
303
377
  ).getShaderLayout?.(this.source);
378
+ const inferredShaderLayout = normalizeShaderPluginAttributeNames(
379
+ reflectedShaderLayout,
380
+ resolvedPlugins.vertexInputs
381
+ );
382
+ const shaderLayout = mergeInferredShaderLayout(
383
+ this.props.shaderLayout,
384
+ inferredShaderLayout,
385
+ Object.keys(resolvedPlugins.vertexInputs)
386
+ );
304
387
  this.props.shaderLayout =
305
- mergeShaderModuleBindingsIntoLayout(
306
- this.props.shaderLayout || inferredShaderLayout || null,
307
- modules
308
- ) || null;
388
+ mergeShaderModuleBindingsIntoLayout(shaderLayout || null, modules) || null;
309
389
  } else {
310
390
  // GLSL
311
391
  const {vs, fs, getUniforms} = this.props.shaderAssembler.assembleGLSLShaderPair({
312
392
  platformInfo,
313
393
  ...this.props,
314
- modules
394
+ modules,
395
+ defines,
396
+ pluginInjections: resolvedPlugins.injections,
397
+ pluginVertexInputs: resolvedPlugins.vertexInputs,
398
+ pluginVaryings: resolvedPlugins.varyings
315
399
  });
316
400
 
317
401
  this.vs = vs;
@@ -322,11 +406,19 @@ export class Model {
322
406
  }
323
407
 
324
408
  this.vertexCount = this.props.vertexCount;
409
+ this.indexCount = this.props.indexCount;
410
+ this.firstVertex = this.props.firstVertex;
411
+ this.firstIndex = this.props.firstIndex;
325
412
  this.instanceCount = this.props.instanceCount;
326
413
 
327
414
  this.topology = this.props.topology;
328
415
  this.bufferLayout = this.props.bufferLayout;
329
416
  this.parameters = this.props.parameters;
417
+ // Seed attachment formats before creating the initial WebGPU pipeline. This is required for
418
+ // depth-only models whose intentional empty color target list must not fall back to the canvas
419
+ // format before the first render pass can synchronize attachment state.
420
+ this._colorAttachmentFormats = this.props.colorAttachmentFormats;
421
+ this._depthStencilAttachmentFormat = this.props.depthStencilAttachmentFormat;
330
422
 
331
423
  // Geometry, if provided, sets topology and vertex cound
332
424
  if (props.geometry) {
@@ -418,10 +510,17 @@ export class Model {
418
510
  return this._bindingTable;
419
511
  }
420
512
 
421
- /** Update uniforms and pipeline state prior to drawing. */
422
- predraw(): void {
513
+ /**
514
+ * Updates uniforms and pipeline state before opening a render pass.
515
+ *
516
+ * @param commandEncoder - Encoder that should own any GPU uploads emitted
517
+ * during draw preparation.
518
+ */
519
+ predraw(commandEncoder: CommandEncoder): void {
423
520
  // Update uniform buffers if needed
424
- this.updateShaderInputs();
521
+ this._syncDynamicBuffers();
522
+ this.updateShaderInputs(commandEncoder);
523
+ this.material?.updateShaderInputs(commandEncoder);
425
524
  // Check if the pipeline is invalidated
426
525
  this.pipeline = this._updatePipeline();
427
526
  }
@@ -432,15 +531,34 @@ export class Model {
432
531
  * @returns `true` if the draw call was executed, `false` if resources were not ready.
433
532
  */
434
533
  draw(renderPass: RenderPass): boolean {
534
+ if (this._drawBlockedReason && !this._pipelineNeedsUpdate) {
535
+ log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)();
536
+ return false;
537
+ }
538
+
435
539
  const loadingBinding = this._areBindingsLoading();
436
540
  if (loadingBinding) {
437
541
  log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${loadingBinding} not loaded`)();
438
542
  return false;
439
543
  }
440
544
 
545
+ this._syncAttachmentFormats(renderPass);
546
+
441
547
  try {
442
548
  renderPass.pushDebugGroup(`${this}.predraw(${renderPass})`);
443
- this.predraw();
549
+ if (this.device.type === 'webgpu') {
550
+ // WebGPU uploads cannot be encoded once the render pass is already open.
551
+ // Keep the implicit draw() path working for existing callers by falling
552
+ // back to immediate writes here; callers that need upload ordering
553
+ // across multiple draws/viewports must call predraw(commandEncoder)
554
+ // before beginRenderPass().
555
+ this.updateShaderInputs();
556
+ this.material?.updateShaderInputs();
557
+ this._syncDynamicBuffers();
558
+ this.pipeline = this._updatePipeline();
559
+ } else {
560
+ this.predraw(this.device.commandEncoder);
561
+ }
444
562
  } finally {
445
563
  renderPass.popDebugGroup();
446
564
  }
@@ -464,35 +582,45 @@ export class Model {
464
582
  )();
465
583
  drawSuccess = false;
466
584
  } else {
467
- const syncBindings = this._getBindings();
468
- const syncBindGroups = this._getBindGroups();
469
-
470
- const {indexBuffer} = this.vertexArray;
471
- const indexCount = indexBuffer
472
- ? indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)
473
- : undefined;
474
-
475
- drawSuccess = this.pipeline.draw({
476
- renderPass,
477
- vertexArray: this.vertexArray,
478
- isInstanced: this.isInstanced,
479
- vertexCount: this.vertexCount,
480
- instanceCount: this.instanceCount,
481
- indexCount,
482
- transformFeedback: this.transformFeedback || undefined,
483
- // Pipelines may be shared across models when caching is enabled, so bindings
484
- // and WebGL uniforms must be supplied on every draw instead of being stored
485
- // on the pipeline instance.
486
- bindings: syncBindings,
487
- bindGroups: syncBindGroups,
488
- _bindGroupCacheKeys: this._getBindGroupCacheKeys(),
489
- uniforms: this.props.uniforms,
490
- // WebGL shares underlying cached pipelines even for models that have different parameters and topology,
491
- // so we must provide our unique parameters to each draw
492
- // (In WebGPU most parameters are encoded in the pipeline and cannot be changed per draw call)
493
- parameters: this.parameters,
494
- topology: this.topology
495
- });
585
+ const drawValidationError = this.vertexArray.getDrawValidationError();
586
+ if (drawValidationError) {
587
+ log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${drawValidationError}`)();
588
+ this._drawBlockedReason = drawValidationError;
589
+ drawSuccess = false;
590
+ } else {
591
+ const shaderLayout = this._getCurrentShaderLayout();
592
+ const syncBindings = this._getBindings(shaderLayout);
593
+ const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
594
+
595
+ const {indexBuffer} = this.vertexArray;
596
+ const indexCount = indexBuffer
597
+ ? (this.indexCount ??
598
+ indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2))
599
+ : undefined;
600
+
601
+ renderPass.setPipeline(this.pipeline);
602
+ renderPass.setBindings(syncBindGroups, {
603
+ _bindGroupCacheKeys: this._getBindGroupCacheKeys()
604
+ });
605
+ renderPass.setVertexArray(this.vertexArray);
606
+ const hasNoInstances = this.isInstanced === true && this.instanceCount === 0;
607
+ drawSuccess = hasNoInstances
608
+ ? true
609
+ : renderPass.draw({
610
+ isInstanced: this.isInstanced,
611
+ vertexCount: this.vertexCount,
612
+ instanceCount: this.isInstanced ? this.instanceCount : undefined,
613
+ indexCount,
614
+ firstVertex: this.firstVertex,
615
+ firstIndex: this.firstIndex,
616
+ transformFeedback: this.transformFeedback || undefined,
617
+ uniforms: this.props.uniforms,
618
+ // WebGL shares underlying cached programs even for models that have different
619
+ // parameters and topology, so those compatibility overrides remain per draw.
620
+ parameters: this.parameters,
621
+ topology: this.topology
622
+ });
623
+ }
496
624
  }
497
625
  } finally {
498
626
  renderPass.popDebugGroup();
@@ -506,6 +634,9 @@ export class Model {
506
634
  this._needsRedraw = false;
507
635
  } else if (pipelineErrored) {
508
636
  this._needsRedraw = PIPELINE_INITIALIZATION_FAILED;
637
+ this._drawBlockedReason = PIPELINE_INITIALIZATION_FAILED;
638
+ } else if (this._drawBlockedReason) {
639
+ this._needsRedraw = this._drawBlockedReason;
509
640
  } else {
510
641
  this._needsRedraw = 'waiting for resource initialization';
511
642
  }
@@ -553,9 +684,14 @@ export class Model {
553
684
  */
554
685
  setBufferLayout(bufferLayout: BufferLayout[]): void {
555
686
  const bufferLayoutHelper = new BufferLayoutHelper(this.bufferLayout);
556
- this.bufferLayout = this._gpuGeometry
687
+ const nextBufferLayout = this._gpuGeometry
557
688
  ? bufferLayoutHelper.mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout)
558
689
  : bufferLayout;
690
+ if (deepEqual(nextBufferLayout, this.bufferLayout, -1)) {
691
+ return;
692
+ }
693
+
694
+ this.bufferLayout = nextBufferLayout;
559
695
  this._setPipelineNeedsUpdate('bufferLayout');
560
696
 
561
697
  // Recreate the pipeline
@@ -611,6 +747,19 @@ export class Model {
611
747
  this.setNeedsRedraw('vertexCount');
612
748
  }
613
749
 
750
+ /** Updates the indexed draw count override. */
751
+ setIndexCount(indexCount: number | undefined): void {
752
+ this.indexCount = indexCount;
753
+ this.setNeedsRedraw('indexCount');
754
+ }
755
+
756
+ /** Updates the first indexed/non-indexed draw offsets. */
757
+ setDrawOffsets({firstVertex, firstIndex}: {firstVertex: number; firstIndex: number}): void {
758
+ this.firstVertex = firstVertex;
759
+ this.firstIndex = firstIndex;
760
+ this.setNeedsRedraw('drawOffsets');
761
+ }
762
+
614
763
  /** Set the shader inputs */
615
764
  setShaderInputs(shaderInputs: ShaderInputs): void {
616
765
  this.shaderInputs = shaderInputs;
@@ -631,8 +780,15 @@ export class Model {
631
780
  }
632
781
 
633
782
  /** Update uniform buffers from the model's shader inputs */
634
- updateShaderInputs(): void {
635
- this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
783
+ /**
784
+ * Flushes current shader-input values into managed uniform buffers and
785
+ * non-material bindings.
786
+ *
787
+ * @param commandEncoder - Optional encoder used to order uniform uploads with
788
+ * subsequent draw commands.
789
+ */
790
+ updateShaderInputs(commandEncoder?: CommandEncoder): void {
791
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(), commandEncoder);
636
792
  this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues()));
637
793
  // TODO - this is already tracked through buffer/texture update times?
638
794
  this.setNeedsRedraw('shaderInputs');
@@ -641,7 +797,7 @@ export class Model {
641
797
  /**
642
798
  * Sets bindings (textures, samplers, uniform buffers)
643
799
  */
644
- setBindings(bindings: Record<string, Binding | DynamicTexture>): void {
800
+ setBindings(bindings: Record<string, ModelBinding>): void {
645
801
  Object.assign(this.bindings, bindings);
646
802
  this.setNeedsRedraw('bindings');
647
803
  }
@@ -658,8 +814,15 @@ export class Model {
658
814
  * Sets the index buffer
659
815
  * @todo - how to unset it if we change geometry?
660
816
  */
661
- setIndexBuffer(indexBuffer: Buffer | null): void {
662
- this.vertexArray.setIndexBuffer(indexBuffer);
817
+ setIndexBuffer(indexBuffer: ModelBuffer | null): void {
818
+ const resolvedIndexBuffer =
819
+ indexBuffer instanceof DynamicBuffer ? indexBuffer.buffer : indexBuffer;
820
+ this.indexBuffer = resolvedIndexBuffer;
821
+ this._dynamicIndexBufferSource =
822
+ indexBuffer instanceof DynamicBuffer
823
+ ? {source: indexBuffer, generation: indexBuffer.generation}
824
+ : null;
825
+ this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
663
826
  this.setNeedsRedraw('indexBuffer');
664
827
  }
665
828
 
@@ -667,7 +830,8 @@ export class Model {
667
830
  * Sets attributes (buffers)
668
831
  * @note Overrides any attributes previously set with the same name
669
832
  */
670
- setAttributes(buffers: Record<string, Buffer>, options?: {disableWarnings?: boolean}): void {
833
+ setAttributes(buffers: Record<string, ModelBuffer>, options?: {disableWarnings?: boolean}): void {
834
+ this._drawBlockedReason = false;
671
835
  const disableWarnings = options?.disableWarnings ?? this.props.disableWarnings;
672
836
  if (buffers['indices']) {
673
837
  log.warn(
@@ -685,6 +849,7 @@ export class Model {
685
849
 
686
850
  // Check if all buffers have a layout
687
851
  for (const [bufferName, buffer] of Object.entries(buffers)) {
852
+ const resolvedBuffer = buffer instanceof DynamicBuffer ? buffer.buffer : buffer;
688
853
  const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
689
854
  if (!bufferLayout) {
690
855
  if (!disableWarnings) {
@@ -700,18 +865,34 @@ export class Model {
700
865
  for (const attributeName of attributeNames) {
701
866
  const attributeInfo = this._attributeInfos[attributeName];
702
867
  if (attributeInfo) {
703
- const location =
868
+ const bufferSlot =
704
869
  this.device.type === 'webgpu'
705
- ? bufferLayoutHelper.getBufferIndex(attributeInfo.bufferName)
870
+ ? this.vertexArray.getBufferSlot(attributeInfo.bufferName)
706
871
  : attributeInfo.location;
707
-
708
- this.vertexArray.setBuffer(location, buffer);
872
+ if (bufferSlot === null) {
873
+ if (!disableWarnings) {
874
+ log.warn(
875
+ `Model(${this.id}): Missing vertex array slot for buffer "${attributeInfo.bufferName}".`
876
+ )();
877
+ }
878
+ continue; // eslint-disable-line no-continue
879
+ }
880
+
881
+ this.vertexArray.setBuffer(bufferSlot, resolvedBuffer);
882
+ if (buffer instanceof DynamicBuffer) {
883
+ this._dynamicAttributeBufferSources[bufferSlot] = {
884
+ source: buffer,
885
+ generation: buffer.generation
886
+ };
887
+ } else {
888
+ delete this._dynamicAttributeBufferSources[bufferSlot];
889
+ }
709
890
  set = true;
710
891
  }
711
892
  }
712
893
  if (!set && !disableWarnings) {
713
894
  log.warn(
714
- `Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`
895
+ `Model(${this.id}): Ignoring buffer "${resolvedBuffer.id}" for unknown attribute "${bufferName}"`
715
896
  )();
716
897
  }
717
898
  }
@@ -748,47 +929,57 @@ export class Model {
748
929
  /** Check that bindings are loaded. Returns id of first binding that is still loading. */
749
930
  _areBindingsLoading(): string | false {
750
931
  for (const binding of Object.values(this.bindings)) {
751
- if (binding instanceof DynamicTexture && !binding.isReady) {
932
+ if (isTextureBindingSource(binding) && !binding.isReady) {
752
933
  return binding.id;
753
934
  }
754
935
  }
755
936
  for (const binding of Object.values(this.material?.bindings || {})) {
756
- if (binding instanceof DynamicTexture && !binding.isReady) {
937
+ if (isTextureBindingSource(binding) && !binding.isReady) {
757
938
  return binding.id;
758
939
  }
759
940
  }
760
941
  return false;
761
942
  }
762
943
 
763
- /** Extracts texture view from loaded async textures. Returns null if any textures have not yet been loaded. */
764
- _getBindings(): Record<string, Binding> {
944
+ /**
945
+ * Resolves ready model bindings for the current shader layout.
946
+ * @param shaderLayout Reflected bindings used to select copied or external texture resolution.
947
+ */
948
+ _getBindings(
949
+ shaderLayout: AnyShaderLayout = this._getCurrentShaderLayout()
950
+ ): Record<string, Binding> {
765
951
  const validBindings: Record<string, Binding> = {};
766
952
 
767
953
  for (const [name, binding] of Object.entries(this.bindings)) {
768
- if (binding instanceof DynamicTexture) {
769
- // Check that async textures are loaded
770
- if (binding.isReady) {
771
- validBindings[name] = binding.texture;
772
- }
773
- } else {
774
- validBindings[name] = binding;
954
+ const resolvedBinding = resolveModelBinding(name, binding, shaderLayout);
955
+ if (resolvedBinding) {
956
+ validBindings[name] = resolvedBinding;
775
957
  }
776
958
  }
777
959
 
778
960
  return validBindings;
779
961
  }
780
962
 
781
- _getBindGroups(): BindingsByGroup {
782
- const shaderLayout = this.pipeline?.shaderLayout || this.props.shaderLayout || {bindings: []};
963
+ /**
964
+ * Groups resolved model and material bindings for the current shader layout.
965
+ * @param shaderLayout Reflected bindings used to group logical binding names.
966
+ * @param bindings Model bindings already resolved for this draw preparation.
967
+ */
968
+ _getBindGroups(
969
+ shaderLayout: AnyShaderLayout = this._getCurrentShaderLayout(),
970
+ bindings: Record<string, Binding> = this._getBindings(shaderLayout)
971
+ ): BindingsByGroup {
783
972
  const bindGroups = shaderLayout.bindings.length
784
- ? normalizeBindingsByGroup(shaderLayout, this._getBindings())
785
- : {0: this._getBindings()};
973
+ ? normalizeBindingsByGroup(shaderLayout, bindings)
974
+ : {0: bindings};
786
975
 
787
976
  if (!this.material) {
788
977
  return bindGroups;
789
978
  }
790
979
 
791
- for (const [groupKey, groupBindings] of Object.entries(this.material.getBindingsByGroup())) {
980
+ for (const [groupKey, groupBindings] of Object.entries(
981
+ this.material.getBindingsByGroup(shaderLayout)
982
+ )) {
792
983
  const group = Number(groupKey);
793
984
  bindGroups[group] = {
794
985
  ...(bindGroups[group] || {}),
@@ -807,18 +998,35 @@ export class Model {
807
998
  /** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
808
999
  _getBindingsUpdateTimestamp(): number {
809
1000
  let timestamp = 0;
1001
+ if (this._dynamicIndexBufferSource) {
1002
+ timestamp = Math.max(timestamp, this._dynamicIndexBufferSource.source.updateTimestamp);
1003
+ }
1004
+ for (const entry of Object.values(this._dynamicAttributeBufferSources)) {
1005
+ timestamp = Math.max(timestamp, entry.source.updateTimestamp);
1006
+ }
810
1007
  for (const binding of Object.values(this.bindings)) {
811
1008
  if (binding instanceof TextureView) {
812
1009
  timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
813
- } else if (binding instanceof Buffer || binding instanceof Texture) {
1010
+ } else if (
1011
+ binding instanceof Buffer ||
1012
+ binding instanceof Texture ||
1013
+ binding instanceof ExternalTexture
1014
+ ) {
814
1015
  timestamp = Math.max(timestamp, binding.updateTimestamp);
815
- } else if (binding instanceof DynamicTexture) {
816
- timestamp = binding.texture
817
- ? Math.max(timestamp, binding.texture.updateTimestamp)
1016
+ } else if (binding instanceof DynamicBuffer) {
1017
+ timestamp = Math.max(timestamp, binding.updateTimestamp);
1018
+ } else if (isTextureBindingSource(binding)) {
1019
+ timestamp = binding.isReady
1020
+ ? Math.max(timestamp, binding.updateTimestamp)
818
1021
  : // The texture will become available in the future
819
1022
  Infinity;
820
- } else if (!(binding instanceof Sampler)) {
821
- timestamp = Math.max(timestamp, binding.buffer.updateTimestamp);
1023
+ } else if (isBufferRangeBinding(binding)) {
1024
+ timestamp = Math.max(
1025
+ timestamp,
1026
+ binding.buffer instanceof DynamicBuffer
1027
+ ? binding.buffer.updateTimestamp
1028
+ : binding.buffer.updateTimestamp
1029
+ );
822
1030
  }
823
1031
  }
824
1032
  return Math.max(timestamp, this.material?.getBindingsUpdateTimestamp() || 0);
@@ -853,6 +1061,7 @@ export class Model {
853
1061
  /** Mark pipeline as needing update */
854
1062
  _setPipelineNeedsUpdate(reason: string): void {
855
1063
  this._pipelineNeedsUpdate ||= reason;
1064
+ this._drawBlockedReason = false;
856
1065
  this.setNeedsRedraw(reason);
857
1066
  }
858
1067
 
@@ -895,9 +1104,11 @@ export class Model {
895
1104
  ...this.props,
896
1105
  bindings: undefined,
897
1106
  bufferLayout: this.bufferLayout,
1107
+ colorAttachmentFormats: this._colorAttachmentFormats,
1108
+ depthStencilAttachmentFormat: this._depthStencilAttachmentFormat,
898
1109
  topology: this.topology,
899
1110
  parameters: this.parameters,
900
- bindGroups: this._getBindGroups(),
1111
+ bindGroups: undefined,
901
1112
  vs,
902
1113
  fs
903
1114
  });
@@ -1004,13 +1215,13 @@ export class Model {
1004
1215
  }
1005
1216
 
1006
1217
  private _getNonMaterialBindings(
1007
- bindings: Record<string, Binding | DynamicTexture>
1008
- ): Record<string, Binding | DynamicTexture> {
1218
+ bindings: Record<string, ModelBinding>
1219
+ ): Record<string, ModelBinding> {
1009
1220
  if (!this.material) {
1010
1221
  return bindings;
1011
1222
  }
1012
1223
 
1013
- const filteredBindings: Record<string, Binding | DynamicTexture> = {};
1224
+ const filteredBindings: Record<string, ModelBinding> = {};
1014
1225
  for (const [name, binding] of Object.entries(bindings)) {
1015
1226
  if (!this.material.ownsBinding(name)) {
1016
1227
  filteredBindings[name] = binding;
@@ -1018,10 +1229,137 @@ export class Model {
1018
1229
  }
1019
1230
  return filteredBindings;
1020
1231
  }
1232
+
1233
+ /** Returns the current reflected shader layout or the pre-reflection empty layout. */
1234
+ private _getCurrentShaderLayout(): AnyShaderLayout {
1235
+ return this.pipeline?.shaderLayout || this.props.shaderLayout || {bindings: []};
1236
+ }
1237
+
1238
+ private _syncDynamicBuffers(): void {
1239
+ if (
1240
+ this._dynamicIndexBufferSource &&
1241
+ this._dynamicIndexBufferSource.generation !== this._dynamicIndexBufferSource.source.generation
1242
+ ) {
1243
+ const resolvedIndexBuffer = this._dynamicIndexBufferSource.source.buffer;
1244
+ this.indexBuffer = resolvedIndexBuffer;
1245
+ this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
1246
+ this._dynamicIndexBufferSource.generation = this._dynamicIndexBufferSource.source.generation;
1247
+ this.setNeedsRedraw('dynamic index buffer');
1248
+ }
1249
+
1250
+ for (const [locationKey, entry] of Object.entries(this._dynamicAttributeBufferSources)) {
1251
+ if (entry.generation !== entry.source.generation) {
1252
+ this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer);
1253
+ entry.generation = entry.source.generation;
1254
+ this.setNeedsRedraw('dynamic attribute buffer');
1255
+ }
1256
+ }
1257
+ }
1258
+ private _syncAttachmentFormats(renderPass: RenderPass): void {
1259
+ if (this.device.type !== 'webgpu') {
1260
+ return;
1261
+ }
1262
+
1263
+ const framebuffer =
1264
+ (
1265
+ renderPass as RenderPass & {
1266
+ framebuffer?: {
1267
+ colorAttachments?: Array<{texture?: {format?: TextureFormatColor}} | null>;
1268
+ depthStencilAttachment?: {texture?: {format?: TextureFormatDepthStencil}} | null;
1269
+ };
1270
+ }
1271
+ ).framebuffer || renderPass.props.framebuffer;
1272
+ const renderBundleProps = renderPass.props as RenderPass['props'] & {
1273
+ colorAttachmentFormats?: (TextureFormatColor | null)[];
1274
+ depthStencilAttachmentFormat?: TextureFormatDepthStencil | false;
1275
+ };
1276
+
1277
+ const nextColorAttachmentFormats =
1278
+ renderBundleProps.colorAttachmentFormats ??
1279
+ framebuffer?.colorAttachments?.map(colorAttachment =>
1280
+ asColorAttachmentFormat(colorAttachment?.texture?.format)
1281
+ );
1282
+ const nextDepthStencilAttachmentFormat =
1283
+ renderBundleProps.depthStencilAttachmentFormat === false
1284
+ ? undefined
1285
+ : (renderBundleProps.depthStencilAttachmentFormat ??
1286
+ asDepthStencilAttachmentFormat(framebuffer?.depthStencilAttachment?.texture?.format));
1287
+
1288
+ if (
1289
+ !deepEqual(this._colorAttachmentFormats, nextColorAttachmentFormats, 1) ||
1290
+ this._depthStencilAttachmentFormat !== nextDepthStencilAttachmentFormat
1291
+ ) {
1292
+ this._colorAttachmentFormats = nextColorAttachmentFormats;
1293
+ this._depthStencilAttachmentFormat = nextDepthStencilAttachmentFormat;
1294
+ this._setPipelineNeedsUpdate('attachment formats');
1295
+ }
1296
+ }
1021
1297
  }
1022
1298
 
1023
1299
  // HELPERS
1024
1300
 
1301
+ function normalizeShaderPluginAttributeNames(
1302
+ shaderLayout: ShaderLayout | null | undefined,
1303
+ vertexInputs: Record<string, AttributeShaderType>
1304
+ ): ShaderLayout | null | undefined {
1305
+ if (!shaderLayout || Object.keys(vertexInputs).length === 0) {
1306
+ return shaderLayout;
1307
+ }
1308
+
1309
+ return {
1310
+ ...shaderLayout,
1311
+ attributes: shaderLayout.attributes.map(attribute => {
1312
+ const publicName = attribute.name.startsWith('_luma_')
1313
+ ? attribute.name.slice('_luma_'.length)
1314
+ : null;
1315
+ return publicName && vertexInputs[publicName] ? {...attribute, name: publicName} : attribute;
1316
+ })
1317
+ };
1318
+ }
1319
+
1320
+ /**
1321
+ * Resolves one model binding against the current shader layout.
1322
+ * @param bindingName Logical model binding name.
1323
+ * @param binding Model binding or deferred engine binding source.
1324
+ * @param shaderLayout Reflected bindings used to select copied or external texture resolution.
1325
+ * @returns Concrete core binding, or `null` while a deferred source is unavailable.
1326
+ */
1327
+ function resolveModelBinding(
1328
+ bindingName: string,
1329
+ binding: ModelBinding,
1330
+ shaderLayout: AnyShaderLayout
1331
+ ): Binding | null {
1332
+ if (isTextureBindingSource(binding)) {
1333
+ const bindingLayout = getTextureBindingLayout(shaderLayout, bindingName, {
1334
+ fallbackGroup: 0
1335
+ });
1336
+ return bindingLayout ? binding.resolveTextureBinding(bindingLayout) : null;
1337
+ }
1338
+
1339
+ if (binding instanceof DynamicBuffer) {
1340
+ return binding.buffer;
1341
+ }
1342
+
1343
+ if (isBufferRangeBinding(binding)) {
1344
+ return resolveBufferRangeBinding(binding);
1345
+ }
1346
+
1347
+ return binding;
1348
+ }
1349
+ function asColorAttachmentFormat(format?: string | null): TextureFormatColor | null {
1350
+ return format && !isDepthStencilAttachmentFormat(format) ? (format as TextureFormatColor) : null;
1351
+ }
1352
+
1353
+ function asDepthStencilAttachmentFormat(
1354
+ format?: string | null
1355
+ ): TextureFormatDepthStencil | undefined {
1356
+ return format && isDepthStencilAttachmentFormat(format) ? format : undefined;
1357
+ }
1358
+
1359
+ function isDepthStencilAttachmentFormat(format: string): format is TextureFormatDepthStencil {
1360
+ return DEPTH_STENCIL_ATTACHMENT_FORMATS.includes(format as TextureFormatDepthStencil);
1361
+ }
1362
+
1025
1363
  /** Create a shadertools platform info from the Device */
1026
1364
  export function getPlatformInfo(device: Device): PlatformInfo {
1027
1365
  return {
@@ -1029,6 +1367,7 @@ export function getPlatformInfo(device: Device): PlatformInfo {
1029
1367
  shaderLanguage: device.info.shadingLanguage,
1030
1368
  shaderLanguageVersion: device.info.shadingLanguageVersion as 100 | 300,
1031
1369
  gpu: device.info.gpu,
1370
+ limits: device.limits as unknown as Record<string, number | undefined>,
1032
1371
  // HACK - we pretend that the DeviceFeatures is a Set, it has a similar API
1033
1372
  features: device.features as unknown as Set<DeviceFeature>
1034
1373
  };