Example #1
0
        static void Main(string[] args)
        {
            bool exit = false;

            Console.CancelKeyPress += (s, e) =>
            {
                if (e.SpecialKey == ConsoleSpecialKey.ControlC)
                {
                    e.Cancel = true;
                }
                exit = true;
            };
            long inVBlank = 0;
            var  acc      = new SortedDictionary <int, long>();

            using (var viewport = new ViewportDX(new ViewportParams
            {
                WindowHeight = 1,
                WindowWidth = 1,
                FullScreen = false
            }))
            {
                while (!exit)
                {
                    int  scanline = viewport.GetScanline();
                    long n;
                    if (scanline < 0)
                    {
                        inVBlank++;
                    }
                    else
                    {
                        acc.TryGetValue(scanline, out n);
                        acc[scanline] = n + 1;
                    }
                }
            }
            Console.WriteLine("{0} InVBlank", inVBlank);
            Console.WriteLine("{0} not InVBlank", acc.Values.Sum());
            foreach (var p in acc)
            {
                Console.WriteLine("{0,3}: {1,8}", p.Key, p.Value);
            }
        }
Example #2
0
        void Render()
        {
            long realTicks = sw.ElapsedTicks, dt = realTicks - curTicks;

            //Console.Write(" " + dt/10);
            if (curTicks != long.MinValue)
            {
                double ms     = realTicks * 1e3 / Stopwatch.Frequency;
                double pixels = (ms / ms2pixel) % this.ClientSize.Width;
                //Stats.Add(dt * 1e3 / Stopwatch.Frequency);
                //BiStats.Add(n, ms);
                //curTicks = realTicks;

                // Tested on:
                // YODA. 1920x1018 AMD HD 6570, W7x64 i5-3470 [email protected], Mem speed is ~20GB/s, so
                // 8MB*65 times ~ 0.5GB => / 20 = 2,5% read and 5% copy, should be.
                // SEASHELL. 1366x705, W10x64 i5-3317U [email protected], Mem speed ~15GB/s, so
                // 4MB*65 ~ 0.25GB => /15 = 1.7% read and 3.3% copy.

                // 0. Nop.
                // YODA: 3.3% out of 25%, 65 FPS (max)
                // SEASHELL: 4.3% out of 25%, 64 FPS (max)
                //PlaceBitmapDummy(RazorGFX, tbmp.Bitmap, 0);

                // 1. float DrawImage
                // YODA: 12 FPS, 25%
                // SEASHELL: 64 FPS, 18%
                //float fx = (float)pixels;
                //PlaceBitmapFloat(RazorGFX, tbmp.Bitmap, fx);

                // 2. int DrawImage
                // YODA: 24%, 65 FPS.
                // SEASHELL: 18%, 64 FPS
                int x = (int)pixels;
                //PlaceBitmapInt(RazorGFX, tbmp.Bitmap, x);

                // 3. DrawImageUnscaled
                // YODA: 24%, 65 FPS, no shift, just to try.
                //PlaceBitmapUnscaled(RazorGFX, tbmp.Bitmap, 0);

                // 4. unsafe copy int*w*h + 2*(Lock+Unlock)Bits
                // YODA: 11.6%
                // SEASHELL: 13-14%
                //PlaceBitmapUnsafe(RazorBMP, tbmp.Bitmap, x);

                // 4'. unsafe memcpy (int*w)*h + 2*(Lock+Unlock)Bits
                // YODA: 6.2%
                // SEASHELL: 6.8%
                PlaceBitmapUnsafe2(RazorBMP, tbmp.Bitmap, x);

                // 5. SetDIBitsToDevice + (Lock/Unlock)Bits + (Get/Release)Hdc
                // YODA: 10.0%
                // SeaShell: 11%
                //PlaceBitmapSetDIBitsToDevice(RazorGFX, tbmp.Bitmap, x);

                // 6. BitBlt + 2*(Get/Release)Hdc + GetHBitmap/DeleteObject + 2*SelectObject
                // YODA: 38 FPS, but can be cached (Bitmap.GetHBitmap and hDCs)
                // SeaShell: 50 FPS, 25%
                //PlaceBitmapBitBlt(RazorGFX, tbmp.Bitmap, x);

                // DIBPainter:  YODA 8.9%, SEASHELL 11.0%, mustn't cache destination Graphics!
                // BlitPainter: YODA 9.6%, SEASHELL 12.3%, mustn't cache destination Graphics!
                //painter.PlaceBitmap(x);
                int    scanline = viewport.GetScanline();
                string s        = String.Format(" {0}", scanline < 0 ? "VBLANK" : scanline.ToString());
                RazorGFX.DrawString(s, SystemFonts.CaptionFont, SystemBrushes.Window, 0, 0);
            }

            this.RazorPaint();
            FramesCounter++;
            //Console.Write(" {0,-4:G3}", (sw.ElapsedTicks - realTicks) * 1000d / Stopwatch.Frequency);
        }