We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4575

Summary: SDL_GL_SetSwapInterval(0) is broken on macOS in hg tip (likely regression)
Product: SDL Reporter: foo.null
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, icculus
Version: don't knowKeywords: target-2.0.10
Hardware: x86   
OS: macOS 10.13   

Description foo.null 2019-04-02 01:29:45 UTC
Running macOS 10.14.4 here, SDL_GL_SetSwapInterval(0) does not work on latest hg tip (12672:d5b4d374a312)

By default on 10.14.4 at least, VSYNC is enabled (SDL should not assume VSYNC is disabled by default).

I know there were recent changes to use a CVDisplayLink which is probably what caused this to regress... If SDL used -[NSOpenGLContext setValues:] this would probably work fine.

Furthermore, SDL probably shouldn't force developers to use a display link and should allow VSYNC to work with NSOpenGLContext API (which regressed on 10.14 but works again on 10.14.4+). I don't know the exact details but I believe there are implications for using a display link with regards to multiple monitors and it's not a straight forward win path (I don't know what Metal does though).

Probable workaround for me: Don't use SDL APIs, use Cocoa directly.
Comment 1 Alex Szpakowski 2019-04-11 01:35:14 UTC
I put in a fix for SetSwapInterval(0) not working at https://hg.libsdl.org/SDL/rev/0ff5bbe35bf5

As for display link use in general, I'm not sure about multi-monitor issues with CVDisplayLink but it's worth mentioning its use enables "adaptive vsync" (SetSwapInterval(-1)) which isn't possible with NSOpenGLContextParameterSwapInterval. I wouldn't consider its loss a big deal if switching back to the NSOpenGLContext APIs fixes bugs though.
Comment 2 foo.null 2019-04-13 02:46:14 UTC
SDL could let the developer decide if they want to use adaptive vsync or not rather than only provide adaptive vsync with a display link. SDL_GL_SetSwapInterval does take three different input possibilities.
Comment 3 foo.null 2019-04-13 02:50:26 UTC
Default should be whatever the native API does in case the user doesn't explicitly enable/disable VSYNC, I'd think.
Comment 4 Alex Szpakowski 2019-04-13 03:20:14 UTC
(In reply to foo.null from comment #2)
> SDL could let the developer decide if they want to use adaptive vsync or not
> rather than only provide adaptive vsync with a display link.
> SDL_GL_SetSwapInterval does take three different input possibilities.

That's already the case. SetSwapInterval(1) enables standard vsync, and SetSwapInterval(-1) enables adaptive vsync, with SDL's display link implementation of vsync on macOS.

If you mean SDL should use NSOpenGL's APIs for setting normal vsync and only use a display link when SetSwapInterval(-1), I suppose that's a possibility. It does have the downside of relying on two separate codepaths (and two separate places where macOS can break things itself) though.
Comment 5 Ryan C. Gordon 2019-04-13 03:34:12 UTC
We did the CVDisplayLink stuff because 10.14.0 broke vsync for OpenGL apps. This has actually been fixed in the latest 10.14.x builds, and I think we should rip the CVDisplayLink stuff out entirely.

(imho.)

--ryan.
Comment 6 Ryan C. Gordon 2019-05-18 18:48:53 UTC
Tagging a bunch of bugs with "target-2.0.10" so we have a clear list of things to address before a 2.0.10 release.

Please note that "addressing" one of these bugs might mean deciding to defer on it until after 2.0.10, or resolving it as WONTFIX, etc. This is just here to tell us we should look at it carefully, and soon.

If you have new information or feedback on this issue, this is a good time to add it to the conversation, as we're likely to be paying attention to this specific report in the next few days/weeks.

Thanks!

--ryan.
Comment 7 Ryan C. Gordon 2019-05-20 04:47:27 UTC
I'm going to back out the CVDisplayLink code in the morning. I just don't think the -1 interval support is worth the headaches this causes. Alex, feel free to stop me if you feel strongly about this, though!

--ryan.
Comment 8 Alex Szpakowski 2019-05-20 04:50:58 UTC
Sounds good to me.
Comment 9 Ryan C. Gordon 2019-06-12 03:28:19 UTC
CVDisplayLink code is backed out in https://hg.libsdl.org/SDL/rev/1b6f67e84802, confirmed vsync is working again anyhow on 10.14.5. Resolving bug!

--ryan.