shader: v_fmac/v_mac's accumulator takes its VOP3 abs/neg bits; a level query reads no array slice #2387

Manually merged
github merged 1 commit from github-bot/gh-2387 into main 2026-11-30 14:15:41 +00:00 AGit
Owner

@⁠FIocker on GitHub · 2026-11-29 12:36 UTC · original
FIocker:contrib/fmac-acc-mods-lod-slice → main · +16 −2 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Two translator fixes in emit/lower.rs:

  1. v_fmac / v_mac in VOP3 form. The accumulator is source 2, but its abs and neg bits (bit 2 of each field) were dropped, so the sign is wrong wherever the title sets them. They are now applied to the accumulator. After SmokinDoinkV1 (GPL-3.0).
  2. Level query (image_get_lod, op 81) on arrays. The query read the array slice coordinate too. The title may leave that register unwritten, and DXIL wants it undefined, so array level queries failed validation. Only the spatial coordinates are read now. After coasting (GPL-3.0).

Checked: workspace check clean; victory-shader lib tests 462 passed (release, together with the two other open translator/HLE fixes from this account). Also played in our local fork since 2026-11-28 with no regressions seen.

🤖 Generated with Claude Code

**@⁠FIocker** on GitHub · 2026-11-29 12:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387) `FIocker:contrib/fmac-acc-mods-lod-slice` → `main` · +16 −2 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC Two translator fixes in `emit/lower.rs`: 1. **v_fmac / v_mac in VOP3 form.** The accumulator is source 2, but its `abs` and `neg` bits (bit 2 of each field) were dropped, so the sign is wrong wherever the title sets them. They are now applied to the accumulator. After SmokinDoinkV1 (GPL-3.0). 2. **Level query (image_get_lod, op 81) on arrays.** The query read the array slice coordinate too. The title may leave that register unwritten, and DXIL wants it undefined, so array level queries failed validation. Only the spatial coordinates are read now. After coasting (GPL-3.0). Checked: workspace check clean; `victory-shader` lib tests 462 passed (release, together with the two other open translator/HLE fixes from this account). Also played in our local fork since 2026-11-28 with no regressions seen. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In the VOP3 form the accumulator of v_fmac_f32/v_mac_f32/v_mac_legacy_f32
is source 2, and its abs and neg bits apply to it: they were dropped, a
sign wrong wherever the title sets them (after SmokinDoinkV1, GPL-3.0; its
fused legacy MAD is not taken). image_get_lod on arrays read the slice
coordinate into calculateLOD, which failed validation; it reads the
spatial ones only (after coasting, GPL-3.0). victory-shader tests 299 ok;
run x1 (cold, 3495 translated): no refusal, no panic, flicker 0.33.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit d1c928788e9a8658d898bd3f8b05017b4e363b39)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 12:38:08 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 12:49 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean 18-line merge in crates/victory-shader/src/emit/lower.rs.
  • Tests (RTX 5090):
    • cargo test -p victory-shader --lib emit::tests:: passed (26 passed; 0 failed; 1 ignored).
    • cargo test -p victory-shader --lib emit::lower::tests:: passed (25 passed; 0 failed; 1 ignored).
  • 0 new warnings.

Clean RDNA2 VOP3 abs/neg accumulator handling for v_fmac/v_mac and level-query array-slice fix. LGTM.

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

**@⁠Dukestar69** on GitHub · 2026-11-29 12:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387#pullrequestreview-6102943795) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean 18-line merge in `crates/victory-shader/src/emit/lower.rs`. - **Tests (RTX 5090)**: - `cargo test -p victory-shader --lib emit::tests::` passed (`26 passed; 0 failed; 1 ignored`). - `cargo test -p victory-shader --lib emit::lower::tests::` passed (`25 passed; 0 failed; 1 ignored`). - 0 new warnings. Clean RDNA2 VOP3 `abs`/`neg` accumulator handling for `v_fmac`/`v_mac` and level-query array-slice fix. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-30 06:11 UTC · original

Checked the v_fmac_f32 half of this against a Radeon gfx1036 (RDNA 2) running the same kernel natively, and ran the translator's output for main and for this PR on an RTX 5080 and on that Radeon through D3D12. The level-query half (image op == 81) is not covered here.

Setup

  • main at 41adb551 with this PR's head (1799baa) merged locally, no conflict. The victory-shader test binary was built from that merged tree (own tree and target directory).
  • Kernel: hand-written GFX10 code, nothing from a title. Wave32, a 64-thread group (two waves); outputs v10.. stored per lane. The VOP3 v_fmac_f32 forms are raw encodings (opcode 0x12B, the src2 field 0, abs / neg bit 2 set for the accumulator).
  • Hardware rows: the same machine code dispatched natively on the gfx1036, MODE IEEE on with f32 denormals kept, and once more with IEEE off and denormals flushed: both give the same values.
  • Host runs: super::emit (32-lane host), dxil.dll validation, dispatched on the 5080 and on the Radeon (VICTORY_ADAPTER=radeon).

Case fmac_src2_mods: a in {1, 2, -1, 0.5}, b in {3, -5, 0.25, 7.5, 1e-3, -2, 100, 0}, the accumulator c in {1, -1, 4, -4, 0, -0, 10, -0.125}, mixed over the 64 lanes. Outputs (vdst holds c before each):

out modifiers gfx1036 computes
v10 none a*b + c
v11 neg bit 2 a*b - c
v12 abs bit 2 a*b + abs(c)
v13 abs and neg bit 2 a*b - abs(c)
v14 neg bit 0 -a*b + c
v15 neg bits 0, 2 -a*b - c
v16 abs bits 1, 2, neg bit 2 a*abs(b) - abs(c)
v17 abs bit 0, neg bit 2 abs(a)*b - c

The hardware column matches that formula in all 512 values, signed zeros included: the accumulator does take the VOP3 abs / neg bits 2.

Results (values that differ from the gfx1036, out of 64 lanes x 8 outputs)

output main, 5080 main, Radeon this PR, 5080 this PR, Radeon
v10 none exact exact exact exact
v11 neg bit 2 48 48 exact exact
v12 abs bit 2 24 24 exact exact
v13 abs + neg bit 2 24 24 exact exact
v14 neg bit 0 exact exact exact exact
v15 neg bits 0, 2 50 50 exact exact
v16 abs bits 1, 2 + neg bit 2 24 24 exact exact
v17 abs bit 0 + neg bit 2 48 48 exact exact

Main drops the accumulator's bits on both cards (the same values on each), every lane where they change the result: lane 0 (a = 1, b = 3, c = 1) gives v11 = 4.0 where the gfx1036 gives 2.0, v15 = -2.0 where it gives -4.0; lane 3 (a = 0.5, b = 3, c = -0.125) gives v12 = 1.375 where it gives 1.625. The bits on sources 0 and 1 were already applied.

Verdict: correct for v_fmac_f32: all 512 values exact on both cards, signed zeros included (2 of the results are -0, 22 are +0). The other wave32 cases in the run give the same values as main.

Not covered: v_mac_f32 (the same code path in this PR, no case here) and the level-query change.

AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.

**@⁠Lyrnc** on GitHub · 2026-11-30 06:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387#issuecomment-7270393618) Checked the `v_fmac_f32` half of this against a Radeon gfx1036 (RDNA 2) running the same kernel natively, and ran the translator's output for main and for this PR on an RTX 5080 and on that Radeon through D3D12. The level-query half (image `op == 81`) is not covered here. **Setup** - `main` at 41adb551 with this PR's head (1799baa) merged locally, no conflict. The victory-shader test binary was built from that merged tree (own tree and target directory). - Kernel: hand-written GFX10 code, nothing from a title. Wave32, a 64-thread group (two waves); outputs v10.. stored per lane. The VOP3 `v_fmac_f32` forms are raw encodings (opcode 0x12B, the src2 field 0, `abs` / `neg` bit 2 set for the accumulator). - Hardware rows: the same machine code dispatched natively on the gfx1036, MODE IEEE on with f32 denormals kept, and once more with IEEE off and denormals flushed: both give the same values. - Host runs: `super::emit` (32-lane host), `dxil.dll` validation, dispatched on the 5080 and on the Radeon (`VICTORY_ADAPTER=radeon`). **Case** `fmac_src2_mods`: a in {1, 2, -1, 0.5}, b in {3, -5, 0.25, 7.5, 1e-3, -2, 100, 0}, the accumulator c in {1, -1, 4, -4, 0, -0, 10, -0.125}, mixed over the 64 lanes. Outputs (vdst holds c before each): | out | modifiers | gfx1036 computes | |---|---|---| | v10 | none | a*b + c | | v11 | neg bit 2 | a*b - c | | v12 | abs bit 2 | a*b + abs(c) | | v13 | abs and neg bit 2 | a*b - abs(c) | | v14 | neg bit 0 | -a*b + c | | v15 | neg bits 0, 2 | -a*b - c | | v16 | abs bits 1, 2, neg bit 2 | a*abs(b) - abs(c) | | v17 | abs bit 0, neg bit 2 | abs(a)*b - c | The hardware column matches that formula in all 512 values, signed zeros included: the accumulator does take the VOP3 `abs` / `neg` bits 2. **Results** (values that differ from the gfx1036, out of 64 lanes x 8 outputs) | output | main, 5080 | main, Radeon | this PR, 5080 | this PR, Radeon | |---|---|---|---|---| | v10 none | exact | exact | exact | exact | | v11 neg bit 2 | 48 | 48 | exact | exact | | v12 abs bit 2 | 24 | 24 | exact | exact | | v13 abs + neg bit 2 | 24 | 24 | exact | exact | | v14 neg bit 0 | exact | exact | exact | exact | | v15 neg bits 0, 2 | 50 | 50 | exact | exact | | v16 abs bits 1, 2 + neg bit 2 | 24 | 24 | exact | exact | | v17 abs bit 0 + neg bit 2 | 48 | 48 | exact | exact | Main drops the accumulator's bits on both cards (the same values on each), every lane where they change the result: lane 0 (a = 1, b = 3, c = 1) gives v11 = 4.0 where the gfx1036 gives 2.0, v15 = -2.0 where it gives -4.0; lane 3 (a = 0.5, b = 3, c = -0.125) gives v12 = 1.375 where it gives 1.625. The bits on sources 0 and 1 were already applied. **Verdict: correct** for `v_fmac_f32`: all 512 values exact on both cards, signed zeros included (2 of the results are -0, 22 are +0). The other wave32 cases in the run give the same values as main. Not covered: `v_mac_f32` (the same code path in this PR, no case here) and the level-query change. AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.
github manually merged commit 2bbbccdad3 into main 2026-11-30 14:15:41 +00:00
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/trustno1-coder--VIctory-NVIDIA!2387
No description provided.