Skip to content

Commit

Permalink
SharedImage: share one gles2::FeatureInfo in SharedContextStat
Browse files Browse the repository at this point in the history
Creating and initializing a gles2::FeatureInfo is not cost free.
It queries and parses GL strings, so use the feature_info in
SharedContextState for shared image backing factories to avoid
the duplicated work.

Bug: none
Change-Id: I38458a181e75ff43f96b75da2fff8ec7020db51f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3638764
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002004}
  • Loading branch information
phuang authored and Chromium LUCI CQ committed May 11, 2022
1 parent d9ccf8b commit 69f6ae9
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,8 @@ void SharedImageBackingAHB::EndOverlayAccess() {
}

SharedImageBackingFactoryAHB::SharedImageBackingFactoryAHB(
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info) {
const gles2::FeatureInfo* feature_info) {
DCHECK(base::AndroidHardwareBufferCompat::IsSupportAvailable());
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2, false,
gles2::DisallowedFeatures());
const gles2::Validators* validators = feature_info->validators();
const bool is_egl_image_supported =
gl::g_current_gl_driver->ext.b_GL_OES_EGL_image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ class ColorSpace;
} // namespace gfx

namespace gpu {

namespace gles2 {
class FeatureInfo;
} // namespace gles2

class SharedImageBacking;
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct Mailbox;

// Implementation of SharedImageBackingFactory that produces AHardwareBuffer
// backed SharedImages. This is meant to be used on Android only.
class GPU_GLES2_EXPORT SharedImageBackingFactoryAHB
: public SharedImageBackingFactory {
public:
SharedImageBackingFactoryAHB(const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info);
explicit SharedImageBackingFactoryAHB(const gles2::FeatureInfo* feature_info);

SharedImageBackingFactoryAHB(const SharedImageBackingFactoryAHB&) = delete;
SharedImageBackingFactoryAHB& operator=(const SharedImageBackingFactoryAHB&) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SharedImageBackingFactoryAHBTest : public testing::Test {
context_state_->InitializeGL(GpuPreferences(), std::move(feature_info));

backing_factory_ = std::make_unique<SharedImageBackingFactoryAHB>(
workarounds, GpuFeatureInfo());
context_state_->feature_info());

memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
shared_image_representation_factory_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,10 @@ std::unique_ptr<SharedImageRepresentationSkia> AngleVulkanBacking::ProduceSkia(
SharedImageBackingFactoryAngleVulkan::SharedImageBackingFactoryAngleVulkan(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
SharedContextState* context_state)
: SharedImageBackingFactoryGLCommon(gpu_preferences,
workarounds,
gpu_feature_info,
context_state->feature_info(),
context_state->progress_reporter()),
context_state_(context_state) {
DCHECK(context_state_->GrContextIsVulkan());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SharedImageBackingFactoryAngleVulkan
SharedImageBackingFactoryAngleVulkan(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
SharedContextState* context_state);
~SharedImageBackingFactoryAngleVulkan() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ namespace gpu {
SharedImageBackingFactoryEGL::SharedImageBackingFactoryEGL(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
SharedImageBatchAccessManager* batch_access_manager)
: SharedImageBackingFactoryGLCommon(gpu_preferences,
workarounds,
gpu_feature_info,
feature_info,
/*progress_reporter=*/nullptr),
batch_access_manager_(batch_access_manager) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace gpu {
class SharedImageBacking;
class SharedImageBatchAccessManager;
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;
struct Mailbox;

Expand All @@ -37,7 +36,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryEGL
SharedImageBackingFactoryEGL(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
SharedImageBatchAccessManager* batch_access_manager);
~SharedImageBackingFactoryEGL() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SharedImageBackingFactoryEGLThreadSafeTest
GpuPreferences preferences;
preferences.use_passthrough_cmd_decoder = use_passthrough();
backing_factory_ = std::make_unique<SharedImageBackingFactoryEGL>(
preferences, workarounds, GpuFeatureInfo(),
preferences, workarounds, context_state_->feature_info(),
shared_image_manager_->batch_access_manager());

memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
#include "ui/gl/progress_reporter.h"

namespace gpu {

///////////////////////////////////////////////////////////////////////////////
// SharedImageBackingFactoryGLCommon

SharedImageBackingFactoryGLCommon::SharedImageBackingFactoryGLCommon(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
gl::ProgressReporter* progress_reporter)
: use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported()),
Expand All @@ -38,11 +37,6 @@ SharedImageBackingFactoryGLCommon::SharedImageBackingFactoryGLCommon(
// cases, clamped to INT_MAX, always invalid.
max_texture_size_ = std::min(max_texture_size_, INT_MAX - 1);

// TODO(piman): Can we extract the logic out of FeatureInfo?
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2,
use_passthrough_, gles2::DisallowedFeatures());
texture_usage_angle_ = feature_info->feature_flags().angle_texture_usage;
attribs_.es3_capable = feature_info->IsES3Capable();
attribs_.desktop_gl = !feature_info->gl_version_info().is_es;
Expand Down Expand Up @@ -74,12 +68,12 @@ SharedImageBackingFactoryGLCommon::SharedImageBackingFactoryGLCommon(
info.gl_format = gl_format;
info.gl_type = gl_type;
info.swizzle = gles2::TextureManager::GetCompatibilitySwizzle(
feature_info.get(), gl_format);
feature_info, gl_format);
info.image_internal_format =
gles2::TextureManager::AdjustTexInternalFormat(
feature_info.get(), image_internal_format, gl_type);
feature_info, image_internal_format, gl_type);
info.adjusted_format =
gles2::TextureManager::AdjustTexFormat(feature_info.get(), gl_format);
gles2::TextureManager::AdjustTexFormat(feature_info, gl_format);
}
if (!info.enabled)
continue;
Expand All @@ -91,7 +85,7 @@ SharedImageBackingFactoryGLCommon::SharedImageBackingFactoryGLCommon(
info.supports_storage = true;
info.storage_internal_format =
gles2::TextureManager::AdjustTexStorageFormat(
feature_info.get(), storage_internal_format);
feature_info, storage_internal_format);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class ProgressReporter;
} // namespace gl

namespace gpu {

namespace gles2 {
class FeatureInfo;
} // namespace gles2

class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;

// Common constructor and helper functions for
Expand Down Expand Up @@ -59,7 +63,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLCommon
protected:
SharedImageBackingFactoryGLCommon(const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
gl::ProgressReporter* progress_reporter);
~SharedImageBackingFactoryGLCommon() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@ using InitializeGLTextureParams =
SharedImageBackingFactoryGLImage::SharedImageBackingFactoryGLImage(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
ImageFactory* image_factory,
gl::ProgressReporter* progress_reporter,
const bool for_shared_memory_gmbs)
: SharedImageBackingFactoryGLCommon(gpu_preferences,
workarounds,
gpu_feature_info,
feature_info,
progress_reporter),
image_factory_(image_factory),
for_shared_memory_gmbs_(for_shared_memory_gmbs) {
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2,
use_passthrough_, gles2::DisallowedFeatures());
gpu_memory_buffer_formats_ =
feature_info->feature_flags().gpu_memory_buffer_formats;
// Return if scanout images are not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ProgressReporter;
namespace gpu {
class SharedImageBacking;
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;
struct Mailbox;
class ImageFactory;
Expand All @@ -42,7 +41,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLImage
// other parts with OzoneBacking and other backings.
SharedImageBackingFactoryGLImage(const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
ImageFactory* image_factory,
gl::ProgressReporter* progress_reporter,
const bool for_shared_memory_gmbs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class SharedImageBackingFactoryGLImageTestBase
GpuPreferences preferences;
preferences.use_passthrough_cmd_decoder = use_passthrough();
backing_factory_ = std::make_unique<SharedImageBackingFactoryGLImage>(
preferences, workarounds, GpuFeatureInfo(), factory,
preferences, workarounds, context_state_->feature_info(), factory,
&progress_reporter_, /*for_shared_memory_gmbs=*/false);
backing_factory_shmem_ = std::make_unique<SharedImageBackingFactoryGLImage>(
preferences, workarounds, GpuFeatureInfo(), factory,
preferences, workarounds, context_state_->feature_info(), factory,
&progress_reporter_, /*for_shared_memory_gmbs=*/true);

memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ using InitializeGLTextureParams =
SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
gl::ProgressReporter* progress_reporter)
: SharedImageBackingFactoryGLCommon(gpu_preferences,
workarounds,
gpu_feature_info,
feature_info,
progress_reporter) {}

SharedImageBackingFactoryGLTexture::~SharedImageBackingFactoryGLTexture() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ProgressReporter;
namespace gpu {
class SharedImageBacking;
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;
struct Mailbox;

Expand All @@ -34,7 +33,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
public:
SharedImageBackingFactoryGLTexture(const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
const gles2::FeatureInfo* feature_info,
gl::ProgressReporter* progress_reporter);
~SharedImageBackingFactoryGLTexture() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class SharedImageBackingFactoryGLTextureTestBase
GpuPreferences preferences;
preferences.use_passthrough_cmd_decoder = use_passthrough();
backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
preferences, workarounds, GpuFeatureInfo(), &progress_reporter_);
preferences, workarounds, context_state_->feature_info(),
&progress_reporter_);

memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
shared_image_representation_factory_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class SharedImageBackingFactoryIOSurfaceTest : public testing::Test {
context_state_->InitializeGL(preferences, std::move(feature_info));

backing_factory_ = std::make_unique<SharedImageBackingFactoryGLImage>(
preferences, workarounds, GpuFeatureInfo(), &image_factory_,
preferences, workarounds, context_state_->feature_info(),
&image_factory_,
/*progress_reporter=*/nullptr, /*for_shared_memory_gmbs=*/false);

memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
Expand Down
28 changes: 21 additions & 7 deletions gpu/command_buffer/service/shared_image_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ SharedImageFactory::SharedImageFactory(
gr_context_type_ == GrContextType::kVulkan);
#endif

scoped_refptr<gles2::FeatureInfo> feature_info;
if (shared_context_state_) {
feature_info = shared_context_state_->feature_info();
}

if (!feature_info) {
// For some unit tests, shared_context_state_ could be nullptr.
bool use_passthrough = gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported();
feature_info = new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2,
use_passthrough, gles2::DisallowedFeatures());
}

if (!set_dmabuf_supported_metric_) {
bool pixmap_supported = ShouldUseOzoneFactory();
bool vulkan_ext_supported = false;
Expand Down Expand Up @@ -297,7 +311,7 @@ SharedImageFactory::SharedImageFactory(
if (use_gl) {
auto gl_texture_backing_factory =
std::make_unique<SharedImageBackingFactoryGLTexture>(
gpu_preferences, workarounds, gpu_feature_info,
gpu_preferences, workarounds, feature_info.get(),
shared_context_state_ ? shared_context_state_->progress_reporter()
: nullptr);
factories_.push_back(std::move(gl_texture_backing_factory));
Expand All @@ -318,7 +332,7 @@ SharedImageFactory::SharedImageFactory(
if (use_gl) {
auto gl_image_backing_factory =
std::make_unique<SharedImageBackingFactoryGLImage>(
gpu_preferences, workarounds, gpu_feature_info, image_factory,
gpu_preferences, workarounds, feature_info.get(), image_factory,
shared_context_state_ ? shared_context_state_->progress_reporter()
: nullptr,
/*for_shared_memory_gmbs=*/true);
Expand All @@ -331,7 +345,7 @@ SharedImageFactory::SharedImageFactory(
if ((gr_context_type_ == GrContextType::kVulkan) &&
(base::FeatureList::IsEnabled(features::kVulkanFromANGLE))) {
auto factory = std::make_unique<SharedImageBackingFactoryAngleVulkan>(
gpu_preferences, workarounds, gpu_feature_info, context_state);
gpu_preferences, workarounds, context_state);
factories_.push_back(std::move(factory));
}
#endif
Expand All @@ -345,7 +359,7 @@ SharedImageFactory::SharedImageFactory(
#elif BUILDFLAG(IS_ANDROID)
if (use_gl) {
auto egl_backing_factory = std::make_unique<SharedImageBackingFactoryEGL>(
gpu_preferences, workarounds, gpu_feature_info,
gpu_preferences, workarounds, feature_info.get(),
shared_image_manager->batch_access_manager());
factories_.push_back(std::move(egl_backing_factory));
}
Expand All @@ -362,8 +376,8 @@ SharedImageFactory::SharedImageFactory(
VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME);
}
if (is_ahb_supported) {
auto ahb_factory = std::make_unique<SharedImageBackingFactoryAHB>(
workarounds, gpu_feature_info);
auto ahb_factory =
std::make_unique<SharedImageBackingFactoryAHB>(feature_info.get());
factories_.push_back(std::move(ahb_factory));
}
if (gr_context_type_ == GrContextType::kVulkan &&
Expand Down Expand Up @@ -409,7 +423,7 @@ SharedImageFactory::SharedImageFactory(
if (use_gl) {
auto gl_image_backing_factory =
std::make_unique<SharedImageBackingFactoryGLImage>(
gpu_preferences, workarounds, gpu_feature_info, image_factory,
gpu_preferences, workarounds, feature_info.get(), image_factory,
shared_context_state_ ? shared_context_state_->progress_reporter()
: nullptr,
/*for_shared_memory_gmbs=*/false);
Expand Down

0 comments on commit 69f6ae9

Please sign in to comment.