1# ANGLE Restricted Traces 2 3The files in this directory are traces of real applications. We host them 4internally because they may contain third party IP which we don't want 5to share publicly. 6 7## Accessing the traces 8 9In order to compile and run with these, you must be granted access by Google, 10then authenticate with [CIPD](CIPD). Googlers, use your @google account. 11``` 12cipd auth-login 13``` 14Add the following to ANGLE's .gclient file: 15``` 16 "custom_vars": { 17 "checkout_angle_restricted_traces": True 18 }, 19``` 20 21Note: alternatively, you can checkout only a few specific traces using the following format (`angle_restricted_traces` in gn args below should be a matching list or a subset): 22``` 23 "custom_vars": { 24 "checkout_angle_restricted_trace_{trace_name_1}": True, 25 "checkout_angle_restricted_trace_{trace_name_2}": True, 26 ... 27 }, 28``` 29 30Then use gclient to pull down binary files from CIPD. 31``` 32gclient sync -D 33``` 34This should result in a number of directories created in `src/tests/restricted_traces` that contain 35the trace files listed in [restricted_traces.json](restricted_traces.json): 36``` 37$ ls -d src/tests/restricted_traces/*/ 38src/tests/restricted_traces/aliexpress/ 39src/tests/restricted_traces/angry_birds_2_1500/ 40src/tests/restricted_traces/arena_of_valor/ 41src/tests/restricted_traces/asphalt_8/ 42src/tests/restricted_traces/brawl_stars/ 43src/tests/restricted_traces/bus_simulator_indonesia/ 44src/tests/restricted_traces/candy_crush_500/ 45src/tests/restricted_traces/clash_of_clans/ 46src/tests/restricted_traces/clash_royale/ 47src/tests/restricted_traces/cod_mobile/ 48... 49``` 50 51[CIPD]: https://chromium.googlesource.com/infra/luci/luci-go/+/main/cipd/README.md 52 53## Building the trace tests 54 55To build for Android, follow the steps in [DevSetupAndroid.md](../../../doc/DevSetupAndroid.md) 56(Recommend using the [`Performance`](../../../doc/DevSetupAndroid.md#performance-config) arguments 57for best performance) 58 59To build for Desktop, follow the steps in [DevSetup.md](../../../doc/DevSetup.md) 60 61When that is working, add the following GN arg to your setup: 62``` 63build_angle_trace_perf_tests = true 64``` 65### Selecting which traces to build 66 67Since the traces are numerous, you should limit compilation to a subset with the following GN arg: 68``` 69angle_restricted_traces = ["among_us 5", "street_fighter_duel 1"] 70``` 71If you choose not to pick any traces and build them all, you must follow different steps for Android. Skip ahead to [Building and running all traces for Android](#building-and-running-all-traces-for-android) 72 73To build the trace tests: 74``` 75autoninja -C out/<config> angle_trace_tests 76``` 77## Running the trace tests 78The trace tests can be run with default options like so: 79``` 80out/<config>/angle_trace_tests 81``` 82To select a specific trace to run, provide it with a filter: 83``` 84out/<config>/angle_trace_tests --gtest_filter=TraceTest.<trace_name> 85``` 86The specific options available with traces can be found in the PerfTests [`README`](../perf_tests/README.md#trace-tests) 87 88Common options used are: 89``` 90# Use ANGLE as the driver with the system's Vulkan driver as backend 91--use-angle=vulkan 92 93# Use the system's native GLES driver 94--use-gl=native 95``` 96 97### Building and running all traces for Android 98Our trace library has gotten large enough that they no longer fit in a single APK. To support building and running the entire library, we can compile the libraries by themselves, outside of the APK, and push them to locations accessible by the test harness. 99 100To do so, remove `angle_restricted_traces` from your GN args, then compile with: 101``` 102autoninja -C out/<config> angle_trace_perf_tests 103``` 104and run with (including recommended options): 105``` 106out/<config>/angle_trace_tests --filter='*among_us*' --verbose --fixed-test-time-with-warmup 10 107``` 108 109If more than one device is connected, the target device serial should be provided as well: 110``` 111ANDROID_SERIAL=<device_serial> out/<config>/angle_trace_tests ... 112``` 113 114# Capturing and adding new Android traces 115 116Generally we want to use a Debug setup for recording new traces. That allows us to see asserts and 117errors if the tracer needs to be improved. 118Add the following GN arg to your Debug setup: 119``` 120angle_with_capture_by_default = true 121``` 122 123After [building](../../../doc/DevSetupAndroid.md#building-angle-for-android) and 124[installing](../../../doc/DevSetupAndroid.md#install-the-angle-apk) the APK with the above arg, 125we're ready to start capturing. 126 127## Determine the target app 128 129We first need to identify which application we want to trace. That can generally be done by 130looking at the web-based Play Store entry for your app. For instance, Angry Birds 2 is listed 131here: https://play.google.com/store/apps/details?id=com.rovio.baba 132 133If there is no Play Store entry for your app, there are a couple of ways you can determine the 134app's name. 135 136If you have a userdebug build of Android, you can check logcat when you launch the application. 137You should see an entry like this: 138``` 139GraphicsEnvironment: ANGLE Developer option for 'com.rovio.baba' set to: 'default' 140``` 141If you just have an APK, you can use the following command to find the package name: 142``` 143$ aapt dump badging angry_birds_2.apk | grep package 144package: name='com.rovio.baba' versionCode='24900001' versionName='2.49.1' platformBuildVersionName='' 145``` 146You can also just guess at the package name, then check your device to see if it is installed. Keep 147trying combinations until you find it: 148``` 149$ adb shell pm list packages | grep rovio 150package:com.rovio.baba 151``` 152Track the package name for use in later steps: 153``` 154export PACKAGE_NAME=com.rovio.baba 155``` 156 157## Choose a trace name 158 159Next, we need to chose a name for the trace. Choose something simple that identifies the app, then use snake 160case. This will be the name of the trace files, including the trace directory. Changing this value later is possible, 161but not recommended. 162``` 163export LABEL=angry_birds_2 164``` 165 166## Opt the application into ANGLE 167 168Next, opt the application into using your ANGLE with capture enabled by default: 169``` 170adb shell settings put global angle_debug_package org.chromium.angle 171adb shell settings put global angle_gl_driver_selection_pkgs $PACKAGE_NAME 172adb shell settings put global angle_gl_driver_selection_values angle 173``` 174 175## Set up some Capture/Replay properties 176 177We also need to set some debug properties used by the tracer. 178 179Ensure frame capture is enabled. This might be redundant, but ensure the property isn't set to 180zero, which disables frame capture. 181``` 182adb shell setprop debug.angle.capture.enabled 1 183``` 184Empty the start and end frames. Again, this might be redundant, but it is less confusing. 185``` 186adb shell setprop debug.angle.capture.frame_start '""' 187adb shell setprop debug.angle.capture.frame_end '""' 188``` 189Set the label to be used in the trace files 190``` 191adb shell setprop debug.angle.capture.label $LABEL 192``` 193Set a trigger value to be used by the tracer. This should be set to the *number of frames* you want 194to capture. We typically use 10 to get an idea of how a scene is running, but some workloads 195require more. Use your discretion here: 196``` 197adb shell setprop debug.angle.capture.trigger 10 198``` 199 200## Create output location 201 202We need to write out the trace file in a location accessible by the app. We use the app's data 203storage on sdcard, but create a subfolder to isolate ANGLE's files: 204``` 205adb shell mkdir -p /sdcard/Android/data/$PACKAGE_NAME/angle_capture 206``` 207 208## Start the target app 209 210From here, you can start the application. You should see logcat entries like the following, 211indicating that we've succesfully turned on capturing: 212``` 213ANGLE : INFO: Capture trigger detected, disabling capture start/end frame. 214ANGLE : INFO: Limiting binary format support count to zero while FrameCapture enabled 215ANGLE : INFO: Limiting image unit count to 8 while FrameCapture enabled 216ANGLE : INFO: Setting uniform buffer offset alignment to 256 while FrameCapture enabled 217ANGLE : INFO: Disabling GL_EXT_map_buffer_range and GL_OES_mapbuffer during capture, which are not supported on some native drivers 218ANGLE : INFO: Disabling GL_CHROMIUM_bind_uniform_location during capture, which is not supported on native drivers 219ANGLE : INFO: Disabling GL_NV_shader_noperspective_interpolation during capture, which is not supported on some native drivers 220ANGLE : INFO: Limiting draw buffer count to 4 while FrameCapture enabled 221``` 222## Trigger the capture 223 224When you have reached the content in your application that you want to record, set the trigger 225value to zero: 226``` 227adb shell setprop debug.angle.capture.trigger 0 228``` 229In logcat we'll see another entry corresponding to this: 230``` 231ANGLE : INFO: Capture triggered after frame 30440 for 10 frames 232``` 233The app may pause briefly when the capture is completing. You can check its progress by looking at 234the file system: 235``` 236adb shell ls -la /sdcard/Android/data/$PACKAGE_NAME/angle_capture 237``` 238Allow the app to run until the logcat entry indicating the end of the API 239capture. The app should continue rendering after that: 240``` 241ANGLE : INFO: Finished recording graphics API capture 242``` 243 244## Pull the trace files 245 246Next, we want to pull those files over to the host and run some scripts. 247``` 248cd $CHROMIUM_SRC/third_party/angle/src/tests/restricted_traces 249mkdir -p $LABEL 250adb pull /sdcard/Android/data/$PACKAGE_NAME/angle_capture/. $LABEL/ 251``` 252 253## Add the new trace to the JSON list 254 255The list of traces is tracked in [restricted_traces.json](restricted_traces.json). Manually add your 256new trace to this list. Use version "1" for the trace version. 257 258On Linux, you can also use a tool called `jq` to update the list. This ensures we get them in 259alphabetical order with no duplicates. It can also be done by hand if you are unable to install it, 260for some reason. 261``` 262sudo apt-get install jq 263``` 264Then run the following command: 265``` 266export VERSION=1 267jq ".traces = (.traces + [\"$LABEL $VERSION\"] | unique)" restricted_traces.json | sponge restricted_traces.json 268``` 269 270## Run code auto-generation 271 272The [`gen_restricted_traces`](gen_restricted_traces.py) script auto-generates entries 273in our checkout dependencies to sync restricted trace data on checkout. To trigger 274code generation run the following from the angle root folder: 275``` 276python ./scripts/run_code_generation.py 277``` 278After this you should be able to `git diff` and see changes in the following files: 279 280 * `DEPS` 281 * `scripts/code_generation_hashes/restricted_traces.json` 282 * `src/tests/restricted_traces/restricted_traces.json` (this is the file you originally modified) 283 284Note the absence of the traces themselves listed above. They are automatically 285ignored by [`.gitignore`](.gitignore) since they won't be checked in directly 286to the repo. 287 288## Upload your trace to CIPD 289 290Once you feel good about your trace, you can upload it to our collection of traces. This can only 291be done by Googlers with write access to the trace CIPD prefix. If you need write access contact 292someone listed in the `OWNERS` file. 293 294Please kindly go over the trace content with ANGLE code owners before running 295below commands. You can share your trace through Google Drive for content 296iterations. We cannot delete trace files once they are up on the CIPD. 297Doing additional rounds of content check can help us save CIPD resources. 298 299``` 300src/tests/restricted_traces/sync_restricted_traces_to_cipd.py 301``` 302 303## Upload your CL 304 305Ensure your current working directory is up-to-date, and upload: 306 307``` 308git cl upload 309``` 310 311You're now ready to run your new trace on CI! 312 313# Comparing screenshots against the native driver 314 315To compare trace screenshots from ANGLE vs the native driver, you can 316use the `compare_trace_screenshots.py` script. 317 318The following steps will work on Android, but are transferrable to 319any operating system. 320 321First, make a spot for the results: 322``` 323adb shell rm -r /sdcard/angle/screenshots 324adb shell mkdir -p /sdcard/angle/screenshots 325``` 326 327Then run the traces using ANGLE: 328``` 329out/AndroidPerformance/angle_trace_tests --verbose --run-to-key-frame --screenshot-dir /sdcard/angle/screenshots --shard-timeout 1000000 330``` 331 332And again with the native driver: 333``` 334out/AndroidPerformance/angle_trace_tests --verbose --run-to-key-frame --screenshot-dir /sdcard/angle/screenshots --shard-timeout 1000000 --use-gl=native 335``` 336 337It may take a few tries as some drivers will crash. In that case, run the ones at the end that were stragglers, i.e.: 338``` 339out/AndroidPerformance/angle_trace_tests --verbose --run-to-key-frame --screenshot-dir /sdcard/angle/screenshots --shard-timeout 1000000 --use-gl=native --gtest_filter="*words*:*world*:*worms*:*zenonia*:*zillow*:*zombie*" 340``` 341 342Pull the screenshots: 343``` 344adb pull /sdcard/angle/screenshots 345cd screenshots 346``` 347 348And run the compare script: 349``` 350python3 ../src/tests/restricted_traces/compare_trace_screenshots.py versus_native --trace-list-path ../src/tests/restricted_traces/ 351``` 352 353The script will print out results comparing ANGLE vs. native screenshots at different fuzz factors. 354It may also print out NA for missing screenshots: 355``` 356... 357arknights angle_vulkan_arknights.png MISSING_EXT.png NA NA NA NA NA NA 358asphalt_8 angle_vulkan_asphalt_8.png angle_native_asphalt_8.png 641849 222157 116426 1701 82 22 359asphalt_9 angle_vulkan_asphalt_9.png angle_native_asphalt_9.png 17919 420 305 293 232 3 360... 361``` 362# Upgrading existing traces 363 364With tracer updates sometimes we want to re-run tracing to upgrade the trace file format or to 365take advantage of new tracer improvements. The [`retrace_restricted_traces`](retrace_restricted_traces.py) 366script allows us to re-run tracing using [SwiftShader](https://swiftshader.googlesource.com/SwiftShader) 367on a desktop machine. As of writing we require re-tracing on a Windows machine because of size 368limitations with a Linux app window. 369 370## Part 1: Retrace it 371 372Upgrade your trace into a new directory called `retrace-wip` 373 374In this instance, we'll upgrade `octopath_traveler` 375``` 376export TRACE_GN_PATH=out/Debug 377export TRACE_NAME=octopath_traveler 378src/tests/restricted_traces/retrace_restricted_traces.py upgrade $TRACE_GN_PATH retrace-wip -f $TRACE_NAME 379``` 380 381## Part 2: Verify it 382 383Before we check in an upgraded trace, we want to put it through enough paces to 384ensure behaves the same or better. 385 386### Screenshots 387 388For screenshots, we want to verify all frames render correctly before and after Reset. 389 390So make two spots to gather the screenshots, and one to gather results: 391``` 392mkdir retrace-wip/${TRACE_NAME}_before 393mkdir retrace-wip/${TRACE_NAME}_after 394mkdir retrace-wip/${TRACE_NAME}_compare 395``` 396 397We need two loops to verify Reset, so you'll need to inspect how many frames 398are in the trace. In this case, `octopath_traveler` has 500 frames, so we need 3991000 screenshots. We use -1 as the screenshot frame so we get all images: 400``` 401out/Debug/angle_trace_tests --gtest_filter=TraceTest.${TRACE_NAME} --use-angle=swiftshader --max-steps-performed 1000 --screenshot-dir retrace-wip/${TRACE_NAME}_before --screenshot-frame -1 402``` 403 404Then move the new trace in and run it again: 405``` 406mv src/tests/restricted_traces/${TRACE_NAME} retrace-wip/${TRACE_NAME}_orig 407cp -r retrace-wip/${TRACE_NAME} src/tests/restricted_traces 408autoninja -C out/Debug angle_trace_tests 409out/Debug/angle_trace_tests --gtest_filter=TraceTest.${TRACE_NAME} --use-angle=swiftshader --max-steps-performed 1000 --screenshot-dir retrace-wip/${TRACE_NAME}_after --screenshot-frame -1 410``` 411 412After that, we have a script that will compare the before and after screenshots, 413saving the results: 414``` 415src/tests/restricted_traces/compare_trace_screenshots.py versus_upgrade --before retrace-wip/${TRACE_NAME}_before --after retrace-wip/${TRACE_NAME}_after --outdir retrace-wip/${TRACE_NAME}_compare 416``` 417 418If you have any diffs, they will pop out like this, and you need to investigate: 419``` 420angle_vulkan_swiftshader_octopath_traveler_frame1.png 0 421angle_vulkan_swiftshader_octopath_traveler_frame10.png 0 422angle_vulkan_swiftshader_octopath_traveler_frame100.png 1.12185e+06 423Pixel diff detected! 424``` 425 426### Performance 427 428We need to ensure we're getting the same frame times and memory usage. 429 430The easiest way to do that is on Android, which can show us GPU and CPU memory. 431 432First, restore the original trace, then build and install the most optimized build: 433``` 434rm -r src/tests/restricted_traces/${TRACE_NAME} 435cp -r retrace-wip/${TRACE_NAME}_orig src/tests/restricted_traces/${TRACE_NAME} 436autoninja -C out/AndroidPerformance angle_trace_tests 437out/AndroidPerformance/angle_trace_tests --gtest_filter=TraceTest.${TRACE_NAME} --run-to-key-frame --no-warmup 438``` 439 440Then run the `restricted_trace_perf.py` script to gather frame times and memory: 441``` 442out/AndroidPerformance/restricted_trace_perf --fixedtime 10 --sleep 10 --power --output-tag ${TRACE_NAME}.before --loop-count 5 --renderer vulkan --filter ${TRACE_NAME} 443``` 444 445You should get output like this: 446``` 447trace wall_time gpu_time cpu_time gpu_power cpu_power gpu_mem_sustained gpu_mem_peak proc_mem_median proc_mem_peak 448 449Starting run 1 with vulkan at 2023-08-17 16:26:29 450 451vulkan_octopath_traveler 2.9650 0 3.8901000000 5183 5659 186837550 206241792 586976000 591528000 452 453Starting run 2 with vulkan at 2023-08-17 16:26:54 454 455vulkan_octopath_traveler 3.0038 0 3.9452525714 5295 5128 186467084 205910016 584568000 589196000 456 457Starting run 3 with vulkan at 2023-08-17 16:27:18 458 459vulkan_octopath_traveler 3.0061 0 3.9361028571 5203 5182 187197952 205262848 586596000 590324000 460 461Starting run 4 with vulkan at 2023-08-17 16:27:42 462 463vulkan_octopath_traveler 2.9901 0 3.9330551429 5461 5165 194881803 197480448 585268000 588384000 464 465Starting run 5 with vulkan at 2023-08-17 16:28:05 466 467vulkan_octopath_traveler 3.0749 0 3.9652568571 5197 5096 193443742 203177984 583636000 586380000 468``` 469 470Bring in the upgraded trace, build and install the trace again: 471``` 472rm -rf src/tests/restricted_traces/${TRACE_NAME} 473cp -r retrace-wip/${TRACE_NAME} src/tests/restricted_traces/${TRACE_NAME} 474autoninja -C out/AndroidPerformance angle_trace_tests 475out/AndroidPerformance/angle_trace_tests --gtest_filter=TraceTest.${TRACE_NAME} --run-to-key-frame --no-warmup 476``` 477 478And collect performance data: 479``` 480out/AndroidPerformance/restricted_trace_perf --fixedtime 10 --sleep 10 --power --output-tag ${TRACE_NAME}.after --loop-count 5 --renderer vulkan --filter ${TRACE_NAME} 481``` 482 483Verify using a spreadsheet that the values are relatively the same. 484If you notice a marked difference, spend some time understanding it. 485For instance, you may see memory decrease due to fixed in the upgrade. 486 487## Part 3: Test the upgraded traces under an experimental prefix 488 489To test the trace on all platforms, we first upload them to a temporary CIPD 490path for testing. After a successful run on the CQ, we will then upload them 491to the main ANGLE prefix. 492 493To enable the experimental prefix, edit 494[`restricted_traces.json`](restricted_traces.json) to use a version 495number beginning with 'x'. For example: 496 497``` 498 "traces": [ 499 ... 500 "octopath_traveler x1", 501 ... 502``` 503 504Then run: 505 506``` 507src/tests/restricted_traces/sync_restricted_traces_to_cipd.py --filter ${TRACE_NAME} 508scripts/run_code_generation.py 509``` 510 511After these commands complete succesfully, create and upload a CL as normal. 512 513Before running tests, you need to grant the bots access to your experimental 514CIPD files (substituting your account name): 515``` 516cipd acl-edit experimental/google.com/$USERNAME -reader user:[email protected] 517cipd acl-edit experimental/google.com/$USERNAME -reader user:chromium-try-gpu-builder@chops-service-accounts.iam.gserviceaccount.com 518``` 519 520You can verify it worked by running this command and seeing the bot added to readers: 521``` 522cipd acl-list experimental/google.com/$USERNAME/angle/traces 523... 524Readers: 525 via "experimental/google.com/$USERNAME": 526 user:[email protected] 527 user:chromium-try-gpu-builder@chops-service-accounts.iam.gserviceaccount.com 528``` 529 530Run CQ +1 Dry-Run. If you find a test regression, see the section below on 531diagnosing tracer errors. Otherwise proceed with the steps below. 532 533## Part 5: Upload the verified traces to CIPD under the stable prefix 534 535Now that you've validated the traces on the CQ, update 536[`restricted_traces.json`](restricted_traces.json) to remove the 'x' prefix 537and incrementing the version of the traces (skipping versions if you prefer) 538and then run: 539 540``` 541src/tests/restricted_traces/sync_restricted_traces_to_cipd.py --filter ${TRACE_NAME} 542scripts/run_code_generation.py 543``` 544 545Then create and upload a CL as normal. Congratulations, you've finished the 546trace upgrade! 547 548## Finding a trace's minimum requirements 549 550`retrace_restricted_traces.py` can be used to determine a trace's minimum 551extensions and GLES version. Run the command: 552 553``` 554src/tests/restricted_traces/retrace_restricted_traces.py get_min_reqs $TRACE_GN_PATH [--traces "*"] 555``` 556 557The script will run each listed trace multiple times so it can find the minimum 558required GLES version and each required extension. Finally it records that 559information to the trace's json file. 560 561By default it will run with SwiftShader. To make the script use your machine's 562native vulkan drivers, use the `--no-swiftshader` argument before the script's 563command: 564 565``` 566src/tests/restricted_traces/retrace_restricted_traces.py --no-swiftshader get_min_reqs $TRACE_GN_PATH [--traces "*"] 567``` 568 569If retracing an existing trace, any associated `addExtensionPrerequisite()` calls must be removed from `TracePerfTest.cpp` and 570the tracename.json file must be made writable. 571 572Traces are run with all extensions enabled by default. It may be useful to test with only a subset of extensions. 573This can be done by adding the `--request-extensions` argument to `angle_trace_tests`. Multiple extensions must be contained by quotation 574marks and only a single space can be used as a separator. To run with no extensions enabled, specify a null list -- `""`: 575 576``` 577./out/Debug/angle_trace_tests --gtest_filter=*tracename --request-extensions "EXT_color_buffer_float GL_EXT_texture_filter_anisotropic" 578``` 579 or 580``` 581./out/Debug/angle_trace_tests --gtest_filter=*tracename --request-extensions "" 582``` 583 584## Extended testing and full trace upgrades 585 586If you want to really drill down on trace differences, you might want to use the 587built in validation support, which serailizes the internal state of ANGLE. 588 589## Prep work: Back up existing traces 590 591This will save the original traces in a temporary folder if you need to revert to the prior trace format: 592 593``` 594src/tests/restricted_traces/retrace_restricted_traces.py backup "*" 595``` 596 597*Note: on Linux, remove the command `py` prefix to the Python scripts.* 598 599This will save the traces to `./retrace-backups`. At any time you can revert the trace files by running: 600 601``` 602src/tests/restricted_traces/retrace_restricted_traces.py restore "*" 603``` 604 605## Part 1: Upgrading Sanity Check with T-Rex 606 607First we'll retrace a single app to verify the workflow is intact. Please 608ensure you replace the specified variables with paths that work on your 609configuration and checkout: 610 611### Step 1/3: Capture T-Rex with Validation 612 613``` 614export TRACE_GN_PATH=out/Debug 615export TRACE_NAME=trex_200 616src/tests/restricted_traces/retrace_restricted_traces.py upgrade $TRACE_GN_PATH retrace-wip -f $TRACE_NAME --validation --limit 3 617``` 618 619The `--validation` flag will turn on additional validation checks in the 620trace. The `--limit 3` flag forces a maximum of 3 frames of tracing so the 621test will run more quickly. The trace will end up in the `retrace-wip` 622folder. 623 624### Step 2/3: Validate T-Rex 625 626The command below will update your copy of the trace, rebuild, the run the 627test suite with validation enabled: 628 629``` 630src/tests/restricted_traces/retrace_restricted_traces.py validate $TRACE_GN_PATH retrace-wip $TRACE_NAME 631``` 632 633If the trace failed validation, see the section below on diagnosing tracer 634errors. Otherwise proceed with the steps below. 635 636### Step 3/3: Restore the Canonical T-Rex Trace 637 638``` 639src/tests/restricted_traces/retrace_restricted_traces.py restore $TRACE_NAME 640``` 641 642## Part 2: Do a limited trace upgrade with validation enabled 643 644### Step 1/3: Upgrade all traces with a limit of 3 frames 645 646``` 647src/tests/restricted_traces/retrace_restricted_traces.py upgrade $TRACE_GN_PATH retrace-wip --validation --limit 3 --no-overwrite 648``` 649 650If this process gets interrupted, re-run the upgrade command. The 651`--no-overwrite` argument will ensure it will complete eventually. 652 653If any traces failed to upgrade, see the section below on diagnosing tracer 654errors. Otherwise proceed with the steps below. 655 656### Step 2/3: Validate all upgraded traces 657 658``` 659src/tests/restricted_traces/retrace_restricted_traces.py validate $TRACE_GN_PATH retrace-wip "*" 660``` 661 662If any traces failed validation, see the section below on diagnosing tracer 663errors. 664 665### Step 3/3: Restore all traces 666 667``` 668src/tests/restricted_traces/retrace_restricted_traces.py restore "*" 669``` 670 671## Part 3: Do the full trace upgrade 672 673``` 674rm -rf retrace-wip 675src/tests/restricted_traces/retrace_restricted_traces.py upgrade $TRACE_GN_PATH retrace-wip --no-overwrite 676``` 677 678If this process gets interrupted, re-run the upgrade command. The 679`--no-overwrite` argument will ensure it will complete eventually. 680 681If any traces failed to upgrade, see the section below on diagnosing tracer 682errors. 683 684Otherwise, use the steps above to [verify and upgrade your traces](#part-3-test-the-upgraded-traces-under-an-experimental-prefix). 685 686 687# Diagnosing and fixing tracer errors 688 689## Debugging a crash or GLES error 690 691Ensure you're building ANGLE in Debug. Then look in the retrace script output 692to find the exact command line and environment variables the script uses to 693produce the failure. For example: 694 695``` 696INFO:root:ANGLE_CAPTURE_LABEL=trex_200 ANGLE_CAPTURE_OUT_DIR=C:\src\angle\retrace-wip\trex_200 ANGLE_CAPTURE_FRAME_START=2 ANGLE_CAPTURE_FRAME_END=4 ANGLE_CAPTURE_VALIDATION=1 ANGLE_FEATURE_OVERRIDES_ENABLED=allocateNonZeroMemory:forceInitShaderVariables out\Debug\angle_trace_tests.exe --gtest_filter=TraceTest.trex_200 --use-angle=swiftshader --max-steps-performed 3 --retrace-mode 697``` 698 699Once you can reproduce the issue you can use a debugger or other standard 700debugging processes to find the root cause and a fix. 701 702## Debugging a serialization difference 703 704If you encouter a serialization mismatch in the retrace, you can find the 705complete serialization output by looking in the retrace script output. ANGLE 706saves the complete serialization file contents on any mismatch. You can 707inspect and diff these files in a text editor to help diagnose what objects 708are faulty. 709 710If the mismatch is with a Buffer or Texture object content, you can manually 711edit the `frame_capture_utils.cpp` file to force some or all of the objects 712to serialize their entire contents. This can help show what kind of pixel or 713data differences might be causing the issue. For example, change this line: 714 715``` 716json->addBlob("data", dataPtr->data(), dataPtr->size()); 717``` 718 719to 720 721``` 722json->addBlobWithMax("data", dataPtr->data(), dataPtr->size(), 1000000); 723``` 724 725Note: in the future, we might make this option exposed via an envioronment 726variable, or even allow serialization of entire data blocks in text-encoded 727form that could be decoded to separate files. 728 729If you still can't determine what code might be causing the state difference, 730we can insert finer-grained serialization checkpoints to "bisect" where the 731coding mismatch is happening. It is not possible to force checkpoints after 732every GLES call, because serialization and validation is so prohibitively 733expensive. ANGLE instead has feature in the tracer that allows us to 734precisely control where the tracer inserts and validates the checkpoints, by 735using a boolean expression language. 736 737The retrace script command `--validation-expr` allows us to specify a C-like 738expression that determines when to add serialization checkpoints. For 739example, we can specify this validation expression: 740 741``` 742((frame == 2) && (call < 1189) && (call > 1100) && ((call % 5) == 0)) 743``` 744 745Using this expression will insert a serialization checkpoint in the second 746frame, on every 5th captured call, and when the captured call count is 747between 1101 and 1188. Here the `call` keyword denotes the call counter, 748which resets to 1 every frame, and increments by 1 with every captured GLES 749API call. The `frame` keyword denotes the frame counter, which starts at 1 750and increments by 1 every captured frame. The expression syntax supports all 751common C boolean operators. 752 753By finding a starting and ending frame range, and narrowing this range through 754experimentation, you can pinpoint the exact call that triggers the 755serialization mismatch, and then diagnose and fix the root cause. In some 756cases you can use RenderDoc or other frame debugging tools to inspect 757resource states before/after the bad call once you have found it. 758 759See also: [`http://crrev.com/c/3136094`](http://crrev.com/c/3136094) 760 761## Debugging a pixel test failure without a serialization mismatch 762 763Sometimes you manage to complete validation and upload, just to find a golden 764image pixel difference that manifests in some trace configurations. These 765problems can be harder to root cause. For instance, some configurations may 766render undefined pixels that are in practice well-defined on most GLES 767implementations. 768 769The pixel differences can also be a product of mismatched state even if the 770trace validation says all states are matched. Because ANGLE's GLES state 771serialization is incomplete, it can help to check the state serialization 772logic and add missing features as necessary. 773