Skip to content

Commit

Permalink
Adds warning about using Tensors::OpenGlBufferViews with multiple GlC…
Browse files Browse the repository at this point in the history
…ontexts.

PiperOrigin-RevId: 592924315
  • Loading branch information
MediaPipe Team authored and copybara-github committed Dec 21, 2023
1 parent cfb4465 commit 8609e5f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mediapipe/framework/formats/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<absl::MutexLock>(&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
Expand Down Expand Up @@ -376,6 +384,14 @@ Tensor::OpenGlBufferView Tensor::GetOpenGlBufferWriteView(
uint64_t source_location_hash) const {
auto lock(absl::make_unique<absl::MutexLock>(&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};
Expand Down

0 comments on commit 8609e5f

Please sign in to comment.