Skip to content

upscale: state the accuracy contract on low-contrast input; test holds well-conditioned samples to ErrorBound - #152

Merged
tannevaled merged 1 commit into
mainfrom
fix/upscale-lowcontrast
Nov 29, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix/upscale-lowcontrast

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Refs #141 (item 1 of "What is not established").

Cause

Not an arithmetic defect: the conditioning of EASU's edge analysis. For each bilinear corner, lenX = sat(|d-b| * rcp(max(|d-c|, |c-b|))) on three neighbouring lumas. Where different colours share a luma (about 13 luma values on 3-level noise) the denominator and the numerator are both zero in exact arithmetic: 0/0, with no answer defined by ffx_fsr1.h. A precision answers with rounding noise: the oracle sees the float32 colours in float64 (a tie is 7.45e-9 from zero), the float32 path rounds the same luma to exactly 0 or to 6e-8. Worst case found: edge strength 0 against 0.94, which reshapes the kernel; EASU's clamp bounds the output change by the range of the four nearest colours.

Found by locating the divergence (dir identical to 6 digits, ln 1.05 against 1.88, then per corner), then confirming by classification: 42 228 of 1.17 M samples have such a neighbourhood and hold all 10 394 outliers; the other 1 130 097 are within 3.4e-5.

Bisect

Same probe on v0.21.0, v0.22.0, v0.23.0, v0.24.0, v0.25.0, scalar and GOEXPERIMENT=simd: worst 4.67e-3 and 11 208 to 11 211 samples outside on every one (10 394 at v0.25.0 after the integer phase fix). Present since the package began; not introduced by the vector kernels, the Scaler or the AVX-512 gather. Worker count does not enter (bytes identical across counts). The Vulkan/Metal module is not merged, so not probed.

Change

No code change: the bound is restated, because removing the ambiguity would add a flush to every vector kernel (and shader) and deviate from the reference where it is itself undefined. TestOracleLowContrast now asserts: every well-conditioned sample within ErrorBound; any sample within ErrorBound of the range of its four nearest colours; and that the corpus still exercises degenerate samples. Doc comment and README updated.

Regression value: changing ln *= 0.5 to 0.49 passes the old test (worst 4.8e-3 under its 1.2e-2 local range, 1.4 % under 3 %) and fails the new one (6 810 well-conditioned samples outside, worst 6.0e-4).

go test ./upscale/... green with and without GOEXPERIMENT=simd; gofmt -l empty.

🤖 Generated with Claude Code

…st that holds the well-conditioned part to ErrorBound

TestOracleLowContrast left 0.9 % of samples outside ErrorBound (up to 4.7e-3)
with the cause "not established". It is the conditioning of EASU's edge
analysis: lenX = sat(|d-b| * rcp(max(|d-c|, |c-b|))) is 0/0 where three
different colours share a luma, and the reference defines no answer there.
The oracle sees the float32 colours in float64 (a tie is 7e-9 from zero); the
float32 path rounds the same luma to exactly 0 or 6e-8. Each reports an edge
strength anywhere in [0,1] and the kernel reshapes. Present since v0.21.0, on
the scalar and the vector paths alike.

The test now classifies each sample: every well-conditioned sample (1.13
million, worst 3.4e-5) is within ErrorBound, and any sample is within
ErrorBound of the range of its four nearest colours. Breaking the arithmetic
(ln scale 0.5 to 0.49) fails the new test and passed the old one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit ac21ef7 into main Nov 29, 2026
24 checks passed
@tannevaled
tannevaled deleted the fix/upscale-lowcontrast branch November 29, 2026 18:56
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