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

Open
github-bot wants to merge 3 commits from github-bot/gh-222 into main AGit
Owner

@⁠mutlusinan on GitHub · 2026-11-27 19:53 UTC · original
mutlusinan:fix/shader-lod-lanes-interp → main · +143 −2 · 3 files · 3 commits · open

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** on GitHub · 2026-11-27 19:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222) `mutlusinan:fix/shader-lod-lanes-interp` → `main` · +143 −2 · 3 files · 3 commits · open ### 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).
A `calculateLOD` result for a 2-D array is two values; the host's
`calculateLOD` still takes three coordinates, and the array slice is not
one of them. Passing the slice as the third coordinate read the wrong
level: a 2-D array's third and a 1-D array's second and third are now
undefined, as DXIL expects.

Ported from uiliannn/VItoriaBr 18df163.
A scalar pair can be parked in two VGPR lanes and restored one dword at a
time. The spill pass then turns the pair into scalar moves, and with the
two dwords written apart nothing tied them back to the mask they came
from. A pair whose two words still come from the same known mask, in
order, is that mask again.

Ported from uiliannn/VItoriaBr a51c1ea.
DXIL requires every signature element packed into the same row to share
one interpolation mode. An integer or SV_IsFrontFace element forces the
row to constant; otherwise a used element's mode wins over unread
siblings, which were left declaring whatever kind their name says.

Ported from uiliannn/VItoriaBr 5943771.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:58:37 +00:00
Author
Owner

@⁠mutlusinan on GitHub · 2026-11-27 20:21 UTC · original

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.
**@⁠mutlusinan** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222#issuecomment-7227420571) ### 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`.
Author
Owner

@⁠1tsethan on GitHub · 2026-11-27 23:00 UTC · original

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.

**@⁠1tsethan** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/222#issuecomment-7229798717) 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 -->
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/222/head:github-bot/gh-222'
git switch 'github-bot/gh-222'

Merge

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