Shaders: honor op_sel[3], clamp, and omod on v_interp_p2_f16 #1338

Open
AscilCH wants to merge 1 commit from upstream-pr/1338 into main
AscilCH commented 2026-11-24 17:33:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T17:33:05Z.


Bug

In crates/victory-shader/src/emit/lower.rs, Lower::interp() lowered v_interp_p2_f16 (VOP3 0x35a) via self.low_half(), unconditionally writing the converted f16 to bits [15:0] and ignoring VOP3 op_sel[3] (high destination half), clamp, and omod.

On RDNA2 (GFX10.3), v_interp_p2_f16 uses op_sel[3] to select whether the result is written to vdst[15:0] or vdst[31:16] while preserving the untouched half, and supports omod (*2, *4, /2) and clamp ([0.0, 1.0]) on the interpolated result before converting to f16.

Reproduction (Before Fix)

With a synthetic RDNA2 VS+PS draw lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, Windows 11) and WARP:

hardware: pixel 0 got [2.5, 0, 2.5, -2], want [-0.5, 2.5, 0.5, 1.0]

Fix

  • Apply v.omod and v.clamp in Lower::interp() before legacyF32ToF16, and return self.write_half(inst, r, None) so op_sel[3] places the 16-bit result into the chosen half while preserving the other half.
  • Added synthetic end-to-end VS+PS test emit::valu_tests::v_interp_p2_f16_respects_opsel_and_clamp covering low-half (op_sel[3]=0), high-half (op_sel[3]=1 preserving low half), clamp, and omod (mul:2 / div:2).

Verification

Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK dxil.dll:

  • rustfmt --edition 2024 --check on valu_tests.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- v_interp_p2_f16_respects_opsel_and_clamp --nocapture --test-threads=1: passed (hardware + WARP + dxil.dll)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587696468 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T17:33:05Z. --- ### Bug In `crates/victory-shader/src/emit/lower.rs`, `Lower::interp()` lowered `v_interp_p2_f16` (`VOP3 0x35a`) via `self.low_half()`, unconditionally writing the converted `f16` to bits `[15:0]` and ignoring VOP3 `op_sel[3]` (high destination half), `clamp`, and `omod`. On RDNA2 (GFX10.3), `v_interp_p2_f16` uses `op_sel[3]` to select whether the result is written to `vdst[15:0]` or `vdst[31:16]` while preserving the untouched half, and supports `omod` (`*2`, `*4`, `/2`) and `clamp` (`[0.0, 1.0]`) on the interpolated result before converting to `f16`. ### Reproduction (Before Fix) With a synthetic RDNA2 VS+PS draw lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, Windows 11) and WARP: ```text hardware: pixel 0 got [2.5, 0, 2.5, -2], want [-0.5, 2.5, 0.5, 1.0] ``` ### Fix - Apply `v.omod` and `v.clamp` in `Lower::interp()` before `legacyF32ToF16`, and return `self.write_half(inst, r, None)` so `op_sel[3]` places the 16-bit result into the chosen half while preserving the other half. - Added synthetic end-to-end VS+PS test `emit::valu_tests::v_interp_p2_f16_respects_opsel_and_clamp` covering low-half (`op_sel[3]=0`), high-half (`op_sel[3]=1` preserving low half), `clamp`, and `omod` (`mul:2` / `div:2`). ### Verification Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK `dxil.dll`: - `rustfmt --edition 2024 --check` on `valu_tests.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- v_interp_p2_f16_respects_opsel_and_clamp --nocapture --test-threads=1`: passed (hardware + WARP + `dxil.dll`) - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `121 passed, 0 failed, 1 ignored`
catminou4 commented 2026-11-24 21:02:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:54Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Honors op_sel[3], clamp and omod on v_interp_p2_f16; v_interp_p2_f16_respects_opsel_and_clamp covers the combinations.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046558137 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338#pullrequestreview-6046558137). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:54Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Honors op_sel[3], clamp and omod on v_interp_p2_f16; v_interp_p2_f16_respects_opsel_and_clamp covers the combinations.
Marvisak commented 2026-11-25 02:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:23:02Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149488878 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7149488878). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:23:02Z. --- <!-- victory-triage v1 head=e2dc6baec3a64fc523230728089413bd3978efe3 verdict=needs-rebase at=2026-11-25T01:23:01Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 02:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:58Z.


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

Result: no count change against main.

Offline. I merged head e2dc6ba 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:7149988901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7149988901). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:48:58Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head e2dc6ba 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).
Headache3318 commented 2026-11-25 02:06:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T02:00:06Z.


Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head e2dc6ba applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 96 passed, 0 failed, 1 ignored. All tests pass. The new v_interp_p2_f16_respects_opsel_and_clamp test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 2 errors (vs 4 on main). The PR net-reduces clippy errors by fixing unused imports.

Not tested: Windows MSVC build, the title itself. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150203099 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7150203099). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T02:00:06Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `e2dc6ba` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 96 passed, 0 failed, 1 ignored. All tests pass. The new `v_interp_p2_f16_respects_opsel_and_clamp` test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 2 errors (vs 4 on main). The PR net-reduces clippy errors by fixing unused imports. Not tested: Windows MSVC build, the title itself. AI-assisted.
Dathinel commented 2026-11-25 03:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T02:19:39Z.


I tested the draw fixture from e2dc6ba on main@940d32f with the lowering from #1696. A test-only rebase worked with one change to the synthetic pixel shader input signature.

With the original fixture, pixel shader emission stopped before the draw at offset 128 with a packed input half no element holds. The fixture sets fp16: true, pack2: true, but its ISG1 declares TEXCOORD as float32. Main’s packed-half lookup uses the element’s parsed component type. In the test’s ps_isg1, changing the second element’s component type from 3 to 6 (float16, little-endian u32 at byte 56) was sufficient. The shader instructions and expected pixels stayed the same.

All 16 pixels matched on both the RTX 3050 Laptop and WARP (Windows/MSVC). Two independent controls on hardware show what the test catches: disabling only clamp changed pixel 0’s alpha from 1 to 0.5, and disabling only omod changed blue from 0.5 to 0.25. Restoring main passed on both backends again.

To reproduce, append v_interp_p2_f16_respects_opsel_and_clamp from this PR to main’s valu_tests.rs and run the following before and after changing the fixture field:

cargo test --locked -p victory-shader --lib emit::valu_tests::v_interp_p2_f16_respects_opsel_and_clamp -- --exact --nocapture

AI-assisted. Synthetic draw only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150582239 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7150582239). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T02:19:39Z. --- I tested the draw fixture from `e2dc6ba` on `main@940d32f` with the lowering from #1696. A test-only rebase worked with one change to the synthetic pixel shader input signature. With the original fixture, pixel shader emission stopped before the draw at offset 128 with `a packed input half no element holds`. The fixture sets `fp16: true, pack2: true`, but its ISG1 declares `TEXCOORD` as float32. Main’s [packed-half lookup](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-shader/src/emit/lower.rs#L408-L414) uses the element’s [parsed component type](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-shader/src/emit/mod.rs#L581-L610). In the test’s `ps_isg1`, changing the second element’s component type from `3` to `6` (float16, little-endian u32 at byte 56) was sufficient. The shader instructions and expected pixels stayed the same. All 16 pixels matched on both the RTX 3050 Laptop and WARP (Windows/MSVC). Two independent controls on hardware show what the test catches: disabling only `clamp` changed pixel 0’s alpha from 1 to 0.5, and disabling only `omod` changed blue from 0.5 to 0.25. Restoring main passed on both backends again. To reproduce, append `v_interp_p2_f16_respects_opsel_and_clamp` from this PR to main’s `valu_tests.rs` and run the following before and after changing the fixture field: ```sh cargo test --locked -p victory-shader --lib emit::valu_tests::v_interp_p2_f16_respects_opsel_and_clamp -- --exact --nocapture ``` AI-assisted. Synthetic draw only.
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/1338:upstream-pr/1338'
git switch 'upstream-pr/1338'

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/1338'
git switch 'upstream-pr/1338'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1338'
git switch 'upstream-pr/1338'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1338'
git switch 'main'
git merge --squash 'upstream-pr/1338'
git switch 'main'
git merge --ff-only 'upstream-pr/1338'
git switch 'main'
git merge 'upstream-pr/1338'
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
Marvisak/VIctory!1338
No description provided.