Performance ideas (loading objects in workers, faster texture uploads, etc)

@donmccurdy Would it be possible to have two scenes in separate threads, and loading GPU textures to them so that one scene can render while one is uploading a texture? I think no matter how many offscreen canvases we have, my guess is this won’t work because uploading to the GPU would block all threads depending on the GPU, right?

So it would be like this (if it could work, but I’m guessing GPU will block both threads):

  • receive texture from network in scene B (thread B)
  • in thread B, upload the texture to GPU.
  • keep rendering scene A (thread A) to its OffscreenCanvas while thread B loads the texture to GPU
  • When texture upload is complete, transfer the texture to thread A as a Transferable (fast)
  • now thread B takes over rendering to its OffscreenCanvas (main thread has to swap which canvas element is visible)
  • thread A uploads the texture to the GPU while thread B is rendering so that it can get to the same state
  • after thread A is caught up (texture uploaded), continue rendering with thread A (stop thread B from rendering)
  • later when thread B receives a new texture, repeat the whole process.

Is this possible? Or will thread B force any gl contexts (no matter what thread they are in) to be blocked?