So I am using webgl to test the memory cost on GPU recently.
I can understand that if i load a image with 512512, RGBA,
usually it should cost 512512*4 bytes, which is 1MB, even if i add the mipmap 1.33MB top.
But to be honest if I load a lot of this kind of 512 * 512 images, then I check the memory monitor, it's way much more than it should be.
Does anyone got any idea how it works?
Thanks a lot
It is not possible to know how much memory is used. It's up to the browser, the driver and the OS.
You load an image (via an img tag) and upload to a texture
- Does the browser keep the raw file around? Up to the browser.
- The browser decodes the image. Does it throw this away or keep it? up to the browser
- The browser, assuming you're going to display that image in an
<img>
tag might upload the decoded image data to the GPU
- You ask for that image to be copied to a texture. WebGL has requirements the
<img>
tag does not so the image might have to be decoded again. If so, when the browser releases that re-decoded image is undefined. For example it might cache it in case you ask for it again
- That image data is sent to the GPU process in browsers that have a GPU process so now there are 2 copies, at least for a moment. The one in the CPU process and the one in the GPU process.
- The GPU process then uploads that to the driver. The driver itself might keep 2 copies. One on the GPU and one on the CPU. I know older OpenGL drivers used to do this so that you could reference more textures than fit in memory, DirectX does not (or at least didn't used to)
- The driver itself may emulate certain formats. It's common that desktop GPUs expand anything < RGBA8 to RGBA8. For example R8 or RGB8 or RGBA UNSIGNED_SHORT_4444 etc maybe or may not get expanded to RGBA8 (or any other higher precision format)
- The GPU may have alignment restrictions forcing it to pad your texture if it's not the correct size.
- The browser may try to swap textures for you allowing more than the driver itself.
In other words you can't really know.
That said, we can watch and see what the system reports. Of course what my system reports in this version of this browser might be different on a different system, or a different browser, or a different version of the same browser, or different with an OS upgrade, or a driver upgrade, etc...