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 1939 - [Patch] SDL_GL_MakeCurrent backend code inefficient in OS X
Summary: [Patch] SDL_GL_MakeCurrent backend code inefficient in OS X
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Mac OS X 10.8
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-04 00:14 UTC by Alex Szpakowski
Modified: 2013-07-05 04:48 UTC (History)
0 users

See Also:


Attachments
Patch to fix SDL_GL_MakeCurrent's OSX performance (481 bytes, patch)
2013-07-04 00:14 UTC, Alex Szpakowski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Szpakowski 2013-07-04 00:14:13 UTC
Created attachment 1206 [details]
Patch to fix SDL_GL_MakeCurrent's OSX performance

The Cocoa / OS X backend code for SDL_GL_MakeCurrent does unnecessary work which makes it *much* (up to orders of magnitude) less performant than it should be.

The backend code sets the context's view to the provided window's view without checking whether it's actually different from the context's current view (this is all independent of the actual NSOpenGL MakeCurrent call.)

I have attached a patch which fixes the issue.
Comment 1 Ryan C. Gordon 2013-07-05 01:19:03 UTC
The higher-level call, SDL_GL_MakeCurrent(), in SDL/src/video/SDL_video.c, already checks that we're not setting the same context, before calling Cocoa_GL_MakeCurrent().

Are we hitting this performance problem on Mac OS X, despite that?

(I've applied the patch, because it's a little extra robustness in any case, but I'm just curious. The patch is now hg changeset b4f6a86e8523, thanks!)

--ryan.
Comment 2 Alex Szpakowski 2013-07-05 04:48:45 UTC
Well, the higher level check is actually technically wrong, since GL contexts are current on a per-thread basis rather than globally (although that's something to discuss in a separate bug report or mailing list thread, I think. There are several issues that stem from the fact that SDL assumes a context that is made current in one thread is current in all threads.)

In any case, since the context can still be made current on a different thread without switching the window its attached to (e.g. by calling SDL_GL_MakeCurrent(NULL, NULL) in one thread, then SDL_GL_MakeCurrent(window, context) in another - which probably should be done when using a single context in multiple threads anyway), the performance of MakeCurrent was still impacted by the unnecessary function calls.

Thanks!