reset shader compilations for stats
authorjoshualitt <joshualitt@chromium.org>
Wed, 2 Dec 2015 21:36:47 +0000 (13:36 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 2 Dec 2015 21:36:47 +0000 (13:36 -0800)
BUG=skia:

Review URL: https://codereview.chromium.org/1491823003

bench/SKPBench.cpp
src/gpu/GrGpu.h
src/gpu/gl/GrGLGpu.cpp
src/gpu/gl/GrGLGpu.h
src/gpu/gl/GrGLGpuProgramCache.cpp

index c5480904053dbfd98cce060e1860f3bc366f3e61..6f4c688d231ff61c0de6ddad82537a2c6496dc4a 100644 (file)
@@ -157,6 +157,7 @@ void SKPBench::drawPicture() {
 }
 
 #if SK_SUPPORT_GPU
+#include "GrGpu.h"
 static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture,
                                SkTArray<SkString>* keys, SkTArray<double>* values,
                                const char* tag) {
@@ -186,6 +187,7 @@ void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray<SkString>* keys, SkTArray<
     context->flush();
     context->freeGpuResources();
     context->resetContext();
+    context->getGpu()->resetShaderCacheForTesting();
     draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame");
 
     // draw second frame
index beeb01aced79d1caf4c7e66e72005b03998ca4f2..9c36d0555f9f1477b1b2fb860ac52f125efffcf6 100644 (file)
@@ -414,6 +414,9 @@ public:
     // This is only to be used in GL-specific tests.
     virtual const GrGLContext* glContextForTesting() const { return nullptr; }
 
+    // This is only to be used by testing code
+    virtual void resetShaderCacheForTesting() const {}
+
 protected:
     // Functions used to map clip-respecting stencil tests into normal
     // stencil funcs supported by GPUs.
index 58f69be87c5820460498ffcbc2f5673417036ec3..99fddbf27c5fd8891e87af6702f70050991b7207 100644 (file)
@@ -3384,6 +3384,10 @@ void GrGLGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTe
 #endif
 }
 
+void GrGLGpu::resetShaderCacheForTesting() const {
+    fProgramCache->abandon();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw(
                                                 GrGLGpu* gpu,
index c2431c764aabffbcafe6b44eebeeb638d96a4c56..6ec3881b893d3e47826aedbf0cc0d8b1a5007eb1 100644 (file)
@@ -129,6 +129,8 @@ public:
     bool isTestingOnlyBackendTexture(GrBackendObject) const override;
     void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) const override;
 
+    void resetShaderCacheForTesting() const override;
+
 private:
     GrGLGpu(GrGLContext* ctx, GrContext* context);
 
@@ -215,6 +217,7 @@ private:
         ProgramCache(GrGLGpu* gpu);
         ~ProgramCache();
 
+        void reset();
         void abandon();
         GrGLProgram* refProgram(const DrawArgs&);
 
index d5f2b9d23daa36af1bcd30ccaae987c69f840b02..df8cf60c7b3cf0d04298f61fe9c5e80c1bf1fe69 100644 (file)
@@ -77,13 +77,30 @@ GrGLGpu::ProgramCache::~ProgramCache() {
 #endif
 }
 
-void GrGLGpu::ProgramCache::abandon() {
+void GrGLGpu::ProgramCache::reset() {
     for (int i = 0; i < fCount; ++i) {
         SkASSERT(fEntries[i]->fProgram.get());
         fEntries[i]->fProgram->abandon();
         delete fEntries[i];
+        fEntries[i] = nullptr;
     }
     fCount = 0;
+
+    // zero out hash table
+    for (int i = 0; i < 1 << kHashBits; i++) {
+        fHashTable[i] = nullptr;
+    }
+
+    fCurrLRUStamp = 0;
+#ifdef PROGRAM_CACHE_STATS
+    fTotalRequests = 0;
+    fCacheMisses = 0;
+    fHashMisses = 0;
+#endif
+}
+
+void GrGLGpu::ProgramCache::abandon() {
+    this->reset();
 }
 
 int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const {