Skip to content

Metal: expose transaction presentation completion#9828

Draft
yay wants to merge 1 commit into
gfx-rs:trunkfrom
yay:steady/metal-transaction-presentation-completion
Draft

Metal: expose transaction presentation completion#9828
yay wants to merge 1 commit into
gfx-rs:trunkfrom
yay:steady/metal-transaction-presentation-completion

Conversation

@yay

@yay yay commented Jul 7, 2026

Copy link
Copy Markdown

Why

This came out of chasing a particularly slippery macOS live-resize race in egui.

When a CAMetalLayer uses transaction presentation, AppKit can report that native live resize has
ended while the final transaction-presented drawable is still in flight. If the client disables
transaction presentation and reconfigures its surface at that point, the window can briefly stop
accepting interaction and then adjust to a slightly different size when the delayed drawable is
finally shown.

A timer or an extra event-loop turn made the problem less frequent, but did not make it reliable.
The useful synchronization point is Metal's own confirmation that the final drawable was
presented. The downstream context is emilk/egui#8280.

What changed

  • Assign a monotonically increasing generation to drawables presented through
    presentsWithTransaction.
  • Use MTLDrawable::addPresentedHandler to record the greatest generation Metal has presented.
  • Expose the submitted and completed generations on the Metal HAL surface.
  • Allow clients to register one-shot callbacks for a target generation. Multiple waiters are
    retained and callbacks registered after completion run immediately.

This is intentionally Metal HAL-specific. It does not change the portable wgpu surface API or
the non-transaction presentation path.

This is a draft because I would appreciate feedback on the HAL API shape before adapting the
downstream egui PR to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant