tools/client/test_portable_devices.py (1894B)
1 """Compare Direct3D device contracts and rendered pixels with Windows x86.""" 2 import pathlib 3 import subprocess 4 5 6 root = pathlib.Path(__file__).resolve().parents[2] 7 decompiled = root / "client" 8 work = root / "local/client/portable-devices" 9 work.mkdir(parents=True, exist_ok=True) 10 reference = work / "reference.exe" 11 subprocess.run([ 12 str(root / "toolchains/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe"), 13 "-O2", "tests/devices.c", "-o", str(reference), 14 ], cwd=decompiled, check=True) 15 expected = subprocess.check_output([str(reference), str(work / "reference.rgb")], text=True, timeout=30) 16 linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:] 17 linux_work = "/mnt/" + work.drive[0].lower() + work.as_posix()[2:] 18 wsl = ["wsl", "-d", "Ubuntu-26.04", "--cd", linux_path, "--exec"] 19 subprocess.run(wsl + [ 20 "gcc", "-O2", "-Wall", "-Wextra", "-DRECOMP_PORTABLE", "-Iruntime", "-fno-strict-aliasing", 21 "tests/devices.c", "runtime/linux_graphics.c", "runtime/linux_window.c", "runtime/gl_renderer.c", 22 "runtime/guest_heap.c", "runtime/guest_memory.c", "runtime/recomp_state.c", "-lSDL2", "-lGL", "-lm", "-o", linux_work + "/translated", 23 ], check=True) 24 actual = subprocess.check_output(wsl + ["env", "GALLIUM_DRIVER=d3d12", linux_work + "/translated", linux_work + "/native.rgb"], text=True, timeout=30) 25 assert actual == expected, (expected, actual) 26 windows_pixels = (work / "reference.rgb").read_bytes() 27 linux_pixels = (work / "native.rgb").read_bytes() 28 assert len(windows_pixels) == len(linux_pixels) == 19421184 29 error = max(abs(a - b) for a, b in zip(windows_pixels, linux_pixels)) 30 assert error <= 1, error 31 print("Windows == Linux: " + actual.strip()) 32 print("6472576 pixels agree within one 8-bit channel step; maximum error:", error) 33 print("1152 filtered half-byte alpha cutoffs allow either visibility result; all other pixels are compared.")