SDL_GL_SwapBuffers() is slow

Discussion in 'Game Development (Technical)' started by esrix, Jun 5, 2006.

  1. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    I've been trying to get a stable 60 fps using SDL + OpenGL. Every other line of code seems to be going at a decent speed, but SDL_GL_SwapBuffers() is very very slow to execute. I've even put glFlush() and glFinish() after it and it still runs slow.

    Anyone have any suggestions on how to get around this?
     
  2. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    How did you determine that function was slow?

    Also as an FYI: glFlush and glFinish actually slow you down. glFlush blocks GPU command buffer read until all prior ops are completed. glFinish blocks the CPU (!) until all prior ops are completed. Take them out unless you need them for a particular purpose.
     
  3. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    I'm not sure if it's the same thing, but while I was using AllegroGL instead of SDL, my app would happily render at 100/120 fps. After switching, it locked to 60 (my monitor refresh rate). I'm guessing SDL enables some sort of refresh sync, but I havn't seen any way to turn it off.

    AllegroGL (for whatever reason) was quite unstable, so I've just learned to live with SDL's sync'ed update.
     
  4. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    OpenGL by default syncs to the monitor refresh. You need to use wglSwapIntervalEXT() to turn it off (which, oddly, is not a formal WGL function but rather an extension).

    It could be that AllegroGL disables vsync by default while SDL doesn't touch it.

    Edit: Typos, all instances of "gl" should be "wgl" :)
     
    #4 vjvj, Jun 5, 2006
    Last edited: Jun 5, 2006
  5. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    I've been using SDL_GetTicks() to compare times for the major functions. Every other function is getting 2 - 4 milliseconds to complete. SDL_GL_SwapBuffers() is taking a good 14 to 27 milliseconds, even without glFlush and glFinish. My framerate occassionally hits 62 but dips as low as 34 with just one or two basic programs like Firefox and Notepad running.

    I'm don't think it's a hardware performance issue, as I've tested the Irrlicht Engine from source and gotten well into the hundreds for my FPS.
     
  6. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    It sounds like you might be doing something wrong. 14-27 ms to swap buffers is crazy if not impossible under normal circumstances. Someone who knows SDL better should probably chime in at this point and look for usage problems.

    I'm rendering to OpenGL through SDL as well, and I'm CPU bound (my code is the bottleneck, not SDL) at 450 fps.

    Edit: Oh and I advise using a real profiler instead of SDL_GetTicks() :)
     
  7. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    Vjvj- any suggestions on a proper profiler?
     
  8. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    Codeanalyst by AMD if you are on an Athlon, otherwise VTune if you are on Intel. Codeanalyst is free, unfortunately VTune is not free.

    You also might want to check out www.gamedev.net, their forums are more populated and they have more people who can help you out.
     
  9. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Awesome, thanks vjvj. That was exactly what I was looking for, and it did the trick.
     
  10. PeterM

    Original Member

    Joined:
    Aug 5, 2004
    Messages:
    343
    Likes Received:
    0
    I believe the new version of SDL has a new SDL_GL_ATTRIBUTE that allows you to set the swap interval, so you don't have to call a WGL specific function.
     
  11. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    Okay, I've got an AMD 3000 xp, so I'll be downloading it's profiler today. And I'll download the newest version of SDL. Thanks guys! Really appreciate it :)
     
  12. PeterM

    Original Member

    Joined:
    Aug 5, 2004
    Messages:
    343
    Likes Received:
    0
    How are you drawing your stuff?

    Maybe the delay isn't the swap, but the 3D card driver waiting for drawing to complete.
     
  13. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    Awesome, thanks! I didn't know that.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer