reset shader compilations for stats

BUG=skia:

Review URL: https://codereview.chromium.org/1491823003
This commit is contained in:
joshualitt 2015-12-02 13:36:47 -08:00 committed by Commit bot
parent fa498fe122
commit 8fd844f38e
5 changed files with 30 additions and 1 deletions

View 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

View 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.

View 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,

View 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&);

View 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 {