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