1e5c31af7Sopenharmony_ci# Amber 2e5c31af7Sopenharmony_ci 3e5c31af7Sopenharmony_ciAmber is a multi-API shader test framework. 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_ciAmber lets you capture and communicate shader bugs with the fluidity and ease of 6e5c31af7Sopenharmony_cia scripting flow: 7e5c31af7Sopenharmony_ci 8e5c31af7Sopenharmony_ci* No graphics API programming is required. 9e5c31af7Sopenharmony_ci * Supports Vulkan graphics API 10e5c31af7Sopenharmony_ci * WIP: Supports [Dawn][Dawn] graphics API 11e5c31af7Sopenharmony_ci* A single text string (or file) maps to a single graphics API pipeline test 12e5c31af7Sopenharmony_ci case. The text includes: 13e5c31af7Sopenharmony_ci * Input data, including buffers and images. 14e5c31af7Sopenharmony_ci * Shaders. 15e5c31af7Sopenharmony_ci * Expectations for the result of running the pipeline. 16e5c31af7Sopenharmony_ci* Shaders can be expressed in binary form (as hex), in SPIR-V assembly, or in a 17e5c31af7Sopenharmony_ci higher level shader language. 18e5c31af7Sopenharmony_ci* After executing the pipeline, result buffers and images can be saved to output 19e5c31af7Sopenharmony_ci files. 20e5c31af7Sopenharmony_ci 21e5c31af7Sopenharmony_ciAmber is influenced by [Talvos][Talvos] and [VkRunner][VkRunner]. 22e5c31af7Sopenharmony_ciThe [VkScript](docs/vk_script.md) syntax matches the format used by VkRunner. 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ciThis is not an officially supported Google product. 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ci## Writing Amber Tests 27e5c31af7Sopenharmony_ciWorking with Amber involves writing input test files. Some example files can be 28e5c31af7Sopenharmony_cisee in the [tests/cases](tests/cases) folder. 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ciThe main input format is [Amberscript](docs/amber_script.md). New features are 31e5c31af7Sopenharmony_ciadded to AmberScript as Amber is enhanced. This is the preferred format in which 32e5c31af7Sopenharmony_cinew script files are written. 33e5c31af7Sopenharmony_ci 34e5c31af7Sopenharmony_ci### Clear test as AmberScript 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_ci```groovy 37e5c31af7Sopenharmony_ciSHADER vertex vtex_shader PASSTHROUGH 38e5c31af7Sopenharmony_ciSHADER fragment frag_shader GLSL 39e5c31af7Sopenharmony_ci#version 430 40e5c31af7Sopenharmony_ci 41e5c31af7Sopenharmony_cilayout(location = 0) in vec4 color_in; 42e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 43e5c31af7Sopenharmony_ci 44e5c31af7Sopenharmony_civoid main() { 45e5c31af7Sopenharmony_ci color_out = color_in; 46e5c31af7Sopenharmony_ci} 47e5c31af7Sopenharmony_ciEND 48e5c31af7Sopenharmony_ci 49e5c31af7Sopenharmony_ciBUFFER img_buf FORMAT B8G8R8A8_UNORM 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_ciPIPELINE graphics my_pipeline 52e5c31af7Sopenharmony_ci ATTACH vtex_shader 53e5c31af7Sopenharmony_ci ATTACH frag_shader 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ci FRAMEBUFFER_SIZE 256 256 56e5c31af7Sopenharmony_ci BIND BUFFER img_buf AS color LOCATION 0 57e5c31af7Sopenharmony_ciEND 58e5c31af7Sopenharmony_ci 59e5c31af7Sopenharmony_ciCLEAR my_pipeline 60e5c31af7Sopenharmony_ciEXPECT img_buf IDX 0 0 SIZE 256 256 EQ_RGBA 0 0 0 0 61e5c31af7Sopenharmony_ci``` 62e5c31af7Sopenharmony_ci 63e5c31af7Sopenharmony_ciThe [VkScript](docs/vk_script.md) format is supported for historic reasons. It 64e5c31af7Sopenharmony_ciis based off, and very closely matches, the format accepted by VkRunner. There 65e5c31af7Sopenharmony_ciare no new features being added to VkScript, it is for historical use. 66e5c31af7Sopenharmony_ci 67e5c31af7Sopenharmony_ci### Clear test as VkScript 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ci``` 70e5c31af7Sopenharmony_ci[require] 71e5c31af7Sopenharmony_ciVK_KHR_get_physical_device_properties2 72e5c31af7Sopenharmony_ci 73e5c31af7Sopenharmony_ci[vertex shader passthrough] 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ci[fragment shader] 76e5c31af7Sopenharmony_ci#version 430 77e5c31af7Sopenharmony_ci 78e5c31af7Sopenharmony_cilayout(location = 0) in vec4 color_in; 79e5c31af7Sopenharmony_cilayout(location = 0) out vec4 color_out; 80e5c31af7Sopenharmony_ci 81e5c31af7Sopenharmony_civoid main() { 82e5c31af7Sopenharmony_ci color_out = color_in; 83e5c31af7Sopenharmony_ci} 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_ci[test] 86e5c31af7Sopenharmony_ciclear 87e5c31af7Sopenharmony_cirelative probe rect rgba (0.0, 0.0, 1.0, 1.0) (0, 0, 0, 0) 88e5c31af7Sopenharmony_ci``` 89e5c31af7Sopenharmony_ci 90e5c31af7Sopenharmony_ci## Requirements 91e5c31af7Sopenharmony_ci 92e5c31af7Sopenharmony_ci * Recommended: Configure at least one backend. See [Backends](#backends) below. 93e5c31af7Sopenharmony_ci * Git 94e5c31af7Sopenharmony_ci * CMake (version 3.7+ enables automatic discovery of an installed Vulkan SDK) 95e5c31af7Sopenharmony_ci * Ninja (or other build tool) 96e5c31af7Sopenharmony_ci * Python, for fetching dependencies and building Vulkan wrappers 97e5c31af7Sopenharmony_ci 98e5c31af7Sopenharmony_ci 99e5c31af7Sopenharmony_ci## Building 100e5c31af7Sopenharmony_ci``` 101e5c31af7Sopenharmony_cigit clone https://github.com/google/amber.git 102e5c31af7Sopenharmony_cicd amber 103e5c31af7Sopenharmony_ci./tools/git-sync-deps 104e5c31af7Sopenharmony_cimkdir -p out/Debug 105e5c31af7Sopenharmony_cicd out/Debug 106e5c31af7Sopenharmony_cicmake -GNinja ../.. 107e5c31af7Sopenharmony_cininja 108e5c31af7Sopenharmony_ci``` 109e5c31af7Sopenharmony_ci 110e5c31af7Sopenharmony_ciAlternatives: 111e5c31af7Sopenharmony_ci 112e5c31af7Sopenharmony_ci* On Windows, Amber normally statically links against the C runtime library. 113e5c31af7Sopenharmony_ci To override this and link against a shared C runtime, CMake option 114e5c31af7Sopenharmony_ci `-DAMBER_ENABLE_SHARED_CRT`. 115e5c31af7Sopenharmony_ci This will cause Amber to be built with `/MD` for release builds or `/MDd` for 116e5c31af7Sopenharmony_ci debug builds. 117e5c31af7Sopenharmony_ci 118e5c31af7Sopenharmony_ci### Android 119e5c31af7Sopenharmony_ci 120e5c31af7Sopenharmony_ci* Android build needs Android SDK 28, Android NDK r25b, Java 8. If you prefer 121e5c31af7Sopenharmony_ci other versions of Android SDK, Android NDK, Java, then you can change 122e5c31af7Sopenharmony_ci `ANDROID_PLATFORM` and `ANDROID_BUILD_TOOL_VERSION` in 123e5c31af7Sopenharmony_ci `tools/build-amber-sample.sh`. 124e5c31af7Sopenharmony_ci* Set up Android SDK path by running 125e5c31af7Sopenharmony_ci `export ANDROID_SDK_HOME=path/to/Android/SDK` in your shell. 126e5c31af7Sopenharmony_ci* Set up Android NDK path by running 127e5c31af7Sopenharmony_ci `export ANDROID_NDK_HOME=path/to/Android/NDK` in your shell. 128e5c31af7Sopenharmony_ci* Generate a KeyStore using `keytool` command and set up `KEY_STORE_PATH` 129e5c31af7Sopenharmony_ci env variable for the KeyStore file path. 130e5c31af7Sopenharmony_ci* Run `./tools/build-amber-sample.sh [build output directory path]`. 131e5c31af7Sopenharmony_ci 132e5c31af7Sopenharmony_ci#### Android plain executable 133e5c31af7Sopenharmony_ci 134e5c31af7Sopenharmony_ciIt is possible to obtain a plain executable for Android, as opposed to an APK, 135e5c31af7Sopenharmony_ciwith the following: 136e5c31af7Sopenharmony_ci 137e5c31af7Sopenharmony_ci``` 138e5c31af7Sopenharmony_cigit clone https://github.com/google/amber.git 139e5c31af7Sopenharmony_cicd amber 140e5c31af7Sopenharmony_ci./tools/git-sync-deps 141e5c31af7Sopenharmony_ci 142e5c31af7Sopenharmony_ci./tools/update_build_version.py . samples/ third_party/ 143e5c31af7Sopenharmony_ci./tools/update_vk_wrappers.py . . 144e5c31af7Sopenharmony_ci 145e5c31af7Sopenharmony_cimkdir build 146e5c31af7Sopenharmony_cicd build 147e5c31af7Sopenharmony_cimkdir app 148e5c31af7Sopenharmony_cimkdir libs 149e5c31af7Sopenharmony_ci${ANDROID_NDK_HOME}/ndk-build -C ../samples NDK_PROJECT_PATH=. NDK_LIBS_OUT=`pwd`/libs NDK_APP_OUT=`pwd`/app 150e5c31af7Sopenharmony_ci``` 151e5c31af7Sopenharmony_ci 152e5c31af7Sopenharmony_ciThe list of target ABIs can be configured in `samples/jni/Application.mk` by 153e5c31af7Sopenharmony_ciediting the APP_ABI entry: 154e5c31af7Sopenharmony_ci 155e5c31af7Sopenharmony_ci``` 156e5c31af7Sopenharmony_ciAPP_ABI := arm64-v8a armeabi-v7a x86 x86_64 157e5c31af7Sopenharmony_ci``` 158e5c31af7Sopenharmony_ci 159e5c31af7Sopenharmony_ciThe resulting executable will be produced as 160e5c31af7Sopenharmony_ci`build/app/local/<abi>/amber_ndk`. This executable can be run via the adb shell 161e5c31af7Sopenharmony_cion your device, e.g. under `/data/local/tmp` (`/sdcard` is generally not 162e5c31af7Sopenharmony_cisuitable because it is mounted with a non-executable flag). Also, vulkan layers 163e5c31af7Sopenharmony_cimay not be available to this executable as it is not an app, so make sure to use 164e5c31af7Sopenharmony_cithe `-d` flag to disable Vulkan layers: 165e5c31af7Sopenharmony_ci 166e5c31af7Sopenharmony_ci``` 167e5c31af7Sopenharmony_ciadb push build/app/local/<abi>/amber_ndk /data/local/tmp 168e5c31af7Sopenharmony_ciadb shell 169e5c31af7Sopenharmony_ci# Now on device shell 170e5c31af7Sopenharmony_cicd /data/local/tmp 171e5c31af7Sopenharmony_ci./amber_ndk -d <shader-test-files> 172e5c31af7Sopenharmony_ci``` 173e5c31af7Sopenharmony_ci 174e5c31af7Sopenharmony_ci### Optional Components 175e5c31af7Sopenharmony_ci 176e5c31af7Sopenharmony_ciThe components which build up Amber can be enabled or disabled as needed. Any 177e5c31af7Sopenharmony_cioption with `_SKIP_` in the name is on by default, any with `_USE_` is off by 178e5c31af7Sopenharmony_cidefault. 179e5c31af7Sopenharmony_ci 180e5c31af7Sopenharmony_ciThe available flags which can be defined are: 181e5c31af7Sopenharmony_ci * AMBER_SKIP_TESTS -- Skip building Amber unit tests 182e5c31af7Sopenharmony_ci * AMBER_SKIP_SAMPLES -- Skip building the Amber sample applications 183e5c31af7Sopenharmony_ci * AMBER_SKIP_SPIRV_TOOLS -- Disable the SPIRV-Tools integration 184e5c31af7Sopenharmony_ci * AMBER_SKIP_SHADERC -- Disable the ShaderC integration 185e5c31af7Sopenharmony_ci * AMBER_SKIP_LODEPNG -- Disable the LodePNG integration 186e5c31af7Sopenharmony_ci * AMBER_USE_DXC -- Enables DXC as a shader compiler 187e5c31af7Sopenharmony_ci * AMBER_USE_LOCAL_VULKAN -- Does not try to find the Vulkan SDK, builds needed 188e5c31af7Sopenharmony_ci components locally 189e5c31af7Sopenharmony_ci * AMBER_USE_CLSPV -- Enables CLSPV as a shader compiler 190e5c31af7Sopenharmony_ci * AMBER_USE_SWIFTSHADER -- Builds Swiftshader so it can be used as a Vulkan ICD 191e5c31af7Sopenharmony_ci 192e5c31af7Sopenharmony_ci``` 193e5c31af7Sopenharmony_cicmake -DAMBER_SKIP_TESTS=True -DAMBER_SKIP_SPIRV_TOOLS=True -GNinja ../.. 194e5c31af7Sopenharmony_ci``` 195e5c31af7Sopenharmony_ci 196e5c31af7Sopenharmony_ci#### DXC 197e5c31af7Sopenharmony_ci 198e5c31af7Sopenharmony_ciDXC can be enabled in Amber by adding the `-DAMBER_USE_DXC=true` flag when 199e5c31af7Sopenharmony_cirunning cmake. 200e5c31af7Sopenharmony_ci 201e5c31af7Sopenharmony_ci## Build Bots 202e5c31af7Sopenharmony_ci 203e5c31af7Sopenharmony_ciThere are a number of build bots to verify Amber continues to compile and run 204e5c31af7Sopenharmony_cion the various targets. Due to bot limitations, the integration tests are not 205e5c31af7Sopenharmony_cibeing run on the bots, just the unit tests. 206e5c31af7Sopenharmony_ci 207e5c31af7Sopenharmony_ci## Backends 208e5c31af7Sopenharmony_ci 209e5c31af7Sopenharmony_ciAmber is designed to run against different graphics APIs. 210e5c31af7Sopenharmony_ciAmber will build if no graphics API is found, but will only allow verifying the 211e5c31af7Sopenharmony_cisyntax of the amber script files. 212e5c31af7Sopenharmony_ci 213e5c31af7Sopenharmony_ciCurrently the Vulkan and Dawn graphics APIs are supported. 214e5c31af7Sopenharmony_ci 215e5c31af7Sopenharmony_ci### Using Vulkan as a backend 216e5c31af7Sopenharmony_ci 217e5c31af7Sopenharmony_ciA Vulkan implementation is found by CMake in the following priority order: 218e5c31af7Sopenharmony_ci 219e5c31af7Sopenharmony_ci * If `AMBER_USE_LOCAL_VULKAN` is enable the headers, loader and layers will be 220e5c31af7Sopenharmony_ci built locally and not found on the system. 221e5c31af7Sopenharmony_ci * If an enclosing CMake project includes the 222e5c31af7Sopenharmony_ci [Vulkan-Headers][Vulkan-Headers] 223e5c31af7Sopenharmony_ci CMake project, then headers will be picked up from there. 224e5c31af7Sopenharmony_ci 225e5c31af7Sopenharmony_ci In this case the CMake variable `Vulkan_LIBRARIES` can name the 226e5c31af7Sopenharmony_ci Vulkan library, or a default of `vulkan` will be used. 227e5c31af7Sopenharmony_ci 228e5c31af7Sopenharmony_ci * If you have CMake 3.7 or later, then the Vulkan implementation will 229e5c31af7Sopenharmony_ci be found from a Vulkan SDK as published by LunarG. 230e5c31af7Sopenharmony_ci 231e5c31af7Sopenharmony_ci Environment variables: 232e5c31af7Sopenharmony_ci * `VULKAN_SDK` should point to the platform-specific SDK directory 233e5c31af7Sopenharmony_ci that contains the `include` and `lib` directories. 234e5c31af7Sopenharmony_ci * `VK_ICD_FILENAMES` should point to the ICD JSON file. 235e5c31af7Sopenharmony_ci * `VK_LAYER_PATH` should point to the explicit\_layer.d folder. 236e5c31af7Sopenharmony_ci * `LD_LIBRARY_PATH` must contain the $VULKAN_SDK/lib/ folder for the 237e5c31af7Sopenharmony_ci validation libraries. 238e5c31af7Sopenharmony_ci 239e5c31af7Sopenharmony_ci ``` 240e5c31af7Sopenharmony_ci export VULKAN_SDK=$HOME/vulkan-macos-1.1.85.0/macOS 241e5c31af7Sopenharmony_ci export VK_ICD_FILENAMES=$VULKAN_SDK/etc/vulkan/icd.d/MoltenVK_icd.json 242e5c31af7Sopenharmony_ci export VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/explicit_layer.d 243e5c31af7Sopenharmony_ci export LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH 244e5c31af7Sopenharmony_ci ``` 245e5c31af7Sopenharmony_ci 246e5c31af7Sopenharmony_ci### Using Dawn as a backend 247e5c31af7Sopenharmony_ci 248e5c31af7Sopenharmony_ciWe assume you have built [Dawn][Dawn] from source, and have access to both the 249e5c31af7Sopenharmony_cisource and build trees. To build a Dawn backend for Amber, set the following 250e5c31af7Sopenharmony_ciCMake variables when configuring Amber: 251e5c31af7Sopenharmony_ci 252e5c31af7Sopenharmony_ci * `Dawn_INCLUDE_DIR`: The directory containing `dawn/dawn_export.h` 253e5c31af7Sopenharmony_ci (in the source tree). 254e5c31af7Sopenharmony_ci * `Dawn_GEN_INCLUDE_DIR`: The directory containing generated header 255e5c31af7Sopenharmony_ci `dawn/dawncpp.h` (in the build output tree). 256e5c31af7Sopenharmony_ci * `Dawn_LIBRARY_DIR`: The directory containing the `dawn_native` library (in 257e5c31af7Sopenharmony_ci the build output tree). 258e5c31af7Sopenharmony_ci 259e5c31af7Sopenharmony_ci### Using SwiftShader as a backend 260e5c31af7Sopenharmony_ci 261e5c31af7Sopenharmony_ciSwiftShader, if available, can be used by by exporting the `VK_ICD_FILENAMES` 262e5c31af7Sopenharmony_cienvironment variable and using it directly. If SwiftShader is not installed it 263e5c31af7Sopenharmony_cican be built with Amber by setting `AMBER_ENABLE_SWIFTSHADER` during the 264e5c31af7Sopenharmony_ciconfigure step of CMake. 265e5c31af7Sopenharmony_ci 266e5c31af7Sopenharmony_ci 267e5c31af7Sopenharmony_ci``` 268e5c31af7Sopenharmony_cimkdir out/sw 269e5c31af7Sopenharmony_cicd out/sw 270e5c31af7Sopenharmony_cicmake -GNinja -DAMBER_ENABLE_SWIFTSHADER=TRUE ../.. 271e5c31af7Sopenharmony_cininja 272e5c31af7Sopenharmony_ciexport VK_ICD_FILENAMES=$PWD/Linux/vk_swiftshader_icd.json 273e5c31af7Sopenharmony_ci./amber -d -V # Should see SwiftShader listed as device 274e5c31af7Sopenharmony_ci./amber -d ../../tests/cases/clear.amber 275e5c31af7Sopenharmony_ci``` 276e5c31af7Sopenharmony_ci 277e5c31af7Sopenharmony_ci## Amber Samples 278e5c31af7Sopenharmony_ci 279e5c31af7Sopenharmony_ciThe build will generate an `out/Debug/amber` executable which can be used to 280e5c31af7Sopenharmony_cirun amber scripts. The script can be used as 281e5c31af7Sopenharmony_ci`out/Debug/amber <path to amber file>`. 282e5c31af7Sopenharmony_ci 283e5c31af7Sopenharmony_ci``` 284e5c31af7Sopenharmony_ciout/Debug/amber tests/cases/clear.amber 285e5c31af7Sopenharmony_ci``` 286e5c31af7Sopenharmony_ci 287e5c31af7Sopenharmony_ciThe sample app returns a value of 0 on success or non-zero on error. Any issues 288e5c31af7Sopenharmony_ciencountered should be displayed on the console. 289e5c31af7Sopenharmony_ci 290e5c31af7Sopenharmony_ciRun `out/Debug/amber -h` to see a description of the program's command line options. 291e5c31af7Sopenharmony_ci 292e5c31af7Sopenharmony_ciExample AmberScript files can be found in the [tests/cases](tests/cases) 293e5c31af7Sopenharmony_cidirectory in this repository. 294e5c31af7Sopenharmony_ciAlso the [Vulkan Conformance Test 295e5c31af7Sopenharmony_ciSuite](https://github.com/KhronosGroup/VK-GL-CTS) contains many real-world 296e5c31af7Sopenharmony_ciexamples in its 297e5c31af7Sopenharmony_ci[external/vulkancts/data/vulkan/amber](https://github.com/KhronosGroup/VK-GL-CTS/tree/master/external/vulkancts/data/vulkan/amber) 298e5c31af7Sopenharmony_cisubdirectory. 299e5c31af7Sopenharmony_ci 300e5c31af7Sopenharmony_ciBy default, `out/Debug/amber` supports saving the output image into '.png' 301e5c31af7Sopenharmony_cifile. You can disable this by passing `-DAMBER_SKIP_LODEPNG=true` to cmake. 302e5c31af7Sopenharmony_ci 303e5c31af7Sopenharmony_ciThe `image_diff` program will also be created. This allows comparing two images 304e5c31af7Sopenharmony_ciusing the Amber buffer comparison methods. 305e5c31af7Sopenharmony_ci 306e5c31af7Sopenharmony_ci## Contributing 307e5c31af7Sopenharmony_ci 308e5c31af7Sopenharmony_ciPlease see the [CONTRIBUTING](CONTRIBUTING.md) and 309e5c31af7Sopenharmony_ci[CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) files on how to contribute to Amber. 310e5c31af7Sopenharmony_ci 311e5c31af7Sopenharmony_ci 312e5c31af7Sopenharmony_ci## References 313e5c31af7Sopenharmony_ci[Dawn]: https://dawn.googlesource.com/dawn/ 314e5c31af7Sopenharmony_ci[Talvos]: https://talvos.github.io/ 315e5c31af7Sopenharmony_ci[Vulkan-Headers]: https://github.com/KhronosGroup/Vulkan-Headers 316e5c31af7Sopenharmony_ci[VkRunner]: https://github.com/igalia/vkrunner 317e5c31af7Sopenharmony_ci 318