Inventory grid harness: -goldenOut writes the shader's own output as the golden
tests/fixtures/inventory-grid holds the grid renders of the atlas (4 regimes x 3 passes x 2 widths), the thermal pipes (S32, S16), the five alpha and clip cases, and the overlay capture's three crops, written by -goldenOut in runs that still passed every sprite bound: atlas worst 4, hull worst 4, thermal rms 0.0430 and hull 0.1007, alpha and clip worst 1, masked 0 (the readings of cda9474b1), overlay worst 3. The next commit judges against them.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3d715e8021
commit
44100ca4a8
36 changed files with 167 additions and 9 deletions
|
|
@ -10,13 +10,16 @@ using int2 = CultMath.int2;
|
|||
// InventoryGridParityCapture cannot draw. An overlay canvas draws to the Game view's back buffer, so this enters play mode and
|
||||
// reads the screen at the end of a frame: once with the sprite cells, once with the grid over the same canvas rects.
|
||||
//
|
||||
// Unity -batchmode -projectPath <project> -executeMethod InventoryGridOverlayCapture.Run [-pngOut <dir>] -logFile <log>
|
||||
// Unity -batchmode -projectPath <project> -executeMethod InventoryGridOverlayCapture.Run [-pngOut <dir>] [-goldenOut [<dir>]] -logFile <log>
|
||||
//
|
||||
// -goldenOut also writes the grid's crop of each capture as overlay-<name>.png into <dir> (default tests/fixtures/inventory-grid/).
|
||||
//
|
||||
// Needs a GPU device; do not pass -nographics or -quit. Logs "[InventoryGridOverlay]" lines and exits 0 or 1.
|
||||
public static class InventoryGridOverlayCapture
|
||||
{
|
||||
private const string Pending = "InventoryGridOverlayCapture.pending";
|
||||
private const string PngKey = "InventoryGridOverlayCapture.png";
|
||||
private const string GoldenKey = "InventoryGridOverlayCapture.golden";
|
||||
// The parity harness's atlas bound (InventoryGridParityCapture.AtlasBound): sqrt(4 x 66).
|
||||
private const int Bound = 16;
|
||||
|
||||
|
|
@ -25,6 +28,9 @@ public static class InventoryGridOverlayCapture
|
|||
var args = Environment.GetCommandLineArgs();
|
||||
var i = Array.IndexOf(args, "-pngOut");
|
||||
SessionState.SetString(PngKey, i >= 0 && i + 1 < args.Length ? args[i + 1] : "");
|
||||
var golden = Array.IndexOf(args, "-goldenOut");
|
||||
SessionState.SetString(GoldenKey, golden < 0 ? "" : golden + 1 < args.Length && !args[golden + 1].StartsWith("-") ? args[golden + 1]
|
||||
: Path.Combine(Directory.GetParent(Application.dataPath)!.FullName, "tests", "fixtures", "inventory-grid"));
|
||||
SessionState.SetBool(Pending, true);
|
||||
EditorApplication.EnterPlaymode();
|
||||
}
|
||||
|
|
@ -69,6 +75,7 @@ public static class InventoryGridOverlayCapture
|
|||
var failed = false;
|
||||
var overallWorst = 0;
|
||||
var png = SessionState.GetString(PngKey, "");
|
||||
var goldenOut = SessionState.GetString(GoldenKey, "");
|
||||
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/UI/Inventory.prefab");
|
||||
var panel = prefab.GetComponentInChildren<InventoryPanel>(true);
|
||||
var shader = AssetDatabase.LoadAssetAtPath<Shader>("Assets/Shaders/InventoryGrid.shader");
|
||||
|
|
@ -188,11 +195,24 @@ public static class InventoryGridOverlayCapture
|
|||
failed = true;
|
||||
Log($"BOUND BREACHED overlay {name}: worst {worst} (bound {Bound}), lit {lit}");
|
||||
}
|
||||
var cropW = Mathf.Min(old.width, Mathf.CeilToInt((8 + 8 * stride) * scale));
|
||||
var cropH = Mathf.Min(old.height, Mathf.CeilToInt((8 + 12 * stride) * scale));
|
||||
if (goldenOut != "")
|
||||
{
|
||||
Directory.CreateDirectory(goldenOut);
|
||||
var crop = new Texture2D(cropW, cropH, TextureFormat.RGBA32, false, true);
|
||||
var cropPixels = new Color32[cropW * cropH];
|
||||
for (var y = 0; y < cropH; y++)
|
||||
for (var x = 0; x < cropW; x++)
|
||||
cropPixels[y * cropW + x] = b[y * old.width + x];
|
||||
crop.SetPixels32(cropPixels);
|
||||
File.WriteAllBytes(Path.Combine(goldenOut, $"overlay-{name}.png"), crop.EncodeToPNG());
|
||||
Destroy(crop);
|
||||
Log($"golden written: overlay-{name}.png {cropW}x{cropH}");
|
||||
}
|
||||
if (png != "")
|
||||
{
|
||||
Directory.CreateDirectory(png);
|
||||
var cropW = Mathf.Min(old.width, Mathf.CeilToInt((8 + 8 * stride) * scale));
|
||||
var cropH = Mathf.Min(old.height, Mathf.CeilToInt((8 + 12 * stride) * scale));
|
||||
var sheet = new Texture2D(cropW * 3, cropH, TextureFormat.RGBA32, false);
|
||||
var pixels = new Color32[cropW * 3 * cropH];
|
||||
for (var y = 0; y < cropH; y++)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ using int2 = CultMath.int2;
|
|||
// The parity harness of the inventory grid (map IG): the sheet sprites are the oracle and InventoryGrid is judged against them.
|
||||
// Every check logs one "[InventoryGridParity]" line, and the run exits 0 when every bound holds, 1 otherwise.
|
||||
//
|
||||
// Unity -batchmode -projectPath <project> -executeMethod InventoryGridParityCapture.Run [-pngOut <dir>] [-mutant <name>] [-hullOnly] [-recordsIn <golden>] -logFile <log>
|
||||
// Unity -batchmode -projectPath <project> -executeMethod InventoryGridParityCapture.Run [-pngOut <dir>] [-mutant <name>] [-hullOnly] [-recordsIn <golden>] [-goldenOut [<dir>]] -logFile <log>
|
||||
//
|
||||
// -goldenOut writes the grid renders of the synthetic sections (the atlas, the thermal pipes, vertex alpha and clip) as PNGs into <dir>
|
||||
// (default tests/fixtures/inventory-grid/), cropped to the judged region. A run that writes them must pass every sprite bound, so the golden is
|
||||
// the shader's output at a commit where the sheets judged it.
|
||||
//
|
||||
// -recordsIn is the golden of the real-hull states (every cell's record and rect in page canvas units, and the temperature display's
|
||||
// rect) that the first commit of the switch cut wrote from the sprite panels (`-recordsOut`, which exists only at that commit); the live
|
||||
|
|
@ -44,7 +48,7 @@ public static class InventoryGridParityCapture
|
|||
private static double _thermalWorst, _thermalHullWorst;
|
||||
|
||||
private static string _mutant = "";
|
||||
private static string _pngOut, _recordsIn;
|
||||
private static string _pngOut, _recordsIn, _goldenOut;
|
||||
private static readonly List<string> Breaches = new List<string>();
|
||||
|
||||
public static readonly string[] Mutants =
|
||||
|
|
@ -54,6 +58,26 @@ public static class InventoryGridParityCapture
|
|||
|
||||
private static void Log(string line) => Debug.Log("[InventoryGridParity] " + line);
|
||||
|
||||
// The golden of the shader's own output: one RGBA PNG per synthetic case, cropped to the judged region.
|
||||
private static string GoldenDefault => Path.Combine(Directory.GetParent(Application.dataPath)!.FullName, "tests", "fixtures", "inventory-grid");
|
||||
|
||||
private static void WriteGolden(string name, Rig rig, Color32[] pixels, RectInt region)
|
||||
{
|
||||
if (_goldenOut == null) return;
|
||||
var x1 = Mathf.Min(rig.Width, region.x + region.width);
|
||||
var y1 = Mathf.Min(rig.Height, region.y + region.height);
|
||||
region = new RectInt(Mathf.Max(0, region.x), Mathf.Max(0, region.y), x1 - Mathf.Max(0, region.x), y1 - Mathf.Max(0, region.y));
|
||||
var crop = new Color32[region.width * region.height];
|
||||
for (var y = 0; y < region.height; y++)
|
||||
for (var x = 0; x < region.width; x++)
|
||||
crop[y * region.width + x] = pixels[(region.y + y) * rig.Width + region.x + x];
|
||||
var texture = new Texture2D(region.width, region.height, TextureFormat.RGBA32, false, true);
|
||||
texture.SetPixels32(crop);
|
||||
File.WriteAllBytes(Path.Combine(_goldenOut, name + ".png"), texture.EncodeToPNG());
|
||||
UnityEngine.Object.DestroyImmediate(texture);
|
||||
Log($"golden written: {name}.png {region.width}x{region.height}");
|
||||
}
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
try
|
||||
|
|
@ -64,6 +88,13 @@ public static class InventoryGridParityCapture
|
|||
_recordsIn = Arg("-recordsIn");
|
||||
if (Arg("-recordsOut") != null) throw new InvalidOperationException("-recordsOut writes the golden from the sprite panels and exists only at the first commit of the switch cut.");
|
||||
_mutant = Arg("-mutant") ?? "";
|
||||
var goldenAt = Array.IndexOf(args, "-goldenOut");
|
||||
if (goldenAt >= 0)
|
||||
{
|
||||
if (_mutant != "") throw new InvalidOperationException("-goldenOut writes the shader's own output and cannot run with a mutant.");
|
||||
_goldenOut = goldenAt + 1 < args.Length && !args[goldenAt + 1].StartsWith("-") ? args[goldenAt + 1] : GoldenDefault;
|
||||
Directory.CreateDirectory(_goldenOut);
|
||||
}
|
||||
if (Arg("-atlasBound") != null) AtlasBound = int.Parse(Arg("-atlasBound"));
|
||||
if (Arg("-thermalBound") != null) ThermalHullBound = ThermalBound = double.Parse(Arg("-thermalBound"), System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (_mutant != "" && !Mutants.Contains(_mutant)) throw new InvalidOperationException("Unknown mutant " + _mutant);
|
||||
|
|
@ -334,8 +365,9 @@ public static class InventoryGridParityCapture
|
|||
Log($"atlas {regime.Name} w={width} pass={pass} max8bitDiff={worst} (mask {worstMask}) slipFootprintMax={slip} padSlipMax={pad}");
|
||||
_atlasWorst = Math.Max(_atlasWorst, worst);
|
||||
if (worst > AtlasBound) Breaches.Add($"atlas {regime.Name} w={width} pass={pass}: {worst} > {AtlasBound}");
|
||||
if (pass == 0 || pass == 2) SaveSideBySide($"atlas-{regime.Name}-{width}-pass{pass}.png", rig, old, fresh,
|
||||
new RectInt(0, 0, Mathf.CeilToInt((8 + columns * stride) * rig.Scale), Mathf.CeilToInt((8 + 16 * stride) * rig.Scale)));
|
||||
var atlasRegion = new RectInt(0, 0, Mathf.CeilToInt((8 + columns * stride) * rig.Scale), Mathf.CeilToInt((8 + 16 * stride) * rig.Scale));
|
||||
WriteGolden($"atlas-{regime.Name}-w{width}-pass{pass}", rig, fresh, atlasRegion);
|
||||
if (pass == 0 || pass == 2) SaveSideBySide($"atlas-{regime.Name}-{width}-pass{pass}.png", rig, old, fresh, atlasRegion);
|
||||
_ = cells;
|
||||
}
|
||||
}
|
||||
|
|
@ -553,7 +585,9 @@ public static class InventoryGridParityCapture
|
|||
_alphaClipWorst = Math.Max(_alphaClipWorst, worst);
|
||||
if (lit == 0) Breaches.Add($"{name}: nothing drawn");
|
||||
if (worst > AtlasBound) Breaches.Add($"{name}: {worst} > {AtlasBound}");
|
||||
SaveSideBySide($"alpha-clip-{name.Replace(' ', '-')}.png", rig, old, fresh, new RectInt(0, 0, Mathf.CeilToInt(8 + 16 * stride), Mathf.CeilToInt(8 + 4 * stride)));
|
||||
var clipRegion = new RectInt(0, 0, Mathf.CeilToInt(8 + 16 * stride), Mathf.CeilToInt(8 + 4 * stride));
|
||||
WriteGolden($"alpha-clip-{name.Replace(' ', '-')}", rig, fresh, clipRegion);
|
||||
SaveSideBySide($"alpha-clip-{name.Replace(' ', '-')}.png", rig, old, fresh, clipRegion);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -735,7 +769,9 @@ public static class InventoryGridParityCapture
|
|||
Log($"thermal S{sizes[k]} worstRms={worst:F4} (mask {Array.IndexOf(rms, worst)})");
|
||||
_thermalWorst = Math.Max(_thermalWorst, worst);
|
||||
if (worst > ThermalBound) Breaches.Add($"thermal S{sizes[k]}: rms {worst:F4} > {ThermalBound}");
|
||||
SaveSideBySide($"thermal-S{sizes[k]}.png", rigs[k], olds[k], fresh, new RectInt(0, 0, Mathf.CeilToInt(8 + 16 * stride), Mathf.CeilToInt(8 + sizes[k] + 8)));
|
||||
var thermalRegion = new RectInt(0, 0, Mathf.CeilToInt(8 + 16 * stride), Mathf.CeilToInt(8 + sizes[k] + 8));
|
||||
WriteGolden($"thermal-S{sizes[k]}", rigs[k], fresh, thermalRegion);
|
||||
SaveSideBySide($"thermal-S{sizes[k]}.png", rigs[k], olds[k], fresh, thermalRegion);
|
||||
}
|
||||
foreach (var rig in rigs) rig.Dispose();
|
||||
}
|
||||
|
|
|
|||
BIN
tests/fixtures/inventory-grid/alpha-clip-RectMask2D-and-half-alpha.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/alpha-clip-RectMask2D-and-half-alpha.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/alpha-clip-RectMask2D.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/alpha-clip-RectMask2D.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/alpha-clip-half-alpha.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/alpha-clip-half-alpha.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/alpha-clip-opaque.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/alpha-clip-opaque.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/alpha-clip-quarter-alpha.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/alpha-clip-quarter-alpha.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S10m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S16m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S32m1-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w1920-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass0.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/atlas-S6m1.5-w2560-pass2.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/overlay-S16m1.5.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/overlay-S16m1.5.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/overlay-S32m1-halfalpha.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/overlay-S32m1-halfalpha.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/overlay-S32m1.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/overlay-S32m1.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/thermal-S16.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/thermal-S16.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/inventory-grid/thermal-S32.png
(Stored with Git LFS)
vendored
Normal file
BIN
tests/fixtures/inventory-grid/thermal-S32.png
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue