voxolith

makePerf()

Measure frame times and adapt the render scale to hit a frame-time target. Feed it every rendered frame; it lowers the scale quickly when frames run over budget and raises it in 0.05 steps when they fit, remembering a scale that proved too slow for retryAfterMs. With enabled it also adds a small...

function makePerf(opts: PerfOptions): Perf;

Defined in: perf.ts:102

Measure frame times and adapt the render scale to hit a frame-time target. Feed it every rendered frame; it lowers the scale quickly when frames run over budget and raises it in 0.05 steps when they fit, remembering a scale that proved too slow for retryAfterMs. With enabled it also adds a small overlay to document.body, so it needs a browser.

Frame times come from performance.now() deltas between rendered frames, so they include vsync waits: under a 60 Hz display nothing reads below 16.7 ms.

Parameters

ParameterTypeDescription
optsPerfOptionsStarting scale, limits, target and overlay settings.

Returns

Perf

The controller; apply scale() to gpu.renderScale each frame.

Example

import { makeFrameLoop, makePerf, resizeToDisplay } from "@voxolith/renderer";

const perf = makePerf({
  enabled: new URLSearchParams(location.search).has("perf"),
  scale: gpu.renderScale,
  minScale: gpu.software ? 0.25 : 0.4,
});
const loop = makeFrameLoop({
  continuous: true,
  render: (now) => {
    perf.frame(now);
    gpu.renderScale = perf.scale();
    resizeToDisplay(gpu);
    renderer.render({ ...camera(now / 50), ...sky });
  },
});

On this page