diff --git a/mediapipe/gpu/gl_texture_buffer.h b/mediapipe/gpu/gl_texture_buffer.h index a770163b5..1be24a86b 100644 --- a/mediapipe/gpu/gl_texture_buffer.h +++ b/mediapipe/gpu/gl_texture_buffer.h @@ -143,6 +143,10 @@ class GlTextureBuffer return producer_context_; } +#if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER + static constexpr bool kDisableGpuBufferRegistration = true; +#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER + private: // Creates a texture of dimensions width x height and allocates space for it. // If data is provided, it is uploaded to the texture; otherwise, it can be diff --git a/mediapipe/gpu/gpu_buffer_storage.h b/mediapipe/gpu/gpu_buffer_storage.h index 214f506c0..0da5f236a 100644 --- a/mediapipe/gpu/gpu_buffer_storage.h +++ b/mediapipe/gpu/gpu_buffer_storage.h @@ -84,11 +84,17 @@ class GpuBufferStorageRegistry { template RegistryToken RegisterFactory(F&& factory) { + if constexpr (kDisableRegistration) { + return {}; + } return Register(factory, Storage::GetProviderTypes()); } template RegistryToken RegisterConverter(F&& converter) { + if constexpr (kDisableRegistration) { + return {}; + } return Register( [converter](std::shared_ptr source) -> std::shared_ptr { @@ -119,6 +125,13 @@ class GpuBufferStorageRegistry { return std::make_shared(args...); } + // Temporary workaround: a Storage class can define a static constexpr + // kDisableGpuBufferRegistration member to true to prevent registering any + // factory of converter that would produce it. + // TODO: better solution for storage priorities. + template + static constexpr bool kDisableRegistration = false; + RegistryToken Register(StorageFactory factory, std::vector provider_hashes); RegistryToken Register(StorageConverter converter, @@ -130,6 +143,13 @@ class GpuBufferStorageRegistry { converter_for_view_provider_and_existing_storage_; }; +// Putting this outside the class body to work around a GCC bug. +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71954 +template +constexpr bool GpuBufferStorageRegistry::kDisableRegistration< + Storage, std::void_t> = + Storage::kDisableGpuBufferRegistration; + // Defining a member of this type causes P to be ODR-used, which forces its // instantiation if it's a static member of a template. template