2022-06-19 05:43:55 +00:00
|
|
|
import argparse
|
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import multiprocessing
|
|
|
|
from pathlib import Path
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
def is_gs_path(path):
|
|
|
|
ppath = Path(path)
|
|
|
|
for extension in [[".gs"], [".gs", ".xz"], [".gs", ".zst"]]:
|
|
|
|
if ppath.suffixes == extension:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-02-07 22:18:43 +00:00
|
|
|
def run_regression_test(runner, dumpdir, renderer, parallel, renderhacks, gspath):
|
2022-06-19 05:43:55 +00:00
|
|
|
args = [runner]
|
|
|
|
gsname = Path(gspath).name
|
|
|
|
while gsname.rfind('.') >= 0:
|
|
|
|
gsname = gsname[:gsname.rfind('.')]
|
|
|
|
|
2022-10-22 11:34:03 +00:00
|
|
|
real_dumpdir = os.path.join(dumpdir, gsname).strip()
|
2022-06-19 05:43:55 +00:00
|
|
|
if not os.path.exists(real_dumpdir):
|
|
|
|
os.mkdir(real_dumpdir)
|
|
|
|
|
|
|
|
if renderer is not None:
|
|
|
|
args.extend(["-renderer", renderer])
|
2023-02-07 22:18:43 +00:00
|
|
|
|
|
|
|
if renderhacks is not None:
|
|
|
|
args.extend(["-renderhacks", renderhacks])
|
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
args.extend(["-dumpdir", real_dumpdir])
|
2022-10-22 11:34:03 +00:00
|
|
|
args.extend(["-logfile", os.path.join(real_dumpdir, "emulog.txt")])
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
# loop a couple of times for those stubborn merge/interlace dumps that don't render anything
|
|
|
|
# the first time around
|
|
|
|
args.extend(["-loop", "2"])
|
|
|
|
|
2022-10-22 11:34:03 +00:00
|
|
|
# disable shader cache for parallel runs, otherwise it'll have sharing violations
|
|
|
|
if parallel > 1:
|
|
|
|
args.append("-noshadercache")
|
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
args.append("--")
|
|
|
|
args.append(gspath)
|
|
|
|
|
|
|
|
print("Running '%s'" % (" ".join(args)))
|
|
|
|
subprocess.run(args)
|
|
|
|
|
|
|
|
|
2023-02-07 22:18:43 +00:00
|
|
|
def run_regression_tests(runner, gsdir, dumpdir, renderer, renderhacks, parallel=1):
|
2022-06-19 05:43:55 +00:00
|
|
|
paths = glob.glob(gsdir + "/*.*", recursive=True)
|
|
|
|
gamepaths = list(filter(is_gs_path, paths))
|
|
|
|
|
|
|
|
if not os.path.isdir(dumpdir):
|
|
|
|
os.mkdir(dumpdir)
|
|
|
|
|
|
|
|
print("Found %u GS dumps" % len(gamepaths))
|
|
|
|
|
|
|
|
if parallel <= 1:
|
|
|
|
for game in gamepaths:
|
2023-02-07 22:18:43 +00:00
|
|
|
run_regression_test(runner, dumpdir, renderer, parallel, renderhacks, game)
|
2022-06-19 05:43:55 +00:00
|
|
|
else:
|
|
|
|
print("Processing %u games on %u processors" % (len(gamepaths), parallel))
|
2023-02-07 22:18:43 +00:00
|
|
|
func = partial(run_regression_test, runner, dumpdir, renderer, parallel, renderhacks)
|
2022-06-19 05:43:55 +00:00
|
|
|
pool = multiprocessing.Pool(parallel)
|
|
|
|
pool.map(func, gamepaths)
|
|
|
|
pool.close()
|
|
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description="Generate frame dump images for regression tests")
|
|
|
|
parser.add_argument("-runner", action="store", required=True, help="Path to PCSX2 GS runner")
|
|
|
|
parser.add_argument("-gsdir", action="store", required=True, help="Directory containing GS dumps")
|
|
|
|
parser.add_argument("-dumpdir", action="store", required=True, help="Base directory to dump frames to")
|
|
|
|
parser.add_argument("-renderer", action="store", required=False, help="Renderer to use")
|
|
|
|
parser.add_argument("-parallel", action="store", type=int, default=1, help="Number of proceeses to run")
|
2023-02-07 22:18:43 +00:00
|
|
|
parser.add_argument("-renderhacks", action="store", required=False, help="Enable HW Renering hacks")
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-02-07 22:18:43 +00:00
|
|
|
if not run_regression_tests(args.runner, os.path.realpath(args.gsdir), os.path.realpath(args.dumpdir), args.renderer, args.renderhacks, args.parallel):
|
2022-06-19 05:43:55 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|
|
|
|
|