Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Difference between Vsync/double buffering/triple buffering and when should i use them.

Discussion in 'Scripting' started by aLovedHater, Mar 6, 2016.

  1. aLovedHater

    aLovedHater

    Joined:
    Oct 12, 2014
    Posts:
    16
    Recntly i've started working on an options menu for my game and i wanted to make sure i has every options i could and that i understood how all of them worked, when i came to Vsync i was sure i knew what it was, but then when i checked what tripple-buffering was; i was confused on what exactly vsync was.
    So triple buffering would look like
    Code (CSharp):
    1. QualitySettings.maxQueuedFrames = 3;
    and Vsync would look like
    Code (CSharp):
    1. QualitySettings.vSyncCount = 1;
    or
    Code (CSharp):
    1. QualitySettings.vSyncCount = 2;
    now I'm confused.. What would be vSyncCount at 1, and what would it be at 2? I looked around and didnt see much, i checked out the game CS:GO and saw that in its options for vSync it had "none,double buffering, triple buffering" so now i'm thinking vSyncCount = 2 is double buffering which would be the same thing as maxQueuedFrames = 2; Are they the same thing..? Would i have to disable triple buffering if VsyncCount is 2 and the other way around? where would VsyncCount = 1 come in here? I'm very confused and would like to know what these things are and how i should use them and i'd appreciate any guidance that anyone can give me! The main things i want to know are: What is VsyncCount 1 and 2, is VsyncCount 2 the same as maxQueuedFrames 2, and how do i use them together(can they both be active as the same time, or not?)?

    Thanks in advance for any help that i get!
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Why, vSync and frame queue buffers are two completely different things.

    vSync of 1 will wait for every vBlank to start rendering the next frame. 2 will wait every second vBlank. And 0 won't wait at all.

    Most monitors have a frequency of 60hz, that's 60 refreshes per second. Since the vBlank is what's in between the screen refreshes, that's 60 vBlanks per second.

    So a vSync of 1 will attempt to render at 60fps, once for every refresh.

    A vSync of 2 is saying we're targeting 30 fps, once for every other refresh (every inbetween refresh is just going to display the previous frame, a second time).

    This number changes depending on the display's frequency.

    This avoids tearing because it won't draw to the video buffer during a refresh, only during the vBlank, so that way the refresh won't include half of the previous frame, and half of the next.



    maxQueuedFrames is the maximum number of frames allowed to be buffered before pushed to the display. This allows for smoother graphics because the gpu can predraw the graphics, place it in queue to then be pushed to the display.

    Downside is that this can cause a bit of lag if the queue is allowed to get long. Because more frames may potentially get queued, rather than displayed, meaning what the player sees on screen is behind what they're inputting on the keyboard/gamepad.
     
  3. aLovedHater

    aLovedHater

    Joined:
    Oct 12, 2014
    Posts:
    16
    Thank you, that helped me a ton!
    One last thing, should i give the user to switch between setting their VsyncCount between 1 or 2, or should i just say keep it at 2 when on, and 0 when off? (seeing that that is what i see most other people do)
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Depends on your game.

    Most of the time there is very little to gain by turning vsync off. On a faster rig it means the game can burn through frames. But the user never sees them, so what's the point? And on a slower rig you won't notice it.

    Allowing to switch between very vblank and every second vblank actually makes sense. On a faster rig it lets you improve visual quality, but you can still run on a slower rig.

    Edit: Disclaimer, I'm not a graphics person in the least. This may be all wrong.
     
  5. aLovedHater

    aLovedHater

    Joined:
    Oct 12, 2014
    Posts:
    16
    thanks, i'll keep that in mind!
     
  6. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Vsync: stands for vertical synchronisation. Which might tells you... nothing :).

    So let's start at the beginning. Your screen is made out of pixels, that are drawn line by line from top to bottom, that is vertically (one term down, one to go). It happens really fast, but it still takes sometime for your monitor to fully draw a complete screen ( a frame). Typically, 1/60th of a second, that's why an average monitor run at 60 frames per second fps.

    When a game is graphically performant, that is it has been made in way that it does not ask too much work to be done by the graphics card, the graphics card can draw more that 60 frames. So fast, that it can draw another frame while the monitor has not finished to update the previous one! When that happens, you can have a mix of two frames drawn of the screen. And that can be a bit annoying, since it results in perceiving a horizontal line appearing randomly on the screen. This artifact is called Screen Tearing and can be avoided by Vertical Synchronization, which means that the graphics card will synchronize (second term down) with the monitor; it will wait until the monitor has finished with drawing the current frame before asking it to draw a new one.

    That's for vsync, I'll explain double-buffering in another post.

    Edit:
    Though vsync removed Screen Tearing, it makes the graphics card idle while waiting the monitor to update. Which result it less frames drawn. So enabling vsync drops the fps count.
     
    Last edited: Mar 6, 2016