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

Just to give one example, if you want to do forensic analysis on the signal based on inaudible differences. That's a valid use case for an archive that doesn't apply to consumer (even audiophile) consumption of music streams.

comment 3y ago · link · parent

Agreed, for archival purposes we should be using lossless codecs. Not because you can hear the difference but because it makes it easier to reason about whether there's any distortion introduced by the compression. And we can consider the original artifact, as created by the mastering engineer, an authoritative source of truth, even if it's an imperfect representation of what was performed by the musicians.

comment 3y ago · link · parent

Why is the standard considered to be CD quality? In that way, the article shows its age. Today you wouldn't be talking about 44.1kHz 16 bit, it would be all about 24 bit 192kHz. If you're looking at spectrum plots, CD is very much on the low quality side of the spectrum of what's possible. Maybe we should be considering megahertz sampling rates and 32 bits, surely we have enough bandwidth.

Why not then? Because there is a ton of science and empirical evidence that humans cannot hear the difference[1]. Good engineering is about meeting the requirements with minimal cost. If the requirement is that it sounds good to humans, and the cost is number of bits to encode (and thus store and transmit) the signal, then modern codecs like Opus are clearly superior to uncompressed and losslessly compressed signals, much less higher sampling rates.

If your goal is something other than good engineering, for example the aesthetic satisfaction that the bits are the same as what the mastering engineer put on the CD, or for some reason caring how clean spectrum plots of artificial signals look, then the arguments may have some merit. But let's be clear on the goals.

[1]: https://people.xiph.org/~xiphmont/demo/neil-young.html

comment 3y ago · link · parent

Yeah, dynamic memory allocation from GPU space seems to be the real sticking point. I'll look into HSA queues, that looks very interesting, thanks.

comment 3y ago · link · parent

Yeah, that's a big if. In theory there's nothing preventing good compilation to Vulkan compute shaders, in practice people just aren't doing it, as CUDA actually works today.

I also agree that Vulkan is more promising than OpenCL. With recent extensions, it has real pointers (buffer device address), cooperative matrix multiplication (also known as tensor cores or WMMA), scalar types other than 32 bits, proper barrier (including device-scoped, needed for single pass scan), and other important features.

comment 3y ago · link · parent

There are a lot of similarities, but the granularity is finer. The idea is that you make a decision to launch one workgroup (typically 1024 threads) when the input is available, which would typically be driven by queues, and potentially with joins as well, which is something the new work graph stuff can't quite do. Otherwise the idea of stages running in parallel, connected by queues, is similar. But I did an analysis of work graphs and came to the conclusion that it wouldn't help with the Vello (2d vector graphics) workload at all.

comment 3y ago · link · parent

ROCm makes me sad, as it reminds me of how much better GPUs could be than they are today.

I've lately been exploring the idea of a "Good Parallel Computer," which combines most of the agility of a CPU with the efficient parallel throughput of a GPU. The central concept is that the decision to launch a workgroup is made by a programmable controller, rather than just being a cube of (x, y, z) or downstream of triangles. A particular workload it would likely excel at is sparse matrix multiplication, including multiple quantization levels like SpQR[1]. I'm hopeful that it could be an advance in execution model, but also a simplification, as I believe a lot of the complexity of the current GPU model is because of lots of workarounds for the weak execution model.

I'm not optimistic about this being built any time soon, as it requires rethinking the software stack. But it's fun to think about. I might blog about it at some point, but I'm also interested in connecting with people who have been thinking along similar lines.

[1]: https://arxiv.org/abs/2306.03078

comment 3y ago · link · parent

Go for it! I think you will learn a lot, and it seems like your expectations are calibrated well.

Source: wrote a browser[1]. I enjoyed it and learned a lot. My motivation for starting it is that the open source browser landscape was bleak at the time. There was khtml, which seemed fairly solid, but that was KDE and I was firmly in the Gnome camp. Mine was very fast and lean, but wouldn't scale to embrace what's now considered the basics of a web browser: JS and CSS. Motivation tailed off sharply when Mozilla announced they would be open sourcing their browser. If I had known it would take them over 4 years to ship Firefox 1.0, I might have kept at it.

Gambatte!

[1]: https://levien.com/gzilla/

comment 3y ago · link · parent

Yeah, Rich Feldman has a good talk on this, entitled Why Static Typing Came Back[1]. It makes a good argument that static typing can recover most of the advantages traditionally accounted to dynamic typing. Rapid iteration you can get from incremental compilers, being concise you can get from powerful type inference, etc. Conversely, the advantages of static typing (largely boiling down to increased reliability) cannot easily be captured by dynamically typed languages. Gradual typing, particularly successful by TypeScript, might be an interesting middle ground, or it might just be a reflection of the dynamic history of JS.

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

comment 3y ago · link · parent

The actual formula is O(n^6) scaling, and for circles it's very easy to achieve that. So a circle divided into 16ths has 4096 times less error than one in quarters and one made of 128 nodes is a (binary) billion times better.

This is true for curve fitting of arbitrary curves, not just circles, though arbitrary curve fitting is a bit tricky (it requires solving quartic equations). I personally think you can take this as evidence that cubic Béziers are "good enough" for all practical tasks requiring curve representation, though for specific applications there might be other representations that work better.

comment 3y ago · link · parent

It's a bit tricky, but my decimal adc is 19 lines of code, all of which is fairly straightforward, mostly bit fiddling stuff that I expect will compile to a few instructions each.

I need to go through an open source releasing process but I'll get that going. Thanks for your interest!

comment 3y ago · link · parent

I'm also noodling on an emulator, shooting for cycle accuracy (to the point where you'd be able to run vapor lock demos). Mine passes the 6502 functional tests but not yet the Tom Harte suite. To add to the difficulty, I want to run it on an RP2040 and bit-bang the video. Is yours up in an open source repo? Mine isn't (yet) but I'm open to joining forces.

I started mine about 6 years ago, put it on the shelf, and am getting back to it. Overall I think Rust is working well for it (and for pico DVI out), but I can also see the advantages of Zig for something this low-level and specialized.

comment 3y ago · link · parent

They are related, thanks for the pointer! The representation of the tree is very similar, as are the techniques to get better than O(log n) - the work efficiency stuff. I'll add a reference to that if/when I do a published version. That said, I am unaware of any publications on parallel implementations of succinct trees.

comment 3y ago · link · parent

The stack monoid is related to the bicyclic semigroup (which got its name before "monoid" was more common, though I do see both names), but I am drawing a distinction: the bicyclic semigroup counts parentheses, while the stack monoid actually contains elements of some type (which is free). So the primary difference is how much storage is required for the representation; the bicyclic semigroup is very conveniently represented as a pair of natural numbers, while the stack monoid requires space proportional to the maximum stack depth. That's why it's so challenging to implement on GPU.

comment 3y ago · link · parent

Not sure why this is popping up now, but people should know there's been quite a bit of followup work. One is a draft paper (not yet polished for publication), on arXiv[1]. I have an issue on my blog[2], and one of these days I intend to get back to it. It's also in use in Vello for the clip stack, in particular computing the intersection of bounding boxes of all clip paths in the spine of the tree from the leaf draw object to the root (clips can be nested to considerable depth). In any case, happy to talk about it.

[1]: https://arxiv.org/abs/2205.11659

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

comment 3y ago · link · parent

This is a good reason to bit-bang the protocol. It is in fact possible to get HDMI including audio out of an RP2040, as is demonstrated by infones[1], a NES emulator.

[1]: https://github.com/shuichitakano/pico-infones

comment 3y ago · link · parent

It needs to be done in the renderer. I think it's doable though, the FidelityFX library looks like it can be ported, it'll just run a bit slow because of the lack of subgroups. This particular library isn't based on a fancy scan implementation, as the state-of-the-art CUDA implementations are. There's a bit more followup in the linked Zulip thread.

comment 3y ago · link · parent

I can perhaps refine (1) and provide some insight in support of (2).

It does make intuitive sense for handles to be 1/3 of the length of the curve, as that makes the "speed" close to constant, but this is not the smoothest possible choice in general. In particular, it's not the best approximation to a circular arc, which by most reasonable definitions is the smoothest possible curve. I did the math[1] and found that there's a parabola around each endpoint that does result in an accurate arc approximation, and in fact may be easier to apply as it doesn't move around as the length of the curve changes. Rather, each of the parabolas can be applied independently.

Evidence in favor of this is O(n^5) accuracy scaling to approximate Euler spirals (which are also a good candidate for "smoothest possible curve" depending on the way you define that). I suspect, but haven't yet demonstrated, that there's some variational sense in which this choice is optimum, or at least to a first order approximation.

You can think of cubic Béziers as forming a four-dimensional parameter space (the parameters can be accounted as the lengths and angles of the control handles; in this scheme, the positions of the endpoints are not counted). By applying a rule such as 1/3 arc length, or falling on a parabola, that reduces it to a two-dimensional space (same dimensionality as quadratic Beziers, Euler spirals, and sections of rectangular elastica). I think two dimensions is too few, as it doesn't give you the ability to easily form superellipse shapes, a particular strength of cubic Béziers and quite handy for font design, as superellipse is extremely common in fonts. I think there may be some value in exploring a three-dimensional parameter space (which, among other things, is the count for general elastica) and have some ideas.

As for (2), the problem is that for s-shaped curves, cubic Béziers tend to put curvature maxima near but not exactly on endpoints. Since the curvature maximum is visually salient, you do better subdividing your curves so you can place them at joins. Other curve families, notably those based on elastica and Euler spirals, don't have this problem.

[1]: https://raphlinus.github.io/curves/2021/02/19/parallel-curve...

comment 3y ago · link · parent

The goals look quite similar to my hyperbezier explorations. There's an online demo of the first draft[1], and a Zulip thread on some progress toward a second draft[2]. The tl;dr is that I think I have the mathematics of the curve family, but I haven't finished the mapping between control points and the parameters of the curve family.

Both drafts have (exact) Euler spirals inside their parameter space, and thus circular arcs as well. I think that's a good criterion for a Bézier successor.

It's on the back burner for now, but I hope to get back to it, and am open to collaboration.

[1]: https://www.cmyr.net/blog/hyperbezier.html

[2]: https://xi.zulipchat.com/#narrow/stream/260979-kurbo/topic/H...

comment 3y ago · link · parent

I'm also looking forward to it. One of the big challenges is the sorting, for which I'm unaware of a good WebGPU implementation. I have some more notes on this question in a Zulip thread[1].

[1]: https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/Gau...

comment 3y ago · link · parent

Right, in relatively recent versions of LLVM, there is a "freeze" operation. Making it available to programmers, possibly as a method off MaybeUninit, would potentially be useful. The safety overlaps that of "safe transmute" (and ecosystem crates such as bytemuck that provide that). The Pod trait[1] probably establishes the invariants so that freeze on uninitialized memory is safe.

I imagine the details are tricky (my understanding is that "freeze" took a long time to land in LLVM), but that there's no fundamental reason it can't be done. But I also imagine there are a lot higher priorities; the use case in this blog is pretty niche.

There's more discussion in this thread: [2]

[1]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html

[2]: https://internals.rust-lang.org/t/freeze-maybeuninit-t-maybe...

comment 3y ago · link · parent

I suspect it may be: https://www.youtube.com/watch?v=5I4YPkVU7mY

I'm interested in this because these linearized tree representations lend themselves well to processing on GPU. We use them in Vello for representing clip and blend groups, with quite deep nesting level allowed. By contrast, the traditional pointer chasing approach to ASTs limits parallelism and has poor utilization of memory bandwidth.

comment 3y ago · link · parent

Last I checked[1], Swift JSON performance was terrible, well over an order of magnitude slower than serde. It's possible it's been improved since then but if so I didn't find any announcement.

[1]: https://github.com/xi-editor/xi-mac/issues/102

comment 3y ago · link · parent

Amen. When someone does the math and adds up the winners and losers in all this, one clear winner will be this video from Asianometry, entitled The History of Superconductors (Before LK-99)[1]. It only lightly touched on LK-99 itself, but did an excellent job going through the actual science-based history of superconductors, covering in particular detail previous hype waves. A major point is that the YBCO superconductors, while an amazing scientific discovery, haven't had revolutionary applications, and have only lightly displaced lower temperature (niobium-titanium metal alloy) superconductors in applications requiring generating strong magnetic fields, including MRI machines. For the curious, [2] goes into considerable detail on potential applications and challenges for HTSC in MRI.

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

[2]: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5472374/

comment 3y ago · link · parent

So the HP 2645 did use a half-bit shift and it's quite clever. It's shown in this video[1] by CuriousMarc (I've set the timestamp to the relevant part). The document shown in the video is available on the Internet Archive[2]. It also reminds me of techniques used in Epson dot matrix printer fonts, where the rate of pin firing couldn't be increased, but the half-pixel timing could be.

I'm pretty sure DEC VT100 and VT220 did not do this. There is some dot-stretching logic in the VT100 and VT220[3], which improves appearance but doesn't increase effective resolution.

Apple ][ is a slightly different story. The high bit (very similar to the HP terminal) does cause a half-pixel shift, but I believe this was almost entirely used to create more colors through NTSC artifacts, not to increase horizontal resolution. I'm unaware of a character ROM that uses the technique, but I could be missing something. The best writeup I've found is [4], and I also found an original description in BYTE magazine[5] from Steve Wozniak himself.

[1]: https://www.youtube.com/watch?v=QikO0WOAGWI&t=371s

[2]: https://archive.org/details/bitsavers_hpterminaleriesCharact...

[3]: https://www.masswerk.at/nowgobang/2019/dec-crt-typography

[4]: https://retrocomputing.stackexchange.com/questions/6271/what...

[5]: https://archive.org/details/byte-magazine-1979-06/page/n61/m...

comment 3y ago · link · parent

To a first approximation, Kompute[1] is that. It doesn't seem to be catching on, I'm seeing more buzz around WebGPU solutions, including wonnx[2] and more hand-rolled approaches, and IREE[3], the latter of which has a Vulkan back-end.

[1]: https://kompute.cc/

[2]: https://github.com/webonnx/wonnx

[3]: https://github.com/openxla/iree

comment 3y ago · link · parent

I think we'll get there but it will take years to arrive at a robust solution, because of the complexity of the ecosystem. The cooperative matrix extension, the portable and standard way to do what is usually marketed as "tensor cores," just landed in the spec and drivers a couple months ago. It will take people time to figure out how to use them effectively, partly because you have to query which options are supported at runtime.

There's still a driver and you're still at mercy of it (bugs and all), it's just much more likely to be installed on your Windows or Linux machine than a ROCm stack.

comment 3y ago · link · parent

I'll give some context. Shaping is converting a string of unicode code points into a sequence of glyphs, each with an advance and also finer positioning. For typical Latin fonts, shaping is straightforward; each code point generally corresponds to one glyph, but sometimes there are ligatures ("fi" is often one glyph), and then there is kerning, usually placing pairs of glyphs such as AV closer together if there would be a gap between them. But for complex fonts such as Nastaliq (used in writing Urdu), the rules get a lot more complicated.

OpenType shaping is currently defined in terms of a whole bunch of rewrite rules, with some script-specific knowledge (such as reordering vowels in Indic) added in by the shaping engine. The original idea is that it would be declarative and fairly easy for font designers to work with, but in practice it's pretty clunky, and doesn't scale well as complexity goes up. It's also slow to evaluate on modern computers because sequence matching is very branchy, and it's not unusual to require dozens of passes.

A particularly striking example is hieroglyphics. These compose multiple elements together into a block, with rules not unlike CSS grid. Sometimes there's vertical stacking, sometimes horizontal, occasionally more complex interactions like nestling inside an L. It is possible to encode this into OpenType rules, but it's very much a hack - at heart you need to do fairly simple geometry calculations to add up the total widths and divide them proportionally, but think about writing that as a regex and you'll get some idea how it comes out.

This proposal replaces the OpenType shaping rules with a call into WASM, where you can do these sorts of calculations straightforwardly and in a single pass. It is another Turing complete language (as is OpenType shaping, as proved by Behdad a few years ago, and TrueType hints), but there are excellent off-the-shelf implementations and it's well known how to run it securely sandboxed.

Even for Latin, this kind of thing would be useful for making a font that looks like real handwriting, for example. You can fake that in OpenType to a certain extent, but it goes beyond what the format was designed to handle.

This is a first cut, as it only affects positioning of premade glyphs. One thing I'd like to see going forward is adjusting variation parameters. As an example, a typical Devanagari (Hindi) font has 6 or so different widths of "ि" depending on the width of the consonant cluster it composes with (so रि or ल्कि). With variation connected to shaping, you could have one glyph of variable width, and the shaping engine could just set the variation to the right value, and with greater precision to boot.

If I were designing a new font format from scratch, this is definitely the way I'd do it. I'm excited to see where it goes.

comment 3y ago · link · parent

I think the suitable followup to this is the Richard Feldman talk, "Why Static Typing Came Back."[1] It gives the major reasons why one would prefer one over the other, and makes the case that static types can provide most of the actual benefits of dynamic languages, but the reverse is not true.

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

comment 3y ago · link · parent

I love flattened ASTs. One of my favorite uses of them is for inline markup in pulldown-cmark (see [1] for a brief description).

Here's a sketch of the problem being solved. The raw input is broken into a sequence of nodes, and something like * is turned into a "MaybeEmphasis" node, as it has the potential to turn into emphasis, or remain text if no match for it is found.

Another pass goes through those nodes in sequence, using a stack to find potential matches (the rules for whether a pair of such nodes actually match are quite fiddly and complicated). When a match is found, the MaybeEmphasis node is turned into the appropriate emphasis node, and the entire sequence of nodes between open and close is snipped out and made into a subtree of the new node. This is a somewhat unusual tree transformation, and a straightforward implementation could easily be O(n). But with the flattened AST representation, it can all be done O(1), no matter the number of nodes or stack depth.

For those interested in details, the tree representation is in [2] - there's basically a "child" and "next" index along with the node body - and the tree surgery on emphasis match is in [3].

The performance is excellent. I think pulldown-cmark may not be the single fastest CommonMark parser out there, but it's certainly competitive, and a lot faster than approaches that do, for example, an allocation per node.

[1]: https://fullyfaithful.eu/pulldown-cmark/

[2]: https://github.com/raphlinus/pulldown-cmark/blob/b7e709c0bd6...

[3]: https://github.com/raphlinus/pulldown-cmark/blob/b7e709c0bd6...

1
91011
63