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!
What is the best/fastest practise to redraw the screen?
Re: What is the best/fastest practise to redraw the screen?
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.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!
Re: What is the best/fastest practise to redraw the screen?
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
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?
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.
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
Discord:https://discord.gg/zn2vV2Su