Commit f02517f9 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

GpuVideoDecoder: add OnMemoryDump capability

ToT memory-infra dump shows the Textures allocated for GPU video
decoding, but it has no idea of the Renderer client on behalf of
whom the GPU-side allocation has happened, see e.g. [1].

This CL adds GpuVideoDecoder::OnMemoryDump(), with the
appropriate OwnershipEdge, so that:
- The textures from the GPU process are reported with
  |effective_size| 0 and a renderer owner, e.g. [2].
- The Renderer has a new gpu sub-category |video_decoding|
  with the textures reporting both |size| and |effective_size|,
  and to which those in the GPU process can refer to, e.g. [3].

There's a bunch of changes to GpuVideoAcceleratorFactories{Impl}
to be able to access the gpu::ContextSupport (intermediate types
are not available to media/filters); also media/filters can't
depend on ui/gl, so this CL adds a trivial trace_util.{cc,h} to
media/video, respecting the hierarchies.

[1] https://i.imgur.com/3tJThzL.png (https://imgur.com/a/7Y01lQ9)
[2] https://i.imgur.com/KqJ8jQf.jpg  (https://imgur.com/a/jrXGM49)
[3] https://i.imgur.com/f0u5xeR.png (https://imgur.com/a/zrlSVke)

Bug: 916807
Change-Id: Iffbb3cf8911ff6009a7f4989409e1bb6a95cf719
Reviewed-on: https://chromium-review.googlesource.com/c/1385546
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618662}
parent 96d8d106
......@@ -204,6 +204,11 @@ BrowserGpuVideoAcceleratorFactories::GetMediaContextProvider() {
return context_provider_;
}
gpu::ContextSupport*
BrowserGpuVideoAcceleratorFactories::GetMediaContextProviderContextSupport() {
return GetMediaContextProvider()->ContextSupport();
}
void BrowserGpuVideoAcceleratorFactories::SetRenderingColorSpace(
const gfx::ColorSpace& color_space) {}
......
......@@ -63,6 +63,7 @@ class BrowserGpuVideoAcceleratorFactories
GetVideoEncodeAcceleratorSupportedProfiles() override;
scoped_refptr<ws::ContextProviderCommandBuffer> GetMediaContextProvider()
override;
gpu::ContextSupport* GetMediaContextProviderContextSupport() override;
void SetRenderingColorSpace(const gfx::ColorSpace& color_space) override;
scoped_refptr<ws::ContextProviderCommandBuffer> context_provider_;
......
......@@ -481,6 +481,12 @@ GpuVideoAcceleratorFactoriesImpl::GetMediaContextProvider() {
return CheckContextLost() ? nullptr : context_provider_;
}
gpu::ContextSupport*
GpuVideoAcceleratorFactoriesImpl::GetMediaContextProviderContextSupport() {
auto context_provider = GetMediaContextProvider();
return context_provider ? context_provider->ContextSupport() : nullptr;
}
void GpuVideoAcceleratorFactoriesImpl::SetRenderingColorSpace(
const gfx::ColorSpace& color_space) {
rendering_color_space_ = color_space;
......
......@@ -125,6 +125,7 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
scoped_refptr<ws::ContextProviderCommandBuffer> GetMediaContextProvider()
override;
gpu::ContextSupport* GetMediaContextProviderContextSupport() override;
void SetRenderingColorSpace(const gfx::ColorSpace& color_space) override;
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include <array>
#include <cinttypes>
#include <utility>
#include "base/bind.h"
......@@ -17,9 +18,13 @@
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/cdm_context.h"
......@@ -31,6 +36,7 @@
#include "media/base/video_util.h"
#include "media/media_buildflags.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "media/video/trace_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#if defined(OS_ANDROID) && BUILDFLAG(USE_PROPRIETARY_CODECS)
......@@ -91,6 +97,8 @@ GpuVideoDecoder::GpuVideoDecoder(
bitstream_buffer_id_of_last_gc_(0),
weak_factory_(this) {
DCHECK(factories_);
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "media::GpuVideoDecoder", base::ThreadTaskRunnerHandle::Get());
}
void GpuVideoDecoder::Reset(const base::Closure& closure) {
......@@ -814,6 +822,9 @@ GpuVideoDecoder::~GpuVideoDecoder() {
DVLOG(3) << __func__;
DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
if (vda_)
DestroyVDA();
DCHECK(assigned_picture_buffers_.empty());
......@@ -889,6 +900,44 @@ void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) {
DestroyVDA();
}
bool GpuVideoDecoder::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
using base::trace_event::MemoryAllocatorDump;
DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent();
if (assigned_picture_buffers_.empty())
return false;
if (!factories_)
return false;
auto* context_support = factories_->GetMediaContextProviderContextSupport();
if (!context_support)
return false;
const uint64_t context_group_tracing_id =
context_support->ShareGroupTracingGUID();
for (const auto& picture_buffer : assigned_picture_buffers_) {
PictureBuffer::TextureIds texture_ids =
picture_buffer.second.client_texture_ids();
for (uint32_t id : texture_ids) {
const auto dump_name = base::StringPrintf(
"gpu/video_decoding/context_group_0x%" PRIx64 "/texture_0x%" PRIX32,
context_group_tracing_id, id);
MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(
MemoryAllocatorDump::kNameSize, MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(picture_buffer.second.size().GetArea() * 4));
const auto client_guid =
GetGLTextureClientGUIDForTracing(context_group_tracing_id, id);
pmd->CreateSharedGlobalAllocatorDump(client_guid);
pmd->AddOwnershipEdge(dump->guid(), client_guid, 2 /* importance */);
}
}
return true;
}
bool GpuVideoDecoder::IsProfileSupported(
const VideoDecodeAccelerator::Capabilities& capabilities,
VideoCodecProfile profile,
......
......@@ -17,6 +17,7 @@
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/trace_event/memory_dump_provider.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "media/base/overlay_info.h"
#include "media/base/pipeline_status.h"
......@@ -45,7 +46,8 @@ class MediaLog;
// GetMessageLoop().
class MEDIA_EXPORT GpuVideoDecoder
: public VideoDecoder,
public VideoDecodeAccelerator::Client {
public VideoDecodeAccelerator::Client,
public base::trace_event::MemoryDumpProvider {
public:
GpuVideoDecoder(GpuVideoAcceleratorFactories* factories,
const RequestOverlayInfoCB& request_overlay_info_cb,
......@@ -83,6 +85,10 @@ class MEDIA_EXPORT GpuVideoDecoder
void NotifyResetDone() override;
void NotifyError(media::VideoDecodeAccelerator::Error error) override;
// base::trace_event::MemoryDumpProvider implementation.
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;
static const char kDecoderName[];
private:
......
......@@ -35,6 +35,8 @@ source_set("video") {
"jpeg_encode_accelerator.h",
"picture.cc",
"picture.h",
"trace_util.cc",
"trace_util.h",
"video_decode_accelerator.cc",
"video_decode_accelerator.h",
"video_encode_accelerator.cc",
......
......@@ -35,6 +35,7 @@ class Size;
}
namespace gpu {
class ContextSupport;
struct SyncToken;
}
......@@ -154,6 +155,7 @@ class MEDIA_EXPORT GpuVideoAcceleratorFactories {
virtual scoped_refptr<ws::ContextProviderCommandBuffer>
GetMediaContextProvider() = 0;
virtual gpu::ContextSupport* GetMediaContextProviderContextSupport() = 0;
// Sets the current pipeline rendering color space.
virtual void SetRenderingColorSpace(const gfx::ColorSpace& color_space) = 0;
......
......@@ -67,6 +67,7 @@ class MockGpuVideoAcceleratorFactories : public GpuVideoAcceleratorFactories {
VideoEncodeAccelerator::SupportedProfiles());
MOCK_METHOD0(GetMediaContextProvider,
scoped_refptr<ws::ContextProviderCommandBuffer>());
MOCK_METHOD0(GetMediaContextProviderContextSupport, gpu::ContextSupport*());
MOCK_METHOD1(SetRenderingColorSpace, void(const gfx::ColorSpace&));
std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
......
// 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 "media/video/trace_util.h"
#include "base/trace_event/memory_allocator_dump_guid.h"
#include "ui/gl/trace_util.h"
namespace media {
base::trace_event::MemoryAllocatorDumpGuid GetGLTextureClientGUIDForTracing(
uint64_t context_group_tracing_id,
uint32_t texture_id) {
return gl::GetGLTextureClientGUIDForTracing(context_group_tracing_id,
texture_id);
}
} // namespace media
// 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 MEDIA_VIDEO_TRACE_UTIL_H_
#define MEDIA_VIDEO_TRACE_UTIL_H_
#include <stdint.h>
namespace base {
namespace trace_event {
class MemoryAllocatorDumpGuid;
}
} // namespace base
namespace media {
base::trace_event::MemoryAllocatorDumpGuid GetGLTextureClientGUIDForTracing(
uint64_t context_group_tracing_id,
uint32_t texture_id);
} // namespace media
#endif // MEDIA_VIDEO_TRACE_UTIL_H_
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