gfx-rs nuts and bolts

gfx-rs is a project bringing efficient cross-platform graphics to rust. This blog supposedly hosts the major milestones, concepts, and recaps of the project.


This Year in Wgpu - 2021

25 Dec 2021

gfx-rs community’s goal is to make graphics programming in Rust easy, fast, and reliable. Our main projects are:

  • wgpu is built on top of wgpu-hal and naga. It provides safety, accessibility, and portability for graphics applications.
  • naga translates shader programs between languages, including WGSL. It also provides shader validation and transformation, ensuring user code running on the GPU is safe and efficient.

As 2021 comes to an end, let’s look back at everything that has been accomplished.

Fredrik Norén's terrain with trees

Wgpu

We moved from gfx-hal to the newly created wgpu-hal and restructured the repository to keep everything together. At the same time, we dropped SPIRV-Cross in favor of naga, reaching the pure-rust tech stack. Read more in the 0.10 release post. Credit goes to @kvark.

At the same time, @cwfitzgerald has revamped our testing infrastructure with Rust integration tests and example snapshots. On top of that, wgpu has tightly integrated with Deno (thanks to the effort of Deno team!), opening up the road to testing on a real CTS, which is available in CI now.

One shiny highlight of the year was the WebGL port, which became practically usable. Getting it ready was truly a collaborative effort, kicked off by @zicklag. Today, wgpu-rs examples can be run online with WebGL.

In terms of correctness and portability, @Wumpf landed the titanic work of ensuring all our resources are properly zero-initialized. This has proven to be much more involved than it seems, and now users will get consistent behavior across platforms.

Finally, we just released version 0.12 with the fresh and good stuff!

Naga

Naga grew more backends (HLSL, WGSL) and greatly improved support all around the table. It went from an experimental prototype in 0.3 to production, shipping in Firefox Nightly. It proved to be 4x faster than SPIRV-Cross at SPV->MSL translation.

One notable improvement, led by @JCapucho with some help from @jimblandy, is the rewrite of SPIR-V control flow processing. This has been a very problematic and complicated area in past, and now it’s mostly solved.

Things have been busy on GLSL frontend as well. It got a completely new parser thanks to @JCapucho, which made it easier to improve and maintain.

Validation grew to cover all the expressions and types and everything. For some time, it was annoying to see rough validation errors without any reference to the source. But @ElectronicRU saved the day by making our errors really nice, similar to how WGSL parser errors were made pretty by @grovesNL work earlier.

Last but not the least, SPIR-V and MSL backends have been bullet-proofed by @jimblandy. This includes guarding against out-of-bounds accesses on arrays, buffers, and textures.

Future Work

One big project that hasn’t landed is the removal of “hubs”. This is a purely internal change, but a grand one. It would streamline our policy of locking internal data and allow the whole infrastructure to scale better with more elaborate user workloads. We hope to see it coming in 2022.

Another missing piece is DX11 backend. We know it’s much needed, and it was the only regression from the wgpu-hal port. This becomes especially important now as Intel stopped supporting DX12 on its Haswell GPUs.

Overall, there’s been a lot of good quality contributions, and this list by no means can describe the depth of it. We greatly appreciate all the improvements and would love to shout out about your work at the earliest opportunity. Big thanks for everybody involved!