What does vSync mean and how does it affect tearing and jerkiness?
Autor: Johannes Post
06/13/2006, 18:35 CET
Tearing, jerkiness, frame drops – all of these are issues which mostly gamers feel annoyed by, as they can often make all the difference between winning and losing. With the following five aspects, we want to try to give a comprehensible in-depth explanation of what some of the pros and cons of vertical synchronization in this context are.
Further discussions concerning this topic can be found in the Prad board by using the search function.
1. What does the VGA card do? What is "vSync"?
The vertical frequency, (abbr. vSync) is generated by the graphics card. This works as follows:
A clock generator on the graphics card creates the pixel clock. This is usually somewhere in the MHz range. The length of a pixel clock cycle determines the time that passes between two individual pixels that the graphics card sequentially (successively) sends out at its VGA or DVI output.
Advertisement
A counter counts the cycles of the pixel clock on each line. Each time a line (including borders and invisible pixels for the horizontal retrace of the electron ray) is completed, a hSync impulse is generated and the counter is reset. This way, the so called horizontal frequency (hSync) is created. A line is always run through from the left to the right.
Another counter counts the lines. Each time an entire picture was completed, a vSync impulse is generated and the counter is reset.
During all of that time, voltages signaling the respective color intensity for the current pixel are applied to the R, G and B channels of the VGA output.
This way, the VGA card continuously transmits picture after picture; one for every vertical cycle. Each picture is transmitted line after line from the top to the bottom. Each line is transmitted pixel after pixel from the left to the right.
DVI almost works the same way – with the difference of the signals carried the wires for the color channels being digital instead of analog. However, DVI transmits (on a separate wire) the pixel clock as well. Whereas in case of the analog transmission, there are only the hSync and vSync impulses apart from the color values.
The graphics card retrieves the necessary information from the video memory which is usually located on the graphics card itself. The way this information is encoded depends on the color depth (more exactly: pixel format) of the respective current graphics settings of the PC.
There are quite a number of color depths: 1 bits per pixel (black/white), 2 bits per pixel (CGA, 4 colors), 4 bits per pixel (EGA, 16 colors), 8 bits per pixel (VGA, 256 colors), 16 bits per pixel (65536 colors), 24 und 32 bits per pixel (both about 16.7 million colors).
With regard to the amount of colors, there is no difference between 24 and 32 bits. A maximum of 8 bit per pixel can be interpreted for each color channel. The main reason why 32 bit is used, is because it exactly equals the word length of 32 bit processors. One "word" of a processor is defined as the amount of data that fits into one (standard) (data) register of a processor.
This allows for higher access speeds to individual pixels and simplifies designing graphics processors. For this reason, most games only offer the settings of either 16 bit or 32 bit, but not for 24 bit, - although the latter is feasible, too - as it would just be slower.
However the information on the graphics card encoded may be encoded, the colors are always reproduced the same way as voltages on the VGA output. Generating these voltage values is done by three digital analog converters working in parallel, the so called "RAMDAC".
These have to be pretty fast: A pixel clock of 162 MHz would be typical for 1600 x 1200 pixels. 162 million times per second the RAMDAC has to generate three voltage values from three digital 8 bit values.
Thus, internally on a digital level, the graphics card already converts each color depth to 3 times 8 bit during the output! Depending on the graphics mode utilized, the part of the video memory used for the actual picture at display will take up a different size (in bit), which is calculated by multiplying the amount of pixels by color depth. This part of the graphics memory is referred to as "frame buffer".
Hence, different graphics modes are defined by pixel format, pixel clock, line length (in pixels), picture height (in lines), and sizes of the border areas and the retrace areas.
Using the appropriate tools such as "Powerstrip" (Windows) or "Modelines" (Linux), one is free to create an almost arbitrary amount of custom graphic modes.
2. How is the illusion of motion created?
The content shown on the monitor is a continuous sequence of pictures that are transmitted from the graphics card. If we only show the desktop, these pictures are (almost) always identical to each other.
But, in order to create motion, these pictures have to change over time. Which means that the content of the video memory has to be changing continuously. To make the mouse cursor move on the Windows desktop, the following cycle runs in a continuous loop:
- Retrieve new mouse position
- Save the rectangular area of the desktop at the new mouse position. (i.e. copy it from the frame buffer to a different part of the memory
- "Paint" mouse pointer at its new position into the frame buffer.
- Wait some time (or respectively do something else , e.g. continue to execute the currently running program)
- Delete the mouse pointer again by copying the previously saved area back again.
- Redo the mouse cycle
It should not be too hard to recognize that this method is anything but perfect: For a short time just after deleting the mouse pointer, there is no mouse pointer at all in the frame buffer!
If the position of the mouse on the desktop is supposed to be changed, the mouse pointer needs to be "turned off" temporarily, because otherwise the saved background rectangle would not be correct anymore.
However, these "mouse drops" can hardly ever be observed nowadays, since PCs simply have become so fast that process of deleting and redrawing of the mouse pointer is a matter of way less than the millionth part of a second.
In this period, even the highest resolutions graphics modes transmit a few dozen pixels only. Thereby, the probability of pixels being transmitted at this position and at the very moment when the mouse is being deleted is very low.
More important, however, is the fact that the timing of the mouse cycle is usually not synchronized with the vertical frequency of the graphics card. This means: Every mouse cycle takes about the 50th part of a second.
But, what the graphics card is doing in the meantime is not taken account of in all this. It is not hard to imagine how a sequence of picture transmitted from the VGA output of the graphics card must look like: Occasionally, the mouse will occur on the same position in two consecutive pictures.
It is in the nature of the human eye to trace moving objects. If we move the mouse, we automatically follow the mouse pointer with our eyes. However, the eye assumes a relatively uniform motion. The irregularities resulting from the lack of synchronization are therefore perceived as unnatural and annoying.
But PC users seem to have adapted to the jerkiness of the mouse surprisingly well. This can be interpreted as another indicator for the enormous adaptability of the human brain. Note: on almost all of the "old" computer system (i.e. Atari ST, Amiga, C64) the mouse was synchronized!
3. How does this apply to the way images are displayed in games?
First, there are usually considerably more objects moving in a game than just the mouse pointer. As a rule, 3D games continuously recalculate actually the entire picture. Here, the "drop" problem, which can almost never be perceived with the mouse pointer alone, takes entirely different proportions:
The calculation of one frame for a 3D game usually works in such a way that the entire previous picture gets deleted, just to rebuild the new picture object after object (or polygon after polygon). Each completed picture is referred to as "frame".
The number of frames drawn per second is called "frame rate" and is measured in "frames per second", or short: fps. The process of calculating such a frame is one of the most elaborate tasks of a game.
This is also why the frame rate often goes way down when there is a lot of action going on in the game: the reason being that the computer just can't cope with calculating the frames fast enough any more.
Now let's imagine all of this happened inside the frame buffer. The result would be hideous flickering since most of the time one would see the picture in the process of being drawn.
However, since the video output of VGA cards works in a continuous manner, it would be pure chance to have the VGA card read the frame buffer just at the very moment when the calculation of a picture has been completed.
For this reason, almost all of the games use "Double Buffering": There is a primary buffer (frame buffer) and a back buffer. The back buffer is intended for drawing the next picture, while the primary buffer stores the previous picture in all its beauty.
As soon as the new picture is ready, a page flip is performed: In doing so, the back buffer is declared the new primary buffer and what was previously the primary buffer now becomes the back buffer.
Graphics cards are able to swap frame buffers addresses at any given time! And each time, the currently ongoing video signal output is seamlessly continued at the exact same pixel position in the new frame buffer.
3. How do vSync and Tearing relate to each other?
This is exactly where we cut to the core of the issue. Because everytime the aforementioned happens, we get the situation of seeing one frame changing to the next frame "in the middle" of the picture.
Therefore, there will be a horizontal split (somewhere) in the picture transmitted by the graphics card: the previous frame is above the split and the new one below the split. This effect is called tearing since this split literally "tears" frames apart.
Tearing will occur always and as a basic principle whenever there is vertical synchronization is disabled.
Now, if the frame rate is substantially higher than the vertical frequency (e.g. vertical frequency 60 Hz, frame rate 150 Hz), there will be generally even more than one page-flip occurring per vertical cycle, resulting in a picture divided into several parts, with each one representing one of the previous frames!
If the frame rate is lower than the vertical frequency, one occasionally will be able to see pictures without a split in them.
If vertical synchronization is enabled, it means that the page flip is basically held back until the next vSync impulse is generated. The transition to the next picture is not performed until the transmission of an entire frame is completed.
This way, it is ensured that only complete pictures are transmitted and that no tearing can occur, as long as the internal panel frequency of the LCD monitor used in the process is synchronized with the vertical frequency.
Although stating otherwise in their data sheet, many LCDs internally don't run at 60 or 75 Hz exactly. In such cases tearing and jerkiness can become visible despite having vSync enabled.
This issue is also addressed in our monitor reviews. Furthermore, using the search function of the Prad board, you will be able to find some threads concerning this topic, too.
In the mean time, some of the more recent gamer displays, such as the ViewSonic VX922, are featuring the ability to synchronize their internal panel frequency with the vertical frequency, thereby preventing the problem of tearing and jerkiness.
5. Let's play some Counter-Strike!
In order to make things seem more tangible, let's assume the following: We are playing Counter-Strike (CS). The graphic mode is 640 x 480 pixels at 100 Hz and vSync is enabled. We are using a Pentium 500 with a GeForce graphics card.
When there is not much happening in the game, it takes the computer about 0.007 seconds to calculate one frame. Hence, he could theoretically reach 142 fps.
But at each page flip, the vertical synchronization forces CS to wait for the vSync impulse to occur before the next frame can be started!
So each time, the computer is left bored for 0.003 seconds until the graphics card has finished transmitting the current frame. Hence, this adds up to a frame rate of 100 Hz which is thereby identical to the vertical frequency.
We are running around a corner and suddenly see an enemy in front of us. Now a sprite has to be drawn in addition to the background; what's more, the CPU takes up additional resources for collision detection.
For this reason, the calculation of a frame now takes a little longer, let's say 0.011 seconds. So, the PC just doesn't make it in time to calculate a frame within a given vertical cycle!
This means the page-flip shortly misses each vSync impulse and has to wait 0.009 seconds for the next one, as each frame is transmitted by the graphics card two times. So now there are 0.02 seconds between two frames, meaning we are down to half the frame rate at now 50 fps only!
Since this frame drop happens very sudden, the difference can be felt very clearly even with such high frame rates. As a result being startled by this, we didn't react fast enough, so we were caught by the enemy with our pants down.
So we will switch to ghost mode and only see our bodily remains. Furthermore, another group of enemies is comes around the corner, charging the PC's limited capabilities even further: It now needs 0.023 seconds per frame.
The result of which is that each frame is now shown 3 times; hence, the frame rate drops down to 33.33 fps.
Now, if vSync had been disabled, the frame rate always would have been exactly as high as the PC would have been capable of rendering them at each moment. The transitions between high and low frame rate would be significantly less abrupt.
This is the advantage of disabled vSync. The drawback is: we have to put up with tearing. And because of tearing, most of the frames are displayed "torn".
What's more: If we wanted to follow a uniformly moving object with our eyes, we would notice that the motion is not uniform anymore because of tearing.
If the frame rate is higher than the vertical frequency, the object occasionally "skips" one of the steps in its motion sequence.
If the frame rate is lower, one of the steps in the motion sequence is occasionally displayed two (or more) times. In any case, the uniformity of motion is clearly diminished compared to vSync enabled.
For this reason, it is ideal to have both a CPU and graphics card powerful enough to be able to handle the frequency one has set (in our example 100 hz) even under heavy load. This keeps frame drops from occurring when vSync is enabled, and tearing will be avoided, too.
go to the forum!