Shaders: accept inline constants in V_PK_FMAC_F16 #3148

Open
github-bot wants to merge 2 commits from github-bot/gh-3148 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:23 UTC · original
andrewpozdnakov7-jpg:fix/pk-fmac-f16-constants → main · +61 −4 · 2 files · 2 commits · open

Merge #2884 before #3148. The nearest-even packed FMA lowering in #2884 covers the infinite-multiplier case observed by Steven on the RTX 5080 and app-local WARP 1.0.22. With that dependency, Steven reported 360/360 results on each of three adapters. Adapter results

The PR now includes Steven's original test commit 7510c12 for representative inline encodings, finite and infinite multipliers, and a register control. The local combination with #2884 at 64c62d5 passed all three packed FMAC tests, the packed single-rounding test, and 37 VALU tests on app-local WARP 1.0.22 with DXIL validation. The five-encoding fixture also passed in three fresh local WARP runs on the test commit alone.

Please retain Steven's Git authorship for the regression test. If folding it into a different commit, use Co-authored-by: steven-seagull27 <[email protected]>.

V_PK_FMAC_F16 fails to lower when SRC0 is an inline constant. Use the existing GFX10 FP16 operand decoder, which places inline FP16 constants in the low half with zero in the high half. LLVM AMDGPU encoding. The inline-float case was also noted in #1136.

The synthetic VOP2 fixture returns Unsupported on main. With the change, it checks both output halves on WARP for inline 0.5, -4.0, and integer zero. The register-source control and all 36 VALU tests passed on WARP. Strict shader Clippy and the asset policy passed.

AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If folded into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 10:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3148) `andrewpozdnakov7-jpg:fix/pk-fmac-f16-constants` → `main` · +61 −4 · 2 files · 2 commits · open **Merge #2884 before #3148.** The nearest-even packed FMA lowering in #2884 covers the infinite-multiplier case observed by Steven on the RTX 5080 and app-local WARP 1.0.22. With that dependency, Steven reported 360/360 results on each of three adapters. [Adapter results](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3148) The PR now includes Steven's original test commit `7510c12` for representative inline encodings, finite and infinite multipliers, and a register control. The local combination with #2884 at `64c62d5` passed all three packed FMAC tests, the packed single-rounding test, and 37 VALU tests on app-local WARP 1.0.22 with DXIL validation. The five-encoding fixture also passed in three fresh local WARP runs on the test commit alone. Please retain Steven's Git authorship for the regression test. If folding it into a different commit, use `Co-authored-by: steven-seagull27 <242719754+[email protected]>`. `V_PK_FMAC_F16` fails to lower when SRC0 is an inline constant. Use the existing GFX10 FP16 operand decoder, which places inline FP16 constants in the low half with zero in the high half. [LLVM AMDGPU encoding](https://llvm.org/docs/doxygen/AMDGPUBaseInfo_8cpp_source.html#l03106). The inline-float case was also noted in #1136. The synthetic VOP2 fixture returns `Unsupported` on main. With the change, it checks both output halves on WARP for inline 0.5, -4.0, and integer zero. The register-source control and all 36 VALU tests passed on WARP. Strict shader Clippy and the asset policy passed. AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If folded into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:44 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:28 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib packed_fmac_accepts_inline_constants -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean fix allowing inline constants in V_PK_FMAC_F16.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 10:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3148#pullrequestreview-6072427302) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib packed_fmac_accepts_inline_constants -- --test-threads=1`: passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Clean fix allowing inline constants in `V_PK_FMAC_F16`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 10:41 UTC · original

I confirmed the three existing packed-FMAC inline cases on an RTX 5080, Windows WARP, and WARP 1.0.22. That agrees with the RTX 5090 review. I also found one case where the inline and register forms give different answers on this head (c95fa3b).

I tested all 90 inline encodings with a finite and an infinite high-half multiplier, reading both halves of each packed word. The register control loaded the same 32-bit pattern at run time. Each column counts mismatched halves out of 360. NaNs were compared by class, so different NaN signs or payloads pass.

Adapter Inline on #3148 Register on #3148 Inline with #2884’s packed-FMA change added
RTX 5080, driver 621.40 74 0 0
Windows WARP 10.0.26100.10068 0 0 0
App-local WARP 1.0.22 74 0 0

All 74 differences were in the high half: the 65 nonnegative integer encodings and nine floating-point encodings contributed +0 there. With an infinite multiplier and a +1 accumulator, those cases returned +1 where 0 × ∞ + 1 should produce a NaN. For example, with inline integer 1 (src0=129), multiplier 0x7c006400, and accumulator 0x3c000000, the RTX 5080 read 0x3c000400 inline and 0x7fff0400 from the register. The low halves and every finite-multiplier control matched on all three adapters. The parent (63bcca4) refused all 90 inline programs during translation, while the register control passed on all three.

I applied only the packed-FMA lowering change from #2884 at 64c62d5 on top of this head. Both source forms then matched all 360 half results on each adapter. That gives the two PRs a concrete shared test for round-to-nearest-even.

The test-only commit keeps five representative encodings, both multipliers, and the same-bit register control. To apply it on this PR and reproduce:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3148-packed-inline-coverage
git cherry-pick 7510c1286abe5da4041b60be1c64746e69e2beb1
cargo test --locked -p victory-shader --lib packed_fmac_ -- --test-threads=1 --nocapture

These are synthetic shader readbacks. AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-26 10:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3148#issuecomment-7189703496) I confirmed the three existing packed-FMAC inline cases on an RTX 5080, Windows WARP, and WARP 1.0.22. That agrees with the [RTX 5090 review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3148). I also found one case where the inline and register forms give different answers on this head (`c95fa3b`). I tested all 90 inline encodings with a finite and an infinite high-half multiplier, reading both halves of each packed word. The register control loaded the same 32-bit pattern at run time. Each column counts mismatched halves out of 360. NaNs were compared by class, so different NaN signs or payloads pass. | Adapter | Inline on #3148 | Register on #3148 | Inline with #2884’s packed-FMA change added | |---|---:|---:|---:| | RTX 5080, driver 621.40 | 74 | 0 | 0 | | Windows WARP 10.0.26100.10068 | 0 | 0 | 0 | | App-local WARP 1.0.22 | 74 | 0 | 0 | All 74 differences were in the high half: the 65 nonnegative integer encodings and nine floating-point encodings contributed `+0` there. With an infinite multiplier and a `+1` accumulator, those cases returned `+1` where `0 × ∞ + 1` should produce a NaN. For example, with inline integer `1` (`src0=129`), multiplier `0x7c006400`, and accumulator `0x3c000000`, the RTX 5080 read `0x3c000400` inline and `0x7fff0400` from the register. The low halves and every finite-multiplier control matched on all three adapters. The parent (`63bcca4`) refused all 90 inline programs during translation, while the register control passed on all three. I applied only the packed-FMA lowering change from [#2884 at `64c62d5`](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2884) on top of this head. Both source forms then matched all 360 half results on each adapter. That gives the two PRs a concrete shared test for round-to-nearest-even. The [test-only commit](https://github.com/steven-seagull27/VIctory/commit/7510c1286abe5da4041b60be1c64746e69e2beb1) keeps five representative encodings, both multipliers, and the same-bit register control. To apply it on this PR and reproduce: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3148-packed-inline-coverage git cherry-pick 7510c1286abe5da4041b60be1c64746e69e2beb1 cargo test --locked -p victory-shader --lib packed_fmac_ -- --test-threads=1 --nocapture ``` These are synthetic shader readbacks. AI-assisted with Codex.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 11:44 UTC · original

Thanks, @⁠steven-seagull27. I added your original test commit 7510c12 with its Git authorship intact. On app-local WARP 1.0.22 with DXIL validation, the local combination with #2884 at 64c62d5 passed the three packed FMAC tests, the packed single-rounding test, and all 37 VALU tests. The smaller five-encoding fixture also passed in three fresh local WARP runs on the test commit alone. The 360-result matrix on each adapter is from your report.

Please merge #2884 before #3148. If folding the regression test into another commit, please retain Co-authored-by: steven-seagull27 <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 11:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3148#issuecomment-7191107781) Thanks, @⁠steven-seagull27. I added your original test commit `7510c12` with its Git authorship intact. On app-local WARP 1.0.22 with DXIL validation, the local combination with #2884 at `64c62d5` passed the three packed FMAC tests, the packed single-rounding test, and all 37 VALU tests. The smaller five-encoding fixture also passed in three fresh local WARP runs on the test commit alone. The 360-result matrix on each adapter is from your report. Please merge #2884 before #3148. If folding the regression test into another commit, please retain `Co-authored-by: steven-seagull27 <242719754+[email protected]>`.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-26 17:21 UTC · original

Checked 7510c12 on RDNA2 hardware, for all 90 inline encodings of SRC0 in VOP2 v_pk_fmac_f16. I also checked it merged together with #2884 (64c62d5).

What the hardware puts in the high half of an inline constant. I read each half as constant × 1.0 + -0:

  • Inline integers are the sign-extended 32-bit value.
    • 1..64 give 0x00000001..0x00000040, so the high half is 0.
    • -1..-16 give 0xffffffff..0xfffffff0, so the high half is 0xffff, which is a NaN.
  • Inline floats (240..248) are the f16 bits in the low half, with 0 in the high half. For example, 0.5 is 0x00003800, -4.0 is 0x0000c400, and 1/(2π) is 0x00003118.

That is what f16_operand gives.

Setup.

  • Hardware: Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs 4 encodings per kernel, with the accumulator in a VGPR. There are 16 multiplier/accumulator rows:
    • ±1, 1024, 2 and ±inf multipliers;
    • -0 and +0 accumulators;
    • random values.
  • Translator: the same words through a local copy of the build_valu_cs harness (a local test, not part of this PR). I ran it on main 63bcca4, on the PR merged onto it, and on #2884 + this PR. Each ran on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in hardware_adapter).

Both halves of each word are compared as f16, which gives 1,440 results.

Host branch matches the hardware bit for bit NaN with a different payload other differences refused
Radeon gfx1036 main 0 0 0 1,440 (a constant operand of v_pk_fmac_f16)
Radeon gfx1036 #3148 1,218 0 222 0
Radeon gfx1036 #2884 + #3148 1,440 0 0 0
RTX 5080 main 0 0 0 1,440
RTX 5080 #3148 962 256 222 0
RTX 5080 #2884 + #3148 1,110 330 0 0
  • This PR on its own: all 222 differences come from the f32 FMad path, and both GPUs give the same ones:

    • +0 × x + -0 comes out -0 where the hardware gives +0 (148 results). Example: code 242 (1.0), multiplier 1.0, accumulator -0. The high half is 0x8000 here and 0x0000 on the hardware.
    • 0 × inf + 1 comes out 1.0 where the hardware gives a NaN (74 results).

    The same values loaded from a register match on every branch, so this happens because the constant's high half is a compile-time 0.

  • With #2884: every result matches the hardware bit for bit on the Radeon. On the 5080 only NaN payloads differ.

So the merge order in your description is right: #2884 first, then this PR.

No game data was used.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.

**@⁠Lyrnc** on GitHub · 2026-11-26 17:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/3148#issuecomment-7198884706) Checked `7510c12` on RDNA2 hardware, for all 90 inline encodings of SRC0 in VOP2 `v_pk_fmac_f16`. I also checked it merged together with #2884 (`64c62d5`). **What the hardware puts in the high half of an inline constant.** I read each half as `constant × 1.0 + -0`: - **Inline integers** are the sign-extended 32-bit value. - 1..64 give `0x00000001`..`0x00000040`, so the high half is 0. - -1..-16 give `0xffffffff`..`0xfffffff0`, so the high half is `0xffff`, which is a NaN. - **Inline floats** (240..248) are the f16 bits in the low half, with 0 in the high half. For example, 0.5 is `0x00003800`, -4.0 is `0x0000c400`, and 1/(2π) is `0x00003118`. That is what `f16_operand` gives. **Setup.** - **Hardware:** Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs 4 encodings per kernel, with the accumulator in a VGPR. There are 16 multiplier/accumulator rows: - ±1, 1024, 2 and ±inf multipliers; - -0 and +0 accumulators; - random values. - **Translator:** the same words through a local copy of the `build_valu_cs` harness (a local test, not part of this PR). I ran it on `main` 63bcca4, on the PR merged onto it, and on #2884 + this PR. Each ran on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in `hardware_adapter`). Both halves of each word are compared as f16, which gives 1,440 results. | Host | branch | matches the hardware bit for bit | NaN with a different payload | other differences | refused | |---|---|---|---|---|---| | Radeon gfx1036 | main | 0 | 0 | 0 | 1,440 (`a constant operand of v_pk_fmac_f16`) | | Radeon gfx1036 | #3148 | 1,218 | 0 | 222 | 0 | | Radeon gfx1036 | #2884 + #3148 | 1,440 | 0 | **0** | 0 | | RTX 5080 | main | 0 | 0 | 0 | 1,440 | | RTX 5080 | #3148 | 962 | 256 | 222 | 0 | | RTX 5080 | #2884 + #3148 | 1,110 | 330 | **0** | 0 | - **This PR on its own:** all 222 differences come from the f32 `FMad` path, and both GPUs give the same ones: - `+0 × x + -0` comes out `-0` where the hardware gives `+0` (148 results). Example: code 242 (1.0), multiplier 1.0, accumulator -0. The high half is `0x8000` here and `0x0000` on the hardware. - `0 × inf + 1` comes out `1.0` where the hardware gives a NaN (74 results). The same values loaded from a register match on every branch, so this happens because the constant's high half is a compile-time 0. - **With #2884:** every result matches the hardware bit for bit on the Radeon. On the 5080 only NaN payloads differ. So the merge order in your description is right: #2884 first, then this PR. No game data was used. AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3148/head:github-bot/gh-3148'
git switch 'github-bot/gh-3148'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3148'
git switch 'github-bot/gh-3148'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3148'
git switch 'github-bot/gh-3148'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3148'
git switch 'main'
git merge --squash 'github-bot/gh-3148'
git switch 'main'
git merge --ff-only 'github-bot/gh-3148'
git switch 'main'
git merge 'github-bot/gh-3148'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/Marvisak--VIctory!3148
No description provided.