gfx-rs/wgpu
examples
The examples/ directory contains every demo program shipped with the repository. There are two kinds:
- Feature demos under
examples/features/— share a common framework and a single binary entry point. - Standalone demos under
examples/standalone/— copy-and-paste-ready, intentionally self-contained. - Bug repros under
examples/bug-repro/— minimal programs reproducing specific issues.
The pre-built feature demos are also published online at https://wgpu.rs/examples/.
Feature demos
examples/features/
├── Cargo.toml
└── src/
├── main.rs dispatch entry point
├── framework.rs ~27 KB — winit + state-machine framework shared by every demo
├── lib.rs
├── utils.rs
├── big_compute_buffers/
├── boids/
├── bunnymark/
├── conservative_raster/
├── cooperative_matrix/
├── cube/
├── hello_synchronization/
├── hello_triangle/
├── hello_windows/
├── hello_workgroups/
├── mesh_shader/
├── mipmap/
├── msaa_line/
├── multiple_render_targets/
├── multiview/
├── ray_aabb_compute/
├── ray_cube_compute/
├── ray_cube_fragment/
├── ray_cube_normals/
├── ray_scene/
├── ray_shadows/
├── ray_traced_triangle/
├── render_to_texture/
├── render_with_compute/
├── repeated_compute/
├── shadow/
├── skybox/
├── srgb_blend/
├── stencil_triangles/
├── storage_texture/
├── texture_arrays/
├── timestamp_queries/
├── uniform_values/
└── water/31 demos in total. Each is a directory with:
- A
mod.rs(ormain.rs) implementing theframework::Exampletrait. - One or more
*.wgslshaders. - An optional
README.mddescribing the technique.
Run them
cargo run --bin wgpu-examples cube
cargo run --bin wgpu-examples water
cargo xtask run-wasm # web build, served locallyframework.rs provides a winit + pollster-based skeleton: window creation, surface configuration, swapchain handling, frame loop, input forwarding to each example.
As tests
cargo xtask test --bin wgpu-examples runs each example for a single frame, captures the output, and compares it to a reference image in the example's directory using nv-flip. This catches regressions in shader translation and rendering pipelines.
docs/testing.md's "Example Tests" section documents the harness.
Standalone demos
examples/standalone/
├── 01_hello_compute/ compute shader saying hello
├── 02_hello_window/ minimal window + clear color
└── custom_backend/ how to plug in a custom backend via `wgpu::backend::custom`These intentionally don't depend on the shared framework so they can be lifted into a fresh project. Each has its own Cargo.toml. They're not tested as part of xtask test.
Bug repros
examples/bug-repro/...Tiny self-contained programs that reproduce specific upstream issues. They live in the workspace so they keep building (and so contributors don't have to file new repros for old known bugs).
Integration points
- Above: developers learning wgpu, contributors testing a feature.
- Below:
wgpu(re-exporting everything else).
When to add a new example
- Adding a new feature gate: pair it with a feature demo so the API gets exercised.
- Demonstrating a non-obvious technique: a feature demo if it benefits from the shared framework, a standalone if it should be copy-paste-able.
- Reproducing a bug: a bug-repro that the maintainers can run locally.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.