| 1 |
/* |
| 2 |
* Copyright 2021 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef GrThreadSafePipelineBuilder_Base_DEFINED |
| 9 |
#define GrThreadSafePipelineBuilder_Base_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkString.h" // IWYU pragma: keep |
| 13 |
#include "include/core/SkTypes.h" |
| 14 |
#include "include/private/base/SkTArray.h" |
| 15 |
|
| 16 |
#include <atomic> |
| 17 |
|
| 18 |
class GrThreadSafePipelineBuilder : public SkRefCnt { |
| 19 |
public: |
| 20 |
GrThreadSafePipelineBuilder() = default; |
| 21 |
|
| 22 |
class Stats { |
| 23 |
public: |
| 24 |
enum class ProgramCacheResult { |
| 25 |
kHit, // the program was found in the cache |
| 26 |
kMiss, // the program was not found in the cache (and was, thus, compiled) |
| 27 |
kPartial, // a precompiled version was found in the persistent cache |
| 28 |
|
| 29 |
kLast = kPartial |
| 30 |
}; |
| 31 |
|
| 32 |
#if GR_GPU_STATS |
| 33 |
static const int kNumProgramCacheResults = (int)ProgramCacheResult::kLast + 1; |
| 34 |
|
| 35 |
Stats() = default; |
| 36 |
|
| 37 |
int shaderCompilations() const { return fShaderCompilations; } |
| 38 |
void incShaderCompilations() { fShaderCompilations++; } |
| 39 |
|
| 40 |
int numInlineCompilationFailures() const { return fNumInlineCompilationFailures; } |
| 41 |
void incNumInlineCompilationFailures() { ++fNumInlineCompilationFailures; } |
| 42 |
|
| 43 |
int numInlineProgramCacheResult(ProgramCacheResult stat) const { |
| 44 |
return fInlineProgramCacheStats[(int) stat]; |
| 45 |
} |
| 46 |
void incNumInlineProgramCacheResult(ProgramCacheResult stat) { |
| 47 |
++fInlineProgramCacheStats[(int) stat]; |
| 48 |
} |
| 49 |
|
| 50 |
int numPreCompilationFailures() const { return fNumPreCompilationFailures; } |
| 51 |
void incNumPreCompilationFailures() { ++fNumPreCompilationFailures; } |
| 52 |
|
| 53 |
int numPreProgramCacheResult(ProgramCacheResult stat) const { |
| 54 |
return fPreProgramCacheStats[(int) stat]; |
| 55 |
} |
| 56 |
void incNumPreProgramCacheResult(ProgramCacheResult stat) { |
| 57 |
++fPreProgramCacheStats[(int) stat]; |
| 58 |
} |
| 59 |
|
| 60 |
int numCompilationFailures() const { return fNumCompilationFailures; } |
| 61 |
void incNumCompilationFailures() { ++fNumCompilationFailures; } |
| 62 |
|
| 63 |
int numPartialCompilationSuccesses() const { return fNumPartialCompilationSuccesses; } |
| 64 |
void incNumPartialCompilationSuccesses() { ++fNumPartialCompilationSuccesses; } |
| 65 |
|
| 66 |
int numCompilationSuccesses() const { return fNumCompilationSuccesses; } |
| 67 |
void incNumCompilationSuccesses() { ++fNumCompilationSuccesses; } |
| 68 |
|
| 69 |
#if defined(GPU_TEST_UTILS) |
| 70 |
void dump(SkString*); |
| 71 |
void dumpKeyValuePairs(skia_private::TArray<SkString>* keys, skia_private::TArray<double>* values); |
| 72 |
#endif |
| 73 |
|
| 74 |
private: |
| 75 |
std::atomic<int> fShaderCompilations{0}; |
| 76 |
|
| 77 |
std::atomic<int> fNumInlineCompilationFailures{0}; |
| 78 |
std::atomic<int> fInlineProgramCacheStats[kNumProgramCacheResults]{}; |
| 79 |
|
| 80 |
std::atomic<int> fNumPreCompilationFailures{0}; |
| 81 |
std::atomic<int> fPreProgramCacheStats[kNumProgramCacheResults]{}; |
| 82 |
|
| 83 |
std::atomic<int> fNumCompilationFailures{0}; |
| 84 |
std::atomic<int> fNumPartialCompilationSuccesses{0}; |
| 85 |
std::atomic<int> fNumCompilationSuccesses{0}; |
| 86 |
|
| 87 |
#else |
| 88 |
void incShaderCompilations() {} |
| 89 |
void incNumInlineCompilationFailures() {} |
| 90 |
void incNumInlineProgramCacheResult(ProgramCacheResult stat) {} |
| 91 |
void incNumPreCompilationFailures() {} |
| 92 |
void incNumPreProgramCacheResult(ProgramCacheResult stat) {} |
| 93 |
void incNumCompilationFailures() {} |
| 94 |
void incNumPartialCompilationSuccesses() {} |
| 95 |
void incNumCompilationSuccesses() {} |
| 96 |
|
| 97 |
#if defined(GPU_TEST_UTILS) |
| 98 |
void dump(SkString*) {} |
| 99 |
void dumpKeyValuePairs(skia_private::TArray<SkString>*, skia_private::TArray<double>*) {} |
| 100 |
#endif |
| 101 |
|
| 102 |
#endif // GR_GPU_STATS |
| 103 |
}; |
| 104 |
|
| 105 |
Stats* stats() { return &fStats; } |
| 106 |
|
| 107 |
protected: |
| 108 |
Stats fStats; |
| 109 |
}; |
| 110 |
|
| 111 |
#endif |