пятница, 17 января 2014 г.

Air 4.0 and new graphics stuff

Hello everyone. It was silent here for a long time. I was quite busy - my son was born and I changed a job and moved to new country. Now it seems I have some time for blog.

So, what we have? As you may already know new Air sdk was released recently with some stage3d API improvements. The new method for context request and new buffer usage flag were introduced.

New stage3d request is simple as cake - you just call Stage3D.requestContext3DMatchingProfiles() method with Vector of profile strings (Context3DProfile enum). The highest possible profile will be created.

The next new thing is much interesting - new buffer usage flag. Now in Context3D.createVertexBuffer() you can pass bufferUsage flag (Context3DBufferUsage enum). Currently there're two flags to use - staticDraw and dynamicDraw. Static draw is what we had before. Dynamic draw is good if you change your buffer data often, for example, every frame. You can find more info here - buffer usage on msdn and here - buffer usage on opengl.org. I expecting some performance improvements.

I made a small test - for buffer I reupload data every frame. For desktop I upload 40000 floats 4 times per frame. For mobile I upload 4000 floats 4 times per frame. There're separate tests for ByteArray and Vector data containers.

Here're results:

1. Dynamic buffer usage flag. ByteArray. Desktop.


2. Static buffer usage flag. ByteArray. Desktop.


3. Dynamic buffer usage flag. Vector. Desktop.


4. Static buffer usage flag. Vector. Desktop.


5. Dynamic buffer usage flag. ByteArray. Mobile.


6. Static buffer usage flag. ByteArray. Mobile.


7. Dynamic buffer usage flag. VectorMobile.


8. Static buffer usage flag. VectorMobile.

As you can see on mobile there's absolutely no difference. I made tests on Samsung Nexus 7 with Tegra 3. Maybe all this stuff is gpu-sensitive, so I will not say that this flags are not working on mobile.

The interesting thing is on desktop (I tested on AMD FirePro 2270). Scout says that as3 execution time is dramatically different for different flags. For dynamic usage as3 part is very fast. Much faster then for static usage. But if you'll look carefully onScout chart you'll notice the grey bars and description says - waiting for gpu 25 ms. So, in total we get the same fps in both cases. But with static buffer we're waiting for gpu finish reading data and at this time cpu is locked. And with dynamic buffer usage we can do another stuff while waiting for gpu. So this time can be spent on physics and ai - the total performance of application can be increased. I think that frameworks with Starling-like architecture will benefit a lot with this flag.

The interesting question - why do we need static buffer at all? Honestly, I don't know and hope that someone will bring some light. I can only asume that static buffer can be faster on gpu due to some position in the memory - after all it's static.

The source code for tests can be found here.

3 комментария:

  1. Hi,

    I just ask Chris Campbell (Adobe) and get this response so i fw to you below :)
    -------------------------------------------------------
    Hi Todsaporn,
    I’ve added Cheng Liao, the developer for these features to the discussion for follow up questions or comments. Here’s what I’ve heard back from the team:

    Why do we need static buffer at all?
    In general, static vertex buffers are placed in video memory where reading is faster for GPU and dynamic vertex buffers are placed in AGP memory where writing is faster for CPU. When rendering through the dynamic buffers, the GPU may copy it to the place where is faster for it to read. In this case, if we create all buffers as dynamic, it would cause more memory usage ( one in AGP, one in video memory ). Another case is that every time GPU reads the dynamic buffer from AGP. For those buffers we never update, GPU would need more time to read every frame.
    So the static buffer is still useful.

    These flags are not working on mobile?
    Yes. The hardware and driver on mobile are much simpler than those on desktop. The most manufacturers of mobile are likely to ignore the flags now. But the developing of mobile is very rapid. So it’s possible that it will be supported by the manufacturers soon.

    I hope this helps. Please let us know if you have any questions.

    Thanks,
    Chris
    -------------------------------------------------------
    fyi : you can reach him (his email) here http://forums.adobe.com/message/6001351#6001351

    Thanks

    ОтветитьУдалить
  2. please continue to write your awesome blog. I learned a lot about stage3d and 3d graphics from it. many thanks.

    ОтветитьУдалить
  3. @katopz, yeah, as I thought. Thanks for your comment - it's very useful.
    @Eugene, I'll try ).

    ОтветитьУдалить