home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / test / source / TestUberblitPerf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  4.4 KB  |  154 lines

  1. #include "test.h"
  2. #include <intrin.h>
  3. #include <vd2/system/vdalloc.h>
  4. #include <vd2/system/time.h>
  5. #include <vd2/Kasumi/pixmap.h>
  6. #include <vd2/Kasumi/pixmapops.h>
  7. #include <vd2/Kasumi/pixmaputils.h>
  8. #include "../../Kasumi/h/uberblit.h"
  9.  
  10. namespace {
  11.     struct PerfEntry {
  12.         int srcFormat;
  13.         int dstFormat;
  14.         double bltSpeed;
  15.         double uberSpeed;
  16.         double ratio;
  17.     };
  18.  
  19.     struct SortPerfEntriesByRatio {
  20.         bool operator()(const PerfEntry& x, const PerfEntry& y) {
  21.             return x.ratio < y.ratio;
  22.         }
  23.     };
  24. }
  25.  
  26. DEFINE_TEST_NONAUTO(UberblitPerf) {
  27.     static const int kFormats[]={
  28.         nsVDPixmap::kPixFormat_Pal1,
  29.         nsVDPixmap::kPixFormat_Pal2,
  30.         nsVDPixmap::kPixFormat_Pal4,
  31.         nsVDPixmap::kPixFormat_Pal8,
  32.         nsVDPixmap::kPixFormat_XRGB1555,        // 4
  33.         nsVDPixmap::kPixFormat_RGB565,
  34.         nsVDPixmap::kPixFormat_RGB888,
  35.         nsVDPixmap::kPixFormat_XRGB8888,
  36.         nsVDPixmap::kPixFormat_Y8,                // 8
  37.         nsVDPixmap::kPixFormat_YUV422_UYVY,
  38.         nsVDPixmap::kPixFormat_YUV422_YUYV,
  39.         nsVDPixmap::kPixFormat_YUV444_Planar,
  40.         nsVDPixmap::kPixFormat_YUV422_Planar,    // 12
  41.         nsVDPixmap::kPixFormat_YUV422_Planar_16F,
  42.         nsVDPixmap::kPixFormat_YUV420_Planar,
  43.         nsVDPixmap::kPixFormat_YUV411_Planar,
  44.         nsVDPixmap::kPixFormat_YUV410_Planar,
  45.         nsVDPixmap::kPixFormat_YUV422_V210,
  46.         nsVDPixmap::kPixFormat_YUV422_UYVY_709,
  47.         nsVDPixmap::kPixFormat_YUV420_NV12
  48.     };
  49.  
  50.     enum {
  51. #if 1
  52.         kSrcStart = 4,
  53.         kDstStart = 4,
  54. #else
  55.         kSrcStart = 9,
  56.         kDstStart = 7,
  57. #endif
  58.         kFormatCount = sizeof(kFormats)/sizeof(kFormats[0])
  59.     };
  60.  
  61.     static const int kSize = 512;
  62.  
  63.     vdautoarrayptr<char> dstbuf(new char[kSize*kSize*4]);
  64.     vdautoarrayptr<char> srcbuf(new char[kSize*kSize*4]);
  65.     uint32 palette[256]={0};
  66.  
  67.     VDPixmap srcPixmaps[kFormatCount];
  68.  
  69.     for(int srcformat = kSrcStart; srcformat < kFormatCount; ++srcformat) {
  70.         VDPixmapLayout layout;
  71.         VDPixmapCreateLinearLayout(layout, kFormats[srcformat], kSize, kSize, 16);
  72.         srcPixmaps[srcformat] = VDPixmapFromLayout(layout, srcbuf.get());
  73.         srcPixmaps[srcformat].palette = palette;
  74.     }
  75.  
  76.     vdfastvector<PerfEntry> perfEntries;
  77.     for(int dstformat = kDstStart; dstformat < kFormatCount; ++dstformat) {
  78. //        dstformat = 5;
  79.  
  80.         VDPixmapLayout layout;
  81.         VDPixmapCreateLinearLayout(layout, kFormats[dstformat], kSize, kSize, 16);
  82.         VDPixmap dstPixmap = VDPixmapFromLayout(layout, srcbuf.get());
  83.         dstPixmap.palette = palette;
  84.  
  85.         const char *dstName = VDPixmapGetInfo(kFormats[dstformat]).name;
  86.  
  87.         for(int srcformat = kSrcStart; srcformat < kFormatCount; ++srcformat) {
  88. //        srcformat = 15;
  89.             const VDPixmap& srcPixmap = srcPixmaps[srcformat];
  90.             const char *srcName = VDPixmapGetInfo(kFormats[srcformat]).name;
  91.  
  92.             uint64 bltTime = (uint64)(sint64)-1;
  93.             for(int i=0; i<10; ++i) {
  94.                 uint64 t1 = VDGetPreciseTick();
  95.                 VDPixmapBlt(dstPixmap, srcPixmap);
  96.                 t1 = VDGetPreciseTick() - t1;
  97.  
  98.                 if (bltTime > t1)
  99.                     bltTime = t1;
  100.             }
  101.  
  102.             vdautoptr<IVDPixmapBlitter> blitter(VDPixmapCreateBlitter(dstPixmap, srcPixmap));
  103.  
  104.             uint64 uberTime = (uint64)(sint64)-1;
  105. //            for(;;)
  106.             {
  107.             for(int i=0; i<10; ++i) {
  108.                 uint64 t1 = VDGetPreciseTick();
  109.                 blitter->Blit(dstPixmap, srcPixmap);
  110.                 t1 = VDGetPreciseTick() - t1;
  111.  
  112.                 if (uberTime > t1)
  113.                     uberTime = t1;
  114.             }
  115.             }
  116.  
  117.             double bltSpeed = (double)(kSize*kSize) / 1000000.0 / (double)bltTime * VDGetPreciseTicksPerSecond();
  118.             double uberSpeed = (double)(kSize*kSize) / 1000000.0 / (double)uberTime * VDGetPreciseTicksPerSecond();
  119.  
  120.             printf("%-20s %-20s %8.2fMP/sec %8.2fMP/sec\n", dstName, srcName, bltSpeed, uberSpeed);
  121.  
  122.             PerfEntry& ent = perfEntries.push_back();
  123.  
  124.             ent.srcFormat = srcformat;
  125.             ent.dstFormat = dstformat;
  126.             ent.bltSpeed = bltSpeed;
  127.             ent.uberSpeed = uberSpeed;
  128.             ent.ratio = uberSpeed / bltSpeed;
  129.         }
  130.     }
  131.  
  132.     std::sort(perfEntries.begin(), perfEntries.end(), SortPerfEntriesByRatio());
  133.  
  134.     printf("\nSlower blitters:\n");
  135.  
  136.     vdfastvector<PerfEntry>::const_iterator it(perfEntries.begin()), itEnd(perfEntries.end());
  137.     int idx;
  138.     for(idx=0; it != itEnd; ++it, ++idx) {
  139.         const PerfEntry& ent = *it;
  140.  
  141.         const char *srcName = VDPixmapGetInfo(kFormats[ent.srcFormat]).name;
  142.         const char *dstName = VDPixmapGetInfo(kFormats[ent.dstFormat]).name;
  143.  
  144.         printf("%-20s %-20s %8.2fMP/sec %8.2fMP/sec (%.1f%%)\n", dstName, srcName, ent.bltSpeed, ent.uberSpeed, ent.ratio*100.0);
  145.  
  146.         if (ent.ratio >= 1.0)
  147.             break;
  148.     }
  149.  
  150.     printf("%d/%d blitters slower.\n", idx, (int)perfEntries.size());
  151.  
  152.     return 0;
  153. }
  154.