@luma.gl/engine 9.3.6 → 9.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animator.d.ts +42 -0
- package/dist/animation/animator.d.ts.map +1 -0
- package/dist/animation/animator.js +53 -0
- package/dist/animation/animator.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +14 -2
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +40 -22
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +2 -0
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/application-utils/load-file.d.ts +2 -0
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +31 -5
- package/dist/application-utils/load-file.js.map +1 -1
- package/dist/compute/buffer-transform.d.ts +5 -1
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +7 -3
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.d.ts +20 -8
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +34 -13
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +17 -0
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +4190 -2014
- package/dist/dist.min.js +288 -42
- package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
- package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
- package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +31 -2
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
- package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-binding-source.js +55 -0
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +5 -3
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +5 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.d.ts +101 -0
- package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/video-texture.js +272 -0
- package/dist/dynamic-texture/video-texture.js.map +1 -0
- package/dist/geometries/cube-geometry.d.ts +1 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +22 -2
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +10 -0
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts +36 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +137 -2
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +52 -33
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +70 -19
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -4
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +44 -36
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +4045 -1975
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +22 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +2 -1
- package/dist/material/material-factory.d.ts.map +1 -1
- package/dist/material/material-factory.js.map +1 -1
- package/dist/material/material.d.ts +29 -10
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +84 -21
- package/dist/material/material.js.map +1 -1
- package/dist/model/model.d.ts +81 -23
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +312 -78
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +5 -2
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +28 -10
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/modules/picking/index-color-picking.d.ts +24 -0
- package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-color-picking.js +205 -0
- package/dist/modules/picking/index-color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +3 -3
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +23 -6
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/picking-manager.d.ts +21 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +100 -0
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +4 -4
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +3 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +5 -1
- package/dist/modules/picking/picking.d.ts.map +1 -1
- package/dist/modules/picking/picking.js +6 -0
- package/dist/modules/picking/picking.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +4 -4
- package/dist/passes/shader-pass-renderer.d.ts +92 -25
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +467 -72
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.d.ts +10 -0
- package/dist/passes/texture-transform-module.d.ts.map +1 -0
- package/dist/passes/texture-transform-module.js +50 -0
- package/dist/passes/texture-transform-module.js.map +1 -0
- package/dist/scenegraph/group-node.d.ts +17 -1
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +29 -23
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.d.ts +8 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js +15 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-bounds.d.ts +7 -0
- package/dist/scenegraph/scenegraph-bounds.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-bounds.js +25 -0
- package/dist/scenegraph/scenegraph-bounds.js.map +1 -0
- package/dist/shader-inputs.d.ts +33 -16
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +42 -12
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/buffer-layout-helper.d.ts +0 -1
- package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
- package/dist/utils/buffer-layout-helper.js +2 -11
- package/dist/utils/buffer-layout-helper.js.map +1 -1
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +4 -15
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +2 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -1
- package/dist/utils/shader-module-utils.js +64 -3
- package/dist/utils/shader-module-utils.js.map +1 -1
- package/package.json +4 -4
- package/src/animation/animator.ts +79 -0
- package/src/animation-loop/animation-loop.ts +56 -22
- package/src/animation-loop/animation-props.ts +2 -0
- package/src/animation-loop/make-animation-loop.ts +4 -0
- package/src/application-utils/load-file.ts +38 -5
- package/src/compute/buffer-transform.ts +14 -5
- package/src/compute/computation.ts +53 -21
- package/src/compute/swap.ts +19 -0
- package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
- package/src/dynamic-texture/dynamic-texture.ts +36 -3
- package/src/dynamic-texture/texture-binding-source.ts +94 -0
- package/src/dynamic-texture/texture-data.ts +12 -4
- package/src/dynamic-texture/video-texture.ts +334 -0
- package/src/geometries/cube-geometry.ts +24 -2
- package/src/geometries/plane-geometry.ts +10 -0
- package/src/geometry/geometry-utils.ts +209 -4
- package/src/geometry/geometry.ts +113 -36
- package/src/geometry/gpu-geometry.ts +61 -41
- package/src/index.ts +56 -14
- package/src/material/material-factory.ts +5 -1
- package/src/material/material.ts +123 -27
- package/src/model/model.ts +441 -102
- package/src/model/split-uniforms-and-bindings.ts +7 -3
- package/src/models/billboard-texture-model.ts +33 -12
- package/src/modules/picking/index-color-picking.ts +212 -0
- package/src/modules/picking/index-picking.ts +23 -6
- package/src/modules/picking/picking-manager.ts +141 -0
- package/src/modules/picking/picking-uniforms.ts +7 -4
- package/src/modules/picking/picking.ts +8 -0
- package/src/passes/get-fragment-shader.ts +4 -4
- package/src/passes/shader-pass-renderer.ts +692 -89
- package/src/passes/texture-transform-module.ts +52 -0
- package/src/scenegraph/group-node.ts +63 -26
- package/src/scenegraph/model-node.ts +32 -3
- package/src/scenegraph/scenegraph-bounds.ts +48 -0
- package/src/shader-inputs.ts +65 -17
- package/src/utils/buffer-layout-helper.ts +2 -14
- package/src/utils/buffer-layout-order.ts +14 -24
- package/src/utils/shader-module-utils.ts +109 -3
- package/dist/geometry/gpu-table.d.ts +0 -1
- package/dist/geometry/gpu-table.d.ts.map +0 -1
- package/dist/geometry/gpu-table.js +0 -46
- package/dist/geometry/gpu-table.js.map +0 -1
- package/src/dynamic-texture/texture-data.ts.disabled +0 -296
- package/src/geometry/gpu-table.ts +0 -45
package/dist/model/model.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { Buffer, Texture, TextureView,
|
|
5
|
-
import { ShaderAssembler } from '@luma.gl/shadertools';
|
|
4
|
+
import { Buffer, ExternalTexture, Texture, TextureView, RenderPipeline, PipelineFactory, ShaderFactory, UniformStore, log, dataTypeDecoder, getAttributeInfosFromLayouts, normalizeBindingsByGroup } from '@luma.gl/core';
|
|
5
|
+
import { mergeShaderPluginModules, resolveShaderPlugins, ShaderAssembler } from '@luma.gl/shadertools';
|
|
6
6
|
import { makeGPUGeometry } from "../geometry/gpu-geometry.js";
|
|
7
7
|
import { getDebugTableForShaderLayout } from "../debug/debug-shader-layout.js";
|
|
8
8
|
import { debugFramebuffer } from "../debug/debug-framebuffer.js";
|
|
9
9
|
import { deepEqual } from "../utils/deep-equal.js";
|
|
10
10
|
import { BufferLayoutHelper } from "../utils/buffer-layout-helper.js";
|
|
11
11
|
import { sortedBufferLayoutByShaderSourceLocations } from "../utils/buffer-layout-order.js";
|
|
12
|
-
import { mergeShaderModuleBindingsIntoLayout, shaderModuleHasUniforms } from "../utils/shader-module-utils.js";
|
|
12
|
+
import { mergeInferredShaderLayout, mergeShaderModules, mergeShaderModuleBindingsIntoLayout, shaderModuleHasUniforms } from "../utils/shader-module-utils.js";
|
|
13
13
|
import { uid } from "../utils/uid.js";
|
|
14
14
|
import { ShaderInputs } from "../shader-inputs.js";
|
|
15
|
-
import {
|
|
15
|
+
import { DynamicBuffer, isBufferRangeBinding, resolveBufferRangeBinding } from "../dynamic-buffer/dynamic-buffer.js";
|
|
16
|
+
import { getTextureBindingLayout, isTextureBindingSource } from "../dynamic-texture/texture-binding-source.js";
|
|
16
17
|
const LOG_DRAW_PRIORITY = 2;
|
|
17
18
|
const LOG_DRAW_TIMEOUT = 10000;
|
|
18
19
|
const PIPELINE_INITIALIZATION_FAILED = 'render pipeline initialization failed';
|
|
20
|
+
const DEPTH_STENCIL_ATTACHMENT_FORMATS = [
|
|
21
|
+
'stencil8',
|
|
22
|
+
'depth16unorm',
|
|
23
|
+
'depth24plus',
|
|
24
|
+
'depth24plus-stencil8',
|
|
25
|
+
'depth32float',
|
|
26
|
+
'depth32float-stencil8'
|
|
27
|
+
];
|
|
19
28
|
/**
|
|
20
29
|
* High level draw API for luma.gl.
|
|
21
30
|
*
|
|
@@ -28,7 +37,7 @@ const PIPELINE_INITIALIZATION_FAILED = 'render pipeline initialization failed';
|
|
|
28
37
|
* - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
|
|
29
38
|
* - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
|
|
30
39
|
* - Manages geometry attributes and buffer bindings.
|
|
31
|
-
* - Accepts textures, samplers and uniform buffers as bindings, including
|
|
40
|
+
* - Accepts textures, samplers and uniform buffers as bindings, including texture binding sources.
|
|
32
41
|
* - Provides detailed debug logging and optional shader source inspection.
|
|
33
42
|
*/
|
|
34
43
|
export class Model {
|
|
@@ -42,8 +51,12 @@ export class Model {
|
|
|
42
51
|
userData: {},
|
|
43
52
|
defines: {},
|
|
44
53
|
modules: [],
|
|
54
|
+
plugins: [],
|
|
45
55
|
geometry: null,
|
|
46
56
|
indexBuffer: null,
|
|
57
|
+
indexCount: undefined,
|
|
58
|
+
firstVertex: 0,
|
|
59
|
+
firstIndex: 0,
|
|
47
60
|
attributes: {},
|
|
48
61
|
constantAttributes: {},
|
|
49
62
|
bindings: {},
|
|
@@ -94,6 +107,12 @@ export class Model {
|
|
|
94
107
|
instanceCount = 0;
|
|
95
108
|
/** Vertex count */
|
|
96
109
|
vertexCount;
|
|
110
|
+
/** Indexed draw count override. Undefined draws the full bound index buffer. */
|
|
111
|
+
indexCount;
|
|
112
|
+
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
113
|
+
firstVertex;
|
|
114
|
+
/** First index element for WebGPU indexed draws. */
|
|
115
|
+
firstIndex;
|
|
97
116
|
/** Index buffer */
|
|
98
117
|
indexBuffer = null;
|
|
99
118
|
/** Buffer-valued attributes */
|
|
@@ -121,8 +140,13 @@ export class Model {
|
|
|
121
140
|
_attributeInfos = {};
|
|
122
141
|
_gpuGeometry = null;
|
|
123
142
|
props;
|
|
143
|
+
_dynamicIndexBufferSource = null;
|
|
144
|
+
_dynamicAttributeBufferSources = {};
|
|
145
|
+
_colorAttachmentFormats;
|
|
146
|
+
_depthStencilAttachmentFormat;
|
|
124
147
|
_pipelineNeedsUpdate = 'newly created';
|
|
125
148
|
_needsRedraw = 'initializing';
|
|
149
|
+
_drawBlockedReason = false;
|
|
126
150
|
_destroyed = false;
|
|
127
151
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
128
152
|
_lastDrawTimestamp = -1;
|
|
@@ -140,18 +164,21 @@ export class Model {
|
|
|
140
164
|
this.device = device;
|
|
141
165
|
Object.assign(this.userData, props.userData);
|
|
142
166
|
this.material = props.material || null;
|
|
167
|
+
const platformInfo = getPlatformInfo(device);
|
|
168
|
+
const resolvedPlugins = resolveShaderPlugins(this.props.plugins, platformInfo.shaderLanguage);
|
|
143
169
|
// Setup shader module inputs
|
|
144
|
-
const
|
|
170
|
+
const shaderInputModules = mergeShaderPluginModules(this.props.modules, resolvedPlugins.modules);
|
|
171
|
+
const moduleMap = Object.fromEntries(shaderInputModules.map(module => [module.name, module]));
|
|
145
172
|
const shaderInputs = props.shaderInputs ||
|
|
146
173
|
new ShaderInputs(moduleMap, { disableWarnings: this.props.disableWarnings });
|
|
174
|
+
if (props.shaderInputs && resolvedPlugins.modules.length > 0) {
|
|
175
|
+
shaderInputs.addModules(resolvedPlugins.modules);
|
|
176
|
+
}
|
|
147
177
|
// @ts-ignore
|
|
148
178
|
this.setShaderInputs(shaderInputs);
|
|
149
179
|
// Setup shader assembler
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const modules =
|
|
153
|
-
// @ts-ignore shaderInputs is assigned in setShaderInputs above.
|
|
154
|
-
(this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
|
|
180
|
+
const modules = mergeShaderModules(this.props.modules, shaderInputs.getModules());
|
|
181
|
+
const defines = { ...resolvedPlugins.defines, ...this.props.defines };
|
|
155
182
|
this.props.shaderLayout =
|
|
156
183
|
mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
|
|
157
184
|
const isWebGPU = this.device.type === 'webgpu';
|
|
@@ -163,23 +190,33 @@ export class Model {
|
|
|
163
190
|
const { source, getUniforms, bindingTable } = this.props.shaderAssembler.assembleWGSLShader({
|
|
164
191
|
platformInfo,
|
|
165
192
|
...this.props,
|
|
166
|
-
modules
|
|
193
|
+
modules,
|
|
194
|
+
defines,
|
|
195
|
+
pluginInjections: resolvedPlugins.injections,
|
|
196
|
+
pluginVertexInputs: resolvedPlugins.vertexInputs,
|
|
197
|
+
pluginVaryings: resolvedPlugins.varyings
|
|
167
198
|
});
|
|
168
199
|
this.source = source;
|
|
169
200
|
// @ts-expect-error
|
|
170
201
|
this._getModuleUniforms = getUniforms;
|
|
171
202
|
this._bindingTable = bindingTable;
|
|
172
203
|
// Extract shader layout after modules have been added to WGSL source, to include any bindings added by modules
|
|
173
|
-
const
|
|
204
|
+
const reflectedShaderLayout = device.getShaderLayout?.(this.source);
|
|
205
|
+
const inferredShaderLayout = normalizeShaderPluginAttributeNames(reflectedShaderLayout, resolvedPlugins.vertexInputs);
|
|
206
|
+
const shaderLayout = mergeInferredShaderLayout(this.props.shaderLayout, inferredShaderLayout, Object.keys(resolvedPlugins.vertexInputs));
|
|
174
207
|
this.props.shaderLayout =
|
|
175
|
-
mergeShaderModuleBindingsIntoLayout(
|
|
208
|
+
mergeShaderModuleBindingsIntoLayout(shaderLayout || null, modules) || null;
|
|
176
209
|
}
|
|
177
210
|
else {
|
|
178
211
|
// GLSL
|
|
179
212
|
const { vs, fs, getUniforms } = this.props.shaderAssembler.assembleGLSLShaderPair({
|
|
180
213
|
platformInfo,
|
|
181
214
|
...this.props,
|
|
182
|
-
modules
|
|
215
|
+
modules,
|
|
216
|
+
defines,
|
|
217
|
+
pluginInjections: resolvedPlugins.injections,
|
|
218
|
+
pluginVertexInputs: resolvedPlugins.vertexInputs,
|
|
219
|
+
pluginVaryings: resolvedPlugins.varyings
|
|
183
220
|
});
|
|
184
221
|
this.vs = vs;
|
|
185
222
|
this.fs = fs;
|
|
@@ -188,10 +225,18 @@ export class Model {
|
|
|
188
225
|
this._bindingTable = [];
|
|
189
226
|
}
|
|
190
227
|
this.vertexCount = this.props.vertexCount;
|
|
228
|
+
this.indexCount = this.props.indexCount;
|
|
229
|
+
this.firstVertex = this.props.firstVertex;
|
|
230
|
+
this.firstIndex = this.props.firstIndex;
|
|
191
231
|
this.instanceCount = this.props.instanceCount;
|
|
192
232
|
this.topology = this.props.topology;
|
|
193
233
|
this.bufferLayout = this.props.bufferLayout;
|
|
194
234
|
this.parameters = this.props.parameters;
|
|
235
|
+
// Seed attachment formats before creating the initial WebGPU pipeline. This is required for
|
|
236
|
+
// depth-only models whose intentional empty color target list must not fall back to the canvas
|
|
237
|
+
// format before the first render pass can synchronize attachment state.
|
|
238
|
+
this._colorAttachmentFormats = this.props.colorAttachmentFormats;
|
|
239
|
+
this._depthStencilAttachmentFormat = this.props.depthStencilAttachmentFormat;
|
|
195
240
|
// Geometry, if provided, sets topology and vertex cound
|
|
196
241
|
if (props.geometry) {
|
|
197
242
|
this.setGeometry(props.geometry);
|
|
@@ -270,10 +315,17 @@ export class Model {
|
|
|
270
315
|
getBindingDebugTable() {
|
|
271
316
|
return this._bindingTable;
|
|
272
317
|
}
|
|
273
|
-
/**
|
|
274
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Updates uniforms and pipeline state before opening a render pass.
|
|
320
|
+
*
|
|
321
|
+
* @param commandEncoder - Encoder that should own any GPU uploads emitted
|
|
322
|
+
* during draw preparation.
|
|
323
|
+
*/
|
|
324
|
+
predraw(commandEncoder) {
|
|
275
325
|
// Update uniform buffers if needed
|
|
276
|
-
this.
|
|
326
|
+
this._syncDynamicBuffers();
|
|
327
|
+
this.updateShaderInputs(commandEncoder);
|
|
328
|
+
this.material?.updateShaderInputs(commandEncoder);
|
|
277
329
|
// Check if the pipeline is invalidated
|
|
278
330
|
this.pipeline = this._updatePipeline();
|
|
279
331
|
}
|
|
@@ -283,14 +335,32 @@ export class Model {
|
|
|
283
335
|
* @returns `true` if the draw call was executed, `false` if resources were not ready.
|
|
284
336
|
*/
|
|
285
337
|
draw(renderPass) {
|
|
338
|
+
if (this._drawBlockedReason && !this._pipelineNeedsUpdate) {
|
|
339
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)();
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
286
342
|
const loadingBinding = this._areBindingsLoading();
|
|
287
343
|
if (loadingBinding) {
|
|
288
344
|
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${loadingBinding} not loaded`)();
|
|
289
345
|
return false;
|
|
290
346
|
}
|
|
347
|
+
this._syncAttachmentFormats(renderPass);
|
|
291
348
|
try {
|
|
292
349
|
renderPass.pushDebugGroup(`${this}.predraw(${renderPass})`);
|
|
293
|
-
this.
|
|
350
|
+
if (this.device.type === 'webgpu') {
|
|
351
|
+
// WebGPU uploads cannot be encoded once the render pass is already open.
|
|
352
|
+
// Keep the implicit draw() path working for existing callers by falling
|
|
353
|
+
// back to immediate writes here; callers that need upload ordering
|
|
354
|
+
// across multiple draws/viewports must call predraw(commandEncoder)
|
|
355
|
+
// before beginRenderPass().
|
|
356
|
+
this.updateShaderInputs();
|
|
357
|
+
this.material?.updateShaderInputs();
|
|
358
|
+
this._syncDynamicBuffers();
|
|
359
|
+
this.pipeline = this._updatePipeline();
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
this.predraw(this.device.commandEncoder);
|
|
363
|
+
}
|
|
294
364
|
}
|
|
295
365
|
finally {
|
|
296
366
|
renderPass.popDebugGroup();
|
|
@@ -310,33 +380,44 @@ export class Model {
|
|
|
310
380
|
drawSuccess = false;
|
|
311
381
|
}
|
|
312
382
|
else {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
383
|
+
const drawValidationError = this.vertexArray.getDrawValidationError();
|
|
384
|
+
if (drawValidationError) {
|
|
385
|
+
log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${drawValidationError}`)();
|
|
386
|
+
this._drawBlockedReason = drawValidationError;
|
|
387
|
+
drawSuccess = false;
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const shaderLayout = this._getCurrentShaderLayout();
|
|
391
|
+
const syncBindings = this._getBindings(shaderLayout);
|
|
392
|
+
const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
|
|
393
|
+
const { indexBuffer } = this.vertexArray;
|
|
394
|
+
const indexCount = indexBuffer
|
|
395
|
+
? (this.indexCount ??
|
|
396
|
+
indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2))
|
|
397
|
+
: undefined;
|
|
398
|
+
renderPass.setPipeline(this.pipeline);
|
|
399
|
+
renderPass.setBindings(syncBindGroups, {
|
|
400
|
+
_bindGroupCacheKeys: this._getBindGroupCacheKeys()
|
|
401
|
+
});
|
|
402
|
+
renderPass.setVertexArray(this.vertexArray);
|
|
403
|
+
const hasNoInstances = this.isInstanced === true && this.instanceCount === 0;
|
|
404
|
+
drawSuccess = hasNoInstances
|
|
405
|
+
? true
|
|
406
|
+
: renderPass.draw({
|
|
407
|
+
isInstanced: this.isInstanced,
|
|
408
|
+
vertexCount: this.vertexCount,
|
|
409
|
+
instanceCount: this.isInstanced ? this.instanceCount : undefined,
|
|
410
|
+
indexCount,
|
|
411
|
+
firstVertex: this.firstVertex,
|
|
412
|
+
firstIndex: this.firstIndex,
|
|
413
|
+
transformFeedback: this.transformFeedback || undefined,
|
|
414
|
+
uniforms: this.props.uniforms,
|
|
415
|
+
// WebGL shares underlying cached programs even for models that have different
|
|
416
|
+
// parameters and topology, so those compatibility overrides remain per draw.
|
|
417
|
+
parameters: this.parameters,
|
|
418
|
+
topology: this.topology
|
|
419
|
+
});
|
|
420
|
+
}
|
|
340
421
|
}
|
|
341
422
|
}
|
|
342
423
|
finally {
|
|
@@ -351,6 +432,10 @@ export class Model {
|
|
|
351
432
|
}
|
|
352
433
|
else if (pipelineErrored) {
|
|
353
434
|
this._needsRedraw = PIPELINE_INITIALIZATION_FAILED;
|
|
435
|
+
this._drawBlockedReason = PIPELINE_INITIALIZATION_FAILED;
|
|
436
|
+
}
|
|
437
|
+
else if (this._drawBlockedReason) {
|
|
438
|
+
this._needsRedraw = this._drawBlockedReason;
|
|
354
439
|
}
|
|
355
440
|
else {
|
|
356
441
|
this._needsRedraw = 'waiting for resource initialization';
|
|
@@ -392,9 +477,13 @@ export class Model {
|
|
|
392
477
|
*/
|
|
393
478
|
setBufferLayout(bufferLayout) {
|
|
394
479
|
const bufferLayoutHelper = new BufferLayoutHelper(this.bufferLayout);
|
|
395
|
-
|
|
480
|
+
const nextBufferLayout = this._gpuGeometry
|
|
396
481
|
? bufferLayoutHelper.mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout)
|
|
397
482
|
: bufferLayout;
|
|
483
|
+
if (deepEqual(nextBufferLayout, this.bufferLayout, -1)) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
this.bufferLayout = nextBufferLayout;
|
|
398
487
|
this._setPipelineNeedsUpdate('bufferLayout');
|
|
399
488
|
// Recreate the pipeline
|
|
400
489
|
this.pipeline = this._updatePipeline();
|
|
@@ -442,6 +531,17 @@ export class Model {
|
|
|
442
531
|
this.vertexCount = vertexCount;
|
|
443
532
|
this.setNeedsRedraw('vertexCount');
|
|
444
533
|
}
|
|
534
|
+
/** Updates the indexed draw count override. */
|
|
535
|
+
setIndexCount(indexCount) {
|
|
536
|
+
this.indexCount = indexCount;
|
|
537
|
+
this.setNeedsRedraw('indexCount');
|
|
538
|
+
}
|
|
539
|
+
/** Updates the first indexed/non-indexed draw offsets. */
|
|
540
|
+
setDrawOffsets({ firstVertex, firstIndex }) {
|
|
541
|
+
this.firstVertex = firstVertex;
|
|
542
|
+
this.firstIndex = firstIndex;
|
|
543
|
+
this.setNeedsRedraw('drawOffsets');
|
|
544
|
+
}
|
|
445
545
|
/** Set the shader inputs */
|
|
446
546
|
setShaderInputs(shaderInputs) {
|
|
447
547
|
this.shaderInputs = shaderInputs;
|
|
@@ -460,8 +560,15 @@ export class Model {
|
|
|
460
560
|
this.setNeedsRedraw('material');
|
|
461
561
|
}
|
|
462
562
|
/** Update uniform buffers from the model's shader inputs */
|
|
463
|
-
|
|
464
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Flushes current shader-input values into managed uniform buffers and
|
|
565
|
+
* non-material bindings.
|
|
566
|
+
*
|
|
567
|
+
* @param commandEncoder - Optional encoder used to order uniform uploads with
|
|
568
|
+
* subsequent draw commands.
|
|
569
|
+
*/
|
|
570
|
+
updateShaderInputs(commandEncoder) {
|
|
571
|
+
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(), commandEncoder);
|
|
465
572
|
this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues()));
|
|
466
573
|
// TODO - this is already tracked through buffer/texture update times?
|
|
467
574
|
this.setNeedsRedraw('shaderInputs');
|
|
@@ -485,7 +592,13 @@ export class Model {
|
|
|
485
592
|
* @todo - how to unset it if we change geometry?
|
|
486
593
|
*/
|
|
487
594
|
setIndexBuffer(indexBuffer) {
|
|
488
|
-
|
|
595
|
+
const resolvedIndexBuffer = indexBuffer instanceof DynamicBuffer ? indexBuffer.buffer : indexBuffer;
|
|
596
|
+
this.indexBuffer = resolvedIndexBuffer;
|
|
597
|
+
this._dynamicIndexBufferSource =
|
|
598
|
+
indexBuffer instanceof DynamicBuffer
|
|
599
|
+
? { source: indexBuffer, generation: indexBuffer.generation }
|
|
600
|
+
: null;
|
|
601
|
+
this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
|
|
489
602
|
this.setNeedsRedraw('indexBuffer');
|
|
490
603
|
}
|
|
491
604
|
/**
|
|
@@ -493,6 +606,7 @@ export class Model {
|
|
|
493
606
|
* @note Overrides any attributes previously set with the same name
|
|
494
607
|
*/
|
|
495
608
|
setAttributes(buffers, options) {
|
|
609
|
+
this._drawBlockedReason = false;
|
|
496
610
|
const disableWarnings = options?.disableWarnings ?? this.props.disableWarnings;
|
|
497
611
|
if (buffers['indices']) {
|
|
498
612
|
log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
|
|
@@ -503,6 +617,7 @@ export class Model {
|
|
|
503
617
|
const bufferLayoutHelper = new BufferLayoutHelper(this.bufferLayout);
|
|
504
618
|
// Check if all buffers have a layout
|
|
505
619
|
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
620
|
+
const resolvedBuffer = buffer instanceof DynamicBuffer ? buffer.buffer : buffer;
|
|
506
621
|
const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
|
|
507
622
|
if (!bufferLayout) {
|
|
508
623
|
if (!disableWarnings) {
|
|
@@ -517,15 +632,30 @@ export class Model {
|
|
|
517
632
|
for (const attributeName of attributeNames) {
|
|
518
633
|
const attributeInfo = this._attributeInfos[attributeName];
|
|
519
634
|
if (attributeInfo) {
|
|
520
|
-
const
|
|
521
|
-
?
|
|
635
|
+
const bufferSlot = this.device.type === 'webgpu'
|
|
636
|
+
? this.vertexArray.getBufferSlot(attributeInfo.bufferName)
|
|
522
637
|
: attributeInfo.location;
|
|
523
|
-
|
|
638
|
+
if (bufferSlot === null) {
|
|
639
|
+
if (!disableWarnings) {
|
|
640
|
+
log.warn(`Model(${this.id}): Missing vertex array slot for buffer "${attributeInfo.bufferName}".`)();
|
|
641
|
+
}
|
|
642
|
+
continue; // eslint-disable-line no-continue
|
|
643
|
+
}
|
|
644
|
+
this.vertexArray.setBuffer(bufferSlot, resolvedBuffer);
|
|
645
|
+
if (buffer instanceof DynamicBuffer) {
|
|
646
|
+
this._dynamicAttributeBufferSources[bufferSlot] = {
|
|
647
|
+
source: buffer,
|
|
648
|
+
generation: buffer.generation
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
delete this._dynamicAttributeBufferSources[bufferSlot];
|
|
653
|
+
}
|
|
524
654
|
set = true;
|
|
525
655
|
}
|
|
526
656
|
}
|
|
527
657
|
if (!set && !disableWarnings) {
|
|
528
|
-
log.warn(`Model(${this.id}): Ignoring buffer "${
|
|
658
|
+
log.warn(`Model(${this.id}): Ignoring buffer "${resolvedBuffer.id}" for unknown attribute "${bufferName}"`)();
|
|
529
659
|
}
|
|
530
660
|
}
|
|
531
661
|
this.setNeedsRedraw('attributes');
|
|
@@ -554,42 +684,44 @@ export class Model {
|
|
|
554
684
|
/** Check that bindings are loaded. Returns id of first binding that is still loading. */
|
|
555
685
|
_areBindingsLoading() {
|
|
556
686
|
for (const binding of Object.values(this.bindings)) {
|
|
557
|
-
if (binding
|
|
687
|
+
if (isTextureBindingSource(binding) && !binding.isReady) {
|
|
558
688
|
return binding.id;
|
|
559
689
|
}
|
|
560
690
|
}
|
|
561
691
|
for (const binding of Object.values(this.material?.bindings || {})) {
|
|
562
|
-
if (binding
|
|
692
|
+
if (isTextureBindingSource(binding) && !binding.isReady) {
|
|
563
693
|
return binding.id;
|
|
564
694
|
}
|
|
565
695
|
}
|
|
566
696
|
return false;
|
|
567
697
|
}
|
|
568
|
-
/**
|
|
569
|
-
|
|
698
|
+
/**
|
|
699
|
+
* Resolves ready model bindings for the current shader layout.
|
|
700
|
+
* @param shaderLayout Reflected bindings used to select copied or external texture resolution.
|
|
701
|
+
*/
|
|
702
|
+
_getBindings(shaderLayout = this._getCurrentShaderLayout()) {
|
|
570
703
|
const validBindings = {};
|
|
571
704
|
for (const [name, binding] of Object.entries(this.bindings)) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
validBindings[name] = binding.texture;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
validBindings[name] = binding;
|
|
705
|
+
const resolvedBinding = resolveModelBinding(name, binding, shaderLayout);
|
|
706
|
+
if (resolvedBinding) {
|
|
707
|
+
validBindings[name] = resolvedBinding;
|
|
580
708
|
}
|
|
581
709
|
}
|
|
582
710
|
return validBindings;
|
|
583
711
|
}
|
|
584
|
-
|
|
585
|
-
|
|
712
|
+
/**
|
|
713
|
+
* Groups resolved model and material bindings for the current shader layout.
|
|
714
|
+
* @param shaderLayout Reflected bindings used to group logical binding names.
|
|
715
|
+
* @param bindings Model bindings already resolved for this draw preparation.
|
|
716
|
+
*/
|
|
717
|
+
_getBindGroups(shaderLayout = this._getCurrentShaderLayout(), bindings = this._getBindings(shaderLayout)) {
|
|
586
718
|
const bindGroups = shaderLayout.bindings.length
|
|
587
|
-
? normalizeBindingsByGroup(shaderLayout,
|
|
588
|
-
: { 0:
|
|
719
|
+
? normalizeBindingsByGroup(shaderLayout, bindings)
|
|
720
|
+
: { 0: bindings };
|
|
589
721
|
if (!this.material) {
|
|
590
722
|
return bindGroups;
|
|
591
723
|
}
|
|
592
|
-
for (const [groupKey, groupBindings] of Object.entries(this.material.getBindingsByGroup())) {
|
|
724
|
+
for (const [groupKey, groupBindings] of Object.entries(this.material.getBindingsByGroup(shaderLayout))) {
|
|
593
725
|
const group = Number(groupKey);
|
|
594
726
|
bindGroups[group] = {
|
|
595
727
|
...(bindGroups[group] || {}),
|
|
@@ -605,21 +737,34 @@ export class Model {
|
|
|
605
737
|
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
606
738
|
_getBindingsUpdateTimestamp() {
|
|
607
739
|
let timestamp = 0;
|
|
740
|
+
if (this._dynamicIndexBufferSource) {
|
|
741
|
+
timestamp = Math.max(timestamp, this._dynamicIndexBufferSource.source.updateTimestamp);
|
|
742
|
+
}
|
|
743
|
+
for (const entry of Object.values(this._dynamicAttributeBufferSources)) {
|
|
744
|
+
timestamp = Math.max(timestamp, entry.source.updateTimestamp);
|
|
745
|
+
}
|
|
608
746
|
for (const binding of Object.values(this.bindings)) {
|
|
609
747
|
if (binding instanceof TextureView) {
|
|
610
748
|
timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
|
|
611
749
|
}
|
|
612
|
-
else if (binding instanceof Buffer ||
|
|
750
|
+
else if (binding instanceof Buffer ||
|
|
751
|
+
binding instanceof Texture ||
|
|
752
|
+
binding instanceof ExternalTexture) {
|
|
753
|
+
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
754
|
+
}
|
|
755
|
+
else if (binding instanceof DynamicBuffer) {
|
|
613
756
|
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
614
757
|
}
|
|
615
|
-
else if (binding
|
|
616
|
-
timestamp = binding.
|
|
617
|
-
? Math.max(timestamp, binding.
|
|
758
|
+
else if (isTextureBindingSource(binding)) {
|
|
759
|
+
timestamp = binding.isReady
|
|
760
|
+
? Math.max(timestamp, binding.updateTimestamp)
|
|
618
761
|
: // The texture will become available in the future
|
|
619
762
|
Infinity;
|
|
620
763
|
}
|
|
621
|
-
else if (
|
|
622
|
-
timestamp = Math.max(timestamp, binding.buffer
|
|
764
|
+
else if (isBufferRangeBinding(binding)) {
|
|
765
|
+
timestamp = Math.max(timestamp, binding.buffer instanceof DynamicBuffer
|
|
766
|
+
? binding.buffer.updateTimestamp
|
|
767
|
+
: binding.buffer.updateTimestamp);
|
|
623
768
|
}
|
|
624
769
|
}
|
|
625
770
|
return Math.max(timestamp, this.material?.getBindingsUpdateTimestamp() || 0);
|
|
@@ -648,6 +793,7 @@ export class Model {
|
|
|
648
793
|
/** Mark pipeline as needing update */
|
|
649
794
|
_setPipelineNeedsUpdate(reason) {
|
|
650
795
|
this._pipelineNeedsUpdate ||= reason;
|
|
796
|
+
this._drawBlockedReason = false;
|
|
651
797
|
this.setNeedsRedraw(reason);
|
|
652
798
|
}
|
|
653
799
|
/** Update pipeline if needed */
|
|
@@ -683,9 +829,11 @@ export class Model {
|
|
|
683
829
|
...this.props,
|
|
684
830
|
bindings: undefined,
|
|
685
831
|
bufferLayout: this.bufferLayout,
|
|
832
|
+
colorAttachmentFormats: this._colorAttachmentFormats,
|
|
833
|
+
depthStencilAttachmentFormat: this._depthStencilAttachmentFormat,
|
|
686
834
|
topology: this.topology,
|
|
687
835
|
parameters: this.parameters,
|
|
688
|
-
bindGroups:
|
|
836
|
+
bindGroups: undefined,
|
|
689
837
|
vs,
|
|
690
838
|
fs
|
|
691
839
|
});
|
|
@@ -784,8 +932,93 @@ export class Model {
|
|
|
784
932
|
}
|
|
785
933
|
return filteredBindings;
|
|
786
934
|
}
|
|
935
|
+
/** Returns the current reflected shader layout or the pre-reflection empty layout. */
|
|
936
|
+
_getCurrentShaderLayout() {
|
|
937
|
+
return this.pipeline?.shaderLayout || this.props.shaderLayout || { bindings: [] };
|
|
938
|
+
}
|
|
939
|
+
_syncDynamicBuffers() {
|
|
940
|
+
if (this._dynamicIndexBufferSource &&
|
|
941
|
+
this._dynamicIndexBufferSource.generation !== this._dynamicIndexBufferSource.source.generation) {
|
|
942
|
+
const resolvedIndexBuffer = this._dynamicIndexBufferSource.source.buffer;
|
|
943
|
+
this.indexBuffer = resolvedIndexBuffer;
|
|
944
|
+
this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
|
|
945
|
+
this._dynamicIndexBufferSource.generation = this._dynamicIndexBufferSource.source.generation;
|
|
946
|
+
this.setNeedsRedraw('dynamic index buffer');
|
|
947
|
+
}
|
|
948
|
+
for (const [locationKey, entry] of Object.entries(this._dynamicAttributeBufferSources)) {
|
|
949
|
+
if (entry.generation !== entry.source.generation) {
|
|
950
|
+
this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer);
|
|
951
|
+
entry.generation = entry.source.generation;
|
|
952
|
+
this.setNeedsRedraw('dynamic attribute buffer');
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
_syncAttachmentFormats(renderPass) {
|
|
957
|
+
if (this.device.type !== 'webgpu') {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const framebuffer = renderPass.framebuffer || renderPass.props.framebuffer;
|
|
961
|
+
const renderBundleProps = renderPass.props;
|
|
962
|
+
const nextColorAttachmentFormats = renderBundleProps.colorAttachmentFormats ??
|
|
963
|
+
framebuffer?.colorAttachments?.map(colorAttachment => asColorAttachmentFormat(colorAttachment?.texture?.format));
|
|
964
|
+
const nextDepthStencilAttachmentFormat = renderBundleProps.depthStencilAttachmentFormat === false
|
|
965
|
+
? undefined
|
|
966
|
+
: (renderBundleProps.depthStencilAttachmentFormat ??
|
|
967
|
+
asDepthStencilAttachmentFormat(framebuffer?.depthStencilAttachment?.texture?.format));
|
|
968
|
+
if (!deepEqual(this._colorAttachmentFormats, nextColorAttachmentFormats, 1) ||
|
|
969
|
+
this._depthStencilAttachmentFormat !== nextDepthStencilAttachmentFormat) {
|
|
970
|
+
this._colorAttachmentFormats = nextColorAttachmentFormats;
|
|
971
|
+
this._depthStencilAttachmentFormat = nextDepthStencilAttachmentFormat;
|
|
972
|
+
this._setPipelineNeedsUpdate('attachment formats');
|
|
973
|
+
}
|
|
974
|
+
}
|
|
787
975
|
}
|
|
788
976
|
// HELPERS
|
|
977
|
+
function normalizeShaderPluginAttributeNames(shaderLayout, vertexInputs) {
|
|
978
|
+
if (!shaderLayout || Object.keys(vertexInputs).length === 0) {
|
|
979
|
+
return shaderLayout;
|
|
980
|
+
}
|
|
981
|
+
return {
|
|
982
|
+
...shaderLayout,
|
|
983
|
+
attributes: shaderLayout.attributes.map(attribute => {
|
|
984
|
+
const publicName = attribute.name.startsWith('_luma_')
|
|
985
|
+
? attribute.name.slice('_luma_'.length)
|
|
986
|
+
: null;
|
|
987
|
+
return publicName && vertexInputs[publicName] ? { ...attribute, name: publicName } : attribute;
|
|
988
|
+
})
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Resolves one model binding against the current shader layout.
|
|
993
|
+
* @param bindingName Logical model binding name.
|
|
994
|
+
* @param binding Model binding or deferred engine binding source.
|
|
995
|
+
* @param shaderLayout Reflected bindings used to select copied or external texture resolution.
|
|
996
|
+
* @returns Concrete core binding, or `null` while a deferred source is unavailable.
|
|
997
|
+
*/
|
|
998
|
+
function resolveModelBinding(bindingName, binding, shaderLayout) {
|
|
999
|
+
if (isTextureBindingSource(binding)) {
|
|
1000
|
+
const bindingLayout = getTextureBindingLayout(shaderLayout, bindingName, {
|
|
1001
|
+
fallbackGroup: 0
|
|
1002
|
+
});
|
|
1003
|
+
return bindingLayout ? binding.resolveTextureBinding(bindingLayout) : null;
|
|
1004
|
+
}
|
|
1005
|
+
if (binding instanceof DynamicBuffer) {
|
|
1006
|
+
return binding.buffer;
|
|
1007
|
+
}
|
|
1008
|
+
if (isBufferRangeBinding(binding)) {
|
|
1009
|
+
return resolveBufferRangeBinding(binding);
|
|
1010
|
+
}
|
|
1011
|
+
return binding;
|
|
1012
|
+
}
|
|
1013
|
+
function asColorAttachmentFormat(format) {
|
|
1014
|
+
return format && !isDepthStencilAttachmentFormat(format) ? format : null;
|
|
1015
|
+
}
|
|
1016
|
+
function asDepthStencilAttachmentFormat(format) {
|
|
1017
|
+
return format && isDepthStencilAttachmentFormat(format) ? format : undefined;
|
|
1018
|
+
}
|
|
1019
|
+
function isDepthStencilAttachmentFormat(format) {
|
|
1020
|
+
return DEPTH_STENCIL_ATTACHMENT_FORMATS.includes(format);
|
|
1021
|
+
}
|
|
789
1022
|
/** Create a shadertools platform info from the Device */
|
|
790
1023
|
export function getPlatformInfo(device) {
|
|
791
1024
|
return {
|
|
@@ -793,6 +1026,7 @@ export function getPlatformInfo(device) {
|
|
|
793
1026
|
shaderLanguage: device.info.shadingLanguage,
|
|
794
1027
|
shaderLanguageVersion: device.info.shadingLanguageVersion,
|
|
795
1028
|
gpu: device.info.gpu,
|
|
1029
|
+
limits: device.limits,
|
|
796
1030
|
// HACK - we pretend that the DeviceFeatures is a Set, it has a similar API
|
|
797
1031
|
features: device.features
|
|
798
1032
|
};
|