fix: Register StorageBuffer for WebGPU device lose/restore#8692
Merged
mvaligursky merged 1 commit intomainfrom May 6, 2026
Merged
fix: Register StorageBuffer for WebGPU device lose/restore#8692mvaligursky merged 1 commit intomainfrom
mvaligursky merged 1 commit intomainfrom
Conversation
Track storage buffers on GraphicsDevice with loseContext/restoreContext. GraphicsDevice.restoreContext calls buffer.restoreContext(); vertex/index delegate to unlock. WebgpuBuffer loseContext clears handle only; allocate applies debug labels.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes WebGPU device lose/restore handling for StorageBuffer by ensuring storage buffers are tracked by GraphicsDevice.buffers and participate in the same context loss / restoration lifecycle as other tracked buffers, preventing crashes and stale GPUBuffer references after device re-creation.
Changes:
- Track
StorageBufferinstances inGraphicsDevice.buffers, remove them ondestroy(), and implementloseContext()/restoreContext()with documented “contents undefined” semantics. - Update
GraphicsDevice.restoreContext()to callbuffer.restoreContext()instead ofunlock(); add@ignorerestoreContext()shims toVertexBuffer/IndexBuffer. - Improve WebGPU buffer handling by nulling
WebgpuBuffer.bufferon context loss and consistently applying GPU debug labels during allocation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/graphics/webgpu/webgpu-buffer.js | Clears stale GPUBuffer references on device loss and applies labels in allocate() so restore paths are labeled consistently. |
| src/platform/graphics/vertex-buffer.js | Adds internal restoreContext() delegating to unlock() to preserve existing public API while supporting new restore iteration. |
| src/platform/graphics/storage-buffer.js | Registers storage buffers for device tracking and adds lose/restore context methods; documents post-restore undefined contents behavior. |
| src/platform/graphics/index-buffer.js | Adds internal restoreContext() delegating to unlock() to work with GraphicsDevice.restoreContext() changes. |
| src/platform/graphics/graphics-device.js | Switches buffer restoration loop from unlock() to restoreContext() and clarifies behavior for storage buffers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
WebGPU device loss previously either crashed when iterating
GraphicsDevice.buffers(ifStorageBufferwas tracked withoutloseContext/unlock) or skipped storage buffers entirely, leaving staleGPUBufferreferences afterrequestDevice(). This change registers storage buffers on the device and runs the same lose/restore path as other buffers.Changes:
StorageBuffertoGraphicsDevice.bufferson construction; remove ondestroy().StorageBufferloseContext()/restoreContext()(GPU backing recreated at the same byte size; contents are undefined until rewritten or recomputed). Document that in the class JSDoc.GraphicsDevice.restoreContext()callsbuffer.restoreContext()instead ofunlock().VertexBufferandIndexBufferadd@ignorerestoreContext()delegating tounlock()so the public lock/unlock API is unchanged.WebgpuBuffer:loseContext()clears the buffer reference only (aligned withWebglBuffer);allocate()applies the GPU debug label so staging and storage paths stay consistent.Supersedes the approach of excluding
StorageBufferfromdevice.buffers(e.g. PR #8690).