-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a blog post about pure-rust release
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
layout: post | ||
title: Pure Rust | ||
--- | ||
|
||
One of the most requested features for vange-rs was to have binary releases. It turned out that glsl-to-spirv that we used was completely unportable. It expected to be present on the target machine at the same directory as the developer one had at build time. This happened to be blocking both the binary releases, and a proper Web port in the future. | ||
|
||
## WGSL | ||
|
||
Recently, we finished migrating the essential majority of the shaders to WebGPU Shading Language. This allowed the shaders to be written in a more modern way, with multiple entry points and type inference. For example, this is how the scattering shader looks like now: | ||
|
||
```rust | ||
[[block]] | ||
struct Storage { | ||
data: array<atomic<u32>>; | ||
}; | ||
[[group(2), binding(0)]] var<storage, read_write> s_Storage: Storage; | ||
|
||
[[stage(compute), workgroup_size(16, 16, 1)]] | ||
fn clear([[builtin(global_invocation_id)]] pos: vec3<u32>) { | ||
if (pos.x < u_Locals.screen_size.x && pos.y < u_Locals.screen_size.y) { | ||
//TODO: 0xFFFFFF00U when hex is supported | ||
atomicStore(&s_Storage.data[pos.y * u_Locals.screen_size.x + pos.x], 4294967040u); | ||
} | ||
} | ||
|
||
[[stage(vertex)]] | ||
fn copy_vs([[builtin(vertex_index)]] index: u32) -> [[builtin(position)]] vec4<f32> { | ||
return vec4<f32>( | ||
select(-1.0, 1.0, index < 2u), | ||
select(-1.0, 1.0, (index & 1u) == 1u), | ||
0.0, 1.0, | ||
); | ||
} | ||
|
||
struct CopyOutput { | ||
[[location(0)]] color: vec4<f32>; | ||
[[builtin(frag_depth)]] depth: f32; | ||
}; | ||
|
||
[[stage(fragment)]] | ||
fn copy_fs([[builtin(position)]] pos: vec4<f32>) -> CopyOutput { | ||
... | ||
} | ||
|
||
[[stage(compute), workgroup_size(16,16,1)]] | ||
fn main( | ||
[[builtin(global_invocation_id)]] global_id: vec3<u32>, | ||
[[builtin(num_workgroups)]] num_workgroups: vec3<u32>, | ||
) { | ||
... | ||
} | ||
|
||
``` | ||
|
||
Today, all of the terrain shaders are ported over, and same goes for the object rendering and debugging. Everything except GPU physics is running WGSL path now, which is pure Rust from text to the target user drivers. We haven't figured out if the GPU physics path is worth maintaining/supporting. It's unlikely that physics is going to be a big issue in performance any time soon. | ||
|
||
## Releases | ||
|
||
With glsl-to-spirv out of the way, and vange-rs ported on [wgpu-0.10](https://gfx-rs.github.io/2021/08/18/release-0.10.html) release, the native dependencies (including SPIRV-Cross) are gone. Game is building faster, running faster, and is much easier to maintain. | ||
|
||
It took a few rounds of fixes to get the game to a state where it can be ran consistently on all platforms. It's not flawless by any means: there are frame pacing issues on some, and driver bugs on some other. But the general idea, the concept of having a single sane code base in Rust that is efficiently running on all platforms - that is there. And it runs fast, given how light the wgpu abstraction has become. | ||
|
||
![3rd-person rendering]({{site.baseurl}}/assets/3rd-person.png) | ||
|
||
We've set up an automated releasing workflow, so the binary can be created and uploaded whenever we feel necessary. Check out [Rusty Vangers 0.2](https://github.com/kvark/vange-rs/releases/tag/v0.2.0) release! | ||
|
||
Finally, as the executables are both hosted and portable, we decided it's time to reach out to wider audience. We created a small page for the game on Itch: https://kvark.itch.io/vangers . Hopefully, the running instructions aren't too complicated. | ||
|
||
The future frontier now is publishing directly on the Web, using WebGPU backend. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters