What is the best/fastest practise to redraw the screen?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kashimoto
Posts: 8
Joined: Wed Nov 25, 2020 4:00 pm

What is the best/fastest practise to redraw the screen?

Post 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!
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Re: What is the best/fastest practise to redraw the screen?

Post 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.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: What is the best/fastest practise to redraw the screen?

Post 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
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: What is the best/fastest practise to redraw the screen?

Post 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.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
Post Reply