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

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

@⁠AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/v-interp-p2-f16-opsel-and-clamp → main · +295 −6 · 2 files · 1 commits · open

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
**@⁠AscilCH** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1338) `AscilCH:fix/v-interp-p2-f16-opsel-and-clamp` → `main` · +295 −6 · 2 files · 1 commits · open ### 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`
In crates/victory-shader/src/emit/lower.rs, Lower::interp() lowered v_interp_p2_f16 through self.low_half(), unconditionally writing the interpolated 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 (VOP3 0x35a) uses op_sel[3] to choose the low or high 16-bit half of vdst while preserving the other half, and supports omod and clamp ([0.0, 1.0]) on the interpolated value.

Fix:
- Apply v.omod and v.clamp before converting to f16 in Lower::interp(), and write the result via self.write_half(inst, r, None) so op_sel[3] places the f16 in the chosen half while preserving the untouched half.
- Add synthetic end-to-end VS+PS hardware/WARP/dxil.dll test emit::valu_tests::v_interp_p2_f16_respects_opsel_and_clamp.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:08 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7149488878) <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7149988901) ### 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).
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 02:00 UTC · original

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.

**@⁠Headache3318** on GitHub · 2026-11-25 02:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7150203099) 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.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 02:19 UTC · original

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.

**@⁠Dathinel** on GitHub · 2026-11-25 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1338#issuecomment-7150582239) 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1338/head:github-bot/gh-1338'
git switch 'github-bot/gh-1338'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1338'
git switch 'github-bot/gh-1338'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1338'
git switch 'github-bot/gh-1338'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1338'
git switch 'main'
git merge --squash 'github-bot/gh-1338'
git switch 'main'
git merge --ff-only 'github-bot/gh-1338'
git switch 'main'
git merge 'github-bot/gh-1338'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1338
No description provided.