@luma.gl/engine 9.4.2 → 10.0.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-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 +547 -358
- package/dist/dist.min.js +21 -21
- package/dist/index.cjs +479 -109
- 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 +10 -0
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +129 -65
- 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 +6 -6
- 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 +140 -85
- package/src/passes/shader-pass-renderer.ts +28 -25
package/src/model/model.ts
CHANGED
|
@@ -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!,
|
|
@@ -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
|
|
@@ -311,6 +336,7 @@ export class Model {
|
|
|
311
336
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
312
337
|
_lastDrawTimestamp: number = -1;
|
|
313
338
|
private _bindingTable: ShaderBindingDebugRow[] = [];
|
|
339
|
+
private _pipelineInitialization?: Promise<void>;
|
|
314
340
|
|
|
315
341
|
get [Symbol.toStringTag](): string {
|
|
316
342
|
return 'Model';
|
|
@@ -322,7 +348,7 @@ export class Model {
|
|
|
322
348
|
|
|
323
349
|
constructor(device: Device, props: ModelProps) {
|
|
324
350
|
const defaultShaderAssembler = Model.defaultProps.shaderAssembler;
|
|
325
|
-
const vertexCountSet = props
|
|
351
|
+
const vertexCountSet = Object.hasOwn(props, 'vertexCount');
|
|
326
352
|
this.props = {
|
|
327
353
|
...Model.defaultProps,
|
|
328
354
|
...props,
|
|
@@ -462,56 +488,47 @@ export class Model {
|
|
|
462
488
|
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
463
489
|
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
464
490
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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
|
+
}
|
|
468
505
|
|
|
469
|
-
|
|
506
|
+
private _initializePipelineResources(props: ModelProps): void {
|
|
507
|
+
this.vertexArray = this.device.createVertexArray({
|
|
470
508
|
shaderLayout: this.pipeline.shaderLayout,
|
|
471
509
|
bufferLayout: this.pipeline.bufferLayout
|
|
472
510
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (this.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (props.instanceCount) {
|
|
485
|
-
this.setInstanceCount(props.instanceCount);
|
|
486
|
-
}
|
|
487
|
-
if (props.vertexCount) {
|
|
488
|
-
this.setVertexCount(props.vertexCount);
|
|
489
|
-
}
|
|
490
|
-
if (props.indexBuffer) {
|
|
491
|
-
this.setIndexBuffer(props.indexBuffer);
|
|
492
|
-
}
|
|
493
|
-
if (props.attributes) {
|
|
494
|
-
this.setAttributes(props.attributes);
|
|
495
|
-
}
|
|
496
|
-
if (props.constantAttributes) {
|
|
497
|
-
this.setConstantAttributes(props.constantAttributes);
|
|
498
|
-
}
|
|
499
|
-
if (props.bindings) {
|
|
500
|
-
this.setBindings(props.bindings);
|
|
501
|
-
}
|
|
502
|
-
if (props.transformFeedback) {
|
|
503
|
-
this.transformFeedback = props.transformFeedback;
|
|
504
|
-
}
|
|
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;
|
|
505
520
|
}
|
|
506
521
|
|
|
507
522
|
destroy(): void {
|
|
508
523
|
if (!this._destroyed) {
|
|
509
524
|
// Release pipeline before we destroy the shaders used by the pipeline
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
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
|
+
}
|
|
515
532
|
}
|
|
516
533
|
this._uniformStore.destroy();
|
|
517
534
|
// TODO - mark resource as managed and destroyIfManaged() ?
|
|
@@ -1104,40 +1121,64 @@ export class Model {
|
|
|
1104
1121
|
|
|
1105
1122
|
/** Update pipeline if needed */
|
|
1106
1123
|
_updatePipeline(): RenderPipeline {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
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;
|
|
1117
1142
|
}
|
|
1143
|
+
this._finishPipelineUpdate(update);
|
|
1144
|
+
}
|
|
1145
|
+
return this.pipeline;
|
|
1146
|
+
}
|
|
1118
1147
|
|
|
1119
|
-
|
|
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;
|
|
1120
1162
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
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,
|
|
1125
1177
|
debugShaders: this.props.debugShaders
|
|
1126
1178
|
});
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
fs = vs;
|
|
1131
|
-
} else if (this.fs) {
|
|
1132
|
-
fs = this.shaderFactory.createShader({
|
|
1133
|
-
id: `${this.id}-fragment`,
|
|
1134
|
-
stage: 'fragment',
|
|
1135
|
-
source: this.source || this.fs,
|
|
1136
|
-
debugShaders: this.props.debugShaders
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
1179
|
+
}
|
|
1180
|
+
return {
|
|
1181
|
+
props: {
|
|
1141
1182
|
...this.props,
|
|
1142
1183
|
bindings: undefined,
|
|
1143
1184
|
bufferLayout: this.bufferLayout,
|
|
@@ -1146,21 +1187,35 @@ export class Model {
|
|
|
1146
1187
|
topology: this.topology,
|
|
1147
1188
|
parameters: this.parameters,
|
|
1148
1189
|
bindGroups: undefined,
|
|
1149
|
-
vs,
|
|
1150
|
-
fs
|
|
1151
|
-
}
|
|
1190
|
+
vs: vertexShader,
|
|
1191
|
+
fs: fragmentShader
|
|
1192
|
+
},
|
|
1193
|
+
vertexShader,
|
|
1194
|
+
fragmentShader,
|
|
1195
|
+
previousVertexShader,
|
|
1196
|
+
previousFragmentShader
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1152
1199
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
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
|
+
}
|
|
1157
1210
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
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);
|
|
1162
1218
|
}
|
|
1163
|
-
return this.pipeline;
|
|
1164
1219
|
}
|
|
1165
1220
|
|
|
1166
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(
|