Hash :
98e351cf
Author :
Date :
2023-08-16T15:22:37
Traces: Update steps for upgrading traces
We've settled on a streamlined method of upgrading traces.
We consider the upgraded trace good if:
- gets the same pixels for all frames, including after Reset
- gets the same frame time and memory usage (or better)
This moves away from using serialization, which is useful, but has
become too heavyweight. We've preserved the steps as they are
still useful in some scenarios.
Also formalize a couple of scripts we've been using to compare
trace screenshots.
It supports two scenarios:
- comparing screenshots between ANGLE and native
- verifying screenshots after an upgrade
Example usages:
compare_trace_screenshots.py versus_upgrade \
--before <path> --after <path> --outdir <path>
compare_trace_screenshots.py versus_native \
--screenshot-dir /tmp/screenshots
--trace-list-path src/tests/restricted_traces
Bug: b/294882956
Change-Id: Ifc59d8b31648abb3614da2d8919a1f90a0b6b68f
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4791916
Auto-Submit: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Roman Lavrov <romanl@google.com>
Reviewed-by: Roman Lavrov <romanl@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
#! /usr/bin/env python3
#
# Copyright 2023 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
'''
compare_trace_screenshots.py
This script will cycle through screenshots from traces and compare them in useful ways.
It can run in multiple ways.
* `versus_native`
This mode expects to be run in a directory full of two sets of screenshots
angle_trace_tests --run-to-key-frame --screenshot-dir /tmp/screenshots
angle_trace_tests --run-to-key-frame --screenshot-dir /tmp/screenshots --use-gl=native
python3 compare_trace_screenshots.py versus_native --screenshot-dir /tmp/screenshots --trace-list-path ~/angle/src/tests/restricted_traces/
* `versus_upgrade`
This mode expects to be pointed to two directories of identical images (same names and pixel contents)
python3 compare_trace_screenshots.py versus_upgrade --before /my/trace/before --after /my/trace/after --out /my/trace/compare
Prerequisites
sudo apt-get install imagemagick
'''
import argparse
import json
import logging
import os
import subprocess
import sys
DEFAULT_LOG_LEVEL = 'info'
EXIT_SUCCESS = 0
EXIT_FAILURE = 1
def versus_native(args):
# Get a list of all PNG files in the directory
png_files = os.listdir(args.screenshot_dir)
# Build a set of unique trace names
traces = set()
def get_traces_from_images():
# Iterate through the PNG files
for png_file in sorted(png_files):
if png_file.startswith("angle_native") or png_file.startswith("angle_vulkan"):
# Strip the prefix and the PNG extension from the file name
trace_name = png_file.replace("angle_vulkan_",
"").replace("swiftshader_",
"").replace("angle_native_",
"").replace(".png", "")
traces.add(trace_name)
def get_traces_from_file(restricted_traces_path):
with open(os.path.join(restricted_traces_path, "restricted_traces.json")) as f:
trace_data = json.load(f)
# Have to split the 'trace version' thing up
trace_and_version = trace_data['traces']
for i in trace_and_version:
traces.add(i.split(' ',)[0])
def get_trace_key_frame(restricted_traces_path, trace):
with open(os.path.join(restricted_traces_path, trace, trace + ".json")) as f:
single_trace_data = json.load(f)
metadata = single_trace_data['TraceMetadata']
keyframe = ""
if 'KeyFrames' in metadata:
keyframe = metadata['KeyFrames'][0]
return keyframe
if args.trace_list_path != None:
get_traces_from_file(args.trace_list_path)
else:
get_traces_from_images()
for trace in sorted(traces):
if args.trace_list_path != None:
keyframe = get_trace_key_frame(args.trace_list_path, trace)
frame = ""
if keyframe != "":
frame = "_frame" + str(keyframe)
native_file = "angle_native_" + trace + frame + ".png"
native_file = os.path.join(args.screenshot_dir, native_file)
if not os.path.isfile(native_file):
native_file = "MISSING_EXT.png"
vulkan_file = "angle_vulkan_" + trace + frame + ".png"
vulkan_file = os.path.join(args.screenshot_dir, vulkan_file)
if not os.path.isfile(vulkan_file):
vulkan_file = "angle_vulkan_swiftshader_" + trace + frame + ".png"
vulkan_file = os.path.join(args.screenshot_dir, vulkan_file)
if not os.path.isfile(vulkan_file):
vulkan_file = "MISSING_EXT.png"
# Compare each of the images with different fuzz factors so we can see how each is doing
# `compare -metric AE -fuzz ${FUZZ} ${VULKAN} ${NATIVE} ${TRACE}_fuzz${FUZZ}_diff.png`
results = []
for fuzz in {0, 1, 2, 5, 10, 20}:
diff_file = trace + "_fuzz" + str(fuzz) + "%_TEST_diff.png"
diff_file = os.path.join(args.screenshot_dir, diff_file)
command = "compare -metric AE -fuzz " + str(
fuzz) + "% " + vulkan_file + " " + native_file + " " + diff_file
logging.debug("Running " + command)
diff = subprocess.run(command, shell=True, capture_output=True)
for line in diff.stderr.splitlines():
if "unable to open image".encode('UTF-8') in line:
results.append("NA".encode('UTF-8'))
else:
results.append(diff.stderr)
logging.debug(" for " + trace + " " + str(fuzz) + "%")
print(trace, os.path.basename(vulkan_file), os.path.basename(native_file),
results[0].decode('UTF-8'), results[1].decode('UTF-8'), results[2].decode('UTF-8'),
results[3].decode('UTF-8'), results[4].decode('UTF-8'), results[5].decode('UTF-8'))
def versus_upgrade(args):
# Get a list of all the files in before
before_files = sorted(os.listdir(args.before))
# Get a list of all the files in after
after_files = sorted(os.listdir(args.after))
# If either list is missing files, this is a fail!
if before_files != after_files:
before_minus_after = list(sorted(set(before_files) - set(after_files)))
after_minus_before = list(sorted(set(after_files) - set(before_files)))
print("File lists don't match!")
if before_minus_after is not []:
print("Extra before files: %s" % before_minus_after)
if after_minus_before is not []:
print("Extra after files: %s" % after_minus_before)
exit(1)
# Walk through the before list and compare it with after
for before_image, after_image in zip(sorted(before_files), sorted(after_files)):
# Compare each of the images using root mean squared, no fuzz factor
# `compare -metric RMSE ${BEFORE} ${AFTER} ${TRACE}_RMSE_diff.png;`
results = []
diff_file = args.outdir + "/" + before_image + "_TEST_diff.png"
command = "compare -metric RMSE " + os.path.join(
args.before, before_image) + " " + os.path.join(args.after,
after_image) + " " + diff_file
diff = subprocess.run(command, shell=True, capture_output=True)
for line in diff.stderr.splitlines():
if "unable to open image".encode('UTF-8') in line:
results.append("NA".encode('UTF-8'))
else:
# If the last element of the diff isn't zero, there was a pixel diff
if line.split()[-1] != b'(0)':
print(before_image, diff.stderr.decode('UTF-8'))
print("Pixel diff detected!")
exit(1)
else:
results.append(diff.stderr)
print(before_image, results[0].decode('UTF-8'))
print("Test completed successfully, no diffs detected")
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--log', help='Logging level.', default=DEFAULT_LOG_LEVEL)
# Create commands for different modes of using this script
subparsers = parser.add_subparsers(dest='command', required=True, help='Command to run.')
# This mode will compare images of two runs, vulkan vs. native, and give you fuzzy comparison results
versus_native_parser = subparsers.add_parser(
'versus_native', help='Compares vulkan vs. native images.')
versus_native_parser.add_argument(
'--screenshot-dir', help='Directory containing two sets of screenshots', required=True)
versus_native_parser.add_argument(
'--trace-list-path', help='Path to dir containing restricted_traces.json')
# This mode will compare before and after images when upgrading a trace
versus_upgrade_parser = subparsers.add_parser(
'versus_upgrade', help='Compare images before and after an upgrade')
versus_upgrade_parser.add_argument(
'--before', help='Full path to dir containing *before* screenshots', required=True)
versus_upgrade_parser.add_argument(
'--after', help='Full path to dir containing *after* screenshots', required=True)
versus_upgrade_parser.add_argument('--outdir', help='Where to write output files', default='.')
args = parser.parse_args()
try:
if args.command == 'versus_native':
return versus_native(args)
elif args.command == 'versus_upgrade':
return versus_upgrade(args)
else:
logging.fatal('Unknown command: %s' % args.command)
return EXIT_FAILURE
except subprocess.CalledProcessError as e:
logging.exception('There was an exception: %s', e.output.decode())
return EXIT_FAILURE
if __name__ == '__main__':
sys.exit(main())