OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Benchmark.h" | 9 #include "Benchmark.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 | 12 |
13 #include "GrGpuResource.h" | 13 #include "GrGpuResource.h" |
14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
15 #include "GrContext.h" | 15 #include "GrContext.h" |
16 #include "GrGpu.h" | 16 #include "GrGpu.h" |
17 #include "GrResourceCache.h" | 17 #include "GrResourceCache.h" |
18 #include "SkCanvas.h" | 18 #include "SkCanvas.h" |
19 | 19 |
20 enum { | 20 enum { |
21 CACHE_SIZE_COUNT = 4096, | 21 CACHE_SIZE_COUNT = 4096, |
22 }; | 22 }; |
23 | 23 |
24 class BenchResource : public GrGpuResource { | 24 class BenchResource : public GrGpuResource { |
25 public: | 25 public: |
26 SK_DECLARE_INST_COUNT(BenchResource); | 26 SK_DECLARE_INST_COUNT(BenchResource); |
27 BenchResource (GrGpu* gpu) | 27 BenchResource (GrGpu* gpu, int keyData32Count) |
28 : INHERITED(gpu, kCached_LifeCycle) { | 28 : INHERITED(gpu, kCached_LifeCycle) |
29 , fKeyData32Count(keyData32Count) { | |
29 this->registerWithCache(); | 30 this->registerWithCache(); |
30 } | 31 } |
31 | 32 |
32 static void ComputeKey(int i, GrUniqueKey* key) { | 33 static void ComputeKey(int i, int keyData32Count, GrUniqueKey* key) { |
33 static GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 34 static GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
34 GrUniqueKey::Builder builder(key, kDomain, 1); | 35 GrUniqueKey::Builder builder(key, kDomain, keyData32Count); |
35 builder[0] = i; | 36 for (int j = 0; j < keyData32Count; ++j) { |
37 builder[j] = i + j; | |
38 } | |
36 } | 39 } |
37 | 40 |
38 private: | 41 private: |
39 size_t onGpuMemorySize() const override { return 100; } | 42 size_t onGpuMemorySize() const override { return 100; } |
40 | 43 int fKeyData32Count; |
41 typedef GrGpuResource INHERITED; | 44 typedef GrGpuResource INHERITED; |
42 }; | 45 }; |
43 | 46 |
44 static void populate_cache(GrGpu* gpu, int resourceCount) { | 47 static void populate_cache(GrGpu* gpu, int resourceCount, int keyData32Count) { |
45 for (int i = 0; i < resourceCount; ++i) { | 48 for (int i = 0; i < resourceCount; ++i) { |
46 GrUniqueKey key; | 49 GrUniqueKey key; |
47 BenchResource::ComputeKey(i, &key); | 50 BenchResource::ComputeKey(i, keyData32Count, &key); |
48 GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu)); | 51 GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu, keyData32Count )); |
49 resource->resourcePriv().setUniqueKey(key); | 52 resource->resourcePriv().setUniqueKey(key); |
50 resource->unref(); | 53 resource->unref(); |
51 } | 54 } |
52 } | 55 } |
53 | 56 |
54 class GrResourceCacheBenchAdd : public Benchmark { | 57 class GrResourceCacheBenchAdd : public Benchmark { |
55 public: | 58 public: |
59 GrResourceCacheBenchAdd(int keyData32Count) | |
60 : fFullName("grresourcecache_add") | |
61 , fKeyData32Count(keyData32Count) { | |
62 if (keyData32Count > 1) { | |
63 fFullName.appendf("_%d", fKeyData32Count); | |
64 } | |
65 } | |
66 | |
56 bool isSuitableFor(Backend backend) override { | 67 bool isSuitableFor(Backend backend) override { |
57 return backend == kNonRendering_Backend; | 68 return backend == kNonRendering_Backend; |
58 } | 69 } |
59 | |
60 protected: | 70 protected: |
61 const char* onGetName() override { | 71 const char* onGetName() override { |
62 return "grresourcecache_add"; | 72 return fFullName.c_str(); |
63 } | 73 } |
64 | 74 |
65 void onDraw(const int loops, SkCanvas* canvas) override { | 75 void onDraw(const int loops, SkCanvas* canvas) override { |
66 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 76 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
67 if (NULL == context) { | 77 if (NULL == context) { |
68 return; | 78 return; |
69 } | 79 } |
70 // Set the cache budget to be very large so no purging occurs. | 80 // Set the cache budget to be very large so no purging occurs. |
71 context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); | 81 context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); |
72 | 82 |
73 GrResourceCache* cache = context->getResourceCache(); | 83 GrResourceCache* cache = context->getResourceCache(); |
74 | 84 |
75 // Make sure the cache is empty. | 85 // Make sure the cache is empty. |
76 cache->purgeAllUnlocked(); | 86 cache->purgeAllUnlocked(); |
77 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes( )); | 87 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes( )); |
78 | 88 |
79 GrGpu* gpu = context->getGpu(); | 89 GrGpu* gpu = context->getGpu(); |
80 | 90 |
81 for (int i = 0; i < loops; ++i) { | 91 for (int i = 0; i < loops; ++i) { |
82 populate_cache(gpu, CACHE_SIZE_COUNT); | 92 populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); |
83 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); | 93 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); |
84 } | 94 } |
85 } | 95 } |
86 | 96 |
87 private: | 97 private: |
98 SkString fFullName; | |
99 int fKeyData32Count; | |
88 typedef Benchmark INHERITED; | 100 typedef Benchmark INHERITED; |
89 }; | 101 }; |
90 | 102 |
91 class GrResourceCacheBenchFind : public Benchmark { | 103 class GrResourceCacheBenchFind : public Benchmark { |
92 public: | 104 public: |
105 GrResourceCacheBenchFind(int keyData32Count) | |
106 : fFullName("grresourcecache_find") | |
107 , fKeyData32Count(keyData32Count) { | |
108 if (keyData32Count > 1) { | |
109 fFullName.appendf("_%d", fKeyData32Count); | |
110 } | |
111 } | |
112 | |
93 bool isSuitableFor(Backend backend) override { | 113 bool isSuitableFor(Backend backend) override { |
94 return backend == kNonRendering_Backend; | 114 return backend == kNonRendering_Backend; |
95 } | 115 } |
96 | |
97 protected: | 116 protected: |
98 const char* onGetName() override { | 117 const char* onGetName() override { |
99 return "grresourcecache_find"; | 118 return fFullName.c_str(); |
100 } | 119 } |
101 | 120 |
102 void onPreDraw() override { | 121 void onPreDraw() override { |
103 fContext.reset(GrContext::CreateMockContext()); | 122 fContext.reset(GrContext::CreateMockContext()); |
104 if (!fContext) { | 123 if (!fContext) { |
105 return; | 124 return; |
106 } | 125 } |
107 // Set the cache budget to be very large so no purging occurs. | 126 // Set the cache budget to be very large so no purging occurs. |
108 fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); | 127 fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); |
109 | 128 |
110 GrResourceCache* cache = fContext->getResourceCache(); | 129 GrResourceCache* cache = fContext->getResourceCache(); |
111 | 130 |
112 // Make sure the cache is empty. | 131 // Make sure the cache is empty. |
113 cache->purgeAllUnlocked(); | 132 cache->purgeAllUnlocked(); |
114 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes( )); | 133 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes( )); |
115 | 134 |
116 GrGpu* gpu = fContext->getGpu(); | 135 GrGpu* gpu = fContext->getGpu(); |
117 | 136 |
118 populate_cache(gpu, CACHE_SIZE_COUNT); | 137 populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); |
119 } | 138 } |
120 | 139 |
121 void onDraw(const int loops, SkCanvas* canvas) override { | 140 void onDraw(const int loops, SkCanvas* canvas) override { |
122 if (!fContext) { | 141 if (!fContext) { |
123 return; | 142 return; |
124 } | 143 } |
125 GrResourceCache* cache = fContext->getResourceCache(); | 144 GrResourceCache* cache = fContext->getResourceCache(); |
126 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); | 145 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); |
127 for (int i = 0; i < loops; ++i) { | 146 for (int i = 0; i < loops; ++i) { |
128 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { | 147 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { |
129 GrUniqueKey key; | 148 GrUniqueKey key; |
130 BenchResource::ComputeKey(k, &key); | 149 BenchResource::ComputeKey(k, fKeyData32Count, &key); |
131 SkAutoTUnref<GrGpuResource> resource(cache->findAndRefUniqueReso urce(key)); | 150 SkAutoTUnref<GrGpuResource> resource(cache->findAndRefUniqueReso urce(key)); |
132 SkASSERT(resource); | 151 SkASSERT(resource); |
133 } | 152 } |
134 } | 153 } |
135 } | 154 } |
136 | 155 |
137 private: | 156 private: |
138 SkAutoTUnref<GrContext> fContext; | 157 SkAutoTUnref<GrContext> fContext; |
158 SkString fFullName; | |
159 int fKeyData32Count; | |
139 typedef Benchmark INHERITED; | 160 typedef Benchmark INHERITED; |
140 }; | 161 }; |
141 | 162 |
142 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 163 DEF_BENCH( return new GrResourceCacheBenchAdd(1); ) |
143 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 164 #ifdef SK_RELEASE |
165 // Only on release because on debug the SkTDynamicHash validation is too slow. | |
mtklein
2015/05/15 12:43:06
I'd be okay with #if-0'ing out the validation code
| |
166 DEF_BENCH( return new GrResourceCacheBenchAdd(2); ) | |
167 DEF_BENCH( return new GrResourceCacheBenchAdd(3); ) | |
168 DEF_BENCH( return new GrResourceCacheBenchAdd(4); ) | |
169 DEF_BENCH( return new GrResourceCacheBenchAdd(5); ) | |
170 DEF_BENCH( return new GrResourceCacheBenchAdd(10); ) | |
171 DEF_BENCH( return new GrResourceCacheBenchAdd(25); ) | |
172 DEF_BENCH( return new GrResourceCacheBenchAdd(54); ) | |
173 DEF_BENCH( return new GrResourceCacheBenchAdd(55); ) | |
174 DEF_BENCH( return new GrResourceCacheBenchAdd(56); ) | |
175 #endif | |
176 | |
177 DEF_BENCH( return new GrResourceCacheBenchFind(1); ) | |
178 #ifdef SK_RELEASE | |
179 DEF_BENCH( return new GrResourceCacheBenchFind(2); ) | |
180 DEF_BENCH( return new GrResourceCacheBenchFind(3); ) | |
181 DEF_BENCH( return new GrResourceCacheBenchFind(4); ) | |
182 DEF_BENCH( return new GrResourceCacheBenchFind(5); ) | |
183 DEF_BENCH( return new GrResourceCacheBenchFind(10); ) | |
184 DEF_BENCH( return new GrResourceCacheBenchFind(25); ) | |
185 DEF_BENCH( return new GrResourceCacheBenchFind(54); ) | |
186 DEF_BENCH( return new GrResourceCacheBenchFind(55); ) | |
187 DEF_BENCH( return new GrResourceCacheBenchFind(56); ) | |
188 #endif | |
144 | 189 |
145 #endif | 190 #endif |
OLD | NEW |