engine icon indicating copy to clipboard operation
engine copied to clipboard

Texture API issues

Open slimbuck opened this issue 3 years ago • 8 comments

Some observations of the current texture API:

  • setSource only works with 'browser interface' objects (not arrays of data) and the function correctly tracks which mipmap levels are dirty using _levelsUpdated.
  • getSource will return browser interface objects and also arrays of data which it strictly probably shouldn't (since it is matched with setSource).
  • lock and unlock work with arrays data and the entire texture is always re-uploaded if any mipmap level is locked, whether for read or write.

Ideally we'd have an API that:

  • has a single way of updating both types of texture data
  • tracks which face/mipmap levels have been updated and only upload those to GPU
  • makes it simple to get, set and dirtify individual faces/levels

Also, the current API assumes textures have CPU-side data which is uploaded to GPU. However we often have GPU-side texture data which we want to copy back to CPU.

@mvaligursky are there any additional restrictions or requirements imposed by webgpu on texture handling?

slimbuck avatar May 31 '22 11:05 slimbuck

Not at the moment, but here are some best practices for WebGPU: https://github.com/toji/webgpu-best-practices/blob/main/img-textures.md

mvaligursky avatar May 31 '22 11:05 mvaligursky

From forum: https://forum.playcanvas.com/t/pre-uploading-of-pc-texture/3212/

Users are requesting the ability to manually upload textures to the GPU so they can control the potential framerate stutter when loading in sections of an open world. Eg, they could upload textures over several frames.

yaustar avatar Sep 29 '22 10:09 yaustar

Eg, they could upload textures over several frames.

To add to that: currently the textures are loaded "on demand" (i.e. when they are first drawn). We would like to be able to upload large textures during our initial loading screen instead, in order to prevent frame stutters later in the game. We would be fine with all textures being uploaded in 'one frame' in that case. It's just the overall timing of that frame we are concerned with.

ArztSamuel avatar Sep 30 '22 15:09 ArztSamuel

Regarding the timing - we work around it by drawing a bunch of cubes with all materials that will be used in game during the first frame (which is hidden by a loading screen, so the player doesn't see them), then remove them and show the game.

LeXXik avatar Mar 01 '24 16:03 LeXXik