Rebuild bind groups when a bound texture's GPU resource is recreated#8982
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a WebGPU correctness issue where BindGroup instances could keep referencing destroyed GPU texture resources when a Texture recreates its GPU impl in-place mid-render (e.g. during Texture.resize), by detecting impl identity changes and forcing a bind group rebuild.
Changes:
- Track the last-seen
texture.implper bind-group texture slot and mark the bind group dirty when it changes. - Apply the same
impltracking to storage texture slots to avoid stale GPU texture views there as well.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * For each texture / storage-texture slot, the GPU implementation object the slot was last | ||
| * built against. A texture's `impl` is replaced when its GPU resource is recreated (e.g. | ||
| * {@link Texture#resize}), which can happen mid-render in the same render version the bind | ||
| * group was last built — so the {@link renderVersionDirty} check alone misses it and the bind |
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.
Summary
A
BindGrouprebuilds its underlying GPU bind group when a bound texture changes, but the dirty check missed the case where a texture's GPU resource is recreated in place (sameTextureJS object, newimpl) during a render. When this happens, the bind group keeps a view of the old — now destroyed — GPU texture, which surfaces under WebGPU asDestroyed texture [...] used in a submitvalidation errors and visible corruption (e.g. black frames).The existing texture dirty check in
setTexture/setStorageTextureis:renderVersionDirtyis stamped withdevice.renderVersion, which only increments once per rendered frame (GraphicsDevice.frameStart). So when a texture is resized mid-render — in the same render version the consuming bind group was last built —renderVersionUpdated < renderVersionDirtyis false and the rebuild is skipped, leaving a stale view of the destroyed GPU texture.Repro context
Hit by unified gsplat LOD streaming with
app.autoRender = false: the work-buffer textures (Texture#resize) grow mid-render as splats stream in, in the same render version as the renderers that bind them.Texture.resizealready defers GPU destruction until after submit, but the deferred destroy still fires while a bind group holds a view of the oldimpl, producingDestroyed texture [... R32Uint / RGBA32Uint ...] used in a submit.Fix
Track the GPU
implobject each texture/storage-texture slot was last built against, and mark the bind group dirty when it changes.implidentity changes exactly when the GPU resource is recreated (resize, lose-context, format change), so this catches mid-render recreation regardless of render-version timing, and adds no rebuilds in steady state (implis otherwise stable across frames).Notes
update().