move all rendertest.sh functionality into .py

This commit is contained in:
Ivan Avdeev 2023-11-27 12:01:11 -05:00
parent b09edd28fe
commit 8d67f409bc
2 changed files with 87 additions and 9 deletions

View File

@ -145,5 +145,5 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "loading: %.03fms, diffing: %.03fms, saving: %.03fms; total: %.03fms\n", fprintf(stderr, "loading: %.03fms, diffing: %.03fms, saving: %.03fms; total: %.03fms\n",
MS(loaded_ns - start_ns), MS(diffd_ns - loaded_ns), MS(end_ns - diffd_ns), MS(end_ns - start_ns)); MS(loaded_ns - start_ns), MS(diffd_ns - loaded_ns), MS(end_ns - diffd_ns), MS(end_ns - start_ns));
return over; return over ? 2 : 0;
} }

View File

@ -1,5 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import os
import pathlib
import shutil
import subprocess
ROOT = os.path.dirname(os.path.abspath(__file__))
# TODO load all saves from the save/ dir # TODO load all saves from the save/ dir
saves = [ saves = [
'brush2_01', 'brush2_01',
@ -7,6 +15,7 @@ saves = [
'brush_02', 'brush_02',
'c0a0d_emissive', 'c0a0d_emissive',
'light_01', 'light_01',
#'additive_cullback',
] ]
displays = { displays = {
@ -22,8 +31,6 @@ displays = {
'indirect_diffuse': 'indirect_diff', 'indirect_diffuse': 'indirect_diff',
} }
import argparse
def test_list(arg: str) -> [str]: def test_list(arg: str) -> [str]:
items = arg.split(',') items = arg.split(',')
tests = [] tests = []
@ -35,8 +42,14 @@ def test_list(arg: str) -> [str]:
return tests return tests
parser = argparse.ArgumentParser(description='Generate scripts and makefiles for rendertest') parser = argparse.ArgumentParser(description='Generate scripts and makefiles for rendertest')
parser.add_argument('--script', '-s', type=argparse.FileType('w'), help='Console script for generating images') #parser.add_argument('--script', '-s', type=argparse.FileType('w'), help='Console script for generating images')
parser.add_argument('--tests', '-t', type=test_list, default=saves, help='Run only these tests') parser.add_argument('--tests', '-t', type=test_list, default=saves, help='Run only these tests')
# TODO how to check that the dir is valid? presence of xash3d executable and valve dir?
parser.add_argument('--xash-dir', '-x', type=str, default=os.getcwd(), help='Path to xash3d-fwgs installation directory')
# TODO parse commands in type=.. function
parser.add_argument('command', type=str, default=None, help='Action to perform')
args = parser.parse_args() args = parser.parse_args()
def make_script(file, tests: [str]): def make_script(file, tests: [str]):
@ -52,6 +65,7 @@ rt_debug_fixed_random_seed 31337
''' '''
print(f'Generating script {file.name}')
file.write(header) file.write(header)
for test in tests: for test in tests:
@ -66,12 +80,76 @@ rt_debug_fixed_random_seed 31337
file.write('quit\n') file.write('quit\n')
if args.script: # if args.script:
print(f'Generating script {args.script.name}') # print(f'Generating script {args.script.name}')
make_script(args.script, args.tests) # make_script(args.script, args.tests)
def compile():
subprocess.run(['make', 'imagecompare'], cwd=ROOT, check=True)
with open(f'{args.xash_dir}/rendertest.script', 'w') as script:
make_script(script, args.tests)
def copy_assets():
print('Copying assets')
shutil.copytree(src=f'{ROOT}/maps', dst=f'{args.xash_dir}/valve/maps/', dirs_exist_ok=True)
shutil.copytree(src=f'{ROOT}/save', dst=f'{args.xash_dir}/valve/save/', dirs_exist_ok=True)
def render():
print('Running xash3d')
pathlib.Path(f'{args.xash_dir}/valve/rendertest').mkdir(parents=True, exist_ok=True)
env = os.environ.copy()
env['RADV_PERFTEST'] = 'rt'
env['LD_LIBRARY_PATH'] = '.'
subprocess.run([f'{args.xash_dir}/xash3d', '-ref', 'vk',
'-nowriteconfig', '-nosound', '-log',
'-width', '1280', '-height', '800',
'+exec', 'rendertest.script'],
env=env, check=True)
def compare():
screenshot_base = f'{args.xash_dir}/valve/rendertest'
for test in args.tests:
for name, display in displays.items():
image_base = f'{test}_{name}'
image_test = f'{screenshot_base}/{image_base}.tga'
image_gold = f'{ROOT}/gold/{image_base}.png'
image_diff = f'{ROOT}/work/{image_base}_diff.tga'
compare = subprocess.run([f'{ROOT}/imagecompare', image_gold, image_test, image_diff])
match compare.returncode:
case 0:
pass
case 1:
raise Exception(f'FATAL imagecompare error: TBD')
case 2:
print(f'ERROR: {image_base} differ by more than threshold')
case _:
raise Exception(f'Unexpected imagecompare return code {compare.returncode}')
subprocess.run(['convert',
'(', image_gold, '-bordercolor', 'gold', '-border', '2x2', '-gravity', 'SouthWest', '-font', 'Impact', '-pointsize', '24', '-fill', 'gold', '-stroke', 'black', '-annotate', '0', 'GOLD', ')',
'(', image_test, '-bordercolor', 'white', '-border', '2x2', '-fill', 'white', '-annotate', '0', 'TEST', ')',
'-loop', '0', '-set', 'delay', '25', f'{ROOT}/work/{image_base}_flip.gif'], check=True)
def command_compare():
compare()
def command_run():
compile()
copy_assets()
render()
compare()
#report()
match args.command:
case 'run':
command_run()
case 'compare':
command_compare()
case _:
raise Exception(f'Unknown command {args.command}')
# TODO: # TODO:
# - single command to do everything: compile, run, and compare
# - filter by specific save files
# - parallel processing # - parallel processing
# - HTML report # - HTML report