Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 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/gpu/GrConfig.h" |
| 13 | |
| 14 | #if GR_TEST_UTILS |
| 15 | #include "include/private/SkTArray.h" |
| 16 | class SkString; |
| 17 | #endif |
| 18 | |
| 19 | class GrThreadSafePipelineBuilder : public SkRefCnt { |
| 20 | public: |
| 21 | GrThreadSafePipelineBuilder() = default; |
| 22 | |
| 23 | class Stats { |
| 24 | public: |
| 25 | enum class ProgramCacheResult { |
| 26 | kHit, // the program was found in the cache |
| 27 | kMiss, // the program was not found in the cache (and was, thus, compiled) |
| 28 | kPartial, // a precompiled version was found in the persistent cache |
| 29 | |
| 30 | kLast = kPartial |
| 31 | }; |
| 32 | |
| 33 | #if GR_GPU_STATS |
| 34 | static const int kNumProgramCacheResults = (int)ProgramCacheResult::kLast + 1; |
| 35 | |
| 36 | Stats() = default; |
| 37 | |
| 38 | int shaderCompilations() const { return fShaderCompilations; } |
| 39 | void incShaderCompilations() { fShaderCompilations++; } |
| 40 | |
| 41 | int numInlineCompilationFailures() const { return fNumInlineCompilationFailures; } |
| 42 | void incNumInlineCompilationFailures() { ++fNumInlineCompilationFailures; } |
| 43 | |
| 44 | int numInlineProgramCacheResult(ProgramCacheResult stat) const { |
| 45 | return fInlineProgramCacheStats[(int) stat]; |
| 46 | } |
| 47 | void incNumInlineProgramCacheResult(ProgramCacheResult stat) { |
| 48 | ++fInlineProgramCacheStats[(int) stat]; |
| 49 | } |
| 50 | |
| 51 | int numPreCompilationFailures() const { return fNumPreCompilationFailures; } |
| 52 | void incNumPreCompilationFailures() { ++fNumPreCompilationFailures; } |
| 53 | |
| 54 | int numPreProgramCacheResult(ProgramCacheResult stat) const { |
| 55 | return fPreProgramCacheStats[(int) stat]; |
| 56 | } |
| 57 | void incNumPreProgramCacheResult(ProgramCacheResult stat) { |
| 58 | ++fPreProgramCacheStats[(int) stat]; |
| 59 | } |
| 60 | |
| 61 | int numCompilationFailures() const { return fNumCompilationFailures; } |
| 62 | void incNumCompilationFailures() { ++fNumCompilationFailures; } |
| 63 | |
| 64 | int numPartialCompilationSuccesses() const { return fNumPartialCompilationSuccesses; } |
| 65 | void incNumPartialCompilationSuccesses() { ++fNumPartialCompilationSuccesses; } |
| 66 | |
| 67 | int numCompilationSuccesses() const { return fNumCompilationSuccesses; } |
| 68 | void incNumCompilationSuccesses() { ++fNumCompilationSuccesses; } |
| 69 | |
| 70 | #if GR_TEST_UTILS |
| 71 | void dump(SkString*); |
| 72 | void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); |
| 73 | #endif |
| 74 | |
| 75 | private: |
| 76 | std::atomic<int> fShaderCompilations{0}; |
| 77 | |
| 78 | std::atomic<int> fNumInlineCompilationFailures{0}; |
| 79 | std::atomic<int> fInlineProgramCacheStats[kNumProgramCacheResults]{0}; |
| 80 | |
| 81 | std::atomic<int> fNumPreCompilationFailures{0}; |
| 82 | std::atomic<int> fPreProgramCacheStats[kNumProgramCacheResults]{0}; |
| 83 | |
| 84 | std::atomic<int> fNumCompilationFailures{0}; |
| 85 | std::atomic<int> fNumPartialCompilationSuccesses{0}; |
| 86 | std::atomic<int> fNumCompilationSuccesses{0}; |
| 87 | |
| 88 | #else |
| 89 | void incShaderCompilations() {} |
| 90 | void incNumInlineCompilationFailures() {} |
| 91 | void incNumInlineProgramCacheResult(ProgramCacheResult stat) {} |
| 92 | void incNumPreCompilationFailures() {} |
| 93 | void incNumPreProgramCacheResult(ProgramCacheResult stat) {} |
| 94 | void incNumCompilationFailures() {} |
| 95 | void incNumPartialCompilationSuccesses() {} |
| 96 | void incNumCompilationSuccesses() {} |
| 97 | |
| 98 | #if GR_TEST_UTILS |
| 99 | void dump(SkString*) {} |
| 100 | void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} |
| 101 | #endif |
| 102 | |
| 103 | #endif // GR_GPU_STATS |
| 104 | }; |
| 105 | |
| 106 | Stats* stats() { return &fStats; } |
| 107 | |
| 108 | protected: |
| 109 | Stats fStats; |
| 110 | }; |
| 111 | |
| 112 | #endif |