Add memory reporting. (bug 1365879 part 26, r=mattwoodrow)

This commit is contained in:
David Anderson 2017-06-23 14:23:14 -07:00
parent b02d5e2bfd
commit ea272c6f03
7 changed files with 119 additions and 1 deletions

View File

@ -29,6 +29,7 @@
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/LayerTreeOwnerTracker.h"
#include "mozilla/layers/UiCompositorControllerParent.h"
#include "mozilla/layers/MemoryReportingMLGPU.h"
#include "mozilla/webrender/RenderThread.h"
#include "nsDebugImpl.h"
#include "nsExceptionHandler.h"
@ -104,6 +105,7 @@ GPUParent::Init(base::ProcessId aParentPid,
gfxPlatform::InitNullMetadata();
// Ensure our Factory is initialised, mainly for gfx logging to work.
gfxPlatform::InitMoz2DLogging();
mlg::InitializeMemoryReporters();
#if defined(XP_WIN)
DeviceManagerDx::Init();
#endif

View File

@ -11,6 +11,7 @@
#include "mozilla/gfx/StackArray.h"
#include "mozilla/layers/DiagnosticsD3D11.h"
#include "mozilla/layers/LayerMLGPU.h"
#include "mozilla/layers/MemoryReportingMLGPU.h"
#include "mozilla/layers/ShaderDefinitionsMLGPU.h"
#include "mozilla/widget/CompositorWidget.h"
#include "mozilla/widget/WinCompositorWidget.h"
@ -39,6 +40,9 @@ MLGRenderTargetD3D11::MLGRenderTargetD3D11(const gfx::IntSize& aSize, MLGRenderT
MLGRenderTargetD3D11::~MLGRenderTargetD3D11()
{
if (mDepthBuffer) {
sRenderTargetUsage -= mSize.width * mSize.height * 1;
}
ForgetTexture();
}
@ -119,13 +123,17 @@ MLGRenderTargetD3D11::UpdateTexture(ID3D11Texture2D* aTexture)
mTexture = aTexture;
mRTView = view.forget();
sRenderTargetUsage += mSize.width * mSize.height * 4;
return true;
}
void
MLGRenderTargetD3D11::ForgetTexture()
{
mTexture = nullptr;
if (mTexture) {
sRenderTargetUsage -= mSize.width * mSize.height * 4;
mTexture = nullptr;
}
mRTView = nullptr;
mTextureSource = nullptr;
}
@ -166,6 +174,7 @@ MLGRenderTargetD3D11::CreateDepthBuffer(ID3D11Device* aDevice)
mDepthBuffer = buffer;
mDepthStencilView = dsv;
sRenderTargetUsage += mSize.width * mSize.height * 1;
return true;
}
@ -624,10 +633,26 @@ MLGBufferD3D11::MLGBufferD3D11(ID3D11Buffer* aBuffer, MLGBufferType aType, size_
mType(aType),
mSize(aSize)
{
switch (mType) {
case MLGBufferType::Vertex:
mlg::sVertexBufferUsage += mSize;
break;
case MLGBufferType::Constant:
mlg::sConstantBufferUsage += mSize;
break;
}
}
MLGBufferD3D11::~MLGBufferD3D11()
{
switch (mType) {
case MLGBufferType::Vertex:
mlg::sVertexBufferUsage -= mSize;
break;
case MLGBufferType::Constant:
mlg::sConstantBufferUsage -= mSize;
break;
}
}
MLGTextureD3D11::MLGTextureD3D11(ID3D11Texture2D* aTexture)

View File

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MemoryReportingMLGPU.h"
#include "nsIMemoryReporter.h"
namespace mozilla {
namespace layers {
namespace mlg {
mozilla::Atomic<size_t> sConstantBufferUsage;
mozilla::Atomic<size_t> sVertexBufferUsage;
mozilla::Atomic<size_t> sRenderTargetUsage;
class MemoryReportingMLGPU final : public nsIMemoryReporter
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData,
bool aAnonymize) override
{
if (sConstantBufferUsage) {
MOZ_COLLECT_REPORT(
"mlgpu-constant-buffers", KIND_OTHER, UNITS_BYTES,
sConstantBufferUsage,
"Advanced Layers shader constant buffers.");
}
if (sVertexBufferUsage) {
MOZ_COLLECT_REPORT(
"mlgpu-vertex-buffers", KIND_OTHER, UNITS_BYTES,
sVertexBufferUsage,
"Advanced Layers shader vertex buffers.");
}
if (sRenderTargetUsage) {
MOZ_COLLECT_REPORT(
"mlgpu-render-targets", KIND_OTHER, UNITS_BYTES,
sRenderTargetUsage,
"Advanced Layers render target textures and depth buffers.");
}
return NS_OK;
}
private:
~MemoryReportingMLGPU() {}
};
NS_IMPL_ISUPPORTS(MemoryReportingMLGPU, nsIMemoryReporter);
void
InitializeMemoryReporters()
{
RegisterStrongMemoryReporter(new MemoryReportingMLGPU());
}
} // namespace mlg
} // namespace layers
} // namespace mozilla

View File

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_gfx_layers_mlgpu_MemoryReportingMLGPU_h
#define mozilla_gfx_layers_mlgpu_MemoryReportingMLGPU_h
#include "mozilla/Atomics.h"
namespace mozilla {
namespace layers {
namespace mlg {
void InitializeMemoryReporters();
extern mozilla::Atomic<size_t> sConstantBufferUsage;
extern mozilla::Atomic<size_t> sVertexBufferUsage;
extern mozilla::Atomic<size_t> sRenderTargetUsage;
} // namespace mlg
} // namespace layers
} // namespace mozilla
#endif // mozilla_gfx_layers_mlgpu_MemoryReportingMLGPU_h

View File

@ -6,6 +6,7 @@
#ifndef mozilla_gfx_layers_mlgpu_StagingBuffer_h
#define mozilla_gfx_layers_mlgpu_StagingBuffer_h
#include "mozilla/MathAlgorithms.h"
#include "mozilla/UniquePtr.h"
#include "UtilityMLGPU.h"
#include <algorithm>

View File

@ -200,6 +200,7 @@ EXPORTS.mozilla.layers += [
'LayersTypes.h',
'mlgpu/LayerManagerMLGPU.h',
'mlgpu/LayerMLGPU.h',
'mlgpu/MemoryReportingMLGPU.h',
'mlgpu/MLGDevice.h',
'mlgpu/MLGDeviceTypes.h',
'mlgpu/ShaderDefinitionsMLGPU.h',
@ -411,6 +412,7 @@ UNIFIED_SOURCES += [
'mlgpu/LayerManagerMLGPU.cpp',
'mlgpu/LayerMLGPU.cpp',
'mlgpu/MaskOperation.cpp',
'mlgpu/MemoryReportingMLGPU.cpp',
'mlgpu/MLGDevice.cpp',
'mlgpu/PaintedLayerMLGPU.cpp',
'mlgpu/RenderPassMLGPU.cpp',

View File

@ -137,6 +137,7 @@ class mozilla::gl::SkiaGLGlue : public GenericAtomicRefCounted {
#include "gfxVR.h"
#include "VRManagerChild.h"
#include "mozilla/gfx/GPUParent.h"
#include "mozilla/layers/MemoryReportingMLGPU.h"
#include "prsystem.h"
namespace mozilla {
@ -797,6 +798,7 @@ gfxPlatform::Init()
}
RegisterStrongMemoryReporter(new GfxMemoryImageReporter());
mlg::InitializeMemoryReporters();
if (XRE_IsParentProcess()) {
if (gfxPlatform::ForceSoftwareVsync()) {