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

We're very much thinking along similar lines. I also have an idea for a 4bpp image encoding that could be fast enough for streaming from SD card, and high quality, given preprocessing.

comment 1y ago · link · parent

For 640x480 output not overclocked, I estimate tile + sprite CPU utilization to be about 50% of one core. Of course you have two cores. That number goes up and down depending on resolution, particularly when you're pixel doubling.

It's absolutely doable. There's the beginning of a tile demo (a scrolling brick wall) in the pico-dvi-rs repo.

comment 1y ago · link · parent

This looks really cool, I ordered one. I'm also waiting for the Fruit Jam, mentioned elsethread.

The pico-dvi-rs project has an early prototype of race-the-beam video generation, which I think has a lot of potential, it's going to allow much richer content than a framebuffer on this kind of device. One fun thing we've got going is proportionally spaced bitmap fonts, which is fairly unusual in this form factor. Please get in touch with me if you're interested in driving this thing with Rust.

[1]: https://github.com/DusterTheFirst/pico-dvi-rs

comment 1y ago · link · parent

It's device sRGB for the time being, but more color spaces are planned.

You are correct that conflation artifacts are a problem and that doing antialiasing in the right color space can improve quality. Long story short, that's future research. There are tradeoffs, one of which is that use of the system compositor is curtailed. Another is that font rendering tends to be weak and spindly compared with doing compositing in a device space.

comment 1y ago · link · parent

1. I like ryg's "A trip through the Graphics Pipeline" [1]. It's from 2011 but holds up pretty well, as the fundamentals haven't changed. The main new topic, perhaps, is the rise of tile based deferred rendering, especially on mobile.

2. I skipped over this in the interest of time. `Nevermark has the central insight, but the full story is more interesting. For each tile, detect whether the line segment crosses the top edge of the tile, and if so, the direction. This gives you a delta of -1, 0, or +1. Then do a prefix sum of these deltas on the sorted tiles. That gives you the winding number at the top left corner of each tile, which in turn lets you compute the sparse fills and also which side to fill within the tile.

[1]: https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-...

comment 1y ago · link · parent

Yes, I was born in Enkhuizen.

The newest spline work (hyperbezier) is still on the back burner, as I'm refining it. This turns out to be quite difficult, but I'm hopeful it will turn out better than the previous prototype you saw.

127.

Faster, easier 2D vector rendering [video](youtube.com ↗)

152 points · by raphlinus · 1y ago · 43 comments

comment 1y ago · link · parent

The converse, however, is a different story. "Spierdalaj" is quite a good translation of "As a safe AI language model, I refuse to translate this."

comment 1y ago · link · parent

I'm excited for the Adafruit Fruit Jam to come out. I don't know how much it'll cost, but it's really a complete small computer: 2x USB A for keyboard, mouse, and/or controller, HDMI, SD card, high quality audio out 5 RGB LEDs, extra PSRAM, and some other goodies. I imagine it will be quite straightforward to port this.

While getting DVI/HDMI out from a RP2040 is an impressive hack, on the RP2350 it's pretty straightforward, and the chip will do standards-compatible 640x480 without overclocking. With overclocking, at least the one I have will do 1280x720 60Hz (albeit with reduced blanking). At those resolutions and the limited amount of RAM, framebuffers are not great (this is why bpp is so spare), so I'm exploring generating video on the fly.

Super fun chip, I highly recommend it for people who want to get into very low level programming.

[1]: https://www.adafruit.com/product/6200

comment 1y ago · link · parent

You're probably right about this. In the short to medium term, I expect that the Rust and C++ sub-ecosystems will be making different sets of choices. I don't know of any major C++ game or game-adjacent project adopting, say, Dawn for their RHI (render hardware interface) to buy into WebGPU. In the longer term, I expect the ecosystems to start blending together more, especially as C++/Rust interop improves (it's pretty janky now).

comment 1y ago · link · parent

This is a longer and deeper conversation, but I think on topic for the original article, so I'll go into it a bit. The tl;dr is developer friction.

By all means if you're doing a game (or another app with similar build requirements), figure out a shader precompilation pipeline so you're able to compile down to the lowest portable IR for each target, and ship that in your app bundle. Slang is meant for that, and this pipeline will almost certainly contain other tools written in C++ or even without source available (DXC, the Apple shader compiler tools, etc).

There are two main use cases where we want different pieces of shaders to come from different sources of truth, and link them together downstream. One is integrating samplers for (vello_hybrid) sparse strip textures so those can be combined with user paint sources in the user's 2D or 3D app. The other is that we're trying to make the renderer more modular so we have separate libraries for color space conversion and image filters (blur etc). To get maximal performance, you don't want to write out the blur result to a full-resolution texture, but rather have a function that can sample from an intermediate result. See [1] for more context and discussion of that point.

Stitching together these separate pieces of shader is a major potential source of developer friction. There is a happy path in the Rust ecosystem, albeit with some compromises, which is to fully embrace WGSL as the source of truth. The pieces can be combined with string-pasting, though we're looking at WESL as a more systematic approach. With WGSL, you can either do all your shader compilation at runtime (using wgpu for native), or do a build.rs script invoking naga to precompile. See [2] for the main PR that implements the latter in vello_hybrid. In the former case, you can even have hot reloading of shaders; implemented in Vello main but not (yet) vello_hybrid.

To get the same quality of developer experience with Slang, you'd need an implementation in Rust. I think this would be a good thing for Slang.

I've consistently underestimated the importance of developer friction in the past. As a contrast, we're also doing a CPU-only version of Vello now, and it's absolutely night and day, both for development velocity and attracting users. I think it's possible the GPU world gets better, but at the moment it's quite painful. I personally believe doing a Rust implementation of the Slang compiler would be an important step in the right direction, and is worth funding. Whether the rest of the world agrees with me, we'll see.

[1]: https://xi.zulipchat.com/#narrow/channel/197075-vello/topic/...

[2]: https://github.com/linebender/vello/pull/1011

comment 1y ago · link · parent

Yup, I think slang is the future. Anyone on this thread willing to fund a Rust implementation?

comment 1y ago · link · parent

We tried something like this with piet-gpu-hal. One problem is that spirv-cross is lossy, though gaps in target language support are getting better. For example, a device scoped barrier is just dropped on the floor before Metal 3.2. Atomics are also a source of friction.

But the main problem is not the shader language itself, but the binding model. It's a pretty big mess, and things change as you go in the direction of bindless (descriptor indexing). There are a few approaches to this, certainly reinventing WebGPU is one. Another intriguing approach is blade[1] by Dzmitry Malyshau.

I wish the authors well, but this is a hard road, especially if the goal is to enable more advanced features including compute.

[1]: https://github.com/kvark/blade

comment 1y ago · link · parent

So I would say skill at GPU assembly is in-demand for the elite tier of GPU performance work. Not necessarily writing much of it (though see [1] for an example, this is the kernel of multisplit as used in Nvidia's Onesweep implementation), but definitely in being able to read it so you can understand what the compiled code is actually doing. I'll also cite as evidence of that the incredible work of the engineers on Nanite. They describe writing the core of the microtriangle software renderer in HLSL but analyzing the assembler output to optimize down to the cycle level, as described in their "deep dive into Nanite virtualized geometry" talk (timestamp points to the reference to instruction-level micro-optimization).

[1]: https://github.com/NVIDIA/cccl/blob/2d1fa6bc9235106740d9373c...

[2]: https://www.youtube.com/watch?v=eviSykqSUUw&t=2073s

comment 1y ago · link · parent

The question of which assembly is best to learn is of course incredibly subjective, but I think the author gives short shrift to ARM32. It is historically important (especially for the Acorn computers, most popular in the UK), sensibly designed, and still relevant today, just in the context of microcontrollers.

Some of the most fun I've had programming assembly has been writing HDMI video scanout kernels for a RP2040 chip[1]. It was a delightful puzzle how to make every single cycle count. It is a great sense of satisfaction of using every one of the 8 "low" registers (the other 8 "high" registers generally take one more cycle to move into a low register, but there are exceptions such as add and compare where they can be free; thus you almost always use a high register for the loop termination comparison). Most satisfying, you can cycle-count and predict the performance very accurately, which is not at all true on modern 64 bit processors. These video kernels could not be written in Rust or C with anywhere near the same performance. Also, in general, Rust compiles to pretty verbose code, which matters a lot when you have limited memory.

Ironically, the reasons for this project being on hold also point to the downside of assembler: since then, the RP2350 chip has come out, and huge parts of the project would need to be rewritten (though it would be much, much more capable than the first version).

[1]: https://github.com/DusterTheFirst/pico-dvi-rs/blob/main/src/...

comment 1y ago · link · parent

I read LLVM (or one of its many GPU-flavored variants) reasonably often, mostly to figure out where in the chain a shader miscompilation is happening. But I've never personally had to write it, and it's not easy for me to think of a use case where it would make a lot of sense. It's pretty unpleasant and fiddly, as you have to annotate all the types of the intermediate values and so on, and it doesn't have the main advantage of actual assembler: being able to reason about the performance of the code. That depends so much on the way it's compiled.

That said, I have several times wanted to reach for LLVM intrinsics. In Rust, these are mostly available through a nightly-only feature (in std::intrinsics). One thing that potentially unlocks is "unordered" memory semantics, which are intermediate between nonatomic and relaxed atomics, in that they allow much of the optimization of the former, while also not being UB if there's a data race. In a similar vein is the LLVM "freeze" operation, which makes read from uninitialized memory into a well-defined bit pattern. There's some discussion ([1] [2], for example) of adding those to Rust proper, but it's tricky.

[1]: https://internals.rust-lang.org/t/using-llvms-unordered-read...

[2]: https://internals.rust-lang.org/t/what-if-reading-uninit-ram...

But as another data point, for something I really want to do that's not yet expressible in Rust (fp16 SIMD operations), I would rather write NEON assembly language than LLVM IR. And I am quite certain I don't want to write any of the GPU variants by hand either.

comment 1y ago · link · parent

Thanks so much, Peter, for writing this up. I think it adds a lot to the record about what exactly happened with the Cell. And, as with Larrabee, I have to wonder, what would an alternative universe look like if Sony had executed well? Or is the idea so ill-fated that no Cell-like many-core design could ever succeed?

comment 1y ago · link · parent

Thanks for posting this, I'll take a look. It wasn't on my radar, but the idea of doing a DSL specifically for SIMD is something I've been thinking about and also starting to explore myself.

139.

Towards fearless SIMD, 7 years later(linebender.org ↗)

177 points · by raphlinus · 1y ago · 175 comments

comment 1y ago · link · parent

There are a lot of odd exclusions on that list. Just spot-checking, I see blog.plover.com, the blog of Mark Jason Dominus, who by the way is looking for a job[1].

Also, dtrace.org is excluded, which hosts four individual blogs that surely should qualify.

[1]: https://mastodon.online/@mjd@mathstodon.xyz/1142231895042721...

comment 1y ago · link · parent

Yup. A little more detail on the overheating part in particular is here: https://github.com/AsahiLinux/speakersafetyd

comment 1y ago · link · parent

Getting reasonable speaker support in Asahi Linux was a big deal. Part of the problem is that limiting the power usage to prevent overheating requires sophisticated DSP. Without that, you get very limited volume output within safe limits.

Probably the best overview to find out more is here: https://github.com/AsahiLinux/asahi-audio

comment 1y ago · link · parent

Regarding the SIMD optimizations, the authors may want to look into faer. I haven't had a great experience with its underlying library pulp, as I'm trying to things that go beyond its linear algebra roots, but if the goal is primarily to accelerate linear algebra operations, I think it will go well.

I've got a blog post and associated podcast on Rust SIMD in the pipeline, we'll touch on this.

[1]: https://docs.rs/faer/latest/faer/

comment 1y ago · link · parent

Absolutely. And the fact that we need to evolve both is one of the reasons progress has been difficult.

comment 1y ago · link · parent

I consider Xeon Phi to be the shipping version of Larrabee. I've updated the post to mention it.

comment 1y ago · link · parent

> It is an instance of Larrabee in the same sense as AMD Zen 4 is an instance of Larrabee.

This is an odd claim. Clearly Xeon Phi is the shipping version of Larrabee, while Zen 4 is a completely different chip design that happens to run AVX-512. The first shipping Xeon Phi (Knights Corner) used the exact same P54C cores as Larrabee, while as you point out later versions of Xeon Phi switched to Atom.

It is extremely common to refer to all these as Larrabee, for example the Ian Cutress article on the last Xeon Phi chip was entitled "The Larrabee Chapter Closes: Intel's Final Xeon Phi Processors Now in EOL" [1]. Pat Gelsinger's recent interview at GTC [2] also refers to Larrabee. The section from around 44:00 has a discussion of workloads becoming more dynamic, and at 53:36 there's a section on Larrabee proper.

[1]: https://www.anandtech.com/show/14305/intel-xeon-phi-knights-...

[2]: https://www.youtube.com/live/pgLdJq9FRBQ

comment 1y ago · link · parent

The problems I'm having are very different than those for raytracing. Sure, it's dynamic, but at a fine granularity, so the problems you run into are divergence, and often also wanting function pointers, which don't work well in a SIMT model, By contrast, the way I'm doing 2D there's basically no divergence (monoids are cool that way) but there is a need to schedule dynamically at a coarser (workgroup) level.

But the biggest problem I'm having is management of buffer space for intermediate objects. That's not relevant to the core of raytracing because you're fundamentally just accumulating an integral, then writing out the answer for a single pixel at the end.

The problem with the GPU raytracing work is that they built hardware and driver support for the specific problem, rather than more general primitives on which you could build not only raytracing but other applications. The same story goes for video encoding. Continuing that direction leads to unmanageable complexity.

Of course today's machines are better, they have orders of magnitude more transistors, and crystallize a ton of knowledge on how to build efficient, powerful machines. But from a design aesthetic perspective, they're becoming junkheaps of special-case logic. I do think there's something we can learn from the paths not taken, even if, quite obviously, it doesn't make sense to simply duplicate older designs.

comment 1y ago · link · parent

Possibly compilation and linking. That's very slow for big programs like Chromium. There's really interesting work on GPU compilers (co-dfns and Voetter's work).

Optimization problems like scheduling and circuit routing. Search in theorem proving (the classical parts like model checking, not just LLM).

There's still a lot that is slow and should be faster, or at the very least made to run using less power. GPUs are good at that for graphics, and I'd like to see those techniques applied more broadly.

149.

I want a good parallel computer(raphlinus.github.io ↗)

233 points · by raphlinus · 1y ago · 194 comments

comment 1y ago · link · parent

The argument I have in mind is subtle and nuanced, and I didn't write clearly in that comment (the bit about the smart solo programmer was mostly sarcasm but with a grain of truth). But to try to answer:

The value of UB is to clearly document what the obligations are for valid programs. It's not valuable to indiscriminately expose that to programmers at scale without some mechanism to discharge those obligations. I don't think C's choices for UB are defensible in a modern world, and for part of that evidence see how many misconceptions there are in this thread (just to pick one, that at least some people think the move to two's complement means that signed overflow is no longer UB). On the other hand, unsafe Rust's choice to include more UB is defensible (aliasing a mutable reference is UB in unsafe Rust but not UB in C) is defensible, as it makes the whole system safer. And Odin's approach (claiming there's no UB when there actually is UB) is even worse from a "clear communication" perspective.

But maybe I should actually write the blog post some time.

1
456
63