diff --git a/docs/textures.md b/docs/textures.md index 0aa6cd849b..28d4ce7f21 100644 --- a/docs/textures.md +++ b/docs/textures.md @@ -304,6 +304,14 @@ each mip with a 2x2 box downsample of its parent (at 4x4 block resolution for BC resolution for uncompressed). A correct chain is 0–4 levels, as in the SixNG notes; the control is the first tail mip detiled at origin (0,0). +Signed BC6H final scaling truncates toward zero before assigning the half-float sign: +an interpolated integer of -1 therefore becomes positive zero (`0x0000`), not negative +zero (`0x8000`). This follows [Microsoft's BC6H finalization algorithm](https://learn.microsoft.com/en-us/windows/win32/direct3d11/bc6h-format#unquantization-of-color-endpoints). +`tests/test_ttpf_mips.py` checks the signed finite range and the full unsigned range +against an independent signed-integer scaling oracle, plus synthetic mode-14 blocks +crossing zero at every interpolation weight. The separate signed minimum-endpoint +behavior is tracked in [#6120](https://github.com/ItsNotRexed/Leonida/pull/6120). + | Pool # | Descriptor | Mips | non_tail / first_tail | Max error | Tail control | |---|---|---:|---:|---:|---:| | `interiors_0_3` #19 | 512×256 BC1 | 7 | 1 / 3 | 0.38 | 126.06 | diff --git a/tests/test_ttpf_mips.py b/tests/test_ttpf_mips.py index b1beaf6a50..ba60ef8f07 100644 --- a/tests/test_ttpf_mips.py +++ b/tests/test_ttpf_mips.py @@ -652,6 +652,41 @@ def test_bc6h_modes_uf16_sf16_and_reserved(self): self.assertGreater(px1e[0][0], 0.0) self.assertEqual(px1e[2][0], -px1e[0][0]) + def test_bc6h_finish_scaling_matches_signed_integer_oracle(self): + # Microsoft BC6H: truncate the signed scale toward zero, then encode + # the sign of that integer, not the sign before scaling. + # https://learn.microsoft.com/en-us/windows/win32/direct3d11/bc6h-format + lut = ttpf._f16_lut() + # The separate -32768 endpoint/clamping defect is covered by PR #6120. + for value in range(-32767, 32768): + scaled = int(value * 31 / 32) + expected = abs(scaled) + (0x8000 if scaled < 0 else 0) + actual = struct.unpack("> 5 if h > 0x7BFF: h = 0x7BFF - return lut[h | 0x8000] if neg else lut[h] + return lut[h | 0x8000] if neg and h else lut[h] def decode_bc6h_block(data, at, *, signed=False):