Skip to content

Translator: a pixel shader discards by EXEC at its last vm export, not at the end - #1640

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
StebanSchrader:fix/ps-vm-valid-mask
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
StebanSchrader:fix/ps-vm-valid-mask

Conversation

@StebanSchrader

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1380 (comment) (part 1; the export fuzzer is a separate PR). The claim called the rule inferred; it turned out to be in AMD's manual, see below.

What and why

The PS epilogue did OpKill from EXEC at the end of the program and never read the vm modifier. The RDNA2 ISA reference guide (30-November-2020, §11.1 and §11.2.1) says that with VM set EXEC is the pixel valid mask, that the final one sent is used, and that an export to NULL can update only the mask. So when EXEC is written after that export, the translation kept pixels that should be discarded and discarded pixels that should be kept.

  • A PS now keeps EXEC at each executed vm export (any target, null included) and discards from the last one. A path without a vm export still uses EXEC at the end (the manual requires at least one, so this is only a fallback).
  • This is only emitted when some path can write EXEC after a vm export (a walk over the block graph, loops included). In every other case tested the SPIR-V text is unchanged.

The rule is documented by AMD but not measured: I have no RDNA2 GPU.

Impact on the game is unknown. I have no corpus, so I don't know whether any shader writes EXEC after its vm export. The corpus translate / spirv-val counts were not run.

Tested

On main 99f9989, with hand-written and generated programs only:

  • tests/semantic/test_export_valid_mask.py, 16 tests. Against main's translator 11 fail and 1 errors. Of 13 deliberate breakages of the fix, all 13 are caught.
  • tests/semantic: 1,263 tests OK. Translations made in-process during that run were compared with main's translator: the 19,777 without the latch are byte-identical. All 4,108 EXEC stores emitted there came from instructions that writes_exec predicts.
  • The 144 shaders in runtime/test/shaders translate to the same text as on main (with an empty input signature).
  • tests/test_translate.py: 416 passed, 2 skipped. 19 neighbouring test files (control flow, fuzzers, mesh, f16, images) plus the new one: 455 passed.
  • Random programs against a small model of the rule, written for this PR: 5,000 with forward branches (500 of them with the dispatch loop), and 1,500 loops and irreducible graphs in both control-flow forms (3,000 runs). All match. spirv-val on 200 of the first set: 200 pass.
  • Eight cases drawn with vk_harness on a Radeon 780M (driver 24.10.20.01) and an RTX 4070 Laptop GPU (driver 610.91), Windows 11: 8/8 on both, every pixel. This checks that drivers run the translation as intended; it is not a measurement of RDNA2.

Not run: run_gpu_tests.py, the rest of the test files, the corpus.

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 (AMD's ISA guide, marked as not measured).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

The epilogue killed by EXEC at the end of the program, so an EXEC write
after the `exp ... vm` changed which pixels survive. Keep EXEC at that
export, only where a path can write EXEC afterwards: other programs
translate to the same text as before.

The rule is from the RDNA2 ISA reference guide (30-November-2020),
11.1 and 11.2.1. Not measured on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougmb

dougmb commented Nov 22, 2026

Copy link
Copy Markdown

Tested 5f50d57 merged onto main 41f4482 on RTX 3060, NVIDIA 620.73.04, Linux 6.18: pass

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 115/145 passed, 30 skipped, 0 failed (main alone: 115/145 passed, 30 skipped; the skips are the wave64 tests, no 64-wide subgroup on NVIDIA). tests/semantic/test_export_valid_mask.py (pytest) 16 passed.

AI-assisted (Claude Code); no game files used.

@Impre-visible

Copy link
Copy Markdown

Tested 5f50d57 (as is, base 99f9989) on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression. This covers the run_gpu_tests.py run the description lists as not run, on a second NVIDIA generation.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • tests/semantic: 1263 OK (includes test_export_valid_mask.py)
  • build.py: 139 translated, 139 pass spirv-val; check.py: 100 of 133 pass, 33 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 146/146 translated and pass spirv-val; 111/141 passed, 30 skipped (wave64), 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 141/141 passed

Same counts as main 99f9989 on this GPU, so no existing pixel-shader fixture changes its result. Not covered here: the corpus counts, and the rule itself on RDNA2.

AI-assisted run (Claude). Counts only, no game files involved.

@davidaleksejevs

Copy link
Copy Markdown

Tested 5f50d57 on AMD Radeon RX 7900 XTX (RDNA3, gfx1100), AMD 26.11.2, Windows 11: pass

  • runtime built from the PR's base 99f9989 (the PR changes only tools/, docs and tests), llvm-mc 21.1.8 native
  • python -I scripts/run_gpu_tests.py: 141/141 passed, all ps_* tests exact
  • python -I -m unittest discover -s tests/semantic: 1263 OK

(AI-assisted run.)

@ItsNotRexed
ItsNotRexed merged commit 207b5d9 into ItsNotRexed:main Nov 22, 2026
9 of 10 checks passed
@Bladureau

Copy link
Copy Markdown

Post-merge check on Intel, same head as merged (5f50d57f); the run finished just before the merge.

Tested 5f50d57f merged onto main a0acd33d on Intel UHD Graphics (Raptor Lake, "Intel(R) RaptorLake-S Mobile Graphics Controller"), driver 101.7092, Vulkan 1.4.323, Windows 11 Pro (build 26300): pass, no regression.

First Intel run for this PR (earlier checks: two NVIDIA, one AMD RDNA3).

Runtime built on main a0acd33d (scripts\build_runtime.ps1, MSVC 19.52), used for both sides; the PR changes only the translator, a test and docs. llvm-mc 23.1.6 (AMDGPU), SPIRV-Tools v2026.4. Driver selected with VK_LOADER_DRIVERS_SELECT=igvk*.

Full scripts/run_gpu_tests.py, main alone vs main + this PR:

Mode main a0acd33d main + #1640
Normal 110/163 passed, 52 skipped, 1 failed 110/163 passed, 52 skipped, 1 failed
LEONIDA_W64_EMULATE=1 139/163 passed, 23 skipped, 1 failed 139/163 passed, 23 skipped, 1 failed

Every one of the 163 tests has the same status on both sides, in both modes. Normal run with the PR: 54 ps_* pass, 14 skip.

The one failure, on both sides, is ps_ij_computed: "missing .spv (translation failed)". It's not from this PR. On this Intel driver tools/vk_subgroup_info.py reports "per_vertex_inputs": false, so --f16-interp-fallback turns on by itself, like on MoltenVK, and the translator refuses the computed I/J pair under it. That is the runner issue #1680 / #1681 fix. Worth knowing for those PRs: Intel on Windows hits it too, not only Macs.

CPU tests with the PR: python -m unittest discover -s tests/semantic 1414 OK; test_export_valid_mask.py 16 OK, and 11 failures + 1 error when run against main's tools/rdna2spirv.py, so it does test the change.

AI-assisted (Claude Code ran the commands; I reviewed the results).

@Spaghetih

Copy link
Copy Markdown
Contributor

Tested 5f50d57f on NVIDIA GeForce RTX 4070 Ti, driver 621.24, Windows 11 (Vulkan SDK 1.4.363, llvm-mc 21.1.8 in WSL). Corpus: my own 1.0.2.1 package, 26,503 disassembled shaders; only counts are reported. Pass, with one note for review.

  • python -m unittest discover -s tests/semantic: 1,263 tests OK.
  • scripts/run_gpu_tests.py: 146 shaders translated, all pass spirv-val; 111/141 passed, 30 skipped, 0 failed (older base than today's main).
  • Corpus: 11,640 shaders have an exp mrt* ... vm. On a seeded sample of 400, main and this branch both translate 400/400, and all pass spirv-val. The SPIR-V differs in 341 of the 400. Of two I diffed, one changes 3 lines and the other is 255 lines shorter (mostly id renumbering). The change reaches most pixel shaders. They stay valid, but their results weren't compared on the GPU.

AI-assisted (Claude Code).

@StebanSchrader

Copy link
Copy Markdown
Contributor Author

@Spaghetih thanks for the corpus run. Could the 341/400 be a base mismatch? 5f50d57f is on 99f99890, and main at a0acd33d already had 31 more commits to tools/rdna2spirv.py (53 at 89b047cd).

I compared 99f99890 with 5f50d57f directly on 1,536 pixel programs (synthetic ones and the repo's fixtures, no game files):

  • 963 where EXEC can't change after a vm export: identical output.
  • 573 where it can: 8 to 11 more lines net, and at least 28 changed lines each because temporary ids shift.

So the two diffs you describe (3 lines, and 255 lines shorter) don't look like this PR alone. I can't tell how many game shaders it does change.

Could you rerun the same 400 with 99f99890 vs 5f50d57f (or eb083d26 vs 207b5d9f, the merge and its parent) and post just how many differ? If it's still high, that matters and I'll look into it.

AI-assisted (Claude Code).

@Spaghetih

Copy link
Copy Markdown
Contributor

@StebanSchrader You're right, thanks for catching it. My run compared this branch with main at a0acd33d rather than with its base, so the 341/400 (and the two diffs I described) came from the other translator commits.

Rerun on the same seeded 400 (from the 11,640 corpus shaders with an exp mrt* ... vm), 99f99890 vs 5f50d57f: both translate 400/400, all pass spirv-val, and the SPIR-V is identical in 400 of 400. So in this sample no shipped pixel shader can change EXEC after its last vm export, which fits your 963/573 split. The GPU suite result stands. I'm correcting my #1657 note the same way.

AI-assisted (Claude Code).

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.

7 participants