|
1 | 1 | # Examples
|
2 | 2 |
|
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 using |
| 20 | + [wasm](https://webassembly.org/). |
| 21 | +- **ash:** runs the shader code on the GPU using |
| 22 | + [ash](https://crates.io/crates/ash), a Vulkan wrapper crate for Rust. |
| 23 | +- **CPU:** runs the shader code directly on the CPU, using rayon for |
| 24 | + parallelism. |
| 25 | + |
| 26 | +Not all shaders work with all runners. The following combinations are |
| 27 | +supported. |
| 28 | + |
| 29 | +- WGPU runner: |
| 30 | + - `cargo run --release -p example-runner-wgpu` runs the sky shader. |
| 31 | + - `cargo run --release -p example-runner-wgpu -- --shader=sky` also runs the |
| 32 | + sky shader. |
| 33 | + - `cargo run --release -p example-runner-wgpu -- --shader=simplest` runs the |
| 34 | + simplest shader. |
| 35 | + - `cargo run --release -p example-runner-wgpu -- --shader=mouse` runs the |
| 36 | + mouse shader. |
| 37 | + - `cargo run --release -p example-runner-wgpu -- --shader=compute` runs the |
| 38 | + compute shader. |
| 39 | + |
| 40 | +- WGPU+wasm runner in the browser (requires browser WebGPU support, most |
| 41 | + recently tested with Chromium 140 on Linux): |
| 42 | + - `rustup target add wasm32-unknown-unknown` installs the necessary wasm |
| 43 | + support for Rust. |
| 44 | + - `cargo run-wasm -p example-runner-wgpu` runs the local server hosting the |
| 45 | + mouse shader. |
| 46 | + - `chromium --enable-unsafe-webgpu http://localhost:8000` runs Chromium with |
| 47 | + WebGPU enabled and views the mouse shader. (The mouse shader is the default |
| 48 | + on WGPU+wasm.) |
| 49 | + |
| 50 | +- ash runner: |
| 51 | + - `cargo run --release -p example-runner-ash` runs the sky shader. Use the up and |
| 52 | + down arrows to adjust the sun's intensity. Use F5 to recompile the shader |
| 53 | + code (but note that the image won't redraw afterwards unless the intensity is |
| 54 | + adjusted). |
| 55 | + |
| 56 | +- CPU runner: |
| 57 | + - `cargo run --release -p example-runner-cpu` runs the sky shader. |
| 58 | + |
| 59 | +Finally, the `multibuilder` folder is a very short example of how to use the |
| 60 | +`multimodule` feature of `spirv-builder`. |
0 commit comments