Commit 1e9e40b7 authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

Use SharedImageInterface for gpu and OOP raster

This wires up SharedImageInterface all the way to cc, and uses it for OOP and GPU raster.
This also adds memory accounting in SharedImageFactory/SharedImageStub.

Bug: 870116
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I37eba221bc2aeb4d03b7d4d93bde772482dc681b
Reviewed-on: https://chromium-review.googlesource.com/1178977
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592419}
parent b387b073
...@@ -149,6 +149,11 @@ class GrContext* AwRenderThreadContextProvider::GrContext() { ...@@ -149,6 +149,11 @@ class GrContext* AwRenderThreadContextProvider::GrContext() {
return gr_context_.get(); return gr_context_.get();
} }
gpu::SharedImageInterface*
AwRenderThreadContextProvider::SharedImageInterface() {
return context_->GetSharedImageInterface();
}
viz::ContextCacheController* AwRenderThreadContextProvider::CacheController() { viz::ContextCacheController* AwRenderThreadContextProvider::CacheController() {
DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(main_thread_checker_.CalledOnValidThread());
return cache_controller_.get(); return cache_controller_.get();
......
...@@ -51,6 +51,7 @@ class AwRenderThreadContextProvider ...@@ -51,6 +51,7 @@ class AwRenderThreadContextProvider
gpu::gles2::GLES2Interface* ContextGL() override; gpu::gles2::GLES2Interface* ContextGL() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
viz::ContextCacheController* CacheController() override; viz::ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
void AddObserver(viz::ContextLostObserver* obs) override; void AddObserver(viz::ContextLostObserver* obs) override;
......
...@@ -8,6 +8,8 @@ include_rules = [ ...@@ -8,6 +8,8 @@ include_rules = [
"+gpu/command_buffer/client/gles2_interface_stub.h", # for tests "+gpu/command_buffer/client/gles2_interface_stub.h", # for tests
"+gpu/command_buffer/client/gpu_memory_buffer_manager.h", "+gpu/command_buffer/client/gpu_memory_buffer_manager.h",
"+gpu/command_buffer/client/raster_implementation_gles.h", "+gpu/command_buffer/client/raster_implementation_gles.h",
"+gpu/command_buffer/client/raster_interface.h",
"+gpu/command_buffer/client/shared_image_interface.h",
"+gpu/command_buffer/common/capabilities.h", "+gpu/command_buffer/common/capabilities.h",
"+gpu/command_buffer/common/discardable_handle.h", "+gpu/command_buffer/common/discardable_handle.h",
"+gpu/command_buffer/common/gl2_types.h", "+gpu/command_buffer/common/gl2_types.h",
...@@ -15,7 +17,8 @@ include_rules = [ ...@@ -15,7 +17,8 @@ include_rules = [
"+gpu/command_buffer/common/gpu_memory_buffer_support.h", "+gpu/command_buffer/common/gpu_memory_buffer_support.h",
"+gpu/command_buffer/common/mailbox.h", "+gpu/command_buffer/common/mailbox.h",
"+gpu/command_buffer/common/mailbox_holder.h", "+gpu/command_buffer/common/mailbox_holder.h",
"+gpu/command_buffer/client/raster_interface.h", "+gpu/command_buffer/common/shared_image_trace_utils.h",
"+gpu/command_buffer/common/shared_image_usage.h",
"+gpu/command_buffer/common/sync_token.h", "+gpu/command_buffer/common/sync_token.h",
"+gpu/command_buffer/common/texture_in_use_response.h", "+gpu/command_buffer/common/texture_in_use_response.h",
"+gpu/config/gpu_feature_info.h", "+gpu/config/gpu_feature_info.h",
......
This diff is collapsed.
...@@ -49,10 +49,9 @@ class CC_EXPORT GpuRasterBufferProvider : public RasterBufferProvider { ...@@ -49,10 +49,9 @@ class CC_EXPORT GpuRasterBufferProvider : public RasterBufferProvider {
void Shutdown() override; void Shutdown() override;
gpu::SyncToken PlaybackOnWorkerThread( gpu::SyncToken PlaybackOnWorkerThread(
const gpu::Mailbox& mailbox, gpu::Mailbox* mailbox,
GLenum texture_target, GLenum texture_target,
bool texture_is_overlay_candidate, bool texture_is_overlay_candidate,
bool texture_storage_allocated,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
const gfx::Size& resource_size, const gfx::Size& resource_size,
viz::ResourceFormat resource_format, viz::ResourceFormat resource_format,
...@@ -97,11 +96,10 @@ class CC_EXPORT GpuRasterBufferProvider : public RasterBufferProvider { ...@@ -97,11 +96,10 @@ class CC_EXPORT GpuRasterBufferProvider : public RasterBufferProvider {
const gfx::ColorSpace color_space_; const gfx::ColorSpace color_space_;
const bool resource_has_previous_content_; const bool resource_has_previous_content_;
const gpu::SyncToken before_raster_sync_token_; const gpu::SyncToken before_raster_sync_token_;
const gpu::Mailbox mailbox_;
const GLenum texture_target_; const GLenum texture_target_;
const bool texture_is_overlay_candidate_; const bool texture_is_overlay_candidate_;
// Set to true once allocation is done in the worker thread.
bool texture_storage_allocated_; gpu::Mailbox mailbox_;
// A SyncToken to be returned from the worker thread, and waited on before // A SyncToken to be returned from the worker thread, and waited on before
// using the rastered resource. // using the rastered resource.
gpu::SyncToken after_raster_sync_token_; gpu::SyncToken after_raster_sync_token_;
......
...@@ -117,6 +117,12 @@ class PerfContextProvider ...@@ -117,6 +117,12 @@ class PerfContextProvider
} }
return test_context_provider_->GrContext(); return test_context_provider_->GrContext();
} }
gpu::SharedImageInterface* SharedImageInterface() override {
if (!test_context_provider_) {
test_context_provider_ = viz::TestContextProvider::Create();
}
return test_context_provider_->SharedImageInterface();
}
viz::ContextCacheController* CacheController() override { viz::ContextCacheController* CacheController() override {
return &cache_controller_; return &cache_controller_;
} }
......
...@@ -162,6 +162,15 @@ class GrContext* TestInProcessContextProvider::GrContext() { ...@@ -162,6 +162,15 @@ class GrContext* TestInProcessContextProvider::GrContext() {
return gr_context_->get(); return gr_context_->get();
} }
gpu::SharedImageInterface*
TestInProcessContextProvider::SharedImageInterface() {
if (gles2_context_) {
return gles2_context_->GetSharedImageInterface();
} else {
return raster_context_->GetSharedImageInterface();
}
}
viz::ContextCacheController* TestInProcessContextProvider::CacheController() { viz::ContextCacheController* TestInProcessContextProvider::CacheController() {
return cache_controller_.get(); return cache_controller_.get();
} }
......
...@@ -56,6 +56,7 @@ class TestInProcessContextProvider ...@@ -56,6 +56,7 @@ class TestInProcessContextProvider
gpu::raster::RasterInterface* RasterInterface() override; gpu::raster::RasterInterface* RasterInterface() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
viz::ContextCacheController* CacheController() override; viz::ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
const gpu::Capabilities& ContextCapabilities() const override; const gpu::Capabilities& ContextCapabilities() const override;
......
...@@ -69,6 +69,10 @@ class MockContextProvider : public ContextProvider { ...@@ -69,6 +69,10 @@ class MockContextProvider : public ContextProvider {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
gpu::SharedImageInterface* SharedImageInterface() final {
NOTREACHED();
return nullptr;
}
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const final { const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const final {
NOTREACHED(); NOTREACHED();
return *reinterpret_cast<gpu::GpuFeatureInfo*>(0xdeadbeef); return *reinterpret_cast<gpu::GpuFeatureInfo*>(0xdeadbeef);
......
...@@ -26,6 +26,7 @@ class Lock; ...@@ -26,6 +26,7 @@ class Lock;
namespace gpu { namespace gpu {
class ContextSupport; class ContextSupport;
struct GpuFeatureInfo; struct GpuFeatureInfo;
class SharedImageInterface;
namespace gles2 { namespace gles2 {
class GLES2Interface; class GLES2Interface;
...@@ -92,6 +93,8 @@ class VIZ_COMMON_EXPORT ContextProvider { ...@@ -92,6 +93,8 @@ class VIZ_COMMON_EXPORT ContextProvider {
// nullptr if a GrContext fails to initialize on this context. // nullptr if a GrContext fails to initialize on this context.
virtual class GrContext* GrContext() = 0; virtual class GrContext* GrContext() = 0;
virtual gpu::SharedImageInterface* SharedImageInterface() = 0;
// Returns the capabilities of the currently bound 3d context. The context // Returns the capabilities of the currently bound 3d context. The context
// provider must have been successfully bound to a thread before calling this. // provider must have been successfully bound to a thread before calling this.
virtual const gpu::Capabilities& ContextCapabilities() const = 0; virtual const gpu::Capabilities& ContextCapabilities() const = 0;
......
...@@ -26,6 +26,7 @@ class Lock; ...@@ -26,6 +26,7 @@ class Lock;
namespace gpu { namespace gpu {
class ContextSupport; class ContextSupport;
struct GpuFeatureInfo; struct GpuFeatureInfo;
class SharedImageInterface;
namespace gles2 { namespace gles2 {
class GLES2Interface; class GLES2Interface;
...@@ -99,6 +100,8 @@ class VIZ_COMMON_EXPORT RasterContextProvider { ...@@ -99,6 +100,8 @@ class VIZ_COMMON_EXPORT RasterContextProvider {
// nullptr if a GrContext fails to initialize on this context. // nullptr if a GrContext fails to initialize on this context.
virtual class GrContext* GrContext() = 0; virtual class GrContext* GrContext() = 0;
virtual gpu::SharedImageInterface* SharedImageInterface() = 0;
// Returns the capabilities of the currently bound 3d context. The context // Returns the capabilities of the currently bound 3d context. The context
// provider must have been successfully bound to a thread before calling this. // provider must have been successfully bound to a thread before calling this.
virtual const gpu::Capabilities& ContextCapabilities() const = 0; virtual const gpu::Capabilities& ContextCapabilities() const = 0;
......
...@@ -154,6 +154,10 @@ class GrContext* VizProcessContextProvider::GrContext() { ...@@ -154,6 +154,10 @@ class GrContext* VizProcessContextProvider::GrContext() {
return gr_context_->get(); return gr_context_->get();
} }
gpu::SharedImageInterface* VizProcessContextProvider::SharedImageInterface() {
return command_buffer_->GetSharedImageInterface();
}
ContextCacheController* VizProcessContextProvider::CacheController() { ContextCacheController* VizProcessContextProvider::CacheController() {
return cache_controller_.get(); return cache_controller_.get();
} }
......
...@@ -62,6 +62,7 @@ class VIZ_SERVICE_EXPORT VizProcessContextProvider ...@@ -62,6 +62,7 @@ class VIZ_SERVICE_EXPORT VizProcessContextProvider
gpu::gles2::GLES2Interface* ContextGL() override; gpu::gles2::GLES2Interface* ContextGL() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
ContextCacheController* CacheController() override; ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
const gpu::Capabilities& ContextCapabilities() const override; const gpu::Capabilities& ContextCapabilities() const override;
......
...@@ -6,6 +6,7 @@ include_rules = [ ...@@ -6,6 +6,7 @@ include_rules = [
"+gpu/command_buffer/client/context_support.h", "+gpu/command_buffer/client/context_support.h",
"+gpu/command_buffer/client/gles2_interface_stub.h", "+gpu/command_buffer/client/gles2_interface_stub.h",
"+gpu/command_buffer/client/raster_implementation_gles.h", "+gpu/command_buffer/client/raster_implementation_gles.h",
"+gpu/command_buffer/client/shared_image_interface.h",
"+gpu/command_buffer/common/capabilities.h", "+gpu/command_buffer/common/capabilities.h",
"+gpu/command_buffer/common/skia_utils.h", "+gpu/command_buffer/common/skia_utils.h",
"+gpu/command_buffer/common/sync_token.h", "+gpu/command_buffer/common/sync_token.h",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/viz/common/gpu/context_cache_controller.h" #include "components/viz/common/gpu/context_cache_controller.h"
#include "components/viz/test/test_gles2_interface.h" #include "components/viz/test/test_gles2_interface.h"
#include "gpu/command_buffer/client/raster_implementation_gles.h" #include "gpu/command_buffer/client/raster_implementation_gles.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/skia_utils.h" #include "gpu/command_buffer/common/skia_utils.h"
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h" #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/skia/include/gpu/GrContext.h" #include "third_party/skia/include/gpu/GrContext.h"
...@@ -110,6 +111,29 @@ class TestGLES2InterfaceForContextProvider : public TestGLES2Interface { ...@@ -110,6 +111,29 @@ class TestGLES2InterfaceForContextProvider : public TestGLES2Interface {
DISALLOW_COPY_AND_ASSIGN(TestGLES2InterfaceForContextProvider); DISALLOW_COPY_AND_ASSIGN(TestGLES2InterfaceForContextProvider);
}; };
class TestSharedImageInterface : public gpu::SharedImageInterface {
public:
~TestSharedImageInterface() override = default;
gpu::Mailbox CreateSharedImage(ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) override {
return gpu::Mailbox::Generate();
}
void DestroySharedImage(const gpu::SyncToken& sync_token,
const gpu::Mailbox& mailbox) override {}
gpu::SyncToken GenUnverifiedSyncToken() override {
return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId(), ++release_id_);
}
private:
uint64_t release_id_ = 0;
};
} // namespace } // namespace
// static // static
...@@ -179,6 +203,7 @@ TestContextProvider::TestContextProvider( ...@@ -179,6 +203,7 @@ TestContextProvider::TestContextProvider(
bool support_locking) bool support_locking)
: support_(std::move(support)), : support_(std::move(support)),
context_gl_(std::move(gl)), context_gl_(std::move(gl)),
shared_image_interface_(std::make_unique<TestSharedImageInterface>()),
support_locking_(support_locking), support_locking_(support_locking),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(main_thread_checker_.CalledOnValidThread());
...@@ -271,6 +296,10 @@ class GrContext* TestContextProvider::GrContext() { ...@@ -271,6 +296,10 @@ class GrContext* TestContextProvider::GrContext() {
return gr_context_->get(); return gr_context_->get();
} }
gpu::SharedImageInterface* TestContextProvider::SharedImageInterface() {
return shared_image_interface_.get();
}
ContextCacheController* TestContextProvider::CacheController() { ContextCacheController* TestContextProvider::CacheController() {
CheckValidThreadOrLockAcquired(); CheckValidThreadOrLockAcquired();
return cache_controller_.get(); return cache_controller_.get();
......
...@@ -62,6 +62,7 @@ class TestContextProvider ...@@ -62,6 +62,7 @@ class TestContextProvider
gpu::raster::RasterInterface* RasterInterface() override; gpu::raster::RasterInterface* RasterInterface() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
ContextCacheController* CacheController() override; ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
void AddObserver(ContextLostObserver* obs) override; void AddObserver(ContextLostObserver* obs) override;
...@@ -96,6 +97,7 @@ class TestContextProvider ...@@ -96,6 +97,7 @@ class TestContextProvider
std::unique_ptr<gpu::raster::RasterInterface> raster_context_; std::unique_ptr<gpu::raster::RasterInterface> raster_context_;
std::unique_ptr<skia_bindings::GrContextForGLES2Interface> gr_context_; std::unique_ptr<skia_bindings::GrContextForGLES2Interface> gr_context_;
std::unique_ptr<ContextCacheController> cache_controller_; std::unique_ptr<ContextCacheController> cache_controller_;
std::unique_ptr<gpu::SharedImageInterface> shared_image_interface_;
const bool support_locking_ ALLOW_UNUSED_TYPE; const bool support_locking_ ALLOW_UNUSED_TYPE;
bool bound_ = false; bool bound_ = false;
......
...@@ -87,6 +87,8 @@ jumbo_source_set("common_sources") { ...@@ -87,6 +87,8 @@ jumbo_source_set("common_sources") {
"mailbox_holder.h", "mailbox_holder.h",
"scheduling_priority.cc", "scheduling_priority.cc",
"scheduling_priority.h", "scheduling_priority.h",
"shared_image_trace_utils.cc",
"shared_image_trace_utils.h",
"shared_image_usage.h", "shared_image_usage.h",
"swap_buffers_complete_params.cc", "swap_buffers_complete_params.cc",
"swap_buffers_complete_params.h", "swap_buffers_complete_params.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "base/strings/stringprintf.h"
#include "gpu/command_buffer/common/mailbox.h"
namespace gpu {
base::trace_event::MemoryAllocatorDumpGuid GetSharedImageGUIDForTracing(
const Mailbox& mailbox) {
return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
"gpu-shared-image/%s", mailbox.ToDebugString().c_str()));
}
} // namespace gpu
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_TRACE_UTILS_H_
#define GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_TRACE_UTILS_H_
#include "base/trace_event/memory_allocator_dump.h"
#include "gpu/gpu_export.h"
namespace gpu {
struct Mailbox;
GPU_EXPORT base::trace_event::MemoryAllocatorDumpGuid
GetSharedImageGUIDForTracing(const Mailbox& mailbox);
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_TRACE_UTILS_H_
...@@ -4,8 +4,13 @@ ...@@ -4,8 +4,13 @@
#include "gpu/command_buffer/service/shared_image_factory.h" #include "gpu/command_buffer/service/shared_image_factory.h"
#include <inttypes.h>
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_dump_manager.h"
#include "components/viz/common/resources/resource_format_utils.h" #include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h" #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/command_buffer/service/image_factory.h" #include "gpu/command_buffer/service/image_factory.h"
...@@ -16,6 +21,7 @@ ...@@ -16,6 +21,7 @@
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/trace_util.h"
namespace gpu { namespace gpu {
...@@ -149,7 +155,7 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox, ...@@ -149,7 +155,7 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
return false; return false;
} }
GLenum target = use_buffer ? GL_TEXTURE_2D : format_info.target_for_scanout; GLenum target = use_buffer ? format_info.target_for_scanout : GL_TEXTURE_2D;
GLenum get_target = GL_TEXTURE_BINDING_2D; GLenum get_target = GL_TEXTURE_BINDING_2D;
switch (target) { switch (target) {
...@@ -237,7 +243,10 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox, ...@@ -237,7 +243,10 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
gles2::Texture* texture = new gles2::Texture(service_id); gles2::Texture* texture = new gles2::Texture(service_id);
texture->SetLightweightRef(memory_tracker_.get()); texture->SetLightweightRef(memory_tracker_.get());
texture->SetTarget(target, 1); texture->SetTarget(target, 1);
texture->SetLevelInfo(target, 0, internal_format, size.width(), // TODO(piman): We pretend the texture was created in an ES2 context, so
// that it can be used in other ES2 contexts, and so we have to pass
// gl_format as the internal format. https://crbug.com/628064
texture->SetLevelInfo(target, 0, format_info.gl_format, size.width(),
size.height(), 1, 0, format_info.gl_format, size.height(), 1, 0, format_info.gl_format,
format_info.gl_type, cleared_rect); format_info.gl_type, cleared_rect);
if (format_info.swizzle) if (format_info.swizzle)
...@@ -294,6 +303,52 @@ void SharedImageFactory::DestroyAllSharedImages(bool have_context) { ...@@ -294,6 +303,52 @@ void SharedImageFactory::DestroyAllSharedImages(bool have_context) {
mailboxes_.clear(); mailboxes_.clear();
} }
bool SharedImageFactory::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd,
int client_id,
uint64_t client_tracing_id) {
if (use_passthrough_)
return false;
for (const auto& mailbox : mailboxes_) {
auto* texture =
static_cast<gles2::Texture*>(mailbox_manager_->ConsumeTexture(mailbox));
DCHECK(texture);
// Unique name in the process.
std::string dump_name =
base::StringPrintf("gpu/shared-images/client_0x%" PRIX32 "/mailbox_%s",
client_id, mailbox.ToDebugString().c_str());
base::trace_event::MemoryAllocatorDump* dump =
pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(texture->estimated_size()));
// Add a mailbox guid which expresses shared ownership with the client
// process.
// This must match the client-side.
auto client_guid = GetSharedImageGUIDForTracing(mailbox);
pmd->CreateSharedGlobalAllocatorDump(client_guid);
pmd->AddOwnershipEdge(dump->guid(), client_guid);
// Add a |service_guid| which expresses shared ownership between the various
// GPU dumps.
auto service_guid =
gl::GetGLTextureServiceGUIDForTracing(texture->service_id());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
// Dump all sub-levels held by the texture. They will appear below the main
// gl/textures/client_X/mailbox_Y dump.
texture->DumpLevelMemory(pmd, client_tracing_id, dump_name);
}
return true;
}
SharedImageFactory::FormatInfo::FormatInfo() = default; SharedImageFactory::FormatInfo::FormatInfo() = default;
SharedImageFactory::FormatInfo::~FormatInfo() = default; SharedImageFactory::FormatInfo::~FormatInfo() = default;
......
...@@ -54,6 +54,10 @@ class GPU_GLES2_EXPORT SharedImageFactory { ...@@ -54,6 +54,10 @@ class GPU_GLES2_EXPORT SharedImageFactory {
bool DestroySharedImage(const Mailbox& mailbox); bool DestroySharedImage(const Mailbox& mailbox);
bool HasImages() const { return !mailboxes_.empty(); } bool HasImages() const { return !mailboxes_.empty(); }
void DestroyAllSharedImages(bool have_context); void DestroyAllSharedImages(bool have_context);
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd,
int client_id,
uint64_t client_tracing_id);
private: private:
struct FormatInfo { struct FormatInfo {
......
...@@ -3550,7 +3550,8 @@ void TextureManager::DumpTextureRef(base::trace_event::ProcessMemoryDump* pmd, ...@@ -3550,7 +3550,8 @@ void TextureManager::DumpTextureRef(base::trace_event::ProcessMemoryDump* pmd,
int importance = 0; // Default importance. int importance = 0; // Default importance.
// The link to the memory tracking |client_id| is given a higher importance // The link to the memory tracking |client_id| is given a higher importance
// than other refs. // than other refs.
if (ref == ref->texture()->memory_tracking_ref_) if (!ref->texture()->lightweight_ref_ &&
(ref == ref->texture()->memory_tracking_ref_))
importance = 2; importance = 2;
pmd->AddOwnershipEdge(client_guid, service_guid, importance); pmd->AddOwnershipEdge(client_guid, service_guid, importance);
......
...@@ -40,7 +40,11 @@ GpuChannelHost::GpuChannelHost(int channel_id, ...@@ -40,7 +40,11 @@ GpuChannelHost::GpuChannelHost(int channel_id,
gpu_info_(gpu_info), gpu_info_(gpu_info),
gpu_feature_info_(gpu_feature_info), gpu_feature_info_(gpu_feature_info),
listener_(new Listener(std::move(handle), io_thread_), listener_(new Listener(std::move(handle), io_thread_),
base::OnTaskRunnerDeleter(io_thread_)) { base::OnTaskRunnerDeleter(io_thread_)),
shared_image_interface_(
this,
static_cast<int32_t>(
GpuChannelReservedRoutes::kSharedImageInterface)) {
next_image_id_.GetNext(); next_image_id_.GetNext();
for (int32_t i = 0; for (int32_t i = 0;
i <= static_cast<int32_t>(GpuChannelReservedRoutes::kMaxValue); ++i) i <= static_cast<int32_t>(GpuChannelReservedRoutes::kMaxValue); ++i)
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "gpu/config/gpu_feature_info.h" #include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_info.h" #include "gpu/config/gpu_info.h"
#include "gpu/gpu_export.h" #include "gpu/gpu_export.h"
#include "gpu/ipc/client/shared_image_interface_proxy.h"
#include "ipc/ipc_channel_handle.h" #include "ipc/ipc_channel_handle.h"
#include "ipc/message_filter.h" #include "ipc/message_filter.h"
#include "ipc/message_router.h" #include "ipc/message_router.h"
...@@ -145,6 +146,10 @@ class GPU_EXPORT GpuChannelHost ...@@ -145,6 +146,10 @@ class GPU_EXPORT GpuChannelHost
// otherwise ignored. // otherwise ignored.
void CrashGpuProcessForTesting(); void CrashGpuProcessForTesting();
SharedImageInterface* shared_image_interface() {
return &shared_image_interface_;
}
protected: protected:
friend class base::RefCountedThreadSafe<GpuChannelHost>; friend class base::RefCountedThreadSafe<GpuChannelHost>;
~GpuChannelHost() override; ~GpuChannelHost() override;
...@@ -246,6 +251,8 @@ class GPU_EXPORT GpuChannelHost ...@@ -246,6 +251,8 @@ class GPU_EXPORT GpuChannelHost
// with base::Unretained(listener_). // with base::Unretained(listener_).
std::unique_ptr<Listener, base::OnTaskRunnerDeleter> listener_; std::unique_ptr<Listener, base::OnTaskRunnerDeleter> listener_;
SharedImageInterfaceProxy shared_image_interface_;
// Image IDs are allocated in sequence. // Image IDs are allocated in sequence.
base::AtomicSequenceNumber next_image_id_; base::AtomicSequenceNumber next_image_id_;
......
...@@ -48,6 +48,10 @@ gles2::GLES2Implementation* GLInProcessContext::GetImplementation() { ...@@ -48,6 +48,10 @@ gles2::GLES2Implementation* GLInProcessContext::GetImplementation() {
return gles2_implementation_.get(); return gles2_implementation_.get();
} }
SharedImageInterface* GLInProcessContext::GetSharedImageInterface() {
return command_buffer_->GetSharedImageInterface();
}
ContextResult GLInProcessContext::Initialize( ContextResult GLInProcessContext::Initialize(
scoped_refptr<CommandBufferTaskExecutor> task_executor, scoped_refptr<CommandBufferTaskExecutor> task_executor,
scoped_refptr<gl::GLSurface> surface, scoped_refptr<gl::GLSurface> surface,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
namespace gpu { namespace gpu {
class SharedImageInterface;
class TransferBuffer; class TransferBuffer;
struct GpuFeatureInfo; struct GpuFeatureInfo;
struct SharedMemoryLimits; struct SharedMemoryLimits;
...@@ -58,6 +59,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -58,6 +59,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
// can be used without making it current. // can be used without making it current.
gles2::GLES2Implementation* GetImplementation(); gles2::GLES2Implementation* GetImplementation();
SharedImageInterface* GetSharedImageInterface();
private: private:
// The destruction order is important, don't reorder these member variables. // The destruction order is important, don't reorder these member variables.
std::unique_ptr<InProcessCommandBuffer> command_buffer_; std::unique_ptr<InProcessCommandBuffer> command_buffer_;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "gpu/ipc/service/shared_image_stub.h" #include "gpu/ipc/service/shared_image_stub.h"
#include <inttypes.h>
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "gpu/command_buffer/service/scheduler.h" #include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/shared_image_factory.h" #include "gpu/command_buffer/service/shared_image_factory.h"
...@@ -24,7 +27,10 @@ SharedImageStub::SharedImageStub(GpuChannel* channel, int32_t route_id) ...@@ -24,7 +27,10 @@ SharedImageStub::SharedImageStub(GpuChannel* channel, int32_t route_id)
CommandBufferNamespace::GPU_IO, CommandBufferNamespace::GPU_IO,
CommandBufferIdFromChannelAndRoute(channel->client_id(), CommandBufferIdFromChannelAndRoute(channel->client_id(),
route_id), route_id),
sequence_)) {} sequence_)) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "gpu::SharedImageStub", channel_->task_runner());
}
SharedImageStub::~SharedImageStub() { SharedImageStub::~SharedImageStub() {
channel_->scheduler()->DestroySequence(sequence_); channel_->scheduler()->DestroySequence(sequence_);
...@@ -33,6 +39,8 @@ SharedImageStub::~SharedImageStub() { ...@@ -33,6 +39,8 @@ SharedImageStub::~SharedImageStub() {
bool have_context = MakeContextCurrentAndCreateFactory(); bool have_context = MakeContextCurrentAndCreateFactory();
factory_->DestroyAllSharedImages(have_context); factory_->DestroyAllSharedImages(have_context);
} }
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
} }
bool SharedImageStub::OnMessageReceived(const IPC::Message& msg) { bool SharedImageStub::OnMessageReceived(const IPC::Message& msg) {
...@@ -86,7 +94,11 @@ bool SharedImageStub::MakeContextCurrentAndCreateFactory() { ...@@ -86,7 +94,11 @@ bool SharedImageStub::MakeContextCurrentAndCreateFactory() {
} }
DCHECK(context_state_); DCHECK(context_state_);
DCHECK(!context_state_->context_lost); DCHECK(!context_state_->context_lost);
DCHECK(context_state_->context->IsCurrent(nullptr)); if (!context_state_->context->MakeCurrent(context_state_->surface.get())) {
LOG(ERROR) << "SharedImageStub: MakeCurrent failed";
OnError();
return false;
}
gpu::GpuMemoryBufferFactory* gmb_factory = gpu::GpuMemoryBufferFactory* gmb_factory =
channel_manager->gpu_memory_buffer_factory(); channel_manager->gpu_memory_buffer_factory();
factory_ = std::make_unique<SharedImageFactory>( factory_ = std::make_unique<SharedImageFactory>(
...@@ -136,4 +148,26 @@ uint64_t SharedImageStub::ContextGroupTracingId() const { ...@@ -136,4 +148,26 @@ uint64_t SharedImageStub::ContextGroupTracingId() const {
return sync_point_client_state_->command_buffer_id().GetUnsafeValue(); return sync_point_client_state_->command_buffer_id().GetUnsafeValue();
} }
bool SharedImageStub::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
if (!factory_)
return true;
if (args.level_of_detail ==
base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
std::string dump_name =
base::StringPrintf("gpu/gl/textures/client_0x%" PRIX32, ClientId());
base::trace_event::MemoryAllocatorDump* dump =
pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes, size_);
// Early out, no need for more detail in a BACKGROUND dump.
return true;
}
return factory_->OnMemoryDump(args, pmd, ClientId(), ClientTracingId());
}
} // namespace gpu } // namespace gpu
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_ #ifndef GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_
#define GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_ #define GPU_IPC_SERVICE_SHARED_IMAGE_STUB_H_
#include "base/trace_event/memory_dump_provider.h"
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/memory_tracking.h" #include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/sync_point_manager.h" #include "gpu/command_buffer/service/sync_point_manager.h"
...@@ -21,7 +22,9 @@ namespace raster { ...@@ -21,7 +22,9 @@ namespace raster {
struct RasterDecoderContextState; struct RasterDecoderContextState;
} }
class SharedImageStub : public IPC::Listener, public gles2::MemoryTracker { class SharedImageStub : public IPC::Listener,
public gles2::MemoryTracker,
public base::trace_event::MemoryDumpProvider {
public: public:
SharedImageStub(GpuChannel* channel, int32_t route_id); SharedImageStub(GpuChannel* channel, int32_t route_id);
~SharedImageStub() override; ~SharedImageStub() override;
...@@ -29,13 +32,17 @@ class SharedImageStub : public IPC::Listener, public gles2::MemoryTracker { ...@@ -29,13 +32,17 @@ class SharedImageStub : public IPC::Listener, public gles2::MemoryTracker {
// IPC::Listener implementation: // IPC::Listener implementation:
bool OnMessageReceived(const IPC::Message& msg) override; bool OnMessageReceived(const IPC::Message& msg) override;
// gles2::MemoryTracker implementation; // gles2::MemoryTracker implementation:
void TrackMemoryAllocatedChange(uint64_t delta) override; void TrackMemoryAllocatedChange(uint64_t delta) override;
uint64_t GetSize() const override; uint64_t GetSize() const override;
uint64_t ClientTracingId() const override; uint64_t ClientTracingId() const override;
int ClientId() const override; int ClientId() const override;
uint64_t ContextGroupTracingId() const override; uint64_t ContextGroupTracingId() const override;
// base::trace_event::MemoryDumpProvider implementation:
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;
SequenceId sequence() const { return sequence_; } SequenceId sequence() const { return sequence_; }
private: private:
......
...@@ -396,6 +396,11 @@ class GrContext* ContextProviderCommandBuffer::GrContext() { ...@@ -396,6 +396,11 @@ class GrContext* ContextProviderCommandBuffer::GrContext() {
return gr_context_->get(); return gr_context_->get();
} }
gpu::SharedImageInterface*
ContextProviderCommandBuffer::SharedImageInterface() {
return command_buffer_->channel()->shared_image_interface();
}
viz::ContextCacheController* ContextProviderCommandBuffer::CacheController() { viz::ContextCacheController* ContextProviderCommandBuffer::CacheController() {
CheckValidThreadOrLockAcquired(); CheckValidThreadOrLockAcquired();
return cache_controller_.get(); return cache_controller_.get();
......
...@@ -90,6 +90,7 @@ class ContextProviderCommandBuffer ...@@ -90,6 +90,7 @@ class ContextProviderCommandBuffer
gpu::raster::RasterInterface* RasterInterface() override; gpu::raster::RasterInterface* RasterInterface() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
viz::ContextCacheController* CacheController() override; viz::ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
const gpu::Capabilities& ContextCapabilities() const override; const gpu::Capabilities& ContextCapabilities() const override;
......
...@@ -168,6 +168,10 @@ class GrContext* InProcessContextProvider::GrContext() { ...@@ -168,6 +168,10 @@ class GrContext* InProcessContextProvider::GrContext() {
return gr_context_->get(); return gr_context_->get();
} }
gpu::SharedImageInterface* InProcessContextProvider::SharedImageInterface() {
return context_->GetSharedImageInterface();
}
viz::ContextCacheController* InProcessContextProvider::CacheController() { viz::ContextCacheController* InProcessContextProvider::CacheController() {
CheckValidThreadOrLockAcquired(); CheckValidThreadOrLockAcquired();
return cache_controller_.get(); return cache_controller_.get();
......
...@@ -60,6 +60,7 @@ class InProcessContextProvider ...@@ -60,6 +60,7 @@ class InProcessContextProvider
gpu::raster::RasterInterface* RasterInterface() override; gpu::raster::RasterInterface* RasterInterface() override;
gpu::ContextSupport* ContextSupport() override; gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override; class GrContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
viz::ContextCacheController* CacheController() override; viz::ContextCacheController* CacheController() override;
base::Lock* GetLock() override; base::Lock* GetLock() override;
void AddObserver(viz::ContextLostObserver* obs) override; void AddObserver(viz::ContextLostObserver* obs) override;
......
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