Shaders: honor op_sel, omod and clamp on v_interp_p2_f16 (port of VIctory#1696) #189

Open
github-bot wants to merge 1 commit from github-bot/gh-189 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:25 UTC · original
lcg007xd-c:port/vic-1696 → main · +141 −1 · 2 files · 1 commits · open

Port of Marvisak/VIctory#1696 by Calvix2k. It is cherry-picked with -x, so the commit keeps its author and its upstream hash. This fork's main (000ffdd) does not have it, and it is not in #142.

What it fixes

v_interp_p2_f16 ignored op_sel (which half it writes), omod and clamp. The fork keeps 16-bit inputs as f32, so here omod and clamp are applied to the f32 value before its single conversion to f16, and the result goes through write_half.

Tested (Linux, Rust 1.98.1)

  • New interpolated_f16_writes_the_op_sel_half_with_modifiers (adapted to the fork's track/emit signatures; needs dxc, so Windows). On Linux, a temporary IR test showed no high-half shift without the port; not committed. Upstream's test-formatting hunks for tests this fork does not have were left out.
  • cargo test -p victory-shader --lib on this branch alone: no failures.
  • It applies to main without conflicts, and does not depend on the other open ports.

Not run here: Windows/GPU tests, since I have no Windows machine.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189) `lcg007xd-c:port/vic-1696` → `main` · +141 −1 · 2 files · 1 commits · open Port of [Marvisak/VIctory#1696](https://github.com/Marvisak/VIctory/pull/1696) by Calvix2k. It is cherry-picked with `-x`, so the commit keeps its author and its upstream hash. This fork's `main` (000ffdd) does not have it, and it is not in #142. ## What it fixes `v_interp_p2_f16` ignored `op_sel` (which half it writes), `omod` and `clamp`. The fork keeps 16-bit inputs as f32, so here omod and clamp are applied to the f32 value before its single conversion to f16, and the result goes through `write_half`. ## Tested (Linux, Rust 1.98.1) - New `interpolated_f16_writes_the_op_sel_half_with_modifiers` (adapted to the fork's `track`/`emit` signatures; needs dxc, so Windows). On Linux, a temporary IR test showed no high-half shift without the port; not committed. Upstream's test-formatting hunks for tests this fork does not have were left out. - `cargo test -p victory-shader --lib` on this branch alone: no failures. - It applies to `main` without conflicts, and does not depend on the other open ports. **Not run here:** Windows/GPU tests, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The f16 interpolation always wrote the low destination half via
low_half() and dropped the VOP3 output modifiers. Write through
write_half() (op_sel[3], SDWA) and apply omod then clamp to the f16
result in f32 so the conversion rounds once, matching write_f()'s order.

Addresses VIC-BT-029 from audit #1242.

Validation:
- cargo test -p victory-shader --locked -- --test-threads=1
  --skip emit::valu_tests --skip emit::waterfall_tests
- cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings
- cargo xtask policy

(cherry picked from commit e29391f56c49047ec4046ef347ad3cc8063ac522)

Conflict resolved against the fork's interpolation lowering (16-bit inputs held as f32): omod and clamp are applied to the f32 value before its one conversion to f16; the upstream-only formatting hunks of tests the fork lacks are dropped, and the new test uses the fork's track/emit signatures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:35 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 04:57 UTC · original

Heads-up from a merge test: this PR's new test passes on its own head but fails once merged with current main.

  • PR head 2376b13 (base 000ffdd): interpolated_f16_writes_the_op_sel_half_with_modifiers passes.
  • Merged onto main 4f62c2a: it fails in every run (2 of 2) with
    panicked at crates\victory-shader\src\emit\mod.rs:1117:9:
    low write keeps the high half
    
  • Bisected over the two victory-shader commits between the two bases. Merged onto e48eb83 it passes; merged onto ae75a66 ("Clean-up passes over translated shaders") it fails. So the clean-up passes change what this test sees: either they drop or merge the write that keeps the high half, or the test reads the program at a point that the passes now reshape. I have not looked at which.

The rest of victory-shader is unchanged by the merge: 275 passed, 3 failed. The two other failures are the RDNA2 wave-size tests that fail on main too (#110, #204). Command: cargo test --release -p victory-shader --lib, on an RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. The test itself does not use the GPU.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 04:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189#issuecomment-7183055572) Heads-up from a merge test: this PR's new test passes on its own head but fails once merged with current `main`. - PR head `2376b13` (base `000ffdd`): `interpolated_f16_writes_the_op_sel_half_with_modifiers` passes. - Merged onto `main` `4f62c2a`: it fails in every run (2 of 2) with ``` panicked at crates\victory-shader\src\emit\mod.rs:1117:9: low write keeps the high half ``` - Bisected over the two `victory-shader` commits between the two bases. Merged onto `e48eb83` it passes; merged onto `ae75a66` ("Clean-up passes over translated shaders") it fails. So the clean-up passes change what this test sees: either they drop or merge the write that keeps the high half, or the test reads the program at a point that the passes now reshape. I have not looked at which. The rest of `victory-shader` is unchanged by the merge: 275 passed, 3 failed. The two other failures are the RDNA2 wave-size tests that fail on `main` too (#110, #204). Command: `cargo test --release -p victory-shader --lib`, on an RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. The test itself does not use the GPU. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:44 UTC · original

Tested on Windows 11 with Rust 1.98.1 and dxc/dxil.dll from SDK 10.0.26100.0. Nothing below used the GPU. The head 2376b13 is based on 000ffdd. I cherry-picked it onto current main 4f62c2a, where it applies cleanly, and tested that. Main now runs the bitcode clean-up passes by default.

New test (interpolated_f16_writes_the_op_sel_half_with_modifiers):

  • On 4f62c2a + this PR: fails at assert!(low.contains("-65536"), "low write keeps the high half"). In this test the translator uses the constant 0 for the old v2. The mask becomes and i32 0, -65536, and the clean-up passes fold it away. With VICTORY_SHADER_OPT=0 the test passes.
  • With the passes on, the high-half dump still has shl i32 ..., 16, fmul ... 2.000000e+00 and dx.op.unary.f32(i32 7, ...), and the low dump has no saturate. So only the -65536 assertion depends on the passes. A non-constant kept half, or a check that survives the passes, should make the test pass on main.
  • Without the fix (test only, on 4f62c2a): with VICTORY_SHADER_OPT=0 it fails at "op_sel[3] writes the high half", as intended. With the default passes it fails earlier, at the -65536 assertion.

Whole-title run of the game's shaders.rpf (translate --validate --host-lanes 32-64), 4f62c2a against 4f62c2a + PR:

  • The totals are the same: 26084 programs translated and 40601701 IR instructions.
  • Validation is the same as before:
    • All 14247 VS/PS and all 2682 CS validate.
    • MS: 8694 of 8765 validate.
  • The same two refusal groups appear, and there are no new failures.
  • 4646 pixel shaders get a different DXIL hash. I compared 209 of them with dxc -dumpbin. Each has the same set of instructions and the same instruction count as before. This fits the code: write_half emits its two ands in the opposite order from low_half.
  • The title has 59367 v_interp_p2_f16, and none of them sets op_sel[3], clamp or omod. So the fixed paths are not used in this game.

Not tested:

  • No in-game or GPU rendering check.
  • Only the 32-64 lane config.
  • No corpus run on the head as-is (000ffdd).
  • Only 209 of the 4646 changed shaders were compared instruction by instruction.
**@⁠adrianmjim** on GitHub · 2026-11-26 19:44 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189#issuecomment-7201903745) Tested on Windows 11 with Rust 1.98.1 and dxc/dxil.dll from SDK 10.0.26100.0. Nothing below used the GPU. The head 2376b13 is based on 000ffdd. I cherry-picked it onto current main 4f62c2a, where it applies cleanly, and tested that. Main now runs the bitcode clean-up passes by default. New test (`interpolated_f16_writes_the_op_sel_half_with_modifiers`): - On 4f62c2a + this PR: fails at `assert!(low.contains("-65536"), "low write keeps the high half")`. In this test the translator uses the constant 0 for the old v2. The mask becomes `and i32 0, -65536`, and the clean-up passes fold it away. With `VICTORY_SHADER_OPT=0` the test passes. - With the passes on, the high-half dump still has `shl i32 ..., 16`, `fmul ... 2.000000e+00` and `dx.op.unary.f32(i32 7, ...)`, and the low dump has no saturate. So only the -65536 assertion depends on the passes. A non-constant kept half, or a check that survives the passes, should make the test pass on main. - Without the fix (test only, on 4f62c2a): with `VICTORY_SHADER_OPT=0` it fails at "op_sel[3] writes the high half", as intended. With the default passes it fails earlier, at the -65536 assertion. Whole-title run of the game's shaders.rpf (`translate --validate --host-lanes 32-64`), 4f62c2a against 4f62c2a + PR: - The totals are the same: 26084 programs translated and 40601701 IR instructions. - Validation is the same as before: - All 14247 VS/PS and all 2682 CS validate. - MS: 8694 of 8765 validate. - The same two refusal groups appear, and there are no new failures. - 4646 pixel shaders get a different DXIL hash. I compared 209 of them with `dxc -dumpbin`. Each has the same set of instructions and the same instruction count as before. This fits the code: `write_half` emits its two `and`s in the opposite order from `low_half`. - The title has 59367 `v_interp_p2_f16`, and none of them sets op_sel[3], clamp or omod. So the fixed paths are not used in this game. Not tested: - No in-game or GPU rendering check. - Only the 32-64 lane config. - No corpus run on the head as-is (000ffdd). - Only 209 of the 4646 changed shaders were compared instruction by instruction.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/189/head:github-bot/gh-189'
git switch 'github-bot/gh-189'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-189'
git switch 'github-bot/gh-189'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-189'
git switch 'github-bot/gh-189'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-189'
git switch 'main'
git merge --squash 'github-bot/gh-189'
git switch 'main'
git merge --ff-only 'github-bot/gh-189'
git switch 'main'
git merge 'github-bot/gh-189'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.