Shaders: honor op_sel[3] and modifiers in f16 interpolation #81

Open
BlueCatsz wants to merge 1 commit from upstream-pr/81 into main
BlueCatsz commented 2026-11-26 16:28:09 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by BlueCatsz on 2026-11-26T16:28:09Z.


Fixes three 16-bit pixel interpolation bugs in victory-shader:

Summary of Changes

  1. Preserve op_sel[3] and output modifiers on v_interp_p2_f16 (crates/victory-shader/src/emit/lower.rs)

    • In Lower::interp, v_interp_p2_f16 previously ignored v.omod / v.clamp, bypassed f16_nearest_on() (VICTORY_F16_NEAREST=1), and always wrote via self.low_half, overwriting the low 16 bits even when op_sel[3] selected the high half.
    • Now applies v.omod (×2, ×4, ×0.5) and v.clamp in f32 before converting once through to_f16 (which honors f16_nearest_on()), and writes the result with self.write_half(inst, lo, None) so op_sel[3] places the half while preserving the untouched half.
    • to_f16 in the flat Mode(1) path also shares f16_nearest_on().
  2. Honor modifiers on v_interp_p1ll_f16 (crates/victory-shader/src/io.rs, crates/victory-shader/src/emit/lower.rs)

    • In Halves::pair, paired v_interp_p1ll_f16 instructions with clamp, omod, abs, or neg modifiers were folded into Interp::Interpolated (which skips lowering p1ll), silently dropping those modifiers.
    • Now clears kind = None when v_interp_p1ll_f16 carries modifiers so both halves lower via Interp::Weighted, and Lower::interp finishes v_interp_p1ll_f16 via self.write_f(inst, f, None) (so omod / clamp apply in f32 and abs / neg are rejected rather than ignored).
  3. Synthetic Tests (zero game files)

    • io::tests::f16_first_half_with_modifiers_falls_back_to_weighted
    • emit::barycentric_tests::interpolated_f16_honors_op_sel_and_output_modifiers (verifies op_sel[3], omod, clamp, TEST_F16_NEAREST, p1ll omod/clamp DXIL emission, and rejection of p1ll neg)
    • emit::barycentric_tests::interpolated_f16_draw_checks_high_half_modifiers_and_single_rounding (#[cfg(windows)] D3D12/WARP draw test asserting exact 16-bit bit patterns for high-half op_sel[3], pre-narrowing omod/clamp, single rounding of (2^-15 + 2^-25) * 4.0 -> 0x0801, low-half preservation, and v_interp_p1ll_f16 clamp)

Verification

  • Fork windows-latest CI (Rust 1.98.1, MSVC): CI / check (Clippy --workspace --all-targets -- -D warnings, Clippy --all-features -- -D warnings, and cargo test --workspace --locked with VICTORY_TESTS_ALLOW_SOFTWARE_SKIP=1, victory-shader: 242 passed; 0 failed; 4 ignored, xtask: 4 passed; 0 failed) & Screen / screen both passed.
  • Local Linux (x86_64-unknown-linux-gnu): cargo test --offline --locked -p victory-shader --lib (184 passed; 0 failed; 2 ignored), cargo clippy --offline --locked -p victory-shader --lib -- -D warnings (0 warnings), cargo --offline xtask policy (asset policy: 210 files ok), and git diff --check all passed.
  • Scope / Disclosure: AI-assisted PR (Antigravity). Verified with synthetic unit tests and D3D12/WARP draw tests only; no game executable, asset files, or in-game hardware benchmark were run.
<!-- greyfinch-sync:DexNom/VIctory:issue:5513672663 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/81). Originally posted by [BlueCatsz](https://github.com/BlueCatsz) on 2026-11-26T16:28:09Z. --- Fixes three 16-bit pixel interpolation bugs in `victory-shader`: ### Summary of Changes 1. **Preserve `op_sel[3]` and output modifiers on `v_interp_p2_f16` (`crates/victory-shader/src/emit/lower.rs`)** - In `Lower::interp`, `v_interp_p2_f16` previously ignored `v.omod` / `v.clamp`, bypassed `f16_nearest_on()` (`VICTORY_F16_NEAREST=1`), and always wrote via `self.low_half`, overwriting the low 16 bits even when `op_sel[3]` selected the high half. - Now applies `v.omod` (`×2`, `×4`, `×0.5`) and `v.clamp` in `f32` **before** converting once through `to_f16` (which honors `f16_nearest_on()`), and writes the result with `self.write_half(inst, lo, None)` so `op_sel[3]` places the half while preserving the untouched half. - `to_f16` in the flat `Mode(1)` path also shares `f16_nearest_on()`. 2. **Honor modifiers on `v_interp_p1ll_f16` (`crates/victory-shader/src/io.rs`, `crates/victory-shader/src/emit/lower.rs`)** - In `Halves::pair`, paired `v_interp_p1ll_f16` instructions with `clamp`, `omod`, `abs`, or `neg` modifiers were folded into `Interp::Interpolated` (which skips lowering `p1ll`), silently dropping those modifiers. - Now clears `kind = None` when `v_interp_p1ll_f16` carries modifiers so both halves lower via `Interp::Weighted`, and `Lower::interp` finishes `v_interp_p1ll_f16` via `self.write_f(inst, f, None)` (so `omod` / `clamp` apply in `f32` and `abs` / `neg` are rejected rather than ignored). 3. **Synthetic Tests (zero game files)** - `io::tests::f16_first_half_with_modifiers_falls_back_to_weighted` - `emit::barycentric_tests::interpolated_f16_honors_op_sel_and_output_modifiers` (verifies `op_sel[3]`, `omod`, `clamp`, `TEST_F16_NEAREST`, `p1ll` `omod`/`clamp` DXIL emission, and rejection of `p1ll` `neg`) - `emit::barycentric_tests::interpolated_f16_draw_checks_high_half_modifiers_and_single_rounding` (`#[cfg(windows)]` D3D12/WARP draw test asserting exact 16-bit bit patterns for high-half `op_sel[3]`, pre-narrowing `omod`/`clamp`, single rounding of `(2^-15 + 2^-25) * 4.0 -> 0x0801`, low-half preservation, and `v_interp_p1ll_f16` `clamp`) ### Verification - **Fork `windows-latest` CI (Rust `1.98.1`, MSVC):** [`CI / check`](https://github.com/BlueCatsz/VIctory/actions/runs/45858109423) (`Clippy --workspace --all-targets -- -D warnings`, `Clippy --all-features -- -D warnings`, and `cargo test --workspace --locked` with `VICTORY_TESTS_ALLOW_SOFTWARE_SKIP=1`, `victory-shader`: `242 passed; 0 failed; 4 ignored`, `xtask`: `4 passed; 0 failed`) & [`Screen / screen`](https://github.com/BlueCatsz/VIctory/actions/runs/45858109656) both passed. - **Local Linux (`x86_64-unknown-linux-gnu`):** `cargo test --offline --locked -p victory-shader --lib` (`184 passed; 0 failed; 2 ignored`), `cargo clippy --offline --locked -p victory-shader --lib -- -D warnings` (`0` warnings), `cargo --offline xtask policy` (`asset policy: 210 files ok`), and `git diff --check` all passed. - **Scope / Disclosure:** AI-assisted PR (`Antigravity`). Verified with synthetic unit tests and D3D12/WARP draw tests only; no game executable, asset files, or in-game hardware benchmark were run.
andrewDoing commented 2026-11-26 22:43:20 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T22:43:20Z.


At the exact PR head tested:

Independent Windows hardware check at 2bc1252: all three PR tests passed. A non-skippable extended draw confirmed both RTX 5070 and WARP. Both returned expected half-bit vectors [7a00,3c00,0801,0000] and signed/fractional case [bc00,3000,c000,3a00] under both rounding settings. A control using base lowering and IO code with the same harness produced [3a00,47c0,b800,0000] for the first RTX pixel instead of the expected vector. No gameplay scene tested.

Verification was AI-assisted with GPT-6.2 Astra.

<!-- greyfinch-sync:DexNom/VIctory:comment:7204928160 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/81#issuecomment-7204928160). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T22:43:20Z. --- At the exact PR head tested: Independent Windows hardware check at `2bc1252`: all three PR tests passed. A non-skippable extended draw confirmed both RTX 5070 and WARP. Both returned expected half-bit vectors `[7a00,3c00,0801,0000]` and signed/fractional case `[bc00,3000,c000,3a00]` under both rounding settings. A control using base lowering and IO code with the same harness produced `[3a00,47c0,b800,0000]` for the first RTX pixel instead of the expected vector. No gameplay scene tested. Verification was AI-assisted with GPT-6.2 Astra.
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/81:upstream-pr/81'
git switch 'upstream-pr/81'

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