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

Side by Side Diff: bench/benchmain.cpp

Issue 12607013: Add MSAA configs to bench. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/gpu/GrContext.h » ('j') | src/gpu/GrDrawTarget.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 2011 Google Inc. 3 * Copyright 2011 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 9
10 #include "BenchTimer.h" 10 #include "BenchTimer.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 187
188 enum Backend { 188 enum Backend {
189 kNonRendering_Backend, 189 kNonRendering_Backend,
190 kRaster_Backend, 190 kRaster_Backend,
191 kGPU_Backend, 191 kGPU_Backend,
192 kPDF_Backend, 192 kPDF_Backend,
193 }; 193 };
194 194
195 static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, 195 static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size,
196 Backend backend, GrContext* context) { 196 Backend backend, int sampleCount, GrContext* contex t) {
197 SkDevice* device = NULL; 197 SkDevice* device = NULL;
198 SkBitmap bitmap; 198 SkBitmap bitmap;
199 bitmap.setConfig(config, size.fX, size.fY); 199 bitmap.setConfig(config, size.fX, size.fY);
200 200
201 switch (backend) { 201 switch (backend) {
202 case kRaster_Backend: 202 case kRaster_Backend:
203 bitmap.allocPixels(); 203 bitmap.allocPixels();
204 erase(bitmap); 204 erase(bitmap);
205 device = SkNEW_ARGS(SkDevice, (bitmap)); 205 device = SkNEW_ARGS(SkDevice, (bitmap));
206 break; 206 break;
207 #if SK_SUPPORT_GPU 207 #if SK_SUPPORT_GPU
208 case kGPU_Backend: { 208 case kGPU_Backend: {
209 GrTextureDesc desc; 209 GrTextureDesc desc;
210 desc.fConfig = kSkia8888_GrPixelConfig; 210 desc.fConfig = kSkia8888_GrPixelConfig;
211 desc.fFlags = kRenderTarget_GrTextureFlagBit; 211 desc.fFlags = kRenderTarget_GrTextureFlagBit;
212 desc.fWidth = size.fX; 212 desc.fWidth = size.fX;
213 desc.fHeight = size.fY; 213 desc.fHeight = size.fY;
214 desc.fSampleCnt = sampleCount;
214 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0)); 215 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0));
215 if (!texture) { 216 if (!texture) {
216 return NULL; 217 return NULL;
217 } 218 }
218 device = SkNEW_ARGS(SkGpuDevice, (context, texture.get())); 219 device = SkNEW_ARGS(SkGpuDevice, (context, texture.get()));
219 break; 220 break;
220 } 221 }
221 #endif 222 #endif
222 case kPDF_Backend: 223 case kPDF_Backend:
223 default: 224 default:
224 SkASSERT(!"unsupported"); 225 SkASSERT(!"unsupported");
225 } 226 }
226 return device; 227 return device;
227 } 228 }
228 229
229 #if SK_SUPPORT_GPU 230 #if SK_SUPPORT_GPU
230 GrContextFactory gContextFactory; 231 GrContextFactory gContextFactory;
231 typedef GrContextFactory::GLContextType GLContextType; 232 typedef GrContextFactory::GLContextType GLContextType;
232 static const GLContextType kDontCareGLCtxType = GrContextFactory::kNative_GLCont extType; 233 static const GLContextType kDontCareGLCtxType = GrContextFactory::kNative_GLCont extType;
233 #else 234 #else
234 typedef int GLContextType; 235 typedef int GLContextType;
235 static const GLContextType kDontCareGLCtxType = 0; 236 static const GLContextType kDontCareGLCtxType = 0;
236 #endif 237 #endif
237 238
238 static const struct { 239 static const struct {
239 SkBitmap::Config fConfig; 240 SkBitmap::Config fConfig;
240 const char* fName; 241 const char* fName;
242 int fSampleCnt;
241 Backend fBackend; 243 Backend fBackend;
242 GLContextType fContextType; 244 GLContextType fContextType;
245 bool fRunByDefault;
243 } gConfigs[] = { 246 } gConfigs[] = {
244 { SkBitmap::kNo_Config, "NONRENDERING", kNonRendering_Backend, kD ontCareGLCtxType }, 247 { SkBitmap::kNo_Config, "NONRENDERING", 0, kNonRendering_Backend, kD ontCareGLCtxType, true },
245 { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, kDontCar eGLCtxType }, 248 { SkBitmap::kARGB_8888_Config, "8888", 0, kRaster_Backend, kD ontCareGLCtxType, true },
246 { SkBitmap::kRGB_565_Config, "565", kRaster_Backend, kDontCar eGLCtxType }, 249 { SkBitmap::kRGB_565_Config, "565", 0, kRaster_Backend, kD ontCareGLCtxType, true },
247 #if SK_SUPPORT_GPU 250 #if SK_SUPPORT_GPU
248 { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, GrContextFa ctory::kNative_GLContextType }, 251 { SkBitmap::kARGB_8888_Config, "GPU", 0, kGPU_Backend, Gr ContextFactory::kNative_GLContextType, true },
252 { SkBitmap::kARGB_8888_Config, "MSAA4", 4, kGPU_Backend, Gr ContextFactory::kNative_GLContextType, false },
253 { SkBitmap::kARGB_8888_Config, "MSAA16", 16, kGPU_Backend, Gr ContextFactory::kNative_GLContextType, false },
249 #if SK_ANGLE 254 #if SK_ANGLE
250 { SkBitmap::kARGB_8888_Config, "ANGLE", kGPU_Backend, GrContextFa ctory::kANGLE_GLContextType }, 255 { SkBitmap::kARGB_8888_Config, "ANGLE", 0, kGPU_Backend, Gr ContextFactory::kANGLE_GLContextType, true },
251 #endif // SK_ANGLE 256 #endif // SK_ANGLE
252 #ifdef SK_DEBUG 257 #ifdef SK_DEBUG
253 { SkBitmap::kARGB_8888_Config, "Debug", kGPU_Backend, GrContextFa ctory::kDebug_GLContextType }, 258 { SkBitmap::kARGB_8888_Config, "Debug", 0, kGPU_Backend, Gr ContextFactory::kDebug_GLContextType, GR_DEBUG },
254 #endif // SK_DEBUG 259 #endif // SK_DEBUG
255 { SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, GrContextFa ctory::kNull_GLContextType }, 260 { SkBitmap::kARGB_8888_Config, "NULLGPU", 0, kGPU_Backend, Gr ContextFactory::kNull_GLContextType, true },
256 #endif // SK_SUPPORT_GPU 261 #endif // SK_SUPPORT_GPU
257 }; 262 };
258 263
259 static int findConfig(const char config[]) { 264 static int findConfig(const char config[]) {
260 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { 265 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
261 if (!strcmp(config, gConfigs[i].fName)) { 266 if (!strcmp(config, gConfigs[i].fName)) {
262 return i; 267 return i;
263 } 268 }
264 } 269 }
265 return -1; 270 return -1;
266 } 271 }
267 272
268 static bool skip_name(const SkTDArray<const char*> array, const char name[]) { 273 static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
269 if (0 == array.count()) { 274 if (0 == array.count()) {
270 // no names, so don't skip anything 275 // no names, so don't skip anything
271 return false; 276 return false;
272 } 277 }
273 for (int i = 0; i < array.count(); ++i) { 278 for (int i = 0; i < array.count(); ++i) {
274 if (strstr(name, array[i])) { 279 if (strstr(name, array[i])) {
275 // found the name, so don't skip 280 // found the name, so don't skip
276 return false; 281 return false;
277 } 282 }
278 } 283 }
279 return true; 284 return true;
280 } 285 }
281 286
282 static void help() { 287 static void help() {
288 SkString configsStr;
289 static const size_t kConfigCount = SK_ARRAY_COUNT(gConfigs);
290 for (size_t i = 0; i < kConfigCount; ++i) {
291 configsStr.appendf("%s%s", gConfigs[i].fName, ((i == kConfigCount - 1) ? "" : "|"));
292 }
293
283 SkDebugf("Usage: bench [-o outDir] [--repeat nr] [--logPerIter] " 294 SkDebugf("Usage: bench [-o outDir] [--repeat nr] [--logPerIter] "
284 "[--timers [wcgWC]*] [--rotate]\n" 295 "[--timers [wcgWC]*] [--rotate]\n"
285 " [--scale] [--clip] [--min] [--forceAA 1|0] [--forceFilter 1|0] \n" 296 " [--scale] [--clip] [--min] [--forceAA 1|0] [--forceFilter 1|0] \n"
286 " [--forceDither 1|0] [--forceBlend 1|0]" 297 " [--forceDither 1|0] [--forceBlend 1|0]"
287 #if SK_SUPPORT_GPU 298 #if SK_SUPPORT_GPU
288 " [--gpuCacheSize <bytes> <count>]" 299 " [--gpuCacheSize <bytes> <count>]"
289 #endif 300 #endif
290 "\n" 301 "\n"
291 " [--strokeWidth width] [--match name]\n" 302 " [--strokeWidth width] [--match name]\n"
292 " [--mode normal|deferred|deferredSilent|record|picturerecord]\n " 303 " [--mode normal|deferred|deferredSilent|record|picturerecord]\n "
293 " [--config 8888|565|GPU|ANGLE|NULLGPU] [-Dfoo bar] [--logFile f ilename]\n" 304 " [--config ");
294 " [-h|--help]"); 305 SkDebugf("%s]\n", configsStr.c_str());
306 SkDebugf(" [-Dfoo bar] [--logFile filename] [-h|--help]");
295 SkDebugf("\n\n"); 307 SkDebugf("\n\n");
296 SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n"); 308 SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n");
297 SkDebugf(" --repeat nr : Each bench repeats for nr times.\n"); 309 SkDebugf(" --repeat nr : Each bench repeats for nr times.\n");
298 SkDebugf(" --logPerIter : " 310 SkDebugf(" --logPerIter : "
299 "Log each repeat timer instead of mean, default is disabled.\n"); 311 "Log each repeat timer instead of mean, default is disabled.\n");
300 SkDebugf(" --timers [wcgWC]* : " 312 SkDebugf(" --timers [wcgWC]* : "
301 "Display wall, cpu, gpu, truncated wall or truncated cpu time for e ach bench.\n"); 313 "Display wall, cpu, gpu, truncated wall or truncated cpu time for e ach bench.\n");
302 SkDebugf(" --rotate : Rotate before each bench runs.\n"); 314 SkDebugf(" --rotate : Rotate before each bench runs.\n");
303 SkDebugf(" --scale : Scale before each bench runs.\n"); 315 SkDebugf(" --scale : Scale before each bench runs.\n");
304 SkDebugf(" --clip : Clip before each bench runs.\n"); 316 SkDebugf(" --clip : Clip before each bench runs.\n");
(...skipping 15 matching lines...) Expand all
320 SkDebugf(" --match name : Only run bench whose name is matched.\n"); 332 SkDebugf(" --match name : Only run bench whose name is matched.\n");
321 SkDebugf(" --mode normal|deferred|deferredSilent|record|picturerecord :\n " 333 SkDebugf(" --mode normal|deferred|deferredSilent|record|picturerecord :\n "
322 " Run in the corresponding mode\n" 334 " Run in the corresponding mode\n"
323 " normal, Use a normal canvas to draw to;\n" 335 " normal, Use a normal canvas to draw to;\n"
324 " deferred, Use a deferrred canvas when drawing;\n" 336 " deferred, Use a deferrred canvas when drawing;\n"
325 " deferredSilent, deferred with silent playback;\n" 337 " deferredSilent, deferred with silent playback;\n"
326 " record, Benchmark the time to record to an SkPict ure;\n" 338 " record, Benchmark the time to record to an SkPict ure;\n"
327 " picturerecord, Benchmark the time to do record fr om a \n" 339 " picturerecord, Benchmark the time to do record fr om a \n"
328 " SkPicture to a SkPicture.\n"); 340 " SkPicture to a SkPicture.\n");
329 SkDebugf(" --logFile filename : destination for writing log output, in ad dition to stdout.\n"); 341 SkDebugf(" --logFile filename : destination for writing log output, in ad dition to stdout.\n");
330 SkDebugf(" --config "); 342 SkDebugf(" --config %s:\n", configsStr.c_str());
331 static const size_t kConfigCount = SK_ARRAY_COUNT(gConfigs); 343 SkDebugf(" Run bench in corresponding config mode.\n");
332 for (size_t i = 0; i < kConfigCount; ++i) {
333 SkDebugf("%s%s", gConfigs[i].fName, ((i == kConfigCount - 1) ? "" : "|") );
334 }
335 SkDebugf(" : Run bench in corresponding config mode.\n");
336 SkDebugf(" -Dfoo bar : Add extra definition to bench.\n"); 344 SkDebugf(" -Dfoo bar : Add extra definition to bench.\n");
337 SkDebugf(" -h|--help : Show this help message.\n"); 345 SkDebugf(" -h|--help : Show this help message.\n");
338 } 346 }
339 347
340 int tool_main(int argc, char** argv); 348 int tool_main(int argc, char** argv);
341 int tool_main(int argc, char** argv) { 349 int tool_main(int argc, char** argv) {
342 #if SK_ENABLE_INST_COUNT 350 #if SK_ENABLE_INST_COUNT
343 gPrintInstCount = true; 351 gPrintInstCount = true;
344 #endif 352 #endif
345 SkAutoGraphics ag; 353 SkAutoGraphics ag;
(...skipping 26 matching lines...) Expand all
372 float strokeWidth; 380 float strokeWidth;
373 SkTDArray<const char*> fMatches; 381 SkTDArray<const char*> fMatches;
374 benchModes benchMode = kNormal_benchModes; 382 benchModes benchMode = kNormal_benchModes;
375 SkString perIterTimeformat("%.2f"); 383 SkString perIterTimeformat("%.2f");
376 SkString normalTimeFormat("%6.2f"); 384 SkString normalTimeFormat("%6.2f");
377 385
378 SkString outDir; 386 SkString outDir;
379 SkBitmap::Config outConfig = SkBitmap::kNo_Config; 387 SkBitmap::Config outConfig = SkBitmap::kNo_Config;
380 const char* configName = ""; 388 const char* configName = "";
381 Backend backend = kRaster_Backend; // for warning 389 Backend backend = kRaster_Backend; // for warning
390 int sampleCount = 0;
382 SkTDArray<int> configs; 391 SkTDArray<int> configs;
383 bool userConfig = false; 392 bool userConfig = false;
384 393
385 SkBenchLogger logger; 394 SkBenchLogger logger;
386 395
387 char* const* stop = argv + argc; 396 char* const* stop = argv + argc;
388 for (++argv; argv < stop; ++argv) { 397 for (++argv; argv < stop; ++argv) {
389 if (strcmp(*argv, "-o") == 0) { 398 if (strcmp(*argv, "-o") == 0) {
390 argv++; 399 argv++;
391 if (argv < stop && **argv) { 400 if (argv < stop && **argv) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 && !outDir.isEmpty()) { 590 && !outDir.isEmpty()) {
582 logger.logError("'--mode record' and '--mode picturerecord' are not" 591 logger.logError("'--mode record' and '--mode picturerecord' are not"
583 " compatible with -o.\n"); 592 " compatible with -o.\n");
584 return -1; 593 return -1;
585 } 594 }
586 if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchMod es)) { 595 if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchMod es)) {
587 perIterTimeformat.set("%.4f"); 596 perIterTimeformat.set("%.4f");
588 normalTimeFormat.set("%6.4f"); 597 normalTimeFormat.set("%6.4f");
589 } 598 }
590 if (!userConfig) { 599 if (!userConfig) {
591 // if no config is specified by user, we add them all. 600 // if no config is specified by user, add the default configs
592 for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { 601 for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
593 *configs.append() = i; 602 if (gConfigs[i].fRunByDefault) {
603 *configs.append() = i;
604 }
594 } 605 }
595 } 606 }
596 if (kNormal_benchModes != benchMode) { 607 if (kNormal_benchModes != benchMode) {
597 // Non-rendering configs only run in normal mode 608 // Non-rendering configs only run in normal mode
598 for (int i = 0; i < configs.count(); ++i) { 609 for (int i = 0; i < configs.count(); ++i) {
599 int configIdx = configs[i]; 610 int configIdx = configs[i];
600 if (kNonRendering_Backend == gConfigs[configIdx].fBackend) { 611 if (kNonRendering_Backend == gConfigs[configIdx].fBackend) {
601 configs.remove(i, 1); 612 configs.remove(i, 1);
602 --i; 613 --i;
603 } 614 }
604 } 615 }
605 } 616 }
606 617
618 #if SK_SUPPORT_GPU
619 for (int i = 0; i < configs.count(); ++i) {
620 int configIdx = configs[i];
621
622 if (kGPU_Backend == gConfigs[configIdx].fBackend && gConfigs[configIdx]. fSampleCnt > 0) {
623 GrContext* context = gContextFactory.get(gConfigs[configIdx].fContex tType);
624 if (NULL == context) {
625 SkString error;
626 error.printf("Error creating GrContext for config %s. Config wil l be skipped.\n",
627 gConfigs[configIdx].fName);
628 logger.logError(error.c_str());
629 configs.remove(i);
630 --i;
631 continue;
632 }
633 if (gConfigs[configIdx].fSampleCnt > context->getMaxSampleCount()){
634 SkString error;
635 error.printf("Sample count (%d) for config %s is unsupported. Co nfig will be skipped.\n",
636 gConfigs[configIdx].fSampleCnt, gConfigs[configIdx] .fName);
637 logger.logError(error.c_str());
638 configs.remove(i);
639 --i;
640 continue;
641 }
642 }
643 }
644 #endif
645
607 // report our current settings 646 // report our current settings
608 { 647 {
609 SkString str; 648 SkString str;
610 const char* deferredMode = benchMode == kDeferred_benchModes ? "yes" : 649 const char* deferredMode = benchMode == kDeferred_benchModes ? "yes" :
611 (benchMode == kDeferredSilent_benchModes ? "silent" : "no"); 650 (benchMode == kDeferredSilent_benchModes ? "silent" : "no");
612 str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d " 651 str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d "
613 "deferred=%s logperiter=%d", 652 "deferred=%s logperiter=%d",
614 forceAlpha, forceAA, forceFilter, deferredMode, 653 forceAlpha, forceAA, forceFilter, deferredMode,
615 logPerIter); 654 logPerIter);
616 str.appendf(" rotate=%d scale=%d clip=%d min=%d", 655 str.appendf(" rotate=%d scale=%d clip=%d min=%d",
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 760 }
722 } else { 761 } else {
723 if (!bench->isRendering()) { 762 if (!bench->isRendering()) {
724 continue; 763 continue;
725 } 764 }
726 } 765 }
727 766
728 outConfig = gConfigs[configIndex].fConfig; 767 outConfig = gConfigs[configIndex].fConfig;
729 configName = gConfigs[configIndex].fName; 768 configName = gConfigs[configIndex].fName;
730 backend = gConfigs[configIndex].fBackend; 769 backend = gConfigs[configIndex].fBackend;
770 sampleCount = gConfigs[configIndex].fSampleCnt;
731 GrContext* context = NULL; 771 GrContext* context = NULL;
732 BenchTimer* timer = timers[configIndex]; 772 BenchTimer* timer = timers[configIndex];
733 773
734 #if SK_SUPPORT_GPU 774 #if SK_SUPPORT_GPU
735 SkGLContextHelper* glContext = NULL; 775 SkGLContextHelper* glContext = NULL;
736 if (kGPU_Backend == backend) { 776 if (kGPU_Backend == backend) {
737 context = gContextFactory.get(gConfigs[configIndex].fContextType ); 777 context = gContextFactory.get(gConfigs[configIndex].fContextType );
738 if (NULL == context) { 778 if (NULL == context) {
739 continue; 779 continue;
740 } 780 }
741 glContext = gContextFactory.getGLContext(gConfigs[configIndex].f ContextType); 781 glContext = gContextFactory.getGLContext(gConfigs[configIndex].f ContextType);
742 } 782 }
743 #endif 783 #endif
744 SkDevice* device = NULL; 784 SkDevice* device = NULL;
745 SkCanvas* canvas = NULL; 785 SkCanvas* canvas = NULL;
746 SkPicture pictureRecordFrom; 786 SkPicture pictureRecordFrom;
747 SkPicture pictureRecordTo; 787 SkPicture pictureRecordTo;
748 788
749 if (kNonRendering_Backend != backend) { 789 if (kNonRendering_Backend != backend) {
750 device = make_device(outConfig, dim, backend, context); 790 device = make_device(outConfig, dim, backend, sampleCount, conte xt);
751 791
752 switch(benchMode) { 792 switch(benchMode) {
753 case kDeferredSilent_benchModes: 793 case kDeferredSilent_benchModes:
754 case kDeferred_benchModes: 794 case kDeferred_benchModes:
755 canvas = new SkDeferredCanvas(device); 795 canvas = new SkDeferredCanvas(device);
756 break; 796 break;
757 case kRecord_benchModes: 797 case kRecord_benchModes:
758 canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY, 798 canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY,
759 SkPicture::kUsePathBoundsForClip_RecordingFlag); 799 SkPicture::kUsePathBoundsForClip_RecordingFlag);
760 canvas->ref(); 800 canvas->ref();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 954 }
915 955
916 return 0; 956 return 0;
917 } 957 }
918 958
919 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 959 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
920 int main(int argc, char * const argv[]) { 960 int main(int argc, char * const argv[]) {
921 return tool_main(argc, (char**) argv); 961 return tool_main(argc, (char**) argv);
922 } 962 }
923 #endif 963 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrContext.h » ('j') | src/gpu/GrDrawTarget.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698