Skip to content

fix(textures): emit positive zero after signed BC6H scaling - #6175

Open
SirKingg wants to merge 1 commit into
ItsNotRexed:mainfrom
SirKingg:fix/bc6h-signed-zero
Open

SirKingg wants to merge 1 commit into
ItsNotRexed:mainfrom
SirKingg:fix/bc6h-signed-zero

Conversation

@SirKingg

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6089 (comment)

Depends on: #6120

What and why

Fix the pre-existing signed BC6H zero-sign defect reported at #6089 (comment). An interpolant of -1 scales to integer zero, so its half-word must be 0x0000 rather than 0x8000. Only restore the negative sign when the final magnitude is nonzero.

One production line changes. Add bit-exact tests against an independent signed-integer truncation oracle, all 16 interpolation weights of 272 synthetic mode-14 blocks crossing zero, and a short format note. Reference: Microsoft BC6H finalization. No Microsoft source code or game content is copied.

Conflict, not a code dependency: based independently on main at 561b65a. #6120 at a574976 fixes a different defect (the -32768 endpoint) in the same _bc6h_finish hunk. Its branch was not changed and its fix is not included here. Whichever lands second must preserve both changes: on #6120's implementation the final condition becomes val < 0 and h. The separate minimum-endpoint behavior is unchanged by this PR.

Tested

Windows CPU, Python standard library, synthetic inputs only:

Exact command Result
python -I tests\test_ttpf_mips.py -k bc6h_finish_scaling Before fix: FAIL, -1 produced 0x8000 instead of 0x0000. Covered by the passing full suite below after fix.
python -I tests\test_ttpf_mips.py -k bc6h_signed_mode14_zero Before fix: FAIL on zero-crossing texels. Covered by the passing full suite below after fix.
python -I tests\test_ttpf_mips.py PASS, 79 tests
python -I tests\test_bcpack.py PASS, 17 tests
python -I tests\test_bcpack_history_calib.py PASS, 19 tests
python -I tests\test_ttpf_assets.py PASS, 25 passed / 3 skipped (POSIX-only modes, unbuilt rpf9dump, missing numpy)
python -m compileall -q make_game.py tools tests PASS
git diff --check PASS
python -I - (in-memory compatibility experiment) PASS: exhaustive baseline comparison and combined #6120 checks described below

Across all 65,536 signed and 65,536 unsigned interpolants, comparison with the base implementation found exactly one changed result: signed -1, 0x8000 -> 0x0000. The persisted oracle test covers signed -32767..32767 and unsigned 0..65535; it deliberately leaves #6120's separate -32768 defect alone. Scaling division is exact in binary before truncation for these bounded integers.

Also loaded #6120's two production functions in memory, applied this zero-sign guard, and combined its revised BC6H tests with this branch's suite: 80 tests passed. All 65,536 signed interpolants then matched the independent arithmetic oracle, including -32768 -> 0xfc00. No checkout or modification of the author's branch was needed.

No new GPU run in this PR. The prior independent native D3D11 measurement on RTX 4070 Ti / driver 610.88 is linked in the original finding and #6120 review; it is not presented as a new run. Shader-translator validation: not applicable.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

The translator-rule item is not applicable: no translator changes.

Assign the half-float sign only when the scaled magnitude is nonzero. Add bit-exact synthetic zero-crossing and exhaustive scaling checks against independent arithmetic. Keep the separate minimum-endpoint fix in PR ItsNotRexed#6120 independent.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted Windows CPU check at 41afa94e and #6120 a5749761, using uv CPython 3.12.13. On the mixed-channel blocks from my #6120 check plus finite controls, the #6175 change against round-44 corrected eight 0x8000 half-words to 0x0000. The reference follows Microsoft’s final sign rule after truncation.

The two published commits currently have the same round-44 parent. Exact #6175 alone therefore lacks #6120’s minimum-endpoint correction. Composing the two changes in a disposable in-memory check corrected those same eight zero words, retained all nine 0xfc00 words from #6120, and matched all 192 reference RGB half-words. The finite signed and unsigned controls matched all 96 words in every run.

All four compressed DDS outputs stayed byte-identical, and decoding them reproduced the direct results. The focused suite passed seven with one exporter-dependent skip at #6175. Synthetic inputs only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants