Repository navigation
fix(native_surface): a frame's timestamp resolve is never submitted while a surface is being configured - #1589
Merged
Merged
Conversation
…hile a surface is being configured
Hona
force-pushed
the
fix/345-timestamp-resolve-configure
branch
from
November 23, 2026 07:11
3c312a7 to
2b033de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #345
Root cause
Surface::configurein 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 withGpuWaitTimeout("Failed to wait for GPU to come idle before reconfiguring the Surface").TIMESTAMP_QUERY,SurfaceRenderer::submit(rune-media,native_surface/pipeline/frame.rs) installs anon_submitted_work_donecallback that encodes and submits the frame's timestamp resolve. The callback runs on whichever thread polls the device, usuallyrune-video-completion.window/surface/configure.rsreturns 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 resolveWhat changed
rune_gpu::configure(new): aGate.configuring(f)runs aSurface::configurewith 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, insideconfigure).window::configure(rune), the one place a native surface is configured, runssurface.configureinsideconfiguring.completion::Parked) and flushes through the gate.CompletionWorker::spawnflushes 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.Tests
rune-gpuconfigure::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-mediacompletion_tests:Parkedwith 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 insideconfiguring, 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
Surface::configureran against a playing surface.rune_gpu::configure::gate().try_submit.