Skip to content

SHADER-492: preserve swapped fragment interpolation weights - #2711

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/bary-swap
Nov 23, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/bary-swap

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-492.

What and why

v_swap_b32 exchanges both register values. Pixel input discovery missed the original value in the first operand, and interpolation could continue using a hardware weight after the swap had overwritten the second operand. The changes track both reads and writes and invalidate stale weight copies. A pair with a computed weight also initializes its hardware weights when interpolation is their only consumer. AMD RDNA2 ISA, VOP1

Tested

  • LLVM MC assembled three hand-written fragment shaders for gfx1030. All three translated and passed spirv-val --target-env vulkan1.2 before and after.
  • For incoming weights I = 0.25 and J = 0.5, an exchange of v0 and v1 previously exported (0.5, 0, 0.5, 0). The CPU interpreter now gives (0.5, 0.25, 0.5, 0.25).
  • A second shader swaps 0.125 into the I operand before interpolating a triangle. A third does so through a saved copy. Both previously exported (0.5, 1, 0.25, 0.5) and now give the expected (0.25, 1, 0.25, 0.25). The green channel checks that J still comes from the original triangle.
  • Five focused fragment, interpolation and fallback suites passed, totaling 61 tests and 46 subtests. GPU, driver and retail-corpus results are unmeasured.

AI-assisted with Codex.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

A swapped input can be the first read of a barycentric register, and either operand can replace an interpolation weight. Preserve incoming weights and invalidate copies so a fragment uses the values its program exchanged.
@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent Vulkan run of 7003f7c on RTX 5070 / 621.24. Six synthetic fragment shaders matched 49,152/49,152 pixels across wave32 and wave64 listings on the physical 32-wide subgroup. The parent missed 45,056 pixels on the same inputs.

Alongside raw weight swapping, direct overwrite and overwrite through a saved copy, I checked swapping both weights before interpolation, swapping I under an EXEC mask that covers exactly half the image, and replacing J between the p1 and p2 of a pair. The masked case preserved the original I on the other 2,048 pixels. The two channels distinguish I from J on the fullscreen triangle. All twelve modules passed spirv-val --target-env vulkan1.2, and all 137 test_interp*.py tests passed.

The GPU comparison uses a synthetic triangle and Vulkan barycentric inputs. Native AMD wave64 execution and the retail corpus were outside this run.

@kapitche

kapitche commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested on Linux (WSL2 Ubuntu), Python 3.10.12, CPU only: pass. With upstream/main merged (clean), tests/semantic/test_interp_computed_ij.py runs 17 tests, OK. Negative control: restoring tools/rdna2spirv.py to upstream/main makes 3 of the 17 fail (the new v_swap_b32 cases); the other 14 pass on main as expected. Trial merges are clean with #2722, #2710, #2664 and #2715 (the full tests/semantic suite with #2722 merged also passes: 2574 OK, 3 skipped).

@Jadiac5

Jadiac5 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Corpus run of 7003f7ce against its merge base 49475796, shard 0 of 8 (3,313 of 26,503 shaders), Windows 11, Python 3.12, spirv-val from Vulkan SDK 1.4.363.1: no regression

translated spirv-val valid modules changed
base 49475796 3,313 / 3,313 3,313
this PR 7003f7ce 3,313 / 3,313 3,313 22
  • No shader fails before or after, so the set of failing shaders is unchanged (empty).
  • The 22 changed modules are all pixel shaders (22 of 1,521 in the shard), all larger than before. The same 22 are the only index entries that change, and only in ps_system_inputs.
  • The PR text says "retail-corpus results are unmeasured"; this fills that for one shard. The idiom does occur in the game's shaders, in about 1.4% of the pixel shaders of this shard.
  • Not done: shards 1–7, no GPU run of the 22 modules, no check that the new output is what the hardware does for them.

AI-assisted (Claude Code). Counts only; nothing from the game files is included.

Keep the targeted regression and the intervening upstream changes together for review.
Keep the targeted regression and the intervening upstream changes together for review.
@amarovndres

Copy link
Copy Markdown

Tested c3268852 on AMD Radeon RX 9060 XT (RDNA4, discrete, subgroup 32..64), AMD 26.10.1 (32.0.32015.7029, LLPC, Vulkan 1.4.359), Windows 11 Pro (build 26200): pass.

  • scripts/run_gpu_tests.py (full suite; test programs built from this head with llvm-mingw, llvm-mc 23.1.6): 196/210 passed, 14 skipped, 0 failed. main d0835dd9 on the same machine: 196/210 passed, 14 skipped.
  • tests/semantic/test_interp_computed_ij.py: 22 tests, OK
  • This PR adds no GPU fixture, so the GPU run is a regression check of the translator change on RDNA4 (native wave64), not a test of the new rule itself; the new rule is covered by the semantic test above.

AI-assisted (Claude Code). Synthetic shaders only, no game files.

@bobcatchris

Copy link
Copy Markdown
Contributor

Independent Apple Silicon / MoltenVK check of head 935e5826 (hardware reports Apple M2 / Mac14,3, not M1), macOS 26.4, MoltenVK 1.4.2, subgroup range 4..32, llvm-mc 23.1.6. Translator/Python-only; one harness built from base 3eb4410b shared for the A/B.

  • python -m unittest discover -s tests/semantic -p test_interp_computed_ij.py: 22/22 OK.
  • python -I scripts/run_gpu_tests.py --build <shared harness>: 152/217 passed, 58 skipped, 7 failed — the known MoltenVK expected set, identical per test to base 3eb4410b (0 status differences).

This PR adds no GPU fixture of its own, so the swapped-interpolation-weight fix is checked here only by the semantic tests, not on hardware. No code changes, no game data; counts only.

AI-assisted.

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 935e5826 on Tesla V100-SXM2-32GB (Volta, subgroup 32..32), NVIDIA 580.95.05, Ubuntu 24.04 (kernel 6.14.11), Python 3.12: pass, no regressions.

Setup: the PR diff applied to main 98fa503f (applies cleanly), Linux Vulkan test programs built from that tree (cmake -S runtime -G Ninja), compared against an untouched main 98fa503f built the same way.

  • scripts/run_gpu_tests.py: native 161/217 passed, 56 skipped; LEONIDA_W64_EMULATE=1 LEONIDA_BARY_FALLBACK=1 194/217 passed, 23 skipped. 0 failures, and the same per-test result as main in both modes (the skips are the 64-wide, mesh-shader (Volta has no VK_EXT_mesh_shader), barycentric-only and run by d3d12_* tests).
  • python -m unittest discover -s tests/semantic (llvm-mc 23.1.6, SPIRV-Tools 2026.4 on PATH): 6247 tests, failures=3, errors=2: the same five test_loop_ballot_barrier cases that fail on main here, nothing new.
  • tests/semantic/test_interp_computed_ij.py: 22 OK (main: 20). Negative control: the PR's version of this test on main's tools/ gives 3 failures. test_interp_reaching_write.py: 4 OK.
  • Not covered: no GPU fixture exercises the v_swap_b32 cases, so this is CPU + full-suite only.

No game files. AI-assisted (Claude Code); I ran the commands above and checked the numbers against the logs.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 935e582 merged with main 98fa503 on Linux (Python 3.12.16): pass. test_interp_computed_ij and test_interp_reaching_write 2/2 ok. Negative control with main's tools/rdna2spirv.py: test_interp_computed_ij fails (3 failures).

@ItsNotRexed
ItsNotRexed merged commit 1b5ad07 into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants