airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
199 stars 11 forks source link

Textures eating more GPU memory than they should #457

Open ghost opened 3 years ago

ghost commented 3 years ago

Problem Description

When you create non-rectangular texture using Context3D's createTexture() method, looks like it automatically allocate memory for mipmaps too, even if you don't use mipmaps at all. So AIR allocates x1.5 more memory than we actually want to use. And this is a huge problem, as now we are experiencing a lot of crashes because of using too much GPU memory.

I expect there should be some flag in this method for mipmaps, or at least it should read mipmaps value from loaded compressed texture.

Checked on latest AIR 33.1.1, using local emulator in IDE and Android device build.

Steps to Reproduce

Sample code:

mContext3D.createTexture(4096, 4096, Context3DTextureFormat.BGRA, false);
trace(mContext3D.totalGPUMemory);

this should allocate 67 108 864 bytes, but in fact allocate 100 663 296 bytes.

ajwfrost commented 3 years ago

For this we'd need to pass in a flag .. there's already the 'streamingLevels' parameter, which is used to start displaying a texture as soon as one of the mipmap levels has loaded in. Default is zero so the mipmaps would be created but the texture would only be seen with the highest-resolution image.

https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display3D/Context3D.html#createTexture()

Would it work if we allowed a "-1" value to mean "disable mipmap generation"? Or as an alternative we could either a) set up a global flag on the context to enable/disable mipmap generation b) just add another parameter to that createTexture() method to be clearer than using the streamingLevels value..

Let us know your thoughts!

thanks

ghost commented 3 years ago

Yes, definitely, using -1 would be awesome and pretty enough. Thank you! Everything else is up to you. All options looks well!

dmunsie commented 3 years ago

Please do not change the default behavior, like you said... if anything add another optional parameter for changes like this. Thanks.