Skip to content

Commit 59fe1d7

Browse files
committed
2019 mid-year update
1 parent b5783d5 commit 59fe1d7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

_posts/2019-10-01-update.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
layout: post
3+
title: Project update
4+
---
5+
6+
gfx-rs is a Rust project aiming to make low-level GPU programming portable with low overhead. It's a single Vulkan-like Rust API with multiple backends that implement it: Direct3D 12/11, Metal, Vulkan, and even OpenGL.
7+
8+
wgpu-rs is a Rust project on top of gfx-rs that provides safety, accessibility, and even stronger portability.
9+
10+
This is an update that is not aligned to any dates or releases. We just want to share about some of the exciting work that landed recently, which will make it to the next release cycle.
11+
12+
## Slimmed down gfx-rs
13+
14+
We've done a few big steps towards making gfx-hal easier to build and maintain. First of all, we removed the "magical" dependencies, such as `failure` and `derivative` in favor of straight and simple code. That sped up the fresh gfx-hal build by a factor of 8.5X.
15+
16+
Secondly, the "typed" layer of gfx-hal got removed. Previously, we recognized that the view of the API for the backends (when implementing it) needs to be different from the users (to use it). Backends just need to implement "raw" interfaces, while users need more type safety, such as limiting the set of operations available on a command buffer when recording a render pass. For example, we had different entry points [create_command_pool](https://docs.rs/gfx-hal/0.3.1/gfx_hal/device/trait.Device.html#tymethod.create_command_pool) versus [create_command_pool_typed](https://docs.rs/gfx-hal/0.3.1/gfx_hal/device/trait.Device.html#method.create_command_pool_typed).
17+
18+
This duality of APIs in gfx-hal worked to an extent. Providing safety was impossible without imposing some restrictions or overhead. In the command pool example, it's only safe to re-use a command buffer if it's done execution on the GPU, and the user doesn't intent to use it. We can't possibly know this in gfx-hal without introducing overhead... So, at the end of the day, we decided that the "typed" (user-facing) layer is still useful, it doesn't have to be a part of gfx-hal. Thus, we removed it, recommending `rendy-command` as a replacement. This slimmed up gfx-hal API surface and allowed us to straighten up the terminology (no more "RawXXX" or "XxxTyped").
19+
20+
## Feature-less wgpu-rs
21+
22+
From the very beginning of gfx-rs project, it was structured in a way that backend implementations of the API lived in separate crates. The user (or library client) was responsible to select the proper backend for their needs. It was very difficult for a client to support multiple backends within the same binary, and to our knowledge - nobody did. A typical application would expose separate features for backends up [to the user](https://github.com/cloudhead/rx/blob/a296ebf4ce8dbbd6948488ba27765ed4cf8b4863/Cargo.toml):
23+
```
24+
vulkan = ["rgx/vulkan"]
25+
metal = ["rgx/metal"]
26+
dx11 = ["rgx/dx11"]
27+
dx12 = ["rgx/dx12"]
28+
```
29+
30+
With the set of supported backends growing, this became more and more of an issue. Asking the user to enable the proper feature doesn't solve the problem - it just puts it on the users shoulders. Moreover, using features in such a way is typically non-idiomatic, because in Rust features are supposed to be additive, but all of the user code (including our examples) was written to work with a single backend, even if it's generic.
31+
32+
Today, we are happy to announce that the problem is solved in wgpu-rs! Features are gone. The library knows which backends are supported on the target platform, it checks for their availability and enumerates their phusical adapters. When the user requests an adapter, they can provide a mask of backends, and the implementation will pick the most suitable adapter on one of the enabled backends.
33+
34+
The immediate effect on the users is that the library "just works". All the complicated machinery of the backends is now hidden within the implementation. This is the case currently for `master` and will make it to the next release.
35+
36+
## New swapchain model
37+
38+
Vulkan swapchain model is extremely powerful from the user perspective. Users control when and how each image is used, and explictly synchronize the rendering work with the presentation engine. Mapping this model to other APIs proved to be extremely challenging. Fortunately, Vulkan designers made it an extension from the start (`VK_swapchain_KHR`) as opposed to a part of the core, which leaves the room for experimentation with different models.
39+
40+
To solve this, an entirely new API was prototyped and implemented - all the way from gfx-rs backends to wgpu-rs. This API is roughly as limited as `CAMetalLayer` presentation:
41+
1. get the next image view
42+
2. render to it
43+
3. present it
44+
45+
It maps very nicely to Metal, OpenGL, and DX12/DX11, however requiring a bit more complexity on the Vulkan backend side, which is a cost we can live with.
46+
47+
What we have in the end is:
48+
- fast start-up
49+
- proper full-screen and resizing behavior
50+
- less bugs across the backends, consistency across platforms

0 commit comments

Comments
 (0)