Bug 1506492 - Report WebRender swap-chain memory usage. r=bholley
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 13 Nov 2018 03:15:51 +0000
changeset 502419 8105dec7146e2fdba5c88ba65721c2ff51574fef
parent 502418 c007a3321fe075a21c64b56d82f2cd2346039bcf
child 502420 867aaeefa9adf5e160b198d6ea55b1d2c3c02aa3
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1506492
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506492 - Report WebRender swap-chain memory usage. r=bholley Differential Revision: https://phabricator.services.mozilla.com/D11594
gfx/thebes/gfxPlatform.cpp
gfx/webrender_bindings/RenderThread.cpp
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/RendererOGL.h
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -742,16 +742,17 @@ WebRenderMemoryReporter::CollectReports(
       helper.Report(aReport.rasterized_blobs, "resource-cache/rasterized-blobs");
 
       // GPU Memory.
       helper.ReportTexture(aReport.gpu_cache_textures, "gpu-cache");
       helper.ReportTexture(aReport.vertex_data_textures, "vertex-data");
       helper.ReportTexture(aReport.render_target_textures, "render-targets");
       helper.ReportTexture(aReport.texture_cache_textures, "texture-cache");
       helper.ReportTexture(aReport.depth_target_textures, "depth-targets");
+      helper.ReportTexture(aReport.swap_chain, "swap-chains");
 
       // Total GPU bytes, for sanity-checking the above.
       helper.ReportTotalGPUBytes(aReport.total_gpu_bytes_allocated);
 
       FinishAsyncMemoryReport();
     },
     [](mozilla::ipc::ResponseRejectReason aReason) {
       FinishAsyncMemoryReport();
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -142,23 +142,24 @@ RenderThread::IsInRenderThread()
 {
   return sRenderThread && sRenderThread->mThread->thread_id() == PlatformThread::CurrentId();
 }
 
 void
 RenderThread::DoAccumulateMemoryReport(MemoryReport aReport, const RefPtr<MemoryReportPromise::Private>& aPromise)
 {
   MOZ_ASSERT(IsInRenderThread());
+  MOZ_ASSERT(aReport.total_gpu_bytes_allocated == 0);
+
   for (auto& r: mRenderers) {
-    wr_renderer_accumulate_memory_report(r.second->GetRenderer(), &aReport);
+    r.second->AccumulateMemoryReport(&aReport);
   }
 
   // Note total gpu bytes allocated across all WR instances.
-  MOZ_ASSERT(aReport.total_gpu_bytes_allocated == 0);
-  aReport.total_gpu_bytes_allocated = wr_total_gpu_bytes_allocated();
+  aReport.total_gpu_bytes_allocated += wr_total_gpu_bytes_allocated();
 
   aPromise->Resolve(aReport, __func__);
 }
 
 // static
 RefPtr<MemoryReportPromise>
 RenderThread::AccumulateMemoryReport(MemoryReport aInitial)
 {
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -3,16 +3,17 @@
 /* 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 "RendererOGL.h"
 #include "GLContext.h"
 #include "mozilla/gfx/Logging.h"
 #include "mozilla/gfx/gfxVars.h"
+#include "mozilla/gfx/Types.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/webrender/RenderCompositor.h"
 #include "mozilla/webrender/RenderTextureHost.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 namespace mozilla {
@@ -243,16 +244,32 @@ RendererOGL::FlushPipelineInfo()
 }
 
 RenderTextureHost*
 RendererOGL::GetRenderTexture(wr::WrExternalImageId aExternalImageId)
 {
   return mThread->GetRenderTexture(aExternalImageId);
 }
 
+void
+RendererOGL::AccumulateMemoryReport(MemoryReport* aReport)
+{
+  wr_renderer_accumulate_memory_report(GetRenderer(), aReport);
+
+  LayoutDeviceIntSize size = mCompositor->GetBufferSize();
+
+  // Assume BGRA8 for the format since it's not exposed anywhere,
+  // and all compositor backends should be using that.
+  uintptr_t swapChainSize = size.width * size.height * 
+                            BytesPerPixel(SurfaceFormat::B8G8R8A8) *
+                            (mCompositor->UseTripleBuffering() ? 3 : 2);
+  aReport->swap_chain += swapChainSize;
+  aReport->total_gpu_bytes_allocated += swapChainSize;
+}
+
 static void
 DoNotifyWebRenderError(layers::CompositorBridgeParent* aBridge, WebRenderError aError)
 {
   aBridge->NotifyWebRenderError(aError);
 }
 
 void
 RendererOGL::NotifyWebRenderError(WebRenderError aError)
--- a/gfx/webrender_bindings/RendererOGL.h
+++ b/gfx/webrender_bindings/RendererOGL.h
@@ -90,16 +90,18 @@ public:
   layers::SyncObjectHost* GetSyncObject() const;
 
   layers::CompositorBridgeParent* GetCompositorBridge() { return mBridge; }
 
   RefPtr<WebRenderPipelineInfo> FlushPipelineInfo();
 
   RenderTextureHost* GetRenderTexture(wr::WrExternalImageId aExternalImageId);
 
+  void AccumulateMemoryReport(MemoryReport* aReport);
+
   wr::Renderer* GetRenderer() { return mRenderer; }
 
   gl::GLContext* gl() const;
 
 protected:
   void NotifyWebRenderError(WebRenderError aError);
 
   RefPtr<RenderThread> mThread;