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
|
|
|
|
|
2023-04-08 12:34:55 +00:00
|
|
|
def get_gs_name(path):
|
|
|
|
lpath = path.lower()
|
2022-06-19 05:43:55 +00:00
|
|
|
|
2023-04-08 12:34:55 +00:00
|
|
|
for extension in [".gs", ".gs.xz", ".gs.zst"]:
|
|
|
|
if lpath.endswith(extension):
|
|
|
|
return os.path.basename(path)[:-len(extension)]
|
|
|
|
|
|
|
|
return None
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
|
2023-03-05 06:04:29 +00:00
|
|
|
def run_regression_test(runner, dumpdir, renderer, upscale, renderhacks, parallel, gspath):
|
2022-06-19 05:43:55 +00:00
|
|
|
args = [runner]
|
2023-04-08 12:34:55 +00:00
|
|
|
gsname = get_gs_name(gspath)
|
2022-06-19 05:43:55 +00:00
|
|
|
|
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)
|
2023-07-20 08:37:36 +00:00
|
|
|
else:
|
|
|
|
return
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
if renderer is not None:
|
|
|
|
args.extend(["-renderer", renderer])
|
2023-03-05 06:04:29 +00:00
|
|
|
|
|
|
|
if upscale != 1.0:
|
|
|
|
args.extend(["-upscale", str(upscale)])
|
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")
|
|
|
|
|
2023-03-10 11:26:25 +00:00
|
|
|
# run surfaceless, we don't want tons of windows popping up
|
|
|
|
args.append("-surfaceless");
|
|
|
|
|
2023-03-07 15:15:04 +00:00
|
|
|
# disable output console entirely
|
|
|
|
environ = os.environ.copy()
|
|
|
|
environ["PCSX2_NOCONSOLE"] = "1"
|
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
args.append("--")
|
|
|
|
args.append(gspath)
|
|
|
|
|
2023-03-07 15:15:04 +00:00
|
|
|
#print("Running '%s'" % (" ".join(args)))
|
|
|
|
subprocess.run(args, env=environ, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
|
2023-03-05 06:04:29 +00:00
|
|
|
def run_regression_tests(runner, gsdir, dumpdir, renderer, upscale, renderhacks, parallel=1):
|
2022-06-19 05:43:55 +00:00
|
|
|
paths = glob.glob(gsdir + "/*.*", recursive=True)
|
2023-04-08 12:34:55 +00:00
|
|
|
gamepaths = list(filter(lambda x: get_gs_name(x) is not None, paths))
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
if not os.path.isdir(dumpdir):
|
|
|
|
os.mkdir(dumpdir)
|
|
|
|
|
|
|
|
print("Found %u GS dumps" % len(gamepaths))
|
|
|
|
|
|
|
|
if parallel <= 1:
|
|
|
|
for game in gamepaths:
|
2023-03-05 06:04:29 +00:00
|
|
|
run_regression_test(runner, dumpdir, renderer, upscale, renderhacks, parallel, game)
|
2022-06-19 05:43:55 +00:00
|
|
|
else:
|
|
|
|
print("Processing %u games on %u processors" % (len(gamepaths), parallel))
|
2023-03-05 06:04:29 +00:00
|
|
|
func = partial(run_regression_test, runner, dumpdir, renderer, upscale, renderhacks, parallel)
|
2022-06-19 05:43:55 +00:00
|
|
|
pool = multiprocessing.Pool(parallel)
|
2023-03-07 15:15:04 +00:00
|
|
|
completed = 0
|
|
|
|
for _ in pool.imap_unordered(func, gamepaths, chunksize=1):
|
|
|
|
completed += 1
|
|
|
|
print("Processed %u of %u GS dumps (%u%%)" % (completed, len(gamepaths), (completed * 100) // len(gamepaths)))
|
2022-06-19 05:43:55 +00:00
|
|
|
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")
|
2023-03-05 06:04:29 +00:00
|
|
|
parser.add_argument("-upscale", action="store", type=float, default=1, help="Upscaling multiplier to use")
|
|
|
|
parser.add_argument("-renderhacks", action="store", required=False, help="Enable HW Rendering hacks")
|
2022-06-19 05:43:55 +00:00
|
|
|
parser.add_argument("-parallel", action="store", type=int, default=1, help="Number of proceeses to run")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-03-05 06:04:29 +00:00
|
|
|
if not run_regression_tests(args.runner, os.path.realpath(args.gsdir), os.path.realpath(args.dumpdir), args.renderer, args.upscale, args.renderhacks, args.parallel):
|
2022-06-19 05:43:55 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|
|
|
|
|