Shaders: honor op_sel, omod and clamp on v_interp_p2_f16 #1695

Merged
Calvix2k merged 1 commit from upstream-pr/1696 into main 2026-11-25 00:23:58 +00:00
Calvix2k commented 2026-11-24 20:49:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:49:43Z.


Addresses VIC-BT-029 from audit #1242.

Summary

v_interp_p2_f16 is a VOP3 instruction with op_sel[3] (destination half), omod and clamp, but the lowering always wrote the low half via low_half and dropped the modifiers.

  • The f16 interpolation result now goes through write_half, which honors op_sel[3] and the SDWA destination word while keeping the untouched half.
  • omod (mul:2, mul:4, div:2) is applied first, then clamp, in f32 around a single legacyF32ToF16 conversion — the same order write_f uses for f32 results.
  • f32 interpolation and the existing 16-bit VALU paths are unchanged.

Test

interpolated_f16_writes_the_op_sel_half_with_modifiers builds a synthetic pixel shader (v_interp_p1_f32 + v_interp_p2_f16 + mrt0 export), dumps the emitted DXIL with dxc -dumpbin and checks:

  • the high-half form shifts the result by 16 (shl i32), the low-half form keeps the destination's high half;
  • omod emits the multiply by 2.0 and clamp emits dx.op.unary.f32 opcode 7;
  • the plain low-half form emits neither.

Against lower.rs from main the test fails on the high-half assertion.

Validation

  • cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests — passed (103 tests, 1 ignored).
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings — passed.
  • cargo xtask policy — passed (154 files).

Note: the DXIL check pins the emitted operations; numeric behavior of f16 clamp follows the crate's existing 16-bit float convention (saturate via DXIL fSat).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6591129242 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1696). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:49:43Z. --- Addresses `VIC-BT-029` from [audit #1242](https://github.com/Marvisak/VIctory/issues/1242). ## Summary `v_interp_p2_f16` is a VOP3 instruction with `op_sel[3]` (destination half), `omod` and `clamp`, but the lowering always wrote the low half via `low_half` and dropped the modifiers. - The f16 interpolation result now goes through `write_half`, which honors `op_sel[3]` and the SDWA destination word while keeping the untouched half. - `omod` (mul:2, mul:4, div:2) is applied first, then `clamp`, in f32 around a single `legacyF32ToF16` conversion — the same order `write_f` uses for f32 results. - f32 interpolation and the existing 16-bit VALU paths are unchanged. ## Test `interpolated_f16_writes_the_op_sel_half_with_modifiers` builds a synthetic pixel shader (`v_interp_p1_f32` + `v_interp_p2_f16` + `mrt0` export), dumps the emitted DXIL with `dxc -dumpbin` and checks: - the high-half form shifts the result by 16 (`shl i32`), the low-half form keeps the destination's high half; - `omod` emits the multiply by 2.0 and `clamp` emits `dx.op.unary.f32` opcode 7; - the plain low-half form emits neither. Against `lower.rs` from `main` the test fails on the high-half assertion. ## Validation - `cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests` — passed (103 tests, 1 ignored). - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` — passed. - `cargo xtask policy` — passed (154 files). Note: the DXIL check pins the emitted operations; numeric behavior of f16 clamp follows the crate's existing 16-bit float convention (saturate via DXIL `fSat`).
DenRakEiw commented 2026-11-24 21:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T20:56:56Z.

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib interpolated_f16_writes_the_op_sel_half_with_modifiers — passed
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean half_modifiers handling for op_sel, omod, and clamp on v_interp_p2_f16 with targeted DXIL verification. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047271900 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1696#pullrequestreview-6047271900). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T20:56:56Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib interpolated_f16_writes_the_op_sel_half_with_modifiers` — passed - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean `half_modifiers` handling for `op_sel`, `omod`, and `clamp` on `v_interp_p2_f16` with targeted DXIL verification. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-24 22:01:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:05Z.

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. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

v_interp_p2_f16 honors op_sel, omod and clamp: half_modifiers applies the modifiers to the selected half; the macOS-visible test asserts the low write keeps the high half and op_sel[3] shifts to the high half in DXIL.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047848269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1696#pullrequestreview-6047848269). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:40:05Z. **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. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests. v_interp_p2_f16 honors op_sel, omod and clamp: half_modifiers applies the modifiers to the selected half; the macOS-visible test asserts the low write keeps the high half and op_sel[3] shifts to the high half in DXIL.
Calvix2k commented 2026-11-24 23:05:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:05:53Z.


Rebased onto upstream 70564ae; the only conflict was the test module (upstream added its own pixel-shader helpers, this PR adds the DXIL dump check). Resolution keeps both. cargo check -p victory-shader --tests --locked passes on the resolved tree.

Full test/clippy validation is deferred because the local disk filled during the rebase batch; CI will run it. No code change beyond the rebase.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145799381 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1696#issuecomment-7145799381). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:05:53Z. --- Rebased onto upstream 70564ae; the only conflict was the test module (upstream added its own pixel-shader helpers, this PR adds the DXIL dump check). Resolution keeps both. `cargo check -p victory-shader --tests --locked` passes on the resolved tree. Full test/clippy validation is deferred because the local disk filled during the rebase batch; CI will run it. No code change beyond the rebase.
upipibi commented 2026-11-24 23:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T22:52:02Z.


NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, e29391f (on main 70564ae). interpolated_f16_writes_the_op_sel_half_with_modifiers passes on the hardware adapter.

AI-assisted (Claude Code). Synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146736442 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1696#issuecomment-7146736442). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T22:52:02Z. --- NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `e29391f` (on `main` `70564ae`). `interpolated_f16_writes_the_op_sel_half_with_modifiers` passes on the hardware adapter. AI-assisted (Claude Code). Synthetic tests only.
upstream-sync closed this pull request 2026-11-25 01:07:02 +00:00
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!1695
No description provided.