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

Merged
FIocker merged 1 commit from upstream-pr/2387 into main 2026-11-30 14:12:03 +00:00
FIocker commented 2026-11-29 12:36:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by FIocker on 2026-11-29T12:36:52Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550768889 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387). Originally posted by [FIocker](https://github.com/FIocker) on 2026-11-29T12:36:52Z. --- 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)
Dukestar69 commented 2026-11-29 12:49:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-29T12:49:53Z.

Review: APPROVED


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6102943795 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387#pullrequestreview-6102943795). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-29T12:49:53Z. **Review:** APPROVED --- 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).
Lyrnc commented 2026-11-30 06:11:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T06:11:22Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7270393618 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2387#issuecomment-7270393618). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T06:11:22Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!2387
No description provided.