bevy_render: reconfigure surface on Suboptimal present#24463
Open
rubeniskov wants to merge 1 commit into
Open
Conversation
Bevy 0.18's prepare_windows ignores SurfaceTexture::suboptimal, so when
the swapchain reports VK_SUBOPTIMAL_KHR (compositor scale / output
reconfig on desktop Linux is the common trigger) wgpu_hal logs
WARN present_frames: wgpu_hal::vulkan: Suboptimal present of frame N
on every present until something flips size_changed and forces a
configure_surface. Mirror the SurfaceError::Outdated branch: drop the
suboptimal frame, reconfigure, re-acquire.
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
IceSentry
approved these changes
May 27, 2026
Contributor
IceSentry
left a comment
There was a problem hiding this comment.
I feel like the shared parts could be extracted to a function but not sure if it's worth it.
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.
Bevy 0.18's prepare_windows ignores SurfaceTexture::suboptimal, so when the swapchain reports VK_SUBOPTIMAL_KHR (compositor scale / output reconfig on desktop Linux is the common trigger) wgpu_hal logs
on every present until something flips size_changed and forces a configure_surface. Mirror the SurfaceError::Outdated branch: drop the suboptimal frame, reconfigure, re-acquire.
Objective
prepare_windowsincrates/bevy_render/src/view/window/mod.rstreatswgpu::CurrentSurfaceTexture::Suboptimalexactly likeSuccess: it hands the texture to the renderer and moves on. The swapchain keeps presenting, but it no longer matches the surface (compositor scale change, output reconfiguration, monitor hot-plug on desktop Linux).size_changedand triggersconfigure_surface,wgpu_hallogs oneWARN present_frames: wgpu_hal::vulkan: Suboptimal present of frame Nper frame. On a 144 Hz display that's ~144 spurious warnings per second filling the log.SurfaceError::Outdatedbranch already does the right thing for the analogous "swapchain is stale" case —Suboptimalshould mirror it.Solution
Suboptimalout of the combinedSuccess | Suboptimalarm inprepare_windowsand mirror the existingOutdatedrecovery path:drop(surface_texture)to release the suboptimal frame.render_device.configure_surface(surface, &surface_data.configuration)so the swapchain re-matches the surface.get_current_texture(). If the second acquire still fails,warn!(...)andcontinue(same pattern asOutdated).Testing
cargo check -p bevy_renderis clean.Suboptimalis in practice a Vulkan-on-Linux event, so the change is a no-op on platforms that never report it..stderror unit-test snapshots reference this code path, so nothing else needs updating.RUST_LOG=warn cargo run --release.Showcase
Click to view showcase
Before / after with
RUST_LOG=warn cargo run --releaseon the minimal repro app above, performing a single fractional-scale change at ~3 s: