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