From: Steinar H. Gunderson Date: Mon, 18 Apr 2016 21:12:05 +0000 (+0200) Subject: Put a global lock around glFenceSync/glDeleteSync calls, to workaround apitrace bug... X-Git-Tag: 1.3.0~79 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=10ff4d7e0cba7d0c5d11317aa5e11679382d3cfe;hp=16c71cac0d5c81e84271222d1ed0c501fe723d56;p=nageru Put a global lock around glFenceSync/glDeleteSync calls, to workaround apitrace bug #446. (Replaying Nageru calls using apitrace can be very useful, and it should not have any appreciable performance impact in practice.) --- diff --git a/mixer.cpp b/mixer.cpp index 8c95f38..3d4cccb 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -1205,3 +1205,5 @@ void Mixer::OutputChannel::set_frame_ready_callback(Mixer::new_frame_ready_callb new_frame_ready_callback = callback; has_new_frame_ready_callback = true; } + +mutex RefCountedGLsync::fence_lock; diff --git a/ref_counted_gl_sync.h b/ref_counted_gl_sync.h index 8b6a8af..8b6db68 100644 --- a/ref_counted_gl_sync.h +++ b/ref_counted_gl_sync.h @@ -8,6 +8,7 @@ #include #include +#include typedef std::shared_ptr<__GLsync> RefCountedGLsyncBase; @@ -16,7 +17,23 @@ public: RefCountedGLsync() {} RefCountedGLsync(GLenum condition, GLbitfield flags) - : RefCountedGLsyncBase(glFenceSync(condition, flags), glDeleteSync) {} + : RefCountedGLsyncBase(locked_glFenceSync(condition, flags), glDeleteSync) {} + +private: + // These are to work around apitrace bug #446. + static GLsync locked_glFenceSync(GLenum condition, GLbitfield flags) + { + std::lock_guard lock(fence_lock); + return glFenceSync(condition, flags); + } + + static void locked_glDeleteSync(GLsync sync) + { + std::lock_guard lock(fence_lock); + glDeleteSync(sync); + } + + static std::mutex fence_lock; }; #endif // !defined(_REF_COUNTED_GL_SYNC_H)