Digging Deeper: Galloping Horses Example

Rather than pull out a bunch of math and traditional timing diagrams, we've decided to put together a more straight forward presentation. The diagrams we will use show the frames of an actual animation that would be generated over time as well as what would be seen on the monitor for each method. Hopefully this will help illustrate the quantitative and qualitative differences between the approaches.

Our example consists of a fabricated example (based on an animation example courtesy of Wikipedia) of a "game" rendering a horse galloping across the screen. The basics of this timeline are that our game is capable of rendering at 5 times our refresh rate (it can render 5 different frames before a new one gets swapped to the front buffer). The consistency of the frame rate is not realistic either, as some frames will take longer than others. We cut down on these and other variables for simplicity sake. We'll talk about timing and lag in more detail based on a 60Hz refresh rate and 300 FPS performance, but we didn't want to clutter the diagram too much with times and labels. Obviously this is a theoretical example, but it does a good job of showing the idea of what is happening.

First up, we'll look at double buffering without vsync. In this case, the buffers are swapped as soon as the game is done drawing a frame. This immediately preempts what is being sent to the display at the time. Here's what it looks like in this case:

 


Good performance but with quality issues.


 

The timeline is labeled 0 to 15, and for those keeping count, each step is 3 and 1/3 milliseconds. The timeline for each buffer has a picture on it in the 3.3 ms interval during which the a frame is completed corresponding to the position of the horse and rider at that time in realtime. The large pictures at the bottom of the image represent the image displayed at each vertical refresh on the monitor. The only images we actually see are the frames that get sent to the display. The benefit of all the other frames are to minimize input lag in this case.

We can certainly see, in this extreme case, what bad tearing could look like. For this quick and dirty example, I chose only to composite three frames of animation, but it could be more or fewer tears in reality. The number of different frames drawn to the screen correspond to the length of time it takes for the graphics hardware to send the frame to the monitor. This will happen in less time than the entire interval between refreshes, but I'm not well versed enough in monitor technology to know how long that is. I sort of threw my dart at about half the interval being spent sending the frame for the purposes of this illustration (and thus parts of three completed frames are displayed). If I had to guess, I think I overestimated the time it takes to send a frame to the display.

For the above, FRAPS reported framerate would be 300 FPS, but the actual number of full images that get flashed up on the screen is always only a maximum of the refresh rate (in this example, 60 frames every second). The latency between when a frame is finished rendering and when it starts to appear on screen (this is input latency) is less than 3.3ms.

When we turn on vsync, the tearing goes away, but our real performance goes down and input latency goes up. Here's what we see.

 


Good quality, but bad performance and input lag.


 

If we consider each of these diagrams to be systems rendering the exact same thing starting at the exact same time, we can can see how far "behind" this rendering is. There is none of the tearing that was evident in our first example, but we pay for that with outdated information. In addition, the actual framerate in addition to the reported framerate is 60 FPS. The computer ends up doing a lot less work, of course, but it is at the expense of realized performance despite the fact that we cannot actually see more than the 60 images the monitor displays every second.

Here, the price we pay for eliminating tearing is an increase in latency from a maximum of 3.3ms to a maximum of 13.3ms. With vsync on a 60Hz monitor, the maximum latency that happens between when a rendering if finished and when it is displayed is a full 1/60 of a second (16.67ms), but the effective latency that can be incurred will be higher. Since no more drawing can happen after the next frame to be displayed is finished until it is swapped to the front buffer, the real effect of latency when using vsync will be more than a full vertical refresh when rendering takes longer than one refresh to complete.

Moving on to triple buffering, we can see how it combines the best advantages of the two double buffering approaches.

 


The best of both worlds.


 

And here we are. We are back down to a maximum of 3.3ms of input latency, but with no tearing. Our actual performance is back up to 300 FPS, but this may not be reported correctly by a frame counter that only monitors front buffer flips. Again, only 60 frames actually get pasted up to the monitor every second, but in this case, those 60 frames are the most recent frames fully rendered before the next refresh.

While there may be parts of the frames in double buffering without vsync that are "newer" than corresponding parts of the triple buffered frame, the price that is paid for that is potential visual corruption. The real kicker is that, if you don't actually see tearing in the double buffered case, then those partial updates are not different enough than the previous frame(s) to have really mattered visually anyway. In other words, only when you see the tear are you really getting any useful new information. But how useful is that new information if it only comes with tearing?

What are Double Buffering, vsync and Triple Buffering? Wrapping It Up
Comments Locked

184 Comments

View All Comments

  • velanapontinha - Friday, June 26, 2009 - link

    The eyes and brain that watch a game or a movie are the same. If there was a "Pepsi challenge"-like contest between 30fps, 60fps and 200fps, the error rate would be astronomical, and a lot of overspending gamers would feel bad about spending so much money on hardware that is able to create frames they never see - nor even miss.
  • JS - Friday, June 26, 2009 - link

    The difference is not in the frame rate, but the fact that a film is not a sequence of perfectly sharp static images (like games normally are). Motion blur is automatically introduced by the shutter time on the film camera. That is why 24 fps works for film but not so well for games.

    Most people would definitely see the difference.
  • james jwb - Friday, June 26, 2009 - link

    films also do not require the viewer to make decisions based on what they see. For a movie, fast paced movements in a war scene doesn't require the viewer to see every detail in perfect accuracy and definition, what happens next isn't your choice, you are just watching. In a game, what you see decides what you'll do, and a motion blurred to death fast movement will never suffice in some game genres. You need a compromise somewhere and with games, a higher than film frame rate will significantly help overcome this.
  • BJ Eagle - Saturday, June 27, 2009 - link

    Ahh - good point about the bluring in films...

    But heres another one then:
    In nVidia control panel (vista x64 driver ver 186.18) it clearly states under triple buffering (though only OpenGL is affected as discussed) "Turning on this setting improves performance when Vertical sync is also turned on"...
    This is not quite the impression I got from reading this article. Clearly there is still some confusion of when to enable what settings and having an article like this contradicting nVidias recommendation doesn't really help.. me at least :)
  • profoundWHALE - Monday, January 19, 2015 - link

    I'm just going to leave this here:

    http://www.testufo.com/
  • james jwb - Friday, June 26, 2009 - link

    I can see myself using triple buffering in most situations, but games like CS:S, i don't think it would be wise. For a game like this consistently high frame and refresh rates would be the preferred option. Actually that would be the preferred option for all games, but in order to do this you'd have to delay playing new, graphic intensive games for two years to allow the hardware to catch up.
  • DerekWilson - Friday, June 26, 2009 - link

    i'd still want triple buffering for CS:S ...

    for me, tearing is distracting and i use the top of my display more than the bottom (even if new data were drawn lower on the screen it wouldn't be beneficial to me).
  • james jwb - Friday, June 26, 2009 - link

    ah, see here's a point to consider as to why i said what i said. I use a CRT at 100hz, so the tearing issue becomes almost insignificant. Sure, if I was on an LCD I would agree with youm tearing in CS:S is a disaster in that scenario.
  • JarredWalton - Friday, June 26, 2009 - link

    What I really want is LCDs with a native 120Hz refresh rate and data rate. That last part is key; I want 1920x1200 at 120Hz, not 1920x1200 with 60 images and some funky software interpolating to 120Hz. It would require DisplayPort, dual-link DVI, or HDMI 1.4 (I think?), but with triple buffering that would be the best of all worlds.
  • james jwb - Friday, June 26, 2009 - link

    @ Jarred, i couldn't agree more, but you know that already :)

    If someone like HP can bring a 24" IPS 120hz to market with similar performance to their current model, I'd be in tech-drool heaven. Under this scenario, I'd play CS:S with double buffering, no v-sync, but games that were graphic intensive and could not sustain high frame rates, I'd definitely love the option of triple buffering.

Log in

Don't have an account? Sign up now