[GH-ISSUE #476] Verified FidelityFX CAS PC replacements: 8 fp32 variants, bit-exact golden model (ffx-kit) #7

Open
opened 2026-11-26 20:13:58 +01:00 by 4ld0 · 1 comment
Owner

Originally created by @Cobrall on GitHub (Nov 24, 2026).
Original GitHub issue: https://github.com/ubiquitarianism/leonida/issues/476

Title: Verified FidelityFX CAS PC replacements: 8 fp32 variants, bit-exact golden model (ffx-kit)

Hi! We built a small verification kit that may help with the FidelityFX side of the shader pipeline.

What it does:

  • Compiles official AMD FidelityFX-CAS sources (MIT) with DXC to SPIR-V.
  • Runs them on a real GPU via Vulkan (wgpu-py).
  • Verifies every output against a CPU golden model that mirrors AMD's exact arithmetic:
    APrxLoRcpF1 / APrxMedRcpF1 / APrxLoSqrtF1 bit tricks, the green-channel weight path,
    and D3D saturate(NaN)=0 semantics.

Results (2026-11-24, RTX 4070 Ti, Vulkan, DXC 1.9.2609.5):

  • 8/8 fp32 sharpen-only variants (CAS_BETTER_DIAGONALS x CAS_GO_SLOWER x CAS_SLOW): PASS
  • 144 matrix tests + 3840x2160: worst max abs diff 4.77e-07 (a few fp32 ULPs)
  • manifest.json with per-variant SHA-256 and per-test diffs

Why this may matter: a naive "mathematically correct" reference disagrees with AMD's
fast-math paths by up to ~8.5% of signal, so checking translated FidelityFX output against
exact math produces false failures. This kit reproduces the intended approximations.

Scope / honesty:

  • fp32 sharpen-only today; fp16 packed (CasFilterH) and scaling next.
  • No game files, keys or console binaries - only official open sources.
  • Verified on one GPU so far; reproduction is 4 commands in the README.

Repo: https://github.com/Cobrall/ffx-kit
Happy to adapt the harness to Leonida's pipeline or open PRs if useful.

Originally created by @Cobrall on GitHub (Nov 24, 2026). Original GitHub issue: https://github.com/ubiquitarianism/leonida/issues/476 Title: Verified FidelityFX CAS PC replacements: 8 fp32 variants, bit-exact golden model (ffx-kit) Hi! We built a small verification kit that may help with the FidelityFX side of the shader pipeline. What it does: - Compiles official AMD FidelityFX-CAS sources (MIT) with DXC to SPIR-V. - Runs them on a real GPU via Vulkan (wgpu-py). - Verifies every output against a CPU golden model that mirrors AMD's exact arithmetic: APrxLoRcpF1 / APrxMedRcpF1 / APrxLoSqrtF1 bit tricks, the green-channel weight path, and D3D saturate(NaN)=0 semantics. Results (2026-11-24, RTX 4070 Ti, Vulkan, DXC 1.9.2609.5): - 8/8 fp32 sharpen-only variants (CAS_BETTER_DIAGONALS x CAS_GO_SLOWER x CAS_SLOW): PASS - 144 matrix tests + 3840x2160: worst max abs diff 4.77e-07 (a few fp32 ULPs) - manifest.json with per-variant SHA-256 and per-test diffs Why this may matter: a naive "mathematically correct" reference disagrees with AMD's fast-math paths by up to ~8.5% of signal, so checking translated FidelityFX output against exact math produces false failures. This kit reproduces the intended approximations. Scope / honesty: - fp32 sharpen-only today; fp16 packed (CasFilterH) and scaling next. - No game files, keys or console binaries - only official open sources. - Verified on one GPU so far; reproduction is 4 commands in the README. Repo: https://github.com/Cobrall/ffx-kit Happy to adapt the harness to Leonida's pipeline or open PRs if useful.
Author
Owner

@Cobrall commented on GitHub (Nov 24, 2026):

Hi team,

Following up on the shader pipeline: I've built and open-sourced a GPU-verified FidelityFX CAS harness: github.com/Cobrall/ffx-kit

What it does:

  • Compiles official AMD ffx_cas.h via DXC to SPIR-V.
  • Runs it on a real GPU (Vulkan/wgpu) and verifies the output against a CPU golden model.
  • The CPU model exactly mirrors AMD's fast-math approximations (APrxLoRcpF1, APrxMedRcpF1, APrxLoSqrtF1 bit tricks, green-channel weighting, D3D saturate rules).

Results:

  • 8/8 fp32 variants (BETTER_DIAGONALS × GO_SLOWER × SLOW) PASS with worst max diff of 4.77e-07 (a few ULPs).
  • 4K (3840x2160) pass in ~240ms full cycle.
  • manifest.json includes SHA-256 hashes for every compiled .spv.

Why this matters:
A naive "mathematically exact" CPU reference will disagree with AMD's intended output by up to ~8.5% of the signal due to these fast-math paths. This kit provides the correct reference to validate against, preventing false failures when porting.

Note on fp16: The repo includes the CasFilterH (fp16 packed) HLSL and Python golden model. Automated fp16 GPU verification is noted as limited in the README due to wgpu SPIR-V RelaxedPrecision quirks on Windows, but the HLSL is ready for direct integration into a native C++/Vulkan runtime like Leonida's.

Happy to help adapt this harness to Leonida's CI or answer any questions about the bit-exact golden model!

<!-- gh-comment-id:7124463269 --> @Cobrall commented on GitHub (Nov 24, 2026): Hi team, Following up on the shader pipeline: I've built and open-sourced a GPU-verified FidelityFX CAS harness: **github.com/Cobrall/ffx-kit** **What it does:** - Compiles official AMD `ffx_cas.h` via DXC to SPIR-V. - Runs it on a real GPU (Vulkan/wgpu) and verifies the output against a CPU golden model. - The CPU model exactly mirrors AMD's fast-math approximations (`APrxLoRcpF1`, `APrxMedRcpF1`, `APrxLoSqrtF1` bit tricks, green-channel weighting, D3D `saturate` rules). **Results:** - 8/8 fp32 variants (BETTER_DIAGONALS × GO_SLOWER × SLOW) **PASS** with worst max diff of `4.77e-07` (a few ULPs). - 4K (3840x2160) pass in ~240ms full cycle. - `manifest.json` includes SHA-256 hashes for every compiled `.spv`. **Why this matters:** A naive "mathematically exact" CPU reference will disagree with AMD's intended output by up to ~8.5% of the signal due to these fast-math paths. This kit provides the *correct* reference to validate against, preventing false failures when porting. **Note on fp16:** The repo includes the `CasFilterH` (fp16 packed) HLSL and Python golden model. Automated fp16 GPU verification is noted as limited in the README due to `wgpu` SPIR-V `RelaxedPrecision` quirks on Windows, but the HLSL is ready for direct integration into a native C++/Vulkan runtime like Leonida's. Happy to help adapt this harness to Leonida's CI or answer any questions about the bit-exact golden model!
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#7
No description provided.