From 94d8f1ed6116780346ffa39ed683f1977786434a Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Wed, 18 Dec 2013 17:25:33 +0000 Subject: [PATCH] Update bench pictures to time image decode & upload costs https://codereview.chromium.org/117583002/ git-svn-id: http://skia.googlecode.com/svn/trunk@12742 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gyp/tools.gyp | 3 +++ include/gpu/GrContext.h | 7 +++++++ src/gpu/GrTest.cpp | 5 +++++ tools/PictureBenchmark.cpp | 20 +++++++++++++++++++- tools/PictureBenchmark.h | 5 ++++- tools/PictureRenderer.cpp | 20 ++++++++++++++++++++ tools/PictureRenderer.h | 6 ++++++ tools/bench_pictures_main.cpp | 4 ++++ 8 files changed, 68 insertions(+), 2 deletions(-) diff --git a/gyp/tools.gyp b/gyp/tools.gyp index fd381b7..f748157 100644 --- a/gyp/tools.gyp +++ b/gyp/tools.gyp @@ -287,6 +287,9 @@ 'include_dirs' : [ '../src/gpu', ], + 'dependencies': [ + 'gputest.gyp:skgputest', + ], }, ], ], diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 1770fa6..ad3789b 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -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. */ diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index 934f089..c434322 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -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(); +} diff --git a/tools/PictureBenchmark.cpp b/tools/PictureBenchmark.cpp index f441c37..65f3660 100644 --- a/tools/PictureBenchmark.cpp +++ b/tools/PictureBenchmark.cpp @@ -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(" "); + } configName.append(" "); 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(" "); + } // Beware - since the per-run-timer doesn't ever include a glFinish it can // report a lower time then the long-running-timer diff --git a/tools/PictureBenchmark.h b/tools/PictureBenchmark.h index 1f01ce5..e9d9f65 100644 --- a/tools/PictureBenchmark.h +++ b/tools/PictureBenchmark.h @@ -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[]); diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index 54d4633..4856dd2 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -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) | diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 6d886ab..a22e0b7 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -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) { diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp index 1f3b0c0..5829e18 100644 --- a/tools/bench_pictures_main.cpp +++ b/tools/bench_pictures_main.cpp @@ -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); -- 2.7.4