Skip to content

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

Closed

Description

@edwrdc

Rune rev: 3ff3cc6 (same code at 5d421fd) · Platform: Linux (Fedora 44, niri), Vulkan on Intel Iris Xe and NVIDIA RTX 3050, wgpu 30.0.1

What happens

When a window showing a playing NativeSurface is resized (here by tx.toggle_full_screen()), the main thread sometimes panics:

wgpu error: Validation Error
In Surface::configure
  Failed to wait for GPU to come idle before reconfiguring the Surface

from Win::resize_surface (window/win.rs) ← WindowEvent::Resized (window/events.rs).

The panic site is the same as #306, but the cause is different: here the size is fine, and the GPU queue isn't empty.

Why

  • The check: wgpu-core's configure waits for the last submission and then requires an empty queue. If the queue isn't empty, it returns GpuWaitTimeout before it touches the surface. wgpu's own comment: "It can only be non-empty if another thread is submitting at the same time."
  • The other thread: when the device has TIMESTAMP_QUERY (requested whenever the adapter has it), SurfaceRenderer::submit (native_surface/pipeline.rs) installs an on_submitted_work_done callback that calls queue.submit([timestamps.finish()]). That callback runs on the rune-video-completion thread during its device.poll, so it can land between configure's wait and its check.

Repro

Push frames to a NativeSurface at about 30 fps and toggle full screen every 0.75 s for 20 s:

Setup Panicked
Intel, X11 (XWayland) 3/3 runs, after 2–13 toggles
NVIDIA, X11 (XWayland) 2/3
Intel, native Wayland 1/3
NVIDIA, native Wayland 0/2
Intel, X11, no video frames (control) 0/4, about 24 toggles each

In the app, a single full-screen toggle during playback sometimes crashes it.

Expected

A resize during playback never takes the app down.

Possible solution

  • Remove the cause: don't submit from the completion thread. The callback could queue the slot to resolve, and the next SurfaceRenderer::submit on the render thread could encode and submit the resolve. That still runs after the completion fence the Metal comment asks for, but the last frame's timing is reported only when another frame is submitted.
  • Make configure robust: in Win::resize_surface, push an ErrorFilter::Validation scope around surface.configure and retry a few times while it reports an error. GpuWaitTimeout fails before the surface changes, so a retry is safe. This also covers apps that submit from their own threads.

Activity

  1. Hona commented on Nov 23, 2026

    @Hona
    Member

    The cause from the report is gone: a frame's timestamp resolve was submitted from the rune-video-completion thread and could land inside Surface::configure's wait. Surface configures and that submission now go through one gate, and a resolve that comes up during a configure is parked and submitted after it. (The panic itself had already become a failed configure and a replaced surface in #492.) Fixed on dev in #1589 (6e03e22). It was tested on D3D12 and Metal with a real device but no window, and compiled for Linux; the full-screen toggle on Vulkan was not repeated.

  2. edwrdc commented on Nov 23, 2026

    @edwrdc
    Author

    Thanks for your hard work!!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions