Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Severe performance problems with a lot of bitmaps and subbitmaps.

This thread is locked; no one can reply to it. rss feed Print
Severe performance problems with a lot of bitmaps and subbitmaps.
kovarex
Member #14,203
April 2012

Related older topic: https://www.allegro.cc/forums/thread/615015

So I had this problem with performance, the game spent more and more time in the al_flip, and the time was also kind of random, but it could go up to 50ms.

After some investigation, I found out, the time is spent in the _al_d3d_prepare_bitmaps_for_reset that is called every flip, and goes through all of the (tens of thousands) sub-bitmaps we have just to find out it doesn't need to be updated.

More info in the version of the code we use now.

#SelectExpand
1static void d3d_flip_display(ALLEGRO_DISPLAY *al_display) 2{ 3 ALLEGRO_DISPLAY_D3D* d3d_display = (ALLEGRO_DISPLAY_D3D*)al_display; 4 ALLEGRO_DISPLAY_WIN *win_display = &d3d_display->win_display; 5 HRESULT hr; 6 7 if (d3d_display->device_lost) 8 return; 9 10 al_lock_mutex(present_mutex); 11 12 d3d_display->device->EndScene(); 13 14 hr = d3d_display->device->Present(NULL, NULL, win_display->window, NULL); 15 16 d3d_display->device->BeginScene(); 17 18 al_unlock_mutex(present_mutex); 19 20 if (hr == D3DERR_DEVICELOST) { 21 d3d_display->device_lost = true; 22 return; 23 } 24 else { 25 //_al_d3d_prepare_bitmaps_for_reset(d3d_display); 26 27 // This (commenting out the method) is our custom solution of the performance problem of this method when 28 // there are tens of thousands of sprites. 29 30 // In our case, vast majority of the sprites are either sub-bitmaps or bitmaps 31 // marked with NO_PRESEVE flag, so the loop wastefully goes through all of the bitmaps 32 // just to check, that none of these need to be updated. 33 34 // The proper solution would have to have special list of bitmaps that are relevant for the 35 // reset (no subbitmaps, preserved), and check only those. 36 37 } 38}

To avoid problems, I'm calling the _al_d3d_prepare_bitmaps_for_reset once all the game graphics is loaded, so the game bitmaps are preserved, but for the rest of the bitmaps, they are preserved manually.

The question is, is there something special I should be aware of?

www.factorio.com - a factory building game.

SiegeLord
Member #7,827
October 2006
avatar

Haha, wow, I'd never have thought that would become a performance bottleneck. Yes, what you're doing should be okay.

I should note that for the past 1 or 2 versions of 5.1, display->bitmaps no longer contains sub-bitmaps.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

kovarex
Member #14,203
April 2012

Thx for the info.

www.factorio.com - a factory building game.

Go to: