Skip to main content

Module sync

Module sync 

Source
Expand description

Keeping native frame changes and the host’s GPU frame in step (risk 2).

Background (measured on 60 fps video in the prototype): winit redraws from a run-loop observer that runs after Core Animation’s commit observer. Native frames set during the host’s draw therefore wait for the next run-loop pass to commit, while the GPU frame presents on its own schedule.

Two independent switches, both off by default:

  • set_flush_after_draw: commits the pending Core Animation transaction right after the host’s redraw. During the draw, place queues a block on the main run loop and wakes it; the block runs as soon as the host’s redraw (and its GPU present) returns. (A plain run-loop observer at the host’s own order ran before the host’s redraw, ~16 ms after the previous draw, so it couldn’t be used.)
  • set_layer_presents_with_transaction: asks the Metal layer to present inside that transaction. Only honoured by wgpu 28 and later, which read the flag from the layer each frame; wgpu 27 (Iced 0.14) resets it.

Structs§

SyncStats
Counters for the flush switch (diagnostics).

Enums§

StartGate
When the flush observer may start flushing. Flushing the first frames while the window is still being put on screen lost the last startup frame in the spike (the window kept a stale frame until the next redraw).

Functions§

flush
Commits the current Core Animation transaction now.
gap_percentiles
Percentiles (p10, p50, p90) of the time from the last place to the flush block, in microseconds. Diagnostic.
set_flush_after_draw
Turns flushing right after each host redraw on or off.
set_layer_presents_with_transaction
Sets presentsWithTransaction on the content view’s Metal layer. Returns false if there is no such layer. See the module docs for which wgpu versions honour it; on wgpu 27 it freezes the GPU output.
stats
Counters so far.