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

Manually merged
github merged 1 commit from gh-pr/1696/head into gh-pr/1696/base 2026-11-26 04:42:00 +00:00
Owner

@⁠Calvix2k on GitHub · 2026-11-24 20:49 UTC · original
Calvix2k:codex/shader-interp-p2-f16-029 → main · +161 −14 · 2 files · 1 commits · merged 2026-11-25 00:23 UTC

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

**@⁠Calvix2k** on GitHub · 2026-11-24 20:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1696) `Calvix2k:codex/shader-interp-p2-f16-029` → `main` · +161 −14 · 2 files · 1 commits · merged 2026-11-25 00:23 UTC Addresses `VIC-BT-029` from [audit #1242](https://git.gtahub.st/github/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`).
The f16 interpolation always wrote the low destination half via
low_half() and dropped the VOP3 output modifiers. Write through
write_half() (op_sel[3], SDWA) and apply omod then clamp to the f16
result in f32 so the conversion rounds once, matching write_f()'s order.

Addresses VIC-BT-029 from audit #1242.

Validation:
- cargo test -p victory-shader --locked -- --test-threads=1
  --skip emit::valu_tests --skip emit::waterfall_tests
- cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings
- cargo xtask policy
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:41:58 +00:00
github manually merged commit e29391f56c into gh-pr/1696/base 2026-11-26 04:42:00 +00:00
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:05 UTC · original

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.

**@⁠Calvix2k** on GitHub · 2026-11-24 22:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1696#issuecomment-7145799381) 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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:52 UTC · original

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.

**@⁠upipibi** on GitHub · 2026-11-24 22:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1696#issuecomment-7146736442) 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.
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!1696
No description provided.