Skip to content

fix(native_surface): a frame's timestamp resolve is never submitted while a surface is being configured - #1589

Merged
Hona merged 1 commit into
devfrom
fix/345-timestamp-resolve-configure
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/345-timestamp-resolve-configure

Conversation

@Hona

@Hona Hona commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #345

Root cause

  • Surface::configure in wgpu-core waits for the device's last submission, then requires an empty queue. A submission from another thread that lands between the wait and the check makes it refuse the configuration with GpuWaitTimeout ("Failed to wait for GPU to come idle before reconfiguring the Surface").
  • That other thread was Rune's. On a device with TIMESTAMP_QUERY, SurfaceRenderer::submit (rune-media, native_surface/pipeline/frame.rs) installs an on_submitted_work_done callback that encodes and submits the frame's timestamp resolve. The callback runs on whichever thread polls the device, usually rune-video-completion.
  • Since gpu: a lost device or an unconfigured surface makes a new one instead of panicking the app #492 the refusal no longer panics: window/surface/configure.rs returns it as an error, and a resize then marks the surface broken and replaces it. The race itself was still there.
sequenceDiagram
    participant W as Window thread
    participant C as rune-video-completion
    W->>W: Surface::configure: wait for the last submission
    C->>C: poll: the frame is done, its callback runs
    C-->>W: before: queue.submit(resolve) lands here
    W->>W: queue not empty: GpuWaitTimeout
    Note over C: now: the gate is held, the resolve is parked
    W->>W: queue empty: configured, gate released
    C->>C: next poll: submits the parked resolve
Loading

What changed

  • rune_gpu::configure (new): a Gate. configuring(f) runs a Surface::configure with other threads' submissions held off; try_submit(f) runs a submission unless a surface is being configured, and never waits (wgpu also runs completion callbacks on the configuring thread, inside configure).
  • window::configure (rune), the one place a native surface is configured, runs surface.configure inside configuring.
  • The callback no longer submits. It parks the resolve (completion::Parked) and flushes through the gate. CompletionWorker::spawn flushes before every poll and reports the device busy while a resolve is still parked, so the worker comes back for it once the configure is done.
  • Frame timing is unchanged: with no configure in the way the resolve is submitted from the same callback as before, so the last frame before a window goes idle still gets its GPU times.

Tests

  • rune-gpu configure::tests: a submission runs with no configure, is refused from another thread and from inside the configure, and a configure waits for a submission under way.
  • rune-media completion_tests: Parked with a fake submit and its own gate; the completion worker, over a fake poll, submits what a configure kept back once it is done.
  • a_timestamp_resolve_is_not_submitted_while_a_surface_is_being_configured: a real device (D3D12 here, headless) draws a timed frame inside configuring, waits for the frame, and sees no resolve submitted until the configure ends; then the frame's GPU times arrive. It fails with the direct submit put back.

Not run live

  • No window was opened: the full-screen toggle from the issue was not repeated, and no real Surface::configure ran against a playing surface.
  • The tests ran on Windows (D3D12) and on macOS (Metal); the crates were compiled for Linux (aarch64) and the web build was checked. The issue was reported on Linux with Vulkan, where the tests were not run.
  • An app that submits to Rune's device from a thread of its own can still race a configure; it can use rune_gpu::configure::gate().try_submit.

@Hona
Hona force-pushed the fix/345-timestamp-resolve-configure branch from 3c312a7 to 2b033de Compare November 23, 2026 07:11
@Hona
Hona merged commit 6e03e22 into dev Nov 23, 2026
1 check passed
@Hona
Hona deleted the fix/345-timestamp-resolve-configure branch November 23, 2026 07:13
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.

Video: resizing during NativeSurface playback can panic in Surface::configure

1 participant