"""igc_conformance.py -- the golden-model conformance suite. Any port of the IGC/EMC model (RTL, GPU compute, C) must reproduce these outputs bit-for-bit (where pinned) from the committed fixtures in conformance/. The fixtures are REAL captured data from the firmware running on emu860 (see IGC-ENCODING-DERIVATION.md for provenance). Cases: C1 DUMP reference packet parses to the exact named instruction sequence. C2 Synthetic triangle rasterizes to the exact lit-pixel count. C3 Bars pipeline: the cap7 bench per-tile programs (sends_cap7.pkl), with the documented texz seed, compute texu == global x (+2) per pixel. C4 fxtest effect primitives (fx_program.pkl) rasterize: 9 primitives drawn, pinned z-buffer coverage + centroid. Run: python igc_conformance.py (exit 0 = conformant) """ import os, sys, pickle, struct sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import igc_exec HERE = os.path.dirname(os.path.abspath(__file__)) FIX = os.path.join(HERE, 'conformance') def f32(w): return struct.unpack('> 8) & 0xff) == 0x2c] assert len(setups) == 10, len(setups) # rasterize coarsely on a 104x64 grid (1/8 scale) and pin coverage W, H = 104, 64 drawn = 0 covered = 0 zwins = 0 zbuf = [[-1e30] * W for _ in range(H)] for a in setups: edges = [] p = a + 4 while ((rd(p) >> 8) & 0xff) == 0x2c and len(edges) < 6: edges.append((f32(rd(p+4)), f32(rd(p+8)), f32(rd(p+12)))) p += 16 zp = None q = p for _ in range(40): w = rd(q) if ((w >> 8) & 0xff) == 0x21: zp = (f32(rd(q+4)), f32(rd(q+8)), f32(rd(q+12))) break q += 4 if zp is None: continue any_px = False for gy in range(H): for gx in range(W): x, y = gx * 8, gy * 8 vs = [A * x + B * y + C for A, B, C in edges] inside = all(v >= 0 for v in vs) or all(v < 0 for v in vs) if not inside: continue any_px = True covered += 1 z = zp[0] * x + zp[1] * y + zp[2] if z > zbuf[gy][gx]: zbuf[gy][gx] = z zwins += 1 if any_px: drawn += 1 assert drawn == 10, drawn assert covered == 5706, covered assert zwins == 5119, zwins return 'C4 fxtest primitives: PASS (10 drawn, coverage %d, zwins %d)' % (covered, zwins) if __name__ == '__main__': results = [] for case in (c1_dump_reference, c2_synthetic_triangle, c3_bars_pipeline, c4_fxtest_primitives): results.append(case()) print('\n'.join(results)) print('CONFORMANT')