Skip to content

fix(gsplat): release ImageBitmap memory after streamed SOG texture upload#8758

Merged
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-release-imagebitmap
May 21, 2026
Merged

fix(gsplat): release ImageBitmap memory after streamed SOG texture upload#8758
mvaligursky merged 1 commit into
mainfrom
mv-gsplat-release-imagebitmap

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

SOG textures loaded via the gsplat octree retained their source ImageBitmap on Texture._levels for the texture's lifetime, holding fully-decoded pixel data long after the GPU had its own copy of the texture. ImageBitmap storage is implementation-defined (CPU, GPU, or shared memory depending on browser and platform), but in all cases it sits in memory until close() is called — wasteful for streamed gsplat scenes that load many SOG files over time.

Changes:

  • Close any ImageBitmaps held on _levels when a Texture is destroyed
  • Add an opt-in mechanism for textures whose owner re-creates them on device loss: the WebGL and WebGPU upload paths close the ImageBitmap source immediately after upload when opted in
  • Gsplat SOG resources expose a helper that opts in all their source textures; the octree calls it when a file resource arrives, and the octree-instance calls it when the environment placement is created — both points where the octree's _onDeviceLost is guaranteed to dump the resource

Memory:

  • Releases ImageBitmap storage once the GPU upload is complete, for octree-managed SOG textures
  • The Texture.destroy() change is a generic improvement for all textures, not just gsplat
  • No GPU rendering work changes

SOG textures loaded via the gsplat octree retained their source
ImageBitmap on Texture._levels for the texture's lifetime, holding
decoded pixel data long after the GPU had its own copy. Close
ImageBitmaps on Texture.destroy() generically, and add an opt-in
release-after-upload path used by octree-managed SOG textures and the
octree environment resource, both of which are re-created from scratch
on device loss and therefore don't need the CPU source retained.
@mvaligursky mvaligursky self-assigned this May 21, 2026
@mvaligursky mvaligursky changed the title fix(gsplat): release ImageBitmap memory after SOG texture upload fix(gsplat): release ImageBitmap memory after streamed SOG texture upload May 21, 2026
@mvaligursky mvaligursky requested a review from Copilot May 21, 2026 14:17
@mvaligursky mvaligursky merged commit 36db858 into main May 21, 2026
10 checks passed
@mvaligursky mvaligursky deleted the mv-gsplat-release-imagebitmap branch May 21, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces memory retention for streamed gsplat SOG textures by ensuring decoded ImageBitmap sources don’t remain referenced on Texture._levels after the GPU upload is complete, and by adding an explicit opt-in path for resources that are re-created on device loss.

Changes:

  • Add Texture.releaseImageSources() / Texture.setReleaseSourceAfterUpload() and wire them into WebGL/WebGPU upload paths.
  • Ensure Texture.destroy() closes any ImageBitmap sources still referenced by _levels.
  • Expose GSplatSogResource.releaseTextureSources() and invoke it from the unified gsplat octree / octree instance when resources become device-loss-recreatable.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/scene/gsplat/gsplat-sog-resource.js Adds a helper to opt SOG-owned textures into releasing ImageBitmap sources after upload.
src/scene/gsplat-unified/gsplat-octree.js Calls the resource helper on file resource arrival to allow early source release.
src/scene/gsplat-unified/gsplat-octree-instance.js Calls the resource helper once environment placement exists (device-loss teardown guaranteed).
src/platform/graphics/webgpu/webgpu-texture.js Releases opted-in ImageBitmap sources after WebGPU upload completes.
src/platform/graphics/webgl/webgl-texture.js Releases opted-in ImageBitmap sources after WebGL upload completes.
src/platform/graphics/texture.js Implements the new source-release API and closes ImageBitmap sources during texture destruction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +358 to 362
// Free CPU-side decoded pixel data; the GPU has its own copy after upload.
this.releaseImageSources();

this._levels = null;
this.device = null;
Comment on lines +400 to +404
setReleaseSourceAfterUpload() {
this.releaseSourceAfterUpload = true;

// If upload has already happened, release eagerly.
if (!this._needsUpload && !this._needsMipmapsUpload) {
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.

2 participants