GSoC #07 VBE double buffering (vs r1885)
A message that is not in the archive (sent off-list or not yet received): 1745824252.39921223234235570.JavaMail.root@aczmb1
Quoted 6 lines · Colin D Bennett
However, in double buffered mode the last rendered frame might not be in the back buffer after calling
swap_buffers, depending on the double buffering strategy selected at runtime:1. page flipping is in use
2. back buffer is in main memory
With a little bookkeeping you can avoid having to redraw the whole screen. Here are some strategies:
(double buffering with page flipping and drawing to main memory)
Draw to a buffer in main memory. Maintain a list of changed regions. This is your list of dirty rectangles. After completing a frame, blit the dirty rectangles to the page that's about to get flipped into view. Age all dirty rectangles by one frame, and remove all dirty rectangles that were previously aged. If the dirty rectangle list gets too long, just blit the whole screen. Clever algorithms can combine dirty rectangles to save memory.
(double buffering with page flipping without drawing to main memory)
Draw to the back buffer, and maintain a dirty rectangle list. Immediately after vertical retrace start, flip pages, and blit the dirty rectangles to the new back buffer from the (now being displayed) old back buffer. Empty the dirty rectangle list.
(double buffering without page flipping)
Draw to a buffer in main memory, and maintain a dirty rectangle list. During vertical retrace, blit the dirty rectangles to VRAM. Empty the dirty rectangle list.
(single buffering with minimal shearing)
Draw to VRAM. Wait for the start of vertical retrace before drawing. Hopefully all drawing can complete before the monitor gets repainted.
(single buffering)
Draw to VRAM.
Disclaimer: I don't actually know what you're trying to do (plain text, drop shadows, animation, 3D graphics... no clue), so the stuff I suggest might be overkill. Nevertheless, I hope it is helpful.
Signature · 2 lines
Andy Goth | http://andy.junkdrome.org/
unununium@{aircanopy.net,openverse.com}Quoted 40 lines · On Sun, 5 Oct 2008 14:17:42 -0500 (CDT) Andy Goth <[email protected]>…
Quoted 6 lines · Colin D Bennett
However, in double buffered mode the last rendered frame might not be in the back buffer after calling
swap_buffers, depending on the double buffering strategy selected at runtime:1. page flipping is in use
2. back buffer is in main memoryWith a little bookkeeping you can avoid having to redraw the whole screen. Here are some strategies:
(double buffering with page flipping and drawing to main memory)
Draw to a buffer in main memory. Maintain a list of changed regions. This is your list of dirty rectangles. After completing a frame, blit the dirty rectangles to the page that's about to get flipped into view. Age all dirty rectangles by one frame, and remove all dirty rectangles that were previously aged. If the dirty rectangle list gets too long, just blit the whole screen. Clever algorithms can combine dirty rectangles to save memory.
(double buffering with page flipping without drawing to main memory)
Draw to the back buffer, and maintain a dirty rectangle list. Immediately after vertical retrace start, flip pages, and blit the dirty rectangles to the new back buffer from the (now being displayed) old back buffer. Empty the dirty rectangle list.
(double buffering without page flipping)
Draw to a buffer in main memory, and maintain a dirty rectangle list. During vertical retrace, blit the dirty rectangles to VRAM. Empty the dirty rectangle list.
(single buffering with minimal shearing)
Draw to VRAM. Wait for the start of vertical retrace before drawing. Hopefully all drawing can complete before the monitor gets repainted.
Quoted 7 lines
(single buffering)
Draw to VRAM.
Disclaimer: I don't actually know what you're trying to do (plain text, drop shadows, animation, 3D graphics... no clue), so the stuff I suggest might be overkill. Nevertheless, I hope it is helpful.
Thanks for the ideas. Also, I know it is possible to write code that is optimal for each case, my plan is to avoid complicated dirty-region repaint strategies at first. ("First make it work, then make it rock.") After everything is working, then we can profile and do performance optimization. After everything is functioning and performance bottlenecks are identified, then we can perhaps use some techniques like you suggest.
Thanks,
Colin
Quoted 1 line · Colin D Bennett
First make it work, then make it rock.
I certainly do appreciate that, but...
Quoted 2 lines
my plan is to avoid complicated dirty-region repaint strategies at first.
Requiring full-screen repaints is an architectural design that might need rework to undo later. Or might not, depending on how you implement it. The interim approach you choose now should be informed by foresight.
Full-screen repaint approach that will require rework later:
- One function draws everything in sequence. It gets called every frame.
Full-screen repaint approach that will be easy to integrate into a partial update scheme:
- A separate function exists for drawing each logical unit of the screen.
- Every frame, one function calls all the separate functions in sequence.
Or something like that.
Signature · 2 lines
Andy Goth | http://andy.junkdrome.org/
unununium@{aircanopy.net,openverse.com}Quoted 12 lines · Andy Goth
Quoted 1 line · Colin D Bennett
First make it work, then make it rock.
I certainly do appreciate that, but...
Quoted 2 lines
my plan is to avoid complicated dirty-region repaint strategies at first.
Requiring full-screen repaints is an architectural design that might need rework to undo later. Or might not, depending on how you implement it. The interim approach you choose now should be informed by foresight.
Full-screen repaint approach that will require rework later:
Quoted 8 lines
- One function draws everything in sequence. It gets called every frame.
Full-screen repaint approach that will be easy to integrate into a partial update scheme:
- A separate function exists for drawing each logical unit of the screen.
- Every frame, one function calls all the separate functions in sequence.Or something like that.
Hi,
I would like to thank Andy for his comments on the topic. I do share the same concern about designing double buffering to work properly without making hasty implementation first. We can use non-buffered solution as a first stage "hasty implementation" and design good enough solution to handle double buffering well.
Dirty rectangles for every buffer (two in double buffer case) might be the best approach here. I think there is some kind of dirty rectangle implementation on gfxterm so that could be used as a base for this work. After that it could be improved to increase performance but the main point being that there has to be proper framework to make it work properly.
Usually the slowest step is to transfer image data from main memory to video memory (and usually the slowest is to read from video memory to main memory and then save it back to video memory). If we can optimize memory copies between video and main memories we are on good track to solve speed problem.
Thanks,
Vesa Jääskeläinen
Quoted 22 lines · On Mon, 06 Oct 2008 22:02:46 +0300 Vesa Jääskeläinen <[email protected]> wrote:
Quoted 5 lines · Andy Goth
"Colin D Bennett" <[email protected]> wrote:
Requiring full-screen repaints is an architectural design that might need rework to undo later. Or might not, depending on how you implement it. The interim approach you choose now should be informed by foresight.[...]
Hi,I would like to thank Andy for his comments on the topic. I do share the same concern about designing double buffering to work properly without making hasty implementation first. We can use non-buffered solution as a first stage "hasty implementation" and design good enough solution to handle double buffering well.
Dirty rectangles for every buffer (two in double buffer case) might be the best approach here. I think there is some kind of dirty rectangle implementation on gfxterm so that could be used as a base for this work. After that it could be improved to increase performance but the main point being that there has to be proper framework to make it work properly.
Quoted 5 lines
Usually the slowest step is to transfer image data from main memory to video memory (and usually the slowest is to read from video memory to main memory and then save it back to video memory). If we can optimize memory copies between video and main memories we are on good track to solve speed problem.
I agree that a dirty region repaint management system will provide better performance, but I certainly do not have time to implement it now. IMO that would take a lot of work.
I *am* interested in getting high performance, but
(1) I simply don't have time to do it myself right now, and
(2) gfxmenu seems plenty fast to me--I have run Lua-driven full screen animations as a desktop background for gfxmenu, and it worked fantastically. The menu system performs decently even on my ultra-low-power-but-low-performance-too Via C3 system.
Granted, the gfxterm terminal is nearly unusable right now, but I think its performance can be improved significantly through a few relatively minor changes.
Regards,
Colin
Quoted 6 lines · On Mon, 13 Oct 2008 09:48:15 -0700 Colin D Bennett <[email protected]> wrote:
I *am* interested in getting high performance, but
(1) I simply don't have time to do it myself right now, and
(2) gfxmenu seems plenty fast to me--I have run Lua-driven full screen animations as a desktop background for gfxmenu, and it worked fantastically. The menu system performs decently even on my ultra-low-power-but-low-performance-too Via C3 system.
Another reason I did not implement dirty region repaint optimization that I forgot to mention:
(3) Dirty region repaint handling does not help at all when most of the screen is being updated on each frame. Since I expect the "fancy menu" to become more and more full of eye-candy (that is the purpose, after all!), the dirty region handling would only help for the most vanilla of themes. I have said I will add some animation and special effects to GRUB. Things that I think would be cool (and cool => more people drawn to use GRUB) include a fade-in/fade-out when GRUB starts/executes an entry, a fully animated background of some sort (of the type that many xscreensavers use), etc.
Regards,
Colin