test: cover mixed BCPack calibration and history

This commit is contained in:
TheGeogeo
2026-11-28 00:59:20 +01:00
parent 51b2819b65
commit a1e0465356
3 changed files with 43 additions and 2 deletions

View File

@ -23,7 +23,8 @@ Stages (each skips work that is already done, so a stopped build continues where
shaders carve shaders.rpf, unpack the native RDNA2 code, disassemble, translate to SPIR-V; then the same for the
programs inside amd_fidelityfx_upscaler_xbox.dll, XboxBvhBuilder.dll and game_scarlett_master.exe
assets models (OBJ), texture dictionaries and texture pools (DDS), audio banks (AWC; --wav adds PCM WAV)
BCPack uses strict decoding by default. For local calibration use <work>/bcpack-calibration.json.
BCPack uses strict decoding by default and reads confirmed history from <work>/bcpack-history.json.
For local calibration use <work>/bcpack-calibration.json.
runtime build the loader (needs the game's executable to run, not to build). On Linux it is cross-built with
clang-cl and an xwin SDK (docs/testing.md) and gta6rt.sh starts it with Wine; --runtime-build DIR
takes a Windows build of runtime/ instead (the runtime-windows artifact of the Runtime workflow)
@ -3116,7 +3117,8 @@ def main() -> int:
ap.add_argument("--out", type=nonempty_path, help="folder for the finished port (default Documents/Leonida; ~/Leonida on a Mac "
"whose Documents iCloud syncs)")
ap.add_argument("--work", type=nonempty_path, help="folder for intermediate files (hundreds of GB; default <out>/work)")
ap.add_argument("--stages", help="comma list from: " + ",".join(STAGES))
ap.add_argument("--stages", help=f"comma list from: {','.join(STAGES)}. The assets stage reads "
"<work>/bcpack-history.json for strict BCPack and <work>/bcpack-calibration.json for calibration")
ap.add_argument("--check", action="store_true", help="only check the game files")
ap.add_argument("--full-check", action="store_true",
help="also verify each manifest file's SHA-256 using --jobs workers (slow)")

View File

@ -263,6 +263,7 @@ class TextureAssets(unittest.TestCase):
updated = self.folder / self.row_after_export()["File"]
self.assertNotEqual(updated, original)
self.assertEqual(updated.read_bytes()[148:], b"".join(linear.values()))
self.assertFalse(original.exists())
history.unlink()
self.build()
@ -465,6 +466,42 @@ class CompletePoolEarlyReturn(unittest.TestCase):
pool.assert_not_called()
def test_calibrated_and_strict_rows_use_separate_stamps_with_history(self):
pool = mock.Mock(chunks=[(0,)], virtual_size=64)
pool.descriptor.side_effect = [
{"base": 0, "dimension": 1, "format": 77, "mips": 1},
{"base": 8, "dimension": 1, "format": 71, "mips": 1},
]
pool.span.return_value = 8
pool.codecs.return_value = ttpf_assets.bcpack.SUPPORTED_REBUILD_CODECS
calibrated = mock.Mock()
calibrated.LocalDecoder.return_value.formats = {77}
calibrated.LocalDecoder.return_value.dds.return_value = b"calibrated"
history = {"bc1": {"confirmed": {"6": [0, 0, 0, 0, 0, 0]}}}
with tempfile.TemporaryDirectory() as tmp, ExitStack() as stack:
work = Path(tmp)
(work / "bcpack-calibration.json").write_text('{"version": 1}', encoding="utf-8", newline="\n")
stack.enter_context(mock.patch.dict(sys.modules, calibrated_texture=calibrated))
calibrated_stamp, _ = ttpf_assets.load_profile(work)
history_path = work / "bcpack-history.json"
history_path.write_text(json.dumps(history), encoding="utf-8", newline="\n")
strict_stamp = ttpf_assets.strict_stamp(history_path.read_bytes())
settings = ttpf_assets.load_profile(work)
stack.enter_context(mock.patch.object(ttpf_assets.ttpf, "Pool", return_value=pool))
stack.enter_context(mock.patch.object(ttpf_assets.ttpf, "analyze", return_value=mock.sentinel.analysis))
texture_dds = stack.enter_context(mock.patch.object(ttpf_assets.ttpf, "texture_dds", return_value=b"strict"))
calibrated_row = synthetic_row(Index=0, DxgiFormat=77)
strict_row = synthetic_row(Index=1, DxgiFormat=71)
manifest = {"Textures": [calibrated_row, strict_row]}
self.assertEqual(ttpf_assets.complete_pool("synthetic", work, manifest, settings), (2, 0))
calibrated.LocalDecoder.return_value.dds.assert_called_once_with(0)
texture_dds.assert_called_once_with(pool, mock.sentinel.analysis, history=history)
self.assertEqual(manifest["BCPackPass"], f"{calibrated_stamp}+{strict_stamp}")
self.assertEqual(calibrated_row["BCPackDecoder"], calibrated_stamp)
self.assertEqual(strict_row["BCPackDecoder"], strict_stamp)
def test_a_pool_hashes_the_decoder_sources_once_for_all_its_strict_fallback_rows(self):
# With a profile, each row the calibrated decoder can't take falls back to strict decoding; hashing the
# sources per row read them 32 times over for 32 rows. A new pass computes the stamp again.

View File

@ -27,6 +27,8 @@ Run the ordinary build or `python -I make_game.py --game <package> --work <work>
For the strict decoder, place a local combined history from `bcpack_history_calib.py` at `<work>/bcpack-history.json` (use that filename as the tool's `--out`). The assets stage uses this same history for all strict reconstructions, including fallbacks for formats outside a calibration profile. Adding, changing or removing the history invalidates the saved pool pass. Run the assets stage again with the same work folder. Strict decoding still refuses unconfirmed history, and a refusal keeps any previous DDS in the catalog.
Pool-only calibration produces provisional entries. A provisional-only history starts a new pass without supplying confirmed entries for strict decoding. Use exact references with `--ref-dds` or `--ref-pairs` to produce confirmed entries.
The DDS files and their manifest are under `<work>/assets/ttpf/<pool>/` or `<work>/assets/ttpf_pack/<pack>/<pool>/`. The manifest keeps the asset key for model lookup and records the new filename, mip count and decoder. A failed reconstruction keeps the previous file reference and records the reason in `BCPackLimitation`. The stage publishes each DDS before replacing the pool manifest. A completed pass skips decoding on the next build. Adding or changing the profile triggers another pass.
## Version 1 profile