Commit 85867c2d authored by Andres Calderon Jaramillo's avatar Andres Calderon Jaramillo Committed by Commit Bot

Report progress to watchdog for allocation/upload.

This CL makes the SharedImageBackingFactoryGLTexture notify the GPU
watchdog that progress is being made around the code that requests
memory allocation or texture upload. This is an attempt to improve the
crash rate due to allocation taking a long time (as opposed to it being
a GPU hang).

Bug: 1082197
Test: added unit test coverage.
Change-Id: Ic9530fd53df95d5ce0b675231c0ac52e682c69e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215256
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarMaggie Chen <magchen@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813055}
parent 95676d30
...@@ -22,6 +22,10 @@ class Size; ...@@ -22,6 +22,10 @@ class Size;
class ColorSpace; class ColorSpace;
} // namespace gfx } // namespace gfx
namespace gl {
class ProgressReporter;
} // namespace gl
namespace gpu { namespace gpu {
class SharedImageBacking; class SharedImageBacking;
class SharedImageBatchAccessManager; class SharedImageBatchAccessManager;
...@@ -43,7 +47,8 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture ...@@ -43,7 +47,8 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
const GpuDriverBugWorkarounds& workarounds, const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info, const GpuFeatureInfo& gpu_feature_info,
ImageFactory* image_factory, ImageFactory* image_factory,
SharedImageBatchAccessManager* batch_access_manager); SharedImageBatchAccessManager* batch_access_manager,
gl::ProgressReporter* progress_reporter);
~SharedImageBackingFactoryGLTexture() override; ~SharedImageBackingFactoryGLTexture() override;
// SharedImageBackingFactory implementation. // SharedImageBackingFactory implementation.
...@@ -170,6 +175,10 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture ...@@ -170,6 +175,10 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
SharedImageBackingGLCommon::UnpackStateAttribs attribs; SharedImageBackingGLCommon::UnpackStateAttribs attribs;
GpuDriverBugWorkarounds workarounds_; GpuDriverBugWorkarounds workarounds_;
// Used to notify the watchdog before a buffer allocation in case it takes
// long.
gl::ProgressReporter* const progress_reporter_ = nullptr;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
SharedImageBatchAccessManager* batch_access_manager_ = nullptr; SharedImageBatchAccessManager* batch_access_manager_ = nullptr;
#endif #endif
......
...@@ -67,7 +67,8 @@ class SharedImageBackingFactoryIOSurfaceTest : public testing::Test { ...@@ -67,7 +67,8 @@ class SharedImageBackingFactoryIOSurfaceTest : public testing::Test {
backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>( backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
preferences, workarounds, GpuFeatureInfo(), &image_factory_, preferences, workarounds, GpuFeatureInfo(), &image_factory_,
shared_image_manager_.batch_access_manager()); shared_image_manager_.batch_access_manager(),
/*progress_reporter=*/nullptr);
memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr); memory_type_tracker_ = std::make_unique<MemoryTypeTracker>(nullptr);
shared_image_representation_factory_ = shared_image_representation_factory_ =
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "ui/gl/gl_image_shared_memory.h" #include "ui/gl/gl_image_shared_memory.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_version_info.h" #include "ui/gl/gl_version_info.h"
#include "ui/gl/progress_reporter.h"
#include "ui/gl/scoped_binders.h" #include "ui/gl/scoped_binders.h"
#include "ui/gl/shared_gl_fence_egl.h" #include "ui/gl/shared_gl_fence_egl.h"
#include "ui/gl/trace_util.h" #include "ui/gl/trace_util.h"
...@@ -75,11 +76,13 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture( ...@@ -75,11 +76,13 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
const GpuDriverBugWorkarounds& workarounds, const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info, const GpuFeatureInfo& gpu_feature_info,
ImageFactory* image_factory, ImageFactory* image_factory,
SharedImageBatchAccessManager* batch_access_manager) SharedImageBatchAccessManager* batch_access_manager,
gl::ProgressReporter* progress_reporter)
: use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder && : use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported()), gles2::PassthroughCommandDecoderSupported()),
image_factory_(image_factory), image_factory_(image_factory),
workarounds_(workarounds) { workarounds_(workarounds),
progress_reporter_(progress_reporter) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
batch_access_manager_ = batch_access_manager; batch_access_manager_ = batch_access_manager;
#endif #endif
...@@ -505,13 +508,22 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -505,13 +508,22 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
// the internal format in the LevelInfo. https://crbug.com/628064 // the internal format in the LevelInfo. https://crbug.com/628064
GLuint level_info_internal_format = format_info.gl_format; GLuint level_info_internal_format = format_info.gl_format;
bool is_cleared = false; bool is_cleared = false;
// |scoped_progress_reporter| will notify |progress_reporter_| upon
// construction and destruction. We limit the scope so that progress is
// reported immediately after allocation/upload and before other GL
// operations.
if (use_buffer) { if (use_buffer) {
{
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
image = image_factory_->CreateAnonymousImage( image = image_factory_->CreateAnonymousImage(
size, format_info.buffer_format, gfx::BufferUsage::SCANOUT, size, format_info.buffer_format, gfx::BufferUsage::SCANOUT,
surface_handle, &is_cleared); surface_handle, &is_cleared);
}
// Scanout images have different constraints than GL images and might fail // Scanout images have different constraints than GL images and might fail
// to allocate even if GL images can be created. // to allocate even if GL images can be created.
if (!image) { if (!image) {
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
// TODO(dcastagna): Use BufferUsage::GPU_READ_WRITE instead // TODO(dcastagna): Use BufferUsage::GPU_READ_WRITE instead
// BufferUsage::GPU_READ once we add it. // BufferUsage::GPU_READ once we add it.
image = image_factory_->CreateAnonymousImage( image = image_factory_->CreateAnonymousImage(
...@@ -546,6 +558,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -546,6 +558,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
image, mailbox, format, size, color_space, surface_origin, alpha_type, image, mailbox, format, size, color_space, surface_origin, alpha_type,
usage, params, attribs, use_passthrough_); usage, params, attribs, use_passthrough_);
if (!pixel_data.empty()) { if (!pixel_data.empty()) {
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
result->InitializePixels(format_info.adjusted_format, format_info.gl_type, result->InitializePixels(format_info.adjusted_format, format_info.gl_type,
pixel_data.data()); pixel_data.data());
} }
...@@ -561,12 +574,16 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -561,12 +574,16 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
api->glBindTextureFn(target, result->GetGLServiceId()); api->glBindTextureFn(target, result->GetGLServiceId());
if (format_info.supports_storage) { if (format_info.supports_storage) {
{
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
api->glTexStorage2DEXTFn(target, 1, format_info.storage_internal_format, api->glTexStorage2DEXTFn(target, 1, format_info.storage_internal_format,
size.width(), size.height()); size.width(), size.height());
}
if (!pixel_data.empty()) { if (!pixel_data.empty()) {
ScopedResetAndRestoreUnpackState scoped_unpack_state( ScopedResetAndRestoreUnpackState scoped_unpack_state(
api, attribs, true /* uploading_data */); api, attribs, true /* uploading_data */);
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
api->glTexSubImage2DFn(target, 0, 0, 0, size.width(), size.height(), api->glTexSubImage2DFn(target, 0, 0, 0, size.width(), size.height(),
format_info.adjusted_format, format_info.gl_type, format_info.adjusted_format, format_info.gl_type,
pixel_data.data()); pixel_data.data());
...@@ -574,12 +591,14 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -574,12 +591,14 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
} else if (format_info.is_compressed) { } else if (format_info.is_compressed) {
ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs, ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs,
!pixel_data.empty()); !pixel_data.empty());
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
api->glCompressedTexImage2DFn( api->glCompressedTexImage2DFn(
target, 0, format_info.image_internal_format, size.width(), target, 0, format_info.image_internal_format, size.width(),
size.height(), 0, pixel_data.size(), pixel_data.data()); size.height(), 0, pixel_data.size(), pixel_data.data());
} else { } else {
ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs, ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs,
!pixel_data.empty()); !pixel_data.empty());
gl::ScopedProgressReporter scoped_progress_reporter(progress_reporter_);
api->glTexImage2DFn(target, 0, format_info.image_internal_format, api->glTexImage2DFn(target, 0, format_info.image_internal_format,
size.width(), size.height(), 0, size.width(), size.height(), 0,
format_info.adjusted_format, format_info.gl_type, format_info.adjusted_format, format_info.gl_type,
......
...@@ -100,7 +100,9 @@ SharedImageFactory::SharedImageFactory( ...@@ -100,7 +100,9 @@ SharedImageFactory::SharedImageFactory(
if (use_gl) { if (use_gl) {
gl_backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>( gl_backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
gpu_preferences, workarounds, gpu_feature_info, image_factory, gpu_preferences, workarounds, gpu_feature_info, image_factory,
shared_image_manager->batch_access_manager()); shared_image_manager->batch_access_manager(),
shared_context_state_ ? shared_context_state_->progress_reporter()
: nullptr);
} }
// TODO(ccameron): This block of code should be changed to a switch on // TODO(ccameron): This block of code should be changed to a switch on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment