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

Side by Side Diff: bench/GrResourceCacheBench.cpp

Issue 716143004: Replace GrResourceCache with GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix uncalled function 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 | gyp/gpu.gyp » ('j') | src/gpu/GrResourceCache2.h » ('J')
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" 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 "GrContext.h" 14 #include "GrContext.h"
15 #include "GrGpu.h" 15 #include "GrGpu.h"
16 #include "GrResourceCache.h"
17 #include "GrResourceCache2.h" 16 #include "GrResourceCache2.h"
18 #include "GrStencilBuffer.h" 17 #include "GrStencilBuffer.h"
19 #include "GrTexture.h" 18 #include "GrTexture.h"
20 #include "GrTexturePriv.h" 19 #include "GrTexturePriv.h"
21 #include "SkCanvas.h" 20 #include "SkCanvas.h"
22 21
23 enum { 22 enum {
24 CACHE_SIZE_COUNT = 2048, 23 CACHE_SIZE_COUNT = 2048,
25 CACHE_SIZE_BYTES = 2 * 1024 * 1024, 24 CACHE_SIZE_BYTES = 2 * 1024 * 1024,
26 }; 25 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 80
82 typedef GrGpuResource INHERITED; 81 typedef GrGpuResource INHERITED;
83 }; 82 };
84 83
85 static void get_stencil(int i, int* w, int* h, int* s) { 84 static void get_stencil(int i, int* w, int* h, int* s) {
86 *w = i % 1024; 85 *w = i % 1024;
87 *h = i * 2 % 1024; 86 *h = i * 2 % 1024;
88 *s = i % 1 == 0 ? 0 : 4; 87 *s = i % 1 == 0 ? 0 : 4;
89 } 88 }
90 89
91 static void get_texture_desc(int i, GrSurfaceDesc* desc) { 90 static void get_texture_desc(int i, GrSurfaceDesc* desc) {
robertphillips 2014/11/13 14:34:03 one line ?
bsalomon 2014/11/13 14:51:50 Done.
92 desc->fFlags = kRenderTarget_GrSurfaceFlag | 91 desc->fFlags = kRenderTarget_GrSurfaceFlag |
93 kNoStencil_GrSurfaceFlag; 92 kNoStencil_GrSurfaceFlag;
94 desc->fWidth = i % 1024; 93 desc->fWidth = i % 1024;
95 desc->fHeight = i * 2 % 1024; 94 desc->fHeight = i * 2 % 1024;
96 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); 95 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1));
robertphillips 2014/11/13 14:34:03 % 1 ??
bsalomon 2014/11/13 14:51:50 ha, I assume it's supposed to be 2.
97 desc->fSampleCnt = i % 1 == 0 ? 0 : 4; 96 desc->fSampleCnt = i % 1 == 0 ? 0 : 4;
98 } 97 }
99 98
100 static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount ) { 99 static void populate_cache(GrGpu* gpu, int resourceCount) {
101 for (int i = 0; i < resourceCount; ++i) { 100 for (int i = 0; i < resourceCount; ++i) {
102 int w, h, s; 101 int w, h, s;
103 get_stencil(i, &w, &h, &s); 102 get_stencil(i, &w, &h, &s);
104 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); 103 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s);
105 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); 104 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i));
106 cache->purgeAsNeeded(1, resource->gpuMemorySize()); 105 resource->cacheAccess().setContentKey(key);
107 cache->addResource(key, resource);
108 resource->unref(); 106 resource->unref();
109 } 107 }
110 108
111 for (int i = 0; i < resourceCount; ++i) { 109 for (int i = 0; i < resourceCount; ++i) {
112 GrSurfaceDesc desc; 110 GrSurfaceDesc desc;
113 get_texture_desc(i, &desc); 111 get_texture_desc(i, &desc);
114 GrResourceKey key = TextureResource::ComputeKey(desc); 112 GrResourceKey key = TextureResource::ComputeKey(desc);
115 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); 113 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
116 cache->purgeAsNeeded(1, resource->gpuMemorySize()); 114 resource->cacheAccess().setContentKey(key);
117 cache->addResource(key, resource);
118 resource->unref(); 115 resource->unref();
119 } 116 }
120 } 117 }
121 118
122 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { 119 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) {
123 // Benchmark find calls that succeed. 120 // Benchmark find calls that succeed.
124 { 121 {
125 GrSurfaceDesc desc; 122 GrSurfaceDesc desc;
126 get_texture_desc(k, &desc); 123 get_texture_desc(k, &desc);
127 GrResourceKey key = TextureResource::ComputeKey(desc); 124 GrResourceKey key = TextureResource::ComputeKey(desc);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 188 }
192 189
193 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 190 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
194 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 191 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
195 if (NULL == context) { 192 if (NULL == context) {
196 return; 193 return;
197 } 194 }
198 // Set the cache budget to be very large so no purging occurs. 195 // Set the cache budget to be very large so no purging occurs.
199 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); 196 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30);
200 197
201 GrResourceCache* cache = context->getResourceCache();
202 GrResourceCache2* cache2 = context->getResourceCache2(); 198 GrResourceCache2* cache2 = context->getResourceCache2();
203 199
204 // Make sure the cache is empty. 200 // Make sure the cache is empty.
205 cache->purgeAllUnlocked(); 201 cache2->purgeAllUnlocked();
206 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe sourceBytes()); 202 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
207 203
208 GrGpu* gpu = context->getGpu(); 204 GrGpu* gpu = context->getGpu();
209 205
210 for (int i = 0; i < loops; ++i) { 206 for (int i = 0; i < loops; ++i) {
211 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCach edResourceBytes()); 207 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResource Bytes());
212 208
213 populate_cache(cache, gpu, RESOURCE_COUNT); 209 populate_cache(gpu, RESOURCE_COUNT);
214 210
215 // Check that cache works. 211 // Check that cache works.
216 for (int k = 0; k < RESOURCE_COUNT; k += 33) { 212 for (int k = 0; k < RESOURCE_COUNT; k += 33) {
217 check_cache_contents_or_die(cache2, k); 213 check_cache_contents_or_die(cache2, k);
218 } 214 }
219 cache->purgeAllUnlocked(); 215 cache2->purgeAllUnlocked();
220 } 216 }
221 } 217 }
222 218
223 private: 219 private:
224 typedef Benchmark INHERITED; 220 typedef Benchmark INHERITED;
225 }; 221 };
226 222
227 class GrResourceCacheBenchFind : public Benchmark { 223 class GrResourceCacheBenchFind : public Benchmark {
228 enum { 224 enum {
229 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, 225 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2,
(...skipping 10 matching lines...) Expand all
240 } 236 }
241 237
242 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 238 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
243 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); 239 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext());
244 if (NULL == context) { 240 if (NULL == context) {
245 return; 241 return;
246 } 242 }
247 // Set the cache budget to be very large so no purging occurs. 243 // Set the cache budget to be very large so no purging occurs.
248 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); 244 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30);
249 245
250 GrResourceCache* cache = context->getResourceCache();
251 GrResourceCache2* cache2 = context->getResourceCache2(); 246 GrResourceCache2* cache2 = context->getResourceCache2();
252 247
253 // Make sure the cache is empty. 248 // Make sure the cache is empty.
254 cache->purgeAllUnlocked(); 249 cache2->purgeAllUnlocked();
255 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe sourceBytes()); 250 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte s());
256 251
257 GrGpu* gpu = context->getGpu(); 252 GrGpu* gpu = context->getGpu();
258 253
259 populate_cache(cache, gpu, RESOURCE_COUNT); 254 populate_cache(gpu, RESOURCE_COUNT);
260 255
261 for (int i = 0; i < loops; ++i) { 256 for (int i = 0; i < loops; ++i) {
262 for (int k = 0; k < RESOURCE_COUNT; ++k) { 257 for (int k = 0; k < RESOURCE_COUNT; ++k) {
263 check_cache_contents_or_die(cache2, k); 258 check_cache_contents_or_die(cache2, k);
264 } 259 }
265 } 260 }
266 } 261 }
267 262
268 private: 263 private:
269 typedef Benchmark INHERITED; 264 typedef Benchmark INHERITED;
270 }; 265 };
271 266
272 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) 267 DEF_BENCH( return new GrResourceCacheBenchAdd(); )
273 DEF_BENCH( return new GrResourceCacheBenchFind(); ) 268 DEF_BENCH( return new GrResourceCacheBenchFind(); )
274 269
275 #endif 270 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/gpu.gyp » ('j') | src/gpu/GrResourceCache2.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698