Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 592683556
  • Loading branch information
MediaPipe Team authored and copybara-github committed Dec 21, 2023
1 parent 52c1d44 commit 835ee5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions mediapipe/gpu/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 29 additions & 7 deletions mediapipe/gpu/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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<GlSyncPoint> GlContext::CreateSyncToken() {
Expand Down
12 changes: 12 additions & 0 deletions mediapipe/gpu/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

0 comments on commit 835ee5e

Please sign in to comment.