From 8609e5fae5c89bad69995e2ffeec62a9fefc0cb9 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 21 Dec 2023 12:24:15 -0800 Subject: [PATCH] Adds warning about using Tensors::OpenGlBufferViews with multiple GlContexts. PiperOrigin-RevId: 592924315 --- mediapipe/framework/formats/tensor.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mediapipe/framework/formats/tensor.cc b/mediapipe/framework/formats/tensor.cc index bf856f5a9..30823b226 100644 --- a/mediapipe/framework/formats/tensor.cc +++ b/mediapipe/framework/formats/tensor.cc @@ -342,6 +342,14 @@ Tensor::OpenGlBufferView Tensor::GetOpenGlBufferReadView() const { << "Tensor conversion between different GPU backing formats is not " "supported yet."; auto lock(absl::make_unique(&view_mutex_)); + if ((valid_ & kValidOpenGlBuffer) && gl_context_ != nullptr && + !gl_context_->IsCurrent() && GlContext::IsAnyContextCurrent()) { + ABSL_LOG_FIRST_N(WARNING, 1) + << "Tensor::GetOpenGlBufferReadView is not executed on the same GL " + "context where GL buffer was created. Note that Tensor has " + "limited synchronization support when sharing OpenGl objects " + "between multiple OpenGL contexts."; + } AllocateOpenGlBuffer(); if (!(valid_ & kValidOpenGlBuffer)) { // If the call succeeds then AHWB -> SSBO are synchronized so any usage of @@ -376,6 +384,14 @@ Tensor::OpenGlBufferView Tensor::GetOpenGlBufferWriteView( uint64_t source_location_hash) const { auto lock(absl::make_unique(&view_mutex_)); TrackAhwbUsage(source_location_hash); + if ((valid_ & kValidOpenGlBuffer) && gl_context_ != nullptr && + !gl_context_->IsCurrent() && GlContext::IsAnyContextCurrent()) { + ABSL_LOG_FIRST_N(WARNING, 1) + << "Tensor::GetOpenGlBufferWriteView is not executed on the same GL " + "context where GL buffer was created. Note that Tensor has " + "limited synchronization support when sharing OpenGl objects " + "between multiple OpenGL contexts."; + } AllocateOpenGlBuffer(); valid_ = kValidOpenGlBuffer; return {opengl_buffer_, std::move(lock), nullptr};