PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Fullscreen mode kills performance

Problem:
If i run my app at 1280x1024 resolution in windowed mode, performance is excellent. However, if i switch to full screen (on the same desktop display that is 1280x1024), performance is very bad.

Analysis shows that the performance problems are exclusively in the gapidraw library calls: SetPixel(), GetPixel(), BltFast() and AlphaBlt*().

All I am doing to set full screen mode is:
1. pass the GDDISPLAY_FULLSCREEN option to OpenDisplay().
2. set dwDisplayHz = 75.

Any idea why this may occur? It does not seem to happen when using the plasma sample app and I do not see any differences between my app and the sample.

Thank you for any advise.
Problem is when running in full screen mode your back buffer will be stored in video memory, which means AlphaBlt and GetPixel will be terribly slow.

Check the plasma demo for the parameter GDDISPLAY_BACKBUFFERSYSMEM and add it to your application as well, and it should be same performance in windowed mode as in full screen mode.

Cheers
Johan
Thanks for the quick response. I'm still a bit confused though:

GDDISPLAY_BACKBUFFERSYSMEM is not used in any samples. I only see it in the header file. The Plasma sample only sets pixels and does not blt, but if i add in an AlphaBlt once per frame it also slows down considerably (to ~2 fps). So i can duplicate the problem outside of my application.

Then when i add GDDISPLAY_BACKBUFFERSYSMEM as a display flag passed to OpenDisplay, the problem persists.

Am i using this correctly?

Also, in the 'Simple' sample app, it constantly rotates and blts an image. And performance is good. So I'm not clear on how that is happening because when I add in my AlphaBlt, everything gets slow.

Thank you!
Hey,

You are right, seems I removed it a while ago from the samples.

If you add GDDISPLAY_BACKBUFFERSYSMEM to config.dwDisplayFlags in GapiDrawMain, it should run in exactly the same way as it runs in windowed mode.. Isn't there any performance difference at all when you add the flag?

Cheers
Johan
Johan,
After adding this flag there is some performance improvement, however it does not really approach the excellent normal windowed performance.

Do you know the reason why the 'simple' sample program runs with normal performance in full screen mode? Because it does a Blt too. However if I add in my own Blt, it slows noticeably (maybe 3x slower) even with GDDISPLAY_BACKBUFFERSYSMEM set.

If using GDDISPLAY_BACKBUFFERSYSMEM is expected to make performance equal to that of a windowed mode, something must be wrong. I could provide you the Simple sample to show you - I just add a new blt in once per frame.

Thank you
Hey,

Let me do some digging here to see what I can find first.

By the way:
1. What OS do you use?
2. What video adapter do you use (type and actual video memory)?

Cheers
Johan
1. Windows XP (+sp2)
2. Radeon X300/X550 Series by ATI Technologies. Looks like 12MB DDR1 memory.

Hopefully, this answers your question.

Thank you again!
correction: 128MB DDR (not 12)
Hey,

Maybe just email me the sample app and I'll look at it.

Cheers
Johan
I mailed to your develant.com address.
Johan,
It seems that performance is directly related to the amount of information being blt'd to the display buffer.

For example, if i blt 320x240 pixels I get about 21 FPS. If i blt 320x240x2 pixels i get about 11 FPS. If I blt 160x120 pixels, I get about 75 FPS.

So in my app, I flip the full screen every frame. Thus the poor performance.

Are you aware of any solutions for this? If not, I suppose we'll have to move to a DirectX option for full screen desktop.

Thanks.
Ok, to give a brief summary:

If you run in fullscreen mode, by default:
1. Backbuffer will be stored in video memory
2. All surfaces will be stored in video memory

If you want 100% identical performance to windowed mode you have to do two things:
1. Use the display flag GDDISPLAY_BACKBUFFERSYSMEM in GapiDrawMain
2. Use the flag GDRGBASURFACE_SYSTEMMEMORY when you use CreateSurface to force it to be created into system memory.

I saw in your example that you did not use any flags to create the splash image. Remember that reads from video memory is slow, and that alphablt is not accelerated by hardware in GapiDraw. Thus alphablt from a surface that is stored in video memory is slower than slow. :-)

So, change line 165 and 166 in GapiApplication.cpp and add "| GDRGBASURFACE_SYSTEMMEMORY" as a surface flag and you should all be set.

Also.. If you do an operation that is not hardware accelerated on a surface that is stored in video memory GapiDraw will "lock" the video surface during the operation. This locking also takes some overhead, and you thus have the operation LockVideoSurface() which you can call if you have to perform many non-HW accelerated functions on a surface stored in videomemory. Just remember to unlock it when you're done. :-)

Ok, sorry for all the theory ramblings. Specify to store all surfaces in systemmemory if you want to use alphablt and you should be all set. After that you can try some mix-and-match:
1. Try storing backbuffer in videomemory
2. Do all Blt and BltFast that is hardware accelerated if you copy from a surface stored in video memory - this is really fast
3. Then lock the backbuffer
4. Do all non-hw-accelerated stuff, such as alphablt. remember to store alpha surfaces in systemmemory.
5. unlock the backbuffer

With some fixin' you should be able to get much better performance in full screen mode than in windows mode.

Have a nice weekend, cheers
Johan
I'll give it all try - thanks for the input.

Cheers.
YES!!!!!!!!!

THIS IS AWESOME!!

I LOVE YOU. Works perfectly!
:) Nice to hear it's working..