#!/usr/bin/env python3 """Compare L84 and L85 per-tile and whole-view hashes for all four full views.""" 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/l85/hash-check-final" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "L84": ROOT / "Saved/Linux/l84/bin/VoxelForgeCoreHeadless-l84-clang19", "L85": ROOT / "Saved/Linux/l85/bin/VoxelForgeCoreHeadless-clang19", } STAMPS = { "L84": "c433a039b0255ce3c4794bf20313b8a5a11442feeb07b6555f585688949741a5", "L85": "2967bb8aaea5a7beac0cd0735c0c2e5cccd7b31a9622dd33395e81ff1e5f2589", } CAMERAS = { 0: (8.0, 16.0, -372.2626953125), 1: (25.8369140625, 3.19921875, -737.0), 2: (19.166015625, -14.2001953125, -753.3740234375), 3: (-20.0625, -5.068359375, -900.353515625), } EXPECTED_WHOLE = {0: 2850, 1: 2249, 2: 2233, 3: 2329} STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) TILE_HASH = 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_HASH = 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 run(strate: int, version: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"{version.lower()}-s{strate}.log" camera = ",".join(f"{v:.12f}" for v in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "env", "VOXELFORGE_L81_PASSAGE_BOUND_PADDING_VOXELS=0", "timeout", "1740s", str(BINARIES[version]), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--stream-scheduler-policy=3", "--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) output = log.read_text(encoding="utf-8", errors="replace") source, whole = STAMP.search(output), WHOLE_HASH.search(output) hashes = { (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_HASH.finditer(output) } if result.returncode or source is None or whole is None: raise RuntimeError(f"hash run failed: exit={result.returncode} {log}") if source.group(1) != STAMPS[version]: raise RuntimeError(f"source stamp mismatch in {log}: {source.group(1)}") if int(whole.group(1)) != EXPECTED_WHOLE[strate] or len(hashes) != EXPECTED_WHOLE[strate]: raise RuntimeError(f"incomplete whole-view hashes in {log}: tiles={len(hashes)} whole={whole.group(1)}") row = { "version": version, "strate": strate, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "tile_count": len(hashes), "whole_hash": whole.group(1, 2, 3, 4, 5), "hashes": hashes, "source_stamp": source.group(1), "log": str(log.relative_to(ROOT)), } print("[L85HashRun] " + json.dumps( {key: value for key, value in row.items() if key != "hashes"}, sort_keys=True), flush=True) return row def main() -> int: for binary in (*BINARIES.values(), DATA): if not binary.is_file(): raise SystemExit(f"missing input: {binary}") rows, comparisons = [], [] for strate in range(4): pair = {version: run(strate, version) for version in ("L84", "L85")} before, after = pair["L84"], pair["L85"] mismatches = sorted(key for key in set(before["hashes"]) | set(after["hashes"]) if before["hashes"].get(key) != after["hashes"].get(key)) comparison = { "strate": strate, "tile_count": len(before["hashes"]), "tile_hashes_identical": not mismatches, "whole_hash_identical": before["whole_hash"] == after["whole_hash"], "mismatch_count": len(mismatches), "first_mismatches": mismatches[:12], "l84_whole_hash": before["whole_hash"], "l85_whole_hash": after["whole_hash"], "logs": {version: pair[version]["log"] for version in pair}, } comparisons.append(comparison) rows.extend({key: value for key, value in row.items() if key != "hashes"} for row in pair.values()) (OUT / "runs-partial.json").write_text(json.dumps( {"comparisons": comparisons, "runs": rows}, indent=2) + "\n", encoding="utf-8") print("[L85HashComparison] " + json.dumps(comparison, sort_keys=True), flush=True) return 0 if all(row["tile_hashes_identical"] and row["whole_hash_identical"] for row in comparisons) else 1 if __name__ == "__main__": raise SystemExit(main())