|
|
|
|
|
by ben-schaaf
12 days ago
|
|
Real applications don't use 8 bit grayscale font glyphs; there's colour glyphs and subpixel Antialiasing, and subpixel positioning. Commonly you're storing 3 channel alpha (or color), and 6 copies of each glyphs at different subpixel positions. You're not blitting these glyphs, you're blending them with the background. Font atlases do not fit in cache, especially at 4k. You also need to not just write the framebuffer, but also send it to the GPU. On some systems that can be done quickly, on others you're going over PCIe. And on top of all that, you have the data structures that are telling you what text to render where, which further fill the cache. All that to say, your example of blitting a single color is very, very far away from the practical reality of rendering a GUI. |
|
If you're not familiar with some of these algorithms, just know that, for the most part, they're significantly more demanding than the layout systems used by Real Applications (if a browser is a Real Application, anyway) and produce much better results.
On my 1080p display (¼ of 4K) Riffle runs in the range 120–300 frames per second on one of my four cores, at roughly 1 gigapixel per second. However, my LCD is only 60 fps.
I tried to record a video with OBS, but not only did the extra load slow Riffle down to only about 70fps, but OBS started missing most of the screen frames I was seeing when Riffle updated the screen rapidly, adding serious jank to the recording that wasn't there in real life. Worse, my attempts to compress the resulting file with ffmpeg to anything resembling a reasonable size made complete garbage out of the text. So you'll have to run it yourself if you want to see it.
On one core of the Xeon it was first tested on, it draws roughly 3.5 gigapixels per second, which is about 60% faster than memcpy and would be about 400 frames per second at 4K resolution. On my Ryzen 5 3500U laptop, it manages about 1.1 gigapixels per second, which is 55% slower than memcpy and barely over 120 frames per second. I'm hoping I can improve that today.
Although most of the algorithms I'm using produce much higher-quality output than Real Applications, I did do two things that compromise output quality slightly to get speed:
1. Compositing the dark antialiased text onto the light background is done with elementwise minimum rather than standard α-multiplication. This is an imperceptible difference visually, but roughly doubles the fill rate even without LCD subpixel compositing, which it provides for free.
2. The glyph atlas for each frame is generated from a piecewise-linear sampled approximation of the font SDF, which is generated at startup. (Initially, I was just rendering the frame directly from the SDF, but on the Xeon that was only hitting about 1 gigapixel per second.) At large font sizes this produces visible artifacts. However, it also provides continuously variable font size, weight, and outlining.
Again, I don't want to claim that rendering the UI on the CPU is better than doing it on the GPU. Doing it on the GPU is better! But doing it on the CPU is totally tolerable, very far from "pegging the CPU while scrolling [on] a 4k120hz display".
If you want to try it out, it's at https://canonical.org/~kragen/sw/riffle-packed.tar.gz.