3

I would like to improve the performance of my graphics code by implementing a better kind of double buffering for VESA video memory.

Background:

I wrote a simple Game of Life implementation in x86_64, nasm. It boots in QEMU, switches to 64bit and runs the game from some pseudo-random initial state.

I am using a memory buffer to store the "next" state and at the end of each tick I am copying that entire buffer to video mem location, then zeroing it. In my current case that's almost 2MiBs of data swapped/changed on each tick, probably unnecessarily. This approach worked fine in 320x200x8bpp, but now in VESA 640x480x24bpp it is too slow.

I am sure that there is a better way to do it and my first thought is to simply swap the memory addresses of the buffers. I looked for a way to do it but could not find anything on programming the parameters. I can get the VESA mode info etc., but is there a way to set some values?

Or maybe I am doing it wrong and there is a better/other way to do it?

Some notes:

  • 64bit long mode, no BIOS interrupts available
  • I am writing to a continuous video mem mapped to RAM location @ VBEModeInfo.VidMemBasePtr
Paweł Pela
  • 421
  • 3
  • 16
  • 3
    You may be the first person ever to mention "VESA" and "x64" in the same sentence. :) – Sneftel Jan 21 '16 at 11:31
  • 2
    I don't understand why you clear the buffer. Why not use two buffers which alternate? You then swap the buffer pointers and build the next generation from the one you have. Also, if you use 8 bpp (Vesa mode 0x101) you can reduce the write time, and use the palette value as the cell's life status too. – Weather Vane Jan 21 '16 at 12:34
  • @WeatherVane I rewrote it to match your suggestion. I now use two alternating buffers by swapping pointers. Also, I don't clear the "next" buffer anymore. There is a slight performance boost but it is not enough to redraw the screen in more than ~5fps in QEMU. I am currently in 640x480x24bpp mode - I know 24bpp is a lot of overhead for a simple 1 bit simulation such as Life. It's just for learning purposes (and a lesson has been learned, apparently: "no complete screen redraws at this resolution"). – Paweł Pela Jan 21 '16 at 13:33
  • 1
    I like to use the VBE 3 hardware triple buffering using the 16 bit Big-Realmode with MSDOS 6.22. Small demo for 1024x768x32@100hz refreshrate designed for the most 19" CRT monitors with 96 khz capacity and more: www.alice-dsl.net/freecracmaps/Tool/Neutrip.zip (If no error occur it shows some colored balls moving across the screen and if they reached the border they change their direction.) – Dirk Wolfgang Glomp Jan 21 '16 at 17:28
  • @DirkWolfgangGlomp thanks for the tip! I will look at it. – Paweł Pela Jan 22 '16 at 09:55

0 Answers0