Very bad performance with a single bitmap [5.0.5] (Blending issue?)
Max Savenkov

I'm getting very bad performance on my Asus EEE PC 1101HA with Allegro 5.0.5. The only thing I do is draw a single bitmap on screen. Basically, my code looks like this (not the exact code, may contain misspellings or insignificant errors):

al_set_new_bitmap_flags( ALLEGRO_MIPMAP );
al_set_new_display_flags( ALLEGRO_WINDOWED | ALLEGRO_DIRECT3D );
ALLEGRO_DISPLAY *display = al_create_display( 800, 600 );
ALLEGRO_BITMAP *bmp = al_load_bitmap( "bitmap.png" );
while( true )
{
    // Some code to count FPS...
    al_draw_scaled_bitmap( bmp, 0, 0, 700, 500, 0, 0, 800, 600, 0 );
}

I'm getting about 4FPS with that code. While I understand that Intel GMA 500 isn't very good video card, I believe that my old P233 with S3 video card could have handled this task with a lot more FPS...

So, I profiled the code with some external profilers, and got this results: running program takes 100% of CPU time (not surprising, since there is no call to al_rest or sleep), and the function that takes all the time is this:

shader_texture_solid_any_draw_shade_white

which calls this:

_al_blend_inline

After reading the source for Allegro functions, I found out that they implement software blending (despite having a promising "shader" in name :) ). The same code runs at about 5000FPS on my main development rig (Core i7), so it seems that Asus puny CPU just can't handle all those blendings. But here lies a problem: I do not, in fact, do any blending in that case! I understand that Allegro calls blending function anyway, but... It leads to horrible performance.

So, I seek an advice. Should I:

1) Change my code somehow to get better performance when blending is not involved (then again, I'll need blending later, so it's not a very good option)

2) Tap my pool of available graphic software expertise (while I don't do low-level graphic programming, some of my colleagues do) and optimize/rewrite Allegro blending like a hero

3) Wait for main Allegro developers to do 2) :) Or just update to the latest SVN build, if that problem is solved by it already.

4) Just bump up system requirement to exclude low-end netbooks :)

5) Other

Elias

Try ALLEGRO_VIDEO_BITMAP instead of ALLEGRO_MIPMAP. Does it have more FPS?

Max Savenkov

No, that flag did not help (BTW, it's on by default as far as I know). But I discovered that I get the same FPS on the main PC, if I set MEMORY_BITMAP. So it seems that somehow Allegro is just unable to create video bitmaps on my netbook! That explains everything.

The question remains why VIDEO_BITMAP has no effect. As far as I can see in the code, the only case when MEMORY_BITMAP is checked and ignored is here:

static ALLEGRO_BITMAP *do_create_bitmap(int w, int h)
{
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_BITMAP **back;
   ALLEGRO_SYSTEM *system = al_get_system_driver();
   ALLEGRO_DISPLAY *current_display = al_get_current_display();

   if ((al_get_new_bitmap_flags() & ALLEGRO_MEMORY_BITMAP) ||
         (!current_display || !current_display->vt || current_display->vt->create_bitmap == NULL) ||
         (system->displays._size < 1)) {
      return _al_create_memory_bitmap(w, h);
   }

Unfortunately, I can't debug the game on netbook right now, so I can't step into Allegro and find out which condition is wrong.

One thing is for sure: I DO NOT create bitmap before creating display, so all these conditions should be satisfied. I'll try to restore my debugging capabilities and see what goes wrong, but I'm not really sure.

EDIT: No, it's not that. Bitmaps are video (checked by testing for ALLEGRO_VIDEO_BITMAP) after load_bitmap). It seems like I narrowed that down to either lying profiler (two profilers, actually) or VERY shitty Intel driver/hardware which can't even handle simplest things. Arrgh. That might drive me crazy. My 10 year old computer could draw that bitmap 60 times a second, and that f...ing netbook can't.

OK, it seems like I'm going to go with "no shitty Intel hardware" system requirement. Allegro has nothing to do with it, so...

Thread #609630. Printed from Allegro.cc