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 "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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
92 desc->fFlags = kRenderTarget_GrSurfaceFlag | | 91 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; |
93 kNoStencil_GrSurfaceFlag; | |
94 desc->fWidth = i % 1024; | 92 desc->fWidth = i % 1024; |
95 desc->fHeight = i * 2 % 1024; | 93 desc->fHeight = i * 2 % 1024; |
96 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); | 94 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); |
97 desc->fSampleCnt = i % 1 == 0 ? 0 : 4; | 95 desc->fSampleCnt = ((i % 2) == 0) ? 0 : 4; |
98 } | 96 } |
99 | 97 |
100 static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
) { | 98 static void populate_cache(GrGpu* gpu, int resourceCount) { |
101 for (int i = 0; i < resourceCount; ++i) { | 99 for (int i = 0; i < resourceCount; ++i) { |
102 int w, h, s; | 100 int w, h, s; |
103 get_stencil(i, &w, &h, &s); | 101 get_stencil(i, &w, &h, &s); |
104 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); | 102 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); |
105 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); | 103 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); |
106 cache->purgeAsNeeded(1, resource->gpuMemorySize()); | 104 resource->cacheAccess().setContentKey(key); |
107 cache->addResource(key, resource); | |
108 resource->unref(); | 105 resource->unref(); |
109 } | 106 } |
110 | 107 |
111 for (int i = 0; i < resourceCount; ++i) { | 108 for (int i = 0; i < resourceCount; ++i) { |
112 GrSurfaceDesc desc; | 109 GrSurfaceDesc desc; |
113 get_texture_desc(i, &desc); | 110 get_texture_desc(i, &desc); |
114 GrResourceKey key = TextureResource::ComputeKey(desc); | 111 GrResourceKey key = TextureResource::ComputeKey(desc); |
115 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); | 112 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); |
116 cache->purgeAsNeeded(1, resource->gpuMemorySize()); | 113 resource->cacheAccess().setContentKey(key); |
117 cache->addResource(key, resource); | |
118 resource->unref(); | 114 resource->unref(); |
119 } | 115 } |
120 } | 116 } |
121 | 117 |
122 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { | 118 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { |
123 // Benchmark find calls that succeed. | 119 // Benchmark find calls that succeed. |
124 { | 120 { |
125 GrSurfaceDesc desc; | 121 GrSurfaceDesc desc; |
126 get_texture_desc(k, &desc); | 122 get_texture_desc(k, &desc); |
127 GrResourceKey key = TextureResource::ComputeKey(desc); | 123 GrResourceKey key = TextureResource::ComputeKey(desc); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 187 } |
192 | 188 |
193 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 189 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
194 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 190 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
195 if (NULL == context) { | 191 if (NULL == context) { |
196 return; | 192 return; |
197 } | 193 } |
198 // Set the cache budget to be very large so no purging occurs. | 194 // Set the cache budget to be very large so no purging occurs. |
199 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); | 195 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); |
200 | 196 |
201 GrResourceCache* cache = context->getResourceCache(); | |
202 GrResourceCache2* cache2 = context->getResourceCache2(); | 197 GrResourceCache2* cache2 = context->getResourceCache2(); |
203 | 198 |
204 // Make sure the cache is empty. | 199 // Make sure the cache is empty. |
205 cache->purgeAllUnlocked(); | 200 cache2->purgeAllUnlocked(); |
206 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe
sourceBytes()); | 201 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); |
207 | 202 |
208 GrGpu* gpu = context->getGpu(); | 203 GrGpu* gpu = context->getGpu(); |
209 | 204 |
210 for (int i = 0; i < loops; ++i) { | 205 for (int i = 0; i < loops; ++i) { |
211 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCach
edResourceBytes()); | 206 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResource
Bytes()); |
212 | 207 |
213 populate_cache(cache, gpu, RESOURCE_COUNT); | 208 populate_cache(gpu, RESOURCE_COUNT); |
214 | 209 |
215 // Check that cache works. | 210 // Check that cache works. |
216 for (int k = 0; k < RESOURCE_COUNT; k += 33) { | 211 for (int k = 0; k < RESOURCE_COUNT; k += 33) { |
217 check_cache_contents_or_die(cache2, k); | 212 check_cache_contents_or_die(cache2, k); |
218 } | 213 } |
219 cache->purgeAllUnlocked(); | 214 cache2->purgeAllUnlocked(); |
220 } | 215 } |
221 } | 216 } |
222 | 217 |
223 private: | 218 private: |
224 typedef Benchmark INHERITED; | 219 typedef Benchmark INHERITED; |
225 }; | 220 }; |
226 | 221 |
227 class GrResourceCacheBenchFind : public Benchmark { | 222 class GrResourceCacheBenchFind : public Benchmark { |
228 enum { | 223 enum { |
229 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, | 224 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, |
(...skipping 10 matching lines...) Expand all Loading... |
240 } | 235 } |
241 | 236 |
242 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 237 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
243 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 238 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
244 if (NULL == context) { | 239 if (NULL == context) { |
245 return; | 240 return; |
246 } | 241 } |
247 // Set the cache budget to be very large so no purging occurs. | 242 // Set the cache budget to be very large so no purging occurs. |
248 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); | 243 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); |
249 | 244 |
250 GrResourceCache* cache = context->getResourceCache(); | |
251 GrResourceCache2* cache2 = context->getResourceCache2(); | 245 GrResourceCache2* cache2 = context->getResourceCache2(); |
252 | 246 |
253 // Make sure the cache is empty. | 247 // Make sure the cache is empty. |
254 cache->purgeAllUnlocked(); | 248 cache2->purgeAllUnlocked(); |
255 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe
sourceBytes()); | 249 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); |
256 | 250 |
257 GrGpu* gpu = context->getGpu(); | 251 GrGpu* gpu = context->getGpu(); |
258 | 252 |
259 populate_cache(cache, gpu, RESOURCE_COUNT); | 253 populate_cache(gpu, RESOURCE_COUNT); |
260 | 254 |
261 for (int i = 0; i < loops; ++i) { | 255 for (int i = 0; i < loops; ++i) { |
262 for (int k = 0; k < RESOURCE_COUNT; ++k) { | 256 for (int k = 0; k < RESOURCE_COUNT; ++k) { |
263 check_cache_contents_or_die(cache2, k); | 257 check_cache_contents_or_die(cache2, k); |
264 } | 258 } |
265 } | 259 } |
266 } | 260 } |
267 | 261 |
268 private: | 262 private: |
269 typedef Benchmark INHERITED; | 263 typedef Benchmark INHERITED; |
270 }; | 264 }; |
271 | 265 |
272 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 266 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) |
273 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 267 DEF_BENCH( return new GrResourceCacheBenchFind(); ) |
274 | 268 |
275 #endif | 269 #endif |
OLD | NEW |