SDL slow window update and clear

I found out that my program - which only draw two pictures on the screen - runs at 200FPS. 200FPS is really low number at this point of development! It does not matter if I remove all textures and other data.

The slow part of code are SDL_RenderPresent and SDL_RenderClear. Without them, the program runs at about 300K FPS. Could you tell me where could be the problem?

Window and Renderer

Code:
_window = SDL_CreateWindow( “Window”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0 );

if ( _window == NULL ) {
    std::cout << "CreateWindow problem: " << SDL_GetError() << std::endl;
}

_renderer = SDL_CreateRenderer( _window, -1, SDL_RENDERER_ACCELERATED );

if ( _renderer == NULL ) {
    std::cout << "CreateRenderer problem: " << SDL_GetError() << std::endl;
}

Acording to SDL_RendererInfo only two flags are used - SDL_RENDERER_ACCELERATED and SDL_RENDERER_TARGETTEXTURE.

The main loop code
http://pastebin.com/fHdVDEsb

Timer class code
http://lazyfoo.net/SDL_tutorials/lesson12/index.php

Thank you for help------------------------
I’m SDL newbie

I found out that my program - which only draw two pictures on the screen -

runs at 200FPS. 200FPS is really low number at this point of development!
It does not matter if I remove all textures and other data.

I’m quite sure the problem is in the window compositor that add a vsync
somewhere also if you do not ask for it.

Try to benchmark with something in the scene, like a thousand of random
textures and see if the frame rate drops, do not worry about performance in
advance :)–
Bye,
Gabry

I tried this code as “benchmark”:

Code:

SDL_Rect rect;
SDL_Color color;

game->window.clear();

for ( int i = 0; i != 1000; i++) {

    rect = {
        ( std::rand() % 800 ),
        ( std::rand() % 600 ),
        40 + ( std::rand() % (200 - 60 + 1) ),
        40 + ( std::rand() % (200 - 60 + 1) )
    };
    
    color = {
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
    };
    
    game->window.setDrawingColor( color );
    game->window.fillRect( &rect );
}

game->window.update();

FPS is around 18. Well there is solid performance problem!------------------------
I’m SDL newbie

That’s not random textures.
That’s just random size and colors. They’re cheap.
Again, check for v-sync where you don’t ask for it.

The reason why your profiler says that SDL_RenderPresent is the slowest is
because it does the bulk of the work. This is actually what does all those
expensive draw calls.

Also, check if your context is indeed hardware accelerated. Your hint might
have been ignored.

I’m not quite sure about why SDL_RenderClear shows up as slow though.
Doesn’t it just do a glClear(GL_COLOR_BUFFER_BIT)? I’m looking it up in the
source code right now.On Fri, Mar 14, 2014 at 7:14 PM, lorin wrote:

I tried this code as “benchmark”:

Code:

SDL_Rect rect;
SDL_Color color;

game->window.clear();

for ( int i = 0; i != 1000; i++) {

    rect = {
        ( std::rand() % 800 ),
        ( std::rand() % 600 ),
        40 + ( std::rand() % (200 - 60 + 1) ),
        40 + ( std::rand() % (200 - 60 + 1) )
    };

    color = {
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
    };

    game->window.setDrawingColor( color );
    game->window.fillRect( &rect );
}

game->window.update();

FPS is around 18. Well there is solid performance problem!


I’m SDL newbie


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I know, but even with this “low cost” benchmart the program runs around 18 FSP. I means that something is really slowing the rendering down.

How can I check the V-sync? According to SDL_RendererInfo, V-sync flag is not set and HW acceleration is on. I do not know how to test this in system (i mean outside of SDL app).

For testing purposes, I moved to Windows to test it on another OS. And it seems that it is Linux what caused the problem (drivers, config, whatever), because in Windows, program runs around 4000 FPS. This number looks much better. :slight_smile:

I am going to reinstall graphics drivers, that is all I can think of to do right now.
Any suggestion?

Ivan Rubinson wrote:>

That’s not random textures.

That’s just random size and colors. They’re cheap.

Again, check for v-sync where you don’t ask for it.

The reason why your profiler says that SDL_RenderPresent is the slowest is because it does the bulk of the work. This is actually what does all those expensive draw calls.

Also, check if your context is indeed hardware accelerated. Your hint might have been ignored.

I’m not quite sure about why SDL_RenderClear shows up as slow though. Doesn’t it just do a glClear(GL_COLOR_BUFFER_BIT)? I’m looking it up in the source code right now.

On Fri, Mar 14, 2014 at 7:14 PM, lorin <@lorin (@lorin)> wrote:

   	I tried this code as "benchmark": 




Code:

? ?SDL_Rect rect;
? ? SDL_Color color;
? ?
? ? game->window.clear();
? ?
? ? for ( int i = 0; i != 1000; i++) {

? ? ? ? rect = {
? ? ? ? ? ? ( std::rand() % 800 ),
? ? ? ? ? ? ( std::rand() % 600 ),
? ? ? ? ? ? 40 + ( std::rand() % (200 - 60 + 1) ),
? ? ? ? ? ? 40 + ( std::rand() % (200 - 60 + 1) )
? ? ? ? };
? ? ? ?
? ? ? ? color = {
? ? ? ? ? ? ( std::rand() % 255 ),
? ? ? ? ? ? ( std::rand() % 255 ),
? ? ? ? ? ? ( std::rand() % 255 ),
? ? ? ? ? ? ( std::rand() % 255 ),
? ? ? ? };
? ? ? ?
? ? ? ? game->window.setDrawingColor( color );
? ? ? ? game->window.fillRect( &rect );
? ? }
? ?
? ? game->window.update();

FPS is around 18. Well there is solid performance problem!

I’m SDL newbie


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)


I’m SDL newbie

What GPU are you using? Which distro/version of Linux?

2014-03-14 20:51 GMT+01:00 lorin :> I know, but even with this “low cost” benchmart the program runs around

18 FSP. I means that something is really slowing the rendering down.

How can I check the V-sync? According to SDL_RendererInfo, V-sync flag is
not set and HW acceleration is on. I do not know how to test this in system
(i mean outside of SDL app).

For testing purposes, I moved to Windows to test it on another OS. And it
seems that it is Linux what caused the problem (drivers, config, whatever),
because in Windows, program runs around 4000 FPS. This number looks much
better. [image: Smile]

I am going to reinstall graphics drivers, that is all I can think of to do
right now.
Any suggestion?

Ivan Rubinson wrote:

That’s not random textures.

That’s just random size and colors. They’re cheap.

Again, check for v-sync where you don’t ask for it.

The reason why your profiler says that SDL_RenderPresent is the slowest is
because it does the bulk of the work. This is actually what does all those
expensive draw calls.

Also, check if your context is indeed hardware accelerated. Your hint
might have been ignored.

I’m not quite sure about why SDL_RenderClear shows up as slow though.
Doesn’t it just do a glClear(GL_COLOR_BUFFER_BIT)? I’m looking it up in the
source code right now.

On Fri, Mar 14, 2014 at 7:14 PM, lorin <> wrote:

Quote:

I tried this code as “benchmark”:

Code:

SDL_Rect rect;
SDL_Color color;

game->window.clear();

for ( int i = 0; i != 1000; i++) {

    rect = {
        ( std::rand() % 800 ),
        ( std::rand() % 600 ),
        40 + ( std::rand() % (200 - 60 + 1) ),
        40 + ( std::rand() % (200 - 60 + 1) )
    };

    color = {
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
        ( std::rand() % 255 ),
    };

    game->window.setDrawingColor( color );
    game->window.fillRect( &rect );
}

game->window.update();

FPS is around 18. Well there is solid performance problem!

I’m SDL newbie


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


I’m SDL newbie


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Don’t know how it works in Linux, but in windows if you’re windowed in SDL it pretty much syncs each frame to vsync regardless of vsync settings in graphics drivers.

Only if you go fullscreen and have vsync turned off both in drivers and in SDL will you get frames being presented faster than the sync of the monitor.