@luma.gl/engine 9.4.1 → 10.0.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.
- package/dist/animation-loop/animation-loop.d.ts +12 -5
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +3 -1
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +3 -1
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/compute/computation.d.ts +12 -0
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +85 -22
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/kernel.d.ts +54 -0
- package/dist/compute/kernel.d.ts.map +1 -0
- package/dist/compute/kernel.js +103 -0
- package/dist/compute/kernel.js.map +1 -0
- package/dist/compute/render-kernel.d.ts +65 -0
- package/dist/compute/render-kernel.d.ts.map +1 -0
- package/dist/compute/render-kernel.js +129 -0
- package/dist/compute/render-kernel.js.map +1 -0
- package/dist/controls/orbit-controls.d.ts +9 -2
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +55 -8
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/dist.dev.js +483 -127
- package/dist/dist.min.js +23 -23
- package/dist/index.cjs +485 -110
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +13 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +137 -66
- package/dist/model/model.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +12 -12
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +17 -17
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +16 -7
- package/src/animation-loop/animation-props.ts +4 -1
- package/src/compute/computation.ts +83 -30
- package/src/compute/kernel.ts +146 -0
- package/src/compute/render-kernel.ts +192 -0
- package/src/controls/orbit-controls.ts +61 -9
- package/src/index.ts +12 -0
- package/src/model/model.ts +149 -87
- package/src/passes/shader-pass-renderer.ts +28 -25
package/src/model/model.ts
CHANGED
|
@@ -134,7 +134,7 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
134
134
|
|
|
135
135
|
/** Optional index buffer. Dynamic buffers are rebound when resized. */
|
|
136
136
|
indexBuffer?: ModelBuffer | null;
|
|
137
|
-
/** Optional indexed draw count. Defaults to the full bound index buffer length. */
|
|
137
|
+
/** Optional indexed draw count. Defaults to vertexCount, then the full bound index buffer length. */
|
|
138
138
|
indexCount?: number;
|
|
139
139
|
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
140
140
|
firstVertex?: number;
|
|
@@ -180,6 +180,31 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
180
180
|
* - Provides detailed debug logging and optional shader source inspection.
|
|
181
181
|
*/
|
|
182
182
|
export class Model {
|
|
183
|
+
/** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
|
|
184
|
+
static async createAsync(device: Device, props: ModelProps): Promise<Model> {
|
|
185
|
+
const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
|
|
186
|
+
const asyncCompilation = ownsCompilation
|
|
187
|
+
? PipelineFactory.beginAsyncCompilation(device)
|
|
188
|
+
: PipelineFactory.getAsyncCompilation(device)!;
|
|
189
|
+
let model: Model;
|
|
190
|
+
try {
|
|
191
|
+
model = new Model(device, props);
|
|
192
|
+
} finally {
|
|
193
|
+
if (ownsCompilation) PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
if (ownsCompilation) {
|
|
197
|
+
await Promise.all(asyncCompilation);
|
|
198
|
+
} else {
|
|
199
|
+
await model._pipelineInitialization;
|
|
200
|
+
}
|
|
201
|
+
return model;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
model.destroy();
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
183
208
|
static defaultProps: Required<ModelProps> = {
|
|
184
209
|
...RenderPipeline.defaultProps,
|
|
185
210
|
source: undefined!,
|
|
@@ -255,7 +280,7 @@ export class Model {
|
|
|
255
280
|
instanceCount: number = 0;
|
|
256
281
|
/** Vertex count */
|
|
257
282
|
vertexCount: number;
|
|
258
|
-
/** Indexed draw count override. Undefined
|
|
283
|
+
/** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
|
|
259
284
|
indexCount: number | undefined;
|
|
260
285
|
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
261
286
|
firstVertex: number;
|
|
@@ -276,13 +301,13 @@ export class Model {
|
|
|
276
301
|
* @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
|
|
277
302
|
* @todo - allow application to define multiple vertex arrays?
|
|
278
303
|
* */
|
|
279
|
-
vertexArray
|
|
304
|
+
vertexArray!: VertexArray;
|
|
280
305
|
|
|
281
306
|
/** TransformFeedback, WebGL 2 only. */
|
|
282
307
|
transformFeedback: TransformFeedback | null = null;
|
|
283
308
|
|
|
284
309
|
/** The underlying GPU "program". @note May be recreated if parameters change */
|
|
285
|
-
pipeline
|
|
310
|
+
pipeline!: RenderPipeline;
|
|
286
311
|
|
|
287
312
|
/** ShaderInputs instance */
|
|
288
313
|
// @ts-expect-error Assigned in function called by constructor
|
|
@@ -306,10 +331,12 @@ export class Model {
|
|
|
306
331
|
private _needsRedraw: string | false = 'initializing';
|
|
307
332
|
private _drawBlockedReason: string | false = false;
|
|
308
333
|
private _destroyed = false;
|
|
334
|
+
private _vertexCountSet = false;
|
|
309
335
|
|
|
310
336
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
311
337
|
_lastDrawTimestamp: number = -1;
|
|
312
338
|
private _bindingTable: ShaderBindingDebugRow[] = [];
|
|
339
|
+
private _pipelineInitialization?: Promise<void>;
|
|
313
340
|
|
|
314
341
|
get [Symbol.toStringTag](): string {
|
|
315
342
|
return 'Model';
|
|
@@ -321,6 +348,7 @@ export class Model {
|
|
|
321
348
|
|
|
322
349
|
constructor(device: Device, props: ModelProps) {
|
|
323
350
|
const defaultShaderAssembler = Model.defaultProps.shaderAssembler;
|
|
351
|
+
const vertexCountSet = Object.hasOwn(props, 'vertexCount');
|
|
324
352
|
this.props = {
|
|
325
353
|
...Model.defaultProps,
|
|
326
354
|
...props,
|
|
@@ -330,6 +358,7 @@ export class Model {
|
|
|
330
358
|
? defaultShaderAssembler
|
|
331
359
|
: ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
|
|
332
360
|
};
|
|
361
|
+
this._vertexCountSet = vertexCountSet;
|
|
333
362
|
props = this.props;
|
|
334
363
|
this.id = props.id || uid('model');
|
|
335
364
|
this.device = device;
|
|
@@ -459,56 +488,47 @@ export class Model {
|
|
|
459
488
|
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
460
489
|
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
461
490
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
491
|
+
const asyncCompilation = PipelineFactory.getAsyncCompilation(this.device);
|
|
492
|
+
if (asyncCompilation) {
|
|
493
|
+
this._pipelineInitialization = this._initializePipelineAsync(props);
|
|
494
|
+
asyncCompilation.push(this._pipelineInitialization);
|
|
495
|
+
} else {
|
|
496
|
+
this.pipeline = this._updatePipeline();
|
|
497
|
+
this._initializePipelineResources(props);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
private async _initializePipelineAsync(props: ModelProps): Promise<void> {
|
|
502
|
+
await this._updatePipelineAsync();
|
|
503
|
+
this._initializePipelineResources(props);
|
|
504
|
+
}
|
|
465
505
|
|
|
466
|
-
|
|
506
|
+
private _initializePipelineResources(props: ModelProps): void {
|
|
507
|
+
this.vertexArray = this.device.createVertexArray({
|
|
467
508
|
shaderLayout: this.pipeline.shaderLayout,
|
|
468
509
|
bufferLayout: this.pipeline.bufferLayout
|
|
469
510
|
});
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (this.
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (props.instanceCount) {
|
|
482
|
-
this.setInstanceCount(props.instanceCount);
|
|
483
|
-
}
|
|
484
|
-
if (props.vertexCount) {
|
|
485
|
-
this.setVertexCount(props.vertexCount);
|
|
486
|
-
}
|
|
487
|
-
if (props.indexBuffer) {
|
|
488
|
-
this.setIndexBuffer(props.indexBuffer);
|
|
489
|
-
}
|
|
490
|
-
if (props.attributes) {
|
|
491
|
-
this.setAttributes(props.attributes);
|
|
492
|
-
}
|
|
493
|
-
if (props.constantAttributes) {
|
|
494
|
-
this.setConstantAttributes(props.constantAttributes);
|
|
495
|
-
}
|
|
496
|
-
if (props.bindings) {
|
|
497
|
-
this.setBindings(props.bindings);
|
|
498
|
-
}
|
|
499
|
-
if (props.transformFeedback) {
|
|
500
|
-
this.transformFeedback = props.transformFeedback;
|
|
501
|
-
}
|
|
511
|
+
if (this._gpuGeometry) this._setGeometryAttributes(this._gpuGeometry);
|
|
512
|
+
if ('isInstanced' in props) this.isInstanced = props.isInstanced;
|
|
513
|
+
if (props.instanceCount) this.setInstanceCount(props.instanceCount);
|
|
514
|
+
if (props.vertexCount) this.setVertexCount(props.vertexCount);
|
|
515
|
+
if (props.indexBuffer) this.setIndexBuffer(props.indexBuffer);
|
|
516
|
+
if (props.attributes) this.setAttributes(props.attributes);
|
|
517
|
+
if (props.constantAttributes) this.setConstantAttributes(props.constantAttributes);
|
|
518
|
+
if (props.bindings) this.setBindings(props.bindings);
|
|
519
|
+
if (props.transformFeedback) this.transformFeedback = props.transformFeedback;
|
|
502
520
|
}
|
|
503
521
|
|
|
504
522
|
destroy(): void {
|
|
505
523
|
if (!this._destroyed) {
|
|
506
524
|
// Release pipeline before we destroy the shaders used by the pipeline
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
525
|
+
if (this.pipeline) {
|
|
526
|
+
this.pipelineFactory.release(this.pipeline);
|
|
527
|
+
// Release the shaders
|
|
528
|
+
this.shaderFactory.release(this.pipeline.vs);
|
|
529
|
+
if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
|
|
530
|
+
this.shaderFactory.release(this.pipeline.fs);
|
|
531
|
+
}
|
|
512
532
|
}
|
|
513
533
|
this._uniformStore.destroy();
|
|
514
534
|
// TODO - mark resource as managed and destroyIfManaged() ?
|
|
@@ -625,7 +645,9 @@ export class Model {
|
|
|
625
645
|
const {indexBuffer} = this.vertexArray;
|
|
626
646
|
const indexCount = indexBuffer
|
|
627
647
|
? (this.indexCount ??
|
|
628
|
-
|
|
648
|
+
(this._vertexCountSet
|
|
649
|
+
? this.vertexCount
|
|
650
|
+
: indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)))
|
|
629
651
|
: undefined;
|
|
630
652
|
|
|
631
653
|
renderPass.setPipeline(this.pipeline);
|
|
@@ -774,6 +796,7 @@ export class Model {
|
|
|
774
796
|
*/
|
|
775
797
|
setVertexCount(vertexCount: number): void {
|
|
776
798
|
this.vertexCount = vertexCount;
|
|
799
|
+
this._vertexCountSet = true;
|
|
777
800
|
this.setNeedsRedraw('vertexCount');
|
|
778
801
|
}
|
|
779
802
|
|
|
@@ -1081,6 +1104,7 @@ export class Model {
|
|
|
1081
1104
|
|
|
1082
1105
|
// TODO - delete previous geometry?
|
|
1083
1106
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
1107
|
+
this._vertexCountSet = true;
|
|
1084
1108
|
this.setIndexBuffer(gpuGeometry.indices || null);
|
|
1085
1109
|
this.setAttributes(gpuGeometry.attributes, {disableWarnings: true});
|
|
1086
1110
|
this.setAttributes(attributes, {disableWarnings: this.props.disableWarnings});
|
|
@@ -1097,40 +1121,64 @@ export class Model {
|
|
|
1097
1121
|
|
|
1098
1122
|
/** Update pipeline if needed */
|
|
1099
1123
|
_updatePipeline(): RenderPipeline {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1124
|
+
const update = this._preparePipelineUpdate();
|
|
1125
|
+
if (update) {
|
|
1126
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
|
|
1127
|
+
this._finishPipelineUpdate(update);
|
|
1128
|
+
}
|
|
1129
|
+
return this.pipeline;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
|
|
1133
|
+
async _updatePipelineAsync(): Promise<RenderPipeline> {
|
|
1134
|
+
const update = this._preparePipelineUpdate();
|
|
1135
|
+
if (update) {
|
|
1136
|
+
try {
|
|
1137
|
+
this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
|
|
1140
|
+
this._pipelineNeedsUpdate = 'asynchronous pipeline creation failed';
|
|
1141
|
+
throw error;
|
|
1110
1142
|
}
|
|
1143
|
+
this._finishPipelineUpdate(update);
|
|
1144
|
+
}
|
|
1145
|
+
return this.pipeline;
|
|
1146
|
+
}
|
|
1111
1147
|
|
|
1112
|
-
|
|
1148
|
+
private _preparePipelineUpdate(): {
|
|
1149
|
+
props: RenderPipelineProps;
|
|
1150
|
+
vertexShader: Shader;
|
|
1151
|
+
fragmentShader: Shader | null;
|
|
1152
|
+
previousVertexShader: Shader | null;
|
|
1153
|
+
previousFragmentShader: Shader | null;
|
|
1154
|
+
} | null {
|
|
1155
|
+
if (!this._pipelineNeedsUpdate) return null;
|
|
1156
|
+
const previousVertexShader = this.pipeline?.vs ?? null;
|
|
1157
|
+
const previousFragmentShader = this.pipeline?.fs ?? null;
|
|
1158
|
+
if (this.pipeline) {
|
|
1159
|
+
log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
1160
|
+
}
|
|
1161
|
+
this._pipelineNeedsUpdate = false;
|
|
1113
1162
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1163
|
+
const vertexShader = this.shaderFactory.createShader({
|
|
1164
|
+
id: `${this.id}-vertex`,
|
|
1165
|
+
stage: 'vertex',
|
|
1166
|
+
source: this.source || this.vs,
|
|
1167
|
+
debugShaders: this.props.debugShaders
|
|
1168
|
+
});
|
|
1169
|
+
let fragmentShader: Shader | null = null;
|
|
1170
|
+
if (this.source) {
|
|
1171
|
+
fragmentShader = vertexShader;
|
|
1172
|
+
} else if (this.fs) {
|
|
1173
|
+
fragmentShader = this.shaderFactory.createShader({
|
|
1174
|
+
id: `${this.id}-fragment`,
|
|
1175
|
+
stage: 'fragment',
|
|
1176
|
+
source: this.fs,
|
|
1118
1177
|
debugShaders: this.props.debugShaders
|
|
1119
1178
|
});
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
fs = vs;
|
|
1124
|
-
} else if (this.fs) {
|
|
1125
|
-
fs = this.shaderFactory.createShader({
|
|
1126
|
-
id: `${this.id}-fragment`,
|
|
1127
|
-
stage: 'fragment',
|
|
1128
|
-
source: this.source || this.fs,
|
|
1129
|
-
debugShaders: this.props.debugShaders
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
1179
|
+
}
|
|
1180
|
+
return {
|
|
1181
|
+
props: {
|
|
1134
1182
|
...this.props,
|
|
1135
1183
|
bindings: undefined,
|
|
1136
1184
|
bufferLayout: this.bufferLayout,
|
|
@@ -1139,21 +1187,35 @@ export class Model {
|
|
|
1139
1187
|
topology: this.topology,
|
|
1140
1188
|
parameters: this.parameters,
|
|
1141
1189
|
bindGroups: undefined,
|
|
1142
|
-
vs,
|
|
1143
|
-
fs
|
|
1144
|
-
}
|
|
1190
|
+
vs: vertexShader,
|
|
1191
|
+
fs: fragmentShader
|
|
1192
|
+
},
|
|
1193
|
+
vertexShader,
|
|
1194
|
+
fragmentShader,
|
|
1195
|
+
previousVertexShader,
|
|
1196
|
+
previousFragmentShader
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1145
1199
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1200
|
+
private _finishPipelineUpdate(update: {
|
|
1201
|
+
previousVertexShader: Shader | null;
|
|
1202
|
+
previousFragmentShader: Shader | null;
|
|
1203
|
+
}): void {
|
|
1204
|
+
this._attributeInfos = getAttributeInfosFromLayouts(
|
|
1205
|
+
this.pipeline.shaderLayout,
|
|
1206
|
+
this.bufferLayout
|
|
1207
|
+
);
|
|
1208
|
+
this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
|
|
1209
|
+
}
|
|
1150
1210
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1211
|
+
private _releasePipelineShaders(
|
|
1212
|
+
vertexShader: Shader | null,
|
|
1213
|
+
fragmentShader: Shader | null
|
|
1214
|
+
): void {
|
|
1215
|
+
if (vertexShader) this.shaderFactory.release(vertexShader);
|
|
1216
|
+
if (fragmentShader && fragmentShader !== vertexShader) {
|
|
1217
|
+
this.shaderFactory.release(fragmentShader);
|
|
1155
1218
|
}
|
|
1156
|
-
return this.pipeline;
|
|
1157
1219
|
}
|
|
1158
1220
|
|
|
1159
1221
|
/** Throttle draw call logging */
|
|
@@ -6,9 +6,9 @@ import type {Binding, BindingDeclaration, CommandEncoder, TextureFormatColor} fr
|
|
|
6
6
|
import {Buffer, Device, Framebuffer, RenderPass, Texture} from '@luma.gl/core';
|
|
7
7
|
import type {
|
|
8
8
|
ShaderPass,
|
|
9
|
-
|
|
9
|
+
CompositeShaderPassComputeOptimization,
|
|
10
10
|
ShaderPassInputSource,
|
|
11
|
-
|
|
11
|
+
CompositeShaderPass,
|
|
12
12
|
ShaderPassRenderTarget
|
|
13
13
|
} from '@luma.gl/shadertools';
|
|
14
14
|
import {initializeShaderModule} from '@luma.gl/shadertools';
|
|
@@ -23,7 +23,7 @@ import {BackgroundTextureModel} from '../models/billboard-texture-model';
|
|
|
23
23
|
import {getFragmentShaderForRenderPass} from './get-fragment-shader';
|
|
24
24
|
import {textureTransform} from './texture-transform-module';
|
|
25
25
|
|
|
26
|
-
type ShaderPassLike = ShaderPass |
|
|
26
|
+
type ShaderPassLike = ShaderPass | CompositeShaderPass;
|
|
27
27
|
type ShaderSubPass = NonNullable<ShaderPass['passes']>[0];
|
|
28
28
|
|
|
29
29
|
type EffectiveSubPass = {
|
|
@@ -50,7 +50,7 @@ const RESERVED_RENDER_TARGET_NAMES = new Set(['original', 'previous']);
|
|
|
50
50
|
|
|
51
51
|
/** Construction props for {@link ShaderPassRenderer}. */
|
|
52
52
|
export type ShaderPassRendererProps = {
|
|
53
|
-
/** List of ShaderPasses or
|
|
53
|
+
/** List of ShaderPasses or CompositeShaderPasses to apply to the sourceTexture */
|
|
54
54
|
shaderPasses: ShaderPassLike[];
|
|
55
55
|
/** Optional typed ShaderInputs object for setting uniforms */
|
|
56
56
|
shaderInputs?: ShaderInputs;
|
|
@@ -79,7 +79,7 @@ export type ShaderPassRendererRenderOptions = {
|
|
|
79
79
|
*
|
|
80
80
|
* The renderer owns:
|
|
81
81
|
* - a shared ping-pong pair for the logical `previous` chain
|
|
82
|
-
* - any named render targets declared by `
|
|
82
|
+
* - any named render targets declared by `CompositeShaderPass`
|
|
83
83
|
* - a fullscreen model used both to seed the chain and to present to the screen
|
|
84
84
|
*
|
|
85
85
|
* Per-draw `uniforms` and `bindings` passed to `renderToTexture()` or `renderToScreen()` are
|
|
@@ -140,7 +140,7 @@ export class ShaderPassRenderer {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
/** Invalidates persistent
|
|
143
|
+
/** Invalidates persistent composite-pass targets without destroying their allocations. */
|
|
144
144
|
resetHistory(): void {
|
|
145
145
|
for (const passRenderer of this.passRenderers) {
|
|
146
146
|
passRenderer.resetHistory();
|
|
@@ -306,14 +306,14 @@ export class ShaderPassRenderer {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
/** Renders one `ShaderPass` or `
|
|
309
|
+
/** Renders one `ShaderPass` or `CompositeShaderPass` entry in the chain. */
|
|
310
310
|
class PassRenderer {
|
|
311
311
|
device: Device;
|
|
312
312
|
shaderInputs: ShaderInputs;
|
|
313
313
|
passDefinition: ShaderPassLike;
|
|
314
314
|
renderTargets: Record<string, ManagedRenderTarget>;
|
|
315
315
|
subPassExecutions: EffectiveSubPass[];
|
|
316
|
-
computeRenderer?:
|
|
316
|
+
computeRenderer?: CompositeShaderPassComputeRenderer;
|
|
317
317
|
|
|
318
318
|
constructor(
|
|
319
319
|
device: Device,
|
|
@@ -325,11 +325,11 @@ class PassRenderer {
|
|
|
325
325
|
this.shaderInputs = shaderInputs;
|
|
326
326
|
this.passDefinition = passDefinition;
|
|
327
327
|
|
|
328
|
-
if (
|
|
328
|
+
if (isCompositeShaderPass(passDefinition)) {
|
|
329
329
|
validateRenderTargetNames(passDefinition.name, passDefinition.renderTargets || {});
|
|
330
330
|
this.renderTargets = createManagedRenderTargets(device, passDefinition.renderTargets || {});
|
|
331
331
|
if (supportsComputeOptimization(device, passDefinition)) {
|
|
332
|
-
this.computeRenderer = new
|
|
332
|
+
this.computeRenderer = new CompositeShaderPassComputeRenderer(
|
|
333
333
|
device,
|
|
334
334
|
passDefinition.compute!,
|
|
335
335
|
this.renderTargets,
|
|
@@ -517,17 +517,17 @@ class PassRenderer {
|
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
private createStepExecutions(
|
|
520
|
-
|
|
521
|
-
step:
|
|
520
|
+
compositeShaderPass: CompositeShaderPass,
|
|
521
|
+
step: CompositeShaderPass['steps'][number],
|
|
522
522
|
flipY: boolean
|
|
523
523
|
): EffectiveSubPass[] {
|
|
524
524
|
validateShaderPassDoesNotOwnRenderTargets(
|
|
525
525
|
step.shaderPass,
|
|
526
|
-
`${
|
|
526
|
+
`${compositeShaderPass.name}/${step.shaderPass.name}`
|
|
527
527
|
);
|
|
528
528
|
|
|
529
529
|
return this.createPassExecutions(step.shaderPass, {
|
|
530
|
-
ownerName: `${
|
|
530
|
+
ownerName: `${compositeShaderPass.name}/${step.shaderPass.name}`,
|
|
531
531
|
firstInputs: step.inputs,
|
|
532
532
|
lastOutput: step.output,
|
|
533
533
|
uniformOverrides: step.uniforms,
|
|
@@ -592,8 +592,8 @@ class PassRenderer {
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
/** Executes one optional WebGPU compute replacement before the remaining fragment passes. */
|
|
595
|
-
class
|
|
596
|
-
readonly optimization:
|
|
595
|
+
class CompositeShaderPassComputeRenderer {
|
|
596
|
+
readonly optimization: CompositeShaderPassComputeOptimization;
|
|
597
597
|
|
|
598
598
|
private readonly renderTargets: Record<string, ManagedRenderTarget>;
|
|
599
599
|
private readonly shaderInputs: ShaderInputs;
|
|
@@ -602,7 +602,7 @@ class PipelineComputeRenderer {
|
|
|
602
602
|
|
|
603
603
|
constructor(
|
|
604
604
|
device: Device,
|
|
605
|
-
optimization:
|
|
605
|
+
optimization: CompositeShaderPassComputeOptimization,
|
|
606
606
|
renderTargets: Record<string, ManagedRenderTarget>,
|
|
607
607
|
shaderInputs: ShaderInputs
|
|
608
608
|
) {
|
|
@@ -756,17 +756,20 @@ class SubPassRenderer {
|
|
|
756
756
|
|
|
757
757
|
function getExecutableShaderPasses(shaderPasses: ShaderPassLike[]): ShaderPass[] {
|
|
758
758
|
return shaderPasses.flatMap(shaderPass =>
|
|
759
|
-
|
|
759
|
+
isCompositeShaderPass(shaderPass) ? shaderPass.steps.map(step => step.shaderPass) : [shaderPass]
|
|
760
760
|
);
|
|
761
761
|
}
|
|
762
762
|
|
|
763
|
-
function
|
|
763
|
+
function isCompositeShaderPass(shaderPass: ShaderPassLike): shaderPass is CompositeShaderPass {
|
|
764
764
|
return 'steps' in shaderPass;
|
|
765
765
|
}
|
|
766
766
|
|
|
767
|
-
/** @internal Returns whether a
|
|
768
|
-
export function supportsComputeOptimization(
|
|
769
|
-
|
|
767
|
+
/** @internal Returns whether a composite pass's optional compute path is valid for this device. */
|
|
768
|
+
export function supportsComputeOptimization(
|
|
769
|
+
device: Device,
|
|
770
|
+
compositeShaderPass: CompositeShaderPass
|
|
771
|
+
): boolean {
|
|
772
|
+
const optimization = compositeShaderPass.compute;
|
|
770
773
|
if (!optimization || device.type !== 'webgpu') {
|
|
771
774
|
return false;
|
|
772
775
|
}
|
|
@@ -784,7 +787,7 @@ export function supportsComputeOptimization(device: Device, pipeline: ShaderPass
|
|
|
784
787
|
}
|
|
785
788
|
|
|
786
789
|
return outputNames.every(targetName => {
|
|
787
|
-
const target =
|
|
790
|
+
const target = compositeShaderPass.renderTargets?.[targetName];
|
|
788
791
|
if (!target?.storage) {
|
|
789
792
|
return false;
|
|
790
793
|
}
|
|
@@ -801,7 +804,7 @@ function validateShaderPassDoesNotOwnRenderTargets(
|
|
|
801
804
|
.renderTargets;
|
|
802
805
|
if (renderTargets && Object.keys(renderTargets).length > 0) {
|
|
803
806
|
throw new Error(
|
|
804
|
-
`${ownerName}: ShaderPass.renderTargets is not supported; use
|
|
807
|
+
`${ownerName}: ShaderPass.renderTargets is not supported; use CompositeShaderPass.renderTargets instead`
|
|
805
808
|
);
|
|
806
809
|
}
|
|
807
810
|
}
|
|
@@ -859,7 +862,7 @@ function mergeUniforms(
|
|
|
859
862
|
*
|
|
860
863
|
* Merge order is:
|
|
861
864
|
* 1. persisted renderer-level shader inputs
|
|
862
|
-
* 2. uniforms baked into the
|
|
865
|
+
* 2. uniforms baked into the composite pass or subpass definition
|
|
863
866
|
* 3. per-draw runtime overrides
|
|
864
867
|
*/
|
|
865
868
|
function resolveExecutionUniforms(
|