Shaders: lower v_cvt_off_f32_i4 #1391

Merged
AnoHunted merged 1 commit from upstream-pr/1391 into main 2026-11-25 00:22:34 +00:00
AnoHunted commented 2026-11-24 17:41:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AnoHunted on 2026-11-24T17:41:18Z.


What

Lowers the VOP1 v_cvt_off_f32_i4. The opcode was already decoded but had no lowering arm, so it fell through to the integer path and the shader failed to lower. It now sign-extends the low four bits of src0 (shift left 28, arithmetic shift right 28), converts to f32 and multiplies by 1/16. Bits above the low nibble are ignored. All sixteen results (-0.5 to 0.4375 in steps of 0.0625) are exact in f32.

Why

Per the RDNA 2 ISA, D.f32 = signext(S0.i[3:0]) / 16.0. Without a lowering any shader using it is rejected. Earlier attempts (#163, closed unmerged, and the test-merge draft #231) contained this op but it is not on main; this is a small standalone change with a test.

Tested

Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, and WARP.

  • cargo test -p victory-shader --features host cvt_off -- --test-threads=1: new test v_cvt_off_f32_i4_uses_the_signed_low_nibble passes (all 16 nibble values plus inputs with junk in the upper bits, e.g. 0xABCDEF05 -> 0.3125; f32 bit patterns compared exactly; run on the GPU and on WARP, DXIL validated).
  • cargo test -p victory-shader --features host -- --test-threads=1, main vs this branch: main 120 passed, 0 failed, 1 ignored; branch 121 passed, 0 failed, 1 ignored.

Not tested

AMD hardware. Real RDNA2 output of this opcode was not compared; the reference is the ISA documentation.

No game files were used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587838378 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1391). Originally posted by [AnoHunted](https://github.com/AnoHunted) on 2026-11-24T17:41:18Z. --- ## What Lowers the VOP1 `v_cvt_off_f32_i4`. The opcode was already decoded but had no lowering arm, so it fell through to the integer path and the shader failed to lower. It now sign-extends the low four bits of src0 (shift left 28, arithmetic shift right 28), converts to f32 and multiplies by 1/16. Bits above the low nibble are ignored. All sixteen results (-0.5 to 0.4375 in steps of 0.0625) are exact in f32. ## Why Per the RDNA 2 ISA, `D.f32 = signext(S0.i[3:0]) / 16.0`. Without a lowering any shader using it is rejected. Earlier attempts (#163, closed unmerged, and the test-merge draft #231) contained this op but it is not on main; this is a small standalone change with a test. ## Tested Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, and WARP. - `cargo test -p victory-shader --features host cvt_off -- --test-threads=1`: new test `v_cvt_off_f32_i4_uses_the_signed_low_nibble` passes (all 16 nibble values plus inputs with junk in the upper bits, e.g. `0xABCDEF05` -> 0.3125; f32 bit patterns compared exactly; run on the GPU and on WARP, DXIL validated). - `cargo test -p victory-shader --features host -- --test-threads=1`, main vs this branch: main 120 passed, 0 failed, 1 ignored; branch 121 passed, 0 failed, 1 ignored. ## Not tested AMD hardware. Real RDNA2 output of this opcode was not compared; the reference is the ISA documentation. No game files were used.
catminou4 commented 2026-11-24 18:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:52:32Z.

Review: APPROVED


v_cvt_off_f32_i4: sign-extend the low nibble (Shl/AShr 28) then scale by 1/16 — matches the ISA's 'signed 4-bit offset to f32' semantics, and bits above the nibble are correctly ignored. The valu test covers 0x8 -> -0.5 and 0xF -> -0.0625 spot checks. VOP1 0x00e. Windows-only execution. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6044527542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1391#pullrequestreview-6044527542). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:52:32Z. **Review:** APPROVED --- v_cvt_off_f32_i4: sign-extend the low nibble (Shl/AShr 28) then scale by 1/16 — matches the ISA's 'signed 4-bit offset to f32' semantics, and bits above the nibble are correctly ignored. The valu test covers 0x8 -> -0.5 and 0xF -> -0.0625 spot checks. VOP1 0x00e. Windows-only execution. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 96 passed, 0 failed.
mercuryVM commented 2026-11-24 20:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T19:46:06Z.

Review: APPROVED


Tested 78c1267 on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 612 passed, 0 failed (on our fork main), with victory-shader single-threaded. v_cvt_off_f32_i4_uses_the_signed_low_nibble passes on the hardware device.

  • It matches the ISA (signext(S0[3:0]) / 16). shl 28 then ashr 28 sign-extends the nibble, and all 16 quotients are exact in f32, so the multiply by 0.0625 equals the division.
  • The result goes through float(), so clamp and omod apply as for the other VOP1 conversions.
  • The test covers all nibbles plus junk in the upper bits, and compares bit patterns exactly.

Merged into our fork's main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046195981 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1391#pullrequestreview-6046195981). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T19:46:06Z. **Review:** APPROVED --- Tested 78c1267 on Windows 11, RTX 5070, MSVC: builds, `cargo test --workspace --no-fail-fast` 612 passed, 0 failed (on our fork main), with victory-shader single-threaded. `v_cvt_off_f32_i4_uses_the_signed_low_nibble` passes on the hardware device. - It matches the ISA (`signext(S0[3:0]) / 16`). `shl 28` then `ashr 28` sign-extends the nibble, and all 16 quotients are exact in f32, so the multiply by 0.0625 equals the division. - The result goes through `float()`, so `clamp` and `omod` apply as for the other VOP1 conversions. - The test covers all nibbles plus junk in the upper bits, and compares bit patterns exactly. Merged into our fork's main. AI-assisted (Claude Code).
sinan-cmyk commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:44:16Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 78c1267 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143989307 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1391#issuecomment-7143989307). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:44:16Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 78c1267 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:28 +00:00
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
Marvisak/VIctory!1391
No description provided.