gfxbench.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* gfxbench: time the software drawing paths, so each rendering step can be
  2. * measured on target instead of guessed.
  3. *
  4. * The fill/copy/cell/canvas cases run against a screen-sized RAM layer, which
  5. * is what the window manager draws into (the shadow buffer), and the flush
  6. * case times the real shadow -> VRAM copy. The screen itself is never
  7. * disturbed: no drawing lands in the shadow, so the flush copies the WM's
  8. * unchanged content. */
  9. #include "blit.h"
  10. #include "cpu.h"
  11. #include "fbtext.h"
  12. #include "gfx.h"
  13. #include "io.h"
  14. #include "mm.h"
  15. #include "timer.h"
  16. #include "vga.h"
  17. #define LAYER_W 1280
  18. #define LAYER_H 1024
  19. #define CONTENT_W 514
  20. #define CONTENT_H 320
  21. #define WIN_W 514
  22. #define WIN_H 338
  23. #define CELLS_COLS 64
  24. #define CELLS_ROWS 32
  25. static void put_dec(unsigned int n)
  26. {
  27. char buf[11];
  28. unsigned int i = sizeof(buf);
  29. if (n == 0) {
  30. io_putchar('0');
  31. return;
  32. }
  33. while (n && i) {
  34. buf[--i] = (char)('0' + n % 10);
  35. n /= 10;
  36. }
  37. while (i < sizeof(buf))
  38. io_putchar(buf[i++]);
  39. }
  40. static void bench(const char *name, unsigned int n, unsigned int bytes,
  41. unsigned int ms)
  42. {
  43. io_putstr(name);
  44. io_putstr(" ");
  45. put_dec(n);
  46. io_putstr("x ");
  47. put_dec(ms);
  48. io_putstr(" ms");
  49. if (ms) {
  50. /* 32-bit friendly MB/s: bytes/1024 is small enough to scale. */
  51. unsigned int kbs = (bytes / 1024) * n;
  52. unsigned int mbs = (kbs * 1000 / ms) / 1024;
  53. io_putstr(" ");
  54. put_dec(mbs);
  55. io_putstr(" MB/s");
  56. }
  57. io_putstr("\n");
  58. }
  59. static unsigned char *alloc_pages(unsigned int bytes)
  60. {
  61. unsigned int pages = (bytes + 4095) / 4096;
  62. return (unsigned char *)mm_alloc_pages(pages);
  63. }
  64. static void free_pages(unsigned char *p, unsigned int bytes)
  65. {
  66. unsigned int pages = (bytes + 4095) / 4096;
  67. unsigned int i;
  68. for (i = 0; i < pages; i++)
  69. mm_free_page((unsigned int)p + i * 4096);
  70. }
  71. void program_gfxbench_main(void)
  72. {
  73. struct surface layer;
  74. struct gfx_canvas canvas;
  75. unsigned short *cells;
  76. unsigned char *layer_px, *cell_px;
  77. unsigned int t0, t1, i;
  78. unsigned int layer_bytes = LAYER_W * LAYER_H * 4;
  79. io_putstr("gfxbench (sse2: ");
  80. io_putstr(cpu_has_sse2() ? "yes" : "no");
  81. io_putstr(", lfb wc: ");
  82. io_putstr(vga_fb_lfb_wc() ? "yes" : "no");
  83. io_putstr(")\n");
  84. layer_px = alloc_pages(layer_bytes);
  85. if (!layer_px) {
  86. io_putstr("gfxbench: out of memory\n");
  87. return;
  88. }
  89. layer.px = layer_px;
  90. layer.w = LAYER_W;
  91. layer.h = LAYER_H;
  92. layer.pitch = LAYER_W * 4;
  93. layer.bpp = 32;
  94. layer.alpha = 255;
  95. vga_set_target(&layer);
  96. /* Full-screen fill: what a full redraw costs. */
  97. t0 = get_ticks_ms();
  98. for (i = 0; i < 10; i++)
  99. blit->fill(0, 0, LAYER_W, LAYER_H, 0x203040);
  100. t1 = get_ticks_ms();
  101. bench("fill screen ", 10, layer_bytes, t1 - t0);
  102. /* Window content fill (the per-cell background). */
  103. t0 = get_ticks_ms();
  104. for (i = 0; i < 100; i++)
  105. blit->fill(0, 0, CONTENT_W, CONTENT_H, 0x000000);
  106. t1 = get_ticks_ms();
  107. bench("fill content", 100, CONTENT_W * CONTENT_H * 4, t1 - t0);
  108. /* Window move: an overlapping rect copy, as a drag step does. */
  109. t0 = get_ticks_ms();
  110. for (i = 0; i < 100; i++)
  111. blit->copy(1, 1, 0, 0, WIN_W, WIN_H);
  112. t1 = get_ticks_ms();
  113. bench("copy window ", 100, WIN_W * WIN_H * 4, t1 - t0);
  114. /* Cell grid: a whole terminal content repaint (glyph blitting). */
  115. cell_px = alloc_pages(CELLS_COLS * CELLS_ROWS * 2);
  116. if (cell_px) {
  117. cells = (unsigned short *)cell_px;
  118. for (i = 0; i < CELLS_COLS * CELLS_ROWS; i++)
  119. cells[i] = (unsigned short)(0x0A00 | ('A' + (i % 26)));
  120. t0 = get_ticks_ms();
  121. for (i = 0; i < 50; i++)
  122. fbtext_draw_cells_clip(cells, CELLS_COLS, CELLS_ROWS,
  123. 0, 0, 0, 0, CELLS_COLS * 8, CELLS_ROWS * 10);
  124. t1 = get_ticks_ms();
  125. bench("cells 64x32 ", 50, CELLS_COLS * CELLS_ROWS * 80 * 4, t1 - t0);
  126. free_pages(cell_px, CELLS_COLS * CELLS_ROWS * 2);
  127. }
  128. /* Canvas presentation: RGB565 -> 32 bpp expansion. */
  129. if (gfx_alloc(&canvas, CONTENT_W, CONTENT_H) == 0) {
  130. for (i = 0; i < CONTENT_W * CONTENT_H; i++)
  131. canvas.px[i] = (unsigned short)(i * 7);
  132. t0 = get_ticks_ms();
  133. for (i = 0; i < 20; i++)
  134. blit->canvas(&canvas, 0, 0, 0, 0, CONTENT_W, CONTENT_H);
  135. t1 = get_ticks_ms();
  136. bench("canvas 565 ", 20, CONTENT_W * CONTENT_H * 4, t1 - t0);
  137. gfx_free(&canvas);
  138. }
  139. vga_set_target(0);
  140. /* Flush: shadow -> VRAM. This is the copy the WM runs; it uses
  141. * streaming stores because rep movsl does not combine on the VRAM
  142. * path. Report the bytes
  143. * the presenter really copied: a long flush can be preempted, and a
  144. * flush started while another process is inside one is skipped. */
  145. {
  146. unsigned int before = vga_present_copied;
  147. t0 = get_ticks_ms();
  148. for (i = 0; i < 2; i++) {
  149. vga_fb_mark_dirty_rect(0, vga_fb_height());
  150. vga_fb_flush();
  151. }
  152. t1 = get_ticks_ms();
  153. /* one "run" whose size is the bytes actually copied */
  154. bench("flush screen", 1, vga_present_copied - before, t1 - t0);
  155. }
  156. free_pages(layer_px, layer_bytes);
  157. }