Internal change
PiperOrigin-RevId: 477538515
This commit is contained in:
committed by
Sebastian Schmidt
parent
6cdc6443b6
commit
f8af41b1eb
@@ -271,6 +271,7 @@ cc_library(
|
||||
deps = [
|
||||
":gpu_buffer_format",
|
||||
":gpu_buffer_storage",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/port:logging",
|
||||
":gpu_buffer_storage_image_frame",
|
||||
@@ -366,6 +367,23 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "gpu_buffer_storage_ahwb",
|
||||
srcs = ["gpu_buffer_storage_ahwb.cc"],
|
||||
hdrs = ["gpu_buffer_storage_ahwb.h"],
|
||||
linkopts = select({
|
||||
"//conditions:default": [],
|
||||
"//mediapipe:android": [
|
||||
"-landroid",
|
||||
],
|
||||
}),
|
||||
deps = [
|
||||
":gpu_buffer_format",
|
||||
":gpu_buffer_storage",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
],
|
||||
)
|
||||
|
||||
mediapipe_proto_library(
|
||||
name = "gpu_origin_proto",
|
||||
srcs = ["gpu_origin.proto"],
|
||||
@@ -1087,3 +1105,19 @@ ios_unit_test(
|
||||
],
|
||||
deps = [":gl_ios_test_lib"],
|
||||
)
|
||||
|
||||
mediapipe_cc_test(
|
||||
name = "gpu_buffer_storage_ahwb_test",
|
||||
size = "small",
|
||||
srcs = ["gpu_buffer_storage_ahwb_test.cc"],
|
||||
exclude_platforms = [
|
||||
"ios",
|
||||
"wasm",
|
||||
],
|
||||
requires_full_emulation = True,
|
||||
deps = [
|
||||
":gpu_buffer_format",
|
||||
":gpu_buffer_storage_ahwb",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -620,7 +620,9 @@ class GlSyncWrapper {
|
||||
#endif
|
||||
GLenum result = glClientWaitSync(sync_, flags, timeout);
|
||||
if (result == GL_ALREADY_SIGNALED || result == GL_CONDITION_SATISFIED) {
|
||||
Clear();
|
||||
// TODO: we could clear at this point so later calls are faster,
|
||||
// but we need to do so in a thread-safe way.
|
||||
// Clear();
|
||||
}
|
||||
// TODO: do something if the wait fails?
|
||||
}
|
||||
@@ -646,7 +648,9 @@ class GlSyncWrapper {
|
||||
#endif
|
||||
GLenum result = glClientWaitSync(sync_, flags, 0);
|
||||
if (result == GL_ALREADY_SIGNALED || result == GL_CONDITION_SATISFIED) {
|
||||
Clear();
|
||||
// TODO: we could clear at this point so later calls are faster,
|
||||
// but we need to do so in a thread-safe way.
|
||||
// Clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -822,10 +826,17 @@ std::shared_ptr<GlSyncPoint> GlContext::CreateSyncToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
bool GlContext::IsAnyContextCurrent() {
|
||||
ContextBinding ctx;
|
||||
GetCurrentContextBinding(&ctx);
|
||||
return ctx.context != kPlatformGlContextNone;
|
||||
}
|
||||
|
||||
std::shared_ptr<GlSyncPoint>
|
||||
GlContext::CreateSyncTokenForCurrentExternalContext(
|
||||
const std::shared_ptr<GlContext>& delegate_graph_context) {
|
||||
CHECK(delegate_graph_context);
|
||||
if (!IsAnyContextCurrent()) return nullptr;
|
||||
if (delegate_graph_context->ShouldUseFenceSync()) {
|
||||
return std::shared_ptr<GlSyncPoint>(
|
||||
new GlExternalFenceSyncPoint(delegate_graph_context));
|
||||
|
||||
@@ -303,6 +303,10 @@ class GlContext : public std::enable_shared_from_this<GlContext> {
|
||||
return *static_cast<T*>(entry.get());
|
||||
}
|
||||
|
||||
// Returns true if any GL context, including external contexts not managed by
|
||||
// the GlContext class, is current.
|
||||
static bool IsAnyContextCurrent();
|
||||
|
||||
// Creates a synchronization token for the current, non-GlContext-owned
|
||||
// context. This can be passed to MediaPipe so it can synchronize with the
|
||||
// commands issued in the external context up to this point.
|
||||
|
||||
@@ -145,9 +145,13 @@ bool GlTextureBuffer::CreateInternal(const void* data, int alignment) {
|
||||
CHECK_NE(name_, 0);
|
||||
GLuint name_to_delete = name_;
|
||||
context->RunWithoutWaiting([name_to_delete, sync_token]() {
|
||||
// TODO: maybe we do not actually have to wait for the
|
||||
// consumer sync here. Check docs.
|
||||
sync_token->WaitOnGpu();
|
||||
if (sync_token) {
|
||||
// TODO: maybe we do not actually have to wait for the
|
||||
// consumer sync here. Check docs.
|
||||
sync_token->WaitOnGpu();
|
||||
} else {
|
||||
LOG_FIRST_N(WARNING, 5) << "unexpected null sync in deletion_callback";
|
||||
}
|
||||
DLOG_IF(ERROR, !glIsTexture(name_to_delete))
|
||||
<< "Deleting invalid texture id: " << name_to_delete;
|
||||
glDeleteTextures(1, &name_to_delete);
|
||||
@@ -179,13 +183,19 @@ void GlTextureBuffer::Reuse() {
|
||||
void GlTextureBuffer::Updated(std::shared_ptr<GlSyncPoint> prod_token) {
|
||||
CHECK(!producer_sync_)
|
||||
<< "Updated existing texture which had not been marked for reuse!";
|
||||
CHECK(prod_token);
|
||||
producer_sync_ = std::move(prod_token);
|
||||
producer_context_ = producer_sync_->GetContext();
|
||||
}
|
||||
|
||||
void GlTextureBuffer::DidRead(std::shared_ptr<GlSyncPoint> cons_token) const {
|
||||
absl::MutexLock lock(&consumer_sync_mutex_);
|
||||
consumer_multi_sync_->Add(std::move(cons_token));
|
||||
if (cons_token) {
|
||||
consumer_multi_sync_->Add(std::move(cons_token));
|
||||
} else {
|
||||
// TODO: change to a CHECK.
|
||||
LOG_FIRST_N(WARNING, 5) << "unexpected null sync in DidRead";
|
||||
}
|
||||
}
|
||||
|
||||
GlTextureBuffer::~GlTextureBuffer() {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "mediapipe/framework/port/logging.h"
|
||||
|
||||
#if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
|
||||
@@ -10,6 +12,23 @@
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
namespace {
|
||||
|
||||
struct StorageTypeFormatter {
|
||||
void operator()(std::string* out,
|
||||
const std::shared_ptr<internal::GpuBufferStorage>& s) const {
|
||||
absl::StrAppend(out, s->storage_type().name());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string GpuBuffer::DebugString() const {
|
||||
return absl::StrCat("GpuBuffer[",
|
||||
absl::StrJoin(storages_, ", ", StorageTypeFormatter()),
|
||||
"]");
|
||||
}
|
||||
|
||||
internal::GpuBufferStorage& GpuBuffer::GetStorageForView(
|
||||
TypeId view_provider_type, bool for_writing) const {
|
||||
const std::shared_ptr<internal::GpuBufferStorage>* chosen_storage = nullptr;
|
||||
@@ -52,7 +71,10 @@ internal::GpuBufferStorage& GpuBuffer::GetStorageForView(
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(chosen_storage) << "no view provider found";
|
||||
CHECK(chosen_storage) << "no view provider found for requested view "
|
||||
<< view_provider_type.name() << "; storages available: "
|
||||
<< absl::StrJoin(storages_, ", ",
|
||||
StorageTypeFormatter());
|
||||
DCHECK((*chosen_storage)->can_down_cast_to(view_provider_type));
|
||||
return **chosen_storage;
|
||||
}
|
||||
|
||||
@@ -129,6 +129,8 @@ class GpuBuffer {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string DebugString() const;
|
||||
|
||||
private:
|
||||
class PlaceholderGpuBufferStorage
|
||||
: public internal::GpuBufferStorageImpl<PlaceholderGpuBufferStorage> {
|
||||
|
||||
Reference in New Issue
Block a user