• Home
Name Date Size #Lines LOC

..--

android_sample/03-May-2024-516324

android_test/03-May-2024-4210

docs/03-May-2024-2,1611,782

include/amber/03-May-2024-557241

kokoro/03-May-2024-1,096683

samples/03-May-2024-2,6671,979

src/03-May-2024-43,52133,584

tests/03-May-2024-8,8156,743

third_party/03-May-2024-151130

tools/03-May-2024-1,162757

.clang-formatD03-May-202481 32

.gitignoreD03-May-2024426 2522

AUTHORSD03-May-2024294 86

Android.bpD03-May-20241.9 KiB7570

CMakeLists.txtD03-May-20247.5 KiB258224

CODE_OF_CONDUCT.mdD03-May-20244.4 KiB9473

CONTRIBUTING.mdD03-May-20241.1 KiB2920

CPPLINT.cfgD03-May-202427 32

DEPSD03-May-20242.8 KiB7053

DoxyfileD03-May-2024105.8 KiB2,4841,931

LICENSED03-May-202411.1 KiB203169

README.mdD03-May-20249.5 KiB306230

setup_debug_local.envD03-May-2024141 42

README.md

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