1# ANGLE Development 2 3ANGLE provides OpenGL ES 3.1 and EGL 1.5 libraries and tests. You can use these to build and run OpenGL ES applications on Windows, Linux, Mac and Android. 4 5## Development setup 6 7### Version Control 8 9ANGLE uses git for version control. Helpful documentation can be found at [http://git-scm.com/documentation](http://git-scm.com/documentation). 10 11### Required First Setup (do this first) 12 13Note: If you are building inside a Chromium checkout [see these instructions instead](https://chromium.googlesource.com/angle/angle/+/HEAD/doc/BuildingAngleForChromiumDevelopment.md). 14 15Required on all platforms: 16 17 * [Python 3](https://www.python.org/downloads/) must be available in your path. 18 * [depot_tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up) 19 * Required to download dependencies (with gclient), generate build files (with GN), and compile ANGLE (with ninja). 20 * Ensure `depot_tools` is in your path as it provides ninja for compilation. 21 * For Googlers, run `download_from_google_storage --config` to login to Google Storage before fetching the source. 22 23On Windows: 24 25 * ***IMPORTANT: Set `DEPOT_TOOLS_WIN_TOOLCHAIN=0` in your environment if you are not a Googler.*** 26 * Install [Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/) 27 * Install the [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/). 28 * You can install it through Visual Studio Installer if available. It might be necessary to switch to the `Individual components` tab to find the latest version. 29 * The currently supported Windows SDK version can be found in [vs_toolchain.py](https://chromium.googlesource.com/chromium/src/build/+/refs/heads/main/vs_toolchain.py). 30 * The SDK is required for GN-generated Visual Studio projects, the D3D Debug runtime, and the latest HLSL Compiler runtime. 31 * (optional) See the [Chromium Windows build instructions](https://chromium.googlesource.com/chromium/src/+/main/docs/windows_build_instructions.md) for more info. 32 33On Linux: 34 35 * Dependencies will be handled later (see `install-build-deps.sh` below). 36 37On MacOS: 38 39 * [XCode](https://developer.apple.com/xcode/) for Clang and development files. 40 * For Googlers on MacOS, you'll first need authorization to download macOS SDK's from Chromium 41 servers before running `gclient sync`. Obtain this authorization via `cipd auth-login` 42 and following the instructions. 43 44### Getting the source 45 46``` 47mkdir angle 48cd angle 49fetch angle 50``` 51 52If you're contributing code, you will also need to set up the Git `commit-msg` hook. See [ContributingCode#getting-started-with-gerrit](ContributingCode.md#getting-started-with-gerrit) for instructions. 53 54On Linux only, you need to install all the necessary dependencies before going further by running this command: 55``` 56./build/install-build-deps.sh 57``` 58 59If building for Android (which requires Linux), switch to the [Android steps](https://chromium.googlesource.com/angle/angle.git/+/HEAD/doc/DevSetupAndroid.md) at this point. 60 61After this completes successfully, you are ready to generate the ninja files: 62``` 63gn gen out/Debug 64``` 65 66If you had trouble checking out the code, please inspect the error message. As 67a reminder, on Windows, ensure you **set `DEPOT_TOOLS_WIN_TOOLCHAIN=0` in 68your environment if you are not a Googler**. If you are a Googler, ensure you 69ran `download_from_google_storage --config`. 70 71GN will generate ninja files. The default build options build ANGLE with clang 72and in release mode. Often, the default options are the desired ones, but 73they can be changed by running `gn args out/Debug`. Some options that are 74commonly overriden for development are: 75 76``` 77is_component_build = true/false (false forces static links of dependencies) 78target_cpu = "x64"/"x86" (the default is "x64") 79is_debug = true/false (use false for release builds. is_debug = true is the default) 80angle_assert_always_on = true/false (enables release asserts and runtime debug layers) 81is_clang = false (NOT RECOMMENDED) (to use system default compiler instead of clang) 82``` 83 84For a release build run `gn args out/Release` and set `is_debug = false`. 85Optionally set `angle_assert_always_on = true` for Release testing. 86 87On Windows, you can build for the Universal Windows Platform (UWP) or WinUI 3. 88For UWP, set `target_os = "winuwp"` in the args. For WinUI 3, instead set 89`angle_is_winappsdk=true` along with the path to the Windows App SDK 90headers: `winappsdk_dir="/path/to/headers"`. The headers need to be generated 91from the winmd files, which is done by running the `scripts/winappsdk_setup.py` 92script and passing in the path to store the headers. 93For both UWP and WinUI 3, setting `is_component_build = false` is highly 94recommended to support moving libEGL.dll and libGLESv2.dll to an application's 95directory and being self-contained, instead of depending on other DLLs 96(d3dcompiler_47.dll is still needed for the Direct3D backend). 97We also recommend using `is_clang = false`. 98 99For more information on GN run `gn help`. 100 101Use `autoninja` to compile on all platforms with one of the following commands: 102 103``` 104autoninja -C out/Debug 105autoninja -C out/Release 106``` 107 108`depot_tools` provides `autoninja`, so it should be available in your path 109from earlier steps. Ninja automatically calls GN to regenerate the build 110files on any configuration change. `autoninja` automatically specifies a 111thread count to `ninja` based on your system configuration. 112 113### Building with Reclient (Google employees only) 114 115Reclient is the recommended distributed compiler service to build ANGLE faster. 116 117Step 1. Follow [Setup remote execution](https://g3doc.corp.google.com/company/teams/chrome/linux_build_instructions.md?cl=head#setup-remote-execution) 118to download the required configuration, and complete the authentication. 119 120To download the required configuration: 121 122In .gclient, add `"download_remoteexec_cfg: True,"` in custom_vars: 123 124``` 125solutions = [ 126 { 127 # some other args 128 "custom_vars": { 129 "download_remoteexec_cfg": True, 130 }, 131 }, 132] 133 134``` 135 136Then run 137 138``` 139gclient sync 140``` 141 142To complete authentication: 143 1441. Install gcloud SDK go/gcloud-cli#installing-and-using-the-cloud-sdk. 145Make sure the gcloud tool is available on your `$PATH`. 146 1472. Log into gcloud with your @google.com account: 148 149``` 150gcloud auth login 151``` 152 153If asked for a project ID, enter "0". 154 155Step 2. Enable the usage of reclient by adding below content in GN arg: 156 157``` 158use_remoteexec = true 159``` 160 161### Building and Debugging with Visual Studio 162 163To generate the Visual Studio solution in `out/Debug/angle-debug.sln`: 164 165``` 166gn gen out/Debug --sln=angle-debug --ide=vs2022 --ninja-executable="C:\src\angle\third_party\ninja\ninja.exe" 167``` 168 169In Visual Studio: 170 1. Open the ANGLE solution file `out/Debug/angle-debug.sln`. 171 2. We recommended you use `autoninja` from a command line to build manually. 172 3. "Build Solution" from the IDE is broken with GN. You can use the IDE to build one target or one file at a time. 173 174Once the build completes, all ANGLE libraries, tests, and samples will be located in `out/Debug`. 175 176### Building ANGLE for Android 177 178See the Android specific [documentation](DevSetupAndroid.md#ANGLE-for-Android). 179 180### Building ANGLE for iOS simulator 181 182This is currently possible only from Chromium checkout. 183Follow [Chromium for iOS build instructions](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/ios/build_instructions.md). 184GN args used by [ANGLE for iOS builder](https://ci.chromium.org/ui/p/chromium/builders/luci.chromium.ci/ios-angle-builder) are supported, e.g.: 185``` 186dcheck_always_on = true 187enable_run_ios_unittests_with_xctest = true 188is_component_build = false 189is_debug = false 190symbol_level = 1 191target_cpu = "x64" 192target_environment = "simulator" 193target_os = "ios" 194``` 195Building `angle_end2end_tests` and `angle_white_box_tests` targets is supported. 196 197## Application Development with ANGLE 198 199This sections describes how to use ANGLE to build an OpenGL ES application. 200 201### Choosing a Backend 202 203ANGLE can use a variety of backing renderers based on platform. On Windows, it defaults to D3D11 where it's available, 204or D3D9 otherwise. On other desktop platforms, it defaults to GL. On mobile, it defaults to GLES. 205 206ANGLE provides an EGL extension called `EGL_ANGLE_platform_angle` which allows uers to select 207which renderer to use at EGL initialization time by calling eglGetPlatformDisplayEXT with special 208enums. Details of the extension can be found in its specification in 209`extensions/EGL_ANGLE_platform_angle.txt` and `extensions/EGL_ANGLE_platform_angle_*.txt` and 210examples of its use can be seen in the ANGLE samples and tests, particularly `util/EGLWindow.cpp`. 211 212To change the default D3D backend: 213 214 1. Open `src/libANGLE/renderer/d3d/DisplayD3D.cpp` 215 2. Locate the definition of `ANGLE_DEFAULT_D3D11` near the head of the file, and set it to your preference. 216 217To remove any backend entirely: 218 219 1. Run `gn args <path/to/build/dir>` 220 2. Set the appropriate variable to `false`. Options are: 221 - `angle_enable_d3d9` 222 - `angle_enable_d3d11` 223 - `angle_enable_gl` 224 - `angle_enable_metal` 225 - `angle_enable_null` 226 - `angle_enable_vulkan` 227 - `angle_enable_essl` 228 - `angle_enable_glsl` 229 230### To Use ANGLE in Your Application 231On Windows: 232 233 1. Configure your build environment to have access to the `include` folder to provide access to the standard Khronos EGL and GLES2 header files. 234 * For Visual C++ 235 * Right-click your project in the _Solution Explorer_, and select _Properties_. 236 * Under the _Configuration Properties_ branch, click _C/C++_. 237 * Add the relative path to the Khronos EGL and GLES2 header files to _Additional Include Directories_. 238 2. Configure your build environment to have access to `libEGL.lib` and `libGLESv2.lib` found in the build output directory (see [Building ANGLE](#building-with-visual-studio)). 239 * For Visual C++ 240 * Right-click your project in the _Solution Explorer_, and select _Properties_. 241 * Under the _Configuration Properties_ branch, open the _Linker_ branch and click _Input_. 242 * Add the relative paths to both the `libEGL.lib` file and `libGLESv2.lib` file to _Additional Dependencies_, separated by a semicolon. 243 3. Copy `libEGL.dll` and `libGLESv2.dll` from the build output directory (see [Building ANGLE](#building-with-visual-studio)) into your application folder. 244 4. Code your application to the Khronos [OpenGL ES 2.0](http://www.khronos.org/registry/gles/) and [EGL 1.4](http://www.khronos.org/registry/egl/) APIs. 245 246On Linux and MacOS, either: 247 248 - Link you application against `libGLESv2` and `libEGL` 249 - Use `dlopen` to load the OpenGL ES and EGL entry points at runtime. 250 251## GLSL ES Translator 252 253In addition to OpenGL ES and EGL libraries, ANGLE also provides a GLSL ES 254translator. The translator targets various back-ends, including HLSL, GLSL 255for desktop and mobile, SPIR-V and Metal SL. To build the translator, build 256the `angle_shader_translator` target. Run the translator binary without 257arguments to see a usage message. 258 259### Source and Building 260 261The translator code is included with ANGLE but fully independent; it resides 262in [`src/compiler`](../src/compiler). Follow the steps above for 263[getting and building ANGLE](#getting-the-source) to build the translator on 264the platform of your choice. 265 266### Usage 267 268The ANGLE [`shader_translator`](../samples/shader_translator/shader_translator.cpp) 269sample demos basic C++ API usage. To translate a GLSL ES shader, call the following 270functions in the same order: 271 272 * `sh::Initialize()` initializes the translator library and must be called only once from each process using the translator. 273 * `sh::ContructCompiler()` creates a translator object for vertex or fragment shader. 274 * `sh::Compile()` translates the given shader. 275 * `sh::Destruct()` destroys the given translator. 276 * `sh::Finalize()` shuts down the translator library and must be called only once from each process using the translator. 277 278## OpenCL Support 279 280A few GN args are needed to enable OpenCL runtime code to be built in the ANGLE lib(s). 281 282`args.gn` 283``` 284# Global enable flag for OpenCL support 285angle_enable_cl = true 286 287# Enable the Vulkan backend 288angle_enable_vulkan = true 289 290# Enable the CL backend (i.e. passthrough) if needed 291angle_enable_cl_passthrough = false // or true 292``` 293 294### OpenCL artifacts 295 296The two main artifacts generated here are `OpenCL_ANGLE` and `GLESv2`: 297 298- `OpenCL_ANGLE` : Acts as a loader for CL entrypoints from the `GLESv2` library and populates it's 299API dispatch table with them. 300- `GLESv2` : Is the ANGLE library itself that also includes the OpenCL entrypoints/runtime when 301`angle_enable_cl = true`. 302 303Additional `Vulkan-backend` artifacts 304 305- `clspv_core_shared` : clspv as a shared library to compile OpenCL C source over a 306[C API](https://github.com/google/clspv/blob/main/docs/C_API.md) used by the `GLESv2` library. 307 308### OpenCL Usage 309 310ANGLE's OpenCL implementation acts no different from any other OpenCL ICD. Applications can either link to an 311existing system OpenCL-ICD-Loader, or it can link directly to the `OpenCL_ANGLE` via its exported OpenCL 312entrypoints. 313 314If using an existing system OpenCL-ICD-Loader, then make sure `OpenCL_ANGLE` can be found by the OpenCL-ICD-Loader, 315see [OpenCL-ICD-Loader](https://github.com/KhronosGroup/OpenCL-ICD-Loader) for details on this. 316 317In both cases, `OpenCL_ANGLE` works by using `LoadLibrary/dlopen` on the `GLESv2` library to build the OpenCL 318dispatch table using the entrypoints/symbols from `GLESv2` library. From then on, that API dispatch table is either 319given to the system ICD Loader, or if app is linked directly to the `OpenCL_ANGLE` lib, it just uses its 320singular dispatch table to forward onto `GLESv2` OpenCL entrypoints. 321