Texture API issues
Some observations of the current texture API:
-
setSourceonly works with 'browser interface' objects (not arrays of data) and the function correctly tracks which mipmap levels are dirty using_levelsUpdated. -
getSourcewill return browser interface objects and also arrays of data which it strictly probably shouldn't (since it is matched withsetSource). -
lockandunlockwork 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?
Not at the moment, but here are some best practices for WebGPU: https://github.com/toji/webgpu-best-practices/blob/main/img-textures.md
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.
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.
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.