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 4y ago · link · parent

Adapton is definitely an inspiration, and I have cited it in previous iterations (and even had it in an earlier draft - if you check the Markdown source, the link def is still there).

Here's my current thinking on the topic. It all depends on whether you want to model your problem as a tree or a graph (see also [1] for some great discussion of that tension). If you model your problem as a graph, then a general purpose incremental computation engine like Adapton (or Incremental or Salsa) is great. However, if your problem is a tree, then constructing the explicit dependency graph requires a nontrivial amount of ceremony. What Xilem does is represent the most common tree-structured flows of information in a very lightweight manner (mostly just plain code that builds views), while allowing you to insert arbitrary graph edges if you like with more work.

I think it's a discussion worth continuing. One thing you could do is integrate Adapton and Xilem together, where the implementation of most view nodes in the latter becomes queries into the Adapton engine. How well would that work? Really only one way to find out.

[1]: https://glazkov.com/2022/02/06/tension-between-graphs-and-tr...

542.

Xilem: An Architecture for UI in Rust(raphlinus.github.io ↗)

457 points · by raphlinus · 4y ago · 103 comments

comment 4y ago · link · parent

Watch this space. Specifically I am writing up my ideas for a fusion of SwiftUI and Druid, inspired in large part by Taylor's work on rui. This work is conceptual at the moment, not a finished product, but I am hopeful it will be a better direction for UI in Rust.

comment 4y ago · link · parent

https://craphound.com/spamsolutions.txt

comment 4y ago · link · parent

Good question! There are two separate issues with putting the GPU in the same package as the CPU. One is the memcpy bandwidth issue, which is indeed entirely mitigated (assuming the app is smart enough to exploit this). But the round trip times seem more related to context switches. I have an M1 Max here, and just found ~200µs for a very simple dispatch (just clearing 16k of memory).

I personally believe it may be possible to reduce latency using techniques similar to io_uring, but it may not be simple. Likely a major reason for the roundtrips is so that a trusted process (part of the GPU driver) can validate inputs from untrusted user code before it's presented to the GPU hardware.

comment 4y ago · link · parent

The short answer is no, but the long answer is that this is a very complex tradeoff space. Going forward, we may see more of these types of tasks moving to GPU, but for the moment it is generally not a good choice.

The GPU is incredible at raw throughput, and this particular problem can actually implemented fairly straightforwardly (it's a stream compaction, which in turn can be expressed in terms of prefix sum). However, where the GPU absolutely falls down is when you want to interleave CPU and GPU computations. To give round numbers, the roundtrip latency is on the order of 100µs, and even aside from that, the memcpy back and forth between host and device memory might actually be slower than just solving the problem on the CPU. So you only win when the strings are very large, again using round numbers about a megabyte.

Things change if you are able to pipeline a lot of useful computation on the GPU. This is an area of active research (including my own). Aaron Hsu has been doing groundbreaking work implementing an entire compiler on the GPU, and there's more recent work[1], implemented in Futhark, that suggests that that this approach is promising.

I have a paper in the pipeline that includes an extraordinarily high performance (~12G elements/s) GPU implementation of the parentheses matching problem, which is the heart of parsing. If anyone would like to review a draft and provide comments, please add a comment to the GitHub issue[2] I'm using to track this. It's due very soon and I'm on a tight timeline to get all the measurements done, so actionable suggestions on how to improve the text would be most welcome.

[1]: https://theses.liacs.nl/pdf/2020-2021-VoetterRobin.pdf

[2]: https://github.com/raphlinus/raphlinus.github.io/issues/66#i...

comment 4y ago · link · parent

This warms my heart to see. I was looking at various hardware (teensy and so on) at the time I originally started the project, but never had the time and energy to wrangle actually putting it together.

comment 4y ago · link · parent

5th generation computing[1]. This was an initiative by the Japanese computer industry to create a new class of highly parallel computers specialized for AI, in the early 80s, and primarily programmed in Prolog-like languages. There were people who genuinely believed that the success of this project would leapfrog Japan over the Western computing industry, in other words FOMO.

Perhaps ironically, there are some aspects of this project (parallelism and AI) that are now massively important. It's just that they were ahead of their time on those aspects, and Prolog is now largely a historical bywater.

[1]: https://en.wikipedia.org/wiki/Fifth_Generation_Computer_Syst...

comment 4y ago · link · parent

So I read the 7 month old thread, and I found this comment particularly interesting: https://news.ycombinator.com/item?id=28332803

Basically, it answers the question, "why do Rust GUI frameworks use enums rather than closures for messages in the Elm update pattern?" It is very insightful, but doesn't tell the whole story. In particular, as a major counterexample, Druid does use closures for stuff like buttons, and they update state exactly as expected. That said, the Druid approach does have major drawbacks, chief among them that the app state needs a `Data` bound, which (oversimplifying slightly) means that it only works well with immutable data structures.

As it turns out, I've been thinking about how to solve this problem - closures that have convenient access to mutable app state without strange bounds on that state, or strange control flow when doing things like adding and deleting widgets, and think I've finally cracked it. I will be doing a writeup when I have time, but for the eager and curious, there is a code sketch at https://github.com/linebender/druid/blob/lasagna/lasagna/src... .

comment 4y ago · link · parent

For the rope, are you using xi-rope, ropey, or did you roll your own? Any thoughts on how you made that decision?

Glad to see stuff like this, it brings back memories.

comment 4y ago · link · parent

Absolutely, and I don't want to claim I'm the first or only one doing font rendering on GPU. There's Slug as you pointed out, Pathfinder and Spinel as Jasper cited, and also interesting experimental work including GLyphy by Behdad and algorithms by Evan Wallace and Will Dobbie, plus a whole series of academic papers including "Massively Parallel Vector Graphics," "Random Access Vector Graphics," and others.

However, I would say that a common thread is that doing this well is hard. There's no straightforward cookbook scheme that people can just implement, and there are always tradeoffs. Slug is used in a number of games (and congrats to Eric for winning those licenses), but not as far as I know in any UI toolkits, and there are reasons for that.

comment 4y ago · link · parent

I respectfully disagree that CPUs are better than GPUs at font rendering :)

There are a few related things that can be said. Doing fast, high quality font rendering on a GPU is hard; it's much easier on a CPU. Further, the traditional rasterization pipeline of a GPU is not good at rendering fonts. Fortunately, modern GPUs also have compute shaders, which are programmed somewhat like regular computers but just with an astonishingly high number of threads.

This is the topic of my research, and I intend to publish quantitative measurements backing up these assertions before long. Early results look promising.

comment 4y ago · link · parent

http://www.cmyr.net/blog/gui-framework-ingredients.html has a bunch of what you'll need to know about building a GUI from scratch, especially if you're interested in any of the "hard parts" rather than making a toy. It's Rust rather than C++ but many of the principles are similar.

Other than that, I do recommend the immediate mode GUI approach if you're writing everything yourself, as it's the lowest overall system complexity of all the approaches. It has a number of drawbacks, and things don't abstract/compose as easily as a standard object-oriented retained, or a newer React/SwiftUI approach, but exposing the raw parts has its upsides.

comment 4y ago · link · parent

https://www.youtube.com/watch?v=T5YgJx8VGRA is a pretty good one, actually. It's in the form of a joke, but the fact that it got a laugh conveys a sort of shared knowledge they were pulling a fast one over the public.

ETA: If you're asking for more "straight news" types of sources, https://www.washingtonpost.com/politics/2019/03/22/iraq-war-... is a pretty neutral and objective retrospective, relying heavily on a Senate Intelligence Committee report that was approved on a bipartisan basis.

comment 4y ago · link · parent

I think your question is partly answered by the cudaraster work, which is well over a decade old at this point. They basically did write a software rasterizer (that ran on CUDA, but is adaptable to other GPU intermediate languages). The details are interesting, but the tl;dr is that it's approximately 2x slower than hardware. To me, that means you could build a GPU out of a fully general purpose parallel computer, but in practice the space is extremely competitive and nobody will leave that kind of performance on the table.

I think this also informs recent academic work on RISC-V based GPU work such as RV64X. These are mostly a lot of generic cores with just a little graphics hardware added. The results are not yet compelling compared with shipping GPUs, but I think it's a promising approach.

[1]: https://research.nvidia.com/publication/high-performance-sof...

comment 4y ago · link · parent

As is Quaker meeting. I'm deeply involved in mine, and it has been essential for my emotional well-being over (at least) the past couple years.

comment 4y ago · link · parent

You would be asked to leave our Quaker meeting, attend it via Zoom instead.

comment 4y ago · link · parent

Exactly that. You compile down to SPIR-V, then use spirv-cross to generate Metal Shading Language or GLSL. It's clunky and there are some rough edges - these conversions aren't 100% lossless - but it does work. If you play a game on a mac, there's a very good chance this is the compilation strategy used.

comment 4y ago · link · parent

It may be close to a technical impossibility, but the Circle compiler by Sean Baxter is attempting it. That's based on an aggressive "de-pointerization" (see [1] in particular for details). There's also academic work[2] to compile C++ to shaders. I agree that it's an open question how well that will work out.

Also as pointed out elsethread, now that buffer device address is starting to land, the friction to compile pointer-intense C++ code should decrease even more. These are exciting times!

[1]: https://github.com/seanbaxter/shaders#approaching-circle-sha...

[2]: https://arxiv.org/abs/2109.14682

comment 4y ago · link · parent

I'll try to answer.

CUDA is the Nvidia GPU compute infrastructure and runtime. The native language is a variant of C++, but there are lots of ways to use CUDA from Python (very popular in the machine learning world), Julia, etc. It is an extremely mature and polished way to get access to high performance compute. The biggest downside is that it's Nvidia proprietary.

OpenCL is the older non-Nvidia standard infrastructure for GPU compute. It's languishing though. It is traditionally programmed in OpenCL C, but it does support other languages such as SYCL (another C++ dialect, similar in scope to CUDA C++).

HLSL is similar in that it's a language for programming GPU code, also derived from C (with some C++ sprinkled in), but it's different than CUDA and OpenCL in that it's primarily for graphics applications rather than general purpose compute. The line blurs a bit with the concept of "compute shader," which can be seen as a cut-down CUDA or OpenCL that runs inside the GPU graphics API. Compute shaders are becoming more powerful in each generation. That said, HLSL is overwhelmingly popular for game development, because the tools are so good.

This stuff is confusing. I haven't even touched on the different intermediate representations and the tools for converting between the different languages, of which there is an increasingly dense matrix.

comment 4y ago · link · parent

The Gell-Mann Amnesia effect is real here. The difference is that, for many computer and computer-adjacent topics, the principals will often chime in. That gets you a level of authoritativeness that's hard to match. Even within computer topics, though, you see authoritative-sounding comments that are just wrong. That happens like clockwork in any thread having to do with undefined behavior, for example.

I also know a little about Covid (having a minor in molecular and cell biology, and obsessively consuming resources like TWiV for a while), and the median amateur virologist comment here is just a howler. Occasionally you'll have people who really know what they're talking about comment, but it usually gets drowned out.

The key, then, as always, is to read everything critically. Then there's some real insight to be gained here.

comment 4y ago · link · parent

At the moment, I am talking about community contributors. But if you have a credible plan for getting this done and the thing that would hold it back is funding, let's talk.

comment 4y ago · link · parent

I find your ideas intriguing and I wish to subscribe to your newsletter.

More seriously, yes, if you were starting a browser completely from scratch, this would probably be a good approach. There are some subtleties, but probably nothing that couldn't be solved with some elbow grease.

If anyone is seriously interested in exploring this direction, one thing that would be very interesting is a port of piet-gpu to run on top of WebGPU (it's currently running on Vulkan, Metal, and DX12). I've done quite a bit of pre-work to understand what would be involved, but don't personally have the bandwidth to code up the WebGPU port. I would be more than happy to work with somebody who does.

comment 4y ago · link · parent

Yes. Probably the single most effective use of the GPU for audio is convolutional reverb, for which a number of plugins exist. However, the problem is that GPUs are optimized for throughput rather than latency, and it gets worse when multiple applications (including the display compositor) are contending for the same GPU resource - it's not uncommon for dispatches to have to wait multiple milliseconds just to be scheduled.

I think there's potential for interesting things in the future. There's nothing inherently preventing a more latency-optimized GPU implementation, and I personally would love to see that for a number of reasons. That would unlock vastly more computational power for audio applications.

There's also machine learning, of course. You'll definitely be seeing (and hearing) more of that in the future.

comment 4y ago · link · parent

I think one of WebGPU's greatest strengths is learning, as you can get started pretty easily, and you actually learn a modern approach to GPU. Vulkan requires a significant amount of boilerplate just to establish a connection to the GPU and set up basic resources like the ability to allocate buffers. In WebGPU, the latter is one or two lines of code.

That said, there are some really nice learning resources for Vulkan as well, so if you're motivated and determined, it's also not a bad way to learn modern GPU.

comment 4y ago · link · parent

At this point, there are very few tools actually running on WebGPU, as it's too new. One to watch for sure is IREE, which has a WebGPU backend planned and in the works.

comment 4y ago · link · parent

This depends on the algorithm. If it has lots of branching and control flow, then it's unlikely to run well. If it's based on something like FFT or any sort of linear algebra really, then it should run really well.

WebGPU is accessible enough maybe you should try it! You'll learn a lot either way, and it can be fun.

comment 4y ago · link · parent

This is the video that finally made it click for me[1]. Despite the somewhat click-baity title ("What Popularizers of QM Don't Want You to Know") it actually goes into quite a bit of detail of what is and isn't a measurement, in the sense of interactions in a quantum mechanical system that strongly resemble classical behavior (it can be said that the quantum mechanical world is a simulator that can run classical mechanics).

[1]: https://www.youtube.com/watch?v=dEaecUuEqfc

comment 4y ago · link · parent

This one is tasty! It reminds me of Olivetti Cubic a bit, but definitely has its own distinctive style.

comment 4y ago · link · parent

If one side is serving chocolate cake, and the other shit, then what you end up with is a half-shit, half-chocolate confection. Some people apparently like that, but I personally don't.

Another way of saying this is historian John M. Barry's quote, "when you mix politics and science, you get politics," also famously cited by Peter Daszak.

1
181920
63