• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
shaderCompilations()38         int shaderCompilations() const { return fShaderCompilations; }
incShaderCompilations()39         void incShaderCompilations() { fShaderCompilations++; }
40 
numInlineCompilationFailures()41         int numInlineCompilationFailures() const { return fNumInlineCompilationFailures; }
incNumInlineCompilationFailures()42         void incNumInlineCompilationFailures() { ++fNumInlineCompilationFailures; }
43 
numInlineProgramCacheResult(ProgramCacheResult stat)44         int numInlineProgramCacheResult(ProgramCacheResult stat) const {
45             return fInlineProgramCacheStats[(int) stat];
46         }
incNumInlineProgramCacheResult(ProgramCacheResult stat)47         void incNumInlineProgramCacheResult(ProgramCacheResult stat) {
48             ++fInlineProgramCacheStats[(int) stat];
49         }
50 
numPreCompilationFailures()51         int numPreCompilationFailures() const { return fNumPreCompilationFailures; }
incNumPreCompilationFailures()52         void incNumPreCompilationFailures() { ++fNumPreCompilationFailures; }
53 
numPreProgramCacheResult(ProgramCacheResult stat)54         int numPreProgramCacheResult(ProgramCacheResult stat) const {
55             return fPreProgramCacheStats[(int) stat];
56         }
incNumPreProgramCacheResult(ProgramCacheResult stat)57         void incNumPreProgramCacheResult(ProgramCacheResult stat) {
58             ++fPreProgramCacheStats[(int) stat];
59         }
60 
numCompilationFailures()61         int numCompilationFailures() const { return fNumCompilationFailures; }
incNumCompilationFailures()62         void incNumCompilationFailures() { ++fNumCompilationFailures; }
63 
numPartialCompilationSuccesses()64         int numPartialCompilationSuccesses() const { return fNumPartialCompilationSuccesses; }
incNumPartialCompilationSuccesses()65         void incNumPartialCompilationSuccesses() { ++fNumPartialCompilationSuccesses; }
66 
numCompilationSuccesses()67         int numCompilationSuccesses() const { return fNumCompilationSuccesses; }
incNumCompilationSuccesses()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
incShaderCompilations()89         void incShaderCompilations() {}
incNumInlineCompilationFailures()90         void incNumInlineCompilationFailures() {}
incNumInlineProgramCacheResult(ProgramCacheResult stat)91         void incNumInlineProgramCacheResult(ProgramCacheResult stat) {}
incNumPreCompilationFailures()92         void incNumPreCompilationFailures() {}
incNumPreProgramCacheResult(ProgramCacheResult stat)93         void incNumPreProgramCacheResult(ProgramCacheResult stat) {}
incNumCompilationFailures()94         void incNumCompilationFailures() {}
incNumPartialCompilationSuccesses()95         void incNumPartialCompilationSuccesses() {}
incNumCompilationSuccesses()96         void incNumCompilationSuccesses() {}
97 
98 #if GR_TEST_UTILS
dump(SkString *)99         void dump(SkString*) {}
dumpKeyValuePairs(SkTArray<SkString> *,SkTArray<double> *)100         void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {}
101 #endif
102 
103 #endif // GR_GPU_STATS
104     };
105 
stats()106     Stats* stats() { return &fStats; }
107 
108 protected:
109     Stats fStats;
110 };
111 
112 #endif
113