Results 1 to 10 of 43

Thread: Library recommendation?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Use V-sync, the tearing is because you're not. 60hz is likely the refresh rate of your display hence the 60fps of DirectX. This whole 'disable v-sync' deal is a total myth. The only reason it ever improves 'performance' of a game is because developers rarely handle it correctly and waste vast amounts of time spinning in a swap call. When you disable v-sync, it's not the rendering that makes things 'smoother' - the screen can only display (in this case) 60fps - it's the fact that all the other game code in the main thread gets called a lot more which superficially improves 'performance' because you're no longer wasting time waiting for a v-sync when you could be processing input and everything else.

    The correct way to get silky smooth performance with no screen tearing - is to use v-sync and make sure you spend the minimum amount of time blocked in a swap call.

    So if the refresh rate of the display is 60hz, that gives you 16ms per frame to do everything before you call swap. You should time each frame and try to spend (for example) 15ms running your game loop - you only break out and call swap JUST BEFORE the 16ms swap window. Miss the window and you drop a frame. If you drop a frame then you increase your margin to say 2ms - you find the right amount of time to spend processing so you always hit that swap window.

    Bad game loop :

    Do stuff.
    render stuff.
    call swap.
    swap waits.
    swap waits.
    swap waits.
    swap waits.
    swap waits.
    etc etc

    Good game loop :

    Render stuff.
    Do stuff.
    do we have some time left this frame? yes > do stuff, repeat.
    do we have some time left this frame? no > call the swap function.

    Do this properly and you'll have silky smooth, v-synced graphics.

    I render before I do any processing personally. This does mean I introduce a potential delay from input to displayed output - there's no reason you can't call render just before swap and decrease this potential delay - in fact it's probably best for most people - I only do this because the amount of time it takes to render a given frame is variable and can spike causing you to drop frames if you weren't expecting it - I have far more control over how much time I spend doing other things - so I leave them until last so I don't miss my swap window. A (at worst) 16ms delay between an input event and the potential response on the display is nothing to worry about - most guitar effect pedals introduce a greater delay from plucking the string to hearing the sound and believe me - no matter what gamers like to think, if it's good enough for a death metal guitarist? it's good enough for a head shot

    Disabling V-sync to improve performance only works on flawed code and it introduces screen tearing.
    Last edited by phibermon; 07-02-2018 at 02:15 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •