#!/usr/bin/env python3 """Run the engine's own K output kernel on a captured launch of NVIDIA's and compare the four output surfaces. usage: test_out.py CAPTURE_DIR FRAME WORK_DIR KVK [repeats] CAPTURE_DIR: dump/ and replay/ of a run with the output kernel captured (see vulkan/README.md); KVK: the vulkan/kvk binary. """ import glob, os, re, struct, subprocess, sys import numpy as np LDR = os.environ.get('LDR') == '1' # the *_ldr_* kernel variant and the shader's LDR path K = 'hiluma_engine_output_depthinv_mvlo_ldr_max_v2_rel' if LDR else 'hiluma_engine_output_depthinv_mvlo_hdr_max_v2_rel' cap, frame, work, kvk = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4] reps = sys.argv[5] if len(sys.argv) > 5 else '1' HERE = os.path.dirname(os.path.abspath(__file__)) os.makedirs(work, exist_ok=True) seqs = sorted({int(re.match(r'launch-(\d+)-', os.path.basename(f)).group(1)) for f in glob.glob(f'{cap}/dump/launch-*-{K}-arg*')}) seq = seqs[frame] res = {} for f in glob.glob(f'{cap}/dump/launch-{seq:03d}-{K}-arg*'): m = re.search(r'-arg(\d+)-(texture|surface|buffer)-(.*)-fmt(-?\d+)\.bin$', f) res[int(m.group(1))] = (m.group(2), m.group(3), int(m.group(4)), f) rd = f'{cap}/replay/replay-{seq:06d}-{K}' P = open(f'{rd}/args.bin', 'rb').read() man = open(f'{rd}/manifest.txt').read().split('\n') grid = next(l for l in man if l.startswith('launch')).split() ptr = {int(l.split()[1]): int(l.split()[3]) for l in man if l.startswith('pointer')} f2 = lambda o: struct.unpack_from('<2f', P, o) i2 = lambda o: struct.unpack_from('<2i', P, o) h1 = lambda o: float(np.frombuffer(P, np.float16, 1, o)[0]) def expo_tex(off): if off not in res: return 1.0 # LDR: no exposure textures v = float(np.fromfile(res[off][3], np.float16)[0]) return 1.0 if v == 0 else v eA, eB = expo_tex(264), expo_tex(256) s160 = struct.unpack_from('