Boogiwoogie's picture

vsync not working for me [solved] (by updating drivers)

hi there!
i try to enable vsync on the GamewindowSimple.cs file, and it doesnt kick in. i try both on ubuntu 12.04 64bit, with catalyst 13.12 drivers and windows 7 with drivers that date back to 2011 (cant update those because its a notebook and it doesnt let me).
i digged a little bit around in the opentk source code and noticed that the SwapInterval is never actually used, however there seems to be some binding magic that is beyond my understanding anyway.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

GameWindow.VSync = ... calls implementation.Context.SwapInterval = ... internally, where "implementation" is an instance of WinGLContext, X11GLContext, CocoaContext or EglContext depending on your platform.

There were a couple of bugs related to vsync in the develop branch, which have been fixed now. Try compiling a debug version from github - if vsync fails for any reason, you should get an error message in the output window.

Boogiwoogie's picture

i just pulled the develop branch from github, and it seems as if the setter is not called at all.
if i move the debug log up a few lines, it should be called at least once, right?
i start examples, that switch vsync to vsyncmode.od, but no log message.

        public override int SwapInterval
        {
            get
            {
[...]
            }
            set
            {
                Debug.Print("about to call wglSwapIntervalEXT");
                lock (LoadLock)
                {
                    if (vsync_supported)
                    {
                        if (value < 0 && !vsync_tear_supported)
                        {

this is in WinGLContext.cs, using win 7, vs express 2013, debug config
i also spammed breakpoints on the setter, to no avail
settings in the catalyst control center about vsync dont have an effect either, it stays disabled

the Fiddler's picture

Yes, the debug message should show up if you are compiling the Debug configuration. Note that the OpenTK.Examples project launches examples in child processes, which means that breakpoints will not be triggered in Visual Studio.

For what it is worth, I just tried the following code on Windows and vsync appears to be set correctly:

static void Main()
{
    using (var gw = new GameWindow())
    {
        gw.VSync = VSyncMode.Adaptive;
        gw.Run();
    }
}

This calls the WinGLContext.SwapInterval setter as expected.

The only thing I can think is that SDL2 is in your path and you are running the SDL2 backend instead (so Sdl2GraphicsContext.SwapInterval is being called instead.) Otherwise, I simply cannot see why would be seeing this behavior.

Boogiwoogie's picture

alright, i did the same thing, added a project with:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var gw = new GameWindow())
            {
                gw.VSync = VSyncMode.On;
                gw.Run();
            }
        }
    }
}

now it gives me debug messages into the output screen, seems all good imho:

Eine Ausnahme (erste Chance) des Typs "System.DllNotFoundException" ist in OpenTK.dll aufgetreten.
SDL2 init failed with exception: System.DllNotFoundException: Die DLL "SDL2.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
   bei OpenTK.Platform.SDL2.SDL.WasInit(SystemFlags flags)
   bei OpenTK.Configuration.DetectSdl2() in c:\Users\Fields\Desktop\opentk-develop\Source\OpenTK\Configuration.cs:Zeile 206.
SDL2 is not supported
Detected configuration: Windows / .Net
Loaded opengl32.dll: 1548091392
SetProcessDPIAware() returned True
Eine Ausnahme (erste Chance) des Typs "System.DllNotFoundException" ist in OpenTK.dll aufgetreten.
DisplayDevice 1 (primary) supports 144 resolutions.
Creating GraphicsContext.
    GraphicsMode: Index: , Color: 32 (8888), Depth: 16, Stencil: 0, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
    IWindowInfo: Windows.WindowInfo: Handle 1770656, Parent (Windows.WindowInfo: Handle 2687760, Parent (null))
    GraphicsContextFlags: Default
    Requested version: 1.0
    [WGL] Creating temporary context to load extensions
    Setting pixel format... [WGL] ChoosePixelFormatARB not supported on this context
    6
    OpenGL will be bound to window:1770656 on thread:9
    Setting pixel format... 8
    Using WGL_ARB_create_context... success! (id: 65537)
    Destroying window: Windows.WindowInfo: Handle 1311726, Parent (null)
Bindings loaded in 7,1974 ms.
about to call wglSwapIntervalEXT
about to call wglSwapIntervalEXT
Entering main loop.
Destroying window: Windows.WindowInfo: Handle 2687760, Parent (null)
Disposing context 65537.
Der Thread 0xec4 hat mit Code 259 (0x103) geendet.
Der Thread 0x110c hat mit Code 259 (0x103) geendet.
[OpenTK] OpenTK.Platform.Factory+UnsupportedPlatform leaked, did you forget to call Dispose()?
[OpenTK] OpenTK.Platform.Windows.WinFactory leaked, did you forget to call Dispose()?
OpenTK.Toolkit leaked, did you forget to call Dispose()?
OpenTK.Platform.Factory leaked, did you forget to call Dispose()?
Das Programm "[6740] ConsoleApplication1.vshost.exe" wurde mit Code 0 (0x0) beendet.

those "about to call wglSwapIntervalEXT" show up, so you are right, all vsync related code seems to work just fine.
i didnt put code to measure the fps in, but the taskmanager reveals that its running at 100% on one core, so vsync is still disabled.
i guess i leave this issue for now and go with a sleep(16) in the OnRenderFrame() method. i am sick of my notebooks fan starting to scream at every run ;)
thank you for having had a look at it, tho!

the Fiddler's picture
Quote:

the taskmanager reveals that its running at 100% on one core, so vsync is still disabled.

VSync simply synchronizes SwapBuffers with the video retrace signal. This doesn't automatically reduce your CPU usage - the drivers are free to spinlock the CPU if they desire (and a lot of them do.)

To reduce CPU usage, you should enable VSync *and* call Thread.Sleep(1) to yield the CPU.

Boogiwoogie's picture

here is how things turned out for me:
i started spamming debug.prints all over the swapinterval setter, noticed that i can also read out the value and confirm that opengl actually eats it. set it to 1, read out 1, all good. still no vsync, tho. so i started looking for non-opentk applications that use opengl and support vsync. i noticed that my opengl driver is a mess, nothing really worked smoothly as soon as opengl got involved.
so i went out into the web, looking for a new driver. found a weirdly hacked and modded ati driver that seemed to fit my notebook (it has that awkward ati/intel dynamic switching stuff in it). however, i installed it.
long story short: i feel dirty now, and opentk's vsync finally works! i copied the dynamic vbo example into my project, set vsyncmode to on and got a solid 60 fps and a couple of percent cpu usage.

the Fiddler's picture

Thanks for the update. Yes, laptop drivers can be really annoying sometimes, especially when multiple GPUs are involved.