From 835ee5e3542fcc987584dcd00757c9ae33c79008 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 20 Dec 2023 16:13:48 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 592683556 --- mediapipe/gpu/BUILD | 1 + mediapipe/gpu/gl_context.cc | 36 +++++++++++++++++++++++++++++------- mediapipe/gpu/gl_context.h | 12 ++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/mediapipe/gpu/BUILD b/mediapipe/gpu/BUILD index 88864e894..c4ddfb559 100644 --- a/mediapipe/gpu/BUILD +++ b/mediapipe/gpu/BUILD @@ -196,6 +196,7 @@ cc_library( ":gpu_buffer_format", "//mediapipe/framework:executor", "//mediapipe/framework:mediapipe_profiling", + "//mediapipe/framework:port", "//mediapipe/framework:timestamp", "//mediapipe/framework/port:logging", "//mediapipe/framework/port:ret_check", diff --git a/mediapipe/gpu/gl_context.cc b/mediapipe/gpu/gl_context.cc index 4dc90b52a..4fda8da43 100644 --- a/mediapipe/gpu/gl_context.cc +++ b/mediapipe/gpu/gl_context.cc @@ -27,6 +27,7 @@ #include "absl/memory/memory.h" #include "absl/status/status.h" #include "absl/synchronization/mutex.h" +#include "mediapipe/framework/port.h" // IWYU pragma: keep #include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/port/status.h" #include "mediapipe/framework/port/status_builder.h" @@ -48,6 +49,17 @@ namespace mediapipe { +namespace internal_gl_context { + +bool IsOpenGlVersionSameOrAbove(const OpenGlVersion& version, + const OpenGlVersion& expected_version) { + return (version.major == expected_version.major && + version.minor >= expected_version.minor) || + version.major > expected_version.major; +} + +} // namespace internal_gl_context + static void SetThreadName(const char* name) { #if defined(__GLIBC_PREREQ) #define LINUX_STYLE_SETNAME_NP __GLIBC_PREREQ(2, 12) @@ -815,15 +827,25 @@ class GlNopSyncPoint : public GlSyncPoint { #endif bool GlContext::ShouldUseFenceSync() const { -#ifdef __EMSCRIPTEN__ + using internal_gl_context::OpenGlVersion; +#if defined(__EMSCRIPTEN__) // In Emscripten the glWaitSync function is non-null depending on linkopts, - // but only works in a WebGL2 context, so fall back to use Finish if it is a - // WebGL1/ES2 context. - // TODO: apply this more generally once b/152794517 is fixed. - return gl_major_version() > 2; + // but only works in a WebGL2 context. + constexpr OpenGlVersion kMinVersionSyncAvaiable = {.major = 3, .minor = 0}; +#elif defined(MEDIAPIPE_MOBILE) + // OpenGL ES, glWaitSync is available since 3.0 + constexpr OpenGlVersion kMinVersionSyncAvaiable = {.major = 3, .minor = 0}; #else - return SymbolAvailable(&glWaitSync); -#endif // __EMSCRIPTEN__ + // TODO: specify major/minor version per remaining platforms. + // By default, ignoring major/minor version requirement for backward + // compatibility. + constexpr OpenGlVersion kMinVersionSyncAvaiable = {.major = 0, .minor = 0}; +#endif + + return SymbolAvailable(&glWaitSync) && + internal_gl_context::IsOpenGlVersionSameOrAbove( + {.major = gl_major_version(), .minor = gl_minor_version()}, + kMinVersionSyncAvaiable); } std::shared_ptr GlContext::CreateSyncToken() { diff --git a/mediapipe/gpu/gl_context.h b/mediapipe/gpu/gl_context.h index 51faffa0c..8d6948305 100644 --- a/mediapipe/gpu/gl_context.h +++ b/mediapipe/gpu/gl_context.h @@ -487,6 +487,18 @@ ABSL_DEPRECATED( const GlTextureInfo& GlTextureInfoForGpuBufferFormat(GpuBufferFormat format, int plane); +namespace internal_gl_context { + +struct OpenGlVersion { + int major; + int minor; +}; + +bool IsOpenGlVersionSameOrAbove(const OpenGlVersion& version, + const OpenGlVersion& expected_version); + +} // namespace internal_gl_context + } // namespace mediapipe #endif // MEDIAPIPE_GPU_GL_CONTEXT_H_