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

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

@⁠Moon0755 on GitHub · 2026-11-25 13:11 UTC · original
Moon0755:fix/interp-p2-f16-modifiers → main · +185 −2 · 2 files · 1 commits · open

Ports upstream Marvisak/VIctory#1696 (Calvix2k), adapted directly to this fork's f32 intermediate value in Lower::interp.

What changed

  • crates/victory-shader/src/emit/lower.rs (Lower::interp):
    • For f16 v_interp_p2_f16 results, apply VOP3 omod (×2, ×4, ÷2) and clamp (saturate) directly to the f32 value before legacyF32ToF16 narrowing (matching write_f and avoiding an extra f32 → f16 → f32 → f16 round-trip).
    • Route the narrowed result through self.write_half(inst, lo, None) instead of self.low_half(inst, reg, lo), so op_sel[3] (high destination half) and SDWA destination selection are honored while keeping the untouched half intact.
  • crates/victory-shader/src/emit/mod.rs:
    • Add v_interp_p2_f16_translates_and_validates (checks translation and dxil.dll validation across low-half, high-half + omod=1 + clamp, and high-half + omod=3).
    • Add v_interp_p2_f16_honors_op_sel_omod_and_clamp_on_gpu (draws a fullscreen triangle with TEXCOORD0.x = 0.75 on D3D12/WARP and checks bit-for-bit that the untouched half of v3 (0x3800_3400) is preserved and op_sel[3], omod, and clamp produce 0x3800_3A00, 0x3C00_3400, and 0x3600_3400).

Why (RDNA2 / Xbox Series X hardware semantics)

v_interp_p2_f16 is a VOP3 instruction carrying op_sel[3] (destination half select), omod, and clamp modifiers. Previously, lowering always wrote the low 16 bits via low_half and dropped omod and clamp, which overwrote the wrong half whenever op_sel[3] targeted bits [31:16] and produced wrong values for scaled/clamped f16 pixel attributes.

Verification

Verified on windows-latest via GitHub Actions run #45620428420 (scoped to -p victory-shader -p xtask, as workspace-wide clippy on main currently fails on unrelated pre-existing items in victory-gpu):

  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture:
    • victory-shader: 217 passed, 0 failed (3 ignored), including dxil.dll validation and warp: v_interp_p2_f16 op_sel/omod/clamp verified
    • xtask: 4 passed, 0 failed (repository_passes_policy ok)

— Neon

**@⁠Moon0755** on GitHub · 2026-11-25 13:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/934) `Moon0755:fix/interp-p2-f16-modifiers` → `main` · +185 −2 · 2 files · 1 commits · open Ports upstream [Marvisak/VIctory#1696](https://github.com/Marvisak/VIctory/pull/1696) (`Calvix2k`), adapted directly to this fork's `f32` intermediate value in `Lower::interp`. ### What changed - **`crates/victory-shader/src/emit/lower.rs` (`Lower::interp`)**: - For `f16` `v_interp_p2_f16` results, apply VOP3 `omod` (`×2`, `×4`, `÷2`) and `clamp` (`saturate`) directly to the `f32` value before `legacyF32ToF16` narrowing (matching `write_f` and avoiding an extra `f32 → f16 → f32 → f16` round-trip). - Route the narrowed result through `self.write_half(inst, lo, None)` instead of `self.low_half(inst, reg, lo)`, so `op_sel[3]` (high destination half) and SDWA destination selection are honored while keeping the untouched half intact. - **`crates/victory-shader/src/emit/mod.rs`**: - Add `v_interp_p2_f16_translates_and_validates` (checks translation and `dxil.dll` validation across low-half, high-half + `omod=1` + `clamp`, and high-half + `omod=3`). - Add `v_interp_p2_f16_honors_op_sel_omod_and_clamp_on_gpu` (draws a fullscreen triangle with `TEXCOORD0.x = 0.75` on D3D12/WARP and checks bit-for-bit that the untouched half of `v3` (`0x3800_3400`) is preserved and `op_sel[3]`, `omod`, and `clamp` produce `0x3800_3A00`, `0x3C00_3400`, and `0x3600_3400`). ### Why (RDNA2 / Xbox Series X hardware semantics) `v_interp_p2_f16` is a VOP3 instruction carrying `op_sel[3]` (destination half select), `omod`, and `clamp` modifiers. Previously, lowering always wrote the low 16 bits via `low_half` and dropped `omod` and `clamp`, which overwrote the wrong half whenever `op_sel[3]` targeted bits `[31:16]` and produced wrong values for scaled/clamped `f16` pixel attributes. ### Verification Verified on `windows-latest` via [GitHub Actions run #45620428420](https://github.com/Moon0755/victory-fork/actions/runs/45620428420) (scoped to `-p victory-shader -p xtask`, as workspace-wide clippy on `main` currently fails on unrelated pre-existing items in `victory-gpu`): - `cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings`: **passed** - `cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings`: **passed** - `cargo test -p victory-shader -p xtask --locked -- --nocapture`: - `victory-shader`: **217 passed, 0 failed** (3 ignored), including `dxil.dll` validation and `warp: v_interp_p2_f16 op_sel/omod/clamp verified` - `xtask`: **4 passed, 0 failed** (`repository_passes_policy` ok) — Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:09 +00:00
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/934/head:github-bot/gh-934'
git switch 'github-bot/gh-934'

Merge

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