Skip to main content
Known Participant
August 9, 2011
Question

CPU to GPU during playtime?

  • August 9, 2011
  • 1 reply
  • 1015 views

Hey I'm Dan!

I'm currently wrapping up a 9 months game project for the iPhone 3GS/ 4, iPad & iPad 2 and I have managed to get great performance on my game so far. But recently I recieved a report from the german distributors saying that they have measured the amount of "Real Memory" and that it is way too high (>100).

I then started measuring myself to try and see the pattern why this happens with the tools "Instruments" on my iMac.

I'm using GPU rendering.

I started to see a pattern. My game is built up using a lot of scenes and coding directly in the timeline and it works great for me. Most of my backgrounds in the game are bitmaps and I started to see, when I measured, that when I got to this bitmap in the timeline I saw a rather big boost in "Real Memory" usage since the bitmap was uploaded to the GPU. Note that have all my graphical objects set out on the stage. The problem here is that once I navigated through that scene and went to the next one with the exact identical bitmap as the one that was recently uploaded, it uploaded again, and I saw a rather huge boost in "Real memory" usage again! So all these bitmaps in my game gets uploaded, but not re-used. Does anyone have an idea how I can reuse them?

I tried switching to CPU usage and it was great! Performance was good enough and the "Real memory" usage was low (70-80) compared to the GPU version. But, and there is a big but here- as soon as I was to play a mission in the game I fell into heavy stuttering. The player uses his/her finger to move an aim and is supposed to shoot the target. So basicly we've got an MC that is the aim (a sniper scope), three looping targets standing and talking (fbf animation) and a background cachedAsBitmapMatrix. The stuttering only occur when I move the aim around. As soon as I release the aim the stuttering is completely gone. I tried removing all elements except the aim and when I tried to move it with my finger it was still stuttering. Is there a way to optimize this aim for the CPU? Or is it somehow possible to switch from CPU rendering to GPU only when the player is about to play the missions? That means switching rendering modes while the app is running on the device. I might be completely out and fumbling here but should someone know anything about these rendering questions I'd be extremely grateful.

I'd love to be able to use the GPU without the incredibly high "Real Memory" usage due to so many bitmaps in the game or I would love to be able to use the CPU with optimizations for the CPU to get rid of the stuttering.

But beeing able to switch rendering mode while the app is running would be the ultimate choice;)

Anyone out there with some kind of solution or compromise?

Thank you for your time! I really appriciate it:)

Dan

This topic has been closed for replies.

1 reply

Frédéric C.
Inspiring
August 9, 2011

Hi Dan,

Interesting question in fact. I may be wrong, but I don't think it's possible to switch rendering mode on the fly. On the other hand, I'm not sure the stuttering is normal with a few objects on the screen.

With the first PFI, cacheAsBItmap and cacheAsBItmapMatrix were doing miracles. But with the last AIR 2.7 release, it seems they have the opposite effect. Adobe may have chosen to handle all things internally, allowing less performance fine tuning vs ease of port among various platforms. For CPU rendering, I'd try to remove all those optimizations, and see if I get better results. For now, the only reason I found for still using cacheAsBitmap and cacheAsBitmap matrix is on vector and textfield objects, because they are converted to bitmapdata on the fly (they must not be updated often though, or you'll get counter-productive effects). I did a lot of performance measures using latest AIR 2.7 SDK, and I finally decided to go for the CPU route, despite the fact I have huge objects moving on screen: the GPU mode can create hiccups sometimes, while the CPU mode generally offers a smoother, more consistent experience most of the time.

Good luck!

Frédéric

Known Participant
August 9, 2011

Hey Frédéric!

Thanks for your input! Yeah I also suspect switching rendering mode on the fly would be tough or impossible. The optimization that I have applied is basicly caching the vectors and minor tweaks. Should I remove those optimizations and test if the CPU does the work? Like I said, nothing is stuttering and everything's smooth except when the player is moving this aim with his/her finger. The aim is placed above all elements so I guess everything beneath it needs to be redrawn everytime it is moved or animated and that could be the cause this is happening? Or should it be powerful enough to handle this? Is there a way to send things to the GPU even though the CPU is the set rendering mode?

Thanks for anything that could help or point me in the right direction:)

Frédéric C.
Inspiring
August 9, 2011

Hmm, it's a bit difficult to give advices without seeing the actual source code/game, because there are many possible scenarios. From what I read, you have a cached background, you may try to remove this cache and see if it has any impact on performance.

Oh also, there is a method called System.gc() that forces the garbage collector to be activated. It might be interesting to use it between your scenes and see if that frees some memory in GPU mode.