Handle mapAsync rejection when the WebGPU device is lost - #9115
Merged
Conversation
Build size reportThis PR changes the size of the minified bundles.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the WebGPU backend against GPUBuffer.mapAsync() rejections that occur when the WebGPU device is lost, preventing unhandled promise rejections and ensuring readback promises settle instead of hanging.
Changes:
- Added
WebgpuGraphicsDevice.mapBufferAsync()to centralizemapAsynchandling and convert device-lost / buffer-destroyed failures into afalseresult. - Updated WebGPU staging-buffer users (upload stream, dynamic buffers, query set / GPU profiler) to tolerate mapping failure and avoid reporting invalid results.
- Updated
readBuffer-based readback to reject with a descriptive error when mapping fails (instead of never settling).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/graphics/webgpu/webgpu-graphics-device.js | Adds mapBufferAsync() and uses it in readback to avoid unhandled rejections / hanging promises on device loss. |
| src/platform/graphics/webgpu/webgpu-upload-stream.js | Switches staging buffer mapping to mapBufferAsync() and destroys buffers that can’t be safely reused. |
| src/platform/graphics/webgpu/webgpu-dynamic-buffers.js | Switches staging buffer mapping to mapBufferAsync() for device-lost safety during buffer recycling. |
| src/platform/graphics/webgpu/webgpu-query-set.js | Switches query staging buffer mapping to mapBufferAsync() and returns null when mapping fails. |
| src/platform/graphics/webgpu/webgpu-gpu-profiler.js | Skips reporting when query results are unavailable due to device loss. |
💡 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.
Fixes #6677
When the WebGPU device is lost, every in-flight and subsequently issued
GPUBuffer.mapAsync()rejects withAbortError: Failed to execute 'mapAsync' on 'GPUBuffer': Device is lost. None of the engine's fourmapAsynccall sites attached a rejection handler, so this surfaced as an unhandled promise rejection (affecting ~2% of users of the reported game).Changes:
WebgpuGraphicsDevice.mapBufferAsynchelper that skips the call when the context is already lost and converts the device-lost / buffer-destroyed rejection into afalseresult instead of an unhandled rejectionreadBuffer: on failed mapping, the returned promise now rejects with a descriptive error instead of never settling - previouslyStorageBuffer.read()/ texture readback callers would hang forever after device loss