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

This sounds right to me. Rust takes its compatibility promise seriously, but reserves the right to break it when there's a security issue. This looks like it's one of those times.

comment 7y ago · link · parent

Robert Lord's comments on the issue are probably the best explanation, written with the benefit of hindsight.

[0]: https://github.com/xi-editor/xi-editor/issues/1187#issuecomm...

comment 7y ago · link · parent

For sure. If you're doing collaborative editing, then CRDT is a reasonable choice, but it comes with tradeoffs compared with other approaches such as OT, as I hope I've explained. (The comparison with differential synchronization is not as well understood as it should be - I suspect it works pretty well in practice but doesn't lend itself to academic analysis.)

On the other hand, the idea of using CRDT for something other than collaborative editing (or certain types of databases where eventual consistency is a reasonable consistency model) is almost certainly not worth the complexity. That's what I wish I had known when I started.

comment 7y ago · link · parent

Yeah definitely. I would consider this a form of semantic analysis, of the kind provided by Language Server implementations rather than the kind of syntax highlighting provided by syntect. Also note, the syntax highlighting done in xi-editor is both incremental and async[11]. This actually worked out well, and I would preserve it going forward. What I wrote above actually overstates the case, I think the ideal solution is an extremely simple form of OT so you can reuse as much as possible of the already-computed highlighting state, but you certainly throw away the highlighting result for the region being edited. Preserving "before" is trivial, and preserving "after" should be a simple matter of fixing up line counts.

[11]: https://xi-editor.io/docs/rope_science_11.html

comment 7y ago · link · parent

xi-editor pioneers a hybrid where "identifiers" are actually the tuple of revision and position. The motivation is to buy back some of the performance edge that OT has because of its use of position. I think if you are going to do CRDT it's pretty compelling, but that's also somewhat orthogonal to the complexity concerns raised in my original post.

comment 7y ago · link · parent

Thanks for the kind words.

comment 7y ago · link · parent

What you say is certainly true, but also not a fair characterization of what I wrote; we deliberately designed xi-editor from the early days to be consistent with the CRDT model (see the "rope science" series for thinking from the very early days).

But yes, if you have an existing editor or application and you try to just add CRDT, there are a lot of things that can go wrong.

comment 7y ago · link · parent

I'll be giving at talk at Libre Graphics Meeting in a couple weeks on exactly this topic. I'll make the slides available as well. Hopefully they'll make the front page of Hacker News also, as that seems to be a thing these days for my work :)

comment 7y ago · link · parent

It's a fine question. In the past, I've had a lawyer draft a patent grant (this was in 2000, there's a bit on my Wikipedia page about it). This time, I did two things.

First, and to make it legally very crisp, I used an Apache 2 license, which comes with an explicit patent grant. Second, renewal is coming up for the Spiro patent, and I'm not renewing it. Nor am I pursuing the provisional on the new spline work. These will take a few months to become legally binding, as theoretically I could change my mind, but the first I think makes it official right now.

comment 7y ago · link · parent

Just to answer the IME question, it refers to "Input Method Editor" and is an important problem to solve for all platforms, desktop, mobile, and Web. The API's for IME are often crufty and it's easy to get edge cases wrong. These days, lots of people care because emoji, but formerly it was something that English language speakers tended to ignore.

comment 7y ago · link · parent

I like the branch-predict / branch-verify split. It reminds me strongly of the ldrex/strex strategy in ARM for splitting (for example) a compare-exchange in two parts, so that in the non-contended case it basically just flows straight through.

Having recently done a lot of GPU programming, I'm wondering what your thoughts are on a GPU-like approach, with tons of in-order cores. It's hard to program, but maybe we need to figure that out in order to get performance.

comment 7y ago · link · parent

I know. I was eager to get this out. I'll be working on more visuals for a Libre Graphics Meeting presentation, where I'll include some of this in the Rust 2D graphics talk.

comment 7y ago · link · parent

Patrick is of course right here, macOS isn't quite like Flutter because it basically always texturizes, although ultimately this is under control of the programmers.

And perhaps it would be more accurate to say Flutter follows the Web, as many of the team are former Chrome engineers, though I think they've tried to clean up a lot of the warty stuff.

And absolutely, the idea of relying less on the compositor is not original to me, WebRender has similar goals, though I think I can make things performant, rich, and fairly simple by leveraging compute.

comment 7y ago · link · parent

Yes, macOS relies very heavily on CALayer to accomplish smooth scrolling, largely because much of the content of those layers is software-rendered. One thing that I find interesting is the subtle effect this has on the aesthetics of macOS (and iOS also) - lots of semitransparent planes sliding over each other and fading, very few other things that would be expensive in that model.

I think this is a bad approach on modern hardware, for the reasons kllrnohj stated.

comment 7y ago · link · parent

Yes. I'll have more to say soon, but I'm basically building what I think is next-gen UI infrastructure in Rust. That's a project with perhaps overly ambitious scope, so I'm starting with one specific app, namely a font editor. That will be a great showcase for beautifully antialiased vector paths and smooth-as-silk scrolling and interaction, I think.

comment 7y ago · link · parent

What makes you say that 2D graphics has worked well? Scrolling often janks, UI designers constantly have to work around limitations in the imaging model and performance quirks (for a long time, clipping to a rounded rect would kill performance), and there were lots of shortcuts with things like gamma for blending. I'm hoping to build something way better, where the UI always updates smoothly, and the UI designer doesn't have to be conscious of the limitations in the renderer.

comment 7y ago · link · parent

If you're talking about improving support for incremental present in Vulkan implementations, let's definitely connect. Certainly I can see how to do it well on Windows/DirectX, using IDXGISwapChain1::Present1. On macOS I think it's impossible (though Chrome sometimes fakes it by pasting update layers on top of the base window in the compositor).

comment 7y ago · link · parent

It's complicated. 2D graphics aren't inherently harder or require more computation than 3D, but they require very different optimizations. I think it boils down to the fact that 2D graphics is ultimately data structure heavy, whereas 3D graphics can often be represented as a huge array of triangles. So there's a lot of literature (some of which I linked, then those papers have a deep literature review), but no one obviously best solution. One thing I think I contributed is a relatively simple solution, especially for doing almost all the work on GPU rather than relying on CPU for things.

comment 7y ago · link · parent

Yes, https://github.com/linebender/piet-metal , it's mac-only (for now).

comment 7y ago · link · parent

Agree on both fronts! (Also, your username seems familiar somehow - have we had discussions around this before? :)

I didn't talk about this in the post because I haven't actually implemented fancy compositing, but based on what I've seen you never want to render to texture (which Flutter does sometimes) as it uses up scarce global GPU memory bandwidth, and if you're doing that using heuristics, then performance gets very unpredictable. I should express this more clearly, but the goal in piet-metal is not to do the fastest renderer (I'm sure it isn't), but the one with the most consistent and predictable performance.

comment 7y ago · link · parent

Agreed, and there are some deep issues, for example the rendering of very thin strokes which is quite dependent on resolution. Also keep in mind that the 4x4 oversampling you mentioned does not give nice smooth edges. I'm working on font editing, so the quality and smoothness of the line, to most accurately represent the shape without artifacts, is paramount.

comment 7y ago · link · parent

It is true that is more correct (see https://github.com/pcwalton/pathfinder/issues/142). But my motivation is much more user interface than document rendering, so it's quite reasonable to tell the UI designers, "don't do that," especially if the flip side is butter-smooth performance.

comment 7y ago · link · parent

These are all interesting questions. I've been following some of the stuff on Shadertoy, and I think that points the way. Most is 3d, but not all, and in particular there's a lot to be done with distance fields.

I've been thinking about blur (and mentioned some approximation techniques), but it's expensive in any context. Maybe if we think in shaders instead of the blur tool, we'll find a visual palette that is both fresh and efficient.

1524.

Show HN: 2D Graphics on Modern GPU(raphlinus.github.io ↗)

306 points · by raphlinus · 7y ago · 86 comments

comment 7y ago · link · parent

Wow, this is good. I gave it "Configure your pipeline state object with a compute shader that consumes uniforms and vertex buffers." and it came up with this:

Note that the compiler will add a compute shader at compile time and require you to configure your pipeline state every time. This is the equivalent on a more traditional GPU where shader compilation occurs between the GPU and CPU. For example if you want to set the shader with a single pass on a CPU it is reasonable to compile it each time after GPU rendering, and even compile it once on the GPU. This is an extension of the parallel compile-to-script: run-to-script approach.

It's a very compelling illusion of actually understanding the topic. I've seen less coherent responses on Stack Overflow and, dare I say it, Hacker News.

comment 7y ago · link · parent

The other big problem with mmap is what happens when your file changes out from under you. This seems to be mostly for git packfiles, which I think can be treated as immutable by convention, but that's not strongly enforced anywhere. For reading, eg, program source files, I think mmap is hugely problematic.

I've been arguing for a long time that operating systems should provide read only snapshots of files as a primitive, but that's a pretty big ask; it's especially hard to do when the file system is network-mounted. There are a couple of copy-on-write filesystems on Linux (btrfs and ZFS if memory serves) which can do this locally, but it's not mainstream.

comment 7y ago · link · parent

Try some JSON benchmarks with Codables in Swift vs serde in Rust. Rust smokes Swift, something like 20x.

Incidentally I've spent considerable effort on this problem, including writing a prototype faster JSON parser in Swift (still about 3x slower than Rust, but a huge speedup over what's there). I couldn't get anyone in the Swift community to care enough to motivate me to finish the work, which is indicative of a deeper problem: Swift just doesn't have "performance culture," the benchmark game results notwithstanding.

comment 7y ago · link · parent

Yes, I've seen examples of calling Rust from Swift, and I do plan to support that. This particular thing is about calling macOS platform functions from Rust code. Projects either call Objective-C API's from native Rust code using the dynamic invocation mechanism (which I think is slow and code-bloaty but want to measure more carefully), or they use the "cc" crate to include Objective-C code (and then generally use C ABI calls from Rust code into that). I've never seen Rust code that compiles Swift from a "cargo build" but of course would love to be proven wrong.

comment 7y ago · link · parent

Maybe I can, I just haven't found an example of it. Certainly the "cc" crate doesn't seem to know how to compile Swift files. This might be more of a documentation issue than a real technical limitation though.

comment 7y ago · link · parent

I'm an extreme outlier, but I'm about to start an Objective-C codebase (a 2D renderer on top of Metal), because I suspect interop with Rust will be a lot easier. In particular, it looks like you can just build .m files from a build.rs, and I'm pretty sure that's not true with Swift. It's also possible to invoke Obj-C from Rust using the dynamic features, but I think that's both code bloat and a runtime cost. [I'm interested in exploring these issues further, but it's probably outside the scope of this HN thread, get in touch if you want to discuss.]

Example build.rs: https://github.com/emoon/rust_minifb/blob/master/build.rs

1
505152
63