A demo was recently released by Adobe (Thibault Imbert, Blog Post). It features an optimized use of Stage3D. By grouping assets that use the same texture, the number of drawTriangles calls is minimized. Adobe wrapped up this principle in a little framework (called GPUSprite) based on a metaphor of a stage with layers of content containing sprites.
The framework is clever and is a great starting point for understanding Stage3D optimization. I was surprised to see that a framerate measurement layer was placed over the top of the Stage3D content in a traditional Display List layer. It was my understanding that any Display List content over Stage3D would have a significant performance impact. To test this, I modified the sample to display the framerate in a new Stage3D layer and ditched the Display List (actually, you can toggle between the 2 views).
Grab a copy of my modified project here:
BunnyMark Stage3D Update
Surprisingly, performance was not impacted on the desktop and on an iPad1 it was only minimally impacted (perhaps a 1-2 fps savings, but erratic). I am surprised that the mix of Display List and Stage3D content does not cause more diminished performance.
A few notes on my approach to the modification
The Adobe GPUSprite framework was designed to specify UV values for a Sprite just once and never change the UV values for that Sprite. For the display of numerals in this app, I wanted to try shifting the UV values associated with each Sprite numeral rather than removing each of the numeral Sprites and adding a new replacement Sprite for each numeral. I extended a couple of the GPUSprite classes to enable UV shifting.
Some changes and features of the modified app
- Click in the top-left corner to toggle between Display List and Stage3D view.
- I use a single shared framerate counter to provide content for both the Stage3D FPS display and the DisplayList FPS display.
- I scale-up the small Stage3D text without smoothing (that’s why it looks chunky). I could have just used a larger source bitmap for the numerals, but I wanted to give this a try (enlarging a Sprite without smoothing for an exaggerated pixellated look).
- I didn’t modify the Adobe framework classes. I had to extend a couple of them to make the UV updating work.