Better HN
topnewbestaskshowjobs
Log inSign up

raphlinus

14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions

I do research on fundamental UI technology and 2D graphics, with a focus on Rust and fonts. @raph@mastodon.online
Submissions

comment 6y ago · link · parent

I believe Onivim is in this camp. I don't know how well that's working out for them, or whether there are any others.

1172.

Xi-Editor Retrospective(raphlinus.github.io ↗)

538 points · by raphlinus · 6y ago · 157 comments

comment 6y ago · link · parent

Slug has DirectX support (it runs on all major APIs). Pathfinder does not yet, but likely will in time. As always, evaluate the offerings and choose what meets your needs best. Performance is probably comparable between the two, but that depends hugely on workloads and how it's integrated into the rest of your system.

comment 6y ago · link · parent

In the free software world, Pathfinder is probably your best bet, and I'm hopeful that it will take on speedups from compute (directly inspired by my research). The library that's probably the closest fit for what you describe is Slug.

comment 6y ago · link · parent

I recommend reading the blog post series, I'm not sure I can usefully summarize the concepts in a comment reply. But very briefly, there's a flattening step (evaluated on GPU, based on de Casteljau) that converts the Bezier into a polyline (not triangles), then a tiling step that records for each tile a "command list" that contains the complete description of how to render the pixels in a tile, finally "fine rasterization" so that each workgroup reads that command list and renders 256 pixels in parallel from it. From your question, it sounds like your mental model is pretty different from how this pipeline works.

comment 6y ago · link · parent

That's a big topic. I've been able to work around the missing primitives (for example, I autogenerate code for Rust-style structs and enums), but have had much bigger struggles around two issues: tools, which are still quite primitive, and understanding performance, which is extremely difficult. These two problems intersect because I can imagine a lot better tools for digging into performance issues. One that I would have paid good money for is an instruction-level simulator that would highlight the source code to tell me where the stalls, bank conflicts, divergence problems, etc. are in the source code. Such a thing is possible (there are academic papers like [1]), but not as far as I know usable in daily development.

The "impedance mismatch" is that you (generally) have to write in a style to extract lots of parallelism. This tends to be very different than the way you'd write scalar CPU code, but not completely alien to me as it has a lot of similarity with the way you'd write SIMD. I've pretty much gotten the hang of it now. I'm thinking of a blog post of redoing path_coarse.comp from its current basically scalar style to a more parallel version, as that would I think illuminate the issues.

[1] http://comparch.gatech.edu/hparch/papers/gera_ispass18.pdf

comment 6y ago · link · parent

> You can reduce all these to drawing triangles.

You can, people have tried this, and it sucks. The main problem is that the conversion of Bézier paths to triangles is a hard problem with lots of conditional branching. Even when you do it, there is the other problem of rendering triangles with really good antialiasing, MSAA forces a compromise between performance and quality. By contrast, piet-gpu does an exact-area calculation for antialiasing.

So it's not a question of whether you can do it, but whether it works well, and approaches like piet-gpu absolutely stomp triangles.

comment 6y ago · link · parent

This is an interesting and subtle point about doing "software on GPU compute." You are in complete control over what gets computed, and are not at the mercy of the hardware's fixed function pipeline for stuff like rasterization rules and sampling patterns for antialiasing. So I think portable results pixel to pixel are in fact viable.

Of course CPU rendering is always more straightforward than GPU, the higher performance comes at a significant cost in complexity.

comment 6y ago · link · parent

This is changing. I've been doing power measurements as well (just didn't make the cut of this blog post), and the 1060 is surprisingly power-efficient in its low frequency modes. It's also generally the case that the GPU is always active in its role running the compositor.

comment 6y ago · link · parent

Yes, the motivation and long term goal for this work is to provide a performant foundation for cross-platform UI. There's a lot to be done though!

comment 6y ago · link · parent

Not very, and not very. This is research, it depends on compute capabilities that have really only gone mainstream in GPU lately, and the current codebase is about trying out the ideas. Best of luck in your project!

comment 6y ago · link · parent

See this blog, it explains it pretty well imho: https://blog.mecheye.net/2019/05/why-is-2d-graphics-is-harde...

And: historically they've been computed mostly on CPU, but I think it's time for that to change.

comment 6y ago · link · parent

Got it. So far my research prototype really just does filled paths and limited strokes, but the architecture should extend to a richer set of graphics primitives. Pathfinder also started out that way but recent work is building out a good chunk of the SVG imaging model. I definitely recommend checking it out, there's a good chance it'll do what you need.

comment 6y ago · link · parent

Short answer, yes, I believe it could work, though not with much margin to spare. It might require some dedicated optimization work to fit the frame budget, especially when you know things about the scene (it's mostly small glyphs and with basically no overdraw) as opposed to being completely general purpose.

Doing a warp transformation in the element processing kernel would probably work just fine, and give you realistic movement and razor-sharp rendering.

I'd love to see such a thing and would very much like to encourage people to build it based on my results :)

comment 6y ago · link · parent

I expect it to be faster, but doing performance evaluation is really hard work. Performance depends on so many variables, including the workloads you're trying to render and a ton of factors about the GPU and system. I know people are really curious about competitive performance against other renderers, and it's something I should probably do, but honestly I'd love it if somebody else took up that mantle.

comment 6y ago · link · parent

No, it's designed to be portable to all GPU hardware that can support compute, which these days is a pretty good chunk of the fleet. I tested it on Linux on Intel HD 4000, and the master branch seems to run just fine, though previous versions.

A lot of the academic literature (Massively Parallel Vector Graphics, the Li et al scanline work) is dependent on CUDA, but that's just because tools for doing compute on general purpose graphics APIs are so primitive. I have a talk and a bunch of blog posts on exactly this topic, as I had to explore deeply to figure it out. See https://news.ycombinator.com/item?id=22880502 and https://raphlinus.github.io/gpu/2020/04/30/prefix-sum.html for more breadcrumbs on that.

comment 6y ago · link · parent

Metal is definitely used extensively in CoreAnimation, and Apple UI tends to rely on that - relatively slow (and memory hungry) rendering of layer content, which is then composited very smoothly and nicely in CA.

They might use it for other stuff like glyph compositing (I think this is one reason they got rid of RGB subpixeling, to make it more amenable to GPU), but last I profiled it, it was still doing a lot of the pixels on CPU, as others have stated.

comment 6y ago · link · parent

Well said, thanks. It's also a goal of this work to do compositing inside the "fine rasterizer" compute kernel, to avoid multipass as much as possible. Of course, in the general case for stuff like blur that's hard, but that's one reason why I've been working on special cases like blurred rounded rectangles, which I can render pretty much at lightspeed. (It's not integrated into the current code but would be quite easy)

comment 6y ago · link · parent

Others have spoken to this, but as a general introduction I highly recommend Jasper's post "Why are 2D vector graphics so much harder than 3D?" In short, no, it's not a solved problem.

Also, I see a lot of variations of this question, but I should state this more clearly. There's been accelerated graphics in one form or another for a long time, but what I'm doing is a completely different type of thing. In my world, on the CPU you just encode the scene into a binary representation that's optimized for GPU but in many ways is like flatbuffers, and then the GPU runs a highly parallel program to render the whole thing. In previous approaches, the CPU is deeply involved in taking the scene apart and putting it back together in a form that's well suited to relatively dumb pixel pipes. Now that GPUs are really fast, that approach runs into limitations.

It also depends what you're trying to do. I'm focusing here on dynamic paths (and thus font rendering), while most of the libraries optimized for UI put text into texture atlases and then use the GPU to composite quads to the final surface, something they can do well.

https://blog.mecheye.net/2019/05/why-is-2d-graphics-is-harde...

comment 6y ago · link · parent

It's something I'd like to explore at some point, also Swiftshader, which might be easier to explore, as it's already Vulkan. I expect performance to be pretty good, but there are already really advanced CPU renderers such as Blend2D. Doing serious performance evaluation is hard work, so I actually hope it's something others take up, as I have pretty limited time for it myself.

comment 6y ago · link · parent

As Patrick indicated, there's a lot of cross-fertilization of ideas, and one of the best outcomes of this work would be for high performance compute rendering to ship in Pathfinder.

comment 6y ago · link · parent

I absolutely have data visualization in mind for this, as I think it can benefit greatly from the scale. But the pipeline I've built is very agile, it will easily handle a diverse mix of items. It's not like OpenGL etc where there's a certain amount of overhead for a draw call so there are significant gains to be had from instancing and batching.

It is likely that CPU-side encoding can be made more efficient, though, by just filling in quantities to a template, rather than encoding from scratch.

comment 6y ago · link · parent

It's a good question, as honestly the knowledge for 2D graphics is pretty arcane, as opposed to 3D being so widely taught. I actually started a github repo for a book on 2d graphics but have no idea whether I'll actually finish it.

In the meantime, antigrain.com is one good (if old) source. The original PostScript "red book" was extremely influential in its time (it's where I learned a lot of this stuff) but is quite dated now. Best of luck, and I'm also happy to field requests for more specific areas. For example, for color theory (an important aspect of 2D graphics!), handprint.com is quite a remarkable resource.

comment 6y ago · link · parent

Fast 2D rendering on GPU has represented the last few months of concentrated work for me, and I'm happy to present the results now. It's required going pretty deep into various aspects of GPU compute, so feel free to ask me about that, 2D vector graphics, or anything related.

1195.

Fast 2D Rendering on GPU(raphlinus.github.io ↗)

286 points · by raphlinus · 6y ago · 123 comments

comment 6y ago · link · parent

I am finding Rust to be a most excellent language for implementing GUI. There are several active projects working on this (linked in sibling comments), and I think progress is encouraging.

comment 6y ago · link · parent

It depends on the goals. If the goal is accurate frequency response and in particular absence of aliasing, then a little square is a bad reconstruction filter.

But for graphics, why should this be the goal? Perhaps a better goal is high contrast of edges, and for this the box filter is one of the very best. An additional advantage of the box filter is that it has only positive support, so there's no clipping beyond white and black. This is especially helpful when rendering text.

And honestly I believe that those huge sinc-approximating reconstruction filters are overly fetishized even in the audio space. The main reason they sound "nearly perfect" is that the cutoff is safely outside the audible range. Try filtering a perfect slow sawtooth through a brick wall with a cutoff in the audio range, say 8kHz. It sounds like a very audible "ping" at that frequency, with pre-echo at that because of the symmetry of sinc.

comment 6y ago · link · parent

If you do do twitter, https://twitter.com/pangramtweets is fun.

One of my favs (apropos for the HN crowd): I would code it differently by sending the ajax request to the backend server and randomize the number there :Grinning face with smiling eyes: #magento #php #laravel

comment 6y ago · link · parent

This Twitter thread is probably one of the best sources: (from John Burn-Murdoch, who does excellent data visualization work for the Financial Times)

https://twitter.com/jburnmurdoch/status/1268450736398098433

The paywall is also easily crossed by, for example, archive.is

comment 6y ago · link · parent

There is a course on this (taught Autumn 2019 at U Wash) that will also soon be published as a book:

https://callingbullshit.org/

1
394041
63