Skip to content

Commit 548c1ef

Browse files
Merge pull request #1371 from jasonrandrews/review
starting review of WebGPU Learning Path
2 parents b3fcfd7 + 1627c65 commit 548c1ef

File tree

7 files changed

+167
-75
lines changed

7 files changed

+167
-75
lines changed

content/learning-paths/smartphones-and-mobile/android_webgpu_dawn/1-webgpu-fundamentals.md

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,61 @@ layout: learningpathall
88

99
## What is WebGPU?
1010

11-
WebGPU is the successor to [WebGL](https://www.khronos.org/webgl/wiki/), a well adopted modern API standard for interfacing with GPUs. WebGPU provides better compatibility with modern GPUs, support for general-purpose GPU computations, faster operations, and access to more advanced GPU features. It is designed to provide a _unifed access_ to GPUs, agnostic to GPU vendors and Operating System the application runs on. WebGPU is essentially a Render Hardware Interface built on top of various backends APIs like Vulkan, DirectX, Metal depending on OS/platform. This duplicated development effort is made once by the web browsers and made available to us through the webgpu.h header they provide.
11+
WebGPU is the successor to [WebGL](https://www.khronos.org/webgl/wiki/), a well adopted modern API standard for interfacing with GPUs. WebGPU provides better compatibility with modern GPUs, support for general-purpose GPU computations, faster operations, and access to more advanced GPU features. It is designed to provide a _unified access_ to GPUs, agnostic to GPU vendors and operating systems.
1212

13-
![WebGPU High Level View](images/webgpu_highlevel.png "WebGPU High Level View")
13+
WebGPU is a Render Hardware Interface built on top of various backends APIs like Vulkan, DirectX, and Metal (depending on the operating system).
1414

15-
## Why WebGPU?
15+
WebGPU is available through web browsers using the webgpu.h header file.
1616

17-
WebGPU has been designed taking into learnings from older standards like WebGL, OpenGL etc. and is the only graphics API that benefits from
17+
The high level view of WebGPU is shown below:
1818

19-
* A Reasonable level of abstraction
19+
![WebGPU high level view #center](images/webgpu_highlevel.png "WebGPU High Level View")
20+
21+
## What are the benefits of WebGPU?
22+
23+
WebGPU takes into account learnings from older standards like WebGL and OpenGL and provides the following benefits:
24+
25+
* A reasonable level of abstraction
2026
* Good performance
2127
* Cross-platform
22-
* Backed by W3C Standards group
28+
* Backed by W3C standards group
2329
* Future-proof design
2430

25-
WebGPU is a standard and not a true API, so the implementation can be adopted and developed as an interface between native applications developed in any programming language and GPUs. Moreover the requirements in terms of performance for web pages is actually the same as for native application.
31+
WebGPU is a standard and not a true API, so the implementation can be adopted and developed as an interface between native applications developed in any programming language.
32+
33+
The performance requirements for web pages is actually the same as for native application.
2634

2735
{{% notice Note %}}
28-
When designing an API for the Web, the two key constraints are portability and privacy. We benefit here from the effort developed for portability, and fortunately the limitations of the API due to privacy considerations can be disabled when using WebGPU as a native API
36+
When designing an API for the Web, the two key constraints are portability and privacy.
37+
38+
The limitations of the API due to privacy considerations can be disabled when using WebGPU as a native API.
2939
{{% /notice %}}
3040

31-
## Why C++?
41+
## What are the benefits of using C++ for WebGPU?
3242

33-
The initial target for WebGPU was JavaScript and most of the initial implementation was done in JavaScript and the `webgpu.h` header file is written in C. In this learning path, we choose C++ rather than JavaScript or C because:
43+
The initial target for WebGPU was JavaScript. The initial `webgpu.h` header file is written in C.
3444

35-
* C++ is still the primary language used for high performance graphics application (video games, render engines, modeling tools, etc.).
45+
This Learning Path uses C++ rather than JavaScript or C because of the following benefits:
46+
47+
* C++ is still the primary language used for high performance graphics applications, such as video games, render engines, and modeling tools.
3648
* The level of abstraction and control of C++ is well suited for interacting with graphics APIs in general.
37-
* Graphics programming is a very good occasion to really learn C++.
49+
* Graphics programming is a good way to learn more C++.
50+
51+
## Dawn: the Google WebGPU implementation
52+
53+
Since WebGPU is a standard and not an implementation, there are different implementations.
3854

39-
## Dawn, Google's WebGPU implementation
55+
[Dawn](https://github.com/google/dawn) is an open-source and cross-platform implementation of the WebGPU standard.
56+
57+
It implements the WebGPU functionality specified in `webgpu.h`. Dawn is meant to be integrated as part of a larger system like Chromium or a native Android Application.
4058

41-
Since WebGPU is a standard and not implementation, there are different implementations. For this learning path we are using [Dawn](https://github.com/google/dawn), an open-source and cross-platform implementation of the WebGPU standard. It implements the WebGPU functionality specified in `webgpu.h`. Dawn is meant to be integrated as part of a larger systems like WebGPU in Chromium or in an native Android Application.
4259
Dawn provides several WebGPU building blocks:
4360

44-
* WebGPU C/C++ headers that applications and other building blocks use.
45-
* The `webgpu.h` version that Dawn implements.
46-
* A C++ wrapper for the `webgpu.h`.
47-
* A "native" implementation of WebGPU using platforms' GPU APIs: D3D12, Metal, Vulkan and OpenGL. See [per API support](https://github.com/google/dawn/blob/main/docs/support.md) for more details.
48-
* A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers
49-
* Tint is a compiler for the WebGPU Shader Language (WGSL) that can be used in standalone to convert shaders from and to WGSL.
61+
* WebGPU C/C++ headers that applications and other building blocks use, including a header file and C++ wrapper.
62+
* A "native" implementation of WebGPU using appropriate APIs: D3D12, Metal, Vulkan and OpenGL.
63+
* A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers.
64+
* Tint, a compiler for the WebGPU Shader Language (WGSL), that can be used to convert shaders to and from WGSL.
65+
66+
Because it is written in C++, Dawn provides better error messages and logging. Because it is open-source, it is easier to inspect stack traces when applications crash.
5067

51-
Dawn provides better error messages and logging, since it is written in C++ we can build it from source and thus inspect more deeply the stack trace in case of crash.
52-
Dawn is usually ahead of `wgpu-native` another WebGPU implementation with regards to implementation of new functionalities/changes in the standard.
68+
Dawn is usually ahead of `wgpu-native`, another WebGPU implementation, when it comes to new functionalities and standards changes.
Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,68 @@
11
---
2-
title: Setting up development environment
2+
title: Set up a development environment
33
weight: 3
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## Set up your development environment
9+
In this Learning Path, you will learn how to:
1010

11-
In this Learning Path, you will learn how to
12-
13-
* Integrate Dawn (WebGPU) in the application.
11+
* Integrate Dawn (WebGPU) in an application.
1412
* Use the APIs to render a simple 3D object.
1513
* Profile and analyze the application.
1614

1715
The first step is to prepare a development environment with the required software:
1816

1917
* [Android Studio](https://developer.android.com/studio)
20-
* Arm [Streamline](https://developer.arm.com/Tools%20and%20Software/Streamline%20Performance%20Analyzer) Performance Analyzer
21-
* Git.
22-
* Python 3.10 or later.
18+
* [Arm Performance Studio](https://www.arm.com/products/development-tools/graphics/arm-performance-studio)
19+
* Git
20+
* Python 3.10 or later
21+
22+
You can use any computer and operating system which supports the above software.
23+
24+
## Install Android Studio and the Android NDK
25+
26+
1. Download and install the latest version of [Android Studio](https://developer.android.com/studio/).
27+
28+
2. Start Android Studio.
29+
30+
3. Open the `Settings` dialog.
31+
32+
4. Navigate to `Languages & Frameworks`, then select `Android SDK`.
2333

24-
## Install Android Studio and Android NDK
34+
5. In the `SDK Platforms` tab, check `Android 14.0 ("UpsideDownCake")`
2535

26-
Follow these steps to install and configure Android Studio:
36+
![SDK Platforms #center](images/sdk-platforms.png "SDK Platforms")
2737

28-
* Download and install the latest version of [Android Studio](https://developer.android.com/studio/).
29-
* Start Android Studio and open the **Settings** dialog.
30-
* Navigate to **Languages & Frameworks**, then **Android SDK**.
31-
* In the **SDK Platforms** tab, check **Android 14.0 ("UpsideDownCake")**.
32-
* In the **SDK Tools** tab
33-
1. Check **35.0.0** under **Android SDK Build-Tools 35**
34-
2. Check **27.x.xxxxxx** under **NDk(Side by side)**
35-
3. Check **3.xx.x** under **CMake** (latest is recommended)
38+
6. In the `SDK Tools` tab check the following:
39+
* Check `Android SDK Build-Tools 35`
40+
* Check `NDK (Side by side)`
41+
* Check `CMake`
3642

37-
## Install Arm Streamline
43+
![SDK Tools #center](images/sdk-tools.png "SDK Tools")
3844

39-
Profiling an application, to make sure it is performant is an important step in the Android application development cycle. The default profiler in the Android Studio is great to profile CPU related metrics, but does not provide details when it comes to GPUs. Arm has developed a comprehensive profiling software, Streamline, to profile both CPU and GPU. Streamline is an application profiler that can capture data from multiple sources, including:
45+
Click OK to install and update the selected components.
46+
47+
## Install Arm Performance Studio
48+
49+
Profiling is an important step in the Android application development cycle.
50+
51+
The default profiler in the Android Studio is great to profile CPU related metrics, but does not provide GPU details.
52+
53+
Arm Performance Studio is a comprehensive profiling tool to profile both CPU and GPU.
54+
55+
One of the components of Performance Studio is Streamline. Streamline captures data from multiple sources, including:
4056

4157
* Program Counter (PC) samples from running application threads.
42-
* Samples from the hardware Performance Monitoring Unit (PMU) counters in the Arm CPU, Arm® Mali GPUs, and Arm Immortalis GPUs.
58+
* Samples from the hardware Performance Monitoring Unit (PMU) counters in Arm CPUs, Arm Mali GPUs, and Arm Immortalis GPUs.
4359
* Thread scheduling information from the Linux kernel.
4460
* Software-generated annotations and counters from running applications.
4561

46-
You can download and install latest version of [Streamline](https://developer.arm.com/Tools%20and%20Software/Streamline%20Performance%20Analyzer) for your Operating System
62+
Install Arm Performance Studio using the [install guide](/install-guides/ams/).
4763

4864
{{% notice Tip %}}
49-
If you wan to learn more about streamline, you can refer to the ["Getting Started with Streamline"](https://developer.arm.com/documentation/101816/0903/Getting-started-with-Streamline)
65+
If you want to learn more about Arm Performance Studio and Streamline before continuing, refer to ["Get started with Arm Performance Studio for mobile"](https://learn.arm.com/learning-paths/smartphones-and-mobile/ams/ams/)
5066
{{% /notice %}}
67+
68+
Android Studio and Arm Performance Studio are now installed and you are ready to create a WebGPU Android application.
Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Dawn integration
2+
title: Create an application which includes Dawn
33
weight: 4
44

55
### FIXED, DO NOT MODIFY
@@ -8,34 +8,69 @@ layout: learningpathall
88

99
## Set up Android Project
1010

11-
After successful [Android Studio](./2-env-setup.md#install-android-studio-and-android-ndk) installation, open Android studio and create a new C++ game activity
11+
You can start by creating a new Android Studio project.
1212

13-
![New Game Activity](./images/android_studio_new_game_activity.png "Figure 1. New C++ Game Activity")
13+
Open Android studio, click `New Project` and select `Game Activity (C++)` as shown below:
1414

15-
GameActivity is a Jetpack library designed to assist Android games in processing app cycle commands, input events, and text input in the application's C/C++ code. GameActivity is a direct descendant of NativeActivity and shares a similar architecture:
15+
![New Game Activity #center](./images/android_studio_new_game_activity.png "New C++ Game Activity")
1616

17-
![Game Activity Architecture](./images/GameActivityArchitecture.png "Figure 2. Game Activity Architecture")
17+
Select `Next` to continue.
18+
19+
Finish the new project creation by accepting all defaults until the project is created.
20+
21+
## About the Game Activity
22+
23+
GameActivity is a Jetpack library designed to assist Android games in processing app cycle commands, input events, and text input in the application's C/C++ code.
24+
25+
GameActivity is a direct descendant of NativeActivity and shares a similar architecture:
26+
27+
![Game Activity Architecture #center](./images/GameActivityArchitecture.png "Game Activity Architecture")
1828

1929
With GameActivity, you can focus on your core game development and avoid spending excessive time dealing with the Java Native Interface (JNI) code.
30+
2031
GameActivity performs the following functions:
2132

22-
* Interacting with Android framework through the Java-side component.
23-
* Passing app cycle commands, input events, and input text to the native side.
24-
* Renders into a SurfaceView, making it much easier for games to interact with other UI components.
33+
* Interacts with the Android framework through the Java-side component.
34+
* Passes app cycle commands, input events, and input text to the native side.
35+
* Renders into a SurfaceView, making it easier for games to interact with other UI components.
2536

2637
{{% notice Tip %}}
27-
You can find more information about Android Game Activity and its capabilities [here](https://developer.android.com/games/agdk/game-activity).
38+
You can find more information about Android Game Activity and its capabilities in the [Game Activity documentation](https://developer.android.com/games/agdk/game-activity).
2839
{{% /notice %}}
2940

30-
## Upgrade application to include Dawn
41+
## Upgrade the application to include Dawn
42+
43+
The Android Game Activity framework uses OpenGLES3 for graphics.
44+
45+
You can remove this dependency and replace it with WebGPU.
46+
47+
Start by including the [webgpu.hpp](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/webgpu/include/webgpu/webgpu.hpp) header file in the project:
48+
49+
1. In Android Studio, navigate to the project view and find the `app` --> `cpp` folder.
50+
51+
Open terminal in Android Studio. You should be in the MyApplication directory.
3152

32-
The Android stock Game Activity framework uses OpenGLES3 for graphic purposes. We want to remove this dependency and replace it with WebGPU. We start by including the [webgpu.hpp](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/webgpu/include/webgpu/webgpu.hpp) header file in the project:
53+
2. Create a new directory and download the WebGPU header file from GitHub
3354

34-
* Go to **project view** --> **app** --> **cpp**
35-
* Create a new directory **webgpu** --> **include** --> **webgpu**
55+
Run the commands below to download the `webgpu.hpp` header file:
3656

37-
Next copy the remaining files in the [webgpu](https://github.com/varunchariArm/Android_DawnWebGPU/tree/main/app/src/main/cpp/webgpu) directory to corresponding directory in your project.
38-
You can notice in the [FetchDawn.cmake](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/webgpu/FetchDawn.cmake) we are utilizing a stable `chromium/6536` branch of Dawn repository. We are downloading this branch and setting a few CMake options in the file for Dawn build.
57+
```console
58+
mkdir -p app/src/main/cpp/webgpu/include/webgpu
59+
cd app/src/main/cpp/webgpu/include/webgpu
60+
wget https://raw.githubusercontent.com/varunchariArm/Android_DawnWebGPU/refs/heads/main/app/src/main/cpp/webgpu/include/webgpu/webgpu.hpp
61+
cd ../..
62+
```
63+
64+
3. Next copy the remaining files in the [webgpu](https://github.com/varunchariArm/Android_DawnWebGPU/tree/main/app/src/main/cpp/webgpu) directory to corresponding directory in your project.
65+
66+
```console
67+
wget https://raw.githubusercontent.com/varunchariArm/Android_DawnWebGPU/refs/heads/main/app/src/main/cpp/webgpu/CMakeLists.txt
68+
wget https://raw.githubusercontent.com/varunchariArm/Android_DawnWebGPU/refs/heads/main/app/src/main/cpp/webgpu/FetchDawn.cmake
69+
wget https://raw.githubusercontent.com/varunchariArm/Android_DawnWebGPU/refs/heads/main/app/src/main/cpp/webgpu/fetch_dawn_dependencies.py
70+
wget https://raw.githubusercontent.com/varunchariArm/Android_DawnWebGPU/refs/heads/main/app/src/main/cpp/webgpu/webgpu.cmake
71+
```
72+
73+
Notice the [FetchDawn.cmake](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/webgpu/FetchDawn.cmake) uses a stable `chromium/6536` branch of Dawn repository.
3974

4075
{{% notice Note %}}
4176
WebGPU is constantly evolving standard and hence its implementation, Dawn is also under active development. For sake of stability, we have chosen a stable branch for our development. Updating to latest or different branch may cause breakage.
@@ -47,9 +82,17 @@ To add Dawn to our application, we have 2 options:
4782
* Download the source as a dependency and build it as part of the project build
4883

4984
We are choosing the second option, since it provides more debug flexibility.
85+
5086
The [webgpu/webgpu.cmake](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/webgpu/webgpu.cmake) and [CMakeLists.txt](https://github.com/varunchariArm/Android_DawnWebGPU/blob/main/app/src/main/cpp/CMakeLists.txt) file facilitates downloading and building WebGPU with Dawn implementation and integrating Dawn into our main project
5187

52-
We are also setting a few more Dawn build options
88+
Run the build:
89+
90+
```console
91+
cmake .
92+
make -C _deps/dawn-build
93+
```
94+
95+
This section doesn't seen needed, just information:
5396

5497
```bash
5598
#Set Dawn build options
@@ -60,7 +103,9 @@ option(DAWN_USE_X11 "" OFF)
60103
option(ENABLE_PCH "" OFF)
61104
```
62105

63-
Finally make sure you include the built `webgpu` library into your project by
106+
4. Add WebGPU to the project.
107+
108+
Edit the file `CMakeLists.txt` to remove the WebGL and add `webgpu` libraries.
64109

65110
``` bash
66111
# Configure libraries CMake uses to link your target library.
@@ -75,4 +120,6 @@ target_link_libraries(dawnwebgpu
75120
log)
76121
```
77122

78-
Now we have setup our project to download Dawn source code, build it and include it in our project. The `webgpu.hpp` header file acts like an interface, exposing all WebGPU functions and variables to our main Application.
123+
The project is now ready to build.
124+
125+
The `webgpu.hpp` header file acts like an interface, exposing all WebGPU functions and variables to the main Application.

0 commit comments

Comments
 (0)