Frames per second

Changed to display FPS using yesterday’s timer interrupt.
When I tested, it was 120 FPS @ 640×480, 16-17 FPS @ 1920 x 1080 just to fill whole display with a solid color.
Then I added FillRect() and it decreased to 95 FPS @ 640×480 with 3 rectangles.

It’ll be a bit better if I add 8×8 between 32×32 and 1×1, but I didn’t do that today. Even with that, it looks this pixel by pixel draw is too slow if I add more objects. Perhaps I should do block-copy of tiles and sprites.

void FillRect(int x, int y, int width, int height, char color) {
  // left ... draw pixel by pixel
  int x1 = x;
  int x2 = ((x + 31) / 32) * 32;
  if (x1 != x2) {
    char *p8 = (char *)fbRequest.fbBaseAddress;
    p8 += y * kWidth + x1;
    for (int yy = y; yy < y + height; yy++) {
      for (int xx = x1; xx < x2; xx++) {
        *p8++ = color;
      }
      p8 += kWidth - (x2 - x1);
    }
  }

  // center draw 32 pixels at once
  int x3 = ((x + width) / 32) * 32;
  if (x2 != x3) {
    uint32_t *p = (uint32_t *)fbRequest.fbBaseAddress;
    p += (y * kWidth + x2) / 4;
    for (int yy = y; yy < y + height; yy++) {
      for (int xx = x2; xx < x3; xx += 4 * 8) {
        int32_t c = color << 24 | color << 16 | color << 8 | color;
        *p++ = c;
        *p++ = c;
        *p++ = c;
        *p++ = c;
        *p++ = c;
        *p++ = c;
        *p++ = c;
        *p++ = c;
      }
      p += (kWidth - (x3 - x2)) / 4;
    }
  }

  // right ... draw pixel by pixel
  int x4 = x + width;
  if (x3 != x4) {
    char *p8 = (char *)fbRequest.fbBaseAddress;
    p8 += y * kWidth + x3;
    for (int yy = y; yy < y + height; yy++) {
      for (int xx = x3; xx < x4; xx++) {
        *p8++ = color;
      }
      p8 += kWidth - (x4 - x3);
    }
  }
}

Today's code: https://github.com/sokoide/rpi-baremetal -> 006_fps.

fps

Leave a Reply

Your email address will not be published. Required fields are marked *