Search code examples
actionscript-3memory-managementairgpuvga

Allocate memory in GPU, flash/air


This is more an "implementation" of technology kind of question.

In old times, when I worked with C language, you could specify to use VGA memory or ram memory for allocation of bitmaps structures, then you could work with them a lot faster.

Now we are in 2013, I create bitmap in AS3, and it is allocated in ram (I've seen no option to use the GPU and 100% of cases im sure it is using the RAM, because it increases exactly the expected bitmap size.

¿Is there any option to use GPU memory?

Thanks


Solution

  • Check out the API docs for flash.display3D.Texture - there are 3 methods:

    uploadCompressedTextureFromByteArray(data:ByteArray, byteArrayOffset:uint, async:Boolean = false):void
    Uploads a compressed texture in Adobe Texture Format (ATF) from a ByteArray object.
    
    uploadFromBitmapData(source:BitmapData, miplevel:uint = 0):void
    Uploads a texture from a BitmapData object.
    
    uploadFromByteArray(data:ByteArray, byteArrayOffset:uint, miplevel:uint = 0):void
    Uploads a texture from a ByteArray.
    

    So you can't allocate the memory directly in the GPU. You must upload data from a ByteArray or BitmapData, which first exists in RAM. However, to minimize CPU RAM usage, you could potentially reuse a single ByteArray or BitmapData in RAM, change its contents, and upload it many times, or release it after loading. But you can't access the contents of GPU memory directly, as far as I know.

    As far as "read access", the only way to get data back from the GPU memory (again, a slow workaround) is to draw the Context3D back into a BitmapData via Context3D.drawToBitmapData... basically like a screen grab. The Starling Framework has an example of this functionality via Stage.drawToBitmapData.

    Basically, the Stage3D APIs weren't setup so you can easily access the GPU memory.