Very slow rendering

I’m experiencing very slow rendering on my Debian 8 system (SDL2 version 2.0.4). Here’s an example:

Code:

#define _GNU_SOURCE

#include <stdio.h>
#include <SDL.h>

#include <time.h>

int main(void)
{
SDL_version version;
SDL_GetVersion(&version);
printf("%d.%d.%d\n", (int) version.major, (int) version.minor, (int) version.patch);

SDL_Init(SDL_INIT_VIDEO);

SDL_Window *window = SDL_CreateWindow( "An SDL2 window",
    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    640, 480,
    SDL_WINDOW_SHOWN);

SDL_Renderer *renderer = SDL_CreateRenderer(window,
    -1, SDL_RENDERER_ACCELERATED);

SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);

for (int i = 0; i < 60; i++) {
    SDL_RenderClear(renderer);

    struct timespec start_get_time, end_get_time;
    Uint32 start_get_ticks, end_get_ticks;

    start_get_ticks = SDL_GetTicks();
    clock_gettime(CLOCK_MONOTONIC, &start_get_time);

    SDL_RenderPresent(renderer); /* TOO SLOW */

    clock_gettime(CLOCK_MONOTONIC, &end_get_time);
    end_get_ticks = SDL_GetTicks();

    long nsecs = end_get_time.tv_nsec - start_get_time.tv_nsec;

    printf("nsecs: %ld\n", nsecs);
    printf("msecs: %u\n", (unsigned) end_get_ticks - start_get_ticks);
}

SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;

}

and here’s some of the output:

Code:

2.0.4
nsecs: 407449
msecs: 0
nsecs: 306949
msecs: 1
nsecs: 483087
msecs: 0

nsecs: 30375208
msecs: 31
nsecs: 4968098
msecs: 5
nsecs: 28803868
msecs: 29
nsecs: 5190540
msecs: 5
nsecs: 25599449
msecs: 26
nsecs: 28874268
msecs: 30
nsecs: 5098142
msecs: 5
nsecs: 27725881
msecs: 28
nsecs: 29498292
msecs: 29
nsecs: 5148706
msecs: 5
nsecs: 25935731
msecs: 26
nsecs: 1477544
msecs: 1

is that… normal? i assume not? in the real applications, these slowdowns are a lot more consistent. 12-25 milliseconds per call to RenderPresent. strace shows the following:

Code:

socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path=@"/tmp/.X11-unix/X0"}, 20) = 0

recvmsg(3, 0x7ffd9801e220, 0) = -1 EAGAIN (Resource temporarily unavailable)
recvmsg(3, 0x7ffd9801e220, 0) = -1 EAGAIN (Resource temporarily unavailable)

Again, there is a lot more “Resource unavailable” in the real program. Any advice?

So this is interesting.
I wrapped the body of my main rendering function in a loop, that executes it 1000 times. Most of the calls, I see acceptable framerate - 400, 500 fps (2-2.5 msecs per iteration of the loop). But sometimes - I can’t determine what triggers it - the wramerate drops to 59-60 fps (and no lower). It’s as if the vsync randomly turns on. I’m pretty sure that nothing in my code limits the framerate… any ideas? :slight_smile:

Can someone at least tell me just how long - in milliseconds or nanoseconds - should rendering take? I’m talking about the call to RenderPresent only. For example, on Windows machines? I just don’t know what to expect. Maybe SDL2 is simply not a good choice for this particular application. Although SDL1 works just fine… I tried SDL_RENDERER_SOFTWARE (and many other things), that didn’t make any difference. So, is 5 milliseconds normal? 10?

I have an equivalent situation, previously presented in this forum. Very
good refresh rate with SDL1 and slower rate with SDL 2.0x. My applications
run under Windows.

ArmandoOn Wed, Jun 8, 2016 at 3:31 AM, nmapp wrote:

Can someone at least tell me just how long - in milliseconds or
nanoseconds - should rendering take? I’m talking about the call to
RenderPresent only. For example, on Windows machines? I just don’t know
what to expect. Maybe SDL2 is simply not a good choice for this particular
application. Although SDL1 works just fine… I tried SDL_RENDERER_SOFTWARE
(and many other things), that didn’t make any difference. So, is 5
milliseconds normal? 10?


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