@nodetool-ai/timeline 0.8.11 → 0.8.14
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/.nodetool-build-stamp +1 -1
- package/dist/animation/compile.d.ts +1 -1
- package/dist/animation/compile.d.ts.map +1 -1
- package/dist/animation/compile.js +2 -1
- package/dist/animation/compile.js.map +1 -1
- package/dist/animation/custom.d.ts +3 -1
- package/dist/animation/custom.d.ts.map +1 -1
- package/dist/animation/custom.js +13 -13
- package/dist/animation/custom.js.map +1 -1
- package/dist/audioCrossfade.d.ts +2 -0
- package/dist/audioCrossfade.d.ts.map +1 -1
- package/dist/audioCrossfade.js +8 -3
- package/dist/audioCrossfade.js.map +1 -1
- package/dist/automation.d.ts.map +1 -1
- package/dist/automation.js +28 -26
- package/dist/automation.js.map +1 -1
- package/dist/clipSpeed.js +1 -1
- package/dist/clipSpeed.js.map +1 -1
- package/dist/colorSpaceVersion.d.ts +11 -0
- package/dist/colorSpaceVersion.d.ts.map +1 -0
- package/dist/colorSpaceVersion.js +21 -0
- package/dist/colorSpaceVersion.js.map +1 -0
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +7 -1
- package/dist/defaults.js.map +1 -1
- package/dist/effectMasks.d.ts +43 -0
- package/dist/effectMasks.d.ts.map +1 -0
- package/dist/effectMasks.js +170 -0
- package/dist/effectMasks.js.map +1 -0
- package/dist/harmony/expand.d.ts.map +1 -1
- package/dist/harmony/expand.js +19 -4
- package/dist/harmony/expand.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interchange.d.ts +17 -0
- package/dist/interchange.d.ts.map +1 -1
- package/dist/interchange.js +310 -61
- package/dist/interchange.js.map +1 -1
- package/dist/interchangeImport.d.ts +16 -2
- package/dist/interchangeImport.d.ts.map +1 -1
- package/dist/interchangeImport.js +185 -27
- package/dist/interchangeImport.js.map +1 -1
- package/dist/interchangeMotion.d.ts +49 -0
- package/dist/interchangeMotion.d.ts.map +1 -0
- package/dist/interchangeMotion.js +109 -0
- package/dist/interchangeMotion.js.map +1 -0
- package/dist/interchangeMotionImport.d.ts +84 -0
- package/dist/interchangeMotionImport.d.ts.map +1 -0
- package/dist/interchangeMotionImport.js +204 -0
- package/dist/interchangeMotionImport.js.map +1 -0
- package/dist/keyframes.d.ts +29 -3
- package/dist/keyframes.d.ts.map +1 -1
- package/dist/keyframes.js +93 -30
- package/dist/keyframes.js.map +1 -1
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +140 -0
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/op.d.ts +3 -2
- package/dist/ops/op.d.ts.map +1 -1
- package/dist/ops/op.js +4 -0
- package/dist/ops/op.js.map +1 -1
- package/dist/ops/parse.d.ts.map +1 -1
- package/dist/ops/parse.js +16 -0
- package/dist/ops/parse.js.map +1 -1
- package/dist/ops/types.d.ts +1 -0
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/paramCurves.d.ts +56 -0
- package/dist/paramCurves.d.ts.map +1 -0
- package/dist/paramCurves.js +183 -0
- package/dist/paramCurves.js.map +1 -0
- package/dist/render/canvas2d.d.ts +2 -27
- package/dist/render/canvas2d.d.ts.map +1 -1
- package/dist/render/canvas2d.js +35 -7
- package/dist/render/canvas2d.js.map +1 -1
- package/dist/render/clipAnalysis.d.ts +20 -0
- package/dist/render/clipAnalysis.d.ts.map +1 -0
- package/dist/render/clipAnalysis.js +92 -0
- package/dist/render/clipAnalysis.js.map +1 -0
- package/dist/render/cpuLegacyEffects.d.ts +2 -1
- package/dist/render/cpuLegacyEffects.d.ts.map +1 -1
- package/dist/render/cpuLegacyEffects.js +100 -30
- package/dist/render/cpuLegacyEffects.js.map +1 -1
- package/dist/render/curveTransfer.d.ts +5 -0
- package/dist/render/curveTransfer.d.ts.map +1 -0
- package/dist/render/curveTransfer.js +37 -0
- package/dist/render/curveTransfer.js.map +1 -0
- package/dist/render/deband.d.ts +4 -0
- package/dist/render/deband.d.ts.map +1 -0
- package/dist/render/deband.js +51 -0
- package/dist/render/deband.js.map +1 -0
- package/dist/render/denoise.d.ts +12 -0
- package/dist/render/denoise.d.ts.map +1 -0
- package/dist/render/denoise.js +173 -0
- package/dist/render/denoise.js.map +1 -0
- package/dist/render/effects.d.ts +16 -5
- package/dist/render/effects.d.ts.map +1 -1
- package/dist/render/effects.js +238 -47
- package/dist/render/effects.js.map +1 -1
- package/dist/render/exposure.d.ts +3 -0
- package/dist/render/exposure.d.ts.map +1 -0
- package/dist/render/exposure.js +20 -0
- package/dist/render/exposure.js.map +1 -0
- package/dist/render/frameCompositor.d.ts +28 -2
- package/dist/render/frameCompositor.d.ts.map +1 -1
- package/dist/render/frameCompositor.js +196 -54
- package/dist/render/frameCompositor.js.map +1 -1
- package/dist/render/headlessRender.d.ts +1 -0
- package/dist/render/headlessRender.d.ts.map +1 -1
- package/dist/render/hueSatCurves.d.ts +11 -0
- package/dist/render/hueSatCurves.d.ts.map +1 -0
- package/dist/render/hueSatCurves.js +55 -0
- package/dist/render/hueSatCurves.js.map +1 -0
- package/dist/render/index.d.ts +3 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +3 -0
- package/dist/render/index.js.map +1 -1
- package/dist/render/sceneModel.d.ts +3 -2
- package/dist/render/sceneModel.d.ts.map +1 -1
- package/dist/render/sceneModel.js +24 -7
- package/dist/render/sceneModel.js.map +1 -1
- package/dist/render/secondaryColor.d.ts +12 -0
- package/dist/render/secondaryColor.d.ts.map +1 -0
- package/dist/render/secondaryColor.js +88 -0
- package/dist/render/secondaryColor.js.map +1 -0
- package/dist/render/stabilization.d.ts +29 -0
- package/dist/render/stabilization.d.ts.map +1 -0
- package/dist/render/stabilization.js +185 -0
- package/dist/render/stabilization.js.map +1 -0
- package/dist/render/textLayout.d.ts +4 -2
- package/dist/render/textLayout.d.ts.map +1 -1
- package/dist/render/textLayout.js +5 -3
- package/dist/render/textLayout.js.map +1 -1
- package/dist/render/trackEffects.d.ts.map +1 -1
- package/dist/render/trackEffects.js +8 -1
- package/dist/render/trackEffects.js.map +1 -1
- package/dist/render/vignette.d.ts +7 -0
- package/dist/render/vignette.d.ts.map +1 -0
- package/dist/render/vignette.js +16 -0
- package/dist/render/vignette.js.map +1 -0
- package/dist/scene.d.ts +1 -0
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +1 -0
- package/dist/scene.js.map +1 -1
- package/dist/script.d.ts +4 -2
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +52 -18
- package/dist/script.js.map +1 -1
- package/dist/shotLink.d.ts +2 -1
- package/dist/shotLink.d.ts.map +1 -1
- package/dist/shotLink.js +10 -1
- package/dist/shotLink.js.map +1 -1
- package/dist/slideEdit.d.ts.map +1 -1
- package/dist/slideEdit.js +65 -28
- package/dist/slideEdit.js.map +1 -1
- package/dist/source-merge.d.ts +1 -0
- package/dist/source-merge.d.ts.map +1 -1
- package/dist/source-merge.js +6 -0
- package/dist/source-merge.js.map +1 -1
- package/dist/splitClip.d.ts.map +1 -1
- package/dist/splitClip.js +22 -9
- package/dist/splitClip.js.map +1 -1
- package/dist/takes.d.ts.map +1 -1
- package/dist/takes.js +39 -20
- package/dist/takes.js.map +1 -1
- package/dist/testing/ops.d.ts.map +1 -1
- package/dist/testing/ops.js +20 -0
- package/dist/testing/ops.js.map +1 -1
- package/dist/timeRemap.d.ts +4 -3
- package/dist/timeRemap.d.ts.map +1 -1
- package/dist/timeRemap.js +9 -4
- package/dist/timeRemap.js.map +1 -1
- package/dist/transcriptOps.d.ts +267 -0
- package/dist/transcriptOps.d.ts.map +1 -0
- package/dist/transcriptOps.js +754 -0
- package/dist/transcriptOps.js.map +1 -0
- package/dist/trimClip.d.ts.map +1 -1
- package/dist/trimClip.js +24 -13
- package/dist/trimClip.js.map +1 -1
- package/dist/types.d.ts +289 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -1
- package/package.json +17 -5
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The WebGPU compositing rules every timeline render surface draws through.
|
|
3
|
-
*
|
|
4
|
-
* {@link GpuFrameCompositor} is the whole of it: placement, the effects
|
|
5
|
-
* pre-pass, shape masks, track mattes, transition geometry, the dip solid, and
|
|
6
|
-
* the precomposite pass that lets a group's effects and blend mode act on its
|
|
7
|
-
* children together. It is generic in what a layer's pixels arrive as, because
|
|
8
|
-
* that is the only thing its two hosts disagree about — the server hands it CPU
|
|
9
|
-
* RGBA buffers, the editor hands it `<video>` elements and `ImageBitmap`s — and
|
|
10
|
-
* a rule that lived in both would drift, which is exactly what happened while
|
|
11
|
-
* the browser kept a compositor of its own.
|
|
12
|
-
*
|
|
13
|
-
* {@link HeadlessFrameCompositor} is the server host: CPU pixels in, one
|
|
14
|
-
* frame's RGBA read back out. The editor's host lives in `web/` and differs
|
|
15
|
-
* only in uploading through `copyExternalImageToTexture` and presenting to a
|
|
16
|
-
* swap chain instead of a buffer.
|
|
17
|
-
*
|
|
18
|
-
* An instance is reused across every frame of a render: source textures are
|
|
19
|
-
* kept per layer id (re-uploaded only when their pixels change), the
|
|
20
|
-
* precomposite textures per group id, and the readback buffer is allocated
|
|
21
|
-
* once. Everything the GPU holds is owned by the instance and released in
|
|
22
|
-
* `dispose`, so a throw mid-frame leaks nothing.
|
|
23
|
-
*/
|
|
24
1
|
import { blendModeGpuId } from "@nodetool-ai/gpu";
|
|
25
|
-
import { BLIT_FRAGMENT, FULLSCREEN_QUAD_VERTEX, UNPREMULTIPLY_FRAGMENT, WebGPULayerCompositor, forwardClipMatrixToInverseAffine, placedLayerRect, invertClipPlacement } from "@nodetool-ai/gpu/webgpu";
|
|
2
|
+
import { copyWorkingRows, frameReadbackLayout, BLIT_FRAGMENT, FULLSCREEN_QUAD_VERTEX, UNPREMULTIPLY_FRAGMENT, WebGPULayerCompositor, validateRenderTexture, forwardClipMatrixToInverseAffine, placedLayerRect, invertClipPlacement } from "@nodetool-ai/gpu/webgpu";
|
|
26
3
|
import { cropRectPx, hasCrop } from "../crop.js";
|
|
27
4
|
import { parseCssColorOrBlack } from "./color.js";
|
|
28
|
-
import { WebGPUEffectsProcessor } from "./effects.js";
|
|
5
|
+
import { unsupportedGpuEffectTypes, WebGPUEffectsProcessor } from "./effects.js";
|
|
29
6
|
import { IDENTITY_TRANSFORM, buildTransformMatrix, containBaseScale } from "./transform.js";
|
|
30
7
|
import { transitionTransform } from "./transition.js";
|
|
31
8
|
/** Shader edge codes (see `BLEND_COMPOSITE_FRAGMENT` params2). */
|
|
@@ -167,10 +144,13 @@ const TEXTURE_FORMAT = "rgba8unorm";
|
|
|
167
144
|
*/
|
|
168
145
|
const EMPTY_LAYER = "empty";
|
|
169
146
|
export class GpuFrameCompositor {
|
|
147
|
+
skippedLayerIds = [];
|
|
148
|
+
effectsNotApplied = [];
|
|
170
149
|
device;
|
|
171
150
|
core;
|
|
172
151
|
effects;
|
|
173
152
|
label;
|
|
153
|
+
workingFormat;
|
|
174
154
|
upload;
|
|
175
155
|
retainSources;
|
|
176
156
|
width;
|
|
@@ -195,6 +175,9 @@ export class GpuFrameCompositor {
|
|
|
195
175
|
solids = new Map();
|
|
196
176
|
/** One cropped copy per cropped layer, by layer id — see {@link cropSource}. */
|
|
197
177
|
crops = new Map();
|
|
178
|
+
maxPromotionCacheBytes;
|
|
179
|
+
promotedSources = new Map();
|
|
180
|
+
promotionPipeline = null;
|
|
198
181
|
/** Resolves a premultiplied accumulation to the straight alpha the blend
|
|
199
182
|
* shader reads a source as. Built with the second pass. */
|
|
200
183
|
unpremultiply = null;
|
|
@@ -204,14 +187,19 @@ export class GpuFrameCompositor {
|
|
|
204
187
|
mixUniforms = new Map();
|
|
205
188
|
constructor(device, width, height, options) {
|
|
206
189
|
this.device = device;
|
|
190
|
+
this.maxPromotionCacheBytes = options.maxPromotionCacheBytes ?? 64 * 1024 * 1024;
|
|
191
|
+
if (!(this.maxPromotionCacheBytes >= 0)) {
|
|
192
|
+
throw new Error("Promotion cache byte budget must be nonnegative");
|
|
193
|
+
}
|
|
194
|
+
this.workingFormat = options.workingFormat ?? "rgba8unorm";
|
|
207
195
|
this.width = Math.max(1, Math.floor(width));
|
|
208
196
|
this.height = Math.max(1, Math.floor(height));
|
|
209
197
|
this.label = options.label ?? "timeline";
|
|
210
198
|
this.upload = options.upload;
|
|
211
199
|
this.retainSources = options.retainSources ?? (() => { });
|
|
212
|
-
this.core = new WebGPULayerCompositor(device,
|
|
200
|
+
this.core = new WebGPULayerCompositor(device, this.workingFormat, "linear", this.label);
|
|
213
201
|
this.core.ensureSize(this.width, this.height);
|
|
214
|
-
this.effects = new WebGPUEffectsProcessor(device);
|
|
202
|
+
this.effects = new WebGPUEffectsProcessor(device, this.workingFormat);
|
|
215
203
|
}
|
|
216
204
|
/**
|
|
217
205
|
* Change the frame size. The intermediates are frame-sized, so they are
|
|
@@ -268,6 +256,14 @@ export class GpuFrameCompositor {
|
|
|
268
256
|
* its own and submits that after.
|
|
269
257
|
*/
|
|
270
258
|
composite(layers, precomposites = [], clearValue = { r: 0, g: 0, b: 0, a: 1 }, adjustments = []) {
|
|
259
|
+
this.skippedLayerIds.length = 0;
|
|
260
|
+
const scopes = [...layers, ...layers.flatMap(layer => layer.matte ? [layer.matte.layer] : []), ...precomposites, ...adjustments];
|
|
261
|
+
this.effectsNotApplied = unsupportedGpuEffectTypes(scopes.map(scope => ({ ...scope, effects: "transition" in scope && scope.transition?.effect ? [...scope.effects ?? [], scope.transition.effect] : scope.effects })));
|
|
262
|
+
const groupIds = new Set(precomposites.map(group => group.id));
|
|
263
|
+
for (const scope of scopes) {
|
|
264
|
+
if (scope.precomposeGroupId && !groupIds.has(scope.precomposeGroupId))
|
|
265
|
+
throw new Error(`Timeline group ${scope.precomposeGroupId} is missing`);
|
|
266
|
+
}
|
|
271
267
|
const ordered = [...layers].sort((a, b) => a.zIndex - b.zIndex);
|
|
272
268
|
this.retainOnly(ordered, precomposites, adjustments);
|
|
273
269
|
const readStart = this.core.textureA;
|
|
@@ -305,7 +301,8 @@ export class GpuFrameCompositor {
|
|
|
305
301
|
this.core.beginFrame();
|
|
306
302
|
const texture = this.blendStack(encoder, this.core, stack, readStart, writeStart);
|
|
307
303
|
this.device.queue.submit([encoder.finish()]);
|
|
308
|
-
|
|
304
|
+
this.trimPromotionCache();
|
|
305
|
+
return { texture, drawn, frame: { representation: "gpu-texture", texture, format: this.workingFormat, width: this.width, height: this.height, bytesPerRow: null, alpha: "premultiplied", interpretation: "encoded-sdr" } };
|
|
309
306
|
}
|
|
310
307
|
/**
|
|
311
308
|
* Blend `items` bottom-up over whatever `read` holds, ping-ponging between
|
|
@@ -436,7 +433,15 @@ export class GpuFrameCompositor {
|
|
|
436
433
|
// Crop first: everything below — the effect chain, the shape mask, the
|
|
437
434
|
// contain fit, the border radius — then sees the cropped rectangle as the
|
|
438
435
|
// layer's whole picture, which is what a crop means.
|
|
439
|
-
const src = this.cropSource(layer, uploaded, encoder);
|
|
436
|
+
const src = this.cropSource(layer, this.promoteSource(layer.id, uploaded, encoder), encoder);
|
|
437
|
+
const neighbor = (role) => {
|
|
438
|
+
const id = `${layer.id}#denoise-${role}`;
|
|
439
|
+
const value = this.upload(id, layer.temporalSources[role]);
|
|
440
|
+
if (!value)
|
|
441
|
+
throw new Error(`Noise reduction ${role} frame could not be uploaded`);
|
|
442
|
+
return this.cropSource({ ...layer, id }, this.promoteSource(id, value, encoder), encoder).texture;
|
|
443
|
+
};
|
|
444
|
+
const temporalSources = layer.temporalSources ? { before: neighbor("before"), after: neighbor("after") } : undefined;
|
|
440
445
|
const window = layer.sourceWindow;
|
|
441
446
|
const placement = this.placementOf({
|
|
442
447
|
transform: transitionTransform(layer.transform, layer.transition, this.referenceWidth, this.referenceHeight),
|
|
@@ -450,7 +455,7 @@ export class GpuFrameCompositor {
|
|
|
450
455
|
: layer.effects ?? [];
|
|
451
456
|
const trackEffects = layer.trackEffects ?? [];
|
|
452
457
|
const graded = clipEffects.length > 0 || trackEffects.length > 0
|
|
453
|
-
? this.effects.process(layer.id, src.texture, src.width, src.height, clipEffects, trackEffects, "straight", encoder)
|
|
458
|
+
? this.effects.process(layer.id, src.texture, src.width, src.height, clipEffects, trackEffects, "straight", encoder, temporalSources)
|
|
454
459
|
: src.texture;
|
|
455
460
|
// Both the upload and the effects chain hand back straight alpha, which is
|
|
456
461
|
// what `applyMask` bridges from and what the blend shader reads a source
|
|
@@ -459,6 +464,8 @@ export class GpuFrameCompositor {
|
|
|
459
464
|
const coverage = layer.shapeMask
|
|
460
465
|
? this.upload(`${layer.id}#mask`, layer.shapeMask)
|
|
461
466
|
: null;
|
|
467
|
+
if (layer.shapeMask && !coverage)
|
|
468
|
+
throw new Error(`Timeline layer ${layer.id} mask could not be uploaded`);
|
|
462
469
|
const texture = coverage
|
|
463
470
|
? this.effects.applyMask(`mask:${layer.id}`, graded, src.width, src.height, coverage.texture, coverage.width, coverage.height, "straight", encoder)
|
|
464
471
|
: graded;
|
|
@@ -523,6 +530,63 @@ export class GpuFrameCompositor {
|
|
|
523
530
|
borderRadius: 0
|
|
524
531
|
};
|
|
525
532
|
}
|
|
533
|
+
trimPromotionCache() {
|
|
534
|
+
let bytes = 0;
|
|
535
|
+
for (const entry of this.promotedSources.values()) {
|
|
536
|
+
bytes += entry.width * entry.height * 8;
|
|
537
|
+
}
|
|
538
|
+
for (const [id, entry] of this.promotedSources) {
|
|
539
|
+
if (bytes <= this.maxPromotionCacheBytes) {
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
entry.texture.destroy();
|
|
543
|
+
this.promotedSources.delete(id);
|
|
544
|
+
bytes -= entry.width * entry.height * 8;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
promoteSource(id, source, encoder) {
|
|
548
|
+
if (this.workingFormat === "rgba8unorm" || source.texture.format === this.workingFormat) {
|
|
549
|
+
return source;
|
|
550
|
+
}
|
|
551
|
+
let target = this.promotedSources.get(id);
|
|
552
|
+
if (!target || target.width !== source.width || target.height !== source.height) {
|
|
553
|
+
target?.texture.destroy();
|
|
554
|
+
target = {
|
|
555
|
+
width: source.width,
|
|
556
|
+
height: source.height,
|
|
557
|
+
texture: this.device.createTexture({
|
|
558
|
+
label: `${this.label}-promoted-${id}`,
|
|
559
|
+
size: { width: source.width, height: source.height },
|
|
560
|
+
format: this.workingFormat,
|
|
561
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC
|
|
562
|
+
})
|
|
563
|
+
};
|
|
564
|
+
this.promotedSources.set(id, target);
|
|
565
|
+
}
|
|
566
|
+
if (!this.promotionPipeline) {
|
|
567
|
+
const module = this.device.createShaderModule({ code: `${FULLSCREEN_QUAD_VERTEX}\n${BLIT_FRAGMENT}` });
|
|
568
|
+
this.promotionPipeline = this.device.createRenderPipeline({
|
|
569
|
+
layout: "auto",
|
|
570
|
+
vertex: { module, entryPoint: "vs_main" },
|
|
571
|
+
fragment: { module, entryPoint: "fs_blit", targets: [{ format: this.workingFormat }] },
|
|
572
|
+
primitive: { topology: "triangle-strip" }
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
// Copy encoded straight RGBA without filtering or premultiplication. Leaf
|
|
576
|
+
// filtering must still interpolate straight alpha in the blend shader.
|
|
577
|
+
const pass = encoder.beginRenderPass({ colorAttachments: [{
|
|
578
|
+
view: target.texture.createView(), loadOp: "clear", storeOp: "store",
|
|
579
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 }
|
|
580
|
+
}] });
|
|
581
|
+
pass.setPipeline(this.promotionPipeline);
|
|
582
|
+
pass.setBindGroup(0, this.device.createBindGroup({
|
|
583
|
+
layout: this.promotionPipeline.getBindGroupLayout(0),
|
|
584
|
+
entries: [{ binding: 0, resource: source.texture.createView() }]
|
|
585
|
+
}));
|
|
586
|
+
pass.draw(4);
|
|
587
|
+
pass.end();
|
|
588
|
+
return target;
|
|
589
|
+
}
|
|
526
590
|
/**
|
|
527
591
|
* The layer's pixels narrowed to its crop rectangle, as a texture of exactly
|
|
528
592
|
* that size. Returns the upload untouched when there is no usable crop, which
|
|
@@ -548,13 +612,13 @@ export class GpuFrameCompositor {
|
|
|
548
612
|
}
|
|
549
613
|
const rect = cropRectPx(layer.crop, uploaded.width, uploaded.height);
|
|
550
614
|
let entry = this.crops.get(layer.id);
|
|
551
|
-
if (!entry || entry.width !== rect.width || entry.height !== rect.height) {
|
|
615
|
+
if (!entry || entry.width !== rect.width || entry.height !== rect.height || entry.texture.format !== uploaded.texture.format) {
|
|
552
616
|
entry?.texture.destroy();
|
|
553
617
|
entry = {
|
|
554
618
|
texture: this.device.createTexture({
|
|
555
619
|
label: `${this.label}-crop-${layer.id}`,
|
|
556
620
|
size: { width: rect.width, height: rect.height },
|
|
557
|
-
format:
|
|
621
|
+
format: uploaded.texture.format,
|
|
558
622
|
usage: GPUTextureUsage.TEXTURE_BINDING |
|
|
559
623
|
GPUTextureUsage.COPY_DST |
|
|
560
624
|
GPUTextureUsage.COPY_SRC |
|
|
@@ -603,8 +667,10 @@ export class GpuFrameCompositor {
|
|
|
603
667
|
const stack = [];
|
|
604
668
|
for (const layer of layers) {
|
|
605
669
|
const item = this.resolveLayer(layer, encoder);
|
|
606
|
-
if (!item)
|
|
670
|
+
if (!item) {
|
|
671
|
+
this.skippedLayerIds.push(layer.id);
|
|
607
672
|
continue;
|
|
673
|
+
}
|
|
608
674
|
drawn += 1;
|
|
609
675
|
if (item === EMPTY_LAYER)
|
|
610
676
|
continue;
|
|
@@ -635,8 +701,10 @@ export class GpuFrameCompositor {
|
|
|
635
701
|
};
|
|
636
702
|
for (const layer of layers) {
|
|
637
703
|
const item = this.resolveLayer(layer, encoder);
|
|
638
|
-
if (!item)
|
|
704
|
+
if (!item) {
|
|
705
|
+
this.skippedLayerIds.push(layer.id);
|
|
639
706
|
continue;
|
|
707
|
+
}
|
|
640
708
|
drawn += 1;
|
|
641
709
|
if (item === EMPTY_LAYER)
|
|
642
710
|
continue;
|
|
@@ -689,6 +757,8 @@ export class GpuFrameCompositor {
|
|
|
689
757
|
? this.upload(`${adjustment.id}#adjustmask`, adjustment.shapeMask)
|
|
690
758
|
: null
|
|
691
759
|
};
|
|
760
|
+
if (adjustment.shapeMask && !item.coverage)
|
|
761
|
+
throw new Error(`Timeline adjustment ${adjustment.id} mask could not be uploaded`);
|
|
692
762
|
if (adjustment.wipe)
|
|
693
763
|
item.mask = adjustment.wipe;
|
|
694
764
|
return item;
|
|
@@ -845,7 +915,7 @@ export class GpuFrameCompositor {
|
|
|
845
915
|
precompositeCore() {
|
|
846
916
|
let core = this.precompCore;
|
|
847
917
|
if (!core) {
|
|
848
|
-
core = new WebGPULayerCompositor(this.device,
|
|
918
|
+
core = new WebGPULayerCompositor(this.device, this.workingFormat, "linear", `${this.label}-precomp`);
|
|
849
919
|
core.ensureSize(this.width, this.height);
|
|
850
920
|
this.precompCore = core;
|
|
851
921
|
}
|
|
@@ -857,7 +927,7 @@ export class GpuFrameCompositor {
|
|
|
857
927
|
target = this.device.createTexture({
|
|
858
928
|
label: `${this.label}-precomp-target-${id}`,
|
|
859
929
|
size: { width: this.width, height: this.height },
|
|
860
|
-
format:
|
|
930
|
+
format: this.workingFormat,
|
|
861
931
|
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
862
932
|
});
|
|
863
933
|
this.precompTargets.set(id, target);
|
|
@@ -897,7 +967,7 @@ export class GpuFrameCompositor {
|
|
|
897
967
|
fragment: {
|
|
898
968
|
module,
|
|
899
969
|
entryPoint: "fs_mix",
|
|
900
|
-
targets: [{ format:
|
|
970
|
+
targets: [{ format: this.workingFormat }]
|
|
901
971
|
},
|
|
902
972
|
primitive: { topology: "triangle-strip" }
|
|
903
973
|
});
|
|
@@ -910,7 +980,7 @@ export class GpuFrameCompositor {
|
|
|
910
980
|
if (!pipeline) {
|
|
911
981
|
const module = this.device.createShaderModule({
|
|
912
982
|
label: `${this.label}-unpremultiply`,
|
|
913
|
-
code: `${FULLSCREEN_QUAD_VERTEX}\n${UNPREMULTIPLY_FRAGMENT}`
|
|
983
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${this.workingFormat === "rgba8unorm" ? UNPREMULTIPLY_FRAGMENT : UNPREMULTIPLY_FLOAT_FRAGMENT}`
|
|
914
984
|
});
|
|
915
985
|
pipeline = this.device.createRenderPipeline({
|
|
916
986
|
label: `${this.label}-unpremultiply`,
|
|
@@ -919,7 +989,7 @@ export class GpuFrameCompositor {
|
|
|
919
989
|
fragment: {
|
|
920
990
|
module,
|
|
921
991
|
entryPoint: "fs_unpremultiply",
|
|
922
|
-
targets: [{ format:
|
|
992
|
+
targets: [{ format: this.workingFormat }]
|
|
923
993
|
},
|
|
924
994
|
primitive: { topology: "triangle-strip" }
|
|
925
995
|
});
|
|
@@ -935,6 +1005,10 @@ export class GpuFrameCompositor {
|
|
|
935
1005
|
const effectKeys = new Set();
|
|
936
1006
|
const visit = (layer) => {
|
|
937
1007
|
live.add(layer.id);
|
|
1008
|
+
if (layer.temporalSources) {
|
|
1009
|
+
live.add(`${layer.id}#denoise-before`);
|
|
1010
|
+
live.add(`${layer.id}#denoise-after`);
|
|
1011
|
+
}
|
|
938
1012
|
effectKeys.add(layer.id);
|
|
939
1013
|
if (layer.shapeMask) {
|
|
940
1014
|
live.add(`${layer.id}#mask`);
|
|
@@ -968,6 +1042,12 @@ export class GpuFrameCompositor {
|
|
|
968
1042
|
}
|
|
969
1043
|
}
|
|
970
1044
|
this.retainSources(live);
|
|
1045
|
+
for (const [id, entry] of this.promotedSources) {
|
|
1046
|
+
if (!live.has(id)) {
|
|
1047
|
+
entry.texture.destroy();
|
|
1048
|
+
this.promotedSources.delete(id);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
971
1051
|
for (const [id, entry] of this.crops) {
|
|
972
1052
|
if (!live.has(id)) {
|
|
973
1053
|
entry.texture.destroy();
|
|
@@ -997,6 +1077,9 @@ export class GpuFrameCompositor {
|
|
|
997
1077
|
texture.destroy();
|
|
998
1078
|
this.solids.clear();
|
|
999
1079
|
this.effects.dispose();
|
|
1080
|
+
for (const entry of this.promotedSources.values())
|
|
1081
|
+
entry.texture.destroy();
|
|
1082
|
+
this.promotedSources.clear();
|
|
1000
1083
|
for (const entry of this.crops.values())
|
|
1001
1084
|
entry.texture.destroy();
|
|
1002
1085
|
this.crops.clear();
|
|
@@ -1005,8 +1088,6 @@ export class GpuFrameCompositor {
|
|
|
1005
1088
|
this.precompCore = null;
|
|
1006
1089
|
}
|
|
1007
1090
|
}
|
|
1008
|
-
/** `copyTextureToBuffer` requires a 256-byte-aligned `bytesPerRow`. */
|
|
1009
|
-
const ROW_ALIGNMENT = 256;
|
|
1010
1091
|
/**
|
|
1011
1092
|
* The accumulation format for a motion-blurred frame.
|
|
1012
1093
|
*
|
|
@@ -1026,6 +1107,10 @@ const BLUR_ACCUMULATION_FORMAT = "rgba16float";
|
|
|
1026
1107
|
* buffer the finished frame is copied through.
|
|
1027
1108
|
*/
|
|
1028
1109
|
export class HeadlessFrameCompositor {
|
|
1110
|
+
/** Enabled effects omitted by the GPU chain in the latest frame. */
|
|
1111
|
+
get effectsNotApplied() { return this.compositor.effectsNotApplied; }
|
|
1112
|
+
/** Layers omitted because their source or matte could not be uploaded. */
|
|
1113
|
+
get skippedLayerIds() { return this.compositor.skippedLayerIds; }
|
|
1029
1114
|
device;
|
|
1030
1115
|
compositor;
|
|
1031
1116
|
width;
|
|
@@ -1051,11 +1136,19 @@ export class HeadlessFrameCompositor {
|
|
|
1051
1136
|
/** Shared straight-alpha resolve target and pipeline for both render paths. */
|
|
1052
1137
|
resolveTarget = null;
|
|
1053
1138
|
resolvePipeline = null;
|
|
1054
|
-
|
|
1139
|
+
ditherDelivery;
|
|
1140
|
+
constructor(device, width, height, options = {}) {
|
|
1055
1141
|
this.device = device;
|
|
1142
|
+
this.ditherDelivery = options.workingFormat === "rgba16float";
|
|
1056
1143
|
this.width = Math.max(1, Math.floor(width));
|
|
1057
1144
|
this.height = Math.max(1, Math.floor(height));
|
|
1145
|
+
const layout = frameReadbackLayout(this.width, this.height, "rgba8unorm");
|
|
1146
|
+
if (layout.byteLength > device.limits.maxBufferSize) {
|
|
1147
|
+
throw new Error(`Timeline readback exceeds device buffer limit ${device.limits.maxBufferSize}`);
|
|
1148
|
+
}
|
|
1149
|
+
validateRenderTexture(device, this.width, this.height, options.workingFormat ?? "rgba8unorm", GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST);
|
|
1058
1150
|
this.compositor = new GpuFrameCompositor(device, this.width, this.height, {
|
|
1151
|
+
...options,
|
|
1059
1152
|
label: "timeline-headless",
|
|
1060
1153
|
upload: (id, pixels) => this.uploadPixels(id, pixels),
|
|
1061
1154
|
retainSources: (live) => {
|
|
@@ -1067,14 +1160,22 @@ export class HeadlessFrameCompositor {
|
|
|
1067
1160
|
}
|
|
1068
1161
|
}
|
|
1069
1162
|
});
|
|
1070
|
-
this.bytesPerRow =
|
|
1071
|
-
Math.ceil((this.width * 4) / ROW_ALIGNMENT) * ROW_ALIGNMENT;
|
|
1163
|
+
this.bytesPerRow = layout.bytesPerRow;
|
|
1072
1164
|
const makeReadback = (index) => device.createBuffer({
|
|
1073
1165
|
label: `timeline-headless-readback-${index}`,
|
|
1074
1166
|
size: this.bytesPerRow * this.height,
|
|
1075
1167
|
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
1076
1168
|
});
|
|
1077
|
-
|
|
1169
|
+
let first;
|
|
1170
|
+
try {
|
|
1171
|
+
first = makeReadback(0);
|
|
1172
|
+
this.readbacks = [first, makeReadback(1)];
|
|
1173
|
+
}
|
|
1174
|
+
catch (error) {
|
|
1175
|
+
first?.destroy();
|
|
1176
|
+
this.compositor.dispose();
|
|
1177
|
+
throw error;
|
|
1178
|
+
}
|
|
1078
1179
|
}
|
|
1079
1180
|
/**
|
|
1080
1181
|
* Set the sequence resolution a stored transform is expressed against, for
|
|
@@ -1109,6 +1210,31 @@ export class HeadlessFrameCompositor {
|
|
|
1109
1210
|
this.device.queue.submit([encoder.finish()]);
|
|
1110
1211
|
return this.readMapped(readback);
|
|
1111
1212
|
}
|
|
1213
|
+
/** Capture owned, tightly packed working samples before alpha resolve or delivery. */
|
|
1214
|
+
async renderWorkingFrame(layers, precomposites = [], options = {}, adjustments = []) {
|
|
1215
|
+
const { frame } = this.compositor.composite(layers, precomposites, { r: 0, g: 0, b: 0, a: options.alpha ? 0 : 1 }, adjustments);
|
|
1216
|
+
if (frame.representation !== "gpu-texture") {
|
|
1217
|
+
throw new Error("Compositor must return a GPU working frame");
|
|
1218
|
+
}
|
|
1219
|
+
const { format, texture, width, height, alpha, interpretation } = frame;
|
|
1220
|
+
const layout = frameReadbackLayout(width, height, format);
|
|
1221
|
+
const buffer = this.device.createBuffer({
|
|
1222
|
+
size: layout.byteLength, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
1223
|
+
});
|
|
1224
|
+
try {
|
|
1225
|
+
const encoder = this.device.createCommandEncoder();
|
|
1226
|
+
encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow: layout.bytesPerRow }, { width, height });
|
|
1227
|
+
this.device.queue.submit([encoder.finish()]);
|
|
1228
|
+
await buffer.mapAsync(GPUMapMode.READ);
|
|
1229
|
+
const metadata = { width, height, alpha, interpretation, bytesPerRow: layout.rowBytes };
|
|
1230
|
+
return format === "rgba16float"
|
|
1231
|
+
? { ...metadata, representation: format, data: copyWorkingRows(buffer.getMappedRange(), width, height, format) }
|
|
1232
|
+
: { ...metadata, representation: format, data: copyWorkingRows(buffer.getMappedRange(), width, height, format) };
|
|
1233
|
+
}
|
|
1234
|
+
finally {
|
|
1235
|
+
buffer.destroy();
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1112
1238
|
/**
|
|
1113
1239
|
* Composite every instant of one shutter window and return their average as
|
|
1114
1240
|
* straight-alpha RGBA8 — a motion-blurred frame (D10).
|
|
@@ -1278,7 +1404,7 @@ export class HeadlessFrameCompositor {
|
|
|
1278
1404
|
if (!this.resolvePipeline) {
|
|
1279
1405
|
const module = this.device.createShaderModule({
|
|
1280
1406
|
label: "timeline-headless-resolve",
|
|
1281
|
-
code: `${FULLSCREEN_QUAD_VERTEX}\n${UNPREMULTIPLY_FRAGMENT}`
|
|
1407
|
+
code: `${FULLSCREEN_QUAD_VERTEX}\n${this.ditherDelivery ? DITHERED_DELIVERY_FRAGMENT : UNPREMULTIPLY_FRAGMENT}`
|
|
1282
1408
|
});
|
|
1283
1409
|
this.resolvePipeline = this.device.createRenderPipeline({
|
|
1284
1410
|
label: "timeline-headless-resolve",
|
|
@@ -1303,13 +1429,7 @@ export class HeadlessFrameCompositor {
|
|
|
1303
1429
|
async readMapped(readback) {
|
|
1304
1430
|
await readback.mapAsync(GPUMapMode.READ);
|
|
1305
1431
|
try {
|
|
1306
|
-
|
|
1307
|
-
const rgba = new Uint8Array(this.width * this.height * 4);
|
|
1308
|
-
const rowBytes = this.width * 4;
|
|
1309
|
-
for (let row = 0; row < this.height; row++) {
|
|
1310
|
-
rgba.set(mapped.subarray(row * this.bytesPerRow, row * this.bytesPerRow + rowBytes), row * rowBytes);
|
|
1311
|
-
}
|
|
1312
|
-
return rgba;
|
|
1432
|
+
return copyWorkingRows(readback.getMappedRange(), this.width, this.height, "rgba8unorm");
|
|
1313
1433
|
}
|
|
1314
1434
|
finally {
|
|
1315
1435
|
readback.unmap();
|
|
@@ -1336,7 +1456,7 @@ export class HeadlessFrameCompositor {
|
|
|
1336
1456
|
}),
|
|
1337
1457
|
width,
|
|
1338
1458
|
height,
|
|
1339
|
-
version:
|
|
1459
|
+
version: undefined
|
|
1340
1460
|
};
|
|
1341
1461
|
this.sources.set(id, entry);
|
|
1342
1462
|
}
|
|
@@ -1376,4 +1496,26 @@ function dipColorBytes(color) {
|
|
|
1376
1496
|
b: Math.round(b * 255)
|
|
1377
1497
|
};
|
|
1378
1498
|
}
|
|
1499
|
+
// Delivery coordinates follow all scene resampling. Working captures use neither
|
|
1500
|
+
// this shader nor its byte target. Match native DeliveryFrame's centered tile.
|
|
1501
|
+
const UNPREMULTIPLY_RETURN = "return floor(straight * 255.0 + vec4f(0.5)) / 255.0;";
|
|
1502
|
+
/** Replaces `search` in `source`, failing loudly when the shared shader no longer contains it. */
|
|
1503
|
+
function replaceShaderText(source, search, replacement) {
|
|
1504
|
+
if (!source.includes(search)) {
|
|
1505
|
+
throw new Error(`UNPREMULTIPLY_FRAGMENT no longer contains: ${search}`);
|
|
1506
|
+
}
|
|
1507
|
+
return source.replace(search, replacement);
|
|
1508
|
+
}
|
|
1509
|
+
// The shared resolve rounds to 8 bits for an RGBA8 target. A float working
|
|
1510
|
+
// target keeps the straight value, so a precomposite does not lose precision.
|
|
1511
|
+
const UNPREMULTIPLY_FLOAT_FRAGMENT = replaceShaderText(UNPREMULTIPLY_FRAGMENT, UNPREMULTIPLY_RETURN, "return straight;");
|
|
1512
|
+
const DITHERED_DELIVERY_FRAGMENT = replaceShaderText(replaceShaderText(UNPREMULTIPLY_FRAGMENT, "@location(0) uv: vec2f)", "@location(0) uv: vec2f, @builtin(position) position: vec4f)"), UNPREMULTIPLY_RETURN, `var rank = 0u;
|
|
1513
|
+
for (var bit = 0u; bit < 3u; bit++) {
|
|
1514
|
+
let a = (u32(position.x) >> bit) & 1u;
|
|
1515
|
+
let b = (u32(position.y) >> bit) & 1u;
|
|
1516
|
+
rank |= ((a ^ b) * 2u + b) << (4u - bit * 2u);
|
|
1517
|
+
}
|
|
1518
|
+
let noise = (f32(rank) + 0.5) / 64.0 - 0.5;
|
|
1519
|
+
let rgb = clamp(c.rgb / c.a, vec3f(0.0), vec3f(1.0));
|
|
1520
|
+
return vec4f(floor(rgb * 255.0 + noise + 0.5) / 255.0, c.a);`);
|
|
1379
1521
|
//# sourceMappingURL=frameCompositor.js.map
|