Don't drop pending shader events on the reload frame in PipelineCache to fix pipelines never becoming ready on web - #25238
Closed
taearls wants to merge 2 commits into
Closed
Conversation
taearls
marked this pull request as draft
August 1, 2026 05:08
Contributor
Author
|
I received some feedback on Discord that this PR in its current state doesn't resolve the issue it intended to fix. I'm converting this to a draft PR for now. I will look at this again this weekend and try to replicate this specifically on WGL2. |
Member
|
I fixed this in #25245. Just a friendly heads-up to avoid duplicate work. |
Contributor
Author
|
Closing this draft PR in favor of #25245 |
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.
Objective
PipelineCache::waiting_pipelines()never drains, loading-screen statemachines built on the pattern from the loading screen example
never flip to
Ready— the scene renders fine, but the app thinks it's stillloading forever. This worked in 0.18.1 and regressed in 0.19.0, so it's a
P-Regression targeting 0.19.1.
Solution
The regression was in
PipelineCache::extract_shaders. On any frame whereneeds_shader_reloadis set, the system takes a snapshot of every shadercurrently in
Assets<Shader>and re-registers it. Before this PR, it thendrained and discarded all pending
AssetEvent<Shader>and returned early:The intent behind the drain was to avoid double-processing shaders the snapshot
already handled. The problem: that snapshot is additive and only sees shaders
already present in
Assets<Shader>at that instant. If a shader finishesloading asynchronously (very common on the web) its
Addedevent is sitting inthis frame's buffer but the asset may not be in the snapshot yet — and a
Removedevent has no representation in a snapshot that only ever adds. Throwingthe event buffer away on the reload frame means those events are lost, and any
pipeline waiting on that shader stays stuck in
waiting_pipelines()indefinitely.The fix is to stop discarding events: let the reload branch fall through to the
existing per-event loop instead of returning early.
This is safe because the per-event loop is idempotent for the reload case: an
Added/Modifiedevent just re-runsset_shaderwith the same data (harmless),while
Removedis now correctly honored on reload frames instead of beingsilently dropped. The "double-process" the old comment worried about was never a
correctness issue.
Testing
crates/bevy_shader/src/shader_cache.rs):set_shader_makes_a_missing_shader_loadable. It's device-free (ShaderCache<(), ()>,no GPU), so it runs in CI, and it exercises the exact cache operation the fix
restores on the reload frame — a shader reports
ShaderNotLoadeduntilset_shaderapplies it.cargo test -p bevy_shaderpasses.