This page covers the three render modes (always, on-demand, manual), the stage API for organizing task execution, dependency ordering, and the profiling/diagnostics system.
For the useFrame API, see Frame Scheduler.
Render modes
renderMode determines when the canvas re-renders. It is set as a FragCanvas prop and can be changed at runtime via useMotionGPU().renderMode.set(...).
always (default)
Renders every frame via requestAnimationFrame, as long as autoRender is true.
<FragCanvas {material} renderMode="always" />Best for: continuous animations, simulations, video textures.
on-demand
Renders only when something triggers an invalidation or advance() is called.
<FragCanvas {material} renderMode="on-demand" /><script lang="ts">
import { useMotionGPU } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
function handlePointerMove() {
gpu.invalidate();
}
</script>Invalidation sources:
gpu.invalidate()/state.invalidate()from user codeuseFrametasks withautoInvalidate: true(default)useFrametasks withinvalidation: { mode: 'on-change', token: ... }when token changes- Switching to
on-demandmode auto-injects one initial invalidation
Best for: interactive UIs, data visualization, infrequent updates.
manual
Renders only after an explicit advance() call.
<script lang="ts">
import { useMotionGPU } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
function captureFrame() {
gpu.advance();
}
</script>
<button onclick={captureFrame}>Render one frame</button>Best for: frame-by-frame capture, testing, server-side rendering scenarios.
Runtime mode switching
autoRender gate
autoRender is a boolean that acts as a hard override. When false, no rendering occurs regardless of render mode:
Stages API
Stages group tasks into execution phases. By default, all tasks run in a single main stage. You can create custom stages for explicit ordering:
Creating stages
Assigning tasks to stages
The default stage uses an internal symbol key, so referencing it by string (for example 'main') is unsupported.
Stage options
Stage callback
The callback option lets you wrap task execution:
Dependency ordering
Both tasks and stages support before / after dependency edges. Dependencies are resolved via topological sort:
- Tasks within a stage are sorted by their inter-task dependencies.
- Stages are sorted by their inter-stage dependencies.
- Circular dependencies throw an error.
- Missing dependency references throw an error.
Schedule inspection
You can inspect the resolved execution order at any time:
This is useful for debugging task ordering and verifying dependency resolution.
Delta clamping
maxDelta clamps state.delta every frame to prevent large time jumps (e.g., when a tab is background-inseted):
- Default:
0.1seconds - Must be: finite and
> 0 - Configurable via:
FragCanvasprop orgpu.maxDelta.set(value)
<FragCanvas {material} maxDelta={0.05} />Diagnostics and profiling
Diagnostics (single-frame timing)
Profiling (rolling window)
Advanced preset
For convenience, applySchedulerPreset applies a named configuration:
Debug snapshot
captureSchedulerDebugSnapshot returns a full serializable snapshot of the scheduler state: