|
| 1 | +import argparse |
| 2 | +import sys |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import multiprocessing |
| 6 | +from functools import partial |
| 7 | +import platform |
| 8 | +import time |
| 9 | + |
| 10 | +def get_gs_name(path): |
| 11 | + lpath = path.lower() |
| 12 | + |
| 13 | + for extension in [".gs", ".gs.xz", ".gs.zst"]: |
| 14 | + if lpath.endswith(extension): |
| 15 | + return os.path.basename(path)[:-len(extension)] |
| 16 | + |
| 17 | + return None |
| 18 | + |
| 19 | + |
| 20 | +def run_regression_test(runner, dumpdir, renderer, upscale, renderhacks, gspath, gsfastreopen, startfrom, nbatches, batch_id): |
| 21 | + args = [runner] |
| 22 | + |
| 23 | + args.extend(["-batch"]) |
| 24 | + |
| 25 | + args.extend(["-nbatches", str(nbatches)]) |
| 26 | + |
| 27 | + args.extend(["-batch-id", str(batch_id)]) |
| 28 | + |
| 29 | + if renderer is not None: |
| 30 | + args.extend(["-renderer", renderer]) |
| 31 | + |
| 32 | + if upscale != 1.0: |
| 33 | + args.extend(["-upscale", str(upscale)]) |
| 34 | + |
| 35 | + if renderhacks is not None: |
| 36 | + args.extend(["-renderhacks", renderhacks]) |
| 37 | + |
| 38 | + args.extend(["-dumpdir", dumpdir]) |
| 39 | + args.extend(["-logfile", dumpdir]) |
| 40 | + |
| 41 | + if gsfastreopen: |
| 42 | + args.extend(["-batch-gs-fast-reopen"]) |
| 43 | + |
| 44 | + # loop a couple of times for those stubborn merge/interlace dumps that don't render anything |
| 45 | + # the first time around |
| 46 | + args.extend(["-loop", "2"]) |
| 47 | + |
| 48 | + # disable shader cache for parallel runs, otherwise it'll have sharing violations |
| 49 | + if nbatches > 1: |
| 50 | + args.append("-noshadercache") |
| 51 | + |
| 52 | + # run surfaceless, we don't want tons of windows popping up |
| 53 | + args.append("-surfaceless") |
| 54 | + |
| 55 | + if startfrom is not None: |
| 56 | + args.extend(["-batch-start-from", startfrom]) |
| 57 | + |
| 58 | + # disable output console entirely |
| 59 | + environ = os.environ.copy() |
| 60 | + environ["PCSX2_NOCONSOLE"] = "1" |
| 61 | + |
| 62 | + creationflags = 0 |
| 63 | + # Set low priority by default |
| 64 | + if platform.system() == "Windows": |
| 65 | + creationflags = 0x00004000 # BELOW_NORMAL_PRIORITY_CLASS |
| 66 | + elif platform.system() in ["Linux", "Darwin"]: |
| 67 | + try: |
| 68 | + os.nice(10) # lower priority |
| 69 | + except OSError: |
| 70 | + pass |
| 71 | + |
| 72 | + args.append("--") |
| 73 | + args.append(gspath) |
| 74 | + |
| 75 | + #print("Running '%s'" % (" ".join(args))) |
| 76 | + subprocess.run(args, env=environ, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, creationflags=creationflags) |
| 77 | + |
| 78 | + |
| 79 | +def run_regression_tests(runner, gsdir, dumpdir, renderer, upscale, renderhacks, gsfastreopen, startfrom, parallel): |
| 80 | + try: |
| 81 | + os.makedirs(dumpdir) |
| 82 | + except FileExistsError: |
| 83 | + pass |
| 84 | + |
| 85 | + if parallel <= 1: |
| 86 | + run_regression_test(runner, dumpdir, renderer, upscale, renderhacks, gsdir, gsfastreopen, startfrom, 1, 0) |
| 87 | + else: |
| 88 | + print("Processing on %u processors" % (parallel)) |
| 89 | + func = partial(run_regression_test, runner, dumpdir, renderer, upscale, renderhacks, gsdir, gsfastreopen, startfrom, parallel) |
| 90 | + pool = multiprocessing.Pool(parallel) |
| 91 | + for i, _ in enumerate(pool.imap_unordered(func, range(parallel), chunksize=1)): |
| 92 | + print("Process %u finished" % (i)) |
| 93 | + pool.close() |
| 94 | + |
| 95 | + return True |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == "__main__": |
| 99 | + parser = argparse.ArgumentParser(description="Generate frame dump images for regression tests") |
| 100 | + parser.add_argument("-runner", action="store", required=True, help="Path to PCSX2 GS runner") |
| 101 | + parser.add_argument("-gsdir", action="store", required=True, help="Directory containing GS dumps") |
| 102 | + parser.add_argument("-dumpdir", action="store", required=True, help="Base directory to dump frames to") |
| 103 | + parser.add_argument("-renderer", action="store", required=False, help="Renderer to use") |
| 104 | + parser.add_argument("-upscale", action="store", type=float, default=1, help="Upscaling multiplier to use") |
| 105 | + parser.add_argument("-renderhacks", action="store", required=False, help="Enable HW Rendering hacks") |
| 106 | + parser.add_argument("-parallel", action="store", type=int, default=1, help="Number of processes to run") |
| 107 | + parser.add_argument("-gsfastreopen", action="store_true", required=False, help="Enable GS fast reopen") |
| 108 | + parser.add_argument("-startfrom", action="store", required=False, help="Dump name/prefix to start from") |
| 109 | + |
| 110 | + args = parser.parse_args() |
| 111 | + |
| 112 | + start = time.time() |
| 113 | + res = run_regression_tests( |
| 114 | + runner = args.runner, |
| 115 | + gsdir = os.path.realpath(args.gsdir), |
| 116 | + dumpdir = os.path.realpath(args.dumpdir), |
| 117 | + renderer = args.renderer, |
| 118 | + upscale = args.upscale, |
| 119 | + renderhacks = args.renderhacks, |
| 120 | + startfrom = args.startfrom, |
| 121 | + parallel = args.parallel, |
| 122 | + gsfastreopen = args.gsfastreopen, |
| 123 | + ) |
| 124 | + end = time.time() |
| 125 | + print("Regression test %.2f seconds" % (end - start)) |
| 126 | + if not res: |
| 127 | + sys.exit(1) |
| 128 | + else: |
| 129 | + sys.exit(0) |
0 commit comments