#!/usr/bin/env python3 """Compare 24 owner4 tile-hash cases with the pre-cleanup L130 binary.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l131/hash-matrix" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "base": ROOT / "Saved/Linux/l130/bin/VoxelForgeCoreHeadless-l130-{compiler}", "l131": ROOT / "Saved/Linux/l131/bin/VoxelForgeCoreHeadless-l131-{compiler}", } CAMERAS = { "sw": ((8.0, 16.0, -372.2626953125), 2850), "fi": ((25.8369140625, 3.19921875, -737.0), 2249), "tn": ((19.166015625, -14.2001953125, -753.3740234375), 2233), "vs": ((-20.0625, -5.068359375, -900.353515625), 2329), } TILE_RE = re.compile( r"^\[PipelineTileHash\] lod=(-?\d+) x=(-?\d+) y=(-?\d+) z=(-?\d+) " r"density=(0x[0-9a-f]+) mesh=(0x[0-9a-f]+) payload=(0x[0-9a-f]+) " r"topology=(0x[0-9a-f]+)$", re.M) WHOLE_RE = re.compile( r"^\[PipelineWholeViewHash\] tiles=(\d+) density=(0x[0-9a-f]+) " r"mesh=(0x[0-9a-f]+) payload=(0x[0-9a-f]+) topology=(0x[0-9a-f]+)$", re.M) def capture(camera_name: str, compiler: str, workers: int, version: str) -> tuple[dict, tuple[str, ...], float]: camera, expected_tiles = CAMERAS[camera_name] camera_arg = ",".join(f"{value:.12f}" for value in camera) + ",0,0" binary = Path(str(BINARIES[version]).format(compiler=compiler)) log = OUT / f"owner4-{camera_name}-{compiler}-w{workers}-{version}.log" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera_arg}", "--stream-hash-tiles"] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) elapsed = time.monotonic() - started output = log.read_text(encoding="utf-8", errors="replace") tiles = {(int(match.group(1)), int(match.group(2)), int(match.group(3)), int(match.group(4))): match.group(5, 6, 7, 8) for match in TILE_RE.finditer(output)} whole = WHOLE_RE.search(output) if result.returncode or whole is None or len(tiles) != expected_tiles or len(tiles) != int(whole.group(1)): raise RuntimeError(f"incomplete {version} {camera_name}/{compiler}/W{workers}: {log}") return tiles, whole.groups(), elapsed def main() -> int: OUT.mkdir(parents=True, exist_ok=True) rows = [] for camera_name in CAMERAS: for compiler in ("clang", "gcc"): for workers in (1, 8, 12): old_tiles, old_whole, old_s = capture(camera_name, compiler, workers, "base") new_tiles, new_whole, new_s = capture(camera_name, compiler, workers, "l131") keys = set(old_tiles) | set(new_tiles) tile_mismatches = sum(old_tiles.get(key) != new_tiles.get(key) for key in keys) row = {"owner": "owner4", "camera": camera_name, "compiler": compiler, "workers": workers, "tiles": len(new_tiles), "tile_mismatches": tile_mismatches, "whole_view_match": old_whole == new_whole, "base_s": round(old_s, 3), "l131_s": round(new_s, 3), "base_log": f"Saved/Linux/l131/hash-matrix/owner4-{camera_name}-{compiler}-w{workers}-base.log", "l131_log": f"Saved/Linux/l131/hash-matrix/owner4-{camera_name}-{compiler}-w{workers}-l131.log"} rows.append(row) print("[L131HashIdentity] " + json.dumps(row, sort_keys=True), flush=True) (OUT / "runs-partial.json").write_text(json.dumps(rows, indent=2) + "\n") failures = [row for row in rows if row["tile_mismatches"] or not row["whole_view_match"]] (OUT / "summary.json").write_text(json.dumps({"runs": rows, "passed": len(rows)-len(failures), "failed": len(failures)}, indent=2) + "\n") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())