wgpu/documentation/getting_started/
learning_wgpu.rs

1/*!
2# Learning wgpu: Key Concepts and Resources
3
4If you are new to `wgpu` and graphics programming, this page collects
5external learning resources and a primer on the core concepts of the API.
6
7## External resources
8
9Learning materials:
10
11- [Learn Wgpu tutorial](https://sotrh.github.io/learn-wgpu/)
12- [Draw You a Triangle for Great Good](https://github.com/dwbrite/wgpu-rendering-project/wiki/Draw-You-a-Triangle-for-Great-Good)
13- Chinese version of [学习 wgpu](https://jinleili.github.io/learn-wgpu-zh/)
14- [GPU Architecture](https://docs.google.com/presentation/d/1qi2j-SZuzew7Rrf5VKEPDZAQQEitV40k9fKvwJNyicM/edit),
15  a presentation by Kangz on how GPUs work under the hood.
16
17Reference material:
18
19- The `wgpu` examples; see
20  [Running the Examples](crate::documentation::getting_started::running_the_examples).
21- The [WebGPU specification](https://www.w3.org/TR/webgpu/), which `wgpu`
22  follows closely.
23
24Runtimes:
25
26- The [Deno](https://deno.land/) JS/TS runtime.
27
28## Important concepts
29
30### Device and Queue
31
32- [`Device`]
33  - All resource creation.
34  - All of its methods take `&self` (no `&mut`!).
35- [`Queue`]
36  - All GPU work submission.
37
38_Typically_ both are created once on startup, one of each. A [`Device`] is
39created with a set of [`Features`] and [`Limits`], which are enforced
40independently of the underlying hardware's actual capabilities (e.g. texture
41size and formats, number of bound resources, native extensions, …).
42
43### Relationship of [`RenderPipeline`]s and resource binding
44
45A slightly simplified overview of what you need to set up before rendering a
46frame.
47
48*/
49#![doc = include_str!("../images/render-pipeline-and-resource-binding.svg")]
50/*!
51
52- _Round boxes:_ temporary descriptor structs.
53- _Cornered boxes:_ resources created from a [`Device`].
54- _Bold:_ what you deal with on a per-frame basis.
55
56Each [`BindGroupLayoutEntry`] has a (mostly) corresponding
57[`BindingResource`]. Compute pipelines follow a similar pattern.
58
59### Drawing a "frame"
60
61A simplified overview of what you need to do to draw a frame.
62
63*/
64#![doc = include_str!("../images/life-of-a-frame.svg")]
65/*!
66
67- _Full lines:_ needed for creation.
68- _Dashed lines:_ provided as "information".
69
70[`CommandEncoder::finish`] consumes a [`CommandEncoder`] and produces a
71[`CommandBuffer`]; [`Queue::submit`] consumes [`CommandBuffer`]s. The
72[`TextureView`] on a [`RenderPassColorAttachment`] can come from a
73[`Surface`] — a special target for the final output.
74
75*/
76
77use crate::{
78    BindGroupLayoutEntry, BindingResource, CommandBuffer, CommandEncoder, Device, Features, Limits,
79    Queue, RenderPassColorAttachment, RenderPipeline, Surface, TextureView,
80};