From 8fd844f38ed46eaac78bb187623ffcc40b592707 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Wed, 2 Dec 2015 13:36:47 -0800 Subject: [PATCH] reset shader compilations for stats BUG=skia: Review URL: https://codereview.chromium.org/1491823003 --- bench/SKPBench.cpp | 2 ++ src/gpu/GrGpu.h | 3 +++ src/gpu/gl/GrGLGpu.cpp | 4 ++++ src/gpu/gl/GrGLGpu.h | 3 +++ src/gpu/gl/GrGLGpuProgramCache.cpp | 19 ++++++++++++++++++- 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp index c548090405..6f4c688d23 100644 --- a/bench/SKPBench.cpp +++ b/bench/SKPBench.cpp @@ -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* keys, SkTArray* values, const char* tag) { @@ -186,6 +187,7 @@ void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray* 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 diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index beeb01aced..9c36d0555f 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -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. diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 58f69be87c..99fddbf27c 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -3384,6 +3384,10 @@ void GrGLGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTe #endif } +void GrGLGpu::resetShaderCacheForTesting() const { + fProgramCache->abandon(); +} + /////////////////////////////////////////////////////////////////////////////// GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw( GrGLGpu* gpu, diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index c2431c764a..6ec3881b89 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -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&); diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp index d5f2b9d23d..df8cf60c7b 100644 --- a/src/gpu/gl/GrGLGpuProgramCache.cpp +++ b/src/gpu/gl/GrGLGpuProgramCache.cpp @@ -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 { -- 2.34.1