Update bench pictures to time image decode & upload costs
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Dec 2013 17:25:33 +0000 (17:25 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Dec 2013 17:25:33 +0000 (17:25 +0000)
https://codereview.chromium.org/117583002/

git-svn-id: http://skia.googlecode.com/svn/trunk@12742 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/tools.gyp
include/gpu/GrContext.h
src/gpu/GrTest.cpp
tools/PictureBenchmark.cpp
tools/PictureBenchmark.h
tools/PictureRenderer.cpp
tools/PictureRenderer.h
tools/bench_pictures_main.cpp

index fd381b7..f748157 100644 (file)
             'include_dirs' : [
               '../src/gpu',
             ],
+            'dependencies': [
+              'gputest.gyp:skgputest',
+            ],
           },
         ],
       ],
index 1770fa6..ad3789b 100644 (file)
@@ -210,6 +210,13 @@ public:
     void purgeCache();
 
     /**
+     * Purge all the unlocked resources from the cache.
+     * This entry point is mainly meant for timing texture uploads
+     * and is not defined in normal builds of Skia.
+     */
+    void purgeAllUnlockedResources();
+
+    /**
      * Creates a texture that is outside the cache. Does not count against
      * cache's budget.
      */
index 934f089..c434322 100644 (file)
@@ -9,6 +9,7 @@
 #include "GrTest.h"
 
 #include "GrGpu.h"
+#include "GrResourceCache.h"
 
 void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) {
     SkASSERT(!fContext);
@@ -35,3 +36,7 @@ void GrContext::getTestTarget(GrTestTarget* tar) {
 void GrContext::setMaxTextureSizeOverride(int maxTextureSizeOverride) {
     fMaxTextureSizeOverride = maxTextureSizeOverride;
 }
+
+void GrContext::purgeAllUnlockedResources() {
+    fTextureCache->purgeAllUnlocked();
+}
index f441c37..65f3660 100644 (file)
@@ -22,6 +22,7 @@ PictureBenchmark::PictureBenchmark()
 , fTimerResult(TimerData::kAvg_Result)
 , fTimerTypes(0)
 , fTimeIndividualTiles(false)
+, fPurgeDecodedTex(false)
 {}
 
 PictureBenchmark::~PictureBenchmark() {
@@ -79,6 +80,10 @@ void PictureBenchmark::run(SkPicture* pict) {
     fRenderer->render(NULL);
     fRenderer->resetState(true);
 
+    if (fPurgeDecodedTex) {
+        fRenderer->purgeTextures();
+    }
+
     bool usingGpu = false;
 #if SK_SUPPORT_GPU
     usingGpu = fRenderer->isUsingGpuDevice();
@@ -140,6 +145,10 @@ void PictureBenchmark::run(SkPicture* pict) {
                 tiledRenderer->resetState(false);
                 perTileTimer->end();
                 SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get()));
+
+                if (fPurgeDecodedTex) {
+                    fRenderer->purgeTextures();
+                }
             }
             longRunningTimer->truncatedEnd();
             tiledRenderer->resetState(true);
@@ -160,7 +169,9 @@ void PictureBenchmark::run(SkPicture* pict) {
 #if 0
             this->logProgress(result.c_str());
 #endif
-
+            if (fPurgeDecodedTex) {
+                configName.append(" <withPurging>");
+            }
             configName.append(" <averaged>");
             SkString longRunningResult = longRunningTimerData.getResult(
                 tiledRenderer->getNormalTimeFormat().c_str(),
@@ -186,6 +197,10 @@ void PictureBenchmark::run(SkPicture* pict) {
             perRunTimer->end();
 
             SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get()));
+
+            if (fPurgeDecodedTex) {
+                fRenderer->purgeTextures();
+            }
         }
         longRunningTimer->truncatedEnd();
         fRenderer->resetState(true);
@@ -193,6 +208,9 @@ void PictureBenchmark::run(SkPicture* pict) {
         SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get()));
 
         SkString configName = fRenderer->getConfigName();
+        if (fPurgeDecodedTex) {
+            configName.append(" <withPurging>");
+        }
 
         // Beware - since the per-run-timer doesn't ever include a glFinish it can
         // report a lower time then the long-running-timer
index 1f01ce5..e9d9f65 100644 (file)
@@ -41,8 +41,10 @@ public:
      * TiledPictureRenderer.
      */
     void setTimeIndividualTiles(bool indiv) { fTimeIndividualTiles = indiv; }
+    bool timeIndividualTiles() const { return fTimeIndividualTiles; }
 
-    bool timeIndividualTiles() { return fTimeIndividualTiles; }
+    void setPurgeDecodedTex(bool purgeDecodedTex) { fPurgeDecodedTex = purgeDecodedTex; }
+    bool purgeDecodedText() const { return fPurgeDecodedTex; }
 
     PictureRenderer* setRenderer(PictureRenderer*);
 
@@ -59,6 +61,7 @@ private:
     TimerData::Result fTimerResult;
     uint32_t          fTimerTypes; // bitfield of TimerData::TimerFlags values
     bool              fTimeIndividualTiles;
+    bool              fPurgeDecodedTex;
 
     void logProgress(const char msg[]);
 
index 54d4633..4856dd2 100644 (file)
@@ -12,6 +12,7 @@
 #include "SkCanvas.h"
 #include "SkData.h"
 #include "SkDevice.h"
+#include "SkDiscardableMemoryPool.h"
 #include "SkGPipe.h"
 #if SK_SUPPORT_GPU
 #include "gl/GrGLDefines.h"
@@ -246,6 +247,25 @@ void PictureRenderer::resetState(bool callFinish) {
 #endif
 }
 
+void PictureRenderer::purgeTextures() {
+    SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
+
+    pool->dumpPool();
+
+#if SK_SUPPORT_GPU
+    SkGLContextHelper* glContext = this->getGLContext();
+    if (NULL == glContext) {
+        SkASSERT(kBitmap_DeviceType == fDeviceType);
+        return;
+    }
+
+    // resetState should've already done this
+    fGrContext->flush();
+
+    fGrContext->purgeAllUnlockedResources();
+#endif
+}
+
 uint32_t PictureRenderer::recordFlags() {
     return ((kNone_BBoxHierarchyType == fBBoxHierarchyType) ? 0 :
         SkPicture::kOptimizeForClippedPlayback_RecordingFlag) |
index 6d886ab..a22e0b7 100644 (file)
@@ -148,6 +148,12 @@ public:
     void resetState(bool callFinish);
 
     /**
+     * Remove all decoded textures from the CPU caches and all uploaded textures
+     * from the GPU.
+     */
+    void purgeTextures();
+
+    /**
      * Set the backend type. Returns true on success and false on failure.
      */
     bool setDeviceType(SkDeviceTypes deviceType) {
index 1f3b0c0..5829e18 100644 (file)
@@ -41,6 +41,8 @@ DECLARE_string(readPath);
 DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
 DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than "
             "times for drawing the whole page. Requires tiled rendering.");
+DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures "
+            "after each iteration.");
 DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
               " for each picture.");
 DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
@@ -338,6 +340,8 @@ static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
         benchmark->setTimeIndividualTiles(true);
     }
 
+    benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
+
     if (FLAGS_readPath.count() < 1) {
         gLogger.logError(".skp files or directories are required.\n");
         exit(-1);