Hacker News new | ask | show | jobs
by kragen 3 days ago
I have not been able to fix it! I've tried a number of different approaches to minimize the glyph-compositing time, but nothing has worked.

So it's faster than memcpy only on hardware like Xeons, not on my Ryzen 5 3500U laptop. Rendering a 1080P frame of dense text on my laptop takes about 4 milliseconds on one core, half of which is compositing the glyphs with a procedural background. By contrast, memcpy takes only 0.8 milliseconds.

Moreover, I've decided that you're basically right about damage tracking, and I was wrong. As long as there's a framebuffer somewhere in the pipeline, and nothing is gratuitously clearing it, redrawing part of that framebuffer will take less work than redrawing all of it, because you don't have to memcpy the part you aren't changing.

And this is true whether the framebuffer is a SysV shared memory segment, a buffer of unified system RAM, VRAM on a discrete GPU card, GDDRAM in an LCD controller chip you're talking to over SPI, or particles of electret floating in the oil of a bistable e-paper electrophoretic display. The kind of work you save is different from one to the next, but damage rectangles save work in every case, even if it's just a little. Even in cases where it doesn't update the display faster, it often extends battery life.

In most of these scenarios, you can scroll the unchanged part of the screen by setting a couple of registers to scan out the pixels in a different order, as you said, so I was pretty much wrong about that too.

In particular, my example, "to scroll the contents of a browser window but not the browser chrome," can be handled by redrawing the browser chrome in a different position over part of the scrolled page. I'm not sure how you would design the graphics API to make this simple, but you can clearly do it.

Similarly, I think it is correct that "reusing previously rendered lines is faster than rendering all text on every frame". I was wrong about that.

1 comments

> Also, as you can easily see, your code has 2× overdraw, visiting the whole framebuffer roughly from beginning to end twice:

Yes I did it for simplicity, as I wanted to get the estimate of how fast or slow can be CPU rendering. Probably I could clear the buffer by small tiles right before rendering text, so that cleared part stays in L1 cache and can be blended faster.

I glanced through your code but it also seems to copy the data from a glyph cache into the buffer, it just has more optimizations to skip some parts.

> I've heard there are ways to allocate your memory buffers such that you get zero-copy scanout in the fullscreen case (GBM_BO_USE_SCANOUT | GBM_BO_USE_LINEAR or DRM) but I haven't tried Wayland.

Maybe, but a maximized window usually leaves some space for task bars, status bars. Also, on a large monitor you typically do not open windows fullscreen. So the rendering goes through a window buffer in shared memory (on Wayland, and X applications often use SHM extension to achieve the same effect).

> In particular, my example, "to scroll the contents of a browser window but not the browser chrome," can be handled by redrawing the browser chrome in a different position over part of the scrolled page. I'm not sure how you would design the graphics API to make this simple, but you can clearly do it.

Yes it seems that nobody does it these days, so the best you can do is to have two buffers (for the toolbars and for the content) and ask the display compositor to combine them. Which it will do through a memcpy, but if the buffers are in VRAM, the GPU will do the copying.

However, while Wayland supports compositing window from subsurfaces, it doesn't support "scrolling" of a surface (displaying the content of a buffer with an offset and wrapping), so you need to redraw the whole buffer on scrolling.