Skip to content

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

Closed
SirKingg wants to merge 1 commit into
ItsNotRexed:mainfrom
SirKingg:tpd1h81-deere-correction-bc6h-zero-signe
Closed

SirKingg wants to merge 1 commit into
ItsNotRexed:mainfrom
SirKingg:tpd1h81-deere-correction-bc6h-zero-signe

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>
@SirKingg

Copy link
Copy Markdown
Contributor Author

Superseded by #6175 at the same tested commit. Please continue review there. Existing branch and history are retained; nothing was merged.

@SirKingg SirKingg closed this Nov 23, 2026
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.

1 participant