"""Capture decoding shared by full-frame validation and model packaging. Captures are reference data only. The runtime has no dependency on NGX, CUDA, ZLUDA, PTX or the pointer addresses contained in a capture. """ from dataclasses import dataclass from pathlib import Path import re import struct import numpy as np INPUT = 'hiluma_engine_input_depthinv_mvlo_hdr_v2_rel' OUTPUT = 'hiluma_engine_output_depthinv_mvlo_hdr_max_v2_rel' ORDER = ['enc0', 'enc1', 'enc2', 'enc3', 'enc4', 'dec5', 'dec4', 'dec3', 'dec2', 'dec1', 'dec0'] @dataclass class Resource: path: Path width: int height: int channels: int bits: int def validate(self): if self.path.stat().st_size != self.width * self.height * self.channels * self.bits // 8: raise ValueError(f'truncated texture/surface: {self.path}') class Launch: def __init__(self, capture, directory): self.capture, self.directory = Path(capture), Path(directory) self.sequence = int(re.search(r'replay-(\d+)-', self.directory.name).group(1)) self.args = (self.directory / 'args.bin').read_bytes() self.manifest = (self.directory / 'manifest.txt').read_text().splitlines() self.kernel = self.manifest[0].split()[1] self.resources = {} for f in (self.capture / 'dump').glob(f'launch-{self.sequence:03d}-{self.kernel}-arg*'): match = re.search(r'-arg(\d+)-(texture|surface)-(\d+)x(\d+)x(\d+)-fmt(\d+)\.bin$', f.name) if match: offset, kind, w, h, c, fmt = match.groups() resource = Resource(f.resolve(), int(w), int(h), int(c), 32 if fmt == '32' else 16) self.resources[int(offset)] = resource def f2(self, offset): return struct.unpack_from('<2f', self.args, offset) def i2(self, offset): return struct.unpack_from('<2i', self.args, offset) def f1(self, offset): return struct.unpack_from('