Skip to content

Instantly share code, notes, and snippets.

@jimblandy
Created August 14, 2025 14:51
Show Gist options
  • Save jimblandy/d9f58ffa61a5c3d4a2fdcf71e684eb34 to your computer and use it in GitHub Desktop.
Save jimblandy/d9f58ffa61a5c3d4a2fdcf71e684eb34 to your computer and use it in GitHub Desktop.
Notes on Firefox's remote texture architecture

Remote textures

  • Relationships (‘<==>’ means ‘is one-to-one with’)
    • GPU process <==> RemoteTextureMap
    • RemoteTextureOwnerClient <==> WebGPUParent (and thus WebGPUChild)
    • TextureOwner <==> CanvasContext, when configured
  • Tracking
    • TextureOwner
      • has various queues of
        • TextureDataHolder, a struct of
          • TextureHost (?)
          • TextureData (?)
          • SharedResourceWrapper, an enum of
            • gl::SharedSurface
            • webgpu::ExternalTexture
    • RemoteTextureMap
      • RemoteTextureMap::Get returns the singleton
      • keys are (pid, owner) pairs:
        • pid is a child process pid
        • owner is an id allocated in that pid
      • values are TextureOwner
    • RemoteTextureOwnerClient tracks groups of TextureOwner objects
      • mostly a front end for RemoteTextureMap that can operate on the group, or individual members
    • WebGPUParent::mRemoteTextureOwner is its RemoteTextureOwnerClient
  • Adding TextureOwner objects
    • mozilla::webgpu::CanvasContext::Configure
      • allocates a fresh layers::RemoteTextureOwnerId (saved as mRemoteTextureOwnerId)
      • calls mozilla::webgpu::Device::InitSwapChain passing that owner id
      • calls SendDeviceCreateSwapChain, passing that owner id
      • ***** IPC BOUNDARY *****
      • RecvDeviceCreateSwapChain
        • ensures this WebGPUParent has a RemoteTextureOwnerClient
        • calls RemoteTextureOwnerClient::RegisterTextureOwner for the new owner id
        • calls RemoteTextureMap::RegisterTextureOwner
        • poof, now the CanvasContext has a TextureOwner under its mRemoteTextureOwnerId
  • Removing TextureOwner objects
    • CanvasContext::Unconfigure calls SendSwapChainDrop, passing mRemoteTextureOwnerId
    • ***** IPC BOUNDARY *****
    • WebGPUParent::RecvSwapChainDrop
      • calls
        • RemoteTextureOwnerClient::UnregisterTextureOwner
          • calls
            • RemoteTextureMap::UnregisterTextureOwner
              • carefully interacts with compositor, but does eventually remove the entry from RemoteTextureMap::mTextureOwners and destroy it poof
  • Adding RemoteTextureOwnerClient objects
    • RecvDeviceCreateSwapChain ensures the WebGPUParent has one, in the process of creating the ~TextureOwner~a
  • Removing RemoteTextureOwnerClient objects
    • WebGPUParent::ActorDestroy
      • calls RemoteTextureOwnerClient::UnregisterAllTextureOwners
        • which calls RemoteTextureMap::UnregisterTextureOwners, passing the client’s set of owners
          • which does the same as UnregisterTextureOwner (singular), but only acquires the lock once
      • assigns nullptr to mRemoteTextureOwner to free it
  • Initializing the RemoteTextureMap
    • only initialized in the dedicated GPU process or in the main process if the dedicated GPU process is disabled, by calling RemoteTextureMap::Init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment