Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: bench/GrResourceCacheBench.cpp

Issue 707493002: Use GrResourceCache2 to service content key lookups (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move #ifdef SK_SUPPORT_GPU Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/gpu/GrContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10
9 #if SK_SUPPORT_GPU 11 #if SK_SUPPORT_GPU
10 12
11 #include "Benchmark.h"
12 #include "GrGpuResource.h" 13 #include "GrGpuResource.h"
13 #include "GrContext.h" 14 #include "GrContext.h"
14 #include "GrGpu.h" 15 #include "GrGpu.h"
15 #include "GrResourceCache.h" 16 #include "GrResourceCache.h"
17 #include "GrResourceCache2.h"
16 #include "GrStencilBuffer.h" 18 #include "GrStencilBuffer.h"
17 #include "GrTexture.h" 19 #include "GrTexture.h"
18 #include "GrTexturePriv.h" 20 #include "GrTexturePriv.h"
19 #include "SkCanvas.h" 21 #include "SkCanvas.h"
20 22
21 enum { 23 enum {
22 CACHE_SIZE_COUNT = 2048, 24 CACHE_SIZE_COUNT = 2048,
23 CACHE_SIZE_BYTES = 2 * 1024 * 1024, 25 CACHE_SIZE_BYTES = 2 * 1024 * 1024,
24 }; 26 };
25 27
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 GrSurfaceDesc desc; 112 GrSurfaceDesc desc;
111 get_texture_desc(i, &desc); 113 get_texture_desc(i, &desc);
112 GrResourceKey key = TextureResource::ComputeKey(desc); 114 GrResourceKey key = TextureResource::ComputeKey(desc);
113 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); 115 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
114 cache->purgeAsNeeded(1, resource->gpuMemorySize()); 116 cache->purgeAsNeeded(1, resource->gpuMemorySize());
115 cache->addResource(key, resource); 117 cache->addResource(key, resource);
116 resource->unref(); 118 resource->unref();
117 } 119 }
118 } 120 }
119 121
120 static void check_cache_contents_or_die(GrResourceCache* cache, int k) { 122 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) {
121 // Benchmark find calls that succeed. 123 // Benchmark find calls that succeed.
122 { 124 {
123 GrSurfaceDesc desc; 125 GrSurfaceDesc desc;
124 get_texture_desc(k, &desc); 126 get_texture_desc(k, &desc);
125 GrResourceKey key = TextureResource::ComputeKey(desc); 127 GrResourceKey key = TextureResource::ComputeKey(desc);
126 GrGpuResource* item = cache->find(key); 128 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
127 if (NULL == item) { 129 if (!item) {
128 SkFAIL("cache add does not work as expected"); 130 SkFAIL("cache add does not work as expected");
129 return; 131 return;
130 } 132 }
131 if (static_cast<TextureResource*>(item)->fID != k) { 133 if (static_cast<TextureResource*>(item.get())->fID != k) {
132 SkFAIL("cache add does not work as expected"); 134 SkFAIL("cache add does not work as expected");
133 return; 135 return;
134 } 136 }
135 } 137 }
136 { 138 {
137 int w, h, s; 139 int w, h, s;
138 get_stencil(k, &w, &h, &s); 140 get_stencil(k, &w, &h, &s);
139 GrResourceKey key = StencilResource::ComputeKey(w, h, s); 141 GrResourceKey key = StencilResource::ComputeKey(w, h, s);
140 GrGpuResource* item = cache->find(key); 142 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
141 if (NULL == item) { 143 if (!item) {
142 SkFAIL("cache add does not work as expected"); 144 SkFAIL("cache add does not work as expected");
143 return; 145 return;
144 } 146 }
145 if (static_cast<TextureResource*>(item)->fID != k) { 147 if (static_cast<TextureResource*>(item.get())->fID != k) {
146 SkFAIL("cache add does not work as expected"); 148 SkFAIL("cache add does not work as expected");
147 return; 149 return;
148 } 150 }
149 } 151 }
150 152
151 // Benchmark also find calls that always fail. 153 // Benchmark also find calls that always fail.
152 { 154 {
153 GrSurfaceDesc desc; 155 GrSurfaceDesc desc;
154 get_texture_desc(k, &desc); 156 get_texture_desc(k, &desc);
155 desc.fHeight |= 1; 157 desc.fHeight |= 1;
156 GrResourceKey key = TextureResource::ComputeKey(desc); 158 GrResourceKey key = TextureResource::ComputeKey(desc);
157 GrGpuResource* item = cache->find(key); 159 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
158 if (item) { 160 if (item) {
159 SkFAIL("cache add does not work as expected"); 161 SkFAIL("cache add does not work as expected");
160 return; 162 return;
161 } 163 }
162 } 164 }
163 { 165 {
164 int w, h, s; 166 int w, h, s;
165 get_stencil(k, &w, &h, &s); 167 get_stencil(k, &w, &h, &s);
166 h |= 1; 168 h |= 1;
167 GrResourceKey key = StencilResource::ComputeKey(w, h, s); 169 GrResourceKey key = StencilResource::ComputeKey(w, h, s);
168 GrGpuResource* item = cache->find(key); 170 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
169 if (item) { 171 if (item) {
170 SkFAIL("cache add does not work as expected"); 172 SkFAIL("cache add does not work as expected");
171 return; 173 return;
172 } 174 }
173 } 175 }
174 } 176 }
175 177
176 class GrResourceCacheBenchAdd : public Benchmark { 178 class GrResourceCacheBenchAdd : public Benchmark {
177 enum { 179 enum {
178 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, 180 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2,
179 DUPLICATE_COUNT = CACHE_SIZE_COUNT / 4,
180 }; 181 };
181 182
182 public: 183 public:
183 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 184 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
184 return backend == kGPU_Backend; 185 return backend == kNonRendering_Backend;
185 } 186 }
186 187
187 protected: 188 protected:
188 virtual const char* onGetName() SK_OVERRIDE { 189 virtual const char* onGetName() SK_OVERRIDE {
189 return "grresourcecache_add"; 190 return "grresourcecache_add";
190 } 191 }
191 192
192 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 193 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
193 GrGpu* gpu = canvas->getGrContext()->getGpu(); 194 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
195 if (NULL == context) {
196 return;
197 }
198 // Set the cache budget to be very large so no purging occurs.
199 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30);
200
201 GrResourceCache* cache = context->getResourceCache();
202 GrResourceCache2* cache2 = context->getResourceCache2();
203
204 // Make sure the cache is empty.
205 cache->purgeAllUnlocked();
206 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe sourceBytes());
207
208 GrGpu* gpu = context->getGpu();
194 209
195 for (int i = 0; i < loops; ++i) { 210 for (int i = 0; i < loops; ++i) {
196 GrResourceCache cache(gpu->caps(), CACHE_SIZE_COUNT, CACHE_SIZE_BYTE S); 211 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCach edResourceBytes());
197 populate_cache(&cache, gpu, DUPLICATE_COUNT); 212
198 populate_cache(&cache, gpu, RESOURCE_COUNT); 213 populate_cache(cache, gpu, RESOURCE_COUNT);
199 214
200 // Check that cache works. 215 // Check that cache works.
201 for (int k = 0; k < RESOURCE_COUNT; k += 33) { 216 for (int k = 0; k < RESOURCE_COUNT; k += 33) {
202 check_cache_contents_or_die(&cache, k); 217 check_cache_contents_or_die(cache2, k);
203 } 218 }
204 cache.purgeAllUnlocked(); 219 cache->purgeAllUnlocked();
205 } 220 }
206 } 221 }
207 222
208 private: 223 private:
209 typedef Benchmark INHERITED; 224 typedef Benchmark INHERITED;
210 }; 225 };
211 226
212 class GrResourceCacheBenchFind : public Benchmark { 227 class GrResourceCacheBenchFind : public Benchmark {
213 enum { 228 enum {
214 RESOURCE_COUNT = (CACHE_SIZE_COUNT / 2) - 100, 229 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2,
215 DUPLICATE_COUNT = 100
216 }; 230 };
217 231
218 public: 232 public:
219 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { 233 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
220 return backend == kGPU_Backend; 234 return backend == kNonRendering_Backend;
221 } 235 }
222 236
223 protected: 237 protected:
224 virtual const char* onGetName() SK_OVERRIDE { 238 virtual const char* onGetName() SK_OVERRIDE {
225 return "grresourcecache_find"; 239 return "grresourcecache_find";
226 } 240 }
227 241
228 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 242 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
229 GrGpu* gpu = canvas->getGrContext()->getGpu(); 243 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
230 GrResourceCache cache(gpu->caps(), CACHE_SIZE_COUNT, CACHE_SIZE_BYTES); 244 if (NULL == context) {
231 populate_cache(&cache, gpu, DUPLICATE_COUNT); 245 return;
232 populate_cache(&cache, gpu, RESOURCE_COUNT); 246 }
247 // Set the cache budget to be very large so no purging occurs.
248 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30);
249
250 GrResourceCache* cache = context->getResourceCache();
251 GrResourceCache2* cache2 = context->getResourceCache2();
252
253 // Make sure the cache is empty.
254 cache->purgeAllUnlocked();
255 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe sourceBytes());
256
257 GrGpu* gpu = context->getGpu();
258
259 populate_cache(cache, gpu, RESOURCE_COUNT);
233 260
234 for (int i = 0; i < loops; ++i) { 261 for (int i = 0; i < loops; ++i) {
235 for (int k = 0; k < RESOURCE_COUNT; ++k) { 262 for (int k = 0; k < RESOURCE_COUNT; ++k) {
236 check_cache_contents_or_die(&cache, k); 263 check_cache_contents_or_die(cache2, k);
237 } 264 }
238 } 265 }
239 } 266 }
240 267
241 private: 268 private:
242 typedef Benchmark INHERITED; 269 typedef Benchmark INHERITED;
243 }; 270 };
244 271
245 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) 272 DEF_BENCH( return new GrResourceCacheBenchAdd(); )
246 DEF_BENCH( return new GrResourceCacheBenchFind(); ) 273 DEF_BENCH( return new GrResourceCacheBenchFind(); )
247 274
248 #endif 275 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698