Skip to content

Commit a3d33b9

Browse files
committed
Continue next version of The Adapter
1 parent f9bbd9e commit a3d33b9

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

next/getting-started/adapter-and-device/the-adapter.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ The Adapter <span class="bullet">🟢</span>
99

1010
*Resulting code:* [`step005-next`](https://github.com/eliemichel/LearnWebGPU-Code/tree/step005-next)
1111

12-
Before getting our hands on a **device**, we need to select an **adapter**. The same host system may expose **multiple adapters** if it has access to multiple physical GPUs. It may also have an adapter that represents an emulated/virtual device.
12+
Before getting our hands on a WebGPU **device**, we need to select an **adapter**.
13+
14+
```{tip}
15+
This chapter is a bit dense because it is also the occasion to **introduce multiple key concepts** of the WebGPU API, in particular the **asynchronous functions** and the `WGPUStringView` (that represents **character strings**).
16+
17+
Take the time to understand these concepts, it is going to pay off later on!
18+
```
19+
20+
Why do we need an adapter?
21+
--------------------------
22+
23+
The same host system may expose **multiple adapters** if it has access to multiple physical GPUs. It may also have an adapter that represents an emulated/virtual device.
1324

1425
```{note}
1526
It is common that high-end laptops have **two physical GPUs**, a **high performance** one (sometimes called *discrete*) and a **low energy** consumption one (that is usually integrated inside the CPU chip).
@@ -112,7 +123,7 @@ Here is a rough example to **illustrate the `userdata` mechanism**:
112123
void onAdapterRequestEnded(
113124
WGPURequestAdapterStatus status, // a success status
114125
WGPUAdapter adapter, // the returned adapter
115-
struct WGPUStringView message, // optional error message
126+
WGPUStringView message, // optional error message
116127
void* userdata1, // custom user data, as provided when requesting the adapter
117128
void* userdata2 // second custom user data
118129
) {
@@ -316,7 +327,21 @@ std::cerr << "Error while requesting adapter: " << toStdStringView(message) << s
316327

317328
We know how to request the adpater, and how to handle the response. But we do not know yet **how to wait** for the request to end before returning to the main function.
318329

319-
**WIP line**
330+
To keep track of ongoing asynchronous operations, each function that starts such an operation **returns a `WGPUFuture`**, which is some sort of internal ID that **identifies the operation**.
331+
332+
```C++
333+
WGPUFuture adapterRequest = wgpuInstanceRequestAdapter(instance, &options, callbackInfo);
334+
```
335+
336+
```{note}
337+
Although it is technically just an integer value, the `WGPUFuture` should be treated as an **opaque handle**, i.e., one should not try to deduce anything from the very value of this ID.
338+
```
339+
340+
**WIP line** *Maybe move this section up after Asynchronous function*
341+
342+
```C++
343+
WGPUWaitStatus wgpuInstanceWaitAny(WGPUInstance, size_t futureCount, WGPUFutureWaitInfo * futures, 0 /* timeoutNS */);
344+
```
320345
321346
When using the **native** API (Dawn or `wgpu-native`), it is in practice **not needed**, we know that when the `wgpuInstanceRequestAdapter` function returns its callback has been called.
322347
@@ -561,7 +586,11 @@ Conclusion
561586

562587
- The very first thing to do with WebGPU is to get the **adapter**.
563588
- Once we have an adapter, we can inspect its **capabilities** (limits, features) and properties.
564-
- We learned to use **asynchronous functions** and **double call** enumeration functions.
589+
- We learned to use **asynchronous functions**.
565590
- We have learned about `WGPUStringView`.
566591

592+
```{note}
593+
For more information about asynchronous operations in WebGPU, you may consult the [official specification](https://webgpu-native.github.io/webgpu-headers/Asynchronous-Operations.html).
594+
```
595+
567596
*Resulting code:* [`step005-next`](https://github.com/eliemichel/LearnWebGPU-Code/tree/step005-next)

0 commit comments

Comments
 (0)