fix(shader): calculateLOD array coords, split wave64 masks, one interpolation mode per row #222

Merged
mutlusinan merged 3 commits from upstream-pr/222 into main 2026-11-28 19:39:39 +00:00
mutlusinan commented 2026-11-27 19:53:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-27T19:53:41Z.


Problem

Three translation fixes for programs this tree refuses or lowers wrongly:

  1. calculateLOD on an array. The host's calculateLOD still takes three coordinates; a 2-D array's slice was passed as the third. It is not a coordinate, so the wrong level was read.
  2. A wave64 mask restored from split scalar copies. A scalar pair parked in two VGPR lanes and restored one dword at a time is turned into scalar moves by the spill pass; nothing then tied the two words back to the mask they came from, so the restored EXEC lost its lane mask.
  3. One interpolation mode per signature row. DXIL requires every element packed into the same row to share one interpolation mode. Integer and SV_IsFrontFace elements must stay constant; otherwise a used element's mode was not carried to unread siblings in its row.

Fix

  • calculateLOD: the slice coordinate is left undefined (2-D array: third; 1-D array: second and third), per DXIL.
  • structure.rs: a scalar pair whose two words still come from the same known mask, in order, is recognised as that mask again (move_source walks the s_mov_b32 chain).
  • emit/shader.rs: reconcile_row_interp forces a row to constant when any element is integer or SV_IsFrontFace, and otherwise copies a used element's mode to unread siblings in the same row.

Verification

  • cargo check --workspace --target x86_64-pc-windows-msvc --locked — clean.
  • Host tests: cargo test -p victory-shader — 209 passed, 0 failed, including the new split_scalar_copies_across_a_branch_preserve_both_words_of_a_wave64_mask and reconcile_row_interp_matches_constant_and_used_siblings.
  • Not run in game here (no Windows/GPU); the calculateLOD change has no test that does not need a device.

Ported from uiliannn/VItoriaBr 18df163, a51c1ea and 5943771 (GPL-3.0, GPL-compatible).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532328013 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T19:53:41Z. --- ### Problem Three translation fixes for programs this tree refuses or lowers wrongly: 1. **`calculateLOD` on an array.** The host's `calculateLOD` still takes three coordinates; a 2-D array's slice was passed as the third. It is not a coordinate, so the wrong level was read. 2. **A wave64 mask restored from split scalar copies.** A scalar pair parked in two VGPR lanes and restored one dword at a time is turned into scalar moves by the spill pass; nothing then tied the two words back to the mask they came from, so the restored EXEC lost its lane mask. 3. **One interpolation mode per signature row.** DXIL requires every element packed into the same row to share one interpolation mode. Integer and `SV_IsFrontFace` elements must stay constant; otherwise a used element's mode was not carried to unread siblings in its row. ### Fix - `calculateLOD`: the slice coordinate is left undefined (2-D array: third; 1-D array: second and third), per DXIL. - `structure.rs`: a scalar pair whose two words still come from the same known mask, in order, is recognised as that mask again (`move_source` walks the `s_mov_b32` chain). - `emit/shader.rs`: `reconcile_row_interp` forces a row to `constant` when any element is integer or `SV_IsFrontFace`, and otherwise copies a used element's mode to unread siblings in the same row. ### Verification - `cargo check --workspace --target x86_64-pc-windows-msvc --locked` — clean. - Host tests: `cargo test -p victory-shader` — **209 passed, 0 failed**, including the new `split_scalar_copies_across_a_branch_preserve_both_words_of_a_wave64_mask` and `reconcile_row_interp_matches_constant_and_used_siblings`. - Not run in game here (no Windows/GPU); the `calculateLOD` change has no test that does not need a device. Ported from uiliannn/VItoriaBr `18df163`, `a51c1ea` and `5943771` (GPL-3.0, GPL-compatible).
mutlusinan commented 2026-11-27 20:21:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-27T20:21:18Z.


Risk assessment (porting review)

  • calculateLOD: the kind mapping was checked in this tree (crates/victory-shader/src/emit/lower.rs:11259): dim 4 → kind 6 (1-D array, one coordinate) and dim 5 → kind 7 (2-D array, two), so the new branches match the coordinate counts the surrounding code already uses (coords - usize::from(kind == 6 || kind == 7)).
  • Row interpolation: the rule is conservative — any integer or SV_IsFrontFace element forces the row to constant; otherwise a used element's mode wins. It relies on SigElement.row being the DXIL row, which is what the emitter builds. Coverage is synthetic, not real title signatures.
  • Mask recovery: requires the exact, ordered pair of dwords of a known mask and only in wave64; a false positive needs both words to trace back to the same known mask in order, which is the intended case.
  • Rendering-only; no API, format or environment change.
  • Host tests: 209 passed in victory-shader, including the two added here. Not exercised against real title shaders in this environment.
  • Compatibility: merges cleanly and type-checks against main at e69e39c.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7227420571 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222#issuecomment-7227420571). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T20:21:18Z. --- ### Risk assessment (porting review) - **`calculateLOD`:** the kind mapping was checked in this tree (`crates/victory-shader/src/emit/lower.rs:11259`): `dim 4 → kind 6` (1-D array, one coordinate) and `dim 5 → kind 7` (2-D array, two), so the new branches match the coordinate counts the surrounding code already uses (`coords - usize::from(kind == 6 || kind == 7)`). - **Row interpolation:** the rule is conservative — any integer or `SV_IsFrontFace` element forces the row to `constant`; otherwise a used element's mode wins. It relies on `SigElement.row` being the DXIL row, which is what the emitter builds. Coverage is synthetic, not real title signatures. - **Mask recovery:** requires the exact, ordered pair of dwords of a known mask and only in wave64; a false positive needs both words to trace back to the same known mask in order, which is the intended case. - Rendering-only; no API, format or environment change. - Host tests: 209 passed in `victory-shader`, including the two added here. Not exercised against real title shaders in this environment. - **Compatibility:** merges cleanly and type-checks against `main` at `e69e39c`.
1tsethan commented 2026-11-27 23:00:42 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 1tsethan on 2026-11-27T23:00:42Z.


Independent Windows validation of PR #222.

Tested commit: 70850847cf90286da86be0deaa102b6079054dda.

cargo test --locked -p victory-shader reconcile_row_interp -- --nocapture --test-threads=1

Exit: 0.

  • test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 293 filtered out; finished in 0.00s

Coverage here is the interpolation-row regression only; calculateLOD array behavior and other changes still need dedicated device/output validation.

Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229798717 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222#issuecomment-7229798717). Originally posted by [1tsethan](https://github.com/1tsethan) on 2026-11-27T23:00:42Z. --- Independent Windows validation of PR #222. Tested commit: `70850847cf90286da86be0deaa102b6079054dda`. `cargo test --locked -p victory-shader reconcile_row_interp -- --nocapture --test-threads=1` Exit: **0**. - test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 293 filtered out; finished in 0.00s Coverage here is the interpolation-row regression only; calculateLOD array behavior and other changes still need dedicated device/output validation. Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result. <!-- victory-native-validation-20261128 -->
mutlusinan commented 2026-11-28 12:01:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-28T12:01:30Z.


Rebased onto current main

Rebased onto 63b902f (force-with-lease); no conflicts — the three commits still apply to the current lower.rs/structure.rs/shader.rs.

Re-verified after the rebase:

  • cargo check --workspace --target x86_64-pc-windows-msvc --locked — clean.
  • cargo test -p victory-shader -p victory-core -p victory-formats — 209 / 16 / 46 passed, 0 failed, including the two tests these commits add.

No equivalent of any of the three fixes is on main (checked: reconcile_row_interp, move_source, and the array-coordinate branch of calculateLOD are absent), so the risk note above stands unchanged. CI shows action_required (maintainer approval to run a fork's workflow).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7238939821 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222#issuecomment-7238939821). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-28T12:01:30Z. --- ### Rebased onto current `main` Rebased onto `63b902f` (force-with-lease); no conflicts — the three commits still apply to the current `lower.rs`/`structure.rs`/`shader.rs`. Re-verified after the rebase: - `cargo check --workspace --target x86_64-pc-windows-msvc --locked` — clean. - `cargo test -p victory-shader -p victory-core -p victory-formats` — **209 / 16 / 46 passed, 0 failed**, including the two tests these commits add. No equivalent of any of the three fixes is on `main` (checked: `reconcile_row_interp`, `move_source`, and the array-coordinate branch of `calculateLOD` are absent), so the risk note above stands unchanged. CI shows `action_required` (maintainer approval to run a fork's workflow).
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
trustno1-coder/VIctory-NVIDIA!222
No description provided.