Implement deferred destruction for WebGPU textures#8403
Merged
mvaligursky merged 2 commits intomainfrom Jan 23, 2026
Merged
Conversation
willeastcott
approved these changes
Jan 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements deferred destruction for WebGPU textures to prevent validation errors that occur when GPU resources are destroyed while still referenced by pending command buffers.
Changes:
- Adds a
_deferredDestroysqueue toWebgpuGraphicsDeviceto track GPU resources awaiting destruction - Implements a
deferDestroy()method that queues resources for destruction after command buffer submission - Updates
WebgpuTexture.destroy()to use deferred destruction instead of immediate destruction
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/platform/graphics/webgpu/webgpu-graphics-device.js | Adds deferred destruction infrastructure with queue management and processing after command buffer submission |
| src/platform/graphics/webgpu/webgpu-texture.js | Updates texture destruction to use deferred mechanism instead of immediate GPU resource cleanup |
💡 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.
This PR fixes GPU resource management for WebGPU textures:
WebgpuTexture.destroy()was previously empty, relying on JavaScript garbage collection to eventually release the underlyingGPUTexture. This could cause GPU memory pressure when many textures are destroyed.However, calling
gpuTexture.destroy()immediately causes WebGPU validation errors ("Destroyed texture used in a submit") because command buffers referencing the texture may not have been submitted yet.This PR implements deferred destruction:
_deferredDestroysqueue toWebgpuGraphicsDevicedeferDestroy()submit()completes, ensuring all pending commands have been submittedWebgpuTexture.destroy()to use deferred destructionThis ensures GPU memory is released promptly while avoiding use-after-destroy validation errors.