Skip to content

Commit 29dbbaf

Browse files
committed
Improve examples documentation.
Better explain the shaders and runners, and explain how to invoke them, and even document the `+`/`-` feature of the sky shader on ash, which is currently invisible unless you read the code.
1 parent 46dcfc7 commit 29dbbaf

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

examples/README.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
# Examples
22

3-
The examples here are split into a few categories:
4-
5-
- The shaders folder contain various rust-gpu shaders, and are examples of how to use rust-gpu.
6-
- The runners folder contains programs that build and execute the shaders in the shaders folder using, for example,
7-
Vulkan. These programs are not exactly examples of how to use rust-gpu, as they're rather generic vulkan sample apps,
8-
but they do contain some infrastructure examples of how to integrate rust-gpu shaders into a build system (although
9-
both aren't the cleanest of examples, as they're also testing some of the more convoluted ways of consuming rust-gpu).
10-
- Finally, the multibuilder folder is a very short sample app of how to use the `multimodule` feature of `spirv-builder`.
3+
This directory contains several examples of rust-gpu use. There are shader
4+
examples in `shaders`, and runner programs that build and execute the shaders
5+
in a variety of ways in `runners`.
6+
7+
The shaders:
8+
- **sky:** draws a landscape with a small white sun, blue sky, and yellow
9+
ground. This is the default shader.
10+
- **simplest:** draws a red triangle on a green background.
11+
- **mouse:** a swirling animation that can be influenced by clicking and
12+
dragging the mouse cursor.
13+
- **compute:** a compute shader that prints a sequence of integers from the
14+
'3x+1' problem.
15+
16+
The runners:
17+
- **WGPU:** runs the shader code on the GPU using [wgpu](https://wgpu.rs), a
18+
graphics crate based on WebGPU.
19+
- **WGPU+wasm:** like WGPU but runs in a web browser.
20+
- **ash:** runs the shader code on the GPU using
21+
[ash](https://crates.io/crates/ash), a Vulkan wrapper crate for Rust.
22+
- **CPU:** runs the shader code directly on the CPU, using rayon for
23+
parallelism.
24+
25+
Not all shaders work with all runners. The following combinations are
26+
supported.
27+
28+
- WGPU runner:
29+
- `cargo run --release -p example-runner-wgpu` runs the sky shader.
30+
- `cargo run --release -p example-runner-wgpu -- --shader=sky` also runs the
31+
sky shader.
32+
- `cargo run --release -p example-runner-wgpu -- --shader=simplest` runs the
33+
simplest shader.
34+
- `cargo run --release -p example-runner-wgpu -- --shader=mouse` runs the
35+
mouse shader.
36+
- `cargo run --release -p example-runner-wgpu -- --shader=compute` runs the
37+
compute shader.
38+
39+
- WGPU+wasm runner in the browser (requires browser WebGPU support, most
40+
recently tested with Chromium 140 on Linux):
41+
- `rustup target add wasm32-unknown-unknown` installs the necessary wasm
42+
support for Rust.
43+
- `cargo run-wasm -p example-runner-wgpu` runs the local server hosting the
44+
mouse shader.
45+
- `chromium --enable-unsafe-webgpu http://localhost:8000` runs Chromium with
46+
WebGPU enabled and views the mouse shader. (The mouse shader is the default
47+
on WGPU+wasm.)
48+
49+
- ash runner:
50+
- `cargo run --release -p example-runner-ash` runs the sky shader. Use the up and
51+
down arrows to adjust the sun's intensity. Use F5 to recompile the shader
52+
code (but note that the image won't redraw afterwards unless the intensity is
53+
adjusted).
54+
55+
- CPU runner:
56+
- `cargo run --release -p example-runner-cpu` runs the sky shader.
57+
58+
Finally, the `multibuilder` folder is a very short example of how to use the
59+
`multimodule` feature of `spirv-builder`.

0 commit comments

Comments
 (0)