Skip to content

TEST-1506: Preserve the minimum signed BC6H endpoint during texture decoding - #6120

Open
Razdva122 wants to merge 1 commit into
ItsNotRexed:mainfrom
Razdva122:codex/bc6h-signed-endpoint
Open

Razdva122 wants to merge 1 commit into
ItsNotRexed:mainfrom
Razdva122:codex/bc6h-signed-endpoint

Conversation

@Razdva122

@Razdva122 Razdva122 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in coordination issue #6089. Thanks to the contributor who narrowed this down to one 16-byte block in the original report.

What changed

A signed BC6H mode-14 endpoint can be −32768. The CPU decoder clamped it before interpolation, then clamped the output to the largest finite half. This changed the raw texels at the endpoint and at nearby interpolation weights. The decoder now keeps the full signed endpoint and applies the format's final scale. The minimum yields the half-word 0xfc00 (negative infinity). Khronos Data Format §20.2 · Microsoft BC6H format notes

Verification

On an Apple M3 Pro with macOS 15.6.1 and Python 3.14.2, using the CPU and synthetic blocks:

  • Replayed the reported block. On 561b65a all 16 red texels returned 0xfbff. On a574976 all 16 returned 0xfc00.
  • The regression exercises all 16 interpolation weights using literal expected half-words. A separate sweep checked all 65,536 constant signed mode-14 endpoint encodings.
  • Ran the standalone test suites for ttpf_mips, bcpack_history_calib, bcpack and ttpf_assets. 140 tests passed and two optional tests skipped (native calibration dependencies and the built rpf9dump).
  • Checked the HDR mip comparison with synthetic negative-infinity inputs. Identical mips give zero error and comparison with zero gives a finite error.

AI-assisted. The checks used no game content, keys or GPU driver.

Signed-zero review follow-up

The review also identified the pre-existing zero-sign case for an interpolated value of −1. It is being corrected in #6175. The changes touch the same return statement. I combined them locally on a574976 by preserving the full mode-14 endpoint and applying the sign bit only when the scaled magnitude is nonzero. All 80 tests in the combined ttpf_mips suite passed, including both PRs’ regressions. After #6120 lands, #6175 will need that one-line reconciliation.

@Razdva122 Razdva122 changed the title Preserve the minimum signed BC6H endpoint during texture decoding TEST-1506: Preserve the minimum signed BC6H endpoint during texture decoding Nov 23, 2026

@SirKingg SirKingg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review at a574976; AI-assisted.

Native D3D11 Texture2D.Load on Windows, NVIDIA RTX 4070 Ti / driver 610.88: the synthetic signed mode-14 minimum and all 16 interpolation weights match CPU exactly in RGBA float32 bits, including -infinity. Three further synthetic blocks exercised signed wrap in both directions and unsigned wrap: 64 texels total, no skipped GPU cases. The only observed differences were 16 channel results of GPU +0 versus CPU -0 in two wrap cases. This is pre-existing at 561b65a, not caused by this change; reported separately at #6089 (comment).

An independent exhaustive comparison of all 65,536 signed 16-bit endpoints against the published Microsoft BC6H unquantize/finish formulas found the same sole pre-existing difference at -1; all others match. Reference: https://learn.microsoft.com/en-us/windows/win32/direct3d11/bc6h-format

Windows CPU synthetic suites: python -I tests\test_ttpf_mips.py 78 passed; python -I tests\test_bcpack.py 17 passed; python -I tests\test_bcpack_history_calib.py 19 passed; python -I tests\test_ttpf_assets.py 25 passed, 3 skipped (POSIX-only file modes, unbuilt rpf9dump, missing numpy). These CPU suites are not GPU tests. No game files used.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted Windows CPU check at a5749761 against round-44 561b65a8, uv CPython 3.12.13. Two valid mixed-channel signed mode-14 blocks put the minimum endpoint at opposite ends of the interpolation. An independent exact-rational reference found 8/48 mismatched RGB half-words per block on main and 0/48 on the PR. The finite unsigned control matched 48/48 on both.

Each block also went through the stock DDS exporter using a synthetic zlib-backed texture pool. Compressed DDS output was byte-identical across revisions, and decoding those DDS payloads reproduced each revision’s direct half-word results. The stock mip check returned the same finite errors. The focused suite passed six with one exporter-dependent skip on head. Synthetic CPU fixtures only.

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown

Related to @SirKingg's finding (#6089 (comment)), since this PR rewrites the same function: at this head _bc6h_finish still returns negative zero for a signed interpolant of -1. h = (abs(val) * 31) >> 5 is 0 for |val| == 1, and lut[h | 0x8000] then gives half 0x8000, where Microsoft's finish_unquantize gives +0 (0x0000). A one-condition fix that keeps your minimum-endpoint change:

    h = (abs(val) * 31) >> 5
    return lut[h | 0x8000] if val < 0 and h else lut[h]

A regression case: a synthetic signed mode-14 block whose interpolant is -1 should decode to 0x0000. Raising it here rather than in a separate PR, so the two don't conflict on the same lines. AI-assisted (Claude Code).

@tahffo68hk-hash

Copy link
Copy Markdown

I replayed the original endpoint finding in a scratch integration of #6120 a5749761 and #6175 41afa94e. I resolved the two conflicts by retaining both PRs' tests and applying the nonzero-magnitude sign guard to #6120's full signed range. All 80 texture-pool tests passed on Windows.

I also repeated the independent MSVC/bcdec 80859ed comparison, using 1,024 seeded blocks for each of the 14 valid modes and 16 per reserved code. All 48 half-words matched in every one of the 28,800 UF16/SF16 decodes. This is agreement with the Microsoft-style zero-sign result used by bcdec and #6175. The Khronos §20.2 pseudocode restores the sign before that final zero check and differs on the exact-zero-sign case. Synthetic fixtures only, CPU, AI-assisted.

我在临时组合 #6120 a5749761 和 #6175 41afa94e 后重验了最初发现的端点问题。我解决了两处冲突,保留了两个 PR 的测试,并在 #6120 的完整有符号范围上应用了仅为非零幅值恢复符号的判断。Windows 上 80 项纹理池测试全部通过。

我还重跑了 MSVC 编译的独立 bcdec 80859ed 对照。14 种有效模式各生成 1,024 个固定种子的块,四个保留编码各生成 16 个块。UF16 和 SF16 共 28,800 次解码,每次的 48 个半精度字全部一致。这个结果与 bcdec 和 #6175 采用的 Microsoft 零符号规则一致。Khronos 第 20.2 节的伪代码在该处直接恢复原符号,因此在精确零的符号上有差异。仅用 CPU 和合成输入,AI 辅助。

@Kev-Ball

Copy link
Copy Markdown

Verified the minimum endpoint and interpolation on an RTX 3080 Ti, CachyOS, NVIDIA 620.73.04. I uploaded the two synthetic mode-14 blocks as GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, fetched every texel with a compute shader, and read back floatBitsToUint through a storage buffer. This exercises the GPU’s texture decoder and preserves the sign of zeros and infinities.

  • For the original constant minimum-endpoint block, all 16 red texels were negative infinity (half-word 0xfc00). The parent disagreed on all 16; a5749761 matched every RGB component.
  • For the PR’s block exercising all 16 weights, the parent disagreed on 8 red and 16 green components. The PR matched all 48 components, including both red negative infinities and the finite steps through 0xfbf9.

I also tried a separate constant red endpoint of −1. Its GPU result was positive zero on all 32 texels tested; this PR’s CPU result was negative zero. That independently reproduces the distinct case tracked by #6175. Synthetic inputs only, AI-assisted.

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.

6 participants