Add texture create/upload stats and make nanobench have explicit gpu stats flag
authorbsalomon <bsalomon@google.com>
Tue, 3 Feb 2015 05:19:50 +0000 (21:19 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 3 Feb 2015 05:19:50 +0000 (21:19 -0800)
Review URL: https://codereview.chromium.org/891973002

bench/nanobench.cpp
src/gpu/GrGpu.cpp
src/gpu/GrGpu.h
src/gpu/GrTest.cpp

index 8d00ca1..eb48ec2 100644 (file)
@@ -75,6 +75,7 @@ DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
 DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
+DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
 
 static SkString humanize(double ms) {
     if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
@@ -766,10 +767,11 @@ int nanobench_main() {
                         , bench->getUniqueName()
                         );
             }
-#if SK_SUPPORT_GPU && GR_CACHE_STATS
-            if (FLAGS_veryVerbose &&
+#if SK_SUPPORT_GPU
+            if (FLAGS_gpuStats &&
                 Benchmark::kGPU_Backend == targets[j]->config.backend) {
                 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
+                gGrFactory->get(targets[j]->config.ctxType)->printGpuStats();
             }
 #endif
         }
index 1566aab..67637e7 100644 (file)
@@ -74,6 +74,12 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
     if (!this->caps()->reuseScratchTextures() && !isRT) {
         tex->cacheAccess().removeScratchKey();
     }
+    if (tex) {
+        fStats.incTextureCreates();
+        if (srcData) {
+            fStats.incTextureUploads();
+        }
+    }
     return tex;
 }
 
@@ -203,8 +209,12 @@ bool GrGpu::writeTexturePixels(GrTexture* texture,
                                GrPixelConfig config, const void* buffer,
                                size_t rowBytes) {
     this->handleDirtyContext();
-    return this->onWriteTexturePixels(texture, left, top, width, height,
-                                      config, buffer, rowBytes);
+    if (this->onWriteTexturePixels(texture, left, top, width, height,
+                                   config, buffer, rowBytes)) {
+        fStats.incTextureUploads();
+        return true;
+    }
+    return false;
 }
 
 void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
index c989589..8c458f1 100644 (file)
@@ -369,21 +369,34 @@ public:
 #if GR_GPU_STATS
         Stats() { this->reset(); }
 
-        void reset() { fRenderTargetBinds = 0; fShaderCompilations = 0; }
+        void reset() {
+            fRenderTargetBinds = 0;
+            fShaderCompilations = 0;
+            fTextureCreates = 0;
+            fTextureUploads = 0;
+        }
 
         int renderTargetBinds() const { return fRenderTargetBinds; }
         void incRenderTargetBinds() { fRenderTargetBinds++; }
         int shaderCompilations() const { return fShaderCompilations; }
         void incShaderCompilations() { fShaderCompilations++; }
+        int textureCreates() const { return fTextureCreates; }
+        void incTextureCreates() { fTextureCreates++; }
+        int textureUploads() const { return fTextureUploads; }
+        void incTextureUploads() { fTextureUploads++; }
         void dump(SkString*);
 
     private:
         int fRenderTargetBinds;
         int fShaderCompilations;
+        int fTextureCreates;
+        int fTextureUploads;
 #else
         void dump(SkString*) {};
         void incRenderTargetBinds() {}
         void incShaderCompilations() {}
+        void incTextureCreates() {}
+        void incTextureUploads() {}
 #endif
     };
 
index 1689070..05a4a5f 100644 (file)
@@ -69,6 +69,8 @@ void GrContext::printGpuStats() const {
 void GrGpu::Stats::dump(SkString* out) {
     out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
     out->appendf("Shader Compilations: %d\n", fShaderCompilations);
+    out->appendf("Textures Created: %d\n", fTextureCreates);
+    out->appendf("Texture Uploads: %d\n", fTextureUploads);
 }
 #endif