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

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/189 into main
lcg007xd-c commented 2026-11-25 20:25:47 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T20:25:47Z.


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5498604913 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:25:47Z. --- 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)
MamaLeVrai commented 2026-11-26 04:57:47 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T04:57:47Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183055572 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189#issuecomment-7183055572). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T04:57:47Z. --- 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.
adrianmjim commented 2026-11-26 19:44:00 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:44:00Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7201903745 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/189#issuecomment-7201903745). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:44:00Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/189:upstream-pr/189'
git switch 'upstream-pr/189'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/189'
git switch 'upstream-pr/189'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/189'
git switch 'upstream-pr/189'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/189'
git switch 'main'
git merge --squash 'upstream-pr/189'
git switch 'main'
git merge --ff-only 'upstream-pr/189'
git switch 'main'
git merge 'upstream-pr/189'
git push origin 'main'
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
Belobug/VIctory-Belobug-AMD!189
No description provided.