Page 1 of 1
What is the best/fastest practise to redraw the screen?
Posted: Tue Dec 22, 2020 6:06 am
by kashimoto
I am using QEmu biosvga with VBE extensions (1024x768x24) with a memory buffer
that i "upload/copy" to the VGA memory when i want to update it.
And it works well.
The issue is : is pretty slow to upload the entire buffer at once after every mouse move.
(If i only copy a portion of it, graphics gets a little bit random.)
How could i optimize the updating routine?
My code is slow? Qemu slow? Should i use a better VGA in it?
Should i not copy big chunks of memory during an interrupt? Then how should i draw it in the "background" not using a lot cpu power to track the elapsed time? Need to use the timer interrupt?
Thanks a lot!
Re: What is the best/fastest practise to redraw the screen?
Posted: Tue Dec 22, 2020 7:26 am
by 8infy
kashimoto wrote:I am using QEmu biosvga with VBE extensions (1024x768x24) with a memory buffer
that i "upload/copy" to the VGA memory when i want to update it.
And it works well.
The issue is : is pretty slow to upload the entire buffer at once after every mouse move.
(If i only copy a portion of it, graphics gets a little bit random.)
How could i optimize the updating routine?
My code is slow? Qemu slow? Should i use a better VGA in it?
Should i not copy big chunks of memory during an interrupt? Then how should i draw it in the "background" not using a lot cpu power to track the elapsed time? Need to use the timer interrupt?
Thanks a lot!
The best practice is to only redraw dirty parts of the screen. E.g you moved a mouse you only redraw the rect where mouse cursor was + the new mouse cursor. You moved a window you only redraw parts of screen where the window was etc etc. Copying the entire buffer is a terrible idea. Also as a simple thing you can do to speed up drawing on real hardware by like 10-20 times is to enabled write-combining for the framebuffer using PAT.
Re: What is the best/fastest practise to redraw the screen?
Posted: Tue Dec 22, 2020 7:37 am
by bzt
Everything that @8infy said, plus use an SIMD copy with prefetch. That's the fastest. (Full disclosure, on some newer Intel boards REP MOVSB can be fast under certain circumstances, look up ERMSB, but since you're copying into MMIO at unaligned addresses
it won't work as expected).
I don't know if you read the buffer, but never do that. Keep a copy of the framebuffer in RAM, as reading RAM is much much faster than reading the video MMIO.
Cheers,
bzt
Re: What is the best/fastest practise to redraw the screen?
Posted: Wed Dec 23, 2020 5:51 am
by bloodline
For my project, I only update dirty rectangles (i.e. rectangles on screen which have changed since the last update, I use the REP MOVSB instruction to copy each horizontal line from the various buffers to the frame buffer, and finally, I only update once every 16ms (which is in essence, a faked 60Hz VBL interrupt).
You can see the results for yourself by trying the disk image from the link in my signature.
-edit- Also I use a 32bit frame buffer as it just makes everything so much easier.