Introducing a new way to review your PRs.

Read the announcement

walterlow / freecut

FreeCut is a professional-grade video editor that runs entirely in your browser. Professional video editing, zero installation. Create stunning videos with multi-track editing, keyframe animations, real-time preview, and high-quality exports.

View on GitHub

19 documents · Updated Oct 30, 2026

docs / gpu-rendering-pipeline

GPU rendering pipeline

The GPU rendering pipeline turns timeline items into visual pixels for preview and export. It keeps media, effects, masks, shapes, text, nested compositions, and transitions in a shared WebGPU flow when their features are supported. The pipeline manager creates these stages around one GPU device, while the preview system selects the GPU path only when browser playback cannot show the required result. See composition runtime for frame and item orchestration, and playback engine for time and source-frame control.

Pipeline model

Frame assembly

The frame assembly flow prepares each visible item in timeline order. A source becomes a GPU texture, an effect chain or mask changes that texture, and the compositor combines the result with the layers below it. A transition uses two prepared clip images instead of one. The final image can stay GPU-native for later stages or be copied to a canvas for presentation.

The diagram shows the main path from timeline content to a presented frame.

flowchart LR
  A[Timeline item] --> B[Prepare source and transform]
  B --> C{Visual type}
  C -->|Media or composition| D[Upload or use GPU texture]
  C -->|Shape| E[Render shape]
  C -->|Text| F[Layout and render glyphs]
  D --> G[Apply effects]
  E --> G
  F --> G
  G --> H[Build and combine masks]
  H --> I[Composite layers]
  J[Adjacent clip pair] --> K[Render transition]
  K --> I
  I --> L[Canvas or GPU texture output]

Preview presentation may use the browser player for ordinary frames. It keeps a rendered overlay active around GPU-only content such as enabled GPU effects, non-normal blend modes, corner pins, active text motion, and some transition or nested-composition frames. This boundary lets ordinary playback remain simple without losing visual features that need the rendered path.

References: src/…/gpu-pipeline-manager.ts• L13-25 src/…/use-gpu-effects-overlay.ts• L47-73 src/…/use-gpu-effects-overlay.ts• L223-249

Pipeline ownership

The GPU pipeline manager owns the device-derived stages and their shared output and texture caches. The effects stage is the device owner, so the other stages start only after GPU setup succeeds. Creation is lazy. This avoids paying for GPU resources when a frame does not need them.

The same manager also owns the composite canvas and the lifetime of text and bitmap-mask textures. Disposal tears down the compositor resources before the device-owned effect resources. A caller that uses a stage must therefore use the manager lifecycle rather than create unrelated device resources.

References: src/…/gpu-pipeline-manager.ts• L27-59 src/…/gpu-pipeline-manager.ts• L61-111 src/…/gpu-pipeline-manager.ts• L160-192

Render delivery

The render delivery layer carries composition output to browser export without changing how a frame is assembled. It resolves export settings once, checks whether the browser can encode the selected video format, and sends each render through a worker when possible.

When a worker cannot handle a composition or is not available, the same request moves to the main thread. This keeps the canvas render path and export result consistent while allowing the runtime to choose the available execution path.

The diagram shows how resolved export settings reach the frame renderer and encoder.

flowchart LR
  A[Export settings] --> B[Resolve format and codec]
  B --> C{Worker available}
  C -->|Yes| D[Worker render]
  C -->|No or unsupported composition| E[Main-thread render]
  D --> F[Canvas frames]
  E --> F
  F --> G[Browser encoder]
  G --> H[Video or audio output]

References: src/…/render-pipeline.ts• L86-149 src/…/render-pipeline.ts• L248-304 src/…/client-renderer.ts• L164-199

Visual content stages

Media and nested compositions

The media stage places an image, video, canvas, frame, or existing GPU texture into the output space. It applies the source crop, destination rectangle, transform, opacity, rotation, flips, feather, rounded corners, corner pin, and optional mask. A nested composition follows the same idea: its visible children are rendered into a texture, then that texture acts as one item in the parent composition.

Video can use a zero-copy external texture when the browser supports it. Other sources use a GPU upload. If the source is not ready or its size does not match the output target, the stage reports failure so the caller can use another render path.

References: src/…/media-render-pipeline.ts• L3-48 src/…/media-render-pipeline.ts• L230-299 src/…/gpu.ts• L181-232 src/…/gpu.ts• L951-1099

Effects

The effects stage applies an ordered list of enabled GPU effects to one image. Each effect has a registered definition with a category, parameters, shader entry point, and parameter packing rule. The supported groups are color, blur, distortion, stylize, and keying. A normal effect reads one image and writes the next image. A compute effect can use a separate compute pass when it must write data beyond the current pixel.

Adjacent supported color effects can share one pass, while effects with different data or processing needs keep their own pass. This reduces work without changing the order of the effect chain. Effects may also use an auxiliary data texture for values such as curves or color lookup data. The stage updates that data only when the effect parameters change.

The stage supports GPU-native output for transitions and compositing. A caller can keep the effected image in a GPU texture instead of sending it through a canvas first.

References: src/…/types.ts• L15-75 src/…/registry.ts• L10-18 src/…/registry.ts• L33-69 src/…/effects-pipeline.ts• L477-595 src/…/effects-pipeline.ts• L704-858 src/…/effects-pipeline.ts• L1027-1071

Masks

Masks turn shape or bitmap content into alpha that limits a layer. A mask applies only to tracks below it in the composition order. The GPU path renders supported shape masks or uploads bitmap masks, then combines multiple masks by multiplying their alpha values. Each mask can invert its own contribution before the combine step.

When no mask exists, a one-pixel white texture acts as the fully visible mask. This keeps the compositor input contract the same for masked and unmasked layers. SVG masks with feather can require raster work outside the active playback path, so mask policy decides when that work is safe.

References: src/…/mask-scope.ts• L1-3 src/…/mask-texture-manager.ts• L7-33 src/…/mask-combine-pipeline.ts• L64-108 src/…/gpu.ts• L1192-1217 src/…/mask-rendering-policy.ts• L1-13

Shapes

The shape stage draws vector-like items directly into a GPU texture. It supports rectangles, circles, ellipses, triangles, polygons, stars, hearts, and paths. Shape parameters control fill, gradient, stroke, corner radius, rotation, opacity, path trim, and taper. Closed paths can provide a fill; open paths serve as strokes.

The stage uses analytic shape rules for common forms and a bounded list of path vertices for custom paths. The item preparation layer checks path complexity, stroke style, color values, and other limits before selecting this path. Unsupported shape features return control to a non-GPU renderer instead of producing a partial result.

References: src/…/shape-render-pipeline.ts• L4-44 src/…/shape-render-pipeline.ts• L300-380 src/…/gpu.ts• L1307-1354

Text

The text stage shares the repository's text layout rules with other render paths, then draws packed glyphs from a GPU atlas. The atlas stores glyph distance data so the shader can produce smooth fill edges, strokes, shadows, backgrounds, and underlines. Inline text runs keep their own colors and underline state.

Text motion changes glyph positions and alpha for the active frame. Settled text can use a texture cache. Motion-active text bypasses that cache because its pixels change per frame, while the glyph atlas remains reusable. This keeps the visual result aligned with the text timeline without treating every text frame as a permanent cache entry.

References: src/…/glyph-atlas-text-pipeline.ts• L14-33 src/…/glyph-atlas-text-pipeline.ts• L157-165 src/…/glyph-atlas-text-pipeline.ts• L268-309 src/…/gpu.ts• L773-895

Transitions

The transition stage changes one clip into the next by sampling two participant textures in one shader pass. A transition definition supplies its registered identifier, shader, optional parameters, and direction handling. The registry covers dissolves, fades, wipes, slides, flips, and several stylized variants.

The stage can accept canvases or existing GPU textures. Canvas participants are uploaded when needed, while existing GPU participants use a zero-upload path. The result can go directly to a canvas or to a caller-owned texture for later compositing.

References: src/…/transition-pipeline.ts• L13-18 src/…/transition-pipeline.ts• L58-146 src/…/transition-pipeline.ts• L371-522 src/…/registry.ts• L27-60

Layer compositing

The compositor combines prepared layers from bottom to top. For each layer it applies opacity, blend mode, position, scale, rotation, perspective, aspect correction, and mask alpha. It uses two working textures that swap after each layer, so the current composite becomes the base for the next layer.

Video may enter through an external-texture path for zero-copy sampling. A final blit copies the composite to the configured canvas and converts the internal straight-alpha result to the canvas premultiplied-alpha form. The result is therefore suitable for both normal images and transparent composition layers.

References: src/…/compositor-pipeline.ts• L1-12 src/…/compositor-pipeline.ts• L432-537 src/…/compositor-pipeline.ts• L540-578 src/…/compositor-pipeline.ts• L601-610

Color analysis views

Scopes

Scopes are GPU views of the current image for color review rather than content layers in the final composition. The scope renderer uploads the source canvas once, then delegates to histogram, waveform, and vectorscope views. It carries the color matrix coefficients and legal range used to interpret the source.

Histogram and waveform stages first accumulate pixel data with compute work, then draw the view from those accumulators. The vectorscope maps color differences into chroma space before it draws the trace and guide marks. The renderer also has an ImageData upload fallback when a direct canvas upload is not available.

References: src/…/scope-renderer.ts• L10-22 src/…/scope-renderer.ts• L44-63 src/…/scope-renderer.ts• L80-133 src/…/histogram-scope.ts• L1-5 src/…/waveform-scope.ts• L1-5 src/…/vectorscope-scope.ts• L1-5

Shared rendering utilities

Fullscreen pass contract

Most image stages use one shared fullscreen-quad contract. A pass draws six vertices without a vertex buffer and receives top-left-origin UV coordinates. The shared canvas helper starts the render pass, binds the stage resources, draws the quad, and can either submit the command buffer or let a larger pass group commands.

This common contract lets effects, transitions, mask combine, media blend, and final blit stages focus on pixel behavior instead of defining their own screen geometry.

References: src/…/fullscreen-quad.ts• L1-13 src/…/fullscreen-canvas-pass.ts• L1-32 src/…/scope-render-pass.ts• L55-87

Texture reuse

The texture pool reuses released textures by width, height, and format. It keeps in-use textures safe, limits idle textures per key, and removes old idle entries when the byte budget is exceeded. Scratch textures used for effects, masks, and intermediate layer results should follow acquire and release ownership so the pool can control memory use.

Texture reuse reduces allocation work across frames, but it does not change the rule that a stage must receive textures with matching dimensions and compatible formats. A stage that owns a texture cache or a per-frame texture must release or destroy it at the end of its ownership period.

References: src/…/gpu-texture-pool.ts• L15-30 src/…/gpu-texture-pool.ts• L60-133 src/…/gpu.ts• L1139-1276

Curve and lookup data

Shared curve utilities turn effect controls into stable channel curves and then bake the result into a 256-sample RGBA lookup texture. The effects stage samples that texture as part of the color effect. The utility accepts both current multi-point controls and older two-point values, which keeps existing project data usable while the visual pipeline uses one lookup form.

References: src/…/gpu-curves.ts• L219-227 src/…/gpu-curves.ts• L281-334 src/…/types.ts• L25-36

Change checklist

When these files or sections are changed, remember to consider these:

  • Add a GPU effect only when its registry definition, parameter packing, shader bindings, and any data-texture key use the same contract.
  • Change a source or output size only with the media, effect, transition, mask, and compositor texture checks in mind. These stages reject mismatched dimensions.
  • Change alpha or blend behavior in both the layer compositor and the direct media/effect paths. Canvas output uses premultiplied alpha while internal effect and composite textures use straight alpha.
  • Add a shape or mask feature only after updating GPU eligibility checks. An unsupported feature must continue to select the non-GPU render path.
  • Change text layout or style inputs with the GPU text cache key and motion-text cache bypass in mind. A missing key field can reuse stale pixels.
  • Add a transition only when its registry identifier and transition definition match the timeline transition data that selects it.
  • Change scope color interpretation with the matrix and range values passed from the scope facade to all three scope views.
  • Change device setup or teardown with the pipeline manager's lazy creation order and shared device ownership in mind.
  • Change export settings or codec support with both worker rendering and main-thread fallback in mind. The two paths must receive the same resolved settings.

Important failure modes

TriggerConsequenceGuard
WebGPU adapter, device, or required pipeline is unavailableThe GPU stage returns no result and preview or export must use another rendererCreate stages through the pipeline manager and keep the non-GPU path available.
Source, intermediate, or output texture dimensions do not matchMedia, effects, transitions, or mask combine return failure instead of rendering the framePass one resolved render size through the full stage chain.
A video external texture cannot be imported or is not readyThe zero-copy video path produces no frameCheck video readiness and let the caller fall back to decoded-frame or canvas rendering.
A shape uses an unsupported path, stroke style, or trim featureThe GPU shape path is skipped and a partial shape must not be shownUse the GPU eligibility checks before preparing the shape.
A text render exceeds the glyph limit or exhausts the atlasThe text texture cannot be produced for that frameKeep atlas reset and non-GPU text fallback behavior intact.
Multiple masks use an incorrect inversion or combine orderLayer visibility changes in a way that is hard to detect from the source shapesPreserve track scope, per-mask inversion, and alpha multiplication order.
A transition identifier is missing from the GPU registryThe transition stage returns failure and the transition needs another rendererKeep timeline transition IDs and the GPU transition registry aligned.
Released textures are not returned to the pool or cached textures are not destroyedGPU memory grows and later frames can fail under pressureMatch every acquire with release and clear owned caches during disposal.
The selected video codec is not supported by the browserExport cannot use the requested format or codecProbe encoder support before rendering and select a compatible fallback.
The export worker is unavailable or rejects a compositionThe worker render stops before producing outputRe-run the same request on the main thread unless the error is cancellation or an unrelated render error.

Key files

FileWhy to read it
src/…/gpu-pipeline-manager.tsShows the shared GPU device, lazy stage creation, output target, caches, and teardown boundary.
src/…/gpu.tsShows how timeline items become prepared GPU participants and how effects, masks, nested compositions, and scratch textures connect.
src/…/compositor-pipeline.tsDefines layer order, transforms, blend modes, masks, external video input, and final canvas output.
src/…/media-render-pipeline.tsDefines the common source-to-texture placement and image treatment path.
src/…/effects-pipeline.tsDefines ordered effect processing, pass grouping, and GPU-native or canvas output.
src/…/registry.tsDefines how effect types become available to the visual pipeline.
src/…/mask-combine-pipeline.tsDefines the shared alpha rule for combining masks.
src/…/shape-render-pipeline.tsDefines GPU-supported vector shape output and path limits.
src/…/glyph-atlas-text-pipeline.tsDefines GPU text layout handoff, glyph rendering, and motion-text behavior.
src/…/transition-pipeline.tsDefines two-input transition rendering and canvas or GPU-native transition output.
src/…/scope-renderer.tsDefines the source upload and shared settings for color analysis views.
src/…/fullscreen-quad.tsDefines the common UV and draw contract used by fullscreen image passes.
src/…/gpu-texture-pool.tsDefines intermediate texture reuse and memory limits.
src/…/render-pipeline.tsShows the shared handoff from resolved export settings to worker or main-thread rendering.
src/…/client-renderer.tsDefines browser-side codec, container, and encoded output contracts.