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 "GrResourceCache2.h" | 16 #include "GrResourceCache2.h" |
17 #include "GrStencilBuffer.h" | |
18 #include "GrTexture.h" | |
19 #include "GrTexturePriv.h" | |
20 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
21 | 18 |
22 enum { | 19 enum { |
23 CACHE_SIZE_COUNT = 2048, | 20 CACHE_SIZE_COUNT = 2048, |
24 CACHE_SIZE_BYTES = 2 * 1024 * 1024, | 21 CACHE_SIZE_BYTES = 2 * 1024 * 1024, |
25 }; | 22 }; |
26 | 23 |
robertphillips
2014/11/24 14:39:14
// Test resource that emulates a stencil buffer's
| |
27 class StencilResource : public GrGpuResource { | 24 class FooResource : public GrGpuResource { |
28 public: | 25 public: |
29 SK_DECLARE_INST_COUNT(StencilResource); | 26 SK_DECLARE_INST_COUNT(FooResource); |
30 StencilResource(GrGpu* gpu, int id) | 27 FooResource(GrGpu* gpu, int id) |
31 : INHERITED(gpu, false) | 28 : INHERITED(gpu, false) |
32 , fID(id) { | 29 , fID(id) { |
33 this->registerWithCache(); | 30 this->registerWithCache(); |
34 } | 31 } |
35 | 32 |
36 static GrResourceKey ComputeKey(int width, int height, int sampleCnt) { | 33 static GrResourceKey ComputeKey(int width, int height, int sampleCnt) { |
37 return GrStencilBuffer::ComputeKey(width, height, sampleCnt); | 34 GrCacheID::Key key; |
35 memset(&key, 0, sizeof(key)); | |
36 key.fData32[0] = width; | |
37 key.fData32[1] = height; | |
38 key.fData32[2] = sampleCnt; | |
39 static int gType = GrResourceKey::GenerateResourceType(); | |
40 static int gDomain = GrCacheID::GenerateDomain(); | |
41 return GrResourceKey(GrCacheID(gDomain, key), gType, 0); | |
38 } | 42 } |
39 | 43 |
40 int fID; | 44 int fID; |
41 | 45 |
42 private: | 46 private: |
43 virtual size_t onGpuMemorySize() const SK_OVERRIDE { | 47 virtual size_t onGpuMemorySize() const SK_OVERRIDE { |
44 return 100 + ((fID % 1 == 0) ? -5 : 6); | 48 return 100 + ((fID % 1 == 0) ? -5 : 6); |
45 } | 49 } |
46 | 50 |
47 typedef GrGpuResource INHERITED; | 51 typedef GrGpuResource INHERITED; |
48 }; | 52 }; |
49 | 53 |
robertphillips
2014/11/24 14:39:14
// Test resource that emulates a texture's behavio
| |
50 class TextureResource : public GrGpuResource { | 54 class BarResource : public GrGpuResource { |
51 public: | 55 public: |
52 SK_DECLARE_INST_COUNT(TextureResource); | 56 SK_DECLARE_INST_COUNT(BarResource); |
53 TextureResource(GrGpu* gpu, int id) | 57 BarResource(GrGpu* gpu, int id) |
54 : INHERITED(gpu, false) | 58 : INHERITED(gpu, false) |
55 , fID(id) { | 59 , fID(id) { |
56 this->registerWithCache(); | 60 this->registerWithCache(); |
57 } | 61 } |
58 | 62 |
59 static GrResourceKey ComputeKey(const GrSurfaceDesc& desc) { | 63 static GrResourceKey ComputeKey(const GrSurfaceDesc& desc) { |
60 GrCacheID::Key key; | 64 GrCacheID::Key key; |
61 memset(&key, 0, sizeof(key)); | 65 memset(&key, 0, sizeof(key)); |
62 key.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); | 66 key.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); |
63 key.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; | 67 key.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; |
64 key.fData32[2] = desc.fFlags; | 68 key.fData32[2] = desc.fFlags; |
65 static int gType = GrResourceKey::GenerateResourceType(); | 69 static int gType = GrResourceKey::GenerateResourceType(); |
66 static int gDomain = GrCacheID::GenerateDomain(); | 70 static int gDomain = GrCacheID::GenerateDomain(); |
67 return GrResourceKey(GrCacheID(gDomain, key), gType, 0); | 71 return GrResourceKey(GrCacheID(gDomain, key), gType, 0); |
68 } | 72 } |
69 | 73 |
70 int fID; | 74 int fID; |
71 | 75 |
72 private: | 76 private: |
73 virtual size_t onGpuMemorySize() const SK_OVERRIDE { | 77 virtual size_t onGpuMemorySize() const SK_OVERRIDE { |
74 return 100 + ((fID % 1 == 0) ? -40 : 33); | 78 return 100 + ((fID % 1 == 0) ? -40 : 33); |
75 } | 79 } |
76 | 80 |
77 typedef GrGpuResource INHERITED; | 81 typedef GrGpuResource INHERITED; |
78 }; | 82 }; |
79 | 83 |
80 static void get_stencil(int i, int* w, int* h, int* s) { | 84 static void get_foo_params(int i, int* w, int* h, int* s) { |
81 *w = i % 1024; | 85 *w = i % 1024; |
82 *h = i * 2 % 1024; | 86 *h = i * 2 % 1024; |
robertphillips
2014/11/24 14:39:14
% 1 again ?
bsalomon
2014/11/24 14:49:58
yikes, changed to 2.
| |
83 *s = i % 1 == 0 ? 0 : 4; | 87 *s = i % 1 == 0 ? 0 : 4; |
84 } | 88 } |
85 | 89 |
86 static void get_texture_desc(int i, GrSurfaceDesc* desc) { | 90 static void get_bar_surf_desc(int i, GrSurfaceDesc* desc) { |
87 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; | 91 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; |
88 desc->fWidth = i % 1024; | 92 desc->fWidth = i % 1024; |
89 desc->fHeight = i * 2 % 1024; | 93 desc->fHeight = i * 2 % 1024; |
90 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); | 94 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); |
91 desc->fSampleCnt = ((i % 2) == 0) ? 0 : 4; | 95 desc->fSampleCnt = ((i % 2) == 0) ? 0 : 4; |
92 } | 96 } |
93 | 97 |
94 static void populate_cache(GrGpu* gpu, int resourceCount) { | 98 static void populate_cache(GrGpu* gpu, int resourceCount) { |
95 for (int i = 0; i < resourceCount; ++i) { | 99 for (int i = 0; i < resourceCount; ++i) { |
96 int w, h, s; | 100 int w, h, s; |
97 get_stencil(i, &w, &h, &s); | 101 get_foo_params(i, &w, &h, &s); |
98 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); | 102 GrResourceKey key = FooResource::ComputeKey(w, h, s); |
99 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); | 103 GrGpuResource* resource = SkNEW_ARGS(FooResource, (gpu, i)); |
100 resource->cacheAccess().setContentKey(key); | 104 resource->cacheAccess().setContentKey(key); |
101 resource->unref(); | 105 resource->unref(); |
102 } | 106 } |
103 | 107 |
104 for (int i = 0; i < resourceCount; ++i) { | 108 for (int i = 0; i < resourceCount; ++i) { |
105 GrSurfaceDesc desc; | 109 GrSurfaceDesc desc; |
106 get_texture_desc(i, &desc); | 110 get_bar_surf_desc(i, &desc); |
107 GrResourceKey key = TextureResource::ComputeKey(desc); | 111 GrResourceKey key = BarResource::ComputeKey(desc); |
108 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); | 112 GrGpuResource* resource = SkNEW_ARGS(BarResource, (gpu, i)); |
109 resource->cacheAccess().setContentKey(key); | 113 resource->cacheAccess().setContentKey(key); |
110 resource->unref(); | 114 resource->unref(); |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { | 118 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { |
115 // Benchmark find calls that succeed. | 119 // Benchmark find calls that succeed. |
116 { | 120 { |
117 GrSurfaceDesc desc; | 121 GrSurfaceDesc desc; |
118 get_texture_desc(k, &desc); | 122 get_bar_surf_desc(k, &desc); |
119 GrResourceKey key = TextureResource::ComputeKey(desc); | 123 GrResourceKey key = BarResource::ComputeKey(desc); |
120 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); | 124 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); |
121 if (!item) { | 125 if (!item) { |
122 SkFAIL("cache add does not work as expected"); | 126 SkFAIL("cache add does not work as expected"); |
123 return; | 127 return; |
124 } | 128 } |
125 if (static_cast<TextureResource*>(item.get())->fID != k) { | 129 if (static_cast<BarResource*>(item.get())->fID != k) { |
126 SkFAIL("cache add does not work as expected"); | 130 SkFAIL("cache add does not work as expected"); |
127 return; | 131 return; |
128 } | 132 } |
129 } | 133 } |
130 { | 134 { |
131 int w, h, s; | 135 int w, h, s; |
132 get_stencil(k, &w, &h, &s); | 136 get_foo_params(k, &w, &h, &s); |
133 GrResourceKey key = StencilResource::ComputeKey(w, h, s); | 137 GrResourceKey key = FooResource::ComputeKey(w, h, s); |
134 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); | 138 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); |
135 if (!item) { | 139 if (!item) { |
136 SkFAIL("cache add does not work as expected"); | 140 SkFAIL("cache add does not work as expected"); |
137 return; | 141 return; |
138 } | 142 } |
139 if (static_cast<TextureResource*>(item.get())->fID != k) { | 143 if (static_cast<FooResource*>(item.get())->fID != k) { |
140 SkFAIL("cache add does not work as expected"); | 144 SkFAIL("cache add does not work as expected"); |
141 return; | 145 return; |
142 } | 146 } |
143 } | 147 } |
144 | 148 |
145 // Benchmark also find calls that always fail. | 149 // Benchmark also find calls that always fail. |
146 { | 150 { |
147 GrSurfaceDesc desc; | 151 GrSurfaceDesc desc; |
148 get_texture_desc(k, &desc); | 152 get_bar_surf_desc(k, &desc); |
149 desc.fHeight |= 1; | 153 desc.fHeight |= 1; |
150 GrResourceKey key = TextureResource::ComputeKey(desc); | 154 GrResourceKey key = BarResource::ComputeKey(desc); |
151 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); | 155 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); |
152 if (item) { | 156 if (item) { |
153 SkFAIL("cache add does not work as expected"); | 157 SkFAIL("cache add does not work as expected"); |
154 return; | 158 return; |
155 } | 159 } |
156 } | 160 } |
157 { | 161 { |
158 int w, h, s; | 162 int w, h, s; |
159 get_stencil(k, &w, &h, &s); | 163 get_foo_params(k, &w, &h, &s); |
160 h |= 1; | 164 h |= 1; |
161 GrResourceKey key = StencilResource::ComputeKey(w, h, s); | 165 GrResourceKey key = FooResource::ComputeKey(w, h, s); |
162 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); | 166 SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key)); |
163 if (item) { | 167 if (item) { |
164 SkFAIL("cache add does not work as expected"); | 168 SkFAIL("cache add does not work as expected"); |
165 return; | 169 return; |
166 } | 170 } |
167 } | 171 } |
168 } | 172 } |
169 | 173 |
170 class GrResourceCacheBenchAdd : public Benchmark { | 174 class GrResourceCacheBenchAdd : public Benchmark { |
171 enum { | 175 enum { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } | 260 } |
257 | 261 |
258 private: | 262 private: |
259 typedef Benchmark INHERITED; | 263 typedef Benchmark INHERITED; |
260 }; | 264 }; |
261 | 265 |
262 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 266 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) |
263 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 267 DEF_BENCH( return new GrResourceCacheBenchFind(); ) |
264 | 268 |
265 #endif | 269 #endif |
OLD | NEW |