Skip to content

Implement deferred destruction for WebGPU textures#8403

Merged
mvaligursky merged 2 commits intomainfrom
mv-webgpu-texture-destroy
Jan 23, 2026
Merged

Implement deferred destruction for WebGPU textures#8403
mvaligursky merged 2 commits intomainfrom
mv-webgpu-texture-destroy

Conversation

@mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jan 23, 2026

This PR fixes GPU resource management for WebGPU textures:

  • WebgpuTexture.destroy() was previously empty, relying on JavaScript garbage collection to eventually release the underlying GPUTexture. 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:

  • Adds a _deferredDestroys queue to WebgpuGraphicsDevice
  • GPU resources are queued for destruction via deferDestroy()
  • Resources are destroyed after submit() completes, ensuring all pending commands have been submitted
  • Updates WebgpuTexture.destroy() to use deferred destruction

This ensures GPU memory is released promptly while avoiding use-after-destroy validation errors.

@mvaligursky mvaligursky merged commit a12cdcf into main Jan 23, 2026
7 checks passed
@mvaligursky mvaligursky deleted the mv-webgpu-texture-destroy branch January 23, 2026 11:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _deferredDestroys queue to WebgpuGraphicsDevice to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants